Concierge provides a built in translation service for its modules. This service is exposed via the $$
object, a tagged template literal which can be used to translate any literal automatically. The locale of Concierge can be set via the command-line, configuration files or manually within code.
Translation files are stored as json dictionaries within the i18n
subdirectory of a module. The name of the .json
file is the code for the translation (e.g. en.json
is the translations for the en
code). Translations are loaded automatically based on the set locale and are specific to each module.
Example
Within code:
api.sendMessage($$`Example Key ${exampleValue}`, event.thread_id);
The i18n/foo.json
file:
{
"Example Key ${0}": "Some example translation of example key, that embeds the value, ${0}"
}
All of these methods are available for use on the $$
object, which is available globally.
- translate(strings, values, context) ⇒
string
-
Translates a given format string with context.
Automatically aliased as a tagged template literal available via `$$`.
- hook(func, context = null)
Provides a means to override the translation.
- setLocale(localeString)
Sets the current locale of the system.
- getLocale() ⇒
string
Gets the current locale of the system.
- removeContextIfExists(context)
Removes a translation context if that context exists.
Translates a given format string with context.
This method is automatically aliased as a tagged template literal available via $$
. When called via $$
, the context
parameter will be resolved based on the current caller.
Kind: API method
Returns: the translated string.
Param | Type | Description |
---|---|---|
strings | Array |
input format string split at format values. These are the sections outside of the ${x} sections of the format string. |
values | Array |
input format values. These are the values of strings contained within ${x} sections of the format string. |
context | string |
the context in which to translate. This is unique to each module. |
Provides a means to override the translation.
Kind: API method
See: MDN: Tagged Template Literals.
Param | Type | Description |
---|---|---|
func | function() |
a function that will receive a tagged template literal. |
context | string |
the translation context. Either the module name or global context identifier. This parameter is optional, if not provided (null ) will default to the current context. |
Sets the current locale of the system.
Kind: API method
Param | Type | Description |
---|---|---|
localeString | string |
the string to set the locale to. E.g. en for English. |
Gets the current locale of the translation system.
Kind: API method
Returns: locale string. E.g. en
for English.
Removes a translation context if that context exists.
Has no limitations, so has the ability to remove the global context as well... (be careful).
Kind: API method
Param | Type | Description |
---|---|---|
context | string |
the translation context. Either the module name or global context identifier. |