From da5bf23c58a7928b83a6b364d6504a604ab867c2 Mon Sep 17 00:00:00 2001 From: aussig Date: Sun, 11 Jan 2026 13:07:01 +0000 Subject: [PATCH 1/2] Add missing type hinting. Remove legacy code for parsing translations (now in `find_localised_strings.py`). EDCD/EDMarketConnector#2586 --- l10n.py | 32 +------------------------------- 1 file changed, 1 insertion(+), 31 deletions(-) diff --git a/l10n.py b/l10n.py index 5f6c5298..8fc499b5 100755 --- a/l10n.py +++ b/l10n.py @@ -83,7 +83,7 @@ class Translations: :param lang: The language to translate to, defaults to the preferred language """ - available = self.available() + available: set[str] = self.available() available.add(Translations.FALLBACK) if not lang: # Choose the default language @@ -331,33 +331,3 @@ class _Locale: # singletons Locale = _Locale() translations = Translations() - -# generate template strings file - like xgettext -# parsing is limited - only single ' or " delimited strings, and only one string per line -if __name__ == "__main__": - regexp = re.compile(r'''_\([ur]?(['"])(((? Date: Sun, 11 Jan 2026 13:23:11 +0000 Subject: [PATCH 2/2] Adjust regex for finding `# LANG:` comments to cope with `#` characters earlier on the same line. Alpha sort localised strings in output. Support `# LANG: Ignore` to allow a string to be ignored and omitted from the output. EDCD/EDMarketConnector#2586 --- scripts/find_localised_strings.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/find_localised_strings.py b/scripts/find_localised_strings.py index 02f928e3..a72e0f07 100644 --- a/scripts/find_localised_strings.py +++ b/scripts/find_localised_strings.py @@ -60,7 +60,7 @@ COMMENT_OWN_LINE_RE is for a comment on its own line. The difference is necessary in order to tell if a 'above' LANG comment is for its own line (SAME_LINE), or meant to be for this following line (OWN_LINE). """ -COMMENT_SAME_LINE_RE = re.compile(r"^.*?(#.*)$") +COMMENT_SAME_LINE_RE = re.compile(r"^.*(#.*)$") COMMENT_OWN_LINE_RE = re.compile(r"^\s*?(#.*)$") @@ -245,6 +245,8 @@ def generate_lang_template(data: dict[pathlib.Path, list[ast.Call]]) -> str: entries: list[LangEntry] = [] for path, calls in data.items(): for c in calls: + if getattr(c, "comment") == "Ignore": + continue entries.append( LangEntry( [FileLocation.from_call(path, c)], @@ -259,7 +261,8 @@ def generate_lang_template(data: dict[pathlib.Path, list[ast.Call]]) -> str: """ print(f"Done Deduping entries {len(entries)=} {len(deduped)=}", file=sys.stderr) - for entry in deduped: + + for entry in sorted(deduped, key=lambda e: e.string.lower()): if len(entry.comments) != len(entry.locations): raise ValueError("Mismatch: 'comments' and 'locations' must have the same length.")