XZise has uploaded a new change for review.
https://gerrit.wikimedia.org/r/214428
Change subject: [FIX] i18n: twntranslate gets used code
......................................................................
[FIX] i18n: twntranslate gets used code
It fixes an issue with 5767d73d, that twntranslate didn't get the language code
which was actually used. With fallback=True twtranslate might use another
language than the language given in the first place. To inform twntranslate
about that, twntranslate uses a list which is modified by twtranslate.
But with 5767d73d it always added the same value again so that the list wasn't
chaned at all.
Change-Id: I7228b1ab19510769c876e8943e92dc666c6b2ded
---
M pywikibot/i18n.py
M tests/i18n_tests.py
2 files changed, 22 insertions(+), 2 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core
refs/changes/28/214428/1
diff --git a/pywikibot/i18n.py b/pywikibot/i18n.py
index 67b227f..69549f8 100644
--- a/pywikibot/i18n.py
+++ b/pywikibot/i18n.py
@@ -499,7 +499,7 @@
'Read https://mediawiki.org/wiki/PWB/i18n' % twtitle)
# send the language code back via the given list
if code_needed:
- code.append(lang)
+ code.append(alt)
if parameters:
return trans % parameters
else:
diff --git a/tests/i18n_tests.py b/tests/i18n_tests.py
index 0634181..897e2e2 100644
--- a/tests/i18n_tests.py
+++ b/tests/i18n_tests.py
@@ -13,7 +13,7 @@
import pywikibot
-from pywikibot import i18n, bot
+from pywikibot import i18n, bot, plural
from tests.aspects import unittest, TestCase, DefaultSiteTestCase, PwbTestCase
@@ -311,6 +311,26 @@
% {'action': u'Ändere'},
u'Bot: Ändere 1 Zeile von einer Seite.')
+ def test_fallback_lang(self):
+ """
+ Test that twntranslate uses the translation's language.
+
+ twntranslate calls _twtranslate which might return the translation for
+ a different language and then the plural rules from that language need
+ to be applied.
+ """
+ # co has fr as altlang but has no plural rules defined (otherwise this
+ # test might not catch problems) so it's using the plural variant for 0
+ # although French uses the plural variant for numbers > 1 (so not 0)
+ assert('co' not in plural.plural_rules)
+ assert(plural.plural_rules['fr']['plural'](0) is False)
+ self.assertEqual(
+ i18n.twntranslate('co', 'test-plural', {'num': 0, 'descr':
'seulement'}),
+ u'Robot: Changer seulement une page.')
+ self.assertEqual(
+ i18n.twntranslate('co', 'test-plural', {'num': 1, 'descr':
'seulement'}),
+ u'Robot: Changer seulement une page.')
+
class ScriptMessagesTestCase(TWNTestCaseBase):
--
To view, visit https://gerrit.wikimedia.org/r/214428
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I7228b1ab19510769c876e8943e92dc666c6b2ded
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: XZise <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits