Pass full translation dictionary to TranslationGuildContext and decide there whether to use singular or plural
This commit is contained in:
parent
b309f155be
commit
495288b887
3 changed files with 7 additions and 8 deletions
|
@ -27,7 +27,7 @@ namespace Geekbot.net.Commands.Utils
|
||||||
var transContext = await _translation.GetGuildContext(Context);
|
var transContext = await _translation.GetGuildContext(Context);
|
||||||
var choicesArray = choices.Split(';');
|
var choicesArray = choices.Split(';');
|
||||||
var choice = new Random().Next(choicesArray.Length);
|
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)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|
|
@ -10,9 +10,9 @@ namespace Geekbot.net.Lib.Localization
|
||||||
{
|
{
|
||||||
public ITranslationHandler TranslationHandler { get; }
|
public ITranslationHandler TranslationHandler { get; }
|
||||||
public string Language { get; }
|
public string Language { get; }
|
||||||
public Dictionary<string, string> Dict { get; }
|
public Dictionary<string, List<string>> Dict { get; }
|
||||||
|
|
||||||
public TranslationGuildContext(ITranslationHandler translationHandler, string language, Dictionary<string, string> dict)
|
public TranslationGuildContext(ITranslationHandler translationHandler, string language, Dictionary<string, List<string>> dict)
|
||||||
{
|
{
|
||||||
TranslationHandler = translationHandler;
|
TranslationHandler = translationHandler;
|
||||||
Language = language;
|
Language = language;
|
||||||
|
@ -21,7 +21,7 @@ namespace Geekbot.net.Lib.Localization
|
||||||
|
|
||||||
public string GetString(string stringToFormat, params object[] args)
|
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)
|
public string FormatDateTimeAsRemaining(DateTimeOffset dateTime)
|
||||||
|
|
|
@ -127,19 +127,18 @@ namespace Geekbot.net.Lib.Localization
|
||||||
return translation;
|
return translation;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<Dictionary<string, string>> GetDict(ICommandContext context)
|
private async Task<Dictionary<string, List<string>>> GetDict(ICommandContext context)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var command = context.Message.Content.Split(' ').First().TrimStart('!').ToLower();
|
var command = context.Message.Content.Split(' ').First().TrimStart('!').ToLower();
|
||||||
var serverLanguage = await GetServerLanguage(context.Guild?.Id ?? 0);
|
var serverLanguage = await GetServerLanguage(context.Guild?.Id ?? 0);
|
||||||
return _translations[serverLanguage][command]
|
return _translations[serverLanguage][command];
|
||||||
.ToDictionary(dict => dict.Key, dict => dict.Value.First());
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
_logger.Error(LogSource.Geekbot, "No translations for command found", e);
|
_logger.Error(LogSource.Geekbot, "No translations for command found", e);
|
||||||
return new Dictionary<string, string>();
|
return new Dictionary<string, List<string>>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue