The client that this localizer will be used by.
The options for this localizer.
Throws if the supplied default locale is not supported.
Readonly
clientThe client that this localizer will be used by.
Localizer
Readonly
defaultThe default locale to be used in case a guild does not have its locale set in the client's data provider. You should set a data provider before setting this up so the guild's locale can be saved persistently.
Localizer
Readonly
guildThe GuildLocalizers for each guild.
Localizer
Readonly
localeAn object that maps the name of the locale to another object that contains all the available messages mapped by their keys. The messages should follow a ICU standard, for more information on how to structure these messages, please visit the following link.
The following is an example of how to structure this object:
en: {
'message.test.hello': 'Hello',
'message.test.bye': 'Bye',
'message.test.with_value': 'Hello {name}!'
},
es: {
'message.test.hello': 'Hola',
'message.test.bye': 'Adios',
'message.test.with_value': 'Hola {name}!'
},
fr: {
'message.test.hello': 'Bonjour',
'message.test.bye': 'Au revoir',
'message.test.with_value': 'Bonjour {name}!'
}
Localizer
Readonly
optionsThe options for this localizer.
Localizer
Get the localizer for the given guild.
The guild localizer for the given guild.
Private
getGet the formatter object to format the message of the given key and locale. If no message for the given locale exists, then the message for the default locale will be used.
The key of the message to translate.
The locale to translate the message to.
The formatter object for translating the message.
Throws if the key does not resolve to any message.
Throws if the given locale is not supported.
Private
handlePrivate
Handles the creation and initialization of a newly joined guild's localizer.
The guild that was joined.
A promise that resolves once the guild localizer is ready.
Rejects if the guild localizer was being initialized with an unsupported locale retrieved from the data provider. This may happen if the locale saved in the data provider was updated manually.
Private
handlePrivate
Handles the deletion of the localizer of the guild that has been left.
The guild that was left.
A promise that resolves once the guild localizer has been removed from both this and the data provider (if any).
Initializes all the GuildLocalizers for each guild the client is connected to.
You should call this after initializing the client's data provider since this method
will read the locale set for each guild and will initialize their localizer with that value.
In case the client does not have a data provider, you should still call this method, but the
localizers will be initialized with the default locale.
This also registers event handlers for client#guildCreate and client#guildDelete events
to automatically create or delete localizers if the bot joins or leaves another guild.
You should use the GUILDS
intent.
A promise that resolves once all guild localizers are ready.
Rejects if a guild localizer was being initialized with an unsupported locale retrieved from the data provider. This may happen if the locale saved in the data provider was updated manually.
Alias for translate()
.
The key of the message to translate.
Optional
locale: null | stringThe locale to translate the message to.
The dynamic values to be replaced in the message.
The translated message.
Throws if the key does not resolve to any message.
Throws if the given locale is not supported.
Get the message for the given key translated into the given locale. You can also supply an object containing the dynamic values to be used.
The key of the message to translate.
Optional
locale: null | stringThe locale to translate the message to.
The dynamic values to be replaced in the message.
The translated message.
Throws if the key does not resolve to any message.
Throws if the given locale is not supported.
Generated using TypeDoc
A class to help with the localization of your bot. This handles string translation based on the intl-messageformat package. Strings are defined in ICU format and dynamic values inside. It is recommended to have a data provider set in the client for the locale settings to be saved persistently for each guild.