Fix missing localization for unknown locale
This commit is contained in:
parent
4bb719359c
commit
2e278e7323
|
@ -1,5 +1,5 @@
|
||||||
import { registerDebugFunction } from './power-user.js';
|
import { registerDebugFunction } from './power-user.js';
|
||||||
import { updateSecretDisplay } from './secrets.js'
|
import { updateSecretDisplay } from './secrets.js';
|
||||||
|
|
||||||
const storageKey = 'language';
|
const storageKey = 'language';
|
||||||
const overrideLanguage = localStorage.getItem(storageKey);
|
const overrideLanguage = localStorage.getItem(storageKey);
|
||||||
|
@ -14,9 +14,9 @@ const localeData = await getLocaleData(localeFile);
|
||||||
*/
|
*/
|
||||||
async function getLocaleData(language) {
|
async function getLocaleData(language) {
|
||||||
let supportedLang = findLang(language);
|
let supportedLang = findLang(language);
|
||||||
if (!supportedLang) {
|
if (!supportedLang) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = await fetch(`./locales/${language}.json`).then(response => {
|
const data = await fetch(`./locales/${language}.json`).then(response => {
|
||||||
console.log(`Loading locale data from ./locales/${language}.json`);
|
console.log(`Loading locale data from ./locales/${language}.json`);
|
||||||
|
@ -30,19 +30,20 @@ async function getLocaleData(language) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function findLang(language) {
|
function findLang(language) {
|
||||||
var supportedLang = langs.find(x => x.lang === language);
|
var supportedLang = langs.find(x => x.lang === language);
|
||||||
|
|
||||||
if (!supportedLang) {
|
if (!supportedLang) {
|
||||||
console.warn(`Unsupported language: ${language}`);
|
console.warn(`Unsupported language: ${language}`);
|
||||||
}
|
}
|
||||||
return supportedLang;
|
return supportedLang;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getMissingTranslations() {
|
async function getMissingTranslations() {
|
||||||
const missingData = [];
|
const missingData = [];
|
||||||
|
|
||||||
// Determine locales to search for untranslated strings
|
// Determine locales to search for untranslated strings
|
||||||
const langsToProcess = localeFile == 'en' ? langs : [findLang(localeFile)];
|
const isNotSupported = !findLang(localeFile);
|
||||||
|
const langsToProcess = (isNotSupported || localeFile == 'en') ? langs : [findLang(localeFile)];
|
||||||
|
|
||||||
for (const language of langsToProcess) {
|
for (const language of langsToProcess) {
|
||||||
const localeData = await getLocaleData(language.lang);
|
const localeData = await getLocaleData(language.lang);
|
||||||
|
@ -141,7 +142,7 @@ function addLanguagesToDropdown() {
|
||||||
export function initLocales() {
|
export function initLocales() {
|
||||||
applyLocale();
|
applyLocale();
|
||||||
addLanguagesToDropdown();
|
addLanguagesToDropdown();
|
||||||
updateSecretDisplay();
|
updateSecretDisplay();
|
||||||
|
|
||||||
$('#ui_language_select').on('change', async function () {
|
$('#ui_language_select').on('change', async function () {
|
||||||
const language = String($(this).val());
|
const language = String($(this).val());
|
||||||
|
|
|
@ -66,7 +66,7 @@ export function updateSecretDisplay() {
|
||||||
for (const [secret_key, input_selector] of Object.entries(INPUT_MAP)) {
|
for (const [secret_key, input_selector] of Object.entries(INPUT_MAP)) {
|
||||||
const validSecret = !!secret_state[secret_key];
|
const validSecret = !!secret_state[secret_key];
|
||||||
|
|
||||||
const placeholder = $('#viewSecrets').attr(validSecret ? 'key_saved_text' : 'missing_key_text');
|
const placeholder = $('#viewSecrets').attr(validSecret ? 'key_saved_text' : 'missing_key_text');
|
||||||
$(input_selector).attr('placeholder', placeholder);
|
$(input_selector).attr('placeholder', placeholder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue