This is an automated email from the git hooks/post-receive script.
meskio pushed a commit to branch main in repository bridgedb.
commit 3a1531699435c24481fed5e0ddeb8098380b48a8 Author: kez kez@torproject.org AuthorDate: Wed Jul 13 15:09:20 2022 -0700
Enable translation support --- bridgedb/distributors/https/server.py | 19 +++- frontend/bridges.lektorproject | 160 ++++++++++++++++++++++++++++++++++ frontend/build.sh | 29 ++++-- frontend/databags/alternatives.json | 13 +++ frontend/templates/meta.html | 3 + setup.py | 9 +- 6 files changed, 221 insertions(+), 12 deletions(-)
diff --git a/bridgedb/distributors/https/server.py b/bridgedb/distributors/https/server.py index d392d6d..e812e47 100644 --- a/bridgedb/distributors/https/server.py +++ b/bridgedb/distributors/https/server.py @@ -96,6 +96,18 @@ httpsMetrix = metrics.HTTPSMetrics() internalMetrix = metrics.InternalMetrics()
+def getTemplate(langs, template_name): + for lang in langs: + try: + template = lookup.get_template(os.path.join(langs[0], template_name)) + return template + except mako.exceptions.TopLevelLookupException: + continue + + template = lookup.get_template(template_name) + return template + + def stringifyRequestArgs(args): """Turn the given HTTP request arguments from bytes to str.
@@ -410,7 +422,7 @@ class TranslatedTemplateResource(CustomErrorHandlingResource, CSPResource): try: langs = translations.getLocaleFromHTTPRequest(request) rtl = translations.usingRTLLang(langs) - template = lookup.get_template(self.template) + template = getTemplate(langs, self.template) if langs: rendered = template.render(strings=strings, langs=getSortedLangList(), @@ -555,7 +567,7 @@ class CaptchaProtectedResource(CustomErrorHandlingResource, CSPResource): rtl = translations.usingRTLLang(langs) # TODO: this does not work for versions of IE < 8.0 imgstr = b'data:image/jpeg;base64,%s' % base64.b64encode(image) - template = lookup.get_template('captcha.html') + template = getTemplate(langs, 'captcha.html') if langs: rendered = template.render(strings=strings, langs=getSortedLangList(), @@ -1106,8 +1118,9 @@ class BridgesResource(CustomErrorHandlingResource, CSPResource): try: langs = translations.getLocaleFromHTTPRequest(request) rtl = translations.usingRTLLang(langs) - template = lookup.get_template('bridges.html') if langs: + template = getTemplate(langs, 'bridges.html') + # XXX: We might not be using `langs[0]` depending on the result of getTemplate rendered = template.render(strings=strings, langs=getSortedLangList(), rtl=rtl, diff --git a/frontend/bridges.lektorproject b/frontend/bridges.lektorproject index a0637f0..1f70ece 100644 --- a/frontend/bridges.lektorproject +++ b/frontend/bridges.lektorproject @@ -9,3 +9,163 @@ name = English (en) primary = yes url_prefix = / locale = en + +[alternatives.ar] +name = (ar) عربية +url_prefix = /ar/ +locale = ar + +[alternatives.be] +name = беларуская мова (be) +url_prefix = /be/ +locale = be + +[alternatives.ca] +name = Català (ca) +url_prefix = /ca/ +locale = ca + +[alternatives.cs] +name = Czech (cs) +url_prefix = /cs/ +locale = cs + +[alternatives.da] +name = Dansk (da) +url_prefix = /da/ +locale = da + +[alternatives.de] +name = Deutsch (de) +url_prefix = /de/ +locale = de + +[alternatives.es] +name = Español (es) +url_prefix = /es/ +locale = es + +[alternatives.es-AR] +name = placeholder +url_prefix = /es-AR/ +locale = es-AR + +[alternatives.fr] +name = Français (fr) +url_prefix = /fr/ +locale = fr + +[alternatives.ga] +name = Gaeilge (ga) +url_prefix = /ga/ +locale = ga + +[alternatives.he] +name = עברית (he) +url_prefix = /he/ +locale = he + +[alternatives.hr] +name = hrvatski (hr) +url_prefix = /hr/ +locale = hr + +[alternatives.hu] +name = Magyar nyelv (hu) +url_prefix = /hu/ +locale = hu + +[alternatives.is] +name = Íslenska (is) +url_prefix = /is/ +locale = is + +[alternatives.it] +name = Italiano (it) +url_prefix = /it/ +locale = it + +[alternatives.ja] +name = Japanese (ja) +url_prefix = /ja/ +locale = ja + +[alternatives.ka] +name = ქართული ენა (ka) +url_prefix = /ka/ +locale = ka + +[alternatives.lt] +name = lietuvių (lt) +url_prefix = /lt/ +locale = lt + +[alternatives.mk] +name = македонски (mk) +url_prefix = /mk/ +locale = mk + +[alternatives.ml] +name = മലയാളം (ml) +url_prefix = /ml/ +locale = ml + +[alternatives.nb] +name = placeholder +url_prefix = /nb/ +locale = nb + +[alternatives.nl] +name = Nederlands (nl) +url_prefix = /nl/ +locale = nl + +[alternatives.pl] +name = polski (pl) +url_prefix = /pl/ +locale = pl + +[alternatives.pt-BR] +name = Português Brasil (pt-BR) +url_prefix = /pt-BR/ +locale = pt-BR + +[alternatives.pt_PT] +name = Português +url_prefix = /pt-PT/ +locale = pt-PT + +[alternatives.ro] +name = Română (ro) +url_prefix = /ro/ +locale = ro + +[alternatives.ru] +name = Русский (ru) +url_prefix = /ru/ +locale = ru + +[alternatives.sk] +name = placeholder +url_prefix = /sk/ +locale = sk + +[alternatives.sq] +name = shqip (sq) +url_prefix = /sq/ +locale = sq + +[alternatives.sv] +name = placeholder +url_prefix = /sv/ +locale = sv + +[alternatives.tr] +name = Türkçe (tr) +url_prefix = /tr/ +locale = tr + +[alternatives.zh_CN] +name = 简体中文 (zh-CN) +url_prefix = /zh-CN/ +locale = zh-CN diff --git a/frontend/build.sh b/frontend/build.sh index 3c4e174..4480281 100755 --- a/frontend/build.sh +++ b/frontend/build.sh @@ -2,17 +2,36 @@
set -eux
-export LEKTOR_ENV=$1 +export LEKTOR_ENV="$1" + +langs=(be ca cs da de es es_AR fr ga he hr hu is it ja ka lt mk ml nb nl pl pt_BR pt_PT ro ru sk sq sv tr zh_CN) + +copy_lang() { + set +u + + lang="$1" + mkdir -p $(realpath public/"$lang") + cp $(realpath public_tmp/"$lang"/index.html) $(realpath public/"$lang") + cp $(realpath public_tmp/"$lang"/captcha/index.html) $(realpath public/"$lang"/captcha.html) + cp $(realpath public_tmp/"$lang"/bridges/index.html) $(realpath public/"$lang"/bridges.html) + cp $(realpath public_tmp/"$lang"/options/index.html) $(realpath public/"$lang"/options.html) + + set -u +}
cd "$(dirname "$0")"
lektor build -O public_tmp rm -rf public mkdir public -cp public_tmp/index.html public -cp public_tmp/captcha/index.html public/captcha.html -cp public_tmp/bridges/index.html public/bridges.html -cp public_tmp/options/index.html public/options.html + +copy_lang '' + +for lang in $langs +do + copy_lang "$lang" +done + cp -r public_tmp/static public/assets
rm -rf public_tmp diff --git a/frontend/databags/alternatives.json b/frontend/databags/alternatives.json new file mode 100644 index 0000000..1f22a22 --- /dev/null +++ b/frontend/databags/alternatives.json @@ -0,0 +1,13 @@ +{ + "rtl": [ + "ar", + "ckb", + "fa", + "fa-AF", + "he", + "kmr", + "ps", + "ug", + "ur" + ] +} diff --git a/frontend/templates/meta.html b/frontend/templates/meta.html index 95a89da..83bb3da 100644 --- a/frontend/templates/meta.html +++ b/frontend/templates/meta.html @@ -15,6 +15,9 @@ <link rel="stylesheet" href="{{ '/static/css/bootstrap.css'|asseturl }}"> <link rel="stylesheet" href="{{ '/static/fonts/fontawesome/css/all.min.css'|asseturl }}"> <link rel="stylesheet" href="{{ '/static/fonts/fontawesome/css/v4-shims.min.css'|asseturl }}"> + {% if this.alt in bag('alternatives', 'rtl') %} + <link rel="stylesheet" href="{{ '/static/css/rtl.css' | asseturl }}"> + {% endif %} <!-- Standard favicon --> <link rel="icon" type="image/x-icon" href="{{ 'static/images/favicon.ico' | asseturl }}"> <!-- Recommended favicon format --> diff --git a/setup.py b/setup.py index fa5621a..4765661 100644 --- a/setup.py +++ b/setup.py @@ -208,10 +208,11 @@ def get_template_files(): for root, _, files in os.walk(os.path.join(repo_templates, 'assets')): template_files.extend(os.path.join(root, filename) for filename in files)
- for include_pattern in include_patterns: - pattern = os.path.join(repo_templates, include_pattern) - matches = glob(pattern) - template_files.extend(matches) + for root, _, files in os.walk(repo_templates): + for include_pattern in include_patterns: + pattern = os.path.join(root, include_pattern) + matches = glob(pattern) + template_files.extend(matches)
return template_files