http://www.mediawiki.org/wiki/Special:Code/pywikipedia/10431
Revision: 10431
Author: xqt
Date: 2012-06-30 15:47:10 +0000 (Sat, 30 Jun 2012)
Log Message:
-----------
fix for non plural languages when plural_rules returns just 0
Modified Paths:
--------------
branches/rewrite/pywikibot/i18n.py
Modified: branches/rewrite/pywikibot/i18n.py
===================================================================
--- branches/rewrite/pywikibot/i18n.py 2012-06-30 11:11:05 UTC (rev 10430)
+++ branches/rewrite/pywikibot/i18n.py 2012-06-30 15:47:10 UTC (rev 10431)
@@ -389,12 +389,15 @@
lang = code.pop()
# we only need the lang or _default, not a _altlang code
# maybe we should implement this to i18n.translate()
+ # TODO: check against plural_rules[lang]['nplurals']
try:
- plural_func = plural_rules[lang]['plural']
+ index = plural_rules[lang]['plural'](num)
except KeyError:
- plural_func = plural_rules['_default']['plural']
- # TODO: check against plural_rules[lang]['nplurals']
- repl = variants.split('|')[plural_func(num)]
+ index = plural_rules['_default']['plural'](num)
+ except TypeError:
+ # we got an int
+ index = plural_rules[lang]['plural']
+ repl = variants.split('|')[index]
trans = re.sub(PATTERN, repl, trans)
if param:
try: