diff --git a/JetKarmaBot/Commands/ChangeLocaleCommand.cs b/JetKarmaBot/Commands/ChangeLocaleCommand.cs index c2290e9..a0bad1f 100644 --- a/JetKarmaBot/Commands/ChangeLocaleCommand.cs +++ b/JetKarmaBot/Commands/ChangeLocaleCommand.cs @@ -4,6 +4,7 @@ using Telegram.Bot.Args; using Perfusion; using JetKarmaBot.Services; using NLog; +using System.Linq; namespace JetKarmaBot.Commands { @@ -26,6 +27,23 @@ namespace JetKarmaBot.Commands replyToMessageId: args.Message.MessageId); return true; } + else if (cmd.Parameters[0] == "list") + { + Client.SendTextMessageAsync( + args.Message.Chat.Id, + currentLocale["jetkarmabot.changelocale.listalltext"] + "\n" + + string.Join("\n", Locale.Select(a => a.Key)), + replyToMessageId: args.Message.MessageId); + return true; + } + else if (cmd.Parameters[0] == "all") + { + Client.SendTextMessageAsync( + args.Message.Chat.Id, + currentLocale["jetkarmabot.changelocale.errorall"], + replyToMessageId: args.Message.MessageId); + return true; + } string localeId; if (Locale.ContainsLocale(cmd.Parameters[0])) localeId = cmd.Parameters[0]; diff --git a/JetKarmaBot/Services/Localization.cs b/JetKarmaBot/Services/Localization.cs index adbb1ac..ba61371 100644 --- a/JetKarmaBot/Services/Localization.cs +++ b/JetKarmaBot/Services/Localization.cs @@ -1,4 +1,5 @@ using System; +using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; @@ -8,7 +9,7 @@ using Perfusion; namespace JetKarmaBot { - public class Localization + public class Localization : IReadOnlyDictionary { private Dictionary locales = new Dictionary(); @@ -77,21 +78,42 @@ namespace JetKarmaBot void Log(Exception e) => Console.WriteLine(e); - public class Locale - { - private Dictionary locale; - private string localeName; - private string[] commonNames; + public IEnumerable Keys => locales.Keys; - public Locale(JObject locale, string localeName) - { - this.locale = locale.Property("strings").Value.ToObject>(); - this.localeName = localeName; - this.commonNames = locale.Property("names").Value.ToObject(); - } - public string[] CommonNames => commonNames; - public string Name => localeName; - public string this[string name] => locale.ContainsKey(name) ? locale[name] : "unknown"; + public IEnumerable Values => locales.Values; + + public int Count => locales.Count; + + public bool ContainsKey(string key) => locales.ContainsKey(key.ToLower()); + + public bool TryGetValue(string key, out Locale value) + { + return locales.TryGetValue(key.ToLower(), out value); } + + public IEnumerator> GetEnumerator() + { + return locales.GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + + + } + public class Locale + { + private Dictionary locale; + private string localeName; + private string[] commonNames; + + public Locale(JObject locale, string localeName) + { + this.locale = locale.Property("strings").Value.ToObject>(); + this.localeName = localeName; + this.commonNames = locale.Property("names").Value.ToObject(); + } + public string[] CommonNames => commonNames; + public string Name => localeName; + public string this[string name] => locale.ContainsKey(name) ? locale[name] : "unknown"; } } \ No newline at end of file diff --git a/JetKarmaBot/lang/en-US.json b/JetKarmaBot/lang/en-US.json index 012ed26..6390a82 100644 --- a/JetKarmaBot/lang/en-US.json +++ b/JetKarmaBot/lang/en-US.json @@ -14,6 +14,8 @@ "jetkarmabot.status.listspecifictext": "You are at {0}{1} now.", "jetkarmabot.status.havenothing": "You don't have anything yet.", "jetkarmabot.changelocale.justchanged": "Roger that.", - "jetkarmabot.changelocale.getlocale": "I'm currently speaking English." + "jetkarmabot.changelocale.getlocale": "I'm currently speaking English.", + "jetkarmabot.changelocale.listalltext": "I know:", + "jetkarmabot.changelocale.errorall": "I would like to speak all languages at once, but because of the rules of the universe, I am not allowed to do that." } } \ No newline at end of file diff --git a/JetKarmaBot/lang/ru-RU.json b/JetKarmaBot/lang/ru-RU.json index ce2b3c8..9213f47 100644 --- a/JetKarmaBot/lang/ru-RU.json +++ b/JetKarmaBot/lang/ru-RU.json @@ -15,6 +15,8 @@ "jetkarmabot.status.listspecifictext": "У вас сейчас {0}{1}.", "jetkarmabot.status.havenothing": "У вас пока ничего нет.", "jetkarmabot.changelocale.justchanged": "Так точно.", - "jetkarmabot.changelocale.getlocale": "Я сейчас говорю по-русски." + "jetkarmabot.changelocale.getlocale": "Я сейчас говорю по-русски.", + "jetkarmabot.changelocale.listalltext": "Я знаю:", + "jetkarmabot.changelocale.errorall": "Мне бы хотелось говорить на всех языках в то же самое время, но из-за ограничений вселенной, мне это не позволяется." } } \ No newline at end of file