From 954de7f8db700a697a9f1baeb0a2297091c82696 Mon Sep 17 00:00:00 2001 From: runebaas Date: Sat, 25 Aug 2018 23:27:44 +0200 Subject: [PATCH] Revert "Updates to language handler" This reverts commit 5b56c18 --- .../Lib/Localization/TranslationHandler.cs | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/Geekbot.net/Lib/Localization/TranslationHandler.cs b/Geekbot.net/Lib/Localization/TranslationHandler.cs index b1f6e53..88e518e 100644 --- a/Geekbot.net/Lib/Localization/TranslationHandler.cs +++ b/Geekbot.net/Lib/Localization/TranslationHandler.cs @@ -18,7 +18,8 @@ namespace Geekbot.net.Lib.Localization private readonly IGeekbotLogger _logger; private readonly Dictionary _serverLanguages; private Dictionary>> _translations; - + private List _supportedLanguages; + public TranslationHandler(DatabaseContext database, IGeekbotLogger logger) { _database = database; @@ -44,27 +45,30 @@ namespace Geekbot.net.Lib.Localization if (!sortedPerLanguage.ContainsKey(lang.Key)) { var commandDict = new Dictionary>(); - var strDict = new Dictionary {{str.Key, lang.Value}}; + var strDict = new Dictionary(); + strDict.Add(str.Key, lang.Value); commandDict.Add(command.Key, strDict); sortedPerLanguage.Add(lang.Key, commandDict); - break; } if (!sortedPerLanguage[lang.Key].ContainsKey(command.Key)) { - var strDict = new Dictionary {{str.Key, lang.Value}}; + var strDict = new Dictionary(); + strDict.Add(str.Key, lang.Value); sortedPerLanguage[lang.Key].Add(command.Key, strDict); - break; } - sortedPerLanguage[lang.Key][command.Key].Add(str.Key, lang.Value); + if (!sortedPerLanguage[lang.Key][command.Key].ContainsKey(str.Key)) + { + sortedPerLanguage[lang.Key][command.Key].Add(str.Key, lang.Value); + } } } } _translations = sortedPerLanguage; - SupportedLanguages = new List(); + _supportedLanguages = new List(); foreach (var lang in sortedPerLanguage) { - SupportedLanguages.Add(lang.Key); + _supportedLanguages.Add(lang.Key); } } catch (Exception e) @@ -97,7 +101,7 @@ namespace Geekbot.net.Lib.Localization } catch (Exception e) { - _logger.Error(LogSource.Geekbot, "Could not get guild language", e); + _logger.Error(LogSource.Geekbot, "Could not get guild langage", e); return "EN"; } } @@ -145,7 +149,7 @@ namespace Geekbot.net.Lib.Localization { try { - if (!SupportedLanguages.Contains(language)) return false; + if (!_supportedLanguages.Contains(language)) return false; var guild = await GetGuild(guildId); guild.Language = language; _database.GuildSettings.Update(guild); @@ -159,7 +163,7 @@ namespace Geekbot.net.Lib.Localization } } - public List SupportedLanguages { get; private set; } + public List SupportedLanguages => _supportedLanguages; private async Task GetGuild(ulong guildId) {