From c886f5c814e01e7b830964618a0cdc39b98811ac Mon Sep 17 00:00:00 2001 From: Misha133 Date: Mon, 26 Feb 2024 00:18:02 +0300 Subject: [PATCH 1/2] Add example localization to the interaction framework sample --- samples/InteractionFramework/Program.cs | 12 +- .../Resources/CommandLocales.Designer.cs | 66 +++++++++ .../Resources/CommandLocales.resx | 132 ++++++++++++++++++ .../Resources/CommandLocales.ru.resx | 132 ++++++++++++++++++ .../_InteractionFramework.csproj | 27 ++++ 5 files changed, 367 insertions(+), 2 deletions(-) create mode 100644 samples/InteractionFramework/Resources/CommandLocales.Designer.cs create mode 100644 samples/InteractionFramework/Resources/CommandLocales.resx create mode 100644 samples/InteractionFramework/Resources/CommandLocales.ru.resx diff --git a/samples/InteractionFramework/Program.cs b/samples/InteractionFramework/Program.cs index 9731887d5d..d7572d1265 100644 --- a/samples/InteractionFramework/Program.cs +++ b/samples/InteractionFramework/Program.cs @@ -4,6 +4,8 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using System; +using System.Globalization; +using System.Reflection; using System.Threading; using System.Threading.Tasks; @@ -20,18 +22,24 @@ public class Program AlwaysDownloadUsers = true, }; + private static readonly InteractionServiceConfig _interactionServiceConfig = new() + { + LocalizationManager = new ResxLocalizationManager("InteractionFramework.Resources.CommandLocales", Assembly.GetEntryAssembly(), + new CultureInfo("en-US"), new CultureInfo("ru")) + }; + public static async Task Main(string[] args) { _configuration = new ConfigurationBuilder() .AddEnvironmentVariables(prefix: "DC_") .AddJsonFile("appsettings.json", optional: true) .Build(); - + _services = new ServiceCollection() .AddSingleton(_configuration) .AddSingleton(_socketConfig) .AddSingleton() - .AddSingleton(x => new InteractionService(x.GetRequiredService())) + .AddSingleton(x => new InteractionService(x.GetRequiredService(), _interactionServiceConfig)) .AddSingleton() .BuildServiceProvider(); diff --git a/samples/InteractionFramework/Resources/CommandLocales.Designer.cs b/samples/InteractionFramework/Resources/CommandLocales.Designer.cs new file mode 100644 index 0000000000..0d606575f0 --- /dev/null +++ b/samples/InteractionFramework/Resources/CommandLocales.Designer.cs @@ -0,0 +1,66 @@ +[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] +[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] +[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] +internal class CommandLocales +{ + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal CommandLocales() + { + } + + [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("CommandLocales", typeof(CommandLocales).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + + internal static string echo_description + { + get + { + return ResourceManager.GetString("echo.description", resourceCulture); + } + } + + internal static string echo_mention_description + { + get + { + return ResourceManager.GetString("echo.mention.description", resourceCulture); + } + } + + internal static string echo_name + { + get + { + return ResourceManager.GetString("echo.name", resourceCulture); + } + } +} diff --git a/samples/InteractionFramework/Resources/CommandLocales.resx b/samples/InteractionFramework/Resources/CommandLocales.resx new file mode 100644 index 0000000000..dec3a16fbb --- /dev/null +++ b/samples/InteractionFramework/Resources/CommandLocales.resx @@ -0,0 +1,132 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + echo + + + + Repeat the input + + + + mention the user + + + \ No newline at end of file diff --git a/samples/InteractionFramework/Resources/CommandLocales.ru.resx b/samples/InteractionFramework/Resources/CommandLocales.ru.resx new file mode 100644 index 0000000000..884298f004 --- /dev/null +++ b/samples/InteractionFramework/Resources/CommandLocales.ru.resx @@ -0,0 +1,132 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + echo + + + + Повторить ввод + + + + упомянуть пользователя + + + \ No newline at end of file diff --git a/samples/InteractionFramework/_InteractionFramework.csproj b/samples/InteractionFramework/_InteractionFramework.csproj index 2669b76a5b..dbaaec692f 100644 --- a/samples/InteractionFramework/_InteractionFramework.csproj +++ b/samples/InteractionFramework/_InteractionFramework.csproj @@ -16,4 +16,31 @@ + + + True + True + CommandLocales.resx + + + + + + ResXFileCodeGenerator + CommandLocales.Designer.cs + + + + + + ResXFileCodeGenerator + CommandLocales.Designer.cs + + + ResXFileCodeGenerator + CommandLocales.Designer.cs + + + + From 8757d14a24df2191118e9df9ccfc1f46c682258b Mon Sep 17 00:00:00 2001 From: Mihail Gribkov <61027276+Misha-133@users.noreply.github.com> Date: Mon, 26 Feb 2024 00:26:13 +0300 Subject: [PATCH 2/2] whoops --- .../Resources/CommandLocales.Designer.cs | 107 +++++++++--------- 1 file changed, 56 insertions(+), 51 deletions(-) diff --git a/samples/InteractionFramework/Resources/CommandLocales.Designer.cs b/samples/InteractionFramework/Resources/CommandLocales.Designer.cs index 0d606575f0..c4bf8305eb 100644 --- a/samples/InteractionFramework/Resources/CommandLocales.Designer.cs +++ b/samples/InteractionFramework/Resources/CommandLocales.Designer.cs @@ -1,66 +1,71 @@ -[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] -[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] -[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] -internal class CommandLocales -{ - - private static global::System.Resources.ResourceManager resourceMan; - - private static global::System.Globalization.CultureInfo resourceCulture; - - [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal CommandLocales() +namespace DiscordNetTestBot.Properties { + using System; + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class CommandLocales { - } - - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager - { - get + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal CommandLocales() + { + } + + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { - if (object.ReferenceEquals(resourceMan, null)) + get { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("CommandLocales", typeof(CommandLocales).Assembly); - resourceMan = temp; + if (object.ReferenceEquals(resourceMan, null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("CommandLocales", typeof(CommandLocales).Assembly); + resourceMan = temp; + } + return resourceMan; } - return resourceMan; } - } - - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture - { - get + + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { - return resourceCulture; + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } } - set + + internal static string echo_description { - resourceCulture = value; - } - } - - internal static string echo_description - { - get - { - return ResourceManager.GetString("echo.description", resourceCulture); + get + { + return ResourceManager.GetString("echo.description", resourceCulture); + } } - } - - internal static string echo_mention_description - { - get + + internal static string echo_mention_description { - return ResourceManager.GetString("echo.mention.description", resourceCulture); + get + { + return ResourceManager.GetString("echo.mention.description", resourceCulture); + } } - } - - internal static string echo_name - { - get + + internal static string echo_name { - return ResourceManager.GetString("echo.name", resourceCulture); + get + { + return ResourceManager.GetString("echo.name", resourceCulture); + } } } } +