Optional
resources: Map<string, object>When true, returns pseudo language string. Defaults to false.
Returns the current language resource in use
Returns the translated formatted string if exists, falls back to default resource if translated string doesn't exist in current resource throws an error if current resource does not exist
the string to translate
Optional
params: string[]the tokens to replace in translated string if exist
the translated string with tokens
const resource = new Map([
['jp-JP', { "LOADING": "読み込み中..." }],
['en-US', { "LOADING": "Loading..." }]
]);
localizationService = new LfLocalizationService(resource);
localizationService.getString('LOADING'); // 'Loading...'
localizationService.setLanguage('jp-JP');
localizationService.getString('LOADING'); // '読み込み中...'
Resets the resource map to include remote language resource files: en by default, and the closest selected language (e.g.: if selected language is fr-CA, and fr-CA doesn't exists but fr exists, it loads fr)
the url to the language file's folder
const localizationService = new LfLocalizationService();
const resourcesFolder = 'https://lfxstatic.com/npm/@laserfiche/lf-resource-library@4/resources/laserfiche-base';
localizationService.setLanguage('fr-CA');
await localizationService.initResourcesFromUrlAsync(resourcesFolder); // loads en-US.json and fr-FR.json
Sets currentResource given the language code, fall back to available resource if necessary.
const localizationService = new LfLocalizationService();
const resourcesFolder = 'https://lfxstatic.com/npm/@laserfiche/lf-resource-library@4/resources/laserfiche-base';
localizationService.setLanguage('fr-CA'); // gives a warning since no resource exists at this point
await localizationService.initResourcesFromUrlAsync(resourcesFolder); // loads en.json and fr.json because language has been set to be fr-CA
localizationService.currentLanguage // {'language': 'fr', 'resource': { ... }}
const resource = new Map([
['jp-JP', { "LOADING": "読み込み中..." }],
['en-US', { "LOADING": "Loading..." }]
]);
localizationService = new LfLocalizationService(resource);
localizationService.setLanguage('jp-JP'); // set currentResource to ir
localizationService.currentLanguage // {'language': 'jp-JP', 'resource':{ "LOADING": "読み込み中..." }}
Example