From a97117bf7fa3ad2f356723bc0b07981ea46e65ff Mon Sep 17 00:00:00 2001 From: Sella-GH <147769367+Sella-GH@users.noreply.github.com> Date: Thu, 8 Aug 2024 00:32:02 +0200 Subject: [PATCH 1/7] Implement basic command localization --- CHANGELOG.md | 7 +- src/AzzyBot.Bot/AzzyBot.Bot.csproj | 42 ++++++ src/AzzyBot.Bot/Commands/AdminCommands.cs | 14 +- .../CommandDescriptions.Designer.cs | 108 ++++++++++++++ .../CommandDescriptions.de-DE.resx | 135 +++++++++++++++++ .../Localization/CommandDescriptions.resx | 135 +++++++++++++++++ .../Localization/CommandLocalizer.cs | 51 +++++++ .../Localization/CommandNames.Designer.cs | 117 +++++++++++++++ .../Localization/CommandNames.de-DE.resx | 138 ++++++++++++++++++ .../Localization/CommandNames.resx | 138 ++++++++++++++++++ .../CommandParamDescriptions.Designer.cs | 63 ++++++++ .../CommandParamDescriptions.resx | 101 +++++++++++++ .../CommandParamNames.Designer.cs | 63 ++++++++ .../Localization/CommandParamNames.resx | 101 +++++++++++++ 14 files changed, 1205 insertions(+), 8 deletions(-) create mode 100644 src/AzzyBot.Bot/Localization/CommandDescriptions.Designer.cs create mode 100644 src/AzzyBot.Bot/Localization/CommandDescriptions.de-DE.resx create mode 100644 src/AzzyBot.Bot/Localization/CommandDescriptions.resx create mode 100644 src/AzzyBot.Bot/Localization/CommandLocalizer.cs create mode 100644 src/AzzyBot.Bot/Localization/CommandNames.Designer.cs create mode 100644 src/AzzyBot.Bot/Localization/CommandNames.de-DE.resx create mode 100644 src/AzzyBot.Bot/Localization/CommandNames.resx create mode 100644 src/AzzyBot.Bot/Localization/CommandParamDescriptions.Designer.cs create mode 100644 src/AzzyBot.Bot/Localization/CommandParamDescriptions.resx create mode 100644 src/AzzyBot.Bot/Localization/CommandParamNames.Designer.cs create mode 100644 src/AzzyBot.Bot/Localization/CommandParamNames.resx diff --git a/CHANGELOG.md b/CHANGELOG.md index f67812eb..04d286ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,7 @@ -## 2.0.0-preview7 +## 2.0.0-preview8 + + +## 2.0.0-preview7 2024-08-06 ### Breaking Changes - Your Database needs a complete reset, please DROP it and start from scratch - This is probably the last time it needs to be dropped by now @@ -17,7 +20,7 @@ - `player play` to select the provider and provide a url - `player pause` to pause the player - `player resume` to resume the player - - `player queue-clear` to clear the whole queue or only one song + - `player queue-clear` to clear the whole queue or only one songow - `player skip` to skip a song - `player history` to view the song history - `player queue` to view the song queue diff --git a/src/AzzyBot.Bot/AzzyBot.Bot.csproj b/src/AzzyBot.Bot/AzzyBot.Bot.csproj index ab7f8aad..afa00916 100644 --- a/src/AzzyBot.Bot/AzzyBot.Bot.csproj +++ b/src/AzzyBot.Bot/AzzyBot.Bot.csproj @@ -67,6 +67,48 @@ + + + True + True + CommandDescriptions.resx + + + True + True + CommandNames.resx + + + True + True + CommandParamDescriptions.resx + + + True + True + CommandParamNames.resx + + + + + + ResXFileCodeGenerator + CommandDescriptions.Designer.cs + + + ResXFileCodeGenerator + CommandNames.Designer.cs + + + ResXFileCodeGenerator + CommandParamDescriptions.Designer.cs + + + ResXFileCodeGenerator + CommandParamNames.Designer.cs + + + PreserveNewest diff --git a/src/AzzyBot.Bot/Commands/AdminCommands.cs b/src/AzzyBot.Bot/Commands/AdminCommands.cs index c12b18d3..c2af1fd9 100644 --- a/src/AzzyBot.Bot/Commands/AdminCommands.cs +++ b/src/AzzyBot.Bot/Commands/AdminCommands.cs @@ -8,6 +8,7 @@ using System.Threading.Tasks; using AzzyBot.Bot.Commands.Autocompletes; using AzzyBot.Bot.Commands.Choices; +using AzzyBot.Bot.Localization; using AzzyBot.Bot.Services; using AzzyBot.Bot.Utilities; using AzzyBot.Bot.Utilities.Helpers; @@ -19,6 +20,7 @@ using DSharpPlus.Commands.ContextChecks; using DSharpPlus.Commands.Processors.SlashCommands; using DSharpPlus.Commands.Processors.SlashCommands.ArgumentModifiers; +using DSharpPlus.Commands.Processors.SlashCommands.Localization; using DSharpPlus.Entities; using Microsoft.Extensions.Logging; @@ -27,7 +29,7 @@ namespace AzzyBot.Bot.Commands; [SuppressMessage("Design", "CA1034:Nested types should not be visible", Justification = "DSharpPlus best practice")] public sealed class AdminCommands { - [Command("admin"), RequireGuild, RequireApplicationOwner, RequirePermissions(DiscordPermissions.None, DiscordPermissions.Administrator)] + [Command("admin"), RequireGuild, RequireApplicationOwner, RequirePermissions(DiscordPermissions.None, DiscordPermissions.Administrator), InteractionLocalizer] public sealed class AdminGroup(ILogger logger, DbActions dbActions, DiscordBotService botService, DiscordBotServiceHost botServiceHost) { private readonly DbActions _dbActions = dbActions; @@ -35,7 +37,7 @@ public sealed class AdminGroup(ILogger logger, DbActions dbActions, private readonly DiscordBotServiceHost _botServiceHost = botServiceHost; private readonly ILogger _logger = logger; - [Command("change-bot-status"), Description("Change the global bot status according to your likes.")] + [Command("change-bot-status"), Description("Change the global bot status according to your likes."), InteractionLocalizer] public async ValueTask ChangeStatusAsync ( SlashCommandContext context, @@ -64,7 +66,7 @@ public async ValueTask ChangeStatusAsync } } - [Command("get-joined-server"), Description("Displays all servers the bot is in.")] + [Command("get-joined-server"), Description("Displays all servers the bot is in."), InteractionLocalizer] public async ValueTask GetJoinedGuildsAsync ( SlashCommandContext context, @@ -117,7 +119,7 @@ public async ValueTask GetJoinedGuildsAsync await context.EditResponseAsync(stringBuilder.ToString()); } - [Command("remove-joined-server"), Description("Removes the bot from a server.")] + [Command("remove-joined-server"), Description("Removes the bot from a server."), InteractionLocalizer] public async ValueTask RemoveJoinedGuildAsync ( SlashCommandContext context, @@ -149,7 +151,7 @@ public async ValueTask RemoveJoinedGuildAsync await context.EditResponseAsync($"I left **{guild.Name}** ({guild.Id})."); } - [Command("send-bot-wide-message"), Description("Sends a message to all servers the bot is in.")] + [Command("send-bot-wide-message"), Description("Sends a message to all servers the bot is in."), InteractionLocalizer] public async ValueTask SendBotWideMessageAsync ( SlashCommandContext context, @@ -195,7 +197,7 @@ public async ValueTask SendBotWideMessageAsync await context.EditResponseAsync(GeneralStrings.MessageSentToAll); } - [Command("view-logs"), Description("View the logs of the bot.")] + [Command("view-logs"), Description("View the logs of the bot."), InteractionLocalizer] public async ValueTask ViewLogsAsync ( SlashCommandContext context, diff --git a/src/AzzyBot.Bot/Localization/CommandDescriptions.Designer.cs b/src/AzzyBot.Bot/Localization/CommandDescriptions.Designer.cs new file mode 100644 index 00000000..fd71813d --- /dev/null +++ b/src/AzzyBot.Bot/Localization/CommandDescriptions.Designer.cs @@ -0,0 +1,108 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace AzzyBot.Bot.Localization { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class CommandDescriptions { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal CommandDescriptions() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("AzzyBot.Bot.Localization.CommandDescriptions", typeof(CommandDescriptions).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to Change the global bot status according to your likes.. + /// + internal static string change_bot_status { + get { + return ResourceManager.GetString("change-bot-status", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Displays all servers the bot is in.. + /// + internal static string get_joined_server { + get { + return ResourceManager.GetString("get-joined-server", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Removes the bot from a server.. + /// + internal static string remove_joined_server { + get { + return ResourceManager.GetString("remove-joined-server", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Sends a message to all servers the bot is in.. + /// + internal static string send_bot_wide_message { + get { + return ResourceManager.GetString("send-bot-wide-message", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to View the logs of the bot.. + /// + internal static string view_logs { + get { + return ResourceManager.GetString("view-logs", resourceCulture); + } + } + } +} diff --git a/src/AzzyBot.Bot/Localization/CommandDescriptions.de-DE.resx b/src/AzzyBot.Bot/Localization/CommandDescriptions.de-DE.resx new file mode 100644 index 00000000..66b1b0fb --- /dev/null +++ b/src/AzzyBot.Bot/Localization/CommandDescriptions.de-DE.resx @@ -0,0 +1,135 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Ändert den globalen Status des Bots nach deinen Wünschen + + + Zeigt alle beigetretenen Server an. + + + Entfernt den Bot von einem beigetretenen Server. + + + Sendet eine Nachricht an alle Server, in denen der Bot ist. + + + Zeigt die Logs des Bots an. + + \ No newline at end of file diff --git a/src/AzzyBot.Bot/Localization/CommandDescriptions.resx b/src/AzzyBot.Bot/Localization/CommandDescriptions.resx new file mode 100644 index 00000000..3b36e2df --- /dev/null +++ b/src/AzzyBot.Bot/Localization/CommandDescriptions.resx @@ -0,0 +1,135 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Change the global bot status according to your likes. + + + Displays all servers the bot is in. + + + Removes the bot from a server. + + + Sends a message to all servers the bot is in. + + + View the logs of the bot. + + \ No newline at end of file diff --git a/src/AzzyBot.Bot/Localization/CommandLocalizer.cs b/src/AzzyBot.Bot/Localization/CommandLocalizer.cs new file mode 100644 index 00000000..995683f7 --- /dev/null +++ b/src/AzzyBot.Bot/Localization/CommandLocalizer.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Resources; +using System.Threading.Tasks; +using DSharpPlus.Commands.Processors.SlashCommands.Localization; + +namespace AzzyBot.Bot.Localization; + +public sealed class CommandLocalizer : IInteractionLocalizer +{ + public ValueTask> TranslateAsync(string fullSymbolName) + { + ArgumentException.ThrowIfNullOrWhiteSpace(fullSymbolName, nameof(fullSymbolName)); + + bool topLevelCommand = false; + string symbolName = string.Empty; + string[] parts = fullSymbolName.Split('.'); + if (parts.Length is 2) + { + symbolName = parts[0]; + topLevelCommand = true; + } + else if (parts.Length is 3) + { + symbolName = parts[1]; + } + else if (parts.Length is 4) + { + symbolName = parts[2]; + } + + // Use this as reference for the LCID: + // https://learn.microsoft.com/en-us/openspecs/office_standards/ms-oe376/6c085406-a698-4e12-9d4d-c3b0ee3dbc4a + Dictionary locales = new(2); + if (fullSymbolName.EndsWith(".name", StringComparison.OrdinalIgnoreCase)) + { + ResourceManager commandNames = new(typeof(CommandNames)); + locales.Add(DiscordLocale.de, commandNames.GetString(symbolName, new CultureInfo(1031)) ?? string.Empty); + locales.Add(DiscordLocale.en_US, symbolName); + } + else if (fullSymbolName.EndsWith(".description", StringComparison.OrdinalIgnoreCase) && !topLevelCommand) + { + ResourceManager commandDescriptions = new(typeof(CommandDescriptions)); + locales.Add(DiscordLocale.de, commandDescriptions.GetString(symbolName, new CultureInfo(1031)) ?? string.Empty); + locales.Add(DiscordLocale.en_US, commandDescriptions.GetString(symbolName, new CultureInfo(1033)) ?? string.Empty); + } + + return new ValueTask>(locales); + } +} diff --git a/src/AzzyBot.Bot/Localization/CommandNames.Designer.cs b/src/AzzyBot.Bot/Localization/CommandNames.Designer.cs new file mode 100644 index 00000000..28815189 --- /dev/null +++ b/src/AzzyBot.Bot/Localization/CommandNames.Designer.cs @@ -0,0 +1,117 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace AzzyBot.Bot.Localization { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class CommandNames { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal CommandNames() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("AzzyBot.Bot.Localization.CommandNames", typeof(CommandNames).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to admin. + /// + internal static string admin { + get { + return ResourceManager.GetString("admin", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to change-bot-status. + /// + internal static string change_bot_status { + get { + return ResourceManager.GetString("change-bot-status", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to get-joined-server. + /// + internal static string get_joined_server { + get { + return ResourceManager.GetString("get-joined-server", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to remove-joined-server. + /// + internal static string remove_joined_server { + get { + return ResourceManager.GetString("remove-joined-server", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to send-bot-wide-message. + /// + internal static string send_bot_wide_message { + get { + return ResourceManager.GetString("send-bot-wide-message", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to view-logs. + /// + internal static string view_logs { + get { + return ResourceManager.GetString("view-logs", resourceCulture); + } + } + } +} diff --git a/src/AzzyBot.Bot/Localization/CommandNames.de-DE.resx b/src/AzzyBot.Bot/Localization/CommandNames.de-DE.resx new file mode 100644 index 00000000..d8933624 --- /dev/null +++ b/src/AzzyBot.Bot/Localization/CommandNames.de-DE.resx @@ -0,0 +1,138 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + administrator + + + bot-status-ändern + + + zeige-beigetretenen-server + + + entferne-beigetretenen-server + + + sende-bot-weite-nachricht + + + zeige-logs + + \ No newline at end of file diff --git a/src/AzzyBot.Bot/Localization/CommandNames.resx b/src/AzzyBot.Bot/Localization/CommandNames.resx new file mode 100644 index 00000000..9b2bf2c1 --- /dev/null +++ b/src/AzzyBot.Bot/Localization/CommandNames.resx @@ -0,0 +1,138 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + admin + + + change-bot-status + + + get-joined-server + + + remove-joined-server + + + send-bot-wide-message + + + view-logs + + \ No newline at end of file diff --git a/src/AzzyBot.Bot/Localization/CommandParamDescriptions.Designer.cs b/src/AzzyBot.Bot/Localization/CommandParamDescriptions.Designer.cs new file mode 100644 index 00000000..0615d12c --- /dev/null +++ b/src/AzzyBot.Bot/Localization/CommandParamDescriptions.Designer.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace AzzyBot.Bot.Localization { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class CommandParamDescriptions { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal CommandParamDescriptions() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("AzzyBot.Bot.Localization.CommandParamDescriptions", typeof(CommandParamDescriptions).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } +} diff --git a/src/AzzyBot.Bot/Localization/CommandParamDescriptions.resx b/src/AzzyBot.Bot/Localization/CommandParamDescriptions.resx new file mode 100644 index 00000000..4fdb1b6a --- /dev/null +++ b/src/AzzyBot.Bot/Localization/CommandParamDescriptions.resx @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/src/AzzyBot.Bot/Localization/CommandParamNames.Designer.cs b/src/AzzyBot.Bot/Localization/CommandParamNames.Designer.cs new file mode 100644 index 00000000..5e86f527 --- /dev/null +++ b/src/AzzyBot.Bot/Localization/CommandParamNames.Designer.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace AzzyBot.Bot.Localization { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class CommandParamNames { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal CommandParamNames() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("AzzyBot.Bot.Localization.CommandParamNames", typeof(CommandParamNames).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } +} diff --git a/src/AzzyBot.Bot/Localization/CommandParamNames.resx b/src/AzzyBot.Bot/Localization/CommandParamNames.resx new file mode 100644 index 00000000..4fdb1b6a --- /dev/null +++ b/src/AzzyBot.Bot/Localization/CommandParamNames.resx @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file From 1d44019cf2cc82bd860b93156714a81489b4eff8 Mon Sep 17 00:00:00 2001 From: Sella-GH <147769367+Sella-GH@users.noreply.github.com> Date: Thu, 8 Aug 2024 01:40:08 +0200 Subject: [PATCH 2/7] Expand to parameters --- src/AzzyBot.Bot/Commands/AdminCommands.cs | 10 +- .../Localization/CommandLocalizer.cs | 45 ++-- .../CommandParamDescriptions.Designer.cs | 45 ++++ .../CommandParamDescriptions.de-DE.resx | 135 +++++++++++ .../CommandParamDescriptions.resx | 228 ++++++++++-------- .../CommandParamNames.Designer.cs | 45 ++++ .../Localization/CommandParamNames.de-DE.resx | 135 +++++++++++ .../Localization/CommandParamNames.resx | 228 ++++++++++-------- 8 files changed, 657 insertions(+), 214 deletions(-) create mode 100644 src/AzzyBot.Bot/Localization/CommandParamDescriptions.de-DE.resx create mode 100644 src/AzzyBot.Bot/Localization/CommandParamNames.de-DE.resx diff --git a/src/AzzyBot.Bot/Commands/AdminCommands.cs b/src/AzzyBot.Bot/Commands/AdminCommands.cs index c2af1fd9..696ed8d7 100644 --- a/src/AzzyBot.Bot/Commands/AdminCommands.cs +++ b/src/AzzyBot.Bot/Commands/AdminCommands.cs @@ -41,11 +41,11 @@ public sealed class AdminGroup(ILogger logger, DbActions dbActions, public async ValueTask ChangeStatusAsync ( SlashCommandContext context, - [Description("Choose the activity type which the bot should have."), SlashChoiceProvider] int activity = 1, - [Description("Choose the status type which the bot should have."), SlashChoiceProvider] int status = 2, - [Description("Enter a custom doing which is added after the activity type."), MinMaxLength(0, 128)] string doing = "Music", - [Description("Enter a custom url. Only usable when having activity type streaming or watching!")] Uri? url = null, - [Description("Reset the bot status to default."), SlashChoiceProvider] int reset = 0 + [Description("Choose the activity type which the bot should have."), SlashChoiceProvider, InteractionLocalizer] int activity = 1, + [Description("Choose the status type which the bot should have."), SlashChoiceProvider, InteractionLocalizer] int status = 2, + [Description("Enter a custom doing which is added after the activity type."), MinMaxLength(0, 128), InteractionLocalizer] string doing = "Music", + [Description("Enter a custom url. Only usable when having activity type streaming or watching!"), InteractionLocalizer] Uri? url = null, + [Description("Reset the bot status to default."), SlashChoiceProvider, InteractionLocalizer] int reset = 0 ) { ArgumentNullException.ThrowIfNull(context, nameof(context)); diff --git a/src/AzzyBot.Bot/Localization/CommandLocalizer.cs b/src/AzzyBot.Bot/Localization/CommandLocalizer.cs index 995683f7..7c42783e 100644 --- a/src/AzzyBot.Bot/Localization/CommandLocalizer.cs +++ b/src/AzzyBot.Bot/Localization/CommandLocalizer.cs @@ -7,43 +7,58 @@ namespace AzzyBot.Bot.Localization; -public sealed class CommandLocalizer : IInteractionLocalizer +public sealed class CommandLocalizer() : IInteractionLocalizer { public ValueTask> TranslateAsync(string fullSymbolName) { ArgumentException.ThrowIfNullOrWhiteSpace(fullSymbolName, nameof(fullSymbolName)); bool topLevelCommand = false; + bool isParameter = false; string symbolName = string.Empty; - string[] parts = fullSymbolName.Split('.'); - if (parts.Length is 2) + string[] parts; + if (!fullSymbolName.Contains("parameters", StringComparison.OrdinalIgnoreCase)) { - symbolName = parts[0]; - topLevelCommand = true; + parts = fullSymbolName.Split('.'); + if (parts.Length is 2) + { + symbolName = parts[0]; + topLevelCommand = true; + } + else if (parts.Length is 3) + { + symbolName = parts[1]; + } + else if (parts.Length is 4) + { + symbolName = parts[2]; + } } - else if (parts.Length is 3) + else { + parts = fullSymbolName.Split("parameters"); + parts = parts[1].Split('.'); symbolName = parts[1]; + isParameter = true; } - else if (parts.Length is 4) - { - symbolName = parts[2]; - } + + if (string.IsNullOrWhiteSpace(symbolName)) + throw new InvalidOperationException("Symbol name cannot be null or whitespace."); // Use this as reference for the LCID: // https://learn.microsoft.com/en-us/openspecs/office_standards/ms-oe376/6c085406-a698-4e12-9d4d-c3b0ee3dbc4a Dictionary locales = new(2); if (fullSymbolName.EndsWith(".name", StringComparison.OrdinalIgnoreCase)) { - ResourceManager commandNames = new(typeof(CommandNames)); - locales.Add(DiscordLocale.de, commandNames.GetString(symbolName, new CultureInfo(1031)) ?? string.Empty); + ResourceManager resources = (!isParameter) ? new(typeof(CommandNames)) : new(typeof(CommandParamNames)); + locales.Add(DiscordLocale.de, resources.GetString(symbolName, new CultureInfo(1031)) ?? string.Empty); locales.Add(DiscordLocale.en_US, symbolName); } else if (fullSymbolName.EndsWith(".description", StringComparison.OrdinalIgnoreCase) && !topLevelCommand) { - ResourceManager commandDescriptions = new(typeof(CommandDescriptions)); - locales.Add(DiscordLocale.de, commandDescriptions.GetString(symbolName, new CultureInfo(1031)) ?? string.Empty); - locales.Add(DiscordLocale.en_US, commandDescriptions.GetString(symbolName, new CultureInfo(1033)) ?? string.Empty); + ResourceManager resources = (!isParameter) ? new(typeof(CommandDescriptions)) : new(typeof(CommandParamDescriptions)); + locales.Add(DiscordLocale.de, resources.GetString(symbolName, new CultureInfo(1031)) ?? string.Empty); + locales.Add(DiscordLocale.en_US, resources.GetString(symbolName, new CultureInfo(1033)) ?? string.Empty); } return new ValueTask>(locales); diff --git a/src/AzzyBot.Bot/Localization/CommandParamDescriptions.Designer.cs b/src/AzzyBot.Bot/Localization/CommandParamDescriptions.Designer.cs index 0615d12c..d32257fb 100644 --- a/src/AzzyBot.Bot/Localization/CommandParamDescriptions.Designer.cs +++ b/src/AzzyBot.Bot/Localization/CommandParamDescriptions.Designer.cs @@ -59,5 +59,50 @@ internal CommandParamDescriptions() { resourceCulture = value; } } + + /// + /// Looks up a localized string similar to Choose the activity type which the bot should have.. + /// + internal static string activity { + get { + return ResourceManager.GetString("activity", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Enter a custom doing which is added after the activity type.. + /// + internal static string doing { + get { + return ResourceManager.GetString("doing", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Reset the bot status to default.. + /// + internal static string reset { + get { + return ResourceManager.GetString("reset", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Choose the status type which the bot should have. + /// + internal static string status { + get { + return ResourceManager.GetString("status", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Enter a custom url. Only usable when having activity type streaming or watching. + /// + internal static string url { + get { + return ResourceManager.GetString("url", resourceCulture); + } + } } } diff --git a/src/AzzyBot.Bot/Localization/CommandParamDescriptions.de-DE.resx b/src/AzzyBot.Bot/Localization/CommandParamDescriptions.de-DE.resx new file mode 100644 index 00000000..7df6d00f --- /dev/null +++ b/src/AzzyBot.Bot/Localization/CommandParamDescriptions.de-DE.resx @@ -0,0 +1,135 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Wähle den Aktivitäten-Typ welchen der Bot haben soll. + + + Setze eine eigene Tätigkeit welche nach dem Aktivitäten-Typ gesetzt wird. + + + Wähle den Status Typ welchen der Bot haben soll. + + + Setze eine eigene Url. Funktioniert nur wenn der Aktivitäten-Typ "Streamt" oder "Schaut" gesetzt ist. + + + Setze den Bot Status auf den Standard zurück. + + \ No newline at end of file diff --git a/src/AzzyBot.Bot/Localization/CommandParamDescriptions.resx b/src/AzzyBot.Bot/Localization/CommandParamDescriptions.resx index 4fdb1b6a..8975f00a 100644 --- a/src/AzzyBot.Bot/Localization/CommandParamDescriptions.resx +++ b/src/AzzyBot.Bot/Localization/CommandParamDescriptions.resx @@ -1,101 +1,135 @@  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 1.3 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + mimetype: application/x-microsoft.net.object.bytearray.base64 + value : The object must be serialized into a byte array + : using a System.ComponentModel.TypeConverter + : and then encoded with base64 encoding. + --> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Choose the activity type which the bot should have. + + + Enter a custom doing which is added after the activity type. + + + Choose the status type which the bot should have + + + Enter a custom url. Only usable when having activity type streaming or watching + + + Reset the bot status to default. + \ No newline at end of file diff --git a/src/AzzyBot.Bot/Localization/CommandParamNames.Designer.cs b/src/AzzyBot.Bot/Localization/CommandParamNames.Designer.cs index 5e86f527..7d8b961d 100644 --- a/src/AzzyBot.Bot/Localization/CommandParamNames.Designer.cs +++ b/src/AzzyBot.Bot/Localization/CommandParamNames.Designer.cs @@ -59,5 +59,50 @@ internal CommandParamNames() { resourceCulture = value; } } + + /// + /// Looks up a localized string similar to activity. + /// + internal static string activity { + get { + return ResourceManager.GetString("activity", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to doing. + /// + internal static string doing { + get { + return ResourceManager.GetString("doing", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to reset. + /// + internal static string reset { + get { + return ResourceManager.GetString("reset", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to status. + /// + internal static string status { + get { + return ResourceManager.GetString("status", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to url. + /// + internal static string url { + get { + return ResourceManager.GetString("url", resourceCulture); + } + } } } diff --git a/src/AzzyBot.Bot/Localization/CommandParamNames.de-DE.resx b/src/AzzyBot.Bot/Localization/CommandParamNames.de-DE.resx new file mode 100644 index 00000000..553df750 --- /dev/null +++ b/src/AzzyBot.Bot/Localization/CommandParamNames.de-DE.resx @@ -0,0 +1,135 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + aktivität + + + status + + + tätigkeit + + + url + + + zurücksetzen + + \ No newline at end of file diff --git a/src/AzzyBot.Bot/Localization/CommandParamNames.resx b/src/AzzyBot.Bot/Localization/CommandParamNames.resx index 4fdb1b6a..df4dc660 100644 --- a/src/AzzyBot.Bot/Localization/CommandParamNames.resx +++ b/src/AzzyBot.Bot/Localization/CommandParamNames.resx @@ -1,101 +1,135 @@  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 1.3 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + mimetype: application/x-microsoft.net.object.bytearray.base64 + value : The object must be serialized into a byte array + : using a System.ComponentModel.TypeConverter + : and then encoded with base64 encoding. + --> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + activity + + + status + + + doing + + + url + + + reset + \ No newline at end of file From b48fcf6afa88e9dd06fca496de6e75e09b80c8d8 Mon Sep 17 00:00:00 2001 From: Sella-GH <147769367+Sella-GH@users.noreply.github.com> Date: Thu, 8 Aug 2024 02:04:54 +0200 Subject: [PATCH 3/7] Fix some locale issues --- CHANGELOG.md | 2 +- src/AzzyBot.Bot/Localization/CommandDescriptions.de-DE.resx | 4 ++-- .../Localization/CommandParamDescriptions.de-DE.resx | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 04d286ae..22f52c56 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,7 +20,7 @@ - `player play` to select the provider and provide a url - `player pause` to pause the player - `player resume` to resume the player - - `player queue-clear` to clear the whole queue or only one songow + - `player queue-clear` to clear the whole queue or only one song - `player skip` to skip a song - `player history` to view the song history - `player queue` to view the song queue diff --git a/src/AzzyBot.Bot/Localization/CommandDescriptions.de-DE.resx b/src/AzzyBot.Bot/Localization/CommandDescriptions.de-DE.resx index 66b1b0fb..f5d03aa0 100644 --- a/src/AzzyBot.Bot/Localization/CommandDescriptions.de-DE.resx +++ b/src/AzzyBot.Bot/Localization/CommandDescriptions.de-DE.resx @@ -118,7 +118,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - Ändert den globalen Status des Bots nach deinen Wünschen + Ändert den globalen Status des Bots nach deinen Wünschen. Zeigt alle beigetretenen Server an. @@ -127,7 +127,7 @@ Entfernt den Bot von einem beigetretenen Server. - Sendet eine Nachricht an alle Server, in denen der Bot ist. + Sendet eine Nachricht an alle Server in denen der Bot ist. Zeigt die Logs des Bots an. diff --git a/src/AzzyBot.Bot/Localization/CommandParamDescriptions.de-DE.resx b/src/AzzyBot.Bot/Localization/CommandParamDescriptions.de-DE.resx index 7df6d00f..2300535b 100644 --- a/src/AzzyBot.Bot/Localization/CommandParamDescriptions.de-DE.resx +++ b/src/AzzyBot.Bot/Localization/CommandParamDescriptions.de-DE.resx @@ -118,7 +118,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - Wähle den Aktivitäten-Typ welchen der Bot haben soll. + Wähle den Aktivitäten-Typ aus welchen der Bot haben soll. Setze eine eigene Tätigkeit welche nach dem Aktivitäten-Typ gesetzt wird. @@ -127,9 +127,9 @@ Wähle den Status Typ welchen der Bot haben soll. - Setze eine eigene Url. Funktioniert nur wenn der Aktivitäten-Typ "Streamt" oder "Schaut" gesetzt ist. + Setze eine Url. Funktioniert nur wenn der Aktivitäten-Typ "Streamt" oder "Schaut" gesetzt ist. - Setze den Bot Status auf den Standard zurück. + Setzt den Bot Status auf den Standard zurück. \ No newline at end of file From e3e1981b726fed89c8103d8da12c90a4e0b3f73b Mon Sep 17 00:00:00 2001 From: Sella-GH <147769367+Sella-GH@users.noreply.github.com> Date: Thu, 8 Aug 2024 11:54:17 +0200 Subject: [PATCH 4/7] Parameter localization --- src/AzzyBot.Bot/Commands/AdminCommands.cs | 8 ++++---- src/AzzyBot.Bot/Localization/CommandLocalizer.cs | 14 ++++++++++++-- .../CommandParamDescriptions.de-DE.resx | 9 +++++++++ .../Localization/CommandParamDescriptions.resx | 9 +++++++++ .../Localization/CommandParamNames.de-DE.resx | 9 +++++++++ .../Localization/CommandParamNames.resx | 9 +++++++++ .../Extensions/ILoggingBuilderExtensions.cs | 1 + 7 files changed, 53 insertions(+), 6 deletions(-) diff --git a/src/AzzyBot.Bot/Commands/AdminCommands.cs b/src/AzzyBot.Bot/Commands/AdminCommands.cs index 696ed8d7..f0d5abf3 100644 --- a/src/AzzyBot.Bot/Commands/AdminCommands.cs +++ b/src/AzzyBot.Bot/Commands/AdminCommands.cs @@ -70,7 +70,7 @@ public async ValueTask ChangeStatusAsync public async ValueTask GetJoinedGuildsAsync ( SlashCommandContext context, - [Description("Select the server you want to get more information about."), SlashAutoCompleteProvider] string? serverId = null + [Description("Select the server you want to get more information about."), SlashAutoCompleteProvider, InteractionLocalizer] string? serverId = null ) { ArgumentNullException.ThrowIfNull(context, nameof(context)); @@ -123,7 +123,7 @@ public async ValueTask GetJoinedGuildsAsync public async ValueTask RemoveJoinedGuildAsync ( SlashCommandContext context, - [Description("Select the server you want to remove."), SlashAutoCompleteProvider] string serverId + [Description("Select the server you want to remove."), SlashAutoCompleteProvider, InteractionLocalizer] string serverId ) { ArgumentNullException.ThrowIfNull(context, nameof(context)); @@ -155,7 +155,7 @@ public async ValueTask RemoveJoinedGuildAsync public async ValueTask SendBotWideMessageAsync ( SlashCommandContext context, - [Description("The message you want to send."), MinMaxLength(1, 2000)] string message + [Description("The message you want to send."), MinMaxLength(1, 2000), InteractionLocalizer] string message ) { ArgumentNullException.ThrowIfNull(context, nameof(context)); @@ -201,7 +201,7 @@ public async ValueTask SendBotWideMessageAsync public async ValueTask ViewLogsAsync ( SlashCommandContext context, - [Description("The log file you want to read."), SlashAutoCompleteProvider] string? logfile = null + [Description("The log file you want to read."), SlashAutoCompleteProvider, InteractionLocalizer] string? logfile = null ) { ArgumentNullException.ThrowIfNull(context, nameof(context)); diff --git a/src/AzzyBot.Bot/Localization/CommandLocalizer.cs b/src/AzzyBot.Bot/Localization/CommandLocalizer.cs index 7c42783e..83cf7c49 100644 --- a/src/AzzyBot.Bot/Localization/CommandLocalizer.cs +++ b/src/AzzyBot.Bot/Localization/CommandLocalizer.cs @@ -4,11 +4,14 @@ using System.Resources; using System.Threading.Tasks; using DSharpPlus.Commands.Processors.SlashCommands.Localization; +using Microsoft.Extensions.Logging; namespace AzzyBot.Bot.Localization; -public sealed class CommandLocalizer() : IInteractionLocalizer +public sealed class CommandLocalizer(ILogger logger) : IInteractionLocalizer { + private readonly ILogger _logger = logger; + public ValueTask> TranslateAsync(string fullSymbolName) { ArgumentException.ThrowIfNullOrWhiteSpace(fullSymbolName, nameof(fullSymbolName)); @@ -52,7 +55,7 @@ public ValueTask> TranslateAsync(stri { ResourceManager resources = (!isParameter) ? new(typeof(CommandNames)) : new(typeof(CommandParamNames)); locales.Add(DiscordLocale.de, resources.GetString(symbolName, new CultureInfo(1031)) ?? string.Empty); - locales.Add(DiscordLocale.en_US, symbolName); + locales.Add(DiscordLocale.en_US, resources.GetString(symbolName, new CultureInfo(1033)) ?? string.Empty); } else if (fullSymbolName.EndsWith(".description", StringComparison.OrdinalIgnoreCase) && !topLevelCommand) { @@ -61,6 +64,13 @@ public ValueTask> TranslateAsync(stri locales.Add(DiscordLocale.en_US, resources.GetString(symbolName, new CultureInfo(1033)) ?? string.Empty); } + _logger.LogWarning(fullSymbolName); + _logger.LogWarning(symbolName); + foreach (KeyValuePair locale in locales) + { + _logger.LogWarning($"{locale.Key}: {locale.Value}"); + } + return new ValueTask>(locales); } } diff --git a/src/AzzyBot.Bot/Localization/CommandParamDescriptions.de-DE.resx b/src/AzzyBot.Bot/Localization/CommandParamDescriptions.de-DE.resx index 2300535b..2a068214 100644 --- a/src/AzzyBot.Bot/Localization/CommandParamDescriptions.de-DE.resx +++ b/src/AzzyBot.Bot/Localization/CommandParamDescriptions.de-DE.resx @@ -132,4 +132,13 @@ Setzt den Bot Status auf den Standard zurück. + + Wähle den richtigen Server aus. + + + Die Nachricht welche du versenden möchtest. + + + Die Logfile welche du sehen möchtest. + \ No newline at end of file diff --git a/src/AzzyBot.Bot/Localization/CommandParamDescriptions.resx b/src/AzzyBot.Bot/Localization/CommandParamDescriptions.resx index 8975f00a..b488dfd8 100644 --- a/src/AzzyBot.Bot/Localization/CommandParamDescriptions.resx +++ b/src/AzzyBot.Bot/Localization/CommandParamDescriptions.resx @@ -132,4 +132,13 @@ Reset the bot status to default. + + Select the choosen server. + + + The message you want to send. + + + The log file you want to see. + \ No newline at end of file diff --git a/src/AzzyBot.Bot/Localization/CommandParamNames.de-DE.resx b/src/AzzyBot.Bot/Localization/CommandParamNames.de-DE.resx index 553df750..0ce208e7 100644 --- a/src/AzzyBot.Bot/Localization/CommandParamNames.de-DE.resx +++ b/src/AzzyBot.Bot/Localization/CommandParamNames.de-DE.resx @@ -132,4 +132,13 @@ zurücksetzen + + serverid + + + nachricht + + + logfile + \ No newline at end of file diff --git a/src/AzzyBot.Bot/Localization/CommandParamNames.resx b/src/AzzyBot.Bot/Localization/CommandParamNames.resx index df4dc660..a3e5ab85 100644 --- a/src/AzzyBot.Bot/Localization/CommandParamNames.resx +++ b/src/AzzyBot.Bot/Localization/CommandParamNames.resx @@ -132,4 +132,13 @@ reset + + serverid + + + message + + + logfile + \ No newline at end of file diff --git a/src/AzzyBot.Core/Extensions/ILoggingBuilderExtensions.cs b/src/AzzyBot.Core/Extensions/ILoggingBuilderExtensions.cs index c1519387..417e0056 100644 --- a/src/AzzyBot.Core/Extensions/ILoggingBuilderExtensions.cs +++ b/src/AzzyBot.Core/Extensions/ILoggingBuilderExtensions.cs @@ -61,5 +61,6 @@ public static void AzzyBotLogging(this ILoggingBuilder logging, bool isDev = fal config.TimestampFormat = "[yyyy-MM-dd HH:mm:ss] "; }); logging.SetMinimumLevel((isDev || forceDebug) ? LogLevel.Debug : LogLevel.Information); + //logging.SetMinimumLevel(LogLevel.Trace); } } From cf968528388d157b742a30d928e4c8be0fb856bb Mon Sep 17 00:00:00 2001 From: Sella-GH <147769367+Sella-GH@users.noreply.github.com> Date: Sun, 13 Oct 2024 22:07:42 +0200 Subject: [PATCH 5/7] Fix builds --- src/AzzyBot.Bot/AzzyBot.Bot.csproj | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/AzzyBot.Bot/AzzyBot.Bot.csproj b/src/AzzyBot.Bot/AzzyBot.Bot.csproj index 3a0838c2..ecc03a26 100644 --- a/src/AzzyBot.Bot/AzzyBot.Bot.csproj +++ b/src/AzzyBot.Bot/AzzyBot.Bot.csproj @@ -92,6 +92,7 @@ True True CommandParamNames.resx + True True @@ -115,6 +116,7 @@ ResXFileCodeGenerator CommandParamNames.Designer.cs + ResXFileCodeGenerator UriStrings.Designer.cs From 6e6b1b40d8f00a4f11b207220bf215e8481fdca4 Mon Sep 17 00:00:00 2001 From: Sella-GH <147769367+Sella-GH@users.noreply.github.com> Date: Tue, 15 Oct 2024 23:39:32 +0200 Subject: [PATCH 6/7] Add localization for ChoiceProviders --- src/AzzyBot.Bot/AzzyBot.Bot.csproj | 9 + .../Choices/AzuraExportPlaylistProvider.cs | 5 +- .../BooleanEnabledDisabledStateProvider.cs | 5 +- .../Choices/BooleanYesNoStateProvider.cs | 5 +- .../Commands/Choices/BotActivityProvider.cs | 11 +- .../Commands/Choices/BotStatusProvider.cs | 9 +- .../Localization/CommandChoiceLocalizer.cs | 21 ++ .../Localization/CommandChoices.Designer.cs | 198 ++++++++++++++++++ .../Localization/CommandChoices.de-DE.resx | 165 +++++++++++++++ .../Localization/CommandChoices.resx | 165 +++++++++++++++ .../Localization/CommandLocalizer.cs | 29 +-- .../Localization/CommandNames.de-DE.resx | 2 +- .../CommandParamDescriptions.Designer.cs | 27 +++ .../CommandParamNames.Designer.cs | 27 +++ 14 files changed, 648 insertions(+), 30 deletions(-) create mode 100644 src/AzzyBot.Bot/Localization/CommandChoiceLocalizer.cs create mode 100644 src/AzzyBot.Bot/Localization/CommandChoices.Designer.cs create mode 100644 src/AzzyBot.Bot/Localization/CommandChoices.de-DE.resx create mode 100644 src/AzzyBot.Bot/Localization/CommandChoices.resx diff --git a/src/AzzyBot.Bot/AzzyBot.Bot.csproj b/src/AzzyBot.Bot/AzzyBot.Bot.csproj index ecc03a26..f0875857 100644 --- a/src/AzzyBot.Bot/AzzyBot.Bot.csproj +++ b/src/AzzyBot.Bot/AzzyBot.Bot.csproj @@ -73,6 +73,11 @@ + + True + True + CommandChoices.resx + True True @@ -101,6 +106,10 @@ + + ResXFileCodeGenerator + CommandChoices.Designer.cs + ResXFileCodeGenerator CommandDescriptions.Designer.cs diff --git a/src/AzzyBot.Bot/Commands/Choices/AzuraExportPlaylistProvider.cs b/src/AzzyBot.Bot/Commands/Choices/AzuraExportPlaylistProvider.cs index 6c0d94a1..c8011d7c 100644 --- a/src/AzzyBot.Bot/Commands/Choices/AzuraExportPlaylistProvider.cs +++ b/src/AzzyBot.Bot/Commands/Choices/AzuraExportPlaylistProvider.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.Threading.Tasks; +using AzzyBot.Bot.Localization; using DSharpPlus.Commands.Processors.SlashCommands.ArgumentModifiers; using DSharpPlus.Commands.Trees; using DSharpPlus.Entities; @@ -10,8 +11,8 @@ public sealed class AzuraExportPlaylistProvider : IChoiceProvider { private static readonly IEnumerable ExportProviders = [ - new("M3U", "m3u"), - new("PLS", "pls") + new("M3U", "m3u", CommandChoiceLocalizer.GenerateTranslations(nameof(AzuraExportPlaylistProvider), "m3u")), + new("PLS", "pls", CommandChoiceLocalizer.GenerateTranslations(nameof(AzuraExportPlaylistProvider), "pls")), ]; public ValueTask> ProvideAsync(CommandParameter parameter) diff --git a/src/AzzyBot.Bot/Commands/Choices/BooleanEnabledDisabledStateProvider.cs b/src/AzzyBot.Bot/Commands/Choices/BooleanEnabledDisabledStateProvider.cs index 3a2df17f..4dddeed2 100644 --- a/src/AzzyBot.Bot/Commands/Choices/BooleanEnabledDisabledStateProvider.cs +++ b/src/AzzyBot.Bot/Commands/Choices/BooleanEnabledDisabledStateProvider.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.Threading.Tasks; +using AzzyBot.Bot.Localization; using DSharpPlus.Commands.Processors.SlashCommands.ArgumentModifiers; using DSharpPlus.Commands.Trees; using DSharpPlus.Entities; @@ -10,8 +11,8 @@ public sealed class BooleanEnableDisableStateProvider : IChoiceProvider { private static readonly IEnumerable BooleanStates = [ - new("Enable", 1), - new("Disable", 2) + new("Enable", 1, CommandChoiceLocalizer.GenerateTranslations(nameof(BooleanEnableDisableStateProvider), "Enable")), + new("Disable", 2, CommandChoiceLocalizer.GenerateTranslations(nameof(BooleanEnableDisableStateProvider), "Disable")), ]; public ValueTask> ProvideAsync(CommandParameter parameter) diff --git a/src/AzzyBot.Bot/Commands/Choices/BooleanYesNoStateProvider.cs b/src/AzzyBot.Bot/Commands/Choices/BooleanYesNoStateProvider.cs index 3aacb80e..72f4a2ff 100644 --- a/src/AzzyBot.Bot/Commands/Choices/BooleanYesNoStateProvider.cs +++ b/src/AzzyBot.Bot/Commands/Choices/BooleanYesNoStateProvider.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.Threading.Tasks; +using AzzyBot.Bot.Localization; using DSharpPlus.Commands.Processors.SlashCommands.ArgumentModifiers; using DSharpPlus.Commands.Trees; using DSharpPlus.Entities; @@ -10,8 +11,8 @@ public sealed class BooleanYesNoStateProvider : IChoiceProvider { private static readonly IEnumerable BooleanStates = [ - new("Yes", 1), - new("No", 2) + new("Yes", 1, CommandChoiceLocalizer.GenerateTranslations(nameof(BooleanYesNoStateProvider), "Yes")), + new("No", 2, CommandChoiceLocalizer.GenerateTranslations(nameof(BooleanYesNoStateProvider), "No")), ]; public ValueTask> ProvideAsync(CommandParameter parameter) diff --git a/src/AzzyBot.Bot/Commands/Choices/BotActivityProvider.cs b/src/AzzyBot.Bot/Commands/Choices/BotActivityProvider.cs index 3e205a42..a4236a04 100644 --- a/src/AzzyBot.Bot/Commands/Choices/BotActivityProvider.cs +++ b/src/AzzyBot.Bot/Commands/Choices/BotActivityProvider.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.Threading.Tasks; +using AzzyBot.Bot.Localization; using DSharpPlus.Commands.Processors.SlashCommands.ArgumentModifiers; using DSharpPlus.Commands.Trees; using DSharpPlus.Entities; @@ -10,11 +11,11 @@ public sealed class BotActivityProvider : IChoiceProvider { private static readonly IEnumerable BotActivity = [ - new("Playing", 0), - new("Streaming", 1), - new("Listening To", 2), - new("Watching", 3), - new("Competing", 5) + new("Playing", 0, CommandChoiceLocalizer.GenerateTranslations(nameof(BotActivityProvider), "Playing")), + new("Streaming", 1, CommandChoiceLocalizer.GenerateTranslations(nameof(BotActivityProvider), "Streaming")), + new("Listening To", 2, CommandChoiceLocalizer.GenerateTranslations(nameof(BotActivityProvider), "Listening")), + new("Watching", 3, CommandChoiceLocalizer.GenerateTranslations(nameof(BotActivityProvider), "Watching")), + new("Competing", 5, CommandChoiceLocalizer.GenerateTranslations(nameof(BotActivityProvider), "Competing")) ]; public ValueTask> ProvideAsync(CommandParameter parameter) diff --git a/src/AzzyBot.Bot/Commands/Choices/BotStatusProvider.cs b/src/AzzyBot.Bot/Commands/Choices/BotStatusProvider.cs index 4912b58e..75927769 100644 --- a/src/AzzyBot.Bot/Commands/Choices/BotStatusProvider.cs +++ b/src/AzzyBot.Bot/Commands/Choices/BotStatusProvider.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.Threading.Tasks; +using AzzyBot.Bot.Localization; using DSharpPlus.Commands.Processors.SlashCommands.ArgumentModifiers; using DSharpPlus.Commands.Trees; using DSharpPlus.Entities; @@ -10,10 +11,10 @@ public sealed class BotStatusProvider : IChoiceProvider { private static readonly IEnumerable BotStatusChoices = [ - new("Offline", 0), - new("Online", 1), - new("Idle", 2), - new("Do Not Disturb", 4) + new("Offline", 0, CommandChoiceLocalizer.GenerateTranslations(nameof(BotStatusProvider), "Offline")), + new("Online", 1, CommandChoiceLocalizer.GenerateTranslations(nameof(BotStatusProvider), "Online")), + new("Idle", 2, CommandChoiceLocalizer.GenerateTranslations(nameof(BotStatusProvider), "Idle")), + new("Do Not Disturb", 4, CommandChoiceLocalizer.GenerateTranslations(nameof(BotStatusProvider), "Dnd")), ]; public ValueTask> ProvideAsync(CommandParameter parameter) diff --git a/src/AzzyBot.Bot/Localization/CommandChoiceLocalizer.cs b/src/AzzyBot.Bot/Localization/CommandChoiceLocalizer.cs new file mode 100644 index 00000000..0a29b911 --- /dev/null +++ b/src/AzzyBot.Bot/Localization/CommandChoiceLocalizer.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Resources; + +namespace AzzyBot.Bot.Localization; + +public static class CommandChoiceLocalizer +{ + public static Dictionary GenerateTranslations(string typeName, string value) + { + ArgumentException.ThrowIfNullOrWhiteSpace(typeName); + ArgumentException.ThrowIfNullOrWhiteSpace(value); + + Dictionary locales = new(1); + ResourceManager resources = new(typeof(CommandChoices)); + locales.Add("de", resources.GetString($"{typeName}.{value}", new CultureInfo(1031)) ?? string.Empty); + + return locales; + } +} diff --git a/src/AzzyBot.Bot/Localization/CommandChoices.Designer.cs b/src/AzzyBot.Bot/Localization/CommandChoices.Designer.cs new file mode 100644 index 00000000..36178af8 --- /dev/null +++ b/src/AzzyBot.Bot/Localization/CommandChoices.Designer.cs @@ -0,0 +1,198 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace AzzyBot.Bot.Localization { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class CommandChoices { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal CommandChoices() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("AzzyBot.Bot.Localization.CommandChoices", typeof(CommandChoices).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to M3U. + /// + internal static string AzuraExportPlaylistProvider_m3u { + get { + return ResourceManager.GetString("AzuraExportPlaylistProvider.m3u", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to PLS. + /// + internal static string AzuraExportPlaylistProvider_pls { + get { + return ResourceManager.GetString("AzuraExportPlaylistProvider.pls", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Disable. + /// + internal static string BooleanEnableDisableStateProvider_Disable { + get { + return ResourceManager.GetString("BooleanEnableDisableStateProvider.Disable", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Enable. + /// + internal static string BooleanEnableDisableStateProvider_Enable { + get { + return ResourceManager.GetString("BooleanEnableDisableStateProvider.Enable", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to No. + /// + internal static string BooleanYesNoStateProvider_No { + get { + return ResourceManager.GetString("BooleanYesNoStateProvider.No", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Yes. + /// + internal static string BooleanYesNoStateProvider_Yes { + get { + return ResourceManager.GetString("BooleanYesNoStateProvider.Yes", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Competing. + /// + internal static string BotActivityProvider_Competing { + get { + return ResourceManager.GetString("BotActivityProvider.Competing", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Listening To. + /// + internal static string BotActivityProvider_Listening { + get { + return ResourceManager.GetString("BotActivityProvider.Listening", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Playing. + /// + internal static string BotActivityProvider_Playing { + get { + return ResourceManager.GetString("BotActivityProvider.Playing", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Streaming. + /// + internal static string BotActivityProvider_Streaming { + get { + return ResourceManager.GetString("BotActivityProvider.Streaming", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Watching. + /// + internal static string BotActivityProvider_Watching { + get { + return ResourceManager.GetString("BotActivityProvider.Watching", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Do Not Disturb. + /// + internal static string BotStatusProvider_Dnd { + get { + return ResourceManager.GetString("BotStatusProvider.Dnd", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Idle. + /// + internal static string BotStatusProvider_Idle { + get { + return ResourceManager.GetString("BotStatusProvider.Idle", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Offline. + /// + internal static string BotStatusProvider_Offline { + get { + return ResourceManager.GetString("BotStatusProvider.Offline", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Online. + /// + internal static string BotStatusProvider_Online { + get { + return ResourceManager.GetString("BotStatusProvider.Online", resourceCulture); + } + } + } +} diff --git a/src/AzzyBot.Bot/Localization/CommandChoices.de-DE.resx b/src/AzzyBot.Bot/Localization/CommandChoices.de-DE.resx new file mode 100644 index 00000000..4efa17f4 --- /dev/null +++ b/src/AzzyBot.Bot/Localization/CommandChoices.de-DE.resx @@ -0,0 +1,165 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + M3U + + + PLS + + + Deaktivieren + + + Aktivieren + + + Nein + + + Ja + + + Kämpft + + + Hört + + + Spielt + + + Streamt + + + Schaut + + + Bitte nicht stören + + + Abwesend + + + Unsichtbar + + + Online + + \ No newline at end of file diff --git a/src/AzzyBot.Bot/Localization/CommandChoices.resx b/src/AzzyBot.Bot/Localization/CommandChoices.resx new file mode 100644 index 00000000..b615515d --- /dev/null +++ b/src/AzzyBot.Bot/Localization/CommandChoices.resx @@ -0,0 +1,165 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + M3U + + + PLS + + + Disable + + + Enable + + + No + + + Yes + + + Competing + + + Listening To + + + Playing + + + Streaming + + + Watching + + + Do Not Disturb + + + Idle + + + Offline + + + Online + + \ No newline at end of file diff --git a/src/AzzyBot.Bot/Localization/CommandLocalizer.cs b/src/AzzyBot.Bot/Localization/CommandLocalizer.cs index 83cf7c49..6da49053 100644 --- a/src/AzzyBot.Bot/Localization/CommandLocalizer.cs +++ b/src/AzzyBot.Bot/Localization/CommandLocalizer.cs @@ -1,20 +1,21 @@ -using System; +#pragma warning disable S125 // Sections of code should not be commented out +using System; using System.Collections.Generic; using System.Globalization; using System.Resources; using System.Threading.Tasks; using DSharpPlus.Commands.Processors.SlashCommands.Localization; -using Microsoft.Extensions.Logging; +//using Microsoft.Extensions.Logging; namespace AzzyBot.Bot.Localization; -public sealed class CommandLocalizer(ILogger logger) : IInteractionLocalizer +public sealed class CommandLocalizer(/*ILogger logger*/) : IInteractionLocalizer { - private readonly ILogger _logger = logger; + //private readonly ILogger _logger = logger; public ValueTask> TranslateAsync(string fullSymbolName) { - ArgumentException.ThrowIfNullOrWhiteSpace(fullSymbolName, nameof(fullSymbolName)); + ArgumentException.ThrowIfNullOrWhiteSpace(fullSymbolName); bool topLevelCommand = false; bool isParameter = false; @@ -50,27 +51,27 @@ public ValueTask> TranslateAsync(stri // Use this as reference for the LCID: // https://learn.microsoft.com/en-us/openspecs/office_standards/ms-oe376/6c085406-a698-4e12-9d4d-c3b0ee3dbc4a - Dictionary locales = new(2); + Dictionary locales = new(1); if (fullSymbolName.EndsWith(".name", StringComparison.OrdinalIgnoreCase)) { ResourceManager resources = (!isParameter) ? new(typeof(CommandNames)) : new(typeof(CommandParamNames)); locales.Add(DiscordLocale.de, resources.GetString(symbolName, new CultureInfo(1031)) ?? string.Empty); - locales.Add(DiscordLocale.en_US, resources.GetString(symbolName, new CultureInfo(1033)) ?? string.Empty); } else if (fullSymbolName.EndsWith(".description", StringComparison.OrdinalIgnoreCase) && !topLevelCommand) { ResourceManager resources = (!isParameter) ? new(typeof(CommandDescriptions)) : new(typeof(CommandParamDescriptions)); locales.Add(DiscordLocale.de, resources.GetString(symbolName, new CultureInfo(1031)) ?? string.Empty); - locales.Add(DiscordLocale.en_US, resources.GetString(symbolName, new CultureInfo(1033)) ?? string.Empty); } - _logger.LogWarning(fullSymbolName); - _logger.LogWarning(symbolName); - foreach (KeyValuePair locale in locales) - { - _logger.LogWarning($"{locale.Key}: {locale.Value}"); - } + //_logger.LogWarning(fullSymbolName); + //_logger.LogWarning(symbolName); + //foreach (KeyValuePair locale in locales) + //{ + // _logger.LogWarning($"{locale.Key}: {locale.Value}"); + //} return new ValueTask>(locales); } } + +#pragma warning restore S125 // Sections of code should not be commented out diff --git a/src/AzzyBot.Bot/Localization/CommandNames.de-DE.resx b/src/AzzyBot.Bot/Localization/CommandNames.de-DE.resx index d8933624..d26e153c 100644 --- a/src/AzzyBot.Bot/Localization/CommandNames.de-DE.resx +++ b/src/AzzyBot.Bot/Localization/CommandNames.de-DE.resx @@ -118,7 +118,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - administrator + admin bot-status-ändern diff --git a/src/AzzyBot.Bot/Localization/CommandParamDescriptions.Designer.cs b/src/AzzyBot.Bot/Localization/CommandParamDescriptions.Designer.cs index d32257fb..deb064e8 100644 --- a/src/AzzyBot.Bot/Localization/CommandParamDescriptions.Designer.cs +++ b/src/AzzyBot.Bot/Localization/CommandParamDescriptions.Designer.cs @@ -78,6 +78,24 @@ internal static string doing { } } + /// + /// Looks up a localized string similar to The log file you want to see.. + /// + internal static string logfile { + get { + return ResourceManager.GetString("logfile", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to The message you want to send.. + /// + internal static string message { + get { + return ResourceManager.GetString("message", resourceCulture); + } + } + /// /// Looks up a localized string similar to Reset the bot status to default.. /// @@ -87,6 +105,15 @@ internal static string reset { } } + /// + /// Looks up a localized string similar to Select the choosen server.. + /// + internal static string serverid { + get { + return ResourceManager.GetString("serverid", resourceCulture); + } + } + /// /// Looks up a localized string similar to Choose the status type which the bot should have. /// diff --git a/src/AzzyBot.Bot/Localization/CommandParamNames.Designer.cs b/src/AzzyBot.Bot/Localization/CommandParamNames.Designer.cs index 7d8b961d..39aae749 100644 --- a/src/AzzyBot.Bot/Localization/CommandParamNames.Designer.cs +++ b/src/AzzyBot.Bot/Localization/CommandParamNames.Designer.cs @@ -78,6 +78,24 @@ internal static string doing { } } + /// + /// Looks up a localized string similar to logfile. + /// + internal static string logfile { + get { + return ResourceManager.GetString("logfile", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to message. + /// + internal static string message { + get { + return ResourceManager.GetString("message", resourceCulture); + } + } + /// /// Looks up a localized string similar to reset. /// @@ -87,6 +105,15 @@ internal static string reset { } } + /// + /// Looks up a localized string similar to serverid. + /// + internal static string serverid { + get { + return ResourceManager.GetString("serverid", resourceCulture); + } + } + /// /// Looks up a localized string similar to status. /// From 1f94a0938befa5a4a5624cec5ae0b0a2ca6769b3 Mon Sep 17 00:00:00 2001 From: Sella-GH <147769367+Sella-GH@users.noreply.github.com> Date: Wed, 16 Oct 2024 00:57:07 +0200 Subject: [PATCH 7/7] Start to localize Core Commands --- src/AzzyBot.Bot/Commands/CoreCommands.cs | 16 +++--- .../CommandDescriptions.Designer.cs | 45 ++++++++++++++++ .../CommandDescriptions.de-DE.resx | 15 ++++++ .../Localization/CommandDescriptions.resx | 15 ++++++ .../Localization/CommandLocalizer.cs | 38 +++++++++---- .../Localization/CommandNames.Designer.cs | 54 +++++++++++++++++++ .../Localization/CommandNames.de-DE.resx | 20 ++++++- .../Localization/CommandNames.resx | 18 +++++++ .../CommandParamDescriptions.Designer.cs | 9 ++++ .../CommandParamDescriptions.de-DE.resx | 5 +- .../CommandParamDescriptions.resx | 3 ++ .../CommandParamNames.Designer.cs | 9 ++++ .../Localization/CommandParamNames.de-DE.resx | 3 ++ .../Localization/CommandParamNames.resx | 3 ++ 14 files changed, 234 insertions(+), 19 deletions(-) diff --git a/src/AzzyBot.Bot/Commands/CoreCommands.cs b/src/AzzyBot.Bot/Commands/CoreCommands.cs index 82eaa43d..a6017294 100644 --- a/src/AzzyBot.Bot/Commands/CoreCommands.cs +++ b/src/AzzyBot.Bot/Commands/CoreCommands.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Threading.Tasks; using AzzyBot.Bot.Commands.Autocompletes; +using AzzyBot.Bot.Localization; using AzzyBot.Bot.Services; using AzzyBot.Bot.Settings; using AzzyBot.Bot.Utilities; @@ -19,6 +20,7 @@ using DSharpPlus.Commands.ContextChecks; using DSharpPlus.Commands.Processors.SlashCommands; using DSharpPlus.Commands.Processors.SlashCommands.ArgumentModifiers; +using DSharpPlus.Commands.Processors.SlashCommands.Localization; using DSharpPlus.Entities; using Microsoft.Extensions.Logging; @@ -27,7 +29,7 @@ namespace AzzyBot.Bot.Commands; [SuppressMessage("Design", "CA1034:Nested types should not be visible", Justification = "DSharpPlus best practice")] public sealed class CoreCommands { - [Command("core"), RequireGuild] + [Command("core"), RequireGuild, InteractionLocalizer] public sealed class CoreGroup(ILogger logger, AzzyBotSettingsRecord settings, DbActions dbActions, DiscordBotService botService) { private readonly ILogger _logger = logger; @@ -35,7 +37,7 @@ public sealed class CoreGroup(ILogger logger, AzzyBotSettingsRecord s private readonly DbActions _dbActions = dbActions; private readonly DiscordBotService _botService = botService; - [Command("force-channel-permissions-check"), Description("Forces a check of the permissions for the bot in the necessary channel."), RequirePermissions(DiscordPermissions.None, DiscordPermissions.ManageChannels)] + [Command("force-channel-permissions-check"), Description("Forces a check of the permissions for the bot in the necessary channels."), RequirePermissions(DiscordPermissions.None, DiscordPermissions.ManageChannels), InteractionLocalizer] public async ValueTask ForceChannelPermissionsCheckAsync(SlashCommandContext context) { ArgumentNullException.ThrowIfNull(context); @@ -56,7 +58,7 @@ public async ValueTask ForceChannelPermissionsCheckAsync(SlashCommandContext con await _botService.CheckPermissionsAsync(guild); } - [Command("help"), Description("Gives you an overview about all the available commands.")] + [Command("help"), Description("Gives you an overview about all the available commands."), InteractionLocalizer] public async ValueTask HelpAsync ( SlashCommandContext context, @@ -103,13 +105,13 @@ public async ValueTask HelpAsync await context.EditResponseAsync(messageBuilder); } - [Command("stats")] + [Command("stats"), InteractionLocalizer] public sealed class CoreStats(AppStatsRecord stats, ILogger logger) { private readonly AppStatsRecord _stats = stats; private readonly ILogger _logger = logger; - [Command("hardware"), Description("Shows information about the hardware side of the bot.")] + [Command("hardware"), Description("Shows information about the hardware side of the bot."), InteractionLocalizer] public async ValueTask HardwareStatsAsync(SlashCommandContext context) { ArgumentNullException.ThrowIfNull(context); @@ -125,7 +127,7 @@ public async ValueTask HardwareStatsAsync(SlashCommandContext context) await context.EditResponseAsync(embed); } - [Command("info"), Description("Shows information about the bot and it's components.")] + [Command("info"), Description("Shows information about the bot and it's components."), InteractionLocalizer] public async ValueTask InfoStatsAsync(SlashCommandContext context) { ArgumentNullException.ThrowIfNull(context); @@ -141,7 +143,7 @@ public async ValueTask InfoStatsAsync(SlashCommandContext context) await context.EditResponseAsync(embed); } - [Command("ping"), Description("Ping the bot and get the latency to discord.")] + [Command("ping"), Description("Ping the bot and get the latency to discord."), InteractionLocalizer] public async ValueTask PingAsync(SlashCommandContext context) { ArgumentNullException.ThrowIfNull(context); diff --git a/src/AzzyBot.Bot/Localization/CommandDescriptions.Designer.cs b/src/AzzyBot.Bot/Localization/CommandDescriptions.Designer.cs index fd71813d..25ecdbb3 100644 --- a/src/AzzyBot.Bot/Localization/CommandDescriptions.Designer.cs +++ b/src/AzzyBot.Bot/Localization/CommandDescriptions.Designer.cs @@ -69,6 +69,15 @@ internal static string change_bot_status { } } + /// + /// Looks up a localized string similar to Forces a check of the permissions for the bot in the necessary channels.. + /// + internal static string force_channel_permissions_check { + get { + return ResourceManager.GetString("force-channel-permissions-check", resourceCulture); + } + } + /// /// Looks up a localized string similar to Displays all servers the bot is in.. /// @@ -78,6 +87,42 @@ internal static string get_joined_server { } } + /// + /// Looks up a localized string similar to Shows information about the hardware side of the bot.. + /// + internal static string hardware { + get { + return ResourceManager.GetString("hardware", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Gives you can overview about all the available commands.. + /// + internal static string help { + get { + return ResourceManager.GetString("help", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Shows information about the bot and it's components.. + /// + internal static string info { + get { + return ResourceManager.GetString("info", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Ping the bot and get the latency to discord.. + /// + internal static string ping { + get { + return ResourceManager.GetString("ping", resourceCulture); + } + } + /// /// Looks up a localized string similar to Removes the bot from a server.. /// diff --git a/src/AzzyBot.Bot/Localization/CommandDescriptions.de-DE.resx b/src/AzzyBot.Bot/Localization/CommandDescriptions.de-DE.resx index f5d03aa0..40fda98c 100644 --- a/src/AzzyBot.Bot/Localization/CommandDescriptions.de-DE.resx +++ b/src/AzzyBot.Bot/Localization/CommandDescriptions.de-DE.resx @@ -120,9 +120,24 @@ Ändert den globalen Status des Bots nach deinen Wünschen. + + Erzwingt eine Prüfung ob der Bot die nötigen Rechte für seine Channels hat. + Zeigt alle beigetretenen Server an. + + Zeigt Informationen über die Hardware des Bots. + + + Zeigt eine Übersicht über alle verfügbaren Befehle. + + + Zeigt allgemeine Informationen über den Bot und seine Komponenten. + + + Pingt den Bot und zeigt die Latenz zu Discord. + Entfernt den Bot von einem beigetretenen Server. diff --git a/src/AzzyBot.Bot/Localization/CommandDescriptions.resx b/src/AzzyBot.Bot/Localization/CommandDescriptions.resx index 3b36e2df..63518f59 100644 --- a/src/AzzyBot.Bot/Localization/CommandDescriptions.resx +++ b/src/AzzyBot.Bot/Localization/CommandDescriptions.resx @@ -120,9 +120,24 @@ Change the global bot status according to your likes. + + Forces a check of the permissions for the bot in the necessary channels. + Displays all servers the bot is in. + + Shows information about the hardware side of the bot. + + + Gives you can overview about all the available commands. + + + Shows information about the bot and it's components. + + + Ping the bot and get the latency to discord. + Removes the bot from a server. diff --git a/src/AzzyBot.Bot/Localization/CommandLocalizer.cs b/src/AzzyBot.Bot/Localization/CommandLocalizer.cs index 6da49053..0e568278 100644 --- a/src/AzzyBot.Bot/Localization/CommandLocalizer.cs +++ b/src/AzzyBot.Bot/Localization/CommandLocalizer.cs @@ -1,17 +1,18 @@ #pragma warning disable S125 // Sections of code should not be commented out using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Resources; using System.Threading.Tasks; using DSharpPlus.Commands.Processors.SlashCommands.Localization; -//using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging; namespace AzzyBot.Bot.Localization; -public sealed class CommandLocalizer(/*ILogger logger*/) : IInteractionLocalizer +public sealed class CommandLocalizer(ILogger logger) : IInteractionLocalizer { - //private readonly ILogger _logger = logger; + private readonly ILogger _logger = logger; public ValueTask> TranslateAsync(string fullSymbolName) { @@ -21,6 +22,8 @@ public ValueTask> TranslateAsync(stri bool isParameter = false; string symbolName = string.Empty; string[] parts; + + // TODO: Rework this so it's not confused when having 2 nested command groups if (!fullSymbolName.Contains("parameters", StringComparison.OrdinalIgnoreCase)) { parts = fullSymbolName.Split('.'); @@ -57,21 +60,36 @@ public ValueTask> TranslateAsync(stri ResourceManager resources = (!isParameter) ? new(typeof(CommandNames)) : new(typeof(CommandParamNames)); locales.Add(DiscordLocale.de, resources.GetString(symbolName, new CultureInfo(1031)) ?? string.Empty); } - else if (fullSymbolName.EndsWith(".description", StringComparison.OrdinalIgnoreCase) && !topLevelCommand) + else if (fullSymbolName.EndsWith(".description", StringComparison.OrdinalIgnoreCase) && (!topLevelCommand || CheckIfCommandIsExcluded(fullSymbolName))) { ResourceManager resources = (!isParameter) ? new(typeof(CommandDescriptions)) : new(typeof(CommandParamDescriptions)); locales.Add(DiscordLocale.de, resources.GetString(symbolName, new CultureInfo(1031)) ?? string.Empty); } - //_logger.LogWarning(fullSymbolName); - //_logger.LogWarning(symbolName); - //foreach (KeyValuePair locale in locales) - //{ - // _logger.LogWarning($"{locale.Key}: {locale.Value}"); - //} + _logger.LogWarning(fullSymbolName); + _logger.LogWarning(symbolName); + foreach (KeyValuePair locale in locales) + { + _logger.LogWarning($"{locale.Key}: {locale.Value} ({locale.Value.Length})"); + } return new ValueTask>(locales); } + + [SuppressMessage("Minor Code Smell", "S3267:Loops should be simplified with \"LINQ\" expressions", Justification = "Linq is about 8x slower than this.")] + private static bool CheckIfCommandIsExcluded(string fullSymbolName) + { + ArgumentException.ThrowIfNullOrWhiteSpace(fullSymbolName); + + string[] excludedCommands = ["core.stats"]; + foreach (string excluded in excludedCommands) + { + if (fullSymbolName.EndsWith($"{excluded}.description", StringComparison.OrdinalIgnoreCase)) + return true; + } + + return false; + } } #pragma warning restore S125 // Sections of code should not be commented out diff --git a/src/AzzyBot.Bot/Localization/CommandNames.Designer.cs b/src/AzzyBot.Bot/Localization/CommandNames.Designer.cs index 28815189..b3f26ec4 100644 --- a/src/AzzyBot.Bot/Localization/CommandNames.Designer.cs +++ b/src/AzzyBot.Bot/Localization/CommandNames.Designer.cs @@ -78,6 +78,15 @@ internal static string change_bot_status { } } + /// + /// Looks up a localized string similar to force-channel-permissions-check. + /// + internal static string force_channel_permissions_check { + get { + return ResourceManager.GetString("force-channel-permissions-check", resourceCulture); + } + } + /// /// Looks up a localized string similar to get-joined-server. /// @@ -87,6 +96,42 @@ internal static string get_joined_server { } } + /// + /// Looks up a localized string similar to hardware. + /// + internal static string hardware { + get { + return ResourceManager.GetString("hardware", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to help. + /// + internal static string help { + get { + return ResourceManager.GetString("help", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to info. + /// + internal static string info { + get { + return ResourceManager.GetString("info", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to ping. + /// + internal static string ping { + get { + return ResourceManager.GetString("ping", resourceCulture); + } + } + /// /// Looks up a localized string similar to remove-joined-server. /// @@ -105,6 +150,15 @@ internal static string send_bot_wide_message { } } + /// + /// Looks up a localized string similar to stats. + /// + internal static string stats { + get { + return ResourceManager.GetString("stats", resourceCulture); + } + } + /// /// Looks up a localized string similar to view-logs. /// diff --git a/src/AzzyBot.Bot/Localization/CommandNames.de-DE.resx b/src/AzzyBot.Bot/Localization/CommandNames.de-DE.resx index d26e153c..62322a7a 100644 --- a/src/AzzyBot.Bot/Localization/CommandNames.de-DE.resx +++ b/src/AzzyBot.Bot/Localization/CommandNames.de-DE.resx @@ -123,16 +123,34 @@ bot-status-ändern + + erzwinge-channel-rechte-check + zeige-beigetretenen-server + + hardware + + + hilfe + + + info + + + ping + entferne-beigetretenen-server sende-bot-weite-nachricht + + stats + zeige-logs - \ No newline at end of file + diff --git a/src/AzzyBot.Bot/Localization/CommandNames.resx b/src/AzzyBot.Bot/Localization/CommandNames.resx index 9b2bf2c1..5a1020f1 100644 --- a/src/AzzyBot.Bot/Localization/CommandNames.resx +++ b/src/AzzyBot.Bot/Localization/CommandNames.resx @@ -123,15 +123,33 @@ change-bot-status + + force-channel-permissions-check + get-joined-server + + hardware + + + help + + + info + + + ping + remove-joined-server send-bot-wide-message + + stats + view-logs diff --git a/src/AzzyBot.Bot/Localization/CommandParamDescriptions.Designer.cs b/src/AzzyBot.Bot/Localization/CommandParamDescriptions.Designer.cs index deb064e8..efb5f08c 100644 --- a/src/AzzyBot.Bot/Localization/CommandParamDescriptions.Designer.cs +++ b/src/AzzyBot.Bot/Localization/CommandParamDescriptions.Designer.cs @@ -69,6 +69,15 @@ internal static string activity { } } + /// + /// Looks up a localized string similar to The command you want to get more information about.. + /// + internal static string command { + get { + return ResourceManager.GetString("command", resourceCulture); + } + } + /// /// Looks up a localized string similar to Enter a custom doing which is added after the activity type.. /// diff --git a/src/AzzyBot.Bot/Localization/CommandParamDescriptions.de-DE.resx b/src/AzzyBot.Bot/Localization/CommandParamDescriptions.de-DE.resx index 2a068214..0e8d0965 100644 --- a/src/AzzyBot.Bot/Localization/CommandParamDescriptions.de-DE.resx +++ b/src/AzzyBot.Bot/Localization/CommandParamDescriptions.de-DE.resx @@ -133,7 +133,7 @@ Setzt den Bot Status auf den Standard zurück. - Wähle den richtigen Server aus. + Wähle einen Server aus. Die Nachricht welche du versenden möchtest. @@ -141,4 +141,7 @@ Die Logfile welche du sehen möchtest. + + Der Befehl über welchen du mehr Informationen erhalten möchtest. + \ No newline at end of file diff --git a/src/AzzyBot.Bot/Localization/CommandParamDescriptions.resx b/src/AzzyBot.Bot/Localization/CommandParamDescriptions.resx index b488dfd8..c99948d3 100644 --- a/src/AzzyBot.Bot/Localization/CommandParamDescriptions.resx +++ b/src/AzzyBot.Bot/Localization/CommandParamDescriptions.resx @@ -141,4 +141,7 @@ The log file you want to see. + + The command you want to get more information about. + \ No newline at end of file diff --git a/src/AzzyBot.Bot/Localization/CommandParamNames.Designer.cs b/src/AzzyBot.Bot/Localization/CommandParamNames.Designer.cs index 39aae749..4359bfa6 100644 --- a/src/AzzyBot.Bot/Localization/CommandParamNames.Designer.cs +++ b/src/AzzyBot.Bot/Localization/CommandParamNames.Designer.cs @@ -69,6 +69,15 @@ internal static string activity { } } + /// + /// Looks up a localized string similar to command. + /// + internal static string command { + get { + return ResourceManager.GetString("command", resourceCulture); + } + } + /// /// Looks up a localized string similar to doing. /// diff --git a/src/AzzyBot.Bot/Localization/CommandParamNames.de-DE.resx b/src/AzzyBot.Bot/Localization/CommandParamNames.de-DE.resx index 0ce208e7..7c43fa20 100644 --- a/src/AzzyBot.Bot/Localization/CommandParamNames.de-DE.resx +++ b/src/AzzyBot.Bot/Localization/CommandParamNames.de-DE.resx @@ -141,4 +141,7 @@ logfile + + befehl + \ No newline at end of file diff --git a/src/AzzyBot.Bot/Localization/CommandParamNames.resx b/src/AzzyBot.Bot/Localization/CommandParamNames.resx index a3e5ab85..b04aafe5 100644 --- a/src/AzzyBot.Bot/Localization/CommandParamNames.resx +++ b/src/AzzyBot.Bot/Localization/CommandParamNames.resx @@ -141,4 +141,7 @@ logfile + + command + \ No newline at end of file