Do not restrict language codes to two characters
In fact, they may be of 2-8 characters in length according to [BCP 47] 2.2.1. I do not really see any reason to validate them anyway, and this way we could also support e.g. `en-US` vs `en-GB`. [BCP 47]: https://tools.ietf.org/rfc/bcp/bcp47.txt
This commit is contained in:
parent
0ca2a45358
commit
d6d55c9f9c
|
@ -31,12 +31,7 @@ var _data = {};
|
||||||
* @author svartoyg
|
* @author svartoyg
|
||||||
*/
|
*/
|
||||||
async function retrieveData (language) {
|
async function retrieveData (language) {
|
||||||
const regexp = (new RegExp("^([a-z]{2})$"));
|
return (await import(`../loc/${language}.json`)).default
|
||||||
if (regexp.exec(language) === null) {
|
|
||||||
return Promise.reject(new Error('invalid language code "' + language + '"'));
|
|
||||||
} else {
|
|
||||||
return (await import(`../loc/${language}.json`)).default
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue