From 896dc263a1c67e86cc1df9b57b9bedfb1f36cb8e Mon Sep 17 00:00:00 2001 From: Igor Chubin Date: Wed, 21 Apr 2021 20:03:17 +0200 Subject: [PATCH] Add missing translations (#324) (#535) --- bin/proxy.py | 14 +++++++++++++- lib/globals.py | 1 + 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/bin/proxy.py b/bin/proxy.py index 8545212..11e3269 100755 --- a/bin/proxy.py +++ b/bin/proxy.py @@ -36,7 +36,7 @@ MYDIR = os.path.abspath( os.path.dirname(os.path.dirname('__file__'))) sys.path.append("%s/lib/" % MYDIR) -from globals import PROXY_CACHEDIR, PROXY_HOST, PROXY_PORT, USE_METNO, USER_AGENT +from globals import PROXY_CACHEDIR, PROXY_HOST, PROXY_PORT, USE_METNO, USER_AGENT, MISSING_TRANSLATION_LOG from metno import create_standard_json_from_metno, metno_request from translations import PROXY_LANGS # pylint: enable=wrong-import-position @@ -131,11 +131,23 @@ def translate(text, lang): If no translation found, leave it untouched. """ + def _log_unknown_translation(lang, text): + with open(MISSING_TRANSLATION_LOG, "a") as f_missing_translation: + f_missing_translation.write("%s %s\n" % (lang, text)) + if "," in text: terms = text.split(",") translated_terms = [translate(term.strip(), lang) for term in terms] return ", ".join(translated_terms) + if lang not in TRANSLATIONS: + _log_unknown_translation(lang, "UNKNOWN_LANGUAGE") + return text + + if text.lower() not in TRANSLATIONS.get(lang, {}): + _log_unknown_translation(lang, text) + return text + translated = TRANSLATIONS.get(lang, {}).get(text.lower(), text) return translated diff --git a/lib/globals.py b/lib/globals.py index dad0b7d..fe49861 100644 --- a/lib/globals.py +++ b/lib/globals.py @@ -35,6 +35,7 @@ PNG_CACHE = os.path.join(_DATADIR, "cache/png") LRU_CACHE = os.path.join(_DATADIR, "cache/lru") LOG_FILE = os.path.join(_LOGDIR, 'main.log') +MISSING_TRANSLATION_LOG = os.path.join(_LOGDIR, 'missing-translation.log') ALIASES = os.path.join(MYDIR, "share/aliases") ANSI2HTML = os.path.join(MYDIR, "share/ansi2html.sh")