@gobstones/gobstones-lang
Version:
32 lines • 983 B
JavaScript
/* eslint-disable @typescript-eslint/ban-types */
import { LOCALE_EN } from '../i18n/en';
import { LOCALE_ES } from '../i18n/es';
import { LOCALE_PT } from '../i18n/pt';
let CURRENT_LANGUAGE = 'es';
const dictionaries = {
es: LOCALE_ES,
en: LOCALE_EN,
pt: LOCALE_PT
};
export const i18n = (message) => dictionaries[CURRENT_LANGUAGE][message];
export const i18nF = (message) => dictionaries[CURRENT_LANGUAGE][message];
export function i18nWithLanguage(code, thunk) {
if (!(code in dictionaries)) {
throw Error('Invalid language code: ' + code);
}
const oldLanguage = CURRENT_LANGUAGE;
CURRENT_LANGUAGE = code;
try {
return thunk();
}
finally {
CURRENT_LANGUAGE = oldLanguage;
}
}
export const i18nPosition = (position) => {
const msg = i18nF('<position>');
if (typeof msg === 'string')
return msg;
return msg(position.filename, position.line, position.column);
};
//# sourceMappingURL=i18n.js.map