Skip to main content

Module: @sapphire/plugin-i18next

Classes

Interfaces

Type Aliases

BuilderWithNameAndDescription

Ƭ BuilderWithNameAndDescription: BuilderWithName & BuilderWithDescription

Defined in

projects/plugins/packages/i18next/src/lib/types.ts:180


ChannelTarget

Ƭ ChannelTarget: Message | DiscordChannel

Defined in

projects/plugins/packages/i18next/src/lib/types.ts:181


DiscordChannel

Ƭ DiscordChannel: TextBasedDiscordChannel | StageChannel | VoiceChannel

Defined in

projects/plugins/packages/i18next/src/lib/types.ts:139


DynamicOptions

Ƭ Private DynamicOptions<T>: (namespaces: string[], languages: string[]) => T

Type parameters

NameType
Textends InitOptions

Type declaration

▸ (namespaces, languages): T

Used to dynamically add options based on found languages in init.

Since

1.1.0

Parameters
NameType
namespacesstring[]
languagesstring[]
Returns

T

Defined in

projects/plugins/packages/i18next/src/lib/types.ts:63


TFunctionKeys

Ƭ TFunctionKeys: TFuncKey | TemplateStringsArray extends infer A ? A : never

Defined in

projects/plugins/packages/i18next/src/lib/types.ts:21


TFunctionResult

Ƭ TFunctionResult<N, TKPrefix>: TFuncReturn<N, TFunctionKeys, DefaultTFuncReturnWithObject, TKPrefix>

Type parameters

NameType
Nextends Namespace = TypeOptions["defaultNS"]
TKPrefixundefined

Defined in

projects/plugins/packages/i18next/src/lib/types.ts:22


TOptions

Ƭ TOptions<TInterpolationMap>: TOptionsBase & TInterpolationMap

Options that allow open ended values for interpolation unless type is provided.

Type parameters

NameType
TInterpolationMapextends object = StringMap

Defined in

node_modules/i18next/index.d.ts:717


Target

Ƭ Target: CommandInteraction | ChannelTarget | Guild | MessageComponentInteraction

Defined in

projects/plugins/packages/i18next/src/lib/types.ts:182


TextBasedDiscordChannel

Ƭ TextBasedDiscordChannel: Message["channel"]

Defined in

projects/plugins/packages/i18next/src/lib/types.ts:138

Functions

applyDescriptionLocalizedBuilder

applyDescriptionLocalizedBuilder<T>(builder, key): T

Applies the localized descriptions on the builder, calling setDescription and setDescriptionLocalizations.

Type parameters

NameType
Textends BuilderWithDescription<T>

Parameters

NameTypeDescription
builderTThe builder to apply the localizations to.
keystring | TemplateStringsArrayThe key to get the localizations from.

Returns

T

The updated builder.

Defined in

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


applyLocalizedBuilder

applyLocalizedBuilder<T>(builder, ...params): T

Applies the localized names and descriptions on the builder, calling applyNameLocalizedBuilder and applyDescriptionLocalizedBuilder.

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

Example

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.

Example

class UserInfoCommand extends Command {
public registerApplicationCommands(registry: ChatInputCommand.Registry) {
registry.registerChatInputCommand(
(builder) =>
applyLocalizedBuilder(builder, 'commands:userinfo')
.addUserOption(
(input) => applyLocalizedBuilder(input, 'options:userinfo').setRequired(true)
)
);
}
}

Type parameters

NameType
Textends BuilderWithName<T> & BuilderWithDescription<T>

Parameters

NameTypeDescription
builderTThe builder to apply the localizations to.
...params[root: string] | [name: string | TemplateStringsArray, description: string | TemplateStringsArray]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.

Defined in

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


applyNameLocalizedBuilder

applyNameLocalizedBuilder<T>(builder, key): T

Applies the localized names on the builder, calling setName and setNameLocalizations.

Type parameters

NameType
Textends BuilderWithName<T>

Parameters

NameTypeDescription
builderTThe builder to apply the localizations to.
keystring | TemplateStringsArrayThe key to get the localizations from.

Returns

T

The updated builder.

Defined in

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


createLocalizedChoice

createLocalizedChoice<ValueType>(key, options): APIApplicationCommandOptionChoice<ValueType>

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

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' })
)
)
);
}
}

Type parameters

NameType
ValueTypestring | number

Parameters

NameTypeDescription
keystring | TemplateStringsArrayThe 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.

Defined in

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


fetchLanguage

fetchLanguage(target): Promise<string>

Retrieves the language name for a specific target, using fetchLanguage. If fetchLanguage is not defined or this function returns a nullish value, then there will be a series of fallback attempts in the following descending order:

  1. Returns Guild.preferredLocale.
  2. Returns defaultName if no guild was provided.
  3. Returns 'en-US' if nothing else was found.

Since

2.0.0

See

resolveLanguage

Parameters

NameTypeDescription
targetTargetThe target to fetch the language from.

Returns

Promise<string>

The name of the language key.

Defined in

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


fetchT

fetchT(target): Promise<TFunction<"translation", undefined, "translation">>

Retrieves the language-assigned function from i18next designated to a target's preferred language code.

Since

2.0.0

Parameters

NameTypeDescription
targetTargetThe target to fetch the language from.

Returns

Promise<TFunction<"translation", undefined, "translation">>

The language function from i18next.

Defined in

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


getLocalizedData

getLocalizedData(key): LocalizedData

Gets the value and the localizations from a language key.

Remarks

This should be called strictly after loading the locales.

Parameters

NameTypeDescription
keystring | TemplateStringsArrayThe key to get the localizations from.

Returns

LocalizedData

The retrieved data.

Defined in

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


resolveKey

resolveKey<TResult, TKeys, TInterpolationMap>(target, key, options?): Promise<TResult>

Resolves a key and its parameters.

Since

2.0.0

Type parameters

NameType
TResultextends DefaultTFuncReturnWithObject = string
TKeysextends string = string
TInterpolationMapextends object = StringMap

Parameters

NameTypeDescription
targetTargetThe target to fetch the language key from.
keyTKeys | TKeys[]The i18next key.
options?TOptions<TInterpolationMap>The options to be passed to TFunction.

Returns

Promise<TResult>

The data that key held, processed by i18next.

Defined in

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