mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-26 20:59:27 +01:00
Change translate to use the (limited) translatable language list.
This commit is contained in:
parent
1fbf61c571
commit
88ca711d6a
@ -212,6 +212,16 @@ class Google(callbacks.PluginRegexp):
|
||||
irc.reply(s)
|
||||
|
||||
_gtranslateUrl='http://ajax.googleapis.com/ajax/services/language/translate'
|
||||
_transLangs = {'Arabic': 'ar', 'Bulgarian': 'bg',
|
||||
'Chinese_simplified': 'zh-CN',
|
||||
'Chinese_traditional': 'zh-TW', 'Croatian': 'hr',
|
||||
'Czech': 'cs', 'Danish': 'da', 'Dutch': 'nl',
|
||||
'English': 'en', 'Finnish': 'fi', 'French': 'fr',
|
||||
'German': 'de', 'Greek': 'el', 'Hindi': 'hi',
|
||||
'Italian': 'it', 'Japanese': 'ja', 'Korean': 'ko',
|
||||
'Norwegian': 'no', 'Polish': 'pl', 'Portuguese': 'pt',
|
||||
'Romanian': 'ro', 'Russian': 'ru', 'Spanish': 'es',
|
||||
'Swedish': 'sv'}
|
||||
def translate(self, irc, msg, args, fromLang, toLang, text):
|
||||
"""<from-language> [to] <to-language> <text>
|
||||
|
||||
@ -227,12 +237,25 @@ class Google(callbacks.PluginRegexp):
|
||||
headers = utils.web.defaultHeaders
|
||||
headers['Referer'] = ref
|
||||
opts = {'q': text, 'v': '1.0'}
|
||||
if 'lang_%s' % fromLang.lower() not in \
|
||||
conf.supybot.plugins.Google.defaultLanguage.validStrings:
|
||||
irc.errorInvalid('from language')
|
||||
if 'lang_%s' % toLang.lower() not in \
|
||||
conf.supybot.plugins.Google.defaultLanguage.validStrings:
|
||||
irc.errorInvalid('to language')
|
||||
lang = conf.supybot.plugins.Google.defaultLanguage
|
||||
if fromLang.capitalize() in self._transLangs:
|
||||
fromLang = self._transLangs[fromLang.capitalize()]
|
||||
elif lang.normalize('lang_'+fromLang)[5:] \
|
||||
not in self._transLangs.values():
|
||||
irc.errorInvalid('from language', fromLang,
|
||||
format('Valid languages are: %L',
|
||||
self._transLangs.keys()))
|
||||
else:
|
||||
fromLang = lang.normalize('lang_'+fromLang)[5:]
|
||||
if toLang.capitalize() in self._transLangs:
|
||||
toLang = self._transLangs[toLang.capitalize()]
|
||||
elif lang.normalize('lang_'+toLang)[5:] \
|
||||
not in self._transLangs.values():
|
||||
irc.errorInvalid('to language', toLang,
|
||||
format('Valid languages are: %L',
|
||||
self._transLangs.keys()))
|
||||
else:
|
||||
toLang = lang.normalize('lang_'+toLang)[5:]
|
||||
opts['langpair'] = '%s|%s' % (fromLang, toLang)
|
||||
fd = utils.web.getUrlFd('%s?%s' % (self._gtranslateUrl,
|
||||
urllib.urlencode(opts)),
|
||||
|
Loading…
Reference in New Issue
Block a user