WIP: rework of localized strings, instead of generic LocStr, LocStr is now a struct which contains both the key, and the values which should be put into the value's placeholders. strs' properties are now methods which take values as arguments, and properties if they don't

This commit is contained in:
Kwoth
2021-07-26 20:08:02 +02:00
parent 9d375dccee
commit 0115d35247
46 changed files with 176 additions and 273 deletions

View File

@@ -74,12 +74,6 @@ namespace NadekoBot.Modules.Games.Common
private string GetText(LocStr key)
=> _strings.GetText(key, _channel.GuildId);
private string GetText<T>(LocStr<T> key, T param)
=> _strings.GetText(key, _channel.GuildId, param);
private string GetText<T1, T2>(LocStr<T1, T2> key, T1 param, T2 param2)
=> _strings.GetText(key, _channel.GuildId, param, param2);
public string GetState()
{
@@ -104,7 +98,7 @@ namespace NadekoBot.Modules.Games.Common
var embed = _eb.Create()
.WithOkColor()
.WithDescription(Environment.NewLine + GetState())
.WithAuthor(GetText(strs.vs, _users[0], _users[1]));
.WithAuthor(GetText(strs.vs(_users[0], _users[1])));
if (!string.IsNullOrWhiteSpace(title))
embed.WithTitle(title);
@@ -114,10 +108,10 @@ namespace NadekoBot.Modules.Games.Common
if (_phase == Phase.Ended)
embed.WithFooter(GetText(strs.ttt_no_moves));
else
embed.WithFooter(GetText(strs.ttt_users_move, _users[_curUserIndex]));
embed.WithFooter(GetText(strs.ttt_users_move(_users[_curUserIndex])));
}
else
embed.WithFooter(GetText(strs.ttt_has_won, _winner));
embed.WithFooter(GetText(strs.ttt_has_won(_winner)));
return embed;
}

View File

@@ -64,12 +64,6 @@ namespace NadekoBot.Modules.Games.Common.Trivia
private string GetText(in LocStr key)
=> _strings.GetText(key, Channel.GuildId);
private string GetText<T>(in LocStr<T> key, T param1)
=> _strings.GetText(key, Channel.GuildId, param1);
private string GetText<T1, T2>(in LocStr<T1, T2> key, T1 param1, T2 param2)
=> _strings.GetText(key, Channel.GuildId, param1, param2);
public async Task StartGame()
{
@@ -99,7 +93,7 @@ namespace NadekoBot.Modules.Games.Common.Trivia
.AddField(GetText(strs.question), CurrentQuestion.Question);
if (showHowToQuit)
questionEmbed.WithFooter(GetText(strs.trivia_quit, _quitCommand));
questionEmbed.WithFooter(GetText(strs.trivia_quit(_quitCommand)));
if (Uri.IsWellFormedUriString(CurrentQuestion.ImageUrl, UriKind.Absolute))
questionEmbed.WithImageUrl(CurrentQuestion.ImageUrl);
@@ -159,7 +153,7 @@ namespace NadekoBot.Modules.Games.Common.Trivia
{
var embed = _eb.Create().WithErrorColor()
.WithTitle(GetText(strs.trivia_game))
.WithDescription(GetText(strs.trivia_times_up, Format.Bold(CurrentQuestion.Answer)));
.WithDescription(GetText(strs.trivia_times_up(Format.Bold(CurrentQuestion.Answer))));
if (Uri.IsWellFormedUriString(CurrentQuestion.AnswerImageUrl, UriKind.Absolute))
embed.WithImageUrl(CurrentQuestion.AnswerImageUrl);
@@ -246,9 +240,9 @@ namespace NadekoBot.Modules.Games.Common.Trivia
{
var embedS = _eb.Create().WithOkColor()
.WithTitle(GetText(strs.trivia_game))
.WithDescription(GetText(strs.trivia_win,
.WithDescription(GetText(strs.trivia_win(
guildUser.Mention,
Format.Bold(CurrentQuestion.Answer)));
Format.Bold(CurrentQuestion.Answer))));
if (Uri.IsWellFormedUriString(CurrentQuestion.AnswerImageUrl, UriKind.Absolute))
embedS.WithImageUrl(CurrentQuestion.AnswerImageUrl);
await Channel.EmbedAsync(embedS).ConfigureAwait(false);
@@ -264,7 +258,7 @@ namespace NadekoBot.Modules.Games.Common.Trivia
}
var embed = _eb.Create().WithOkColor()
.WithTitle(GetText(strs.trivia_game))
.WithDescription(GetText(strs.trivia_guess, guildUser.Mention, Format.Bold(CurrentQuestion.Answer)));
.WithDescription(GetText(strs.trivia_guess(guildUser.Mention, Format.Bold(CurrentQuestion.Answer))));
if (Uri.IsWellFormedUriString(CurrentQuestion.AnswerImageUrl, UriKind.Absolute))
embed.WithImageUrl(CurrentQuestion.AnswerImageUrl);
await Channel.EmbedAsync(embed).ConfigureAwait(false);
@@ -283,7 +277,7 @@ namespace NadekoBot.Modules.Games.Common.Trivia
foreach (var kvp in Users.OrderByDescending(kvp => kvp.Value))
{
sb.AppendLine(GetText(strs.trivia_points, Format.Bold(kvp.Key.ToString()), kvp.Value).SnPl(kvp.Value));
sb.AppendLine(GetText(strs.trivia_points(Format.Bold(kvp.Key.ToString()), kvp.Value).SnPl(kvp.Value)));
}
return sb.ToString();