-
Notifications
You must be signed in to change notification settings - Fork 234
feat(desktop): surface language toggle #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ import { autoUpdater } from 'electron-updater'; | |
| import { scanDesignSystem } from './design-system'; | ||
| import { BrowserWindow, app, dialog, ipcMain, shell } from './electron-runtime'; | ||
| import { registerExporterIpc } from './exporter-ipc'; | ||
| import { registerLocaleIpc } from './locale-ipc'; | ||
| import { getLogPath, getLogger, initLogger } from './logger'; | ||
| import { | ||
| getApiKeyForProvider, | ||
|
|
@@ -32,6 +33,7 @@ function createWindow(): void { | |
| height: 820, | ||
| minWidth: 960, | ||
| minHeight: 640, | ||
| autoHideMenuBar: process.platform !== 'darwin', | ||
| titleBarStyle: process.platform === 'darwin' ? 'hiddenInset' : 'default', | ||
| backgroundColor: BRAND.backgroundColor, | ||
| show: false, | ||
|
|
@@ -254,6 +256,7 @@ void app.whenReady().then(async () => { | |
| initLogger(); | ||
| await loadConfigOnBoot(); | ||
| registerIpcHandlers(); | ||
| registerLocaleIpc(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Activating Suggested fix: import { join } from 'node:path';
import { app } from './electron-runtime';
const LOCALE_FILE = join(app.getPath('userData'), 'locale.json');
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Activating Suggested fix: import { join } from 'node:path';
import { app } from './electron-runtime';
const LOCALE_FILE = join(app.getPath('userData'), 'locale.json'); |
||
| registerOnboardingIpc(); | ||
| registerExporterIpc(() => mainWindow); | ||
| setupAutoUpdater(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,6 +52,11 @@ const api = { | |
| ipcRenderer.invoke('codesign:clear-design-system') as Promise<OnboardingState>, | ||
| export: (payload: { format: ExportFormat; htmlContent: string; defaultFilename?: string }) => | ||
| ipcRenderer.invoke('codesign:export', payload) as Promise<ExportInvokeResponse>, | ||
| locale: { | ||
| getSystem: () => ipcRenderer.invoke('locale:get-system') as Promise<string>, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These new locale IPC channels are unversioned ( Suggested fix: const LOCALE_GET_SYSTEM = 'locale:v1:get-system';
const LOCALE_GET_CURRENT = 'locale:v1:get-current';
const LOCALE_SET = 'locale:v1:set';
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These new locale IPC channels are unversioned. Suggested fix: const LOCALE_GET_SYSTEM = 'locale:v1:get-system';
const LOCALE_GET_CURRENT = 'locale:v1:get-current';
const LOCALE_SET = 'locale:v1:set';
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These locale IPC channels are still unversioned. Suggested fix: const LOCALE_GET_SYSTEM = 'locale:v1:get-system';
const LOCALE_GET_CURRENT = 'locale:v1:get-current';
const LOCALE_SET = 'locale:v1:set'; |
||
| getCurrent: () => ipcRenderer.invoke('locale:get-current') as Promise<string>, | ||
| set: (locale: string) => ipcRenderer.invoke('locale:set', locale) as Promise<string>, | ||
| }, | ||
| checkForUpdates: () => ipcRenderer.invoke('codesign:check-for-updates'), | ||
| downloadUpdate: () => ipcRenderer.invoke('codesign:download-update'), | ||
| installUpdate: () => ipcRenderer.invoke('codesign:install-update'), | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import { setLocale as applyLocale, getCurrentLocale, useT } from '@open-codesign/i18n'; | ||
| import type { Locale } from '@open-codesign/i18n'; | ||
| import { Globe } from 'lucide-react'; | ||
| import { useEffect, useState } from 'react'; | ||
|
|
||
| function nextLocale(locale: Locale): Locale { | ||
| return locale === 'en' ? 'zh-CN' : 'en'; | ||
| } | ||
|
|
||
| function localeLabel(locale: Locale): string { | ||
| return locale === 'zh-CN' ? 'ZH' : 'EN'; | ||
| } | ||
|
|
||
| export function LanguageToggle() { | ||
| const t = useT(); | ||
| const [locale, setLocaleState] = useState<Locale>(getCurrentLocale()); | ||
|
|
||
| useEffect(() => { | ||
| setLocaleState(getCurrentLocale()); | ||
| }, []); | ||
|
|
||
| async function handleToggle(): Promise<void> { | ||
| const target = nextLocale(locale); | ||
| const persisted = window.codesign ? await window.codesign.locale.set(target) : target; | ||
| const applied = await applyLocale(persisted); | ||
| setLocaleState(applied); | ||
| } | ||
|
|
||
| return ( | ||
| <button | ||
| type="button" | ||
| onClick={() => void handleToggle()} | ||
| className="inline-flex items-center gap-2 h-8 px-3 rounded-[var(--radius-md)] border border-[var(--color-border)] bg-[var(--color-surface)] text-[12px] text-[var(--color-text-primary)] hover:bg-[var(--color-surface-hover)] transition-colors" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested fix: className="... text-[var(--text-xs)] ..." |
||
| aria-label={t('settings.language.label')} | ||
| title={t('settings.language.label')} | ||
| > | ||
| <Globe className="w-3.5 h-3.5 text-[var(--color-text-secondary)]" /> | ||
| <span>{localeLabel(locale)}</span> | ||
| </button> | ||
| ); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Activating
registerLocaleIpc()makes locale persistence live, but that implementation currently writes to a hardcoded~/.config/open-codesign/locale.jsonpath (apps/desktop/src/main/locale-ipc.ts:19). The repo explicitly says not to hard-code paths and to respect XDG / Electron path helpers. Can this be moved underapp.getPath("userData")or the same config-dir helper used elsewhere?Suggested fix: