]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
use fallback plural if none is defined in CLDR
authorAlex Morega <alex@grep.ro>
Mon, 6 Jan 2014 19:19:47 +0000 (21:19 +0200)
committerAlex Morega <alex@grep.ro>
Mon, 6 Jan 2014 19:21:58 +0000 (21:21 +0200)
fixes #69

babel/core.py
tests/test_plural.py

index 56dbf559334ee7e086c1b3735ae40631c439fcac..4ada4661f0280ee31609b32719db94b5c326a450 100644 (file)
@@ -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):
index 5fe67a54833ace9451b56ca3bc81ff86113391c0..7f31fd98f60ef596295b88cdf0789c82ef506d47 100644 (file)
@@ -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'