Module: @sapphire/plugin-i18next
Classes
Interfaces
- $Dictionary
- BuilderWithDescription
- BuilderWithName
- HMROptions
- I18nextFormatters
- InternationalizationClientOptions
- InternationalizationContext
- InternationalizationOptions
- LocalizedData
- TFunction
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:172
ChannelTarget
Ƭ ChannelTarget: Message
| DiscordChannel
Defined in
projects/plugins/packages/i18next/src/lib/types.ts:173
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
Type parameters
Name | Type |
---|---|
T | extends InitOptions |
Type declaration
▸ (namespaces
, languages
): T
Used to dynamically add options based on found languages in init.
Parameters
Name | Type |
---|---|
namespaces | string [] |
languages | string [] |
Returns
T
Since
1.1.0
Defined in
projects/plugins/packages/i18next/src/lib/types.ts:55
TOptions
Ƭ TOptions<TInterpolationMap
>: TOptionsBase
& TInterpolationMap
Type parameters
Name | Type |
---|---|
TInterpolationMap | extends object = $Dictionary |
Defined in
node_modules/i18next/typescript/options.d.ts:751
Target
Ƭ Target: BaseInteraction
| ChannelTarget
| Guild
Defined in
projects/plugins/packages/i18next/src/lib/types.ts:174
TextBasedDiscordChannel
Ƭ TextBasedDiscordChannel: Message
["channel"
]
Defined in
projects/plugins/packages/i18next/src/lib/types.ts:130
Functions
applyDescriptionLocalizedBuilder
▸ applyDescriptionLocalizedBuilder<T
, TOpt
, Ns
, KPrefix
>(builder
, key
): T
Applies the localized descriptions on the builder, calling setDescription
and setDescriptionLocalizations
.
Type parameters
Name | Type |
---|---|
T | extends BuilderWithDescription |
TOpt | extends TOptions = TOptions |
Ns | extends Namespace = "translation" |
KPrefix | undefined |
Parameters
Name | Type | Description |
---|---|---|
builder | T | The builder to apply the localizations to. |
key | string | The 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
Name | Type |
---|---|
T | extends BuilderWithNameAndDescription |
TOpt | extends TOptions = TOptions |
Ns | extends Namespace = "translation" |
KPrefix | undefined |
Parameters
Name | Type | Description |
---|---|---|
builder | T | The 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
Name | Type |
---|---|
T | extends BuilderWithName |
TOpt | extends TOptions = TOptions |
Ns | extends Namespace = "translation" |
KPrefix | undefined |
Parameters
Name | Type | Description |
---|---|---|
builder | T | The builder to apply the localizations to. |
key | string | The 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
Name | Type |
---|---|
ValueType | string | number |
TOpt | extends TOptions = TOptions |
Ns | extends Namespace = "translation" |
KPrefix | undefined |
Parameters
Name | Type | Description |
---|---|---|
key | string | The i18next key for the name of the select option name. |
options | Omit <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 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:
- Returns Guild.preferredLocale.
- Returns defaultName if no guild was provided.
- Returns
'en-US'
if nothing else was found.
Parameters
Name | Type | Description |
---|---|---|
target | Target | The 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
Name | Type | Description |
---|---|---|
target | Target | The 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
Name | Type |
---|---|
TOpt | extends TOptions = TOptions |
Ns | extends Namespace = "translation" |
KPrefix | undefined |
Parameters
Name | Type | Description |
---|---|---|
key | string | The key to get the localizations from. |
Returns
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
Name | Type |
---|---|
Key | extends string |
TOpt | extends TOptions = TOptions |
Ret | extends string | $SpecialObject = TOpt ["returnObjects" ] extends true ? $SpecialObject : string |
Ns | extends Namespace = "translation" |
ActualOptions | extends TOptionsBase & $Dictionary & InterpolationMap <Ret > = TOpt & InterpolationMap <Ret > |
Parameters
Name | Type | Description |
---|---|---|
target | Target | The 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