Skip to content
Merged
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
1 change: 1 addition & 0 deletions openless-all/app/src/components/SettingsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ function LanguagePicker() {
>
<option value={FOLLOW_SYSTEM}>{t('settings.language.followSystem')}</option>
<option value="zh-CN">{t('settings.language.zh')}</option>
<option value="zh-TW">{t('settings.language.zhTW')}</option>
<option value="en">{t('settings.language.en')}</option>
</select>
);
Expand Down
1 change: 1 addition & 0 deletions openless-all/app/src/i18n/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ export const en: typeof zhCN = {
labelDesc: 'Choose "Follow system" to match the OS language at launch.',
followSystem: 'Follow system',
zh: '简体中文',
zhTW: '繁體中文',
en: 'English',
restartHint: 'Some native menus (system tray, etc.) may require an app restart to fully switch.',
},
Expand Down
11 changes: 8 additions & 3 deletions openless-all/app/src/i18n/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import i18n from 'i18next';
import { initReactI18next } from 'react-i18next';
import { en } from './en';
import { zhCN } from './zh-CN';
import { zhTW } from './zh-TW';

export const SUPPORTED_LOCALES = ['zh-CN', 'en'] as const;
export const SUPPORTED_LOCALES = ['zh-CN', 'zh-TW', 'en'] as const;
export type SupportedLocale = (typeof SUPPORTED_LOCALES)[number];

export const LOCALE_STORAGE_KEY = 'ol.locale';
Expand All @@ -22,21 +23,25 @@ const FOLLOW_SYSTEM_VALUE = 'system';
function detectSystemLocale(): SupportedLocale {
if (typeof navigator === 'undefined') return 'zh-CN';
const nav = (navigator.language || '').toLowerCase();
if (nav.startsWith('zh')) return 'zh-CN';
if (nav.startsWith('zh')) {
if (nav.includes('hant') || nav.includes('tw') || nav.includes('hk') || nav.includes('mo')) return 'zh-TW';
return 'zh-CN';
}
return 'en';
}

function getStoredLocale(): SupportedLocale | null {
if (typeof window === 'undefined') return null;
const raw = window.localStorage.getItem(LOCALE_STORAGE_KEY);
return raw === 'zh-CN' || raw === 'en' ? raw : null;
return raw === 'zh-CN' || raw === 'zh-TW' || raw === 'en' ? raw : null;
}

const initialLng: SupportedLocale = getStoredLocale() ?? detectSystemLocale();

void i18n.use(initReactI18next).init({
resources: {
'zh-CN': { translation: zhCN },
'zh-TW': { translation: zhTW },
en: { translation: en },
},
lng: initialLng,
Expand Down
1 change: 1 addition & 0 deletions openless-all/app/src/i18n/zh-CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ export const zhCN = {
labelDesc: '选择「跟随系统」时按操作系统当前语言显示。',
followSystem: '跟随系统',
zh: '简体中文',
zhTW: '繁體中文',
en: 'English',
restartHint: '部分原生菜单(系统托盘等)可能需要重启 App 才会切换。',
},
Expand Down
Loading
Loading