1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-27 12:36:14 +01:00

Correctly handle dash in locale, and add a fallback to en. (#988)

This commit is contained in:
Oscar Hinton 2021-05-21 13:07:33 +02:00 committed by GitHub
parent e34e4728d0
commit 1098adc03d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -11,11 +11,14 @@ let sentSuccess = false;
let locales: any = {};
document.addEventListener('DOMContentLoaded', async () => {
const locale = getQsParam('locale');
const filePath = `locales/${locale}/messages.json?cache=${process.env.CACHE_TAG}`;
const localesResult = await fetch(filePath);
locales = await localesResult.json();
const locale = getQsParam('locale').replace('-', '_');
try {
locales = await loadLocales(locale);
} catch {
console.error('Failed to load the locale', locale);
locales = await loadLocales('en')
}
document.getElementById('msg').innerText = translate('webAuthnFallbackMsg');
document.getElementById('remember-label').innerText = translate('rememberMe');
@ -30,6 +33,12 @@ document.addEventListener('DOMContentLoaded', async () => {
content.classList.remove('d-none');
});
async function loadLocales(locale: string) {
const filePath = `locales/${locale}/messages.json?cache=${process.env.CACHE_TAG}`;
const localesResult = await fetch(filePath);
return await localesResult.json();
}
function translate(id: string) {
return locales[id]?.message || '';
}