import React, { useSyncExternalStore } from 'react'; import { IcCheck } from '../res/icons'; import { SettingsHeader } from './SettingsHeader'; import { PreferenceCategory } from './PreferenceCategory'; import { PreferenceItem } from './PreferenceItem'; import { getLocale, setLocale, subscribeLocale } from '../../../os/locale'; import { strings } from '../res/strings'; import { stringsEn } from '../res/strings.en'; import { useAppStrings } from '@/os/useAppStrings'; const DEFAULT_LANGUAGE = 'zh-Hans'; export const LanguagePickerPage: React.FC = () => { const s = useAppStrings(strings, stringsEn); const LANGUAGE_OPTIONS = [ { value: 'zh-Hans', title: s.chinese_simplified }, { value: 'zh-Hant', title: s.chinese_traditional }, { value: 'en', title: 'English' }, ]; const currentLanguage = useSyncExternalStore( subscribeLocale, () => getLocale() || DEFAULT_LANGUAGE, ); const setLanguage = (value: string) => { setLocale(value as 'zh-Hans' | 'en'); }; return (
{LANGUAGE_OPTIONS.map((opt, idx) => { const selected = opt.value === currentLanguage; return ( setLanguage(opt.value)} > {selected ? : null} ); })}
); }; export default LanguagePickerPage;