diff --git a/scripts/i18n.js b/scripts/i18n.js index 69ae502a7..4ffd613a9 100644 --- a/scripts/i18n.js +++ b/scripts/i18n.js @@ -24,7 +24,7 @@ const defaultLang = 'en'; * @example getParentLanguage('es') === defaultLang // true * @returns the 'parent' language of a langcode */ -function getParentLanguage(langName) { +export function getParentLanguage(langName) { const strParentCode = langName.includes('-') ? langName.split('-')[0] : defaultLang; @@ -71,7 +71,7 @@ async function setTranslationKey(key, langName) { async function setAlertKey(langName) { const lang = await getLanguage(langName); translation['ALERTS'] = lang['ALERTS']; - for (const subKey in lang['ALERTS']) { + for (const subKey in template['ALERTS']) { setAlertSubKey(subKey, langName); } } diff --git a/tests/unit/i18n.spec.js b/tests/unit/i18n.spec.js new file mode 100644 index 000000000..568c7ac64 --- /dev/null +++ b/tests/unit/i18n.spec.js @@ -0,0 +1,12 @@ +import { describe, it, expect } from 'vitest'; +import { getParentLanguage } from '../../scripts/i18n'; + +describe('i18n tests', () => { + it('returns correct parent language', () => { + expect(getParentLanguage('es-ES')).toBe('es'); + expect(getParentLanguage('es')).toBe('en'); + expect(getParentLanguage('en-US')).toBe('en'); + expect(getParentLanguage('it')).toBe('en'); + expect(getParentLanguage('en')).toBe('en'); + }); +});