bonsai_translations - allow .po files going out of sync

We had Chinese translation for Bonsai and some stub file for German and translation.py generation was failing with the error below. Chinese translation is more recent so it has some keys that German file hadn't and some keys were gone in the more recent version. In theory we should make all .po file in sync but let's skip it for now to keep things going.

```
Traceback (most recent call last):
  File "/home/runner/work/IfcOpenShell/IfcOpenShell/src/bonsai/scripts/bonsai_translations.py", line 379, in <module>
    update_translations_from_po(po_directory=Path(args.input), translations_module=Path(args.output))
  File "/home/runner/work/IfcOpenShell/IfcOpenShell/src/bonsai/scripts/bonsai_translations.py", line 203, in update_translations_from_po
    if (msgstr := msg.translations[lang]) in (None, ""):
                  ~~~~~~~~~~~~~~~~^^^^^^
KeyError: 'de_DE'
```
This commit is contained in:
Andrej730
2025-03-07 20:48:36 +05:00
parent 197281eb5a
commit f0e5430daa
+2 -1
View File
@@ -200,7 +200,8 @@ def update_translations_from_po(po_directory: Path, translations_module: Path):
for lang in langs:
ret.append(f'{tab}"{lang}": {{')
for msgid, msg in translation_data.items():
if (msgstr := msg.translations[lang]) in (None, ""):
# World isn't perfect and .po files can get out of sync, so let's make it permissive.
if (msgstr := msg.translations.get(lang)) in (None, ""):
continue
msgctxt = msg.msgctxt
if not msgctxt: