jenkins-bot has submitted this change and it was merged.
Change subject: use a "while" loop to allow multiple "{{PLURAL}}" paths to work
correctly within "translate"
......................................................................
use a "while" loop to allow multiple "{{PLURAL}}" paths to work correctly
within "translate"
With the previous code, the result of the first occurrence of "{{PLURAL}}" was
used
as replacement for all occurrences; a one-by-one regex replacement solves the
issue.
Change-Id: I3c6e28316f7ca667ba9a3e95332301520b86dd97
---
M pywikibot/i18n.py
1 file changed, 20 insertions(+), 19 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/i18n.py b/pywikibot/i18n.py
index 56fb9da..8e93f89 100644
--- a/pywikibot/i18n.py
+++ b/pywikibot/i18n.py
@@ -291,26 +291,27 @@
return trans
# else we check for PLURAL variants
- try:
- selector, variants = re.search(PLURAL_PATTERN, trans).groups()
- except AttributeError:
- pass
- else: # we found PLURAL patterns, process it
- if type(parameters) == dict:
- num = param[selector]
- elif isinstance(parameters, basestring):
- num = int(parameters)
- else:
- num = parameters
- # TODO: check against plural_rules[lang]['nplurals']
+ while re.search(PLURAL_PATTERN, trans):
try:
- index = plural_rules[code]['plural'](num)
- except KeyError:
- index = plural_rules['_default']['plural'](num)
- except TypeError:
- # we got an int, not a function
- index = plural_rules[code]['plural']
- trans = re.sub(PLURAL_PATTERN, variants.split('|')[index], trans)
+ selector, variants = re.search(PLURAL_PATTERN, trans).groups()
+ except AttributeError:
+ pass
+ else: # we found PLURAL patterns, process it
+ if type(parameters) == dict:
+ num = param[selector]
+ elif isinstance(parameters, basestring):
+ num = int(parameters)
+ else:
+ num = parameters
+ # TODO: check against plural_rules[lang]['nplurals']
+ try:
+ index = plural_rules[code]['plural'](num)
+ except KeyError:
+ index = plural_rules['_default']['plural'](num)
+ except TypeError:
+ # we got an int, not a function
+ index = plural_rules[code]['plural']
+ trans = re.sub(PLURAL_PATTERN, variants.split('|')[index], trans,
count=1)
if param:
try:
return trans % param
--
To view, visit https://gerrit.wikimedia.org/r/80698
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I3c6e28316f7ca667ba9a3e95332301520b86dd97
Gerrit-PatchSet: 6
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Ricordisamoa <[email protected]>
Gerrit-Reviewer: Ladsgroup <[email protected]>
Gerrit-Reviewer: Merlijn van Deen <[email protected]>
Gerrit-Reviewer: Ricordisamoa <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
Pywikibot-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits