From: Alex Morega Date: Sun, 7 Jul 2013 10:59:47 +0000 (+0200) Subject: make sure rules are always sorted X-Git-Tag: 1.0~68 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4233823e22aa86bf466d58f6f37f60f59e9d42d2;p=thirdparty%2Fbabel.git make sure rules are always sorted --- diff --git a/babel/plural.py b/babel/plural.py index c3137dbf..afc6d1e1 100644 --- a/babel/plural.py +++ b/babel/plural.py @@ -57,7 +57,7 @@ class PluralRule(object): rules = rules.items() found = set() self.abstract = [] - for key, expr in rules: + for key, expr in sorted(list(rules)): if key not in _plural_tags: raise ValueError('unknown tag %r' % key) elif key in found: @@ -180,7 +180,7 @@ def to_gettext(rule): technically limited to integers and returns indices rather than tags. >>> to_gettext({'one': 'n is 1', 'two': 'n is 2'}) - 'nplurals=3; plural=((n == 2) ? 1 : (n == 1) ? 0 : 2)' + 'nplurals=3; plural=((n == 1) ? 0 : (n == 2) ? 1 : 2)' :param rule: the rules as list or dict, or a `PluralRule` object :return: an equivalent gettext-style plural expression diff --git a/tests/test_plural.py b/tests/test_plural.py index 89a782bd..5fe67a54 100644 --- a/tests/test_plural.py +++ b/tests/test_plural.py @@ -43,7 +43,7 @@ def test_to_python(): def test_to_gettext(): assert (plural.to_gettext({'one': 'n is 1', 'two': 'n is 2'}) - == 'nplurals=3; plural=((n == 2) ? 1 : (n == 1) ? 0 : 2)') + == 'nplurals=3; plural=((n == 1) ? 0 : (n == 2) ? 1 : 2)') def test_in_range_list():