From 97d32a46b6726452993756e806c98001acc28eed Mon Sep 17 00:00:00 2001 From: Kwoth Date: Tue, 14 Feb 2017 17:49:15 +0100 Subject: [PATCH] localization commands localized :OOOO localiception! --- .../Commands/LocalizationCommands.cs | 35 ++++++------ .../Resources/ResponseStrings.Designer.cs | 55 +++++++++++++++++++ src/NadekoBot/Resources/ResponseStrings.resx | 34 ++++++++++++ 3 files changed, 105 insertions(+), 19 deletions(-) diff --git a/src/NadekoBot/Modules/Administration/Commands/LocalizationCommands.cs b/src/NadekoBot/Modules/Administration/Commands/LocalizationCommands.cs index 70fcd6c6..3b3467f6 100644 --- a/src/NadekoBot/Modules/Administration/Commands/LocalizationCommands.cs +++ b/src/NadekoBot/Modules/Administration/Commands/LocalizationCommands.cs @@ -7,7 +7,6 @@ using System.Collections.Generic; using System.Collections.Immutable; using System.Globalization; using System.Linq; -using System.Text; using System.Threading.Tasks; namespace NadekoBot.Modules.Administration @@ -17,7 +16,7 @@ namespace NadekoBot.Modules.Administration [Group] public class LocalizationCommands : NadekoSubmodule { - private ImmutableDictionary SupportedLocales { get; } = new Dictionary() + private ImmutableDictionary supportedLocales { get; } = new Dictionary() { {"en-US", "English, United States" }, {"sr-cyrl-rs", "Serbian, Cyrillic" } @@ -28,7 +27,8 @@ namespace NadekoBot.Modules.Administration public async Task LanguageSet() { var cul = NadekoBot.Localization.GetCultureInfo(Context.Guild); - await Context.Channel.SendConfirmAsync("This server's language is set to " + Format.Bold(cul.ToString()) + " - " + Format.Bold(cul.NativeName)).ConfigureAwait(false); + await ReplyConfirmLocalized("lang_set_show", Format.Bold(cul.ToString()), Format.Bold(cul.NativeName)) + .ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] @@ -36,9 +36,9 @@ namespace NadekoBot.Modules.Administration [RequireUserPermission(GuildPermission.Administrator)] public async Task LanguageSet(string name) { - CultureInfo ci = null; try { + CultureInfo ci; if (name.Trim().ToLowerInvariant() == "default") { NadekoBot.Localization.RemoveGuildCulture(Context.Guild); @@ -50,12 +50,11 @@ namespace NadekoBot.Modules.Administration NadekoBot.Localization.SetGuildCulture(Context.Guild, ci); } - await Context.Channel.SendConfirmAsync($"Your server's locale is now {Format.Bold(ci.ToString())} - {Format.Bold(ci.NativeName)}.").ConfigureAwait(false); + await ReplyConfirmLocalized("lang_set", Format.Bold(ci.ToString()), Format.Bold(ci.NativeName)).ConfigureAwait(false); } - catch(Exception) { - - //_log.warn(ex); - await Context.Channel.SendConfirmAsync($"Failed setting locale. Revisit this command's help.").ConfigureAwait(false); + catch(Exception) + { + await ReplyErrorLocalized("lang_set_fail").ConfigureAwait(false); } } @@ -63,17 +62,16 @@ namespace NadekoBot.Modules.Administration public async Task LanguageSetDefault() { var cul = NadekoBot.Localization.DefaultCultureInfo; - await Context.Channel.SendConfirmAsync("Bot's language is set to " + cul + " - " + cul.NativeName).ConfigureAwait(false); - return; + await ReplyConfirmLocalized("lang_set_bot_show", cul, cul.NativeName).ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] [OwnerOnly] public async Task LanguageSetDefault(string name) { - CultureInfo ci = null; try { + CultureInfo ci; if (name.Trim().ToLowerInvariant() == "default") { NadekoBot.Localization.ResetDefaultCulture(); @@ -84,22 +82,21 @@ namespace NadekoBot.Modules.Administration ci = new CultureInfo(name); NadekoBot.Localization.SetDefaultCulture(ci); } - - await Context.Channel.SendConfirmAsync($"Bot's default locale is now {Format.Bold(ci.ToString())} - {Format.Bold(ci.NativeName)}.").ConfigureAwait(false); + await ReplyConfirmLocalized("lang_set_bot", Format.Bold(ci.ToString()), Format.Bold(ci.NativeName)).ConfigureAwait(false); } catch (Exception) { - //_log.warn(ex); - await Context.Channel.SendConfirmAsync($"Failed setting locale. Revisit this command's help.").ConfigureAwait(false); + await ReplyErrorLocalized("lang_set_fail").ConfigureAwait(false); } } [NadekoCommand, Usage, Description, Aliases] [OwnerOnly] - public async Task LanguagesList(string name) + public async Task LanguagesList() { - await Context.Channel.SendConfirmAsync("List Of Languages", - string.Join("\n", SupportedLocales.Select(x => $"{Format.Code(x.Key)} => {x.Value}"))); + await ReplyConfirmLocalized("lang_list", + string.Join("\n", supportedLocales.Select(x => $"{Format.Code(x.Key)} => {x.Value}"))) + .ConfigureAwait(false); } } } diff --git a/src/NadekoBot/Resources/ResponseStrings.Designer.cs b/src/NadekoBot/Resources/ResponseStrings.Designer.cs index c2109c7d..48733a24 100644 --- a/src/NadekoBot/Resources/ResponseStrings.Designer.cs +++ b/src/NadekoBot/Resources/ResponseStrings.Designer.cs @@ -122,6 +122,61 @@ namespace NadekoBot.Resources { } } + /// + /// Looks up a localized string similar to List Of Languages + ///{0}. + /// + public static string administration_lang_list { + get { + return ResourceManager.GetString("administration_lang_list", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Your server's locale is now {0} - {1}. + /// + public static string administration_lang_set { + get { + return ResourceManager.GetString("administration_lang_set", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Bot's default locale is now {0} - {1}. + /// + public static string administration_lang_set_bot { + get { + return ResourceManager.GetString("administration_lang_set_bot", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Bot's language is set to {0} - {0}. + /// + public static string administration_lang_set_bot_show { + get { + return ResourceManager.GetString("administration_lang_set_bot_show", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Failed setting locale. Revisit this command's help.. + /// + public static string administration_lang_set_fail { + get { + return ResourceManager.GetString("administration_lang_set_fail", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to This server's language is set to {0} - {0}. + /// + public static string administration_lang_set_show { + get { + return ResourceManager.GetString("administration_lang_set_show", resourceCulture); + } + } + /// /// Looks up a localized string similar to I don't have the permission necessary for that most likely.. /// diff --git a/src/NadekoBot/Resources/ResponseStrings.resx b/src/NadekoBot/Resources/ResponseStrings.resx index 7eeb75f1..ff566d6c 100644 --- a/src/NadekoBot/Resources/ResponseStrings.resx +++ b/src/NadekoBot/Resources/ResponseStrings.resx @@ -304,6 +304,40 @@ **Auto assign role** on user join is now **enabled**. + + DM from + + + I will forward DMs to all owners. + + + I will forward DMs only to the first owner. + + + I will forward DMs from now on. + + + I will stop forwarding DMs from now on. + + + List Of Languages +{0} + + + Your server's locale is now {0} - {1} + + + Bot's default locale is now {0} - {1} + + + Bot's language is set to {0} - {0} + + + Failed setting locale. Revisit this command's help. + + + This server's language is set to {0} - {0} + I don't have the permission necessary for that most likely.