Revision: 4374
Author: huji
Date: 2007-09-28 18:51:41 +0000 (Fri, 28 Sep 2007)
Log Message:
-----------
*Updating the translate() function, to work with a nested dictionary of messages.
*Updating basic.py file accordingly.
*This version is NOT a working version.
*The rest of modules should also be updated according to the changes in wikipedia.py
Modified Paths:
--------------
branches/pywikipedia/messages/basic.py
branches/pywikipedia/messages/wikipedia.py
Modified: branches/pywikipedia/messages/basic.py
===================================================================
--- branches/pywikipedia/messages/basic.py 2007-09-28 11:38:13 UTC (rev 4373)
+++ branches/pywikipedia/messages/basic.py 2007-09-28 18:51:41 UTC (rev 4374)
@@ -29,10 +29,6 @@
class BasicBot:
# Edit summary message that should be used.
# NOTE: Put a good description here, and add translations, if possible!
- msg = {
- 'de': u'Bot: Ändere ...',
- 'en': u'Robot: changing ...',
- }
def __init__(self, generator, debug):
"""
@@ -47,7 +43,7 @@
def run(self):
# Set the edit summary message
- wikipedia.setAction(wikipedia.translate(wikipedia.getSite(), self.msg))
+ wikipedia.setAction(wikipedia.translate(wikipedia.getSite(), 'test'))
for page in self.generator:
self.treat(page)
Modified: branches/pywikipedia/messages/wikipedia.py
===================================================================
--- branches/pywikipedia/messages/wikipedia.py 2007-09-28 11:38:13 UTC (rev 4373)
+++ branches/pywikipedia/messages/wikipedia.py 2007-09-28 18:51:41 UTC (rev 4374)
@@ -4635,12 +4635,12 @@
return []
-def translate(code, dict):
+def translate(code, msg):
"""
- Given a language code and a dictionary, returns the dictionary's value for
- key 'code' if this key exists; otherwise tries to return a value for an
- alternative language that is most applicable to use on the Wikipedia in
- language 'code'.
+ Given a language code and a message name, it returns the value appropriate
+ edit comment, according to message dictionary in message.py, if this key
+ exists; otherwise tries to return a value for an alternative language that
+ is most applicable to use on the Wikipedia in language 'code'.
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 first language in the
@@ -4650,15 +4650,26 @@
if hasattr(code,'lang'):
code = code.lang
- if dict.has_key(code):
- return dict[code]
+ #TEMP: Defined messages temporarily here
+ messages = {'en' : {'test' : u'Test message'}, 'test' : {'test' : u'Maesagi testi'}}
+
+ if messages.has_key(code):
+ dict = messages[code]
+ if dict.has_key(msg):
+ return dict[msg]
for alt in altlang(code):
- if dict.has_key(alt):
- return dict[alt]
- if dict.has_key('en'):
- return dict['en']
+ if messages.has_key(alt):
+ dict = messages[alt]
+ if dict.has_key(msg):
+ return dict[msg]
+ if messages.has_key('en'):
+ dict = messages['en']
+ if dict.has_key(msg):
+ return dict[msg]
+ dict = messages.values()[0]
return dict.values()[0]
+
def showDiff(oldtext, newtext):
"""
Prints a string showing the differences between oldtext and newtext.