fix(webui): follow browser language on first visit (#6591)

Co-authored-by: ovo-agentx <351813579+ovo-agentx@users.noreply.github.com>
This commit is contained in:
chengyongruandovo-agentx authored and GitHub committed 2026-11-07 00:46:09 +08:00
1 parent 0ee302253f
commit 12c7d116a0
6 files changed
+108 -8

No files matched your search

+19 -2
View File
@@ -2,7 +2,7 @@ import { useState } from "react";
import { useTranslation } from "react-i18next";
import { currentLocale, setAppLanguage } from "@/i18n";
import { supportedLocales, type SupportedLocale } from "@/i18n/config";
import { persistLocale, supportedLocales, type SupportedLocale } from "@/i18n/config";
import { cn } from "@/lib/utils";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
@@ -27,7 +27,24 @@ export function LanguageSwitcher({ className }: { className?: string }) {
onEscapeKeyDown={() => setPointerFocus(false)}
>
{supportedLocales.map((option) => (
<SelectItem key={option.code} value={option.code}>{option.nativeLabel}</SelectItem>
<SelectItem
key={option.code}
value={option.code}
onPointerUp={(event) => {
if (event.pointerType === "mouse" && option.code === currentLocale()) persistLocale(option.code);
}}
onClick={() => {
if (option.code === currentLocale()) persistLocale(option.code);
}}
onKeyDown={(event) => {
if (option.code !== currentLocale()) return;
if (event.key === "Enter") persistLocale(option.code);
if (event.key === " ") {
// Radix prevents the space key only when it selects, not during typeahead.
queueMicrotask(() => { if (event.defaultPrevented) persistLocale(option.code); });
}
}}
>{option.nativeLabel}</SelectItem>
))}
</SelectContent>
</Select>