[tor-commits] [gettor/master] Update locales and tests

hiro at torproject.org hiro at torproject.org
Wed May 22 17:14:53 UTC 2019


commit d43b45aff04a86f40fb3e7feab604ab7942ca588
Author: hiro <hiro at torproject.org>
Date:   Wed May 22 19:14:48 2019 +0200

    Update locales and tests
---
 gettor/parse/email.py   |  2 +-
 gettor/utils/strings.py | 13 ++++---------
 share/locale/es.json    |  2 +-
 tests/conftests.py      |  1 +
 tests/test_locales.py   | 33 +++++++++++++++++++++++++++++++++
 5 files changed, 40 insertions(+), 11 deletions(-)

diff --git a/gettor/parse/email.py b/gettor/parse/email.py
index 6518946..7a88f70 100644
--- a/gettor/parse/email.py
+++ b/gettor/parse/email.py
@@ -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()
diff --git a/gettor/utils/strings.py b/gettor/utils/strings.py
index 5231dc7..2c7488c 100644
--- a/gettor/utils/strings.py
+++ b/gettor/utils/strings.py
@@ -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):
diff --git a/share/locale/es.json b/share/locale/es.json
index 3006c7c..f424b33 100644
--- a/share/locale/es.json
+++ b/share/locale/es.json
@@ -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",
diff --git a/tests/conftests.py b/tests/conftests.py
index 206b2f4..eaf1098 100644
--- a/tests/conftests.py
+++ b/tests/conftests.py
@@ -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
diff --git a/tests/test_locales.py b/tests/test_locales.py
new file mode 100644
index 0000000..cc43485
--- /dev/null
+++ b/tests/test_locales.py
@@ -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()



More information about the tor-commits mailing list