From b0169067be43c9abe12e2fab76b591b8b1fc84e0 Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Sun, 2 Feb 2025 23:34:04 +0100 Subject: [PATCH] Add utils entry to generate docs i18n source files --- pkgutils.py | 11 +++++++++++ utils/assets.py | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/pkgutils.py b/pkgutils.py index 794ce640..cd097a7f 100755 --- a/pkgutils.py +++ b/pkgutils.py @@ -202,6 +202,17 @@ if __name__ == "__main__": ) cmdBuildQM.set_defaults(func=utils.assets.buildTranslationAssets) + # Update Docs i18n Sources + cmdUpdateDocsPo = parsers.add_parser( + "docs-lupdate", help=( + "Update translation files for internationalisation of the docs. " + "The langauges to be updated can be added as arguments, " + "or set to all to update all existing translations." + ) + ) + cmdUpdateDocsPo.add_argument("lang", nargs="+") + cmdUpdateDocsPo.set_defaults(func=utils.assets.updateDocsTranslationSources) + # Build Manual cmdBuildManual = parsers.add_parser( "manual", help="Build the help documentation as a PDF (requires LaTeX)." diff --git a/utils/assets.py b/utils/assets.py index b9512dfc..902c0c20 100644 --- a/utils/assets.py +++ b/utils/assets.py @@ -248,6 +248,42 @@ def buildTranslationAssets(args: argparse.Namespace | None = None) -> None: return +def updateDocsTranslationSources(args: argparse.Namespace) -> None: + """Build the documentation .po files.""" + print("") + print("Building Docs Translation Files") + print("===============================") + print("") + + docsDir = ROOT_DIR / "docs" + locsDir = ROOT_DIR / "docs" / "source" / "locales" + locsDir.mkdir(exist_ok=True) + + print("Generating POT Files") + subprocess.call(["make", "gettext"], cwd=docsDir) + print("") + + lang = args.lang + update = [] + if lang == ["all"]: + update = [i.stem for i in locsDir.iterdir() if i.is_dir()] + else: + update = lang + + print("Generating PO Files") + print("Languages: ", update) + print("") + + for code in update: + subprocess.call(["sphinx-intl", "update", "-p", "build/gettext", "-l", code], cwd=docsDir) + print("") + + print("Done") + print("") + + return + + def cleanBuiltAssets(args: argparse.Namespace | None = None) -> None: """Remove assets built by this script.""" print("")