Skip to main content

Function: createLocalizedChoice()

createLocalizedChoice<ValueType, TOpt, Ns, KPrefix>(key: string, options: Omit<APIApplicationCommandOptionChoice<ValueType>, "name" | "name_localizations">): APIApplicationCommandOptionChoice<ValueType>

Constructs an object that can be passed into setChoices for String or Number option with localized names.

Type Parameters

Type ParameterDefault type
ValueTypestring | number
TOpt extends TOptionsTOptions
Ns extends Namespace"translation"
KPrefixundefined

Parameters

ParameterTypeDescription
keystringThe i18next key for the name of the select option name.
optionsOmit<APIApplicationCommandOptionChoice<ValueType>, "name" | "name_localizations">The additional Select Menu options. This should at least include the value key.

Returns

APIApplicationCommandOptionChoice<ValueType>

An object with anything provided through createLocalizedChoice.options with name and name_localizations added.

Example

export class TypeCommand extends Command {
public override registerApplicationCommands(registry: ChatInputCommand.Registry) {
registry.registerChatInputCommand((builder) =>
applyLocalizedBuilder(builder, 'commands/names:type').addStringOption((option) =>
applyLocalizedBuilder(option, 'commands/options:type')
.setRequired(true)
.setChoices(
createLocalizedChoice('selects/pokemon:type-grass', { value: 'grass' }),
createLocalizedChoice('selects/pokemon:type-water', { value: 'water' }),
createLocalizedChoice('selects/pokemon:type-fire', { value: 'fire' }),
createLocalizedChoice('selects/pokemon:type-electric', { value: 'electric' })
)
)
);
}
}

Defined in

projects/plugins/packages/i18next/src/lib/functions.ts:356