Revert back to using strings in stead of arrays in the translations

This commit is contained in:
runebaas 2019-05-12 15:49:00 +02:00
parent e0e76d7c27
commit 53f894676c
No known key found for this signature in database
GPG key ID: 2677AF508D0300D6
4 changed files with 120 additions and 226 deletions

View file

@ -7,7 +7,7 @@ namespace Geekbot.net.Lib.Localization
public interface ITranslationHandler
{
Task<string> GetString(ulong guildId, string command, string stringName);
List<string> GetStrings(string language, string command, string stringName);
string GetString(string language, string command, string stringName);
Task<Dictionary<string, string>> GetDict(ICommandContext context, string command);
Task<TranslationGuildContext> GetGuildContext(ICommandContext context);
Task<bool> SetLanguage(ulong guildId, string language);

View file

@ -10,9 +10,9 @@ namespace Geekbot.net.Lib.Localization
{
public ITranslationHandler TranslationHandler { get; }
public string Language { get; }
public Dictionary<string, List<string>> Dict { get; }
public Dictionary<string, string> Dict { get; }
public TranslationGuildContext(ITranslationHandler translationHandler, string language, Dictionary<string, List<string>> dict)
public TranslationGuildContext(ITranslationHandler translationHandler, string language, Dictionary<string, string> 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].First() ?? "", args);
return string.Format(Dict[stringToFormat] ?? "", args);
}
public string FormatDateTimeAsRemaining(DateTimeOffset dateTime)
@ -54,7 +54,7 @@ namespace Geekbot.net.Lib.Localization
{
if (sb.Length > 0)
{
var and = TranslationHandler.GetStrings(Language, "dateTime", "And").First();
var and = TranslationHandler.GetString(Language, "dateTime", "And");
sb.AppendFormat(" {0} ", and);
}
var s = GetTimeString(TimeTypes.Seconds);
@ -69,13 +69,14 @@ namespace Geekbot.net.Lib.Localization
return TranslationHandler.SetLanguage(guildId, language);
}
private List<string> GetTimeString(TimeTypes type)
private string GetTimeString(TimeTypes type)
{
return TranslationHandler.GetStrings(Language, "dateTime", type.ToString());
return TranslationHandler.GetString(Language, "dateTime", type.ToString());
}
private string GetSingOrPlur(int number, List<string> versions)
private string GetSingOrPlur(int number, string rawString)
{
var versions = rawString.Split('|');
return number == 1 ? versions[0] : versions[1];
}

View file

