Ticket #6864: js-i18n-pluralf.diff

File js-i18n-pluralf.diff, 846 bytes (added by Ramiro Morales, 17 years ago)
  • django/views/i18n.py

    diff -r 983be4e9b98c django/views/i18n.py
    a b def javascript_catalog(request, domain='  
    154154        # this should actually be a compiled function of a typical plural-form:
    155155        # 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;
    156156        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)
     157        src.append("""
     158function pluralidx(n) {
     159  var v=%s;
     160  if (typeof(v) == 'boolean') {
     161    return v ? 1 : 0;
     162  } else {
     163    return v;
     164  }
     165}
     166""" % plural)
    158167    else:
    159168        src.append(SimplePlural)
    160169    csrc = []
Back to Top