Xqt has uploaded a new change for review.
https://gerrit.wikimedia.org/r/110671
Change subject: [SYNC] Synchronize with core
......................................................................
[SYNC] Synchronize with core
* [BUGFIX] change site.lang to site.code [1]
* allow empty translations [2]
[1]
The i18n files use WMF language codes instead of ISO 639 language
codes. This means we also have to use these in our translations.
e.g. site code of the Alemannic wikipedia is 'als' whereas the
language code is 'gsw'. The i18n files use 'als', while we now
try to lookup 'gsw', which does not exist.
[2]
Check for 'trans is None' (= no translation found) instead of
for 'not trans' (= no translation found, or empty translation)
Can be relevant for empty configuration variables.
Change-Id: I519eae0c7c87d790c99c0c21658f87aa98409191
---
M pywikibot/i18n.py
1 file changed, 17 insertions(+), 16 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/pywikibot/compat
refs/changes/71/110671/1
diff --git a/pywikibot/i18n.py b/pywikibot/i18n.py
index 8ae944c..b62655d 100644
--- a/pywikibot/i18n.py
+++ b/pywikibot/i18n.py
@@ -1,9 +1,10 @@
# -*- coding: utf-8 -*-
-""" Various i18n functions, both for the internal translation system
- and for TranslateWiki-based translations
+"""
+Various i18n functions, both for the internal translation system
+and for TranslateWiki-based translations
"""
#
-# (C) Pywikipedia bot team, 2004-2013
+# (C) Pywikibot team, 2004-2014
#
# Distributed under the terms of the MIT license.
#
@@ -257,9 +258,9 @@
family = pywikibot.default_family
# If a site is given instead of a code, use its language
- if hasattr(code, 'lang'):
+ if hasattr(code, 'code'):
family = code.family.name
- code = code.lang
+ code = code.code
# Check whether xdict has multiple projects
if type(xdict) == dict:
@@ -337,8 +338,8 @@
code_needed = False
# If a site is given instead of a code, use its language
- if hasattr(code, 'lang'):
- lang = code.lang
+ if hasattr(code, 'code'):
+ lang = code.code
# check whether we need the language code back
elif type(code) == list:
lang = code.pop()
@@ -363,7 +364,7 @@
break
except KeyError:
continue
- if not trans:
+ if trans is None:
raise TranslationError("No English translation has been defined "
"for TranslateWiki key %r" % twtitle)
# send the language code back via the given list
@@ -419,11 +420,11 @@
>>> i18n.twntranslate('en', 'test-changing', {'num':2})
Bot: Changing 2 pages.
#use additional format strings
- >>> i18n.twntranslate('fr', 'test-changing', {'num':1,
'descr':'seulement'})
- Bot: Changer seulement une pages.
+ >>> i18n.twntranslate('fr', 'test-changing', {'num': 1, 'descr':
'seulement'})
+ Robot: Changer seulement une pages.
#use format strings also outside
- >>> i18n.twntranslate('fr', 'test-changing', 0) % {'descr':'seulement'}
- Bot: Changer seulement un peu pages.
+ >>> i18n.twntranslate('fr', 'test-changing', 10) % {'descr': 'seulement'}
+ Robot: Changer seulement un peu pages.
The translations are retrieved from i18n.<package>, based on the callers
import table.
@@ -433,8 +434,8 @@
if type(parameters) == dict:
param = parameters
# If a site is given instead of a code, use its language
- if hasattr(code, 'lang'):
- code = code.lang
+ if hasattr(code, 'code'):
+ code = code.code
# we send the code via list and get the alternate code back
code = [code]
trans = twtranslate(code, twtitle, None)
@@ -492,8 +493,8 @@
package = twtitle.split("-")[0]
transdict = getattr(__import__("i18n", {}, {}, [package]), package).msg
# If a site is given instead of a code, use its language
- if hasattr(code, 'lang'):
- code = code.lang
+ if hasattr(code, 'code'):
+ code = code.code
return code in transdict and twtitle in transdict[code]
--
To view, visit https://gerrit.wikimedia.org/r/110671
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I519eae0c7c87d790c99c0c21658f87aa98409191
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/compat
Gerrit-Branch: master
Gerrit-Owner: Xqt <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits