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


DiscordChannel

ฦฌ DiscordChannel: TextBasedDiscordChannel | StoreChannel | StageChannel | VoiceChannel

Defined in

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


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


StringMap

ฦฌ StringMap: Object

indexer that is open to any value

Index signature

โ–ช [key: string]: any

Defined in

node_modules/i18next/index.d.ts:665


TFunctionKeys

ฦฌ TFunctionKeys: string | TemplateStringsArray

Defined in

node_modules/i18next/index.d.ts:691


TFunctionResult

ฦฌ TFunctionResult: string | object | (string | object)[] | undefined | null

Defined in

node_modules/i18next/index.d.ts:690


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


Target

ฦฌ Target: ChannelTarget | Guild

Defined in

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


TextBasedDiscordChannel

ฦฌ TextBasedDiscordChannel: Message["channel"]

Defined in

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

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

await editLocalized(message, 'commands/ping:success');
// โžก "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:165

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

Edits a message using an objects option.

since 2.0.0

example

await editLocalized(message, { keys: 'commands/ping:success' });
// โžก "Pong!"

example

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


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

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

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

Replies to another message using an object of LocalizedMessageOptions.

since 2.0.0

example

await replyLocalized(message, { keys: 'commands/ping:loading' });
// โžก "Pinging..."

example

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


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

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

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

Send a localized message using an object of LocalizedMessageOptions.

since 2.0.0

example

await sendLocalized(message, { keys: 'commands/ping:loading' });
// โžก "Pinging..."

example

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