[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [bridgedb/develop] Let Babel decide what language is right-to-left.
commit f84361fe92b039370f5e468a0688154f72481ad2
Author: Philipp Winter <phw@xxxxxxxxx>
Date: Thu Oct 10 17:22:17 2019 -0700
Let Babel decide what language is right-to-left.
No need to keep a hard-coded list in our code.
---
bridgedb/_langs.py | 2 --
bridgedb/distributors/https/server.py | 3 ---
bridgedb/test/test_translations.py | 5 +++++
bridgedb/translations.py | 12 +++++++++---
4 files changed, 14 insertions(+), 8 deletions(-)
diff --git a/bridgedb/_langs.py b/bridgedb/_langs.py
index aca8342..149265c 100644
--- a/bridgedb/_langs.py
+++ b/bridgedb/_langs.py
@@ -10,8 +10,6 @@
"""_langs.py - Storage for information on installed language support."""
-RTL_LANGS = ('ar', 'he', 'fa', 'gu_IN', 'ku')
-
def get_langs():
"""Return a list of two-letter country codes of translations which were
diff --git a/bridgedb/distributors/https/server.py b/bridgedb/distributors/https/server.py
index 0fb8014..69f04a3 100644
--- a/bridgedb/distributors/https/server.py
+++ b/bridgedb/distributors/https/server.py
@@ -87,9 +87,6 @@ lookup = TemplateLookup(directories=[TEMPLATE_DIR],
collection_size=500)
logging.debug("Set template root to %s" % TEMPLATE_DIR)
-#: Localisations which BridgeDB supports which should be rendered right-to-left.
-rtl_langs = ('ar', 'he', 'fa', 'gu_IN', 'ku')
-
#: A list of supported language tuples. Use getSortedLangList() to read this variable.
supported_langs = []
diff --git a/bridgedb/test/test_translations.py b/bridgedb/test/test_translations.py
index 5f99901..7d14cc0 100644
--- a/bridgedb/test/test_translations.py
+++ b/bridgedb/test/test_translations.py
@@ -76,3 +76,8 @@ class TranslationsMiscTests(unittest.TestCase):
emailAddr = 'bridges+ar@xxxxxxxxxxxxxx'
replyLocale = translations.getLocaleFromPlusAddr(emailAddr)
self.assertEqual('ar', replyLocale)
+
+ def test_usingRTLLang(self):
+ self.assertFalse(translations.usingRTLLang(['foo_BAR']))
+ self.assertFalse(translations.usingRTLLang(['en']))
+ self.assertTrue(translations.usingRTLLang(['fa']))
diff --git a/bridgedb/translations.py b/bridgedb/translations.py
index 447e808..6d7d332 100644
--- a/bridgedb/translations.py
+++ b/bridgedb/translations.py
@@ -12,6 +12,8 @@ import logging
import os
import re
+import babel.core
+
from bridgedb import _langs
from bridgedb import safelog
from bridgedb.parse import headers
@@ -139,6 +141,10 @@ def usingRTLLang(langs):
otherwise.
"""
lang = getFirstSupportedLang(langs)
- if lang in _langs.RTL_LANGS:
- return True
- return False
+
+ rtl = False
+ try:
+ rtl = babel.core.Locale.parse(lang).text_direction == "rtl"
+ except ValueError as err:
+ logging.warning("Couldn't parse locale %s: %s" % (lang, err))
+ return rtl
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits