<multi> translations almost ok
This commit is contained in:
parent
5cacf17ad1
commit
06230584d8
@ -214,7 +214,7 @@ class WritableObject(SpipInterface):
|
|||||||
) -> list[str]:
|
) -> list[str]:
|
||||||
output: list[str] = []
|
output: list[str] = []
|
||||||
# Output the remaining number of objects to export every step object
|
# Output the remaining number of objects to export every step object
|
||||||
if index % step == 0:
|
if index % step == 0 and limit > 0:
|
||||||
output.append(f"Exporting {limit-index}")
|
output.append(f"Exporting {limit-index}")
|
||||||
output[-1] += f" level {self._depth}"
|
output[-1] += f" level {self._depth}"
|
||||||
s: str = "s" if limit - index > 1 else ""
|
s: str = "s" if limit - index > 1 else ""
|
||||||
@ -535,16 +535,21 @@ class RedactionalObject(WritableObject):
|
|||||||
for lang, translated_attrs in self._translations.items():
|
for lang, translated_attrs in self._translations.items():
|
||||||
LOG.debug(f"Instanciating {lang} translation of section `{self._title}`")
|
LOG.debug(f"Instanciating {lang} translation of section `{self._title}`")
|
||||||
# Copy itself (with every attribute) as a base for the translated object
|
# Copy itself (with every attribute) as a base for the translated object
|
||||||
translation: Self = deepcopy(self)
|
# translation: Self = deepcopy(self)
|
||||||
|
# Define attributes that new translation will need
|
||||||
|
attributes: dict[str, str] = {}
|
||||||
|
translation: Self = type(self)(**translated_attrs, **attributes)
|
||||||
# Replace the lang & the translations attributes of the translated object
|
# Replace the lang & the translations attributes of the translated object
|
||||||
translation.lang = lang
|
translation.lang = lang
|
||||||
translation._translations = {}
|
translation._translations = {}
|
||||||
# Replace the translated attributes of the translated object
|
# Replace the translated attributes of the translated object
|
||||||
for attr, value in translated_attrs.items():
|
# For each translated attribute, output a DEBUG message
|
||||||
setattr(translation, attr, value)
|
for attr in translated_attrs:
|
||||||
LOG.debug(
|
LOG.debug(
|
||||||
f"{lang} `{self._title}` `{attr}`= `{getattr(translation, attr)}`"
|
f"Instanciated {lang} translation of `{self._title}` `{attr}`"
|
||||||
|
+ f" = `{getattr(translation, attr)}`"
|
||||||
)
|
)
|
||||||
|
translations.append(translation)
|
||||||
return translations
|
return translations
|
||||||
|
|
||||||
# Get the children of this object
|
# Get the children of this object
|
||||||
@ -565,19 +570,18 @@ class RedactionalObject(WritableObject):
|
|||||||
|
|
||||||
# Perform all the write steps of this object
|
# Perform all the write steps of this object
|
||||||
def write_all(
|
def write_all(
|
||||||
self,
|
self, parentdepth: int, parentdir: str, index: int, total: int
|
||||||
parentdepth: int,
|
|
||||||
parentdir: str,
|
|
||||||
index: int,
|
|
||||||
total: int,
|
|
||||||
prepend: str = "",
|
|
||||||
) -> RecursiveList:
|
) -> RecursiveList:
|
||||||
|
prepend: str = self.lang + ": " if total <= 0 else ""
|
||||||
output: RecursiveList = super().write_all(
|
output: RecursiveList = super().write_all(
|
||||||
parentdepth, parentdir, index, total, prepend
|
parentdepth, parentdir, index, total, prepend
|
||||||
)
|
)
|
||||||
output.append(self.write_children())
|
output.append(self.write_children())
|
||||||
for i, translated in enumerate(self.translations()):
|
translations = self.translations()
|
||||||
translated.write_all(parentdepth, parentdir, i, 0, self.lang)
|
LOG.debug(f"Initialized translations of {self._title}: {translations}")
|
||||||
|
for translated in translations:
|
||||||
|
LOG.debug(f"Writing {translated.lang} translation of {self._title}")
|
||||||
|
translated.write_all(parentdepth, parentdir, index, 0)
|
||||||
return output
|
return output
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user