summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Morega <alex@grep.ro>2014-01-06 21:19:47 +0200
committerAlex Morega <alex@grep.ro>2014-01-06 21:21:58 +0200
commitb004036f8b2624235af20ba601607efa8c3db3ca (patch)
tree35f38826fb8d9a56ced453bc95a2f726460de58e
parent592104cb12188a83c6896cb42863bbd5f45a65c8 (diff)
downloadbabel-b004036f8b2624235af20ba601607efa8c3db3ca.tar.gz
use fallback plural if none is defined in CLDR
fixes #69
-rw-r--r--babel/core.py4
-rw-r--r--tests/test_plural.py8
2 files changed, 11 insertions, 1 deletions
diff --git a/babel/core.py b/babel/core.py
index 56dbf55..4ada466 100644
--- a/babel/core.py
+++ b/babel/core.py
@@ -13,12 +13,14 @@ import os
from babel import localedata
from babel._compat import pickle, string_types
+from babel.plural import PluralRule
__all__ = ['UnknownLocaleError', 'Locale', 'default_locale', 'negotiate_locale',
'parse_locale']
_global_data = None
+_default_plural_rule = PluralRule({})
def _raise_no_data_error():
@@ -737,7 +739,7 @@ class Locale(object):
>>> Locale('ru').plural_form(100)
'many'
"""
- return self._data['plural_form']
+ return self._data.get('plural_form', _default_plural_rule)
def default_locale(category=None, aliases=LOCALE_ALIASES):
diff --git a/tests/test_plural.py b/tests/test_plural.py
index 5fe67a5..7f31fd9 100644
--- a/tests/test_plural.py
+++ b/tests/test_plural.py
@@ -90,3 +90,11 @@ def test_plural_within_rules():
assert p(7) == 'few'
assert p(8) == 'few'
assert p(9) == 'few'
+
+
+def test_locales_with_no_plural_rules_have_default():
+ from babel import Locale
+ aa_plural = Locale.parse('aa').plural_form
+ assert aa_plural(1) == 'other'
+ assert aa_plural(2) == 'other'
+ assert aa_plural(15) == 'other'