mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
[fix] Return an utf-8 encoded string in _value_for_locale
This commit is contained in:
parent
52a3108708
commit
13e29c038d
1 changed files with 14 additions and 2 deletions
16
app.py
16
app.py
|
@ -1124,18 +1124,30 @@ def _value_for_locale(values):
|
||||||
Keyword arguments:
|
Keyword arguments:
|
||||||
values -- A dict of values associated to their locale
|
values -- A dict of values associated to their locale
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
An utf-8 encoded string
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if not isinstance(values, dict):
|
if not isinstance(values, dict):
|
||||||
return values
|
return values
|
||||||
|
|
||||||
for lang in [m18n.locale, m18n.default_locale]:
|
for lang in [m18n.locale, m18n.default_locale]:
|
||||||
try:
|
try:
|
||||||
return values[lang]
|
return _encode_string(values[lang])
|
||||||
except KeyError:
|
except KeyError:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Fallback to first value
|
# Fallback to first value
|
||||||
return values.values()[0]
|
return _encode_string(values.values()[0])
|
||||||
|
|
||||||
|
|
||||||
|
def _encode_string(value):
|
||||||
|
"""
|
||||||
|
Return the string encoded in utf-8 if needed
|
||||||
|
"""
|
||||||
|
if isinstance(value, unicode):
|
||||||
|
return value.encode('utf8')
|
||||||
|
return value
|
||||||
|
|
||||||
|
|
||||||
def is_true(arg):
|
def is_true(arg):
|
||||||
|
|
Loading…
Add table
Reference in a new issue