jenkins-bot has submitted this change and it was merged.
Change subject: Revert "[FIX] welcome: Fallback for i18n translate" ......................................................................
Revert "[FIX] welcome: Fallback for i18n translate"
revert due to bug T79291
This reverts commit 65518573d2b07c7b807fd890b0e18613e885ecbe.
Change-Id: I0e8a1f3a2b27a3af6e473a021df84d41779fad02 --- M pywikibot/i18n.py M scripts/welcome.py 2 files changed, 15 insertions(+), 28 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/i18n.py b/pywikibot/i18n.py index 06c4049..2fff519 100644 --- a/pywikibot/i18n.py +++ b/pywikibot/i18n.py @@ -365,9 +365,6 @@ return message
-DEFAULT_FALLBACK = ('_default', ) - - def translate(code, xdict, parameters=None, fallback=False): """Return the most appropriate translation from a translation dict.
@@ -378,9 +375,8 @@
The language itself is always checked first, then languages that have been defined to be alternatives, and finally English. If none of - the options gives result, we just take the one language from xdict which may - not be always the same. When fallback is iterable it'll return None if no - code applies (instead of returning one). + the options gives result, we just take the first language in the + list.
For PLURAL support have a look at the twntranslate method
@@ -393,9 +389,9 @@ @type xdict: dict, string, unicode @param parameters: For passing (plural) parameters @type parameters: dict, string, unicode, int - @param fallback: Try an alternate language code. If it's iterable it'll - also try those entries and choose the first match. - @type fallback: boolean or iterable + @param fallback: Try an alternate language code + @type fallback: boolean + """ family = pywikibot.config.family # If a site is given instead of a code, use its language @@ -411,28 +407,20 @@ xdict = xdict['wikipedia']
# Get the translated string + trans = None if not isinstance(xdict, dict): trans = xdict - elif not xdict: - trans = None - else: - codes = [code] - if fallback is True: - codes += _altlang(code) + ['_default', 'en'] - elif fallback is not False: - codes += list(fallback) - for code in codes: - if code in xdict: - trans = xdict[code] + elif code in xdict: + trans = xdict[code] + elif fallback: + for alt in _altlang(code) + ['_default', 'en']: + if alt in xdict: + trans = xdict[alt] + code = alt break else: - if fallback is not False and fallback is not True: - # future versions shouldn't simply return "any one" code but - # no translation as this is not very deterministic. When - # fallback is iterable it's a new mode previously not supported - return + trans = list(xdict.values())[0] code = list(xdict.keys())[0] - trans = xdict[code] if trans is None: return # return None if we have no translation found if parameters is None: diff --git a/scripts/welcome.py b/scripts/welcome.py index cefbf93..65d0e67 100755 --- a/scripts/welcome.py +++ b/scripts/welcome.py @@ -658,8 +658,7 @@ showStatus() pywikibot.output( 'Log page is not exist, getting information for page creation') - text = i18n.translate(self.site, logpage_header, - fallback=i18n.DEFAULT_FALLBACK) + text = i18n.translate(self.site, logpage_header) text += u'\n!%s' % self.site.namespace(2) text += u'\n!%s' % str.capitalize( self.site.mediawiki_message('contribslink'))