Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Hiro
GetTor
Commits
80673c53
Commit
80673c53
authored
May 22, 2019
by
Hiro
🏄
Browse files
Fix load locales
parent
a80ed49f
Changes
2
Hide whitespace changes
Inline
Side-by-side
gettor/utils/strings.py
View file @
80673c53
...
...
@@ -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
]:
...
...
tests/test_locales.py
View file @
80673c53
...
...
@@ -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"
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment