Skip to main content

Module: @sapphire/plugin-i18next

Classes

Interfaces

Type aliases

ChannelTarget

Ƭ ChannelTarget: Message | DiscordChannel

Defined in

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


DiscordChannel

Ƭ DiscordChannel: TextBasedDiscordChannel | StoreChannel | StageChannel | VoiceChannel

Defined in

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


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


Target

Ƭ Target: ChannelTarget | Guild

Defined in

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


TextBasedDiscordChannel

Ƭ TextBasedDiscordChannel: Message["channel"]

Defined in

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

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

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

Edits a message using an objects option.

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>The options to be sent, requiring at least keys to be passed.

Returns

Promise<Message>

Defined in

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


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


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


replyLocalized

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

Replies to another 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:125

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

Replies to another message using an object of 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>The options to be sent, requiring at least keys to be passed.

Returns

Promise<Message>

Defined in

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


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


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

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

Send a localized message using an object of 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>The options to be sent, requiring at least keys to be passed.

Returns

Promise<Message>

Defined in

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