http://www.mediawiki.org/wiki/Special:Code/pywikipedia/10164
Revision: 10164
Author: xqt
Date: 2012-05-01 15:03:51 +0000 (Tue, 01 May 2012)
Log Message:
-----------
i18n.input() from trunk r10132 and xdict for different families from trunk release
Modified Paths:
--------------
branches/rewrite/pywikibot/i18n.py
Modified: branches/rewrite/pywikibot/i18n.py
===================================================================
--- branches/rewrite/pywikibot/i18n.py 2012-05-01 14:40:41 UTC (rev 10163)
+++ branches/rewrite/pywikibot/i18n.py 2012-05-01 15:03:51 UTC (rev 10164)
@@ -3,7 +3,7 @@
and for TranslateWiki-based translations
"""
#
-# (C) Pywikipedia bot team, 2004-2011
+# (C) Pywikipedia bot team, 2004-2012
#
# Distributed under the terms of the MIT license.
#
@@ -12,6 +12,8 @@
import re
from pywikibot import Error
from plural import plural_rules
+import pywikibot
+import config2 as config
# Languages to use for comment text after the actual language but before
# en:. For example, if for language 'xx', you want the preference of
@@ -128,7 +130,7 @@
if code == 'ltg':
return ['lv']
#Dutch
- if code in ['fy', 'li', 'pap', 'srn', 'vls',
'zea']:
+ if code in ['af', 'fy', 'li', 'pap', 'srn',
'vls', 'zea']:
return ['nl']
if code == ['nds-nl']:
return ['nds', 'nl']
@@ -205,6 +207,8 @@
return ['kj', 'ng']
if code in ['meu', 'hmo']:
return ['meu', 'hmo']
+ if code == ['as']:
+ return ['bn']
#Default value
return []
@@ -222,10 +226,20 @@
list.
"""
+ family = pywikibot.default_family
# If a site is given instead of a code, use its language
if hasattr(code, 'lang'):
+ family = code.family.name
code = code.lang
+ # Check whether xdict has multiple projects
+ if family in xdict:
+ xdict = xdict[family]
+ elif 'wikipedia' in xdict:
+ xdict = xdict['wikipedia']
+ if type(xdict) != dict:
+ return xdict
+
if code in xdict:
return xdict[code]
if not fallback:
@@ -250,8 +264,7 @@
@param code The language code
@param twtitle The TranslateWiki string title, in <package>-<key>
format
- @param parameters For passing parameters. In the future, this will
- be used for plural support.
+ @param parameters For passing parameters.
The translations are retrieved from i18n.<package>, based on the callers
import table.
@@ -304,7 +317,7 @@
@param code The language code
@param twtitle The TranslateWiki string title, in <package>-<key> format
- @param parameters For passing parameters.
+ @param parameters For passing (plural) parameters.
Support is implemented like in MediaWiki extension. If the tw message
contains a plural tag inside which looks like
@@ -406,3 +419,22 @@
if hasattr(code, 'lang'):
code = code.lang
return code in transdict and twtitle in transdict[code]
+
+def input(twtitle, parameters=None, password=False):
+ """ Ask the user a question, return the user's answer.
+ @param twtitle The TranslateWiki string title, in <package>-<key>
format
+ @param parameters For passing parameters. In the future, this will
+ be used for plural support.
+ @param password Hides the user's input (for password entry)
+ Returns a unicode string
+
+ The translations are retrieved from i18n.<package>, based on the callers
+ import table.
+ Translation code should be set by in the user_config.py like
+ userinterface_lang = 'de'
+ default is mylang setting
+
+ """
+ code = config.userinterface_lang or config.mylang
+ trans = twtranslate(code, twtitle, parameters)
+ return pywikibot.input(trans, password)