Revision: 8834
Author:   valhallasw
Date:     2011-01-15 18:11:55 +0000 (Sat, 15 Jan 2011)
Log Message:
-----------
Added function to read TranslateWiki translations from i18n/* files.

Created during the Amsterdam Hackathon

Modified Paths:
--------------
    branches/rewrite/pywikibot/i18n.py

Modified: branches/rewrite/pywikibot/i18n.py
===================================================================
--- branches/rewrite/pywikibot/i18n.py  2011-01-15 18:11:50 UTC (rev 8833)
+++ branches/rewrite/pywikibot/i18n.py  2011-01-15 18:11:55 UTC (rev 8834)
@@ -185,3 +185,21 @@
         return xdict['en']
     return xdict.values()[0]
 
+def twtranslate(code, twtitle, parameters=None):
+    """ Uses TranslateWiki files to provide translations based on the TW title
+        twtitle, which corresponds to a page on TW.
+
+        @param parameters is for future addition of plural support
+        @param twtitle is the TranslateWiki string title, in <package>-<key> 
format
+
+        The translations are retrieved from i18n.<package>, based on the 
callers
+        import table.
+    """
+    package = twtitle.split("-")[0]
+    transdict = getattr(__import__("i18n", fromlist=[package]), package).msg
+    trans = translate(code, transdict)[twtitle]
+
+    if parameters:
+        return trans % parameters
+    else:
+        return trans


_______________________________________________
Pywikipedia-svn mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikipedia-svn

Reply via email to