Revision: 4008
Author: valhallasw
Date: 2007-08-08 14:55:17 +0000 (Wed, 08 Aug 2007)
Log Message:
-----------
+input_choice_proposal for wikipedian et al
Added Paths:
-----------
branches/pywikipedia/i18n/input_choice_proposal/
branches/pywikipedia/i18n/input_choice_proposal/ic.py
branches/pywikipedia/i18n/input_choice_proposal/messages.mo
branches/pywikipedia/i18n/input_choice_proposal/messages.po
Added: branches/pywikipedia/i18n/input_choice_proposal/ic.py
===================================================================
--- branches/pywikipedia/i18n/input_choice_proposal/ic.py (rev 0)
+++ branches/pywikipedia/i18n/input_choice_proposal/ic.py 2007-08-08 14:55:17 UTC (rev 4008)
@@ -0,0 +1,58 @@
+import sys
+sys.path.append('../pywikipedia')
+import wikipedia
+ui = wikipedia.ui
+
+from gettext import GNUTranslations
+cat = GNUTranslations(file('messages.mo'))
+
+def i18nChoice(question, answerstring, default = None):
+ """
+ Asks the user a question and offers several options, then returns the
+ user's choice. The user's input will be case-insensitive, so the hotkeys
+ should be distinctive case-insensitively.
+
+ Parameters:
+ * question - a unicode string that will be shown to the user. Don't add a
+ space after the question mark, this method will do this
+ for you.
+ * answers - a list of strings that represent the options.
+ * hotkeys - a list of one-letter strings, one for each answer.
+ * default - an element of hotkeys, or None. The default choice that will
+ be returned when the user just presses Enter.
+
+ Returns a one-letter string in lowercase.
+ """
+
+ # first translate question and answers
+ origQ = question
+ try:
+ transQ = cat._catalog[(question, 0)]
+ except KeyError:
+ transQ = question
+
+ exec('origA = %s' % answerstring, locals(), globals())
+ try:
+ exec('transA = %s' % cat._catalog[(question, 1)], locals(), globals())
+ except KeyError:
+ exec('transA = %s' % answerstring, locals(), globals())
+
+ # get translated answers and hotkeys
+ (answers, hotkeys) = zip(*transA)
+
+ # map translated key to untranslated text
+ keymap = {}
+ for orig, trans in zip(origA, transA):
+ keymap[trans[1].lower()] = orig[0]
+ if orig[0] == default:
+ defaultkey = trans[1]
+
+ answers = list(answers)
+ data = ui.inputChoice(transQ, answers, hotkeys, defaultkey).lower()
+
+ try:
+ return keymap[data]
+ except KeyError:
+ return None
+
+print i18nChoice("Do you want to save?", "[('yes', 'y'), ('no', 'n')]", 'yes')
\ No newline at end of file
Property changes on: branches/pywikipedia/i18n/input_choice_proposal/ic.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: branches/pywikipedia/i18n/input_choice_proposal/messages.mo
===================================================================
(Binary files differ)
Property changes on: branches/pywikipedia/i18n/input_choice_proposal/messages.mo
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Name: svn:keywords
+ Id
Added: branches/pywikipedia/i18n/input_choice_proposal/messages.po
===================================================================
--- branches/pywikipedia/i18n/input_choice_proposal/messages.po (rev 0)
+++ branches/pywikipedia/i18n/input_choice_proposal/messages.po 2007-08-08 14:55:17 UTC (rev 4008)
@@ -0,0 +1,23 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2007-08-08 16:50+0200\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL(a)li.org>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=utf-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#: ic.py:60
+msgid "Do you want to save?"
+msgid_plural "[('yes', 'y'), ('no', 'n')]"
+msgstr[0] "Wilt u opslaan?"
+msgstr[1] "[('ja', 'j'), ('nee', 'n')]"
Property changes on: branches/pywikipedia/i18n/input_choice_proposal/messages.po
___________________________________________________________________
Name: svn:keywords
+ Id