1 # -*- coding: utf-8 -*-
6 Plural form definitions.
8 :copyright: (c) 2013 by the Babel Team.
9 :license: BSD, see LICENSE for more details.
12 from babel.core import default_locale, Locale
13 from operator import itemgetter
16 # XXX: remove this file, duplication with babel.plural
19 LC_CTYPE = default_locale('LC_CTYPE')
29 # Afrikaans - From Pootle's PO's
30 'af': (2, '(n != 1)'),
37 # Arabic - From Pootle's PO's
38 'ar': (6, '(n==0 ? 0 : n==1 ? 1 : n==2 ? 2 : n>=3 && n<=10 ? 3 : n>=11 && n<=99 ? 4 : 5)'),
51 # Bulgarian - From Pootle's PO's
52 'bg': (2, '(n != 1)'),
59 # Bengali - From Pootle's PO's
60 'bn': (2, '(n != 1)'),
61 # Tibetan - as discussed in private with Andrew West
67 # Catalan - From Pootle's PO's
68 'ca': (2, '(n != 1)'),
78 'cs': (3, '(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2)'),
84 'cy': (5, '(n==1 ? 1 : n==2 ? 2 : n==3 ? 3 : n==6 ? 4 : 0)'),
86 'da': (2, '(n != 1)'),
88 'de': (2, '(n != 1)'),
94 'el': (2, '(n != 1)'),
96 'en': (2, '(n != 1)'),
98 'eo': (2, '(n != 1)'),
100 'es': (2, '(n != 1)'),
102 'et': (2, '(n != 1)'),
103 # Basque - From Pootle's PO's
104 'eu': (2, '(n != 1)'),
105 # Persian - From Pootle's PO's
108 'fi': (2, '(n != 1)'),
110 'fr': (2, '(n > 1)'),
111 # Friulian - From Pootle's PO's
112 'fur': (2, '(n > 1)'),
114 'ga': (3, '(n==1 ? 0 : n==2 ? 1 : 2)'),
115 # Galician - From Pootle's PO's
116 'gl': (2, '(n != 1)'),
117 # Hausa - From Pootle's PO's
118 'ha': (2, '(n != 1)'),
120 'he': (2, '(n != 1)'),
121 # Hindi - From Pootle's PO's
122 'hi': (2, '(n != 1)'),
124 'hr': (3, '(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2)'),
127 # Armenian - From Pootle's PO's
129 # Icelandic - From Pootle's PO's
130 'is': (2, '(n != 1)'),
132 'it': (2, '(n != 1)'),
135 # Georgian - From Pootle's PO's
137 # Kongo - From Pootle's PO's
138 'kg': (2, '(n != 1)'),
139 # Khmer - From Pootle's PO's
143 # Kurdish - From Pootle's PO's
144 'ku': (2, '(n != 1)'),
145 # Lao - Another member of the Tai language family, like Thai.
148 'lt': (3, '(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2)'),
150 'lv': (3, '(n%10==1 && n%100!=11 ? 0 : n != 0 ? 1 : 2)'),
151 # Maltese - From Pootle's PO's
152 'mt': (4, '(n==1 ? 0 : n==0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3)'),
154 'nb': (2, '(n != 1)'),
156 'nl': (2, '(n != 1)'),
158 'nn': (2, '(n != 1)'),
160 'no': (2, '(n != 1)'),
161 # Punjabi - From Pootle's PO's
162 'pa': (2, '(n != 1)'),
164 'pl': (3, '(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2)'),
166 'pt': (2, '(n != 1)'),
168 'pt_BR': (2, '(n > 1)'),
169 # Romanian - From Pootle's PO's
170 'ro': (3, '(n==1 ? 0 : (n==0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2)'),
172 'ru': (3, '(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2)'),
174 'sk': (3, '(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2)'),
176 'sl': (4, '(n%100==1 ? 0 : n%100==2 ? 1 : n%100==3 || n%100==4 ? 2 : 3)'),
177 # Serbian - From Pootle's PO's
178 'sr': (3, '(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2)'),
179 # Southern Sotho - From Pootle's PO's
180 'st': (2, '(n != 1)'),
182 'sv': (2, '(n != 1)'),
188 'uk': (3, '(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2)'),
189 # Venda - From Pootle's PO's
190 've': (2, '(n != 1)'),
191 # Vietnamese - From Pootle's PO's
193 # Xhosa - From Pootle's PO's
194 'xh': (2, '(n != 1)'),
195 # Chinese - From Pootle's PO's (modified)
200 DEFAULT_PLURAL = (2, '(n != 1)')
203 class _PluralTuple(tuple):
204 """A tuple with plural information."""
207 num_plurals = property(itemgetter(0), doc="""
208 The number of plurals used by the locale.""")
209 plural_expr = property(itemgetter(1), doc="""
210 The plural expression used by the locale.""")
211 plural_forms = property(lambda x: 'nplurals=%s; plural=%s;' % x, doc="""
212 The plural expression used by the catalog or locale.""")
215 return self.plural_forms
218 def get_plural(locale=LC_CTYPE):
219 """A tuple with the information catalogs need to perform proper
220 pluralization. The first item of the tuple is the number of plural
221 forms, the second the plural expression.
223 >>> get_plural(locale='en')
225 >>> get_plural(locale='ga')
226 (3, '(n==1 ? 0 : n==2 ? 1 : 2)')
228 The object returned is a special tuple with additional members:
230 >>> tup = get_plural("ja")
236 'nplurals=1; plural=0;'
238 Converting the tuple into a string prints the plural forms for a
242 'nplurals=1; plural=0;'
244 locale = Locale.parse(locale)
246 tup = PLURALS[str(locale)]
249 tup = PLURALS[locale.language]
252 return _PluralTuple(tup)