Discord.Net
Discord.Net copied to clipboard
Interactions Command Localization
This PR adds Application Command localization to Core, Rest and WebSocket projects. Introduces a ILocalizationManger
interface and default Localization Managers for Json and ResX in preperation for the Slash Commands localization feature release.
Two LocalizationManagers ship with this update, JsonLocalizationManager and ResxLocalizationManager.
JsonLocaliationManager uses a nested data structure similar to Discord's Application Commands schema. You can get the Json schema here. LocalizationManager accepts a base path and a base file name and automatically discovers every resource file ( \basePath\fileName.locale.json
).
{
"command_1":{
"name": "localized_name",
"description": "localized_description",
"parameter_1":{
"name": "localized_name",
"description": "localized_description"
}
},
"group_1":{
"name": "localized_name",
"description": "localized_description",
"command_1":{
"name": "localized_name",
"description": "localized_description",
"parameter_1":{
"name": "localized_name",
"description": "localized_description"
},
"parameter_2":{
"name": "localized_name",
"description": "localized_description"
}
}
}
}
ResxLocalizationManager uses the naming scheme used by ASP.NET ( group1\command1\parameter2.fr-FR.resx
or group1.command1.parameter2.fr-FR.resx
). Every resx file must have two fields: name and description. Individual .resx files can be defined for every group/command/parameter. Space characters within Context command names are tokenized with tilde character.
Interaction Service can be easily configured to use any ILocalizationManager
implementation by setting the LocalizationManager field of InteractionServiceConfig.
TODO
- [x] Add per-request header support to rest client(#2261)
- [x] Add localization support to parameter choices
- [x] Add locale parameter to Get*ApplicationCommandsAsync methods for fetching localized name and description strings
Breaking Changes
- A new requestHeaders parameter is added to every Send* method of IRestClient.
- Two new parameters have been added to every `Get*ApplicationCommandsAsync` method (`withLocalizations`, `locale`)
@Cenngo perhaps include some docs/guide for this update as well?
XML lgtm, but awaiting to approve until I've verified functionality. Going try to build an app on localization for testing
i also need to do that myself. its been a while since i lasted tested this PR and im sure discord broke a thing or two since then