mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
Adding new flags for supported locales (#420)
* Adding new flags for supported locales * Removing pl-PL locale code from tests * Linting
This commit is contained in:
@@ -40,7 +40,13 @@ export async function setupLocale() {
|
||||
const resourceUrl = loadPath.replace('{{lng}}', lang.replace("-", "_")).replace('{{ns}}', n);
|
||||
const response = await fetch(resourceUrl);
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to load ${resourceUrl}`);
|
||||
// Throw only if we don't have any fallbacks.
|
||||
if (lang === i18next.options.fallbackLng && n === i18next.options.defaultNS) {
|
||||
throw new Error(`Failed to load ${resourceUrl}`);
|
||||
} else {
|
||||
console.warn(`Failed to load ${resourceUrl}`);
|
||||
return;
|
||||
}
|
||||
}
|
||||
i18next.addResourceBundle(lang, n, await response.json());
|
||||
}
|
||||
|
||||
@@ -75,7 +75,12 @@ export function getCountryCode(locale: string) {
|
||||
if (locale === 'en') { return 'US'; }
|
||||
let countryCode = locale.split(/[-_]/)[1];
|
||||
if (countryCode) { return countryCode.toUpperCase(); }
|
||||
countryCode = locale.toUpperCase();
|
||||
|
||||
// Some defaults that we support and can't be read from language code.
|
||||
countryCode = {
|
||||
'uk': 'UA', // Ukraine
|
||||
}[locale] ?? locale.toUpperCase();
|
||||
|
||||
// Test if we can use language as a country code.
|
||||
if (localeCodes.map(code => code.split(/[-_]/)[1]).includes(countryCode)) {
|
||||
return countryCode;
|
||||
|
||||
Reference in New Issue
Block a user