mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-23 11:12:47 +01:00
Google: Keep the list of supported languages in one place.
Signed-off-by: James Vega <jamessan@users.sourceforge.net>
This commit is contained in:
parent
874508867f
commit
461f943d97
@ -1,6 +1,6 @@
|
||||
###
|
||||
# Copyright (c) 2005, Jeremiah Fincher
|
||||
# Copyright (c) 2008, James Vega
|
||||
# Copyright (c) 2008-2009, James Vega
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
@ -48,15 +48,41 @@ def configure(advanced):
|
||||
conf.supybot.plugins.Google.searchSnarfer.setValue(True)
|
||||
|
||||
class Language(registry.OnlySomeStrings):
|
||||
validStrings = ['lang_' + s for s in 'ar bg ca zh-CN zh-TW hr cs da nl en '
|
||||
'et fi fr de el iw hu is id it ja ko '
|
||||
'lv lt no pl pt ro ru sr sk sl es sv '
|
||||
'tr'.split()]
|
||||
transLangs = {'Afrikaans': 'af', 'Albanian': 'sq', 'Amharic': 'am',
|
||||
'Arabic': 'ar', 'Armenian': 'hy', 'Azerbaijani': 'az',
|
||||
'Basque': 'eu', 'Belarusian': 'be', 'Bengali': 'bn',
|
||||
'Bulgarian': 'bg', 'Burmese': 'my', 'Catalan': 'ca',
|
||||
'Chinese': 'zh', 'Chinese_simplified': 'zh-CN',
|
||||
'Chinese_traditional': 'zh-TW', 'Croatian': 'hr',
|
||||
'Czech': 'cs', 'Danish': 'da', 'Dhivehi': 'dv',
|
||||
'Dutch': 'nl', 'English': 'en', 'Esperanto': 'eo',
|
||||
'Estonian': 'et', 'Filipino': 'tl', 'Finnish': 'fi',
|
||||
'French': 'fr', 'Galician': 'gl', 'Georgian': 'ka',
|
||||
'German': 'de', 'Greek': 'el', 'Gujarati': 'gu',
|
||||
'Hebrew': 'iw', 'Hindi': 'hi', 'Hungarian': 'hu',
|
||||
'Icelandic': 'is', 'Indonesian': 'id', 'Inuktitut': 'iu',
|
||||
'Italian': 'it', 'Japanese': 'ja', 'Kannada': 'kn',
|
||||
'Kazakh': 'kk', 'Khmer': 'km', 'Korean': 'ko',
|
||||
'Kurdish': 'ku', 'Kyrgyz': 'ky', 'Laothian': 'lo',
|
||||
'Latvian': 'lv', 'Lithuanian': 'lt', 'Macedonian': 'mk',
|
||||
'Malay': 'ms', 'Malayalam': 'ml', 'Maltese': 'mt',
|
||||
'Marathi': 'mr', 'Mongolian': 'mn', 'Nepali': 'ne',
|
||||
'Norwegian': 'no', 'Oriya': 'or', 'Pashto': 'ps',
|
||||
'Persian': 'fa', 'Polish': 'pl', 'Portuguese': 'pt-PT',
|
||||
'Punjabi': 'pa', 'Romanian': 'ro', 'Russian': 'ru',
|
||||
'Sanskrit': 'sa', 'Serbian': 'sr', 'Sindhi': 'sd',
|
||||
'Sinhalese': 'si', 'Slovak': 'sk', 'Slovenian': 'sl',
|
||||
'Spanish': 'es', 'Swedish': 'sv', 'Tajik': 'tg',
|
||||
'Tamil': 'ta', 'Tagalog': 'tl', 'Telugu': 'te',
|
||||
'Thai': 'th', 'Tibetan': 'bo', 'Turkish': 'tr',
|
||||
'Ukranian': 'uk', 'Urdu': 'ur', 'Uzbek': 'uz',
|
||||
'Uighur': 'ug', 'Vietnamese': 'vi'}
|
||||
validStrings = ['lang_' + s for s in transLangs.values()]
|
||||
validStrings.append('')
|
||||
def normalize(self, s):
|
||||
if s and not s.startswith('lang_'):
|
||||
s = 'lang_' + s
|
||||
if not s.endswith('CN') or s.endswith('TW'):
|
||||
if not s.endswith('CN') or s.endswith('TW') or s.endswith('PT'):
|
||||
s = s.lower()
|
||||
else:
|
||||
s = s.lower()[:-2] + s[-2:]
|
||||
|
@ -231,16 +231,6 @@ 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>
|
||||
|
||||
@ -257,22 +247,22 @@ class Google(callbacks.PluginRegexp):
|
||||
headers['Referer'] = ref
|
||||
opts = {'q': text, 'v': '1.0'}
|
||||
lang = conf.supybot.plugins.Google.defaultLanguage
|
||||
if fromLang.capitalize() in self._transLangs:
|
||||
fromLang = self._transLangs[fromLang.capitalize()]
|
||||
if fromLang.capitalize() in lang.transLangs:
|
||||
fromLang = lang.transLangs[fromLang.capitalize()]
|
||||
elif lang.normalize('lang_'+fromLang)[5:] \
|
||||
not in self._transLangs.values():
|
||||
not in lang.transLangs.values():
|
||||
irc.errorInvalid('from language', fromLang,
|
||||
format('Valid languages are: %L',
|
||||
self._transLangs.keys()))
|
||||
lang.transLangs.keys()))
|
||||
else:
|
||||
fromLang = lang.normalize('lang_'+fromLang)[5:]
|
||||
if toLang.capitalize() in self._transLangs:
|
||||
toLang = self._transLangs[toLang.capitalize()]
|
||||
if toLang.capitalize() in lang.transLangs:
|
||||
toLang = lang.transLangs[toLang.capitalize()]
|
||||
elif lang.normalize('lang_'+toLang)[5:] \
|
||||
not in self._transLangs.values():
|
||||
not in lang.transLangs.values():
|
||||
irc.errorInvalid('to language', toLang,
|
||||
format('Valid languages are: %L',
|
||||
self._transLangs.keys()))
|
||||
lang.transLangs.keys()))
|
||||
else:
|
||||
toLang = lang.normalize('lang_'+toLang)[5:]
|
||||
opts['langpair'] = '%s|%s' % (fromLang, toLang)
|
||||
|
Loading…
Reference in New Issue
Block a user