[fix] Return an utf-8 encoded string in _value_for_locale

This commit is contained in:
Jérôme Lebleu 2014-06-24 16:09:41 +02:00
parent 52a3108708
commit 13e29c038d

16
app.py
View file

@ -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):