summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIsaac Jurado <diptongo@gmail.com>2015-11-20 11:21:04 -0800
committerIsaac Jurado <diptongo@gmail.com>2015-11-20 11:21:04 -0800
commitc7d2305e722997884964e65a02fa8afcc2ff3ab6 (patch)
tree4f4660a24e14d5b7dd49f23fa4b5e9ba53f8f850
parent5116c167241d7e01870f17adf8de0a1c86744ea4 (diff)
parent531f666c163cfa406dfcb6545027001018995051 (diff)
downloadbabel-c7d2305e722997884964e65a02fa8afcc2ff3ab6.tar.gz
Merge pull request #249 from mbirtwell/fix_zh_plural_selection
Fix zh plural selection
-rw-r--r--babel/messages/plurals.py6
-rw-r--r--tests/messages/test_plurals.py27
2 files changed, 24 insertions, 9 deletions
diff --git a/babel/messages/plurals.py b/babel/messages/plurals.py
index c00a211..05f9110 100644
--- a/babel/messages/plurals.py
+++ b/babel/messages/plurals.py
@@ -192,10 +192,8 @@ PLURALS = {
'vi': (1, '0'),
# Xhosa - From Pootle's PO's
'xh': (2, '(n != 1)'),
- # Chinese - From Pootle's PO's
- 'zh_CN': (1, '0'),
- 'zh_HK': (1, '0'),
- 'zh_TW': (1, '0'),
+ # Chinese - From Pootle's PO's (modified)
+ 'zh': (1, '0'),
}
diff --git a/tests/messages/test_plurals.py b/tests/messages/test_plurals.py
index 9466dec..8c11745 100644
--- a/tests/messages/test_plurals.py
+++ b/tests/messages/test_plurals.py
@@ -10,17 +10,34 @@
# This software consists of voluntary contributions made by many
# individuals. For the exact contribution history, see the revision
# history and logs, available at http://babel.edgewall.org/log/.
+import pytest
-import doctest
-import unittest
-
+from babel import Locale
from babel.messages import plurals
-def test_get_plural():
- assert plurals.get_plural(locale='en') == (2, '(n != 1)')
+@pytest.mark.parametrize(('locale', 'num_plurals', 'plural_expr'), [
+ (Locale('en'), 2, '(n != 1)'),
+ (Locale('en', 'US'), 2, '(n != 1)'),
+ (Locale('zh'), 1, '0'),
+ (Locale('zh', script='Hans'), 1, '0'),
+ (Locale('zh', script='Hant'), 1, '0'),
+ (Locale('zh', 'CN', 'Hans'), 1, '0'),
+ (Locale('zh', 'TW', 'Hant'), 1, '0'),
+])
+def test_get_plural_selection(locale, num_plurals, plural_expr):
+ assert plurals.get_plural(locale) == (num_plurals, plural_expr)
+
+
+def test_get_plural_accpets_strings():
assert plurals.get_plural(locale='ga') == (3, '(n==1 ? 0 : n==2 ? 1 : 2)')
+
+def test_get_plural_falls_back_to_default():
+ assert plurals.get_plural('aa') == (2, '(n != 1)')
+
+
+def test_plural_tuple_attributes():
tup = plurals.get_plural("ja")
assert tup.num_plurals == 1
assert tup.plural_expr == '0'