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
9 changes: 7 additions & 2 deletions apps/desktop/src/renderer/src/components/LanguageToggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@ import { useEffect, useState } from 'react';

const noDragStyle = { WebkitAppRegion: 'no-drag' } as CSSProperties;

const LOCALE_CYCLE: Locale[] = ['en', 'zh-CN', 'pt-BR'];

function nextLocale(locale: Locale): Locale {
return locale === 'en' ? 'zh-CN' : 'en';
const i = LOCALE_CYCLE.indexOf(locale);
return LOCALE_CYCLE[(i + 1) % LOCALE_CYCLE.length] ?? 'en';
}

function localeLabel(locale: Locale): string {
return locale === 'zh-CN' ? 'ZH' : 'EN';
if (locale === 'zh-CN') return 'ZH';
if (locale === 'pt-BR') return 'PT';
return 'EN';
}

export function LanguageToggle() {
Expand Down
1 change: 1 addition & 0 deletions apps/desktop/src/renderer/src/components/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1719,6 +1719,7 @@ function AppearanceTab() {
options={[
{ value: 'en', label: t('settings.appearance.langEn') },
{ value: 'zh-CN', label: t('settings.appearance.langZhCN') },
{ value: 'pt-BR', label: t('settings.appearance.langPtBR') },
]}
/>
</Row>
Expand Down
7 changes: 6 additions & 1 deletion packages/i18n/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,18 @@ import i18next from 'i18next';
import { useCallback } from 'react';
import { initReactI18next, useTranslation } from 'react-i18next';
import en from './locales/en.json';
import ptBR from './locales/pt-BR.json';
import zhCN from './locales/zh-CN.json';

export const availableLocales = ['en', 'zh-CN'] as const;
export const availableLocales = ['en', 'zh-CN', 'pt-BR'] as const;
export type Locale = (typeof availableLocales)[number];

const DEFAULT_LOCALE: Locale = 'en';

const resources = {
en: { translation: en },
'zh-CN': { translation: zhCN },
'pt-BR': { translation: ptBR },
} as const;

export function isSupportedLocale(value: string | undefined | null): value is Locale {
Expand All @@ -40,6 +42,9 @@ export function normalizeLocale(value: string | undefined | null): Locale {
if (lower === 'zh' || lower.startsWith('zh-hans') || lower === 'zh-cn' || lower === 'zh_cn') {
return 'zh-CN';
}
if (lower === 'pt-br' || lower === 'pt_br' || lower === 'pt' || lower.startsWith('pt-')) {
return 'pt-BR';
}
if (lower.startsWith('en')) return 'en';
console.warn(
`[i18n] unsupported locale "${value}", falling back to "${DEFAULT_LOCALE}". ` +
Expand Down
3 changes: 2 additions & 1 deletion packages/i18n/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,8 @@
"languageHint": "Language changes take effect immediately.",
"languageLoadFailed": "Failed to load language",
"langEn": "English",
"langZhCN": "中文 (简体)"
"langZhCN": "中文 (简体)",
"langPtBR": "Português (BR)"
},
"language": {
"label": "Language",
Expand Down
Loading
Loading