Skip to main content

Module: @sapphire/plugin-i18next

Classes

Interfaces

Type Aliases

$SpecialObject

Ƭ $SpecialObject: $Dictionary | (string | $Dictionary)[]

This is a re-exported type from i18next. It is the returned type from resolveKey when returnObjects is true in the options.

Defined in

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


BuilderWithNameAndDescription

Ƭ BuilderWithNameAndDescription: BuilderWithName & BuilderWithDescription

Defined in

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


ChannelTarget

Ƭ ChannelTarget: Message | DiscordChannel

Defined in

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


DiscordChannel

Ƭ DiscordChannel: TextBasedDiscordChannel | StageChannel | VoiceChannel

Defined in

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


DynamicOptions

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

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

Since

1.1.0

Type parameters

NameType
Textends InitOptions

Type declaration

▸ (namespaces, languages): T

Parameters
NameType
namespacesstring[]
languagesstring[]
Returns

T

Defined in

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


I18nextFormatter

Ƭ I18nextFormatter: I18nextNamedFormatter | I18nextNamedCachedFormatter

Represents a formatter that is added to i18next with i18next.services.formatter.add or i18next.services.formatter.addCached, depending on the cached property.

Since

7.1.0

Seealso

https://www.i18next.com/translation-function/formatting#adding-custom-format-function

Defined in

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


TOptions

Ƭ TOptions<TInterpolationMap>: TOptionsBase & TInterpolationMap

Type parameters

NameType
TInterpolationMapextends object = $Dictionary

Defined in

node_modules/i18next/typescript/options.d.ts:756


Target

Ƭ Target: BaseInteraction | ChannelTarget | Guild

Defined in

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


TextBasedDiscordChannel

Ƭ TextBasedDiscordChannel: Message["channel"]

Defined in

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

Variables

i18next

Const i18next: i18n

Defined in

node_modules/i18next/index.d.mts:42


version

Const version: string = '[VI]{{inject}}[/VI]'

The @sapphire/plugin-i18next version that you are currently using. An example use of this is showing it of in a bot information command.

Note to Sapphire developers: This needs to explicitly be string so it is not typed as the string that gets replaced by esbuild

Defined in

projects/plugins/packages/i18next/src/index.ts:26

Functions

applyDescriptionLocalizedBuilder

applyDescriptionLocalizedBuilder<T, TOpt, Ns, KPrefix>(builder, key): T

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

Type parameters

NameType
Textends BuilderWithDescription
TOptextends TOptions = TOptions
Nsextends Namespace = "translation"
KPrefixundefined

Parameters

NameTypeDescription
builderTThe builder to apply the localizations to.
keystringThe key to get the localizations from.

Returns

T

The updated builder.

Defined in

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


applyLocalizedBuilder

applyLocalizedBuilder<T, TOpt, Ns, KPrefix>(builder, ...params): T

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

Type parameters

NameType
Textends BuilderWithNameAndDescription
TOptextends TOptions = TOptions
Nsextends Namespace = "translation"
KPrefixundefined

Parameters

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

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

Defined in

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


applyNameLocalizedBuilder

applyNameLocalizedBuilder<T, TOpt, Ns, KPrefix>(builder, key): T

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

Type parameters

NameType
Textends BuilderWithName
TOptextends TOptions = TOptions
Nsextends Namespace = "translation"
KPrefixundefined

Parameters

NameTypeDescription
builderTThe builder to apply the localizations to.
keystringThe key to get the localizations from.

Returns

T

The updated builder.

Defined in

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


createLocalizedChoice

createLocalizedChoice<ValueType, TOpt, Ns, KPrefix>(key, options): APIApplicationCommandOptionChoice<ValueType>

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

Type parameters

NameType
ValueTypestring | number
TOptextends TOptions = TOptions
Nsextends Namespace = "translation"
KPrefixundefined

Parameters

NameTypeDescription
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:304


fetchLanguage

fetchLanguage(target): Promise<string>

Retrieves the language name for a specific target, using InternationalizationHandler.fetchLanguage. If InternationalizationHandler.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 InternationalizationOptions.defaultName if no guild was provided.
  3. Returns 'en-US' if nothing else was found.

Parameters

NameTypeDescription
targetTargetThe target to fetch the language from.

Returns

Promise<string>

The name of the language key.

Since

2.0.0

See

resolveLanguage

Defined in

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


fetchT

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

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

Parameters

NameTypeDescription
targetTargetThe target to fetch the language from.

Returns

Promise<TFunction<"translation", undefined>>

The language function from i18next.

Since

2.0.0

Defined in

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


getLocalizedData

getLocalizedData<TOpt, Ns, KPrefix>(key): LocalizedData

Gets the value and the localizations from a language key.

Type parameters

NameType
TOptextends TOptions = TOptions
Nsextends Namespace = "translation"
KPrefixundefined

Parameters

NameTypeDescription
keystringThe key to get the localizations from.

Returns

LocalizedData

The retrieved data.

Remarks

This should be called strictly after loading the locales.

Defined in

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


resolveKey

resolveKey<Key, TOpt, Ret, Ns, ActualOptions>(target, ...«destructured»): Promise<TFunctionReturnOptionalDetails<Ret, TOpt>>

Resolves a key and its parameters.

Type parameters

NameType
Keyextends string
TOptextends TOptions = TOptions
Retextends string | $SpecialObject = TOpt["returnObjects"] extends true ? $SpecialObject : string
Nsextends Namespace = "translation"
ActualOptionsextends TOptionsBase & $Dictionary = TOpt & InterpolationMap<Ret>

Parameters

NameTypeDescription
targetTargetThe target to fetch the language key from.
...«destructured»[key: Key | Key[], options?: ActualOptions] | [key: string | string[], options: TOpt & $Dictionary & Object] | [key: string | string[], defaultValue: string, options?: TOpt & $Dictionary]-

Returns

Promise<TFunctionReturnOptionalDetails<Ret, TOpt>>

The data that key held, processed by i18next.

Since

2.0.0

Defined in

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