mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-01-19 14:13:34 +01:00
Added error handling if an unknown language code is entered. (#6102)
This commit is contained in:
parent
7eab2fdaa2
commit
6a2ffe6aaf
1 changed files with 18 additions and 0 deletions
|
@ -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;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue