--- a/svghmi/i18n.py Wed Mar 20 12:15:23 2024 +0100
+++ b/svghmi/i18n.py Wed Mar 20 16:44:29 2024 +0100
@@ -27,7 +27,7 @@
""" Opens PO file with POEdit """
if sys.platform.startswith('win'):
- from six.moves import winreg
poedit_cmd = winreg.QueryValue(winreg.HKEY_LOCAL_MACHINE,
@@ -89,9 +89,8 @@
for translation_name, po_path in GetPoFiles(dirpath):
- translations.append((translation_name, r.get_messages()))
+ messages = POReader().read(po_path) + translations.append((translation_name, messages)) def MatchTranslations(translations, messages, errcallback):
@@ -102,16 +101,21 @@
+ incomplete_lang = set() for msgid,label,svgid in messages:
for langcode,translation in translations:
msg = translation.pop(msgid, None)
+ # Missing translation (msgid not in .po) broken_lang.add(langcode)
- errcallback(_('{}: Missing translation for "{}" (label:{}, id:{})\n').format(langcode,msgid,label,svgid))
- translated_message.append(msgid)
- translated_message.append(msg)
+ # Empty translation (msgid is in .po) + incomplete_lang.add(langcode) + translated_message.append(msg) translated_messages.append((msgid,translated_message))
for langcode,translation in translations:
@@ -129,11 +133,16 @@
langs.append((langname,langcode))
- for msgid, msg in translation.items():
- errcallback(_('{}: Unused translation "{}":"{}"\n').format(langcode,msgid,msg))
if broken or langcode in broken_lang:
- errcallback(_('Translation for {} is outdated, please edit {}.po, click "Catalog -> Update from POT File..." and select messages.pot.\n').format(langcode,langcode))
+ _('Translation for {} is outdated and incomplete.') + if langcode in incomplete_lang else + _('Translation for {} is outdated.')).format(langcode) + + " "+_('Edit {}.po, click "Catalog -> Update from POT File..." and select messages.pot.\n').format(langcode)) + elif langcode in incomplete_lang: + errcallback(_('Translation for {} is incomplete. Edit {}.po to complete it.\n').format(langcode,langcode)) return langs,translated_messages
@@ -265,25 +274,24 @@
- def get_messages(self):
def add(self, ctxt, msgid, msgstr, fuzzy):
- "Add a non-fuzzy translation to the dictionary."
- if not fuzzy and msgstr and msgid:
- self.__messages[msgid] = msgstr
- self.__messages[b"%b\x04%b" % (ctxt, id)] = str
+ "Add eventually empty translation to the dictionary." + self.__messages[msgid if ctxt is None else (b"%b\x04%b" % (ctxt, id))] = msgstr - with open(infile, 'rb') as f:
+ with open(infile, 'rb') as f: + raise UserAddressedException( + 'Cannot open PO translation file :%s' % str(e)) @@ -312,12 +320,14 @@
if l.startswith('msgctxt'):
self.add(msgctxt, msgid, msgstr, fuzzy)
elif l.startswith('msgid') and not l.startswith('msgid_plural'):
self.add(msgctxt, msgid, msgstr, fuzzy)
# See whether there is an encoding declaration
@@ -369,5 +379,7 @@
self.add(msgctxt, msgid, msgstr, fuzzy)
--- a/tests/projects/svghmi_i18n/beremiz.xml Wed Mar 20 12:15:23 2024 +0100
+++ b/tests/projects/svghmi_i18n/beremiz.xml Wed Mar 20 16:44:29 2024 +0100
@@ -1,5 +1,5 @@
<?xml version='1.0' encoding='utf-8'?>
-<BeremizRoot xmlns:xsd="http://www.w3.org/2001/XMLSchema" URI_location="PYRO://127.0.0.1:61284">
+<BeremizRoot xmlns:xsd="http://www.w3.org/2001/XMLSchema" URI_location="LOCAL://"> <Libraries Enable_SVGHMI_Library="true"/>