Discord Slash Commands support name/description localization. Localization is available for names and descriptions of Slash Command Groups (GroupAttribute), Slash Commands (SlashCommandAttribute), Slash Command parameters and Slash Command Parameter Choices.
Resx Templates: dotnet tool install --global Discord.Net.Tools.Localization.Resx --version 1.1.0
Json Templates: dotnet tool install --global Discord.Net.Tools.Localization.Json --version 1.0.0
This tool can generate Resx and Json file templates which can be used for localization. By default this tool will generate a file for every command and description in your application and pre-fill values with your current values. You can then modify these files as needed or translate them to other langauges.
The ResxLocalizationManager uses .
delimited key names to traverse the resource files and get the localized strings (group1.group2.command.parameter.name
). A ResxLocalizationManager instance must be initialized with a base resource name, a target assembly and a collection of CultureInfo
s. Every key path must end with either .name
or .description
, including parameter choice strings. This tool can be used to create a resx localization file template using the following command: Resx-Template -t <TOKEN>
where you replace <TOKEN>
with your application's token.
The JsonLocaliationManager uses a nested data structure similar to Discord's Application Commands schema. You can get the Json schema here. JsonLocalizationManager accepts a base path and a base file name and automatically discovers every resource file ( \basePath\fileName.locale.json ). A Json resource file can be generated with this tool by running the following command: Json-Template -t <TOKEN>
where you replace <TOKEN>
with your application's token.
The Discord.Net Interaction Service can be initialized with an ILocalizationManager instance in its config which is used to create the necessary localization dictionaries on command registration. Interaction Service has two built-in ILocalizationManager implementations: ResxLocalizationManager and JsonLocalizationManager.
Insert Usage Example Code Here
Parameter | Description |
---|---|
--help | Display a list of all parameters. |
--version | Display currnet version information. |
-t | Required. The token of the application you want to generate the template for. |
-g | Guild to fetch the commands from. Fetches global commnands if no guild is specified. |
-o | The output directory to use. Defaults to current directory if not specified. |
-f | Name of the output file. Defaults to localizations is not specified. |