Revert "Updates to language handler"

This reverts commit 5b56c18
This commit is contained in:
runebaas 2018-08-25 23:27:44 +02:00
parent e18a512a9b
commit 954de7f8db
No known key found for this signature in database
GPG key ID: 2677AF508D0300D6

View file

@ -18,7 +18,8 @@ namespace Geekbot.net.Lib.Localization
private readonly IGeekbotLogger _logger; private readonly IGeekbotLogger _logger;
private readonly Dictionary<ulong, string> _serverLanguages; private readonly Dictionary<ulong, string> _serverLanguages;
private Dictionary<string, Dictionary<string, Dictionary<string, string>>> _translations; private Dictionary<string, Dictionary<string, Dictionary<string, string>>> _translations;
private List<string> _supportedLanguages;
public TranslationHandler(DatabaseContext database, IGeekbotLogger logger) public TranslationHandler(DatabaseContext database, IGeekbotLogger logger)
{ {
_database = database; _database = database;
@ -44,27 +45,30 @@ namespace Geekbot.net.Lib.Localization
if (!sortedPerLanguage.ContainsKey(lang.Key)) if (!sortedPerLanguage.ContainsKey(lang.Key))
{ {
var commandDict = new Dictionary<string, Dictionary<string, string>>(); var commandDict = new Dictionary<string, Dictionary<string, string>>();
var strDict = new Dictionary<string, string> {{str.Key, lang.Value}}; var strDict = new Dictionary<string, string>();
strDict.Add(str.Key, lang.Value);
commandDict.Add(command.Key, strDict); commandDict.Add(command.Key, strDict);
sortedPerLanguage.Add(lang.Key, commandDict); sortedPerLanguage.Add(lang.Key, commandDict);
break;
} }
if (!sortedPerLanguage[lang.Key].ContainsKey(command.Key)) if (!sortedPerLanguage[lang.Key].ContainsKey(command.Key))
{ {
var strDict = new Dictionary<string, string> {{str.Key, lang.Value}}; var strDict = new Dictionary<string, string>();
strDict.Add(str.Key, lang.Value);
sortedPerLanguage[lang.Key].Add(command.Key, strDict); 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; _translations = sortedPerLanguage;
SupportedLanguages = new List<string>(); _supportedLanguages = new List<string>();
foreach (var lang in sortedPerLanguage) foreach (var lang in sortedPerLanguage)
{ {
SupportedLanguages.Add(lang.Key); _supportedLanguages.Add(lang.Key);
} }
} }
catch (Exception e) catch (Exception e)
@ -97,7 +101,7 @@ namespace Geekbot.net.Lib.Localization
} }
catch (Exception e) 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"; return "EN";
} }
} }
@ -145,7 +149,7 @@ namespace Geekbot.net.Lib.Localization
{ {
try try
{ {
if (!SupportedLanguages.Contains(language)) return false; if (!_supportedLanguages.Contains(language)) return false;
var guild = await GetGuild(guildId); var guild = await GetGuild(guildId);
guild.Language = language; guild.Language = language;
_database.GuildSettings.Update(guild); _database.GuildSettings.Update(guild);
@ -159,7 +163,7 @@ namespace Geekbot.net.Lib.Localization
} }
} }
public List<string> SupportedLanguages { get; private set; } public List<string> SupportedLanguages => _supportedLanguages;
private async Task<GuildSettingsModel> GetGuild(ulong guildId) private async Task<GuildSettingsModel> GetGuild(ulong guildId)
{ {