From 13e29c038d4834c5efc838c8b5fa506a3a162572 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Lebleu?= Date: Tue, 24 Jun 2014 16:09:41 +0200 Subject: [PATCH] [fix] Return an utf-8 encoded string in _value_for_locale --- app.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/app.py b/app.py index d6bc38938..32d8efea9 100644 --- a/app.py +++ b/app.py @@ -1124,18 +1124,30 @@ def _value_for_locale(values): Keyword arguments: values -- A dict of values associated to their locale + Returns: + An utf-8 encoded string + """ if not isinstance(values, dict): return values for lang in [m18n.locale, m18n.default_locale]: try: - return values[lang] + return _encode_string(values[lang]) except KeyError: continue # 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):