From 9c77212f4abd2a189d2b2e61c6ccd507cff2e71f Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Mon, 26 Aug 2024 00:20:49 +0100 Subject: [PATCH] Filter for supported languages before parsing .tr files --- app/tasks/importtasks.py | 5 +---- app/tasks/minetestcheck/tree.py | 7 ++++++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/tasks/importtasks.py b/app/tasks/importtasks.py index 6a5407e0..3f305749 100644 --- a/app/tasks/importtasks.py +++ b/app/tasks/importtasks.py @@ -268,11 +268,8 @@ def update_translations(package: Package, tree: PackageTreeNode): ) conn.execute(stmt) - raw_translations = tree.get_translations(tree.get("textdomain", tree.name)) + raw_translations = tree.get_translations(tree.get("textdomain", tree.name), allowed_languages=allowed_languages) for raw_translation in raw_translations: - if raw_translation.language not in allowed_languages: - continue - to_update = { "title": raw_translation.entries.get(tree.get("title", package.title)), "short_desc": raw_translation.entries.get(tree.get("description", package.short_desc)), diff --git a/app/tasks/minetestcheck/tree.py b/app/tasks/minetestcheck/tree.py index a873e65e..2fea0d18 100644 --- a/app/tasks/minetestcheck/tree.py +++ b/app/tasks/minetestcheck/tree.py @@ -316,10 +316,15 @@ class PackageTreeNode: return ret - def get_translations(self, textdomain: str) -> list[Translation]: + def get_translations(self, textdomain: str, allowed_languages: set[str]) -> list[Translation]: ret = [] for name in glob.glob(f"{self.baseDir}/**/locale/{textdomain}.*.tr", recursive=True): + parts = os.path.basename(name).split(".") + lang = parts[-2] + if lang not in allowed_languages: + continue + try: ret.append(parse_tr(name)) except SyntaxError as e: