UNPKG

eleventy-i18n

Version:

i18n for Eleventy with dynamic parameters and pluralization support

30 lines (23 loc) 717 B
let registry = {}; function getSupportedLanguageTags() { return Object.keys(registry); } function addTranslations(locale, translations) { registry[locale] ??= {}; const collidingKeys = commonKeys(registry[locale], translations); if (collidingKeys.length > 0) { throw new Error(`colliding keys: ${collidingKeys.join(', ')}`); } registry[locale] = { ...registry[locale], ...translations }; } function commonKeys(a, b) { return Object.keys(a).filter(function (key) { return b.hasOwnProperty(key); }); }; module.exports = registry; module.exports.getSupportedLanguageTags = getSupportedLanguageTags; module.exports.addTranslations = addTranslations;