Ticket #11161: django-1.0.2-plural.patch

File django-1.0.2-plural.patch, 4.1 KB (added by daniels, 6 years ago)
  • django/conf/global_settings.py

    diff -ruN Django-1.0.2-final.orig/django/conf/global_settings.py Django-1.0.2-final/django/conf/global_settings.py
    old new  
    9797# Languages using BiDi (right-to-left) layout
    9898LANGUAGES_BIDI = ("he", "ar", "fa")
    9999
     100# Languages plural forms
     101# From http://www.gnu.org/software/gettext/manual/gettext.html#Plural-forms
     102LANGUAGES_PLURAL = {
     103    # Only one form
     104    'ja': 'nplurals=1; plural=0;',
     105    'ko': 'nplurals=1; plural=0;',
     106    # Two forms, singular used for one only
     107    'da': 'nplurals=2; plural=n != 1;',
     108    'de': 'nplurals=2; plural=n != 1;',
     109    'en': 'nplurals=2; plural=n != 1;',
     110    'es': 'nplurals=2; plural=n != 1;',
     111    'es-ar': 'nplurals=2; plural=n != 1;',
     112    'et': 'nplurals=2; plural=n != 1;',
     113    'fi': 'nplurals=2; plural=n != 1;',
     114    'gr': 'nplurals=2; plural=n != 1;',
     115    'he': 'nplurals=2; plural=n != 1;',
     116    'hu': 'nplurals=2; plural=n != 1;',
     117    'it': 'nplurals=2; plural=n != 1;',
     118    'nl': 'nplurals=2; plural=n != 1;',
     119    'no': 'nplurals=2; plural=n != 1;',
     120    'pt': 'nplurals=2; plural=n != 1;',
     121    'sv': 'nplurals=2; plural=n != 1;',
     122    # Two forms, singular used for zero and one
     123    'fr': 'nplurals=2; plural=n>1;',
     124    'pt-br': 'nplurals=2; plural=n>1;',
     125    # Three forms, special case for zero
     126    'lv': 'nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n != 0 ? 1 : 2;',
     127    # Three forms, special cases for one and two
     128    'ga': 'nplurals=3; plural=n==1 ? 0 : n==2 ? 1 : 2;',
     129    # Three forms, special case for numbers ending in 00 or [2-9][0-9]
     130    'ro': 'nplurals=3; plural=n==1 ? 0 : (n==0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2;',
     131    # Three forms, special case for numbers ending in 1[2-9]
     132    'lt': 'nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2;',
     133    # Three forms, special cases for numbers ending in 1 and 2, 3, 4, except those ending in 1[1-4]
     134    'hr': 'nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;',
     135    'ru': 'nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;',
     136    'sr': 'nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;',
     137    'uk': 'nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;',
     138    # Three forms, special cases for 1 and 2, 3, 4
     139    'cs': 'nplurals=3; plural=(n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2;',
     140    'sk': 'nplurals=3; plural=(n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2;',
     141    # Three forms, special case for one and some numbers ending in 2, 3, or 4
     142    'pl': 'nplurals=3; plural=n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;',
     143    # Four forms, special case for one and all numbers ending in 02, 03, or 04
     144    'sl': 'nplurals=4; plural=n%100==1 ? 0 : n%100==2 ? 1 : n%100==3 || n%100==4 ? 2 : 3;',
     145}
     146
    100147# If you set this to False, Django will make some optimizations so as not
    101148# to load the internationalization machinery.
    102149USE_I18N = True
  • django/utils/translation/trans_real.py

    diff -ruN Django-1.0.2-final.orig/django/utils/translation/trans_real.py Django-1.0.2-final/django/utils/translation/trans_real.py
    old new  
    7676    def set_language(self, language):
    7777        self.__language = language
    7878
     79    def set_plural(self, plural_expression):
     80        v = plural_expression.split(';')
     81        plural = v[1].split('plural=')[1]
     82        self.plural = gettext_module.c2py(plural)
     83
    7984    def language(self):
    8085        return self.__language
    8186
     
    144149            try:
    145150                t = gettext_module.translation('django', path, [loc], klass)
    146151                t.set_language(lang)
     152                if lang in settings.LANGUAGES_PLURAL:
     153                    t.set_plural(settings.LANGUAGES_PLURAL[lang])
    147154                return t
    148155            except IOError, e:
    149156                return None
Back to Top