case insensitive language names

This commit is contained in:
Master Kwoth 2016-03-27 06:07:11 +02:00
parent 82cfd7cacf
commit 5e154cbcd1
2 changed files with 70 additions and 75 deletions

View File

@ -21,10 +21,8 @@ namespace NadekoBot.Modules.Translator.Helpers
/// <summary> /// <summary>
/// Gets the supported languages. /// Gets the supported languages.
/// </summary> /// </summary>
public static IEnumerable<string> Languages public static IEnumerable<string> Languages {
{ get {
get
{
GoogleTranslator.EnsureInitialized(); GoogleTranslator.EnsureInitialized();
return GoogleTranslator._languageModeMap.Keys.OrderBy(p => p); return GoogleTranslator._languageModeMap.Keys.OrderBy(p => p);
} }
@ -33,8 +31,7 @@ namespace NadekoBot.Modules.Translator.Helpers
/// <summary> /// <summary>
/// Gets the time taken to perform the translation. /// Gets the time taken to perform the translation.
/// </summary> /// </summary>
public TimeSpan TranslationTime public TimeSpan TranslationTime {
{
get; get;
private set; private set;
} }
@ -43,8 +40,7 @@ namespace NadekoBot.Modules.Translator.Helpers
/// Gets the url used to speak the translation. /// Gets the url used to speak the translation.
/// </summary> /// </summary>
/// <value>The url used to speak the translation.</value> /// <value>The url used to speak the translation.</value>
public string TranslationSpeechUrl public string TranslationSpeechUrl {
{
get; get;
private set; private set;
} }
@ -52,8 +48,7 @@ namespace NadekoBot.Modules.Translator.Helpers
/// <summary> /// <summary>
/// Gets the error. /// Gets the error.
/// </summary> /// </summary>
public Exception Error public Exception Error {
{
get; get;
private set; private set;
} }
@ -186,69 +181,69 @@ namespace NadekoBot.Modules.Translator.Helpers
if (GoogleTranslator._languageModeMap == null) if (GoogleTranslator._languageModeMap == null)
{ {
GoogleTranslator._languageModeMap = new Dictionary<string, string>(); GoogleTranslator._languageModeMap = new Dictionary<string, string>();
GoogleTranslator._languageModeMap.Add("Afrikaans", "af"); GoogleTranslator._languageModeMap.Add("afrikaans", "af");
GoogleTranslator._languageModeMap.Add("Albanian", "sq"); GoogleTranslator._languageModeMap.Add("albanian", "sq");
GoogleTranslator._languageModeMap.Add("Arabic", "ar"); GoogleTranslator._languageModeMap.Add("arabic", "ar");
GoogleTranslator._languageModeMap.Add("Armenian", "hy"); GoogleTranslator._languageModeMap.Add("armenian", "hy");
GoogleTranslator._languageModeMap.Add("Azerbaijani", "az"); GoogleTranslator._languageModeMap.Add("azerbaijani", "az");
GoogleTranslator._languageModeMap.Add("Basque", "eu"); GoogleTranslator._languageModeMap.Add("basque", "eu");
GoogleTranslator._languageModeMap.Add("Belarusian", "be"); GoogleTranslator._languageModeMap.Add("belarusian", "be");
GoogleTranslator._languageModeMap.Add("Bengali", "bn"); GoogleTranslator._languageModeMap.Add("bengali", "bn");
GoogleTranslator._languageModeMap.Add("Bulgarian", "bg"); GoogleTranslator._languageModeMap.Add("bulgarian", "bg");
GoogleTranslator._languageModeMap.Add("Catalan", "ca"); GoogleTranslator._languageModeMap.Add("catalan", "ca");
GoogleTranslator._languageModeMap.Add("Chinese", "zh-CN"); GoogleTranslator._languageModeMap.Add("chinese", "zh-CN");
GoogleTranslator._languageModeMap.Add("Croatian", "hr"); GoogleTranslator._languageModeMap.Add("croatian", "hr");
GoogleTranslator._languageModeMap.Add("Czech", "cs"); GoogleTranslator._languageModeMap.Add("czech", "cs");
GoogleTranslator._languageModeMap.Add("Danish", "da"); GoogleTranslator._languageModeMap.Add("danish", "da");
GoogleTranslator._languageModeMap.Add("Dutch", "nl"); GoogleTranslator._languageModeMap.Add("dutch", "nl");
GoogleTranslator._languageModeMap.Add("English", "en"); GoogleTranslator._languageModeMap.Add("english", "en");
GoogleTranslator._languageModeMap.Add("Esperanto", "eo"); GoogleTranslator._languageModeMap.Add("esperanto", "eo");
GoogleTranslator._languageModeMap.Add("Estonian", "et"); GoogleTranslator._languageModeMap.Add("estonian", "et");
GoogleTranslator._languageModeMap.Add("Filipino", "tl"); GoogleTranslator._languageModeMap.Add("filipino", "tl");
GoogleTranslator._languageModeMap.Add("Finnish", "fi"); GoogleTranslator._languageModeMap.Add("finnish", "fi");
GoogleTranslator._languageModeMap.Add("French", "fr"); GoogleTranslator._languageModeMap.Add("french", "fr");
GoogleTranslator._languageModeMap.Add("Galician", "gl"); GoogleTranslator._languageModeMap.Add("galician", "gl");
GoogleTranslator._languageModeMap.Add("German", "de"); GoogleTranslator._languageModeMap.Add("german", "de");
GoogleTranslator._languageModeMap.Add("Georgian", "ka"); GoogleTranslator._languageModeMap.Add("georgian", "ka");
GoogleTranslator._languageModeMap.Add("Greek", "el"); GoogleTranslator._languageModeMap.Add("greek", "el");
GoogleTranslator._languageModeMap.Add("Haitian Creole", "ht"); GoogleTranslator._languageModeMap.Add("haitian Creole", "ht");
GoogleTranslator._languageModeMap.Add("Hebrew", "iw"); GoogleTranslator._languageModeMap.Add("hebrew", "iw");
GoogleTranslator._languageModeMap.Add("Hindi", "hi"); GoogleTranslator._languageModeMap.Add("hindi", "hi");
GoogleTranslator._languageModeMap.Add("Hungarian", "hu"); GoogleTranslator._languageModeMap.Add("hungarian", "hu");
GoogleTranslator._languageModeMap.Add("Icelandic", "is"); GoogleTranslator._languageModeMap.Add("icelandic", "is");
GoogleTranslator._languageModeMap.Add("Indonesian", "id"); GoogleTranslator._languageModeMap.Add("indonesian", "id");
GoogleTranslator._languageModeMap.Add("Irish", "ga"); GoogleTranslator._languageModeMap.Add("irish", "ga");
GoogleTranslator._languageModeMap.Add("Italian", "it"); GoogleTranslator._languageModeMap.Add("italian", "it");
GoogleTranslator._languageModeMap.Add("Japanese", "ja"); GoogleTranslator._languageModeMap.Add("japanese", "ja");
GoogleTranslator._languageModeMap.Add("Korean", "ko"); GoogleTranslator._languageModeMap.Add("korean", "ko");
GoogleTranslator._languageModeMap.Add("Lao", "lo"); GoogleTranslator._languageModeMap.Add("lao", "lo");
GoogleTranslator._languageModeMap.Add("Latin", "la"); GoogleTranslator._languageModeMap.Add("latin", "la");
GoogleTranslator._languageModeMap.Add("Latvian", "lv"); GoogleTranslator._languageModeMap.Add("latvian", "lv");
GoogleTranslator._languageModeMap.Add("Lithuanian", "lt"); GoogleTranslator._languageModeMap.Add("lithuanian", "lt");
GoogleTranslator._languageModeMap.Add("Macedonian", "mk"); GoogleTranslator._languageModeMap.Add("macedonian", "mk");
GoogleTranslator._languageModeMap.Add("Malay", "ms"); GoogleTranslator._languageModeMap.Add("malay", "ms");
GoogleTranslator._languageModeMap.Add("Maltese", "mt"); GoogleTranslator._languageModeMap.Add("maltese", "mt");
GoogleTranslator._languageModeMap.Add("Norwegian", "no"); GoogleTranslator._languageModeMap.Add("norwegian", "no");
GoogleTranslator._languageModeMap.Add("Persian", "fa"); GoogleTranslator._languageModeMap.Add("persian", "fa");
GoogleTranslator._languageModeMap.Add("Polish", "pl"); GoogleTranslator._languageModeMap.Add("polish", "pl");
GoogleTranslator._languageModeMap.Add("Portuguese", "pt"); GoogleTranslator._languageModeMap.Add("portuguese", "pt");
GoogleTranslator._languageModeMap.Add("Romanian", "ro"); GoogleTranslator._languageModeMap.Add("romanian", "ro");
GoogleTranslator._languageModeMap.Add("Russian", "ru"); GoogleTranslator._languageModeMap.Add("russian", "ru");
GoogleTranslator._languageModeMap.Add("Serbian", "sr"); GoogleTranslator._languageModeMap.Add("serbian", "sr");
GoogleTranslator._languageModeMap.Add("Slovak", "sk"); GoogleTranslator._languageModeMap.Add("slovak", "sk");
GoogleTranslator._languageModeMap.Add("Slovenian", "sl"); GoogleTranslator._languageModeMap.Add("slovenian", "sl");
GoogleTranslator._languageModeMap.Add("Spanish", "es"); GoogleTranslator._languageModeMap.Add("spanish", "es");
GoogleTranslator._languageModeMap.Add("Swahili", "sw"); GoogleTranslator._languageModeMap.Add("swahili", "sw");
GoogleTranslator._languageModeMap.Add("Swedish", "sv"); GoogleTranslator._languageModeMap.Add("swedish", "sv");
GoogleTranslator._languageModeMap.Add("Tamil", "ta"); GoogleTranslator._languageModeMap.Add("tamil", "ta");
GoogleTranslator._languageModeMap.Add("Telugu", "te"); GoogleTranslator._languageModeMap.Add("telugu", "te");
GoogleTranslator._languageModeMap.Add("Thai", "th"); GoogleTranslator._languageModeMap.Add("thai", "th");
GoogleTranslator._languageModeMap.Add("Turkish", "tr"); GoogleTranslator._languageModeMap.Add("turkish", "tr");
GoogleTranslator._languageModeMap.Add("Ukrainian", "uk"); GoogleTranslator._languageModeMap.Add("ukrainian", "uk");
GoogleTranslator._languageModeMap.Add("Urdu", "ur"); GoogleTranslator._languageModeMap.Add("urdu", "ur");
GoogleTranslator._languageModeMap.Add("Vietnamese", "vi"); GoogleTranslator._languageModeMap.Add("vietnamese", "vi");
GoogleTranslator._languageModeMap.Add("Welsh", "cy"); GoogleTranslator._languageModeMap.Add("welsh", "cy");
GoogleTranslator._languageModeMap.Add("Yiddish", "yi"); GoogleTranslator._languageModeMap.Add("yiddish", "yi");
GoogleTranslator._languageModeMap.Add("af", "af"); GoogleTranslator._languageModeMap.Add("af", "af");
GoogleTranslator._languageModeMap.Add("sq", "sq"); GoogleTranslator._languageModeMap.Add("sq", "sq");

View File

@ -24,8 +24,8 @@ namespace NadekoBot.Modules.Translator
try try
{ {
await e.Channel.SendIsTyping(); await e.Channel.SendIsTyping();
string from = e.GetArg("langs").Split('>')[0]; string from = e.GetArg("langs").ToLowerInvariant().Split('>')[0];
string to = e.GetArg("langs").Split('>')[1]; string to = e.GetArg("langs").ToLowerInvariant().Split('>')[1];
string translation = t.Translate(e.GetArg("text"), from, to); string translation = t.Translate(e.GetArg("text"), from, to);
await e.Channel.SendMessage(translation); await e.Channel.SendMessage(translation);