@bigcommerce/checkout-sdk / LanguageService
Responsible for getting language strings.
This object can be used to retrieve language strings that are most appropriate for a given locale.
The language strings provided to the object should follow ICU MessageFormat syntax.
• new LanguageService()
▸ getLocale(): string
Gets the preferred locale of the current customer.
string
The preferred locale code.
▸ mapKeys(maps
): void
Remaps a set of language strings with a different set of keys.
service.mapKeys({
'new_key': 'existing_key',
});
console.log(service.translate('new_key'));
Name | Type | Description |
---|---|---|
maps |
Object |
The set of language strings. |
void
▸ translate(key
, data?
): string
Gets a language string by a key.
service.translate('language_key');
If the language string contains a placeholder, you can replace it by providing a second argument.
service.translate('language_key', { placeholder: 'Hello' });
Name | Type | Description |
---|---|---|
key |
string |
The language key. |
data? |
TranslationData |
Data for replacing placeholders in the language string. |
string
The translated language string.