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 public interface ITranslationHandler
{ {
Task<string> GetString(ulong guildId, string command, string stringName); 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<Dictionary<string, string>> GetDict(ICommandContext context, string command);
Task<TranslationGuildContext> GetGuildContext(ICommandContext context); Task<TranslationGuildContext> GetGuildContext(ICommandContext context);
Task<bool> SetLanguage(ulong guildId, string language); Task<bool> SetLanguage(ulong guildId, string language);

View file

@ -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, 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; 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].First() ?? "", args); return string.Format(Dict[stringToFormat] ?? "", args);
} }
public string FormatDateTimeAsRemaining(DateTimeOffset dateTime) public string FormatDateTimeAsRemaining(DateTimeOffset dateTime)
@ -54,7 +54,7 @@ namespace Geekbot.net.Lib.Localization
{ {
if (sb.Length > 0) if (sb.Length > 0)
{ {
var and = TranslationHandler.GetStrings(Language, "dateTime", "And").First(); var and = TranslationHandler.GetString(Language, "dateTime", "And");
sb.AppendFormat(" {0} ", and); sb.AppendFormat(" {0} ", and);
} }
var s = GetTimeString(TimeTypes.Seconds); var s = GetTimeString(TimeTypes.Seconds);
@ -69,13 +69,14 @@ namespace Geekbot.net.Lib.Localization
return TranslationHandler.SetLanguage(guildId, language); 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]; return number == 1 ? versions[0] : versions[1];
} }

View file

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

View file

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