Commit 80673c53 authored by Hiro's avatar Hiro 🏄
Browse files

Fix load locales

parent a80ed49f
......@@ -92,22 +92,24 @@ def get_locales():
locales = json.load(f)
return locales
def load_strings(current_locale='en'):
def load_strings(current_locale):
"""
Loads translated strings and fallback to English
if the translation does not exist.
"""
global strings, translations
# Load all translations
translations = {}
available_locales = get_locales()
for locale in available_locales:
if current_locale not in available_locales:
current_locale = "en"
filename = get_resource_path("{}.json".format(locale), '../share/locale')
with open(filename, encoding='utf-8') as f:
translations[locale] = json.load(f)
filename = get_resource_path("{}.json".format(current_locale), '../share/locale')
with open(filename, encoding='utf-8') as f:
translations[current_locale] = json.load(f)
strings = {}
for s in translations[current_locale]:
......
......@@ -25,6 +25,10 @@ class EmailServiceTests(unittest.TestCase):
conftests.strings.load_strings("en")
self.assertEqual(conftests.strings._("smtp_mirrors_subject"), "[GetTor] Mirrors")
def test_load_default_strings(self):
conftests.strings.load_strings(None)
self.assertEqual(conftests.strings._("smtp_mirrors_subject"), "[GetTor] Mirrors")
def test_load_es_strings(self):
conftests.strings.load_strings("es")
self.assertEqual(conftests.strings._("smtp_help_subject"), "[GetTor] Ayuda")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment