27 lines
1.2 KiB
TypeScript
27 lines
1.2 KiB
TypeScript
import {createLocalizer, createLanguageController, fetchPack, overlayPack} from './runtime.mjs';
|
|
import type {Pack} from './runtime.mjs';
|
|
import type {Translate} from './messages.generated.mjs';
|
|
|
|
declare const pack: Pack;
|
|
const messages = createLocalizer(pack);
|
|
const t: Translate = messages.t;
|
|
t('common', 'greeting', {first_name: 'Alex'});
|
|
t('common', 'count', {count: 9223372036854775807n});
|
|
t('common', 'count', {count: '9223372036854775807'});
|
|
t('common', 'literal', {});
|
|
// @ts-expect-error a message without parameters accepts only an empty object
|
|
t('common', 'literal', {extra: 1});
|
|
// @ts-expect-error missing parameter
|
|
t('common', 'greeting', {});
|
|
// @ts-expect-error invalid parameter type
|
|
t('common', 'greeting', {first_name: false});
|
|
// @ts-expect-error undeclared parameter
|
|
t('common', 'greeting', {first_name: 'Alex', secret: 'extra'});
|
|
// @ts-expect-error unknown key
|
|
t('common', 'unknown', {});
|
|
// @ts-expect-error unknown namespace
|
|
t('missing', 'literal', {});
|
|
const controller = createLanguageController(pack, locale => fetchPack('/' + locale + '.json'));
|
|
void controller.setLanguage('en');
|
|
overlayPack(pack, [{version: 1, locale: 'en', namespace: 'common', messages: {literal: {value: {text: 'Custom'}}}}]);
|