From 75ae48830e256086be58e25e1534358572d9dd7a Mon Sep 17 00:00:00 2001 From: Florian Pabst Date: Sun, 2 Apr 2023 22:03:05 +0200 Subject: [PATCH] Update EnumConverter and ApplicationCommandOption to register localizations (#2651) --- .../TypeConverters/SlashCommands/EnumConverter.cs | 5 ++++- src/Discord.Net.Rest/API/Common/ApplicationCommandOption.cs | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Discord.Net.Interactions/TypeConverters/SlashCommands/EnumConverter.cs b/src/Discord.Net.Interactions/TypeConverters/SlashCommands/EnumConverter.cs index c46b5a2d..b95e859c 100644 --- a/src/Discord.Net.Interactions/TypeConverters/SlashCommands/EnumConverter.cs +++ b/src/Discord.Net.Interactions/TypeConverters/SlashCommands/EnumConverter.cs @@ -1,6 +1,7 @@ using Discord.WebSocket; using System; using System.Collections.Generic; +using System.Collections.Immutable; using System.Linq; using System.Reflection; using System.Threading.Tasks; @@ -22,6 +23,7 @@ namespace Discord.Interactions { var names = Enum.GetNames(typeof(T)); var members = names.SelectMany(x => typeof(T).GetMember(x)).Where(x => !x.IsDefined(typeof(HideAttribute), true)); + var localizationManager = parameterInfo.Command.Module.CommandService.LocalizationManager; if (members.Count() <= 25) { @@ -33,7 +35,8 @@ namespace Discord.Interactions choices.Add(new ApplicationCommandOptionChoiceProperties { Name = displayValue, - Value = member.Name + Value = member.Name, + NameLocalizations = localizationManager?.GetAllNames(parameterInfo.GetChoicePath(new ParameterChoice(displayValue.ToLower(), member.Name)), LocalizationTarget.Choice) ?? ImmutableDictionary.Empty }); } properties.Choices = choices; diff --git a/src/Discord.Net.Rest/API/Common/ApplicationCommandOption.cs b/src/Discord.Net.Rest/API/Common/ApplicationCommandOption.cs index fb64d5eb..ae0c3215 100644 --- a/src/Discord.Net.Rest/API/Common/ApplicationCommandOption.cs +++ b/src/Discord.Net.Rest/API/Common/ApplicationCommandOption.cs @@ -93,7 +93,8 @@ namespace Discord.API Choices = option.Choices?.Select(x => new ApplicationCommandOptionChoice { Name = x.Name, - Value = x.Value + Value = x.Value, + NameLocalizations = x.NameLocalizations?.ToDictionary() ?? Optional>.Unspecified, }).ToArray() ?? Optional.Unspecified; Options = option.Options?.Select(x => new ApplicationCommandOption(x)).ToArray() ?? Optional.Unspecified;