beremiz

Parents e4339010895b
Children 2ac7232fdb23
SVGHMI: fix i18n : less warnings, supports fuzzy bit, detects incomplete and non-in-sync catalogs.
--- a/svghmi/i18n.py Wed Mar 20 10:58:46 2024 +0100
+++ b/svghmi/i18n.py Thu Mar 21 12:19:48 2024 +0100
@@ -92,16 +92,21 @@
"""
translated_messages = []
broken_lang = set()
+ incomplete_lang = set()
for msgid,label,svgid in messages:
translated_message = []
for langcode,translation in translations:
msg = translation.pop(msgid, None)
if msg is 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)
- else:
- translated_message.append(msg)
+ msg = msgid
+ elif msg == "":
+ # Empty translation (msgid is in .po)
+ incomplete_lang.add(langcode)
+ msg = msgid
+
+ translated_message.append(msg)
translated_messages.append((msgid,translated_message))
langs = []
for langcode,translation in translations:
@@ -119,11 +124,16 @@
langs.append((langname,langcode))
broken = False
- for msgid, msg in translation.iteritems():
+ if translation:
broken = True
- 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))
+ errcallback((
+ _('Translation for "{}" is outdated and incomplete.')
+ if langcode in incomplete_lang else
+ _('Translation for "{}" is outdated.')).format(langcode) +
+ " "+_('Edit {}.po, click "Translation -> 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
@@ -272,7 +282,7 @@
def add(self, msgid, msgstr, fuzzy):
"Add a non-fuzzy translation to the dictionary."
- if not fuzzy and msgstr and msgid:
+ if msgid:
self.__messages[msgid.decode('utf-8')] = msgstr.decode('utf-8')
def read(self, fp):
@@ -302,6 +312,7 @@
if l.startswith('msgid') and not l.startswith('msgid_plural'):
if section == STR:
self.add(msgid, msgstr, fuzzy)
+ fuzzy = 0
section = ID
l = l[5:]
msgid = msgstr = ''