fix(webui): align language flag in toolbar and auto-detect browser language

This commit is contained in:
hanlap0503 committed 2026-10-15 10:06:22 +00:00
1 parent 1e81532be8
commit 6150f7da28
3 files changed
+33 -3

No files matched your search

+12 -1
View File
@@ -1128,6 +1128,16 @@ window.O2I18N = (() => {
return "";
}
};
const browserLocale = () => {
const candidates = [...(navigator.languages || []), navigator.language].filter(Boolean);
for (const candidate of candidates) {
const normalized = String(candidate).toLowerCase();
if (normalized.startsWith('zh')) return 'zh-CN';
if (normalized.startsWith('vi')) return 'vi';
if (normalized.startsWith('en')) return 'en';
}
return '';
};
const init = () => {
document.documentElement.lang = locale;
@@ -1143,7 +1153,8 @@ window.O2I18N = (() => {
);
node.onchange = (event) => setLocale(event.target.value);
});
if (SUPPORTED.includes(stored())) setLocale(stored(), false);
const initial = SUPPORTED.includes(stored()) ? stored() : browserLocale();
if (initial) setLocale(initial, false);
else apply();
syncSelectors();
};
+1 -1
View File
@@ -105,7 +105,7 @@
<div class="toolbar">
<button id="refresh-now" class="ghost" data-i18n="topbar.refresh">立即刷新</button
><button id="logout" class="ghost" data-i18n="topbar.logout">退出</button
><select class="lang-switch" data-lang-switch></select>
><div class="app-lang"><select class="lang-switch" data-lang-switch></select></div>
</div>
</header>
<div id="restart-notice" class="notice hidden"></div>
+20 -1
View File
@@ -318,9 +318,12 @@ pre,
display: inline-flex;
align-items: center;
justify-content: center;
width: auto;
width: 34px;
min-width: 34px;
max-width: 34px;
flex: 0 0 34px;
height: 38px;
overflow: hidden;
padding: 0 4px;
border: 0;
background: transparent;
@@ -948,3 +951,19 @@ textarea {
max-width: 270px;
overflow-wrap: anywhere;
}
.toolbar {
padding-right: 40px;
position: relative;
}
.app-lang {
position: absolute;
right: 0;
top: 50%;
transform: translateY(-50%);
z-index: 20;
}
.login-lang { display: none !important; }