diff --git a/samples/InteractionFramework/Program.cs b/samples/InteractionFramework/Program.cs index 9731887d..d7572d12 100644 --- a/samples/InteractionFramework/Program.cs +++ b/samples/InteractionFramework/Program.cs @@ -4,6 +4,8 @@ using Discord.WebSocket; 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 00000000..c4bf8305 --- /dev/null +++ b/samples/InteractionFramework/Resources/CommandLocales.Designer.cs @@ -0,0 +1,71 @@ +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 + { + + 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 00000000..dec3a16f --- /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 00000000..884298f0 --- /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 2669b76a..dbaaec69 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 + + + +