mirror of https://github.com/django/django.git
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
This commit is contained in:
parent
622a6447f9
commit
eb6a6c4619
|
@ -82,6 +82,17 @@ function interpolate(fmt, obj, named) {
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
PluralIdx = r"""
|
||||||
|
function pluralidx(n) {
|
||||||
|
var v=%s;
|
||||||
|
if (typeof(v) == 'boolean') {
|
||||||
|
return v ? 1 : 0;
|
||||||
|
} else {
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
def null_javascript_catalog(request, domain=None, packages=None):
|
def null_javascript_catalog(request, domain=None, packages=None):
|
||||||
"""
|
"""
|
||||||
Returns "identity" versions of the JavaScript i18n functions -- i.e.,
|
Returns "identity" versions of the JavaScript i18n functions -- i.e.,
|
||||||
|
@ -154,7 +165,7 @@ def javascript_catalog(request, domain='djangojs', packages=None):
|
||||||
# this should actually be a compiled function of a typical plural-form:
|
# this should actually be a compiled function of a typical plural-form:
|
||||||
# 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;
|
# 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;
|
||||||
plural = [el.strip() for el in plural.split(';') if el.strip().startswith('plural=')][0].split('=',1)[1]
|
plural = [el.strip() for el in plural.split(';') if el.strip().startswith('plural=')][0].split('=',1)[1]
|
||||||
src.append('function pluralidx(n) {\n return %s;\n}\n' % plural)
|
src.append(PluralIdx % plural)
|
||||||
else:
|
else:
|
||||||
src.append(SimplePlural)
|
src.append(SimplePlural)
|
||||||
csrc = []
|
csrc = []
|
||||||
|
|
Loading…
Reference in New Issue