http://www.mediawiki.org/wiki/Special:Code/pywikipedia/10132
Revision: 10132
Author: xqt
Date: 2012-04-18 14:04:17 +0000 (Wed, 18 Apr 2012)
Log Message:
-----------
First step for twn support for userinterface. This supports input questions by replacing pywikibot.input() by i18n.input(). Notify the parameters.
Modified Paths:
--------------
trunk/pywikipedia/pywikibot/i18n.py
Modified: trunk/pywikipedia/pywikibot/i18n.py
===================================================================
--- trunk/pywikipedia/pywikibot/i18n.py 2012-04-18 13:04:29 UTC (rev 10131)
+++ trunk/pywikipedia/pywikibot/i18n.py 2012-04-18 14:04:17 UTC (rev 10132)
@@ -12,6 +12,7 @@
import re, sys
from pywikibot import Error
import wikipedia as pywikibot
+import 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
@@ -423,3 +424,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)
http://www.mediawiki.org/wiki/Special:Code/pywikipedia/10131
Revision: 10131
Author: xqt
Date: 2012-04-18 13:04:29 +0000 (Wed, 18 Apr 2012)
Log Message:
-----------
minor doc changes
Modified Paths:
--------------
trunk/pywikipedia/pywikibot/i18n.py
Modified: trunk/pywikipedia/pywikibot/i18n.py
===================================================================
--- trunk/pywikipedia/pywikibot/i18n.py 2012-04-18 09:22:25 UTC (rev 10130)
+++ trunk/pywikipedia/pywikibot/i18n.py 2012-04-18 13:04:29 UTC (rev 10131)
@@ -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.
#
@@ -262,8 +262,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.
@@ -316,7 +315,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
http://www.mediawiki.org/wiki/Special:Code/pywikipedia/10126
Revision: 10126
Author: xqt
Date: 2012-04-17 18:13:05 +0000 (Tue, 17 Apr 2012)
Log Message:
-----------
enable withSection parameter for Page.title()
Modified Paths:
--------------
trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/wikipedia.py
===================================================================
--- trunk/pywikipedia/wikipedia.py 2012-04-17 15:32:32 UTC (rev 10125)
+++ trunk/pywikipedia/wikipedia.py 2012-04-17 18:13:05 UTC (rev 10126)
@@ -453,7 +453,7 @@
@param underscore: if true, replace all ' ' characters with '_'
@param withNamespace: if false, omit the namespace prefix
- @param withSection: - not implemented yet -
+ @param withSection: if false, omit the section
@param asUrl: - not implemented yet -
@param asLink: if true, return the title in the form of a wikilink
@param allowInterwiki: (only used if asLink is true) if true, format
@@ -486,7 +486,7 @@
else:
title = u'[[%s%s:%s]]' % (colon, self._site.lang, title)
elif textlink and (self.isImage() or self.isCategory()):
- title = u'[[:%s]]' % title
+ title = u'[[:%s]]' % title
else:
title = u'[[%s]]' % title
if savetitle or asLink:
@@ -494,6 +494,10 @@
title = title.replace(u"''", u'%27%27')
if underscore:
title = title.replace(' ', '_')
+ if not withSection:
+ sectionName = self.section(underscore=underscore)
+ if sectionName:
+ title = title[:-len(sectionName)-1]
return title
#@deprecated("Page.title(withNamespace=False)")