Filter for supported languages before parsing .tr files

This commit is contained in:
rubenwardy 2024-08-26 00:20:49 +01:00
parent 2b62224a5b
commit 9c77212f4a
2 changed files with 7 additions and 5 deletions

@ -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)),

@ -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: