Function: applyLocalizedBuilder()
applyLocalizedBuilder<
T
,TOpt
,Ns
,KPrefix
>(builder
:T
, ...params
: [string
] | [string
,string
]):T
Applies the localized names and descriptions on the builder, calling applyNameLocalizedBuilder and applyDescriptionLocalizedBuilder.
Type Parameters
Type Parameter | Default type |
---|---|
T extends BuilderWithNameAndDescription | - |
TOpt extends TOptions | TOptions |
Ns extends Namespace | "translation" |
KPrefix | undefined |
Parameters
Parameter | Type | Description |
---|---|---|
builder | T | The builder to apply the localizations to. |
...params | [string ] | [string , string ] | The root key or the key for the name and description keys. This needs to be either 1 or 2 parameters. See examples below for more information. |
Returns
T
The updated builder. You can chain subsequent builder methods on this.
Remarks
If only 2 parameters were passed, then this function will automatically append Name
and Description
to the root-key (wherein root-key
is second parameter in the function, after builder
)
passed through the second parameter.
For example given applyLocalizedBuilder(builder, 'userinfo')
the localized options will use the i18next keys
userinfoName
and userinfoDescription
.
In the following example we provide all parameters and add a User Option
applyLocalizedBuilder
needs either
Examples
class UserInfoCommand extends Command {
public registerApplicationCommands(registry: ChatInputCommand.Registry) {
registry.registerChatInputCommand(
(builder) =>
applyLocalizedBuilder(builder, 'commands/names:userinfo', 'commands/descriptions:userinfo')
.addUserOption(
(input) => applyLocalizedBuilder(input, 'commands/options:userinfo-name', 'commands/options:userinfo-description').setRequired(true)
)
);
}
}
In the following example we provide single root keys which means Name
and Description
get appended as mentioned above.
class UserInfoCommand extends Command {
public registerApplicationCommands(registry: ChatInputCommand.Registry) {
registry.registerChatInputCommand(
(builder) =>
applyLocalizedBuilder(builder, 'commands:userinfo')
.addUserOption(
(input) => applyLocalizedBuilder(input, 'options:userinfo').setRequired(true)
)
);
}
}