mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-30 13:03:53 +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 = {};
|
||||
|
||||
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 || '';
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user