Skip to content

Commit

Permalink
Use gettext tools in path (experimental)
Browse files Browse the repository at this point in the history
  • Loading branch information
wawanbreton committed Nov 27, 2024
1 parent 098ce50 commit 1f523de
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions recipes/translationextractor/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@


class ExtractTranslations(object):
def __init__(self, conanfile: ConanFile, gettext_bindir):
def __init__(self, conanfile: ConanFile):
self._conanfile = conanfile
self._gettext_bindir = gettext_bindir
self._translations_root_path = Path(self._conanfile.source_folder).joinpath("resources", "i18n")
self._all_strings_pot_path = self._translations_root_path.joinpath(
self._conanfile.name + ".pot") # pot file containing all strings untranslated
Expand All @@ -33,9 +32,9 @@ def _update_po_files_all_languages(self) -> None:
if lang_folder.is_dir() and not po_file.exists():
po_file.touch()
self._conanfile.run(
f"{self._gettext_bindir}/msginit --no-translator -i {pot_file} -o {po_file} --locale=en")
f"msginit --no-translator -i {pot_file} -o {po_file} --locale=en", env="conanbuild")
self._conanfile.run(
f"{self._gettext_bindir}/msgmerge --add-location=never --no-wrap --no-fuzzy-matching --sort-output -o {po_file} {po_file} {pot_file}",
f"msgmerge --add-location=never --no-wrap --no-fuzzy-matching --sort-output -o {po_file} {po_file} {pot_file}",
env="conanbuild")

def _remove_pot_header(self, content: str) -> str:
Expand Down Expand Up @@ -90,14 +89,14 @@ def _extract_python(self) -> None:
""" Extract i18n strings from all .py files"""
for path in self._extract_source_files("python", "*.py"):
self._conanfile.run(
f"{self._gettext_bindir}/xgettext --from-code=UTF-8 --join-existing --add-location=never --sort-output --language=python --no-wrap -ki18n:1 -ki18nc:1c,2 -ki18np:1,2 -ki18ncp:1c,2,3 -o {self._all_strings_pot_path} {path}",
f"xgettext --from-code=UTF-8 --join-existing --add-location=never --sort-output --language=python --no-wrap -ki18n:1 -ki18nc:1c,2 -ki18np:1,2 -ki18ncp:1c,2,3 -o {self._all_strings_pot_path} {path}",
env="conanbuild")

def _extract_qml(self) -> None:
""" Extract all i18n strings from qml files"""
for path in self._extract_source_files("qml", "*.qml"):
self._conanfile.run(
f"{self._gettext_bindir}/xgettext --from-code=UTF-8 --join-existing --add-location=never --sort-output --language=javascript --no-wrap -ki18n:1 -ki18nc:1c,2 -ki18np:1,2 -ki18ncp:1c,2,3 -o {self._all_strings_pot_path} {path}",
f"xgettext --from-code=UTF-8 --join-existing --add-location=never --sort-output --language=javascript --no-wrap -ki18n:1 -ki18nc:1c,2 -ki18np:1,2 -ki18ncp:1c,2,3 -o {self._all_strings_pot_path} {path}",
env="conanbuild")

def _extract_plugin(self) -> None:
Expand Down

0 comments on commit 1f523de

Please sign in to comment.