Skip to main content

Module: i18next/src

Classes

Interfaces

Type aliases

ChannelTarget

Ƭ ChannelTarget: Message | DiscordChannel

Defined in

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


DiscordChannel

Ƭ DiscordChannel: TextBasedDiscordChannel | StoreChannel | StageChannel | VoiceChannel

Defined in

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


DynamicOptions

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

Type parameters

NameType
Textends InitOptions

Type declaration

Private (namespaces, languages): T

Used to dynamically add options based on found languages in {@link InternationalizationHandler#init}.

since 1.1.0

Parameters
NameType
namespacesstring[]
languagesstring[]
Returns

T

Defined in

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


StringMap

Ƭ StringMap: Object

indexer that is open to any value

Index signature

[key: string]: any

Defined in

node_modules/i18next/index.d.ts:684


TFunctionKeys

Ƭ TFunctionKeys: string | TemplateStringsArray

Defined in

node_modules/i18next/index.d.ts:741


TFunctionResult

Ƭ TFunctionResult: string | object | TFunctionDetailedResult | (string | object)[] | undefined | null

Defined in

node_modules/i18next/index.d.ts:734


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:689


Target

Ƭ Target: BaseCommandInteraction | ChannelTarget | Guild | MessageComponentInteraction

Defined in

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


TextBasedDiscordChannel

Ƭ TextBasedDiscordChannel: Message["channel"]

Defined in

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

Functions

editLocalized

editLocalized<TKeys>(target, keys): Promise<Message>

Edits a message using the language keys from your i18next language setup.

since 2.0.0

example

// Using a string to specify the key to send
await editLocalized(message, 'commands/ping:fail');
// ➡ "Pong!"

Type parameters

NameType
TKeysextends TFunctionKeys = string

Parameters

NameTypeDescription
targetMessage<boolean>The message to edit.
keysTKeys | TKeys[]The language keys to be sent.

Returns

Promise<Message>

Defined in

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

editLocalized<TKeys, TInterpolationMap>(target, options): Promise<Message>

Edits a message using LocalizedMessageOptions.

since 2.0.0

example

// Using an object to specify the key to send
await editLocalized(message, { keys: 'commands/ping:fail' });
// ➡ "Pong!"

example

// Passing interpolation options into i18next
const latency = 42;
const took = 96;

await editLocalized(message, {
keys: 'commands/ping:success',
formatOptions: { latency, took }
});
// ➡ "Pong! Took me 96ms to reply, and my heart took 42ms to beat!"

Type parameters

NameType
TKeysextends TFunctionKeys = string
TInterpolationMapextends NonNullObject = StringMap

Parameters

NameTypeDescription
targetMessage<boolean>The message to edit.
optionsLocalizedMessageOptions<TKeys, TInterpolationMap>A LocalizedMessageOptions object, requiring at least a keys field.

Returns

Promise<Message>

Defined in

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

editLocalized<TKeys>(target, keys): Promise<ReturnType<BaseCommandInteraction | MessageComponentInteraction["editReply"]>>

Edits a reply to an interaction, optionally deferred, using the given language.

since 2.4.0

example

// Using a string to specify the key to send
await editLocalized(interaction, 'commands/ping:fail');
// ➡ "Pong!"

Type parameters

NameType
TKeysextends TFunctionKeys = string

Parameters

NameTypeDescription
targetBaseCommandInteraction<CacheType> | MessageComponentInteraction<CacheType>The interaction to editReply.
keysTKeys | TKeys[]-

Returns

Promise<ReturnType<BaseCommandInteraction | MessageComponentInteraction["editReply"]>>

Defined in

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

editLocalized<TKeys, TInterpolationMap>(target, options): Promise<ReturnType<BaseCommandInteraction | MessageComponentInteraction["editReply"]>>

Edits a reply to an interaction, optionally deferred, using LocalizedInteractionReplyOptions.

since 2.4.0

example

// Using an object to specify the key to send
await editLocalized(interaction, { keys: 'commands/ping:fail' });
// ➡ "Pong!"

example

// Passing interpolation options into i18next
const latency = 42;
const took = 96;

await editLocalized(interaction, {
keys: 'commands/ping:success',
formatOptions: { latency, took }
});
// ➡ "Pong! Took me 96ms to reply, and my heart took 42ms to beat!"

Type parameters

NameType
TKeysextends TFunctionKeys = string
TInterpolationMapextends NonNullObject = StringMap

Parameters

NameTypeDescription
targetBaseCommandInteraction<CacheType> | MessageComponentInteraction<CacheType>The interaction to editReply.
optionsLocalizedInteractionReplyOptions<TKeys, TInterpolationMap>A LocalizedInteractionReplyOptions object, requiring at least a keys field.

Returns

Promise<ReturnType<BaseCommandInteraction | MessageComponentInteraction["editReply"]>>

Defined in

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


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 {@link Guild.preferredLocale}.
  2. Returns InternationalizationOptions.defaultName if no guild was provided.
  3. Returns 'en-US' if nothing else was found.

since 2.0.0

see {@link 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:35


fetchT

fetchT(target): Promise<TFunction>

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>

The language function from i18next.

Defined in

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


replyLocalized

replyLocalized<TKeys>(target, keys): Promise<Message>

Replies to a message using the language keys from your i18next language setup.

since 2.0.0

example

// Using an object to specify the key to send
await replyLocalized(message, 'commands/ping:loading');
// ➡ "Pinging..."

Type parameters

NameType
TKeysextends TFunctionKeys = string

Parameters

NameTypeDescription
targetMessage<boolean>The message to reply to.
keysTKeys | TKeys[]The language keys to be sent.

Returns

Promise<Message>

Defined in

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

replyLocalized<TKeys, TInterpolationMap>(target, options): Promise<Message>

Replies to a message using LocalizedMessageOptions.

since 2.0.0

example

// Using an object to specify the key to send
await replyLocalized(message, { keys: 'commands/ping:loading' });
// ➡ "Pinging..."

example

// Passing interpolation options into i18next
const latency = 42;

await replyLocalized(message, {
keys: 'commands/ping:loading',
formatOptions: { latency }
});
// ➡ "Pinging... current latency is 42ms."

Type parameters

NameType
TKeysextends TFunctionKeys = string
TInterpolationMapextends NonNullObject = StringMap

Parameters

NameTypeDescription
targetMessage<boolean>The message to reply to.
optionsLocalizedMessageOptions<TKeys, TInterpolationMap>A LocalizedMessageOptions object, requiring at least a keys field.

Returns

Promise<Message>

Defined in

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

replyLocalized<TKeys>(target, keys): Promise<ReturnType<BaseCommandInteraction | MessageComponentInteraction["reply"]>>

Replies to the interaction using the language keys from your i18next language setup.

since 2.4.0

example

// Using an object to specify the key to send
await replyLocalized(interaction, 'commands/ping:loading');
// ➡ "Pinging..."

Type parameters

NameType
TKeysextends TFunctionKeys = string

Parameters

NameTypeDescription
targetBaseCommandInteraction<CacheType> & { reply: (options: string | ReplyMessageOptions | InteractionReplyOptions | MessagePayload) => Promise<Promise<void>> } & MessageComponentInteraction<CacheType> & { reply: (options: string | ReplyMessageOptions | InteractionReplyOptions | MessagePayload) => Promise<Promise<void>> }The interaction to reply to.
keysTKeys | TKeys[]The language keys to be sent.

Returns

Promise<ReturnType<BaseCommandInteraction | MessageComponentInteraction["reply"]>>

Defined in

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

replyLocalized<TKeys, TInterpolationMap>(target, options): Promise<ReturnType<BaseCommandInteraction | MessageComponentInteraction["reply"]>>

Replies to the interaction using LocalizedInteractionReplyOptions.

since 2.4.0

example

// Using an object to specify the key to send
await replyLocalized(interaction, { keys: 'commands/ping:loading' });
// ➡ "Pinging..."

example

// Passing interpolation options into i18next
const latency = 42;

await replyLocalized(interaction, {
keys: 'commands/ping:loading',
formatOptions: { latency }
});
// ➡ "Pinging... current latency is 42ms."

Type parameters

NameType
TKeysextends TFunctionKeys = string
TInterpolationMapextends NonNullObject = StringMap

Parameters

NameTypeDescription
targetBaseCommandInteraction<CacheType> & { reply: (options: string | ReplyMessageOptions | InteractionReplyOptions | MessagePayload) => Promise<Promise<void>> } & MessageComponentInteraction<CacheType> & { reply: (options: string | ReplyMessageOptions | InteractionReplyOptions | MessagePayload) => Promise<Promise<void>> }The interaction to reply to.
optionsLocalizedInteractionReplyOptions<TKeys, TInterpolationMap>A LocalizedInteractionReplyOptions object, requiring at least a keys field.

Returns

Promise<ReturnType<BaseCommandInteraction | MessageComponentInteraction["reply"]>>

Defined in

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


resolveKey

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

Resolves a key and its parameters.

since 2.0.0

Type parameters

NameType
TResultextends TFunctionResult = string
TKeysextends TFunctionKeys = string
TInterpolationMapextends NonNullObject = StringMap

Parameters

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

Returns

Promise<TResult>

The data that key held, processed by i18next.

Defined in

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


sendLocalized

sendLocalized<TKeys>(target, keys): Promise<Message>

Send a localized message using the language keys from your i18next language setup.

since 2.0.0

example

// Using a string to specify the key to send
await sendLocalized(message, 'commands/ping:loading');
// ➡ "Pinging..."

Type parameters

NameType
TKeysextends TFunctionKeys = string

Parameters

NameTypeDescription
targetChannelTargetThe target to send the message to.
keysTKeys | TKeys[]The language keys to be sent.

Returns

Promise<Message>

Defined in

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

sendLocalized<TKeys, TInterpolationMap>(target, options): Promise<Message>

Send a localized message using LocalizedMessageOptions.

since 2.0.0

example

// Using an object to specify the key to send
await sendLocalized(message, { keys: 'commands/ping:loading' });
// ➡ "Pinging..."

example

// Passing interpolation options into i18next
const latency = 42;

await sendLocalized(message, {
keys: 'commands/ping:loading',
formatOptions: { latency }
});
// ➡ "Pinging... current latency is 42ms."

Type parameters

NameType
TKeysextends TFunctionKeys = string
TInterpolationMapextends NonNullObject = StringMap

Parameters

NameTypeDescription
targetChannelTargetThe target to send the message to.
optionsLocalizedMessageOptions<TKeys, TInterpolationMap>A LocalizedMessageOptions object, requiring at least a keys field.

Returns

Promise<Message>

Defined in

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