http://www.mediawiki.org/wiki/Special:Code/pywikipedia/8858
Revision: 8858 Author: xqt Date: 2011-01-18 09:54:40 +0000 (Tue, 18 Jan 2011) Log Message: ----------- define twhas_key to check whether a specified translation is provided (needed for redirect.py for example)
Modified Paths: -------------- branches/rewrite/pywikibot/i18n.py
Modified: branches/rewrite/pywikibot/i18n.py =================================================================== --- branches/rewrite/pywikibot/i18n.py 2011-01-18 09:45:40 UTC (rev 8857) +++ branches/rewrite/pywikibot/i18n.py 2011-01-18 09:54:40 UTC (rev 8858) @@ -239,3 +239,17 @@ return trans % parameters else: return trans + +def twhas_key(code, twtitle): + """ Uses TranslateWiki files to to check whether specified translation + based on the TW title is provided. No code fallback is made. + + @param code The language code + @param twtitle 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 + return code in transdict and twtitle in transdict[code]
pywikipedia-svn@lists.wikimedia.org