]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
More stuff merged from mitsuhiko's cldr-24 branch
authorbenselme <benselme@gmail.com>
Fri, 9 Jan 2015 00:40:28 +0000 (19:40 -0500)
committerbenselme <benselme@gmail.com>
Fri, 9 Jan 2015 00:40:28 +0000 (19:40 -0500)
babel/plural.py
tests/test_plural.py

index 297a4228214b2836c80a2b3421f866bfe7bfa537..ce6659b477c6054c3794eaeae3e90da032e7200b 100644 (file)
@@ -52,6 +52,8 @@ class PluralRule(object):
         found = set()
         self.abstract = []
         for key, expr in sorted(list(rules)):
+            if key == 'other':
+                continue
             if key not in _plural_tags:
                 raise ValueError('unknown tag %r' % key)
             elif key in found:
@@ -450,6 +452,11 @@ class _Compiler(object):
         return getattr(self, 'compile_' + op)(*args)
 
     compile_n = lambda x: 'n'
+    compile_i = lambda x: 'i'
+    compile_v = lambda x: 'v'
+    compile_w = lambda x: 'w'
+    compile_f = lambda x: 'f'
+    compile_t = lambda x: 't'
     compile_value = lambda x, v: str(v)
     compile_and = _binary_compiler('(%s && %s)')
     compile_or = _binary_compiler('(%s || %s)')
@@ -504,18 +511,30 @@ class _GettextCompiler(_Compiler):
 class _JavaScriptCompiler(_GettextCompiler):
     """Compiles the expression to plain of JavaScript."""
 
+    # XXX: presently javascript does not support any of the
+    # fraction support and basically only deals with integers.
+    compile_i = lambda x: 'parseInt(n, 10)'
+    compile_v = lambda x: '0'
+    compile_w = lambda x: '0'
+    compile_f = lambda x: '0'
+    compile_t = lambda x: '0'
+
     def compile_relation(self, method, expr, range_list):
         code = _GettextCompiler.compile_relation(
             self, method, expr, range_list)
         if method == 'in':
             expr = self.compile(expr)
-            code = '(parseInt(%s) == %s && %s)' % (expr, expr, code)
+            code = '(parseInt(%s, 10) == %s && %s)' % (expr, expr, code)
         return code
 
 
 class _UnicodeCompiler(_Compiler):
     """Returns a unicode pluralization rule again."""
 
+    # XXX: this currently spits out the old syntax instead of the new
+    # one.  We can change that, but it will break a whole bunch of stuff
+    # for users I suppose.
+
     compile_is = _binary_compiler('%s is %s')
     compile_isnot = _binary_compiler('%s is not %s')
     compile_and = _binary_compiler('%s and %s')
index 489c0efcb196341e097993be5d9e0089f19fef84..166e2276d78ecbbc20d619dc78d95af3dd9304dc 100644 (file)
@@ -27,6 +27,11 @@ def test_plural_rule():
     assert rule.rules == {'one': 'n is 1'}
 
 
+def test_plural_other_is_ignored():
+    rule = plural.PluralRule({'one': 'n is 1', 'other': '@integer 2'})
+    assert rule(1) == 'one'
+
+
 def test_to_javascript():
     assert (plural.to_javascript({'one': 'n is 1'})
             == "(function(n) { return (n == 1) ? 'one' : 'other'; })")