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:
parent
e34e4728d0
commit
1098adc03d
@ -11,11 +11,14 @@ let sentSuccess = false;
|
|||||||
let locales: any = {};
|
let locales: any = {};
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', async () => {
|
document.addEventListener('DOMContentLoaded', async () => {
|
||||||
const locale = getQsParam('locale');
|
|
||||||
|
|
||||||
const filePath = `locales/${locale}/messages.json?cache=${process.env.CACHE_TAG}`;
|
const locale = getQsParam('locale').replace('-', '_');
|
||||||
const localesResult = await fetch(filePath);
|
try {
|
||||||
locales = await localesResult.json();
|
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('msg').innerText = translate('webAuthnFallbackMsg');
|
||||||
document.getElementById('remember-label').innerText = translate('rememberMe');
|
document.getElementById('remember-label').innerText = translate('rememberMe');
|
||||||
@ -30,6 +33,12 @@ document.addEventListener('DOMContentLoaded', async () => {
|
|||||||
content.classList.remove('d-none');
|
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) {
|
function translate(id: string) {
|
||||||
return locales[id]?.message || '';
|
return locales[id]?.message || '';
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user