From 5e154cbcd1c9840e999c32eb86f4f7c14c65c8c0 Mon Sep 17 00:00:00 2001 From: Master Kwoth Date: Sun, 27 Mar 2016 06:07:11 +0200 Subject: [PATCH] case insensitive language names --- .../Translator/Helpers/GoogleTranslator.cs | 141 +++++++++--------- .../Modules/Translator/TranslateCommand.cs | 4 +- 2 files changed, 70 insertions(+), 75 deletions(-) diff --git a/NadekoBot/Modules/Translator/Helpers/GoogleTranslator.cs b/NadekoBot/Modules/Translator/Helpers/GoogleTranslator.cs index beb8f38a..eb0e466c 100644 --- a/NadekoBot/Modules/Translator/Helpers/GoogleTranslator.cs +++ b/NadekoBot/Modules/Translator/Helpers/GoogleTranslator.cs @@ -21,10 +21,8 @@ namespace NadekoBot.Modules.Translator.Helpers /// /// Gets the supported languages. /// - public static IEnumerable Languages - { - get - { + public static IEnumerable Languages { + get { GoogleTranslator.EnsureInitialized(); return GoogleTranslator._languageModeMap.Keys.OrderBy(p => p); } @@ -33,8 +31,7 @@ namespace NadekoBot.Modules.Translator.Helpers /// /// Gets the time taken to perform the translation. /// - public TimeSpan TranslationTime - { + public TimeSpan TranslationTime { get; private set; } @@ -43,8 +40,7 @@ namespace NadekoBot.Modules.Translator.Helpers /// Gets the url used to speak the translation. /// /// The url used to speak the translation. - public string TranslationSpeechUrl - { + public string TranslationSpeechUrl { get; private set; } @@ -52,8 +48,7 @@ namespace NadekoBot.Modules.Translator.Helpers /// /// Gets the error. /// - public Exception Error - { + public Exception Error { get; private set; } @@ -186,69 +181,69 @@ namespace NadekoBot.Modules.Translator.Helpers if (GoogleTranslator._languageModeMap == null) { GoogleTranslator._languageModeMap = new Dictionary(); - GoogleTranslator._languageModeMap.Add("Afrikaans", "af"); - GoogleTranslator._languageModeMap.Add("Albanian", "sq"); - GoogleTranslator._languageModeMap.Add("Arabic", "ar"); - GoogleTranslator._languageModeMap.Add("Armenian", "hy"); - GoogleTranslator._languageModeMap.Add("Azerbaijani", "az"); - GoogleTranslator._languageModeMap.Add("Basque", "eu"); - GoogleTranslator._languageModeMap.Add("Belarusian", "be"); - GoogleTranslator._languageModeMap.Add("Bengali", "bn"); - GoogleTranslator._languageModeMap.Add("Bulgarian", "bg"); - GoogleTranslator._languageModeMap.Add("Catalan", "ca"); - GoogleTranslator._languageModeMap.Add("Chinese", "zh-CN"); - GoogleTranslator._languageModeMap.Add("Croatian", "hr"); - GoogleTranslator._languageModeMap.Add("Czech", "cs"); - GoogleTranslator._languageModeMap.Add("Danish", "da"); - GoogleTranslator._languageModeMap.Add("Dutch", "nl"); - GoogleTranslator._languageModeMap.Add("English", "en"); - GoogleTranslator._languageModeMap.Add("Esperanto", "eo"); - GoogleTranslator._languageModeMap.Add("Estonian", "et"); - GoogleTranslator._languageModeMap.Add("Filipino", "tl"); - GoogleTranslator._languageModeMap.Add("Finnish", "fi"); - GoogleTranslator._languageModeMap.Add("French", "fr"); - GoogleTranslator._languageModeMap.Add("Galician", "gl"); - GoogleTranslator._languageModeMap.Add("German", "de"); - GoogleTranslator._languageModeMap.Add("Georgian", "ka"); - GoogleTranslator._languageModeMap.Add("Greek", "el"); - GoogleTranslator._languageModeMap.Add("Haitian Creole", "ht"); - GoogleTranslator._languageModeMap.Add("Hebrew", "iw"); - GoogleTranslator._languageModeMap.Add("Hindi", "hi"); - GoogleTranslator._languageModeMap.Add("Hungarian", "hu"); - GoogleTranslator._languageModeMap.Add("Icelandic", "is"); - GoogleTranslator._languageModeMap.Add("Indonesian", "id"); - GoogleTranslator._languageModeMap.Add("Irish", "ga"); - GoogleTranslator._languageModeMap.Add("Italian", "it"); - GoogleTranslator._languageModeMap.Add("Japanese", "ja"); - GoogleTranslator._languageModeMap.Add("Korean", "ko"); - GoogleTranslator._languageModeMap.Add("Lao", "lo"); - GoogleTranslator._languageModeMap.Add("Latin", "la"); - GoogleTranslator._languageModeMap.Add("Latvian", "lv"); - GoogleTranslator._languageModeMap.Add("Lithuanian", "lt"); - GoogleTranslator._languageModeMap.Add("Macedonian", "mk"); - GoogleTranslator._languageModeMap.Add("Malay", "ms"); - GoogleTranslator._languageModeMap.Add("Maltese", "mt"); - GoogleTranslator._languageModeMap.Add("Norwegian", "no"); - GoogleTranslator._languageModeMap.Add("Persian", "fa"); - GoogleTranslator._languageModeMap.Add("Polish", "pl"); - GoogleTranslator._languageModeMap.Add("Portuguese", "pt"); - GoogleTranslator._languageModeMap.Add("Romanian", "ro"); - GoogleTranslator._languageModeMap.Add("Russian", "ru"); - GoogleTranslator._languageModeMap.Add("Serbian", "sr"); - GoogleTranslator._languageModeMap.Add("Slovak", "sk"); - GoogleTranslator._languageModeMap.Add("Slovenian", "sl"); - GoogleTranslator._languageModeMap.Add("Spanish", "es"); - GoogleTranslator._languageModeMap.Add("Swahili", "sw"); - GoogleTranslator._languageModeMap.Add("Swedish", "sv"); - GoogleTranslator._languageModeMap.Add("Tamil", "ta"); - GoogleTranslator._languageModeMap.Add("Telugu", "te"); - GoogleTranslator._languageModeMap.Add("Thai", "th"); - GoogleTranslator._languageModeMap.Add("Turkish", "tr"); - GoogleTranslator._languageModeMap.Add("Ukrainian", "uk"); - GoogleTranslator._languageModeMap.Add("Urdu", "ur"); - GoogleTranslator._languageModeMap.Add("Vietnamese", "vi"); - GoogleTranslator._languageModeMap.Add("Welsh", "cy"); - GoogleTranslator._languageModeMap.Add("Yiddish", "yi"); + GoogleTranslator._languageModeMap.Add("afrikaans", "af"); + GoogleTranslator._languageModeMap.Add("albanian", "sq"); + GoogleTranslator._languageModeMap.Add("arabic", "ar"); + GoogleTranslator._languageModeMap.Add("armenian", "hy"); + GoogleTranslator._languageModeMap.Add("azerbaijani", "az"); + GoogleTranslator._languageModeMap.Add("basque", "eu"); + GoogleTranslator._languageModeMap.Add("belarusian", "be"); + GoogleTranslator._languageModeMap.Add("bengali", "bn"); + GoogleTranslator._languageModeMap.Add("bulgarian", "bg"); + GoogleTranslator._languageModeMap.Add("catalan", "ca"); + GoogleTranslator._languageModeMap.Add("chinese", "zh-CN"); + GoogleTranslator._languageModeMap.Add("croatian", "hr"); + GoogleTranslator._languageModeMap.Add("czech", "cs"); + GoogleTranslator._languageModeMap.Add("danish", "da"); + GoogleTranslator._languageModeMap.Add("dutch", "nl"); + GoogleTranslator._languageModeMap.Add("english", "en"); + GoogleTranslator._languageModeMap.Add("esperanto", "eo"); + GoogleTranslator._languageModeMap.Add("estonian", "et"); + GoogleTranslator._languageModeMap.Add("filipino", "tl"); + GoogleTranslator._languageModeMap.Add("finnish", "fi"); + GoogleTranslator._languageModeMap.Add("french", "fr"); + GoogleTranslator._languageModeMap.Add("galician", "gl"); + GoogleTranslator._languageModeMap.Add("german", "de"); + GoogleTranslator._languageModeMap.Add("georgian", "ka"); + GoogleTranslator._languageModeMap.Add("greek", "el"); + GoogleTranslator._languageModeMap.Add("haitian Creole", "ht"); + GoogleTranslator._languageModeMap.Add("hebrew", "iw"); + GoogleTranslator._languageModeMap.Add("hindi", "hi"); + GoogleTranslator._languageModeMap.Add("hungarian", "hu"); + GoogleTranslator._languageModeMap.Add("icelandic", "is"); + GoogleTranslator._languageModeMap.Add("indonesian", "id"); + GoogleTranslator._languageModeMap.Add("irish", "ga"); + GoogleTranslator._languageModeMap.Add("italian", "it"); + GoogleTranslator._languageModeMap.Add("japanese", "ja"); + GoogleTranslator._languageModeMap.Add("korean", "ko"); + GoogleTranslator._languageModeMap.Add("lao", "lo"); + GoogleTranslator._languageModeMap.Add("latin", "la"); + GoogleTranslator._languageModeMap.Add("latvian", "lv"); + GoogleTranslator._languageModeMap.Add("lithuanian", "lt"); + GoogleTranslator._languageModeMap.Add("macedonian", "mk"); + GoogleTranslator._languageModeMap.Add("malay", "ms"); + GoogleTranslator._languageModeMap.Add("maltese", "mt"); + GoogleTranslator._languageModeMap.Add("norwegian", "no"); + GoogleTranslator._languageModeMap.Add("persian", "fa"); + GoogleTranslator._languageModeMap.Add("polish", "pl"); + GoogleTranslator._languageModeMap.Add("portuguese", "pt"); + GoogleTranslator._languageModeMap.Add("romanian", "ro"); + GoogleTranslator._languageModeMap.Add("russian", "ru"); + GoogleTranslator._languageModeMap.Add("serbian", "sr"); + GoogleTranslator._languageModeMap.Add("slovak", "sk"); + GoogleTranslator._languageModeMap.Add("slovenian", "sl"); + GoogleTranslator._languageModeMap.Add("spanish", "es"); + GoogleTranslator._languageModeMap.Add("swahili", "sw"); + GoogleTranslator._languageModeMap.Add("swedish", "sv"); + GoogleTranslator._languageModeMap.Add("tamil", "ta"); + GoogleTranslator._languageModeMap.Add("telugu", "te"); + GoogleTranslator._languageModeMap.Add("thai", "th"); + GoogleTranslator._languageModeMap.Add("turkish", "tr"); + GoogleTranslator._languageModeMap.Add("ukrainian", "uk"); + GoogleTranslator._languageModeMap.Add("urdu", "ur"); + GoogleTranslator._languageModeMap.Add("vietnamese", "vi"); + GoogleTranslator._languageModeMap.Add("welsh", "cy"); + GoogleTranslator._languageModeMap.Add("yiddish", "yi"); GoogleTranslator._languageModeMap.Add("af", "af"); GoogleTranslator._languageModeMap.Add("sq", "sq"); diff --git a/NadekoBot/Modules/Translator/TranslateCommand.cs b/NadekoBot/Modules/Translator/TranslateCommand.cs index 1002843d..6b0a1d5a 100644 --- a/NadekoBot/Modules/Translator/TranslateCommand.cs +++ b/NadekoBot/Modules/Translator/TranslateCommand.cs @@ -24,8 +24,8 @@ namespace NadekoBot.Modules.Translator try { await e.Channel.SendIsTyping(); - string from = e.GetArg("langs").Split('>')[0]; - string to = e.GetArg("langs").Split('>')[1]; + string from = e.GetArg("langs").ToLowerInvariant().Split('>')[0]; + string to = e.GetArg("langs").ToLowerInvariant().Split('>')[1]; string translation = t.Translate(e.GetArg("text"), from, to); await e.Channel.SendMessage(translation);