Update locales and tests

This commit is contained in:
hiro 2019-05-22 19:14:48 +02:00
parent 3726d31b4e
commit d43b45aff0
5 changed files with 40 additions and 11 deletions

View File

@ -154,7 +154,7 @@ class EmailParser(object):
request["command"] = "help"
break
if not request["command"] and not request["language"]:
if not request["command"] or not request["language"]:
for word in re.split(r"\s+", msg_str.strip()):
if word.lower() in languages:
request["language"] = word.lower()

View File

@ -85,7 +85,7 @@ def get_locales():
"""
Get available_locales
"""
filename = get_resource_path("available_locales.json", '../share/locale')
locales = {}
with open(filename, encoding='utf-8') as f:
@ -109,15 +109,10 @@ def load_strings(current_locale):
with open(filename, encoding='utf-8') as f:
translations[locale] = json.load(f)
# Build strings
default_locale = 'en'
strings = {}
for s in translations[default_locale]:
if s in translations[current_locale] and translations[current_locale][s] != "":
strings[s] = translations[current_locale][s]
else:
strings[s] = translations[default_locale][s]
for s in translations[current_locale]:
strings[s] = translations[current_locale][s]
def translated(k):

View File

@ -7,7 +7,7 @@
"help_config": "Custom config file location (optional)",
"smtp_links_subject": "[GetTor] Links for your request",
"smtp_mirrors_subject": "[GetTor] Mirrors",
"smtp_help_subject": "[GetTor] Help",
"smtp_help_subject": "[GetTor] Ayuda",
"smtp_unsupported_locale_subject": "[GetTor] Unsupported locale",
"smtp_unsupported_locale_msg": "The locale you requested '{}' is not supported.",
"smtp_vlinks_msg": "You requested Tor Browser for {}.\n\nYou will need only one of the links below to download the bundle. If a link does not work for you, try the next one.\n\n{}\n\n \n--\nGetTor",

View File

@ -3,5 +3,6 @@ from __future__ import print_function
from __future__ import unicode_literals
from gettor.utils import options
from gettor.utils import strings
from gettor.services.email import sendmail
from gettor.parse.email import EmailParser, AddressError, DKIMError

33
tests/test_locales.py Normal file
View File

@ -0,0 +1,33 @@
#!/usr/bin/env python3
import pytest
from twisted.trial import unittest
from twisted.internet import defer, reactor
from twisted.internet import task
from . import conftests
class EmailServiceTests(unittest.TestCase):
# Fail any tests which take longer than 15 seconds.
timeout = 15
def setUp(self):
self.settings = conftests.options.parse_settings()
self.locales = conftests.strings.get_locales()
def tearDown(self):
print("tearDown()")
def test_get_available_locales(self):
self.assertEqual({"en": "English", "es": "Español", "pt": "Português Brasil"}, self.locales)
def test_load_en_strings(self):
conftests.strings.load_strings("en")
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")
if __name__ == "__main__":
unittest.main()