Skip to content

Latest commit

 

History

History
101 lines (60 loc) · 1.78 KB

LanguageService.md

File metadata and controls

101 lines (60 loc) · 1.78 KB

@bigcommerce/checkout-sdk / LanguageService

Class: 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.

Table of contents

Constructors

Methods

Constructors

constructor

new LanguageService()

Methods

getLocale

getLocale(): string

Gets the preferred locale of the current customer.

Returns

string

The preferred locale code.


mapKeys

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'));

Parameters

Name Type Description
maps Object The set of language strings.

Returns

void


translate

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' });

Parameters

Name Type Description
key string The language key.
data? TranslationData Data for replacing placeholders in the language string.

Returns

string

The translated language string.