Added error handling if an unknown language code is entered. (#6102)

This commit is contained in:
SamTV12345 2024-01-13 16:23:21 +01:00 committed by GitHub
parent 7eab2fdaa2
commit 6a2ffe6aaf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -74,6 +74,24 @@ const getAllLocales = () => {
if (typeof overrides !== 'object') throw wrongFormatErr; if (typeof overrides !== 'object') throw wrongFormatErr;
_.each(overrides, (localeString, key) => { _.each(overrides, (localeString, key) => {
if (typeof localeString !== 'string') throw wrongFormatErr; if (typeof localeString !== 'string') throw wrongFormatErr;
const locale = locales[langcode];
// Handles the error if an unknown language code is entered
if (locale === undefined) {
const possibleMatches = [];
let strippedLangcode = '';
if (langcode.includes('-')) {
strippedLangcode = langcode.split('-')[0];
}
for (const localeInEtherPad of Object.keys(locales)) {
if (localeInEtherPad.includes(strippedLangcode)) {
possibleMatches.push(localeInEtherPad);
}
}
throw new Error(`Language code ${langcode} is unknown. ` +
`Maybe you meant: ${possibleMatches}`);
}
locales[langcode][key] = localeString; locales[langcode][key] = localeString;
}); });
}); });