Skip to content
This repository was archived by the owner on Feb 28, 2023. It is now read-only.

Commit 201f5a7

Browse files
authored
Add fix and tests for RU-locale (#8)
* Add fix and tests for RU-locale * Return test for DE plural locale * Split tests on plural for differen locales
1 parent 01e156b commit 201f5a7

File tree

3 files changed

+56
-3
lines changed

3 files changed

+56
-3
lines changed

flask_icu/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ def format(string, values=None):
452452
ctx = _request_ctx_stack.top
453453
locale = get_locale()
454454
icu_msg = get_message(string)
455-
msg = MessageFormat(icu_msg)
455+
msg = MessageFormat(icu_msg, locale)
456456
if values is not None:
457457
keys = []
458458
vals = []

tests/tests.py

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,58 @@ def test_icu_plural(self):
173173
=0 {no apples} \
174174
one {one apple} \
175175
other {# apples}}.", {'numApples': 3}) == 'I have 3 apples.'
176+
177+
def test_icu_plural_ru(self):
178+
app = flask.Flask(__name__)
179+
icu = ICU(app, default_locale='ru')
180+
181+
with app.test_request_context():
182+
assert format("I have {numApples, plural, \
183+
=0 {no apples} \
184+
one {one apple} \
185+
other {# apples}}.", {'numApples': 0}) == 'У меня нет яблок.'
186+
assert format("I have {numApples, plural, \
187+
=0 {no apples} \
188+
one {one apple} \
189+
other {# apples}}.", {'numApples': 1}) == 'У меня одно яблоко.'
190+
assert format("I have {numApples, plural, \
191+
=0 {no apples} \
192+
one {one apple} \
193+
other {# apples}}.", {'numApples': 2}) == 'У меня 2 яблока.'
194+
assert format("I have {numApples, plural, \
195+
=0 {no apples} \
196+
one {one apple} \
197+
other {# apples}}.", {'numApples': 3}) == 'У меня 3 яблока.'
198+
assert format("I have {numApples, plural, \
199+
=0 {no apples} \
200+
one {one apple} \
201+
other {# apples}}.", {'numApples': 4}) == 'У меня 4 яблока.'
202+
assert format("I have {numApples, plural, \
203+
=0 {no apples} \
204+
one {one apple} \
205+
other {# apples}}.", {'numApples': 5}) == 'У меня 5 яблок.'
206+
assert format("I have {numApples, plural, \
207+
=0 {no apples} \
208+
one {one apple} \
209+
other {# apples}}.", {'numApples': 10}) == 'У меня 10 яблок.'
210+
assert format("I have {numApples, plural, \
211+
=0 {no apples} \
212+
one {one apple} \
213+
other {# apples}}.", {'numApples': 11}) == 'У меня 11 яблок.'
214+
assert format("I have {numApples, plural, \
215+
=0 {no apples} \
216+
one {one apple} \
217+
other {# apples}}.", {'numApples': 20}) == 'У меня 20 яблок.'
218+
assert format("I have {numApples, plural, \
219+
=0 {no apples} \
220+
one {one apple} \
221+
other {# apples}}.", {'numApples': 21}) == 'У меня 21 яблоко.'
176222

177223

224+
def test_icu_plural_de(self):
225+
app = flask.Flask(__name__)
226+
icu = ICU(app, default_locale='de')
227+
178228
with app.test_request_context():
179229
app.config['ICU_DEFAULT_LOCALE'] = 'de'
180230
icu_refresh()
@@ -192,6 +242,8 @@ def test_icu_plural(self):
192242
one {one apple} \
193243
other {# apples}}.", {'numApples': 3}) == 'Ich habe 3 Äpfeln.'
194244

245+
246+
195247
def test_icu_select(self):
196248
app = flask.Flask(__name__)
197249
icu = ICU(app, default_locale='en')
@@ -227,8 +279,8 @@ def test_list_translations(self):
227279
app = flask.Flask(__name__)
228280
icu = ICU(app, default_locale='de')
229281
translations = icu.list_translations()
230-
assert len(translations) == 2
231-
assert ('en' in translations and 'de' in translations)
282+
assert len(translations) == 3
283+
assert ('en' in translations and 'de' in translations and 'ru' in translations)
232284

233285

234286
if __name__ == '__main__':
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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."}

0 commit comments

Comments
 (0)