@ -19,7 +19,7 @@ namespace Geekbot.net.Lib.Localization
private readonly DatabaseContext _database;
private readonly IGeekbotLogger _logger;
private readonly Dictionary<ulong, string> _serverLanguages;
private Dictionary<string, Dictionary<string, Dictionary<string, List<string>>>> _translations;
private Dictionary<string, Dictionary<string, Dictionary<string, string>>> _translations;
public TranslationHandler(DatabaseContext database, IGeekbotLogger logger)
{
@ -40,10 +40,10 @@ namespace Geekbot.net.Lib.Localization
// Deserialize
var input = new StringReader(translationFile);
var deserializer = new DeserializerBuilder().Build();
var rawTranslations = deserializer.Deserialize<Dictionary<string, Dictionary<string, Dictionary<string, List<string>>>>>(input);
var rawTranslations = deserializer.Deserialize<Dictionary<string, Dictionary<string, Dictionary<string, string>>>>(input);
// Sort
var sortedPerLanguage = new Dictionary<string, Dictionary<string, Dictionary<string, List<string>>>>();
var sortedPerLanguage = new Dictionary<string, Dictionary<string, Dictionary<string, string>>>();
foreach (var command in rawTranslations)
{
foreach (var str in command.Value)
@ -52,8 +52,8 @@ namespace Geekbot.net.Lib.Localization
{
if (!sortedPerLanguage.ContainsKey(lang.Key))
{
var commandDict = new Dictionary<string, Dictionary<string, List<string>>>();
var strDict = new Dictionary<string, List<string>>
var commandDict = new Dictionary<string, Dictionary<string, string>>();
var strDict = new Dictionary<string, string>
{
{str.Key, lang.Value}
};
@ -62,7 +62,7 @@ namespace Geekbot.net.Lib.Localization
}
if (!sortedPerLanguage[lang.Key].ContainsKey(command.Key))
{
var strDict = new Dictionary<string, List<string>>
var strDict = new Dictionary<string, string>
{
{str.Key, lang.Value}
};
@ -122,22 +122,22 @@ namespace Geekbot.net.Lib.Localization
public async Task<string> GetString(ulong guildId, string command, string stringName)
{
var serverLang = await GetServerLanguage(guildId);
return GetStrings(serverLang, command, stringName).First();
return GetString(serverLang, command, stringName);
}
public List<string> GetStrings(string language, string command, string stringName)
public string GetString(string language, string command, string stringName)
{
var translation = _translations[language][command][stringName];
if (!string.IsNullOrWhiteSpace(translation.First())) return translation;
if (!string.IsNullOrWhiteSpace(translation)) return translation;
translation = _translations[command][stringName]["EN"];
if (string.IsNullOrWhiteSpace(translation.First()))
if (string.IsNullOrWhiteSpace(translation))
{
_logger.Warning(LogSource.Geekbot, $"No translation found for {command} - {stringName}");
}
return translation;
}
private async Task<Dictionary<string, List<string>>> GetDict(ICommandContext context)
private async Task<Dictionary<string, string>> GetDict(ICommandContext context)
{
try
{
@ -148,7 +148,7 @@ namespace Geekbot.net.Lib.Localization
catch (Exception e)
{
_logger.Error(LogSource.Geekbot, "No translations for command found", e);
return new Dictionary<string, List<string>>();
return new Dictionary<string, string>();
}
}
@ -164,8 +164,7 @@ namespace Geekbot.net.Lib.Localization
try
{
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)
{

View file

@ -1,265 +1,159 @@
---
dateTime:
Days:
EN:
- "day"
- "days"
CHDE:
- "tag"
- "täg"
EN: "day|days"
CHDE: "tag|täg"
Hours:
EN:
- "hour"
- "hours"
CHDE:
- "stund"
- "stunde"
EN: "hour|hours"
CHDE: "stund|stunde"
Minutes:
EN:
- "minute"
- "minutes"
CHDE:
- "minute"
- "minute"
EN: "minute|minutes"
CHDE: "minute|minute"
Seconds:
EN:
- "second"
- "seconds"
CHDE:
- "sekunde"
- "sekunde"
EN: "second|seconds"
CHDE: "sekunde|sekunde"
And:
EN:
- "and"
CHDE:
- "und"
EN: "and"
CHDE: "und"
admin:
NewLanguageSet:
EN:
- "I will reply in english from now on"
CHDE:
- "I werd ab jetzt uf schwiizerdüütsch antworte, äuuä"
EN: "I will reply in english from now on"
CHDE: "I werd ab jetzt uf schwiizerdüütsch antworte, äuuä"
GetLanguage:
EN:
- "I'm talking english"
CHDE:
- "I red schwiizerdüütsch"
EN: "I'm talking english"
CHDE: "I red schwiizerdüütsch"
errorHandler:
SomethingWentWrong:
EN:
- "Something went wrong :confused:"
CHDE:
- "Öppis isch schief gange :confused:"
EN: "Something went wrong :confused:"
CHDE: "Öppis isch schief gange :confused:"
httpErrors:
403:
EN:
- "Seems like i don't have enough permission to that :confused:"
CHDE:
- "Gseht danach us das ich nid gnueg recht han zum das mache :confused:"
EN: "Seems like i don't have enough permission to that :confused:"
CHDE: "Gseht danach us das ich nid gnueg recht han zum das mache :confused:"
choose:
Choice:
EN:
- "I Choose **{0}**"
CHDE:
- "I nimme **{0}**"
EN: "I Choose **{0}**"
CHDE: "I nimme **{0}**"
good:
CannotChangeOwn:
EN:
- "Sorry {0}, but you can't give yourself karma"
CHDE:
- "Sorry {0}, aber du chasch dr selber kei karma geh"
EN: "Sorry {0}, but you can't give yourself karma"
CHDE: "Sorry {0}, aber du chasch dr selber kei karma geh"
WaitUntill:
EN:
- "Sorry {0}, but you have to wait {1} before you can give karma again..."
CHDE:
- "Sorry {0}, aber du musch no {1} warte bisch d wieder karma chasch geh..."
EN: "Sorry {0}, but you have to wait {1} before you can give karma again..."
CHDE: "Sorry {0}, aber du musch no {1} warte bisch d wieder karma chasch geh..."
Increased:
EN:
- "Karma gained"
CHDE:
- "Karma becho"
EN: "Karma gained"
CHDE: "Karma becho"
By:
EN:
- "By"
CHDE:
- "Vo"
EN: "By"
CHDE: "Vo"
Amount:
EN:
- "Amount"
CHDE:
- "Mengi"
EN: "Amount"
CHDE: "Mengi"
Current:
EN:
- "Current"
CHDE:
- "Jetzt"
EN: "Current"
CHDE: "Jetzt"
bad:
CannotChangeOwn:
EN:
- "Sorry {0}, but you can't lower your own karma"
CHDE:
- "Sorry {0}, aber du chasch dr din eigete karma nid weg neh"
EN: "Sorry {0}, but you can't lower your own karma"
CHDE: "Sorry {0}, aber du chasch dr din eigete karma nid weg neh"
WaitUntill:
EN:
- "Sorry {0}, but you have to wait {1} before you can lower karma again..."
CHDE:
- "Sorry {0}, aber du musch no {1} warte bisch d wieder karma chasch senke..."
EN: "Sorry {0}, but you have to wait {1} before you can lower karma again..."
CHDE: "Sorry {0}, aber du musch no {1} warte bisch d wieder karma chasch senke..."
Decreased:
EN:
- "Karma lowered"
CHDE:
- "Karma gsenkt"
EN: "Karma lowered"
CHDE: "Karma gsenkt"
By:
EN:
- "By"
CHDE:
- "Vo"
EN: "By"
CHDE: "Vo"
Amount:
EN:
- "Amount"
CHDE:
- "Mengi"
EN: "Amount"
CHDE: "Mengi"
Current:
EN:
- "Current"
CHDE:
- "Jetzt"
EN: "Current"
CHDE: "Jetzt"
roll:
Rolled:
EN:
- "{0}, you rolled {1}, your guess was {2}"
CHDE:
- "{0}, du hesch {1} grollt und hesch {2} grate"
EN: "{0}, you rolled {1}, your guess was {2}"
CHDE: "{0}, du hesch {1} grollt und hesch {2} grate"
Gratz:
EN:
- "Congratulations {0}, your guess was correct!"
CHDE:
- "Gratuliere {0}, du hesch richtig grate!"
EN: "Congratulations {0}, your guess was correct!"
CHDE: "Gratuliere {0}, du hesch richtig grate!"
RolledNoGuess:
EN:
- "{0}, you rolled {1}"
CHDE:
- "{0}, du hesch {1} grollt"
EN: "{0}, you rolled {1}"
CHDE: "{0}, du hesch {1} grollt"
NoPrevGuess:
EN:
- ":red_circle: {0}, you can't guess the same number again"
CHDE:
- ":red_circle: {0}, du chasch nid nomol es gliche rate"
EN: ":red_circle: {0}, you can't guess the same number again"
CHDE: ":red_circle: {0}, du chasch nid nomol es gliche rate"
cookies:
GetCookies:
EN:
- "You got {0} cookies, there are now {1} cookies in you cookie jar"
CHDE:
- "Du häsch {0} guetzli becho, du häsch jetzt {1} guetzli ih dr büchse"
EN: "You got {0} cookies, there are now {1} cookies in you cookie jar"
CHDE: "Du häsch {0} guetzli becho, du häsch jetzt {1} guetzli ih dr büchse"
WaitForMoreCookies:
EN:
- "You already got cookies in the last 24 hours, you can have more cookies in {0}"
CHDE:
- "Du hesch scho guetzli becho ih de letzti 24 stund, du chasch meh ha in {0}"
EN: "You already got cookies in the last 24 hours, you can have more cookies in {0}"
CHDE: "Du hesch scho guetzli becho ih de letzti 24 stund, du chasch meh ha in {0}"
InYourJar:
EN:
- "There are {0} cookies in you cookie jar"
CHDE:
- "Es hät {0} guetzli ih dineri büchs"
EN: "There are {0} cookies in you cookie jar"
CHDE: "Es hät {0} guetzli ih dineri büchs"
Given:
EN:
- "You gave {0} cookies to {1}"
CHDE:
- "Du hesch {1} {0} guetzli geh"
EN: "You gave {0} cookies to {1}"
CHDE: "Du hesch {1} {0} guetzli geh"
NotEnoughToGive:
EN:
- "You don't have enough cookies"
CHDE:
- "Du hesch nid gnueg guetzli"
EN: "You don't have enough cookies"
CHDE: "Du hesch nid gnueg guetzli"
NotEnoughCookiesToEat:
EN:
- "Your cookie jar looks almost empty, you should probably not eat a cookie"
CHDE:
- "Du hesch chuum no guetzli ih dineri büchs, du sötsch warschinli keini esse"
EN: "Your cookie jar looks almost empty, you should probably not eat a cookie"
CHDE: "Du hesch chuum no guetzli ih dineri büchs, du sötsch warschinli keini esse"
AteCookies:
EN:
- "You ate {0} cookies, you've only got {1} cookies left"
CHDE:
- "Du hesch {0} guetzli gesse und hesch jezt no {1} übrig"
EN: "You ate {0} cookies, you've only got {1} cookies left"
CHDE: "Du hesch {0} guetzli gesse und hesch jezt no {1} übrig"
role:
NoRolesConfigured:
EN:
- "There are no roles configured for this server"
CHDE:
- "Es sind kei rolle für dä server konfiguriert"
EN: "There are no roles configured for this server"
CHDE: "Es sind kei rolle für dä server konfiguriert"
ListHeader:
EN:
- "**Self Service Roles on {0}**"
CHDE:
- "**Self Service Rollene uf {0}**"
EN: "**Self Service Roles on {0}**"
CHDE: "**Self Service Rollene uf {0}**"
ListInstruction:
EN:
- "To get a role, use `!role [name]`"
CHDE:
- "Zum ä rolle becho, schriib `!role [name]`"
EN: "To get a role, use `!role [name]`"
CHDE: "Zum ä rolle becho, schriib `!role [name]`"
RoleNotFound:
EN:
- "That role doesn't exist or is not on the whitelist"
CHDE:
- "Die rolle gids nid or isch nid uf dr whitelist"
EN: "That role doesn't exist or is not on the whitelist"
CHDE: "Die rolle gids nid or isch nid uf dr whitelist"
RemovedUserFromRole:
EN:
- "Removed you from {0}"
CHDE:
- "Han di entfernt vo {0}"
EN: "Removed you from {0}"
CHDE: "Han di entfernt vo {0}"
AddedUserFromRole:
EN:
- "Added you to {0}"
CHDE:
- "Han di hinzue gfüegt zu {0}"
EN: "Added you to {0}"
CHDE: "Han di hinzue gfüegt zu {0}"
CannotAddManagedRole:
EN:
- "You can't add a role that is managed by discord"
CHDE:
- "Du chasch kei rolle hinzuefüge wo verwalted wird vo discord"
EN: "You can't add a role that is managed by discord"
CHDE: "Du chasch kei rolle hinzuefüge wo verwalted wird vo discord"
CannotAddDangerousRole:
EN:
- "You cannot add that role to self service because it contains one or more dangerous permissions"
CHDE:
- "Du chasch die rolle nid hinzuefüge will er ein oder mehreri gföhrlichi berechtigunge het"
EN: "You cannot add that role to self service because it contains one or more dangerous permissions"
CHDE: "Du chasch die rolle nid hinzuefüge will er ein oder mehreri gföhrlichi berechtigunge het"
AddedRoleToWhitelist:
EN:
- "Added {0} to the whitelist"
CHDE:
- "{0} isch zur whitelist hinzuegfüegt"
EN: "Added {0} to the whitelist"
CHDE: "{0} isch zur whitelist hinzuegfüegt"
RemovedRoleFromWhitelist:
EN:
- "Removed {0} from the whitelist"
CHDE:
- "{0} isch vo dr whitelist glöscht"
EN: "Removed {0} from the whitelist"
CHDE: "{0} isch vo dr whitelist glöscht"
quote:
NoQuotesFound:
EN:
- "This server doesn't seem to have any quotes yet. You can add a quote with `!quote save @user` or `!quote save <messageId>`"
CHDE:
- "Dä server het no kei quotes. Du chasch quotes hinzuefüege mit `!quote save @user` oder `!quote save <messageId>`"
EN: "This server doesn't seem to have any quotes yet. You can add a quote with `!quote save @user` or `!quote save <messageId>`"
CHDE: "Dä server het no kei quotes. Du chasch quotes hinzuefüege mit `!quote save @user` oder `!quote save <messageId>`"
CannotSaveOwnQuotes:
EN:
- "You can't save your own quotes..."
CHDE:
- "Du chasch kei quotes vo dir selber speichere..."
EN: "You can't save your own quotes..."
CHDE: "Du chasch kei quotes vo dir selber speichere..."
CannotQuoteBots:
EN:
- "You can't save quotes by a bot..."
CHDE:
- "Du chasch kei quotes vomne bot speichere..."
EN: "You can't save quotes by a bot..."
CHDE: "Du chasch kei quotes vomne bot speichere..."
QuoteAdded:
EN:
- "**Quote Added**"
CHDE:
- "**Quote hinzugfüegt**"
EN: "**Quote Added**"
CHDE: "**Quote hinzugfüegt**"
Removed:
EN:
- "**Removed #{0}**"
CHDE:
- "**#{0} glöscht**"
EN: "**Removed #{0}**"
CHDE: "**#{0} glöscht**"
NotFoundWithId:
EN:
- "I couldn't find a quote with that ID :disappointed:"
CHDE:
- "Ich chan kei quote finde mit därri ID :disappointed:"
EN: "I couldn't find a quote with that ID :disappointed:"
CHDE: "Ich chan kei quote finde mit därri ID :disappointed:"