From b004036f8b2624235af20ba601607efa8c3db3ca Mon Sep 17 00:00:00 2001 From: Alex Morega Date: Mon, 6 Jan 2014 21:19:47 +0200 Subject: [PATCH] use fallback plural if none is defined in CLDR fixes #69 --- babel/core.py | 4 +++- tests/test_plural.py | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/babel/core.py b/babel/core.py index 56dbf559..4ada4661 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 5fe67a54..7f31fd98 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' -- 2.47.2