Skip to content

Commit

Permalink
Update i18n translation extraction based on Cura
Browse files Browse the repository at this point in the history
  • Loading branch information
wawanbreton committed Feb 21, 2025
1 parent ba91821 commit de589bc
Showing 1 changed file with 14 additions and 25 deletions.
39 changes: 14 additions & 25 deletions conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,19 @@ class UraniumConan(ConanFile):
package_type = "header-library"

python_requires = "translationextractor/[>=2.2.0]@ultimaker/stable"
tool_requires = "gettext/0.22.5"

options = {
"enable_i18n": [True, False],
"i18n_extract": [True, False],
}
default_options = {
"enable_i18n": False,
"i18n_extract": False,
}

def set_version(self):
if not self.version:
self.version = self.conan_data["version"]

@property
def _i18n_options(self):
return self.conf.get("user.i18n:options", default={"extract": True, "build": True}, check_type=dict)

@property
def _base_dir(self):
if self.install_folder is None:
Expand Down Expand Up @@ -87,9 +84,9 @@ def export_sources(self):
copy(self, "*", os.path.join(self.recipe_folder, "tests"), os.path.join(self.export_sources_folder, "tests"))
copy(self, "*", os.path.join(self.recipe_folder, "UM"), os.path.join(self.export_sources_folder, "UM"))

def config_options(self):
if self.settings.os == "Windows" and not self.conf.get("tools.microsoft.bash:path", check_type=str):
del self.options.enable_i18n
def validate(self):
if self.options.i18n_extract and self.settings.os == "Windows" and not self.conf.get("tools.microsoft.bash:path", check_type=str):
raise ConanInvalidConfiguration("Unable to extract translations on Windows without Bash installed")

def configure(self):
self.options["pyarcus"].shared = True
Expand All @@ -102,31 +99,23 @@ def requirements(self):
self.requires(req)
self.requires("cpython/3.12.2")

def build_requirements(self):
if self.options.get_safe("enable_i18n", False):
self.tool_requires("gettext/0.21")

def generate(self):
vr = VirtualRunEnv(self)
vr.generate()

if self.options.get_safe("enable_i18n", False) and self._i18n_options["extract"]:
if self.options.i18n_extract:
vb = VirtualBuildEnv(self)
vb.generate()

cpp_info = self.dependencies.build["gettext"].cpp_info
pot = self.python_requires["translationextractor"].module.ExtractTranslations(self, cpp_info.bindirs[0])
pot = self.python_requires["translationextractor"].module.ExtractTranslations(self)
pot.generate()

def build(self):
if self.options.get_safe("enable_i18n", False) and self._i18n_options["build"]:
for po_file in self.source_path.joinpath("resources", "i18n").glob("**/*.po"):
mo_file = Path(self.build_folder, po_file.with_suffix('.mo').relative_to(self.source_path))
mo_file = mo_file.parent.joinpath("LC_MESSAGES", mo_file.name)
mkdir(self, str(unix_path(self, Path(mo_file).parent)))
cpp_info = self.dependencies.build["gettext"].cpp_info
self.run(f"{cpp_info.bindirs[0]}/msgfmt {po_file} -o {mo_file} -f", env="conanbuild",
ignore_errors=True)
for po_file in Path(self.source_folder, "resources", "i18n").glob("**/*.po"):
mo_file = Path(self.build_folder, po_file.with_suffix('.mo').relative_to(self.source_folder))
mo_file = mo_file.parent.joinpath("LC_MESSAGES", mo_file.name)
mkdir(self, str(unix_path(self, Path(mo_file).parent)))
self.run(f"msgfmt {po_file} -o {mo_file} -f", env="conanbuild")

def layout(self):
self.folders.source = "."
Expand Down Expand Up @@ -154,4 +143,4 @@ def package(self):
def package_id(self):
self.info.clear()

self.info.options.rm_safe("enable_i18n")
self.info.options.rm_safe("i18n_extract")

0 comments on commit de589bc

Please sign in to comment.