Normalize language format

This commit is contained in:
Óscar Carretero 2021-02-26 13:25:34 +01:00 committed by Дамян Минков
parent f718a3e050
commit 62c06441b1
1 changed files with 21 additions and 2 deletions

View File

@ -36,8 +36,7 @@ export default {
} }
} }
// Fix language format (en-US => enUS) found = found.map<string>(normalizeLanguage);
found = found.map<string>(f => f.replace(/[-_]+/g, ''));
return found.length > 0 ? found : undefined; return found.length > 0 ? found : undefined;
}, },
@ -47,3 +46,23 @@ export default {
*/ */
name: 'customNavigatorDetector' name: 'customNavigatorDetector'
}; };
/**
* Normalize language format.
*
* (en-US => enUS)
* (en-gb => enGB)
* (es-es => es).
*
* @param {string} language - Language.
* @returns {string} The normalized language.
*/
function normalizeLanguage(language) {
const [ lang, variant ] = language.replace('_', '-').split('-');
if (!variant || lang === variant) {
return lang;
}
return lang + variant.toUpperCase();
}