Discord.Net icon indicating copy to clipboard operation
Discord.Net copied to clipboard

Interactions Command Localization

Open Cenngo opened this issue 2 years ago • 2 comments

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 avatar Jul 21 '22 14:07 Cenngo

@Cenngo perhaps include some docs/guide for this update as well?

MrCakeSlayer avatar Aug 01 '22 20:08 MrCakeSlayer

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

Cenngo avatar Aug 01 '22 21:08 Cenngo