Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #6864 -- Handle Javascript i18n when the plural form expression…

… returns

True or False (so both booleans and integers are allowed). Thanks, Ramiro Morales.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@7356 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit eb6a6c46199bb8c9b5931d1ed7103677f78b2dbd 1 parent 622a644
Malcolm Tredinnick authored

Showing 1 changed file with 12 additions and 1 deletion. Show diff stats Hide diff stats

  1. 13  django/views/i18n.py
13  django/views/i18n.py
@@ -82,6 +82,17 @@ def set_language(request):
82 82
 }
83 83
 """
84 84
 
  85
+PluralIdx = r"""
  86
+function pluralidx(n) {
  87
+  var v=%s;
  88
+  if (typeof(v) == 'boolean') {
  89
+    return v ? 1 : 0;
  90
+  } else {
  91
+    return v;
  92
+  }
  93
+}
  94
+"""
  95
+
85 96
 def null_javascript_catalog(request, domain=None, packages=None):
86 97
     """
87 98
     Returns "identity" versions of the JavaScript i18n functions -- i.e.,
@@ -154,7 +165,7 @@ def javascript_catalog(request, domain='djangojs', packages=None):
154 165
         # this should actually be a compiled function of a typical plural-form:
155 166
         # Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;
156 167
         plural = [el.strip() for el in plural.split(';') if el.strip().startswith('plural=')][0].split('=',1)[1]
157  
-        src.append('function pluralidx(n) {\n    return %s;\n}\n' % plural)
  168
+        src.append(PluralIdx % plural)
158 169
     else:
159 170
         src.append(SimplePlural)
160 171
     csrc = []

0 notes on commit eb6a6c4

Please sign in to comment.
Something went wrong with that request. Please try again.