From 495288b88700c56cf07ab756e4db9a755c68ee37 Mon Sep 17 00:00:00 2001 From: runebaas Date: Sun, 12 May 2019 01:07:22 +0200 Subject: [PATCH] Pass full translation dictionary to TranslationGuildContext and decide there whether to use singular or plural --- Geekbot.net/Commands/Utils/Choose.cs | 2 +- Geekbot.net/Lib/Localization/TranslationGuildContext.cs | 6 +++--- Geekbot.net/Lib/Localization/TranslationHandler.cs | 7 +++---- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/Geekbot.net/Commands/Utils/Choose.cs b/Geekbot.net/Commands/Utils/Choose.cs index 7060755..62069bd 100644 --- a/Geekbot.net/Commands/Utils/Choose.cs +++ b/Geekbot.net/Commands/Utils/Choose.cs @@ -27,7 +27,7 @@ namespace Geekbot.net.Commands.Utils var transContext = await _translation.GetGuildContext(Context); var choicesArray = choices.Split(';'); var choice = new Random().Next(choicesArray.Length); - await ReplyAsync(transContext.GetString("Choice", choicesArray[choice])); + await ReplyAsync(transContext.GetString("Choice", choicesArray[choice].Trim())); } catch (Exception e) { diff --git a/Geekbot.net/Lib/Localization/TranslationGuildContext.cs b/Geekbot.net/Lib/Localization/TranslationGuildContext.cs index 037ef3a..3f6f923 100644 --- a/Geekbot.net/Lib/Localization/TranslationGuildContext.cs +++ b/Geekbot.net/Lib/Localization/TranslationGuildContext.cs @@ -10,9 +10,9 @@ namespace Geekbot.net.Lib.Localization { public ITranslationHandler TranslationHandler { get; } public string Language { get; } - public Dictionary Dict { get; } + public Dictionary> Dict { get; } - public TranslationGuildContext(ITranslationHandler translationHandler, string language, Dictionary dict) + public TranslationGuildContext(ITranslationHandler translationHandler, string language, Dictionary> dict) { TranslationHandler = translationHandler; Language = language; @@ -21,7 +21,7 @@ namespace Geekbot.net.Lib.Localization public string GetString(string stringToFormat, params object[] args) { - return string.Format(Dict[stringToFormat] ?? "", args); + return string.Format(Dict[stringToFormat].First() ?? "", args); } public string FormatDateTimeAsRemaining(DateTimeOffset dateTime) diff --git a/Geekbot.net/Lib/Localization/TranslationHandler.cs b/Geekbot.net/Lib/Localization/TranslationHandler.cs index f298e2d..8100478 100644 --- a/Geekbot.net/Lib/Localization/TranslationHandler.cs +++ b/Geekbot.net/Lib/Localization/TranslationHandler.cs @@ -127,19 +127,18 @@ namespace Geekbot.net.Lib.Localization return translation; } - private async Task> GetDict(ICommandContext context) + private async Task>> GetDict(ICommandContext context) { try { var command = context.Message.Content.Split(' ').First().TrimStart('!').ToLower(); var serverLanguage = await GetServerLanguage(context.Guild?.Id ?? 0); - return _translations[serverLanguage][command] - .ToDictionary(dict => dict.Key, dict => dict.Value.First()); + return _translations[serverLanguage][command]; } catch (Exception e) { _logger.Error(LogSource.Geekbot, "No translations for command found", e); - return new Dictionary(); + return new Dictionary>(); } }