Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions ui/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { findSectionForActivity } from './sections'
import { UrlAdopter } from './tabs/UrlAdopter'
import { useWorkspace } from './tabs/store'
import { getFocusedTab } from './tabs/types'
import { resolveAppLocale } from './i18n/locale'

/**
* Activity-bar pages — only items that appear as icons in the ActivityBar.
Expand Down Expand Up @@ -51,6 +52,12 @@ function AppShell() {
const section = findSectionForActivity(selectedSidebar)
const isDesktop = useIsDesktop()
const showSidebarPanel = isDesktop && section != null
const appLocale = useMemo(() => resolveAppLocale(), [])

useEffect(() => {
if (typeof document === 'undefined') return
document.documentElement.setAttribute('lang', appLocale === 'zh' ? 'zh-CN' : 'en-US')
}, [appLocale])

// Auto-close the mobile secondary drawer once the user picks a sub-item.
// We snapshot the focused tab at drawer-open time (see openSecondaryDrawer
Expand Down
25 changes: 25 additions & 0 deletions ui/src/i18n/locale.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
export type AppLocale = 'en' | 'zh'

export const APP_LOCALE_KEY = 'openalice-settings-locale'

export function resolveAppLocale(): AppLocale {
if (typeof window === 'undefined') return 'en'

try {
const raw = localStorage.getItem(APP_LOCALE_KEY)
if (raw === 'zh' || raw === 'en') return raw
} catch {
// ignore storage access errors
}

const browser = (window.navigator?.language || '').toLowerCase()
return browser.startsWith('zh') ? 'zh' : 'en'
}

export function saveAppLocale(locale: AppLocale) {
try {
localStorage.setItem(APP_LOCALE_KEY, locale)
} catch {
// ignore storage write errors
}
}