当设备未连接时,各页面默认显示英文语言的文本,并在标题追加 (Disconnect)

This commit is contained in:
eafonyang
2026-07-01 11:23:06 +08:00
parent 8283ffcf14
commit ac7b5da0f0
20 changed files with 113 additions and 440 deletions
+8 -12
View File
@@ -20,9 +20,9 @@ import {
parseFirmwareVersion,
supportsAmbientLed,
} from "@/lib/luxsinApi";
import localeZh from "@/locales/data-zh.json";
import localeZhHK from "@/locales/data-zh-HK.json";
import localeEn from "@/locales/data-en.json";
import { DEFAULT_DEVICE_LANGUAGE, resolveDeviceLanguage, resolveLocalePack } from "@/locales/resolveLocale";
import { usePageTitleWithConnection } from "@/hooks/usePageTitleWithConnection";
function IOSToggle({ checked, onChange }: { checked: boolean; onChange: (v: boolean) => void }) {
return (
@@ -160,12 +160,6 @@ type LocaleSettings = {
};
};
const LOCALE_BY_LANG: Record<number, LocaleSettings> = {
0: localeEn as LocaleSettings,
1: localeZhHK as LocaleSettings,
2: localeZh as LocaleSettings,
};
function optionLabels(items: Array<{ index: number; label: string }> | undefined, fallback: string[]) {
if (!items || items.length === 0) return fallback;
const sorted = [...items].sort((a, b) => a.index - b.index);
@@ -201,8 +195,8 @@ export default function SystemPage() {
const screenOffIdx = ds?.screenOff ?? 2;
const sleepIdx = ds?.sleep ?? 0;
const autoHomeIdx = ds?.autoHome ?? 1;
const rawLangIdx = ds?.language ?? 2;
const langIdx = SUPPORTED_LANGUAGE_INDICES.has(rawLangIdx) ? rawLangIdx : 2;
const rawLangIdx = resolveDeviceLanguage(ds?.language);
const langIdx = SUPPORTED_LANGUAGE_INDICES.has(rawLangIdx) ? rawLangIdx : DEFAULT_DEVICE_LANGUAGE;
const knobBreathLightOn = (ds?.knob_breathlight ?? 1) === 0;
const firmwareVersion = parseFirmwareVersion(ds?.version);
const showAmbientLed = supportsAmbientLed(firmwareVersion);
@@ -227,7 +221,7 @@ export default function SystemPage() {
if (!draggingLedBlue.current) setLocalLedBlue(clampLedChannel(ds?.led_blue));
}, [ds?.led_blue]);
const localeData = LOCALE_BY_LANG[langIdx] ?? localeZh;
const localeData = resolveLocalePack(ds?.language) as LocaleSettings;
const settingsText = localeData.settings;
const ui = settingsText.systemPage;
const SCREEN_LIGHT_OPTIONS = optionLabels(settingsText.screenBrightness?.options, ["亮", "中等", "暗"]);
@@ -247,6 +241,8 @@ export default function SystemPage() {
(localeEn as LocaleSettings).settings.sleep?.label ??
"Sleep";
const pageTitle = usePageTitleWithConnection(settingsText.vu);
const goSelect = (title: string, options: string[], selected: number, key: string) => {
navigateToSelect(title, options, selected, "/system", key);
setLocation("/select");
@@ -258,7 +254,7 @@ export default function SystemPage() {
<button onClick={() => setLocation("/")} className="mr-4 text-white/60 active:text-white transition-colors">
<ChevronLeft size={24} />
</button>
<h1 className="flex-1 text-center text-[17px] font-semibold text-white">{settingsText.vu}</h1>
<h1 className="flex-1 text-center text-[17px] font-semibold text-white">{pageTitle}</h1>
<div className="w-8" />
</div>