diff --git a/flask_icu/__init__.py b/flask_icu/__init__.py index 0766c09..3fdb918 100644 --- a/flask_icu/__init__.py +++ b/flask_icu/__init__.py @@ -452,7 +452,7 @@ def format(string, values=None): ctx = _request_ctx_stack.top locale = get_locale() icu_msg = get_message(string) - msg = MessageFormat(icu_msg) + msg = MessageFormat(icu_msg, locale) if values is not None: keys = [] vals = [] diff --git a/tests/tests.py b/tests/tests.py index c2255fd..e5fad91 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -173,8 +173,58 @@ def test_icu_plural(self): =0 {no apples} \ one {one apple} \ other {# apples}}.", {'numApples': 3}) == 'I have 3 apples.' + + def test_icu_plural_ru(self): + app = flask.Flask(__name__) + icu = ICU(app, default_locale='ru') + + with app.test_request_context(): + assert format("I have {numApples, plural, \ + =0 {no apples} \ + one {one apple} \ + other {# apples}}.", {'numApples': 0}) == 'У меня нет яблок.' + assert format("I have {numApples, plural, \ + =0 {no apples} \ + one {one apple} \ + other {# apples}}.", {'numApples': 1}) == 'У меня одно яблоко.' + assert format("I have {numApples, plural, \ + =0 {no apples} \ + one {one apple} \ + other {# apples}}.", {'numApples': 2}) == 'У меня 2 яблока.' + assert format("I have {numApples, plural, \ + =0 {no apples} \ + one {one apple} \ + other {# apples}}.", {'numApples': 3}) == 'У меня 3 яблока.' + assert format("I have {numApples, plural, \ + =0 {no apples} \ + one {one apple} \ + other {# apples}}.", {'numApples': 4}) == 'У меня 4 яблока.' + assert format("I have {numApples, plural, \ + =0 {no apples} \ + one {one apple} \ + other {# apples}}.", {'numApples': 5}) == 'У меня 5 яблок.' + assert format("I have {numApples, plural, \ + =0 {no apples} \ + one {one apple} \ + other {# apples}}.", {'numApples': 10}) == 'У меня 10 яблок.' + assert format("I have {numApples, plural, \ + =0 {no apples} \ + one {one apple} \ + other {# apples}}.", {'numApples': 11}) == 'У меня 11 яблок.' + assert format("I have {numApples, plural, \ + =0 {no apples} \ + one {one apple} \ + other {# apples}}.", {'numApples': 20}) == 'У меня 20 яблок.' + assert format("I have {numApples, plural, \ + =0 {no apples} \ + one {one apple} \ + other {# apples}}.", {'numApples': 21}) == 'У меня 21 яблоко.' + def test_icu_plural_de(self): + app = flask.Flask(__name__) + icu = ICU(app, default_locale='de') + with app.test_request_context(): app.config['ICU_DEFAULT_LOCALE'] = 'de' icu_refresh() @@ -192,6 +242,8 @@ def test_icu_plural(self): one {one apple} \ other {# apples}}.", {'numApples': 3}) == 'Ich habe 3 Äpfeln.' + + def test_icu_select(self): app = flask.Flask(__name__) icu = ICU(app, default_locale='en') @@ -227,8 +279,8 @@ def test_list_translations(self): app = flask.Flask(__name__) icu = ICU(app, default_locale='de') translations = icu.list_translations() - assert len(translations) == 2 - assert ('en' in translations and 'de' in translations) + assert len(translations) == 3 + assert ('en' in translations and 'de' in translations and 'ru' in translations) if __name__ == '__main__': diff --git a/tests/translations/ru/messages.json b/tests/translations/ru/messages.json new file mode 100644 index 0000000..9e75eca --- /dev/null +++ b/tests/translations/ru/messages.json @@ -0,0 +1 @@ +{"Hello {name}!":"Hello {name}!","{z} and {a} and {2x} and {new} and {0} like this library.":"{z} and {a} and {2x} and {new} and {0} like this library.","I have {numApples, plural, =0 {no apples} one {one apple} other {# apples}}.":"У меня {numApples, plural, =0 {нет яблок} =1 {одно яблоко} one {# яблоко} few {# яблока} other {# яблок}}.","{gender, select, male {He} female {She} other {They}} will respond shortly.":"{gender, select, male {He} female {She} other {They}} will respond shortly."} \ No newline at end of file