Skip to content

Commit

Permalink
Fix undefined alerts when locale is missing (#368)
Browse files Browse the repository at this point in the history
  • Loading branch information
Duddino committed May 15, 2024
1 parent a13822b commit e54fbb5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions scripts/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
Expand Down
12 changes: 12 additions & 0 deletions tests/unit/i18n.spec.js
Original file line number Diff line number Diff line change
@@ -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');
});
});

0 comments on commit e54fbb5

Please sign in to comment.