Skip to content

armgit / mimik

Public Imported from GitHub
0

🎬 A browser extension and desktop app that turns your clicks into step-by-step guides with annotated screenshots 📖

feat(desktop): translate the tray, its menu and the dialogs

Luis Ortizfac46b62e80a
diff --git a/apps/desktop/electron.vite.config.ts b/apps/desktop/electron.vite.config.ts
index 0c91574..9dc0910 100644
--- a/apps/desktop/electron.vite.config.ts
+++ b/apps/desktop/electron.vite.config.ts
@@ -21,7 +21,8 @@ function yaml(): PluginOption {
export default defineConfig({
main: {
- plugins: [externalizeDepsPlugin()],
+ plugins: [externalizeDepsPlugin(), yaml()],
+ resolve: { alias: { '@mimik/locales': locales } },
build: {
outDir: resolve(__dirname, 'out/main'),
rollupOptions: {
diff --git a/apps/desktop/src/main/__tests__/i18n.test.ts b/apps/desktop/src/main/__tests__/i18n.test.ts
new file mode 100644
index 0000000..613c55d
--- /dev/null
+++ b/apps/desktop/src/main/__tests__/i18n.test.ts
@@ -0,0 +1,25 @@
+import { describe, expect, it, vi } from 'vitest';
+
+vi.mock('@mimik/locales/en.yml', () => ({
+ default: { desktop: { trayQuit: 'Quit Mimik', upToDateMessage: 'Mimik $1 is current.', later: 'Later' } },
+}));
+vi.mock('@mimik/locales/pt-BR.yml', () => ({ default: { desktop: { trayQuit: 'Sair do Mimik' } } }));
+vi.mock('@mimik/locales/de.yml', () => ({ default: {} }));
+vi.mock('@mimik/locales/es.yml', () => ({ default: {} }));
+vi.mock('@mimik/locales/fr.yml', () => ({ default: {} }));
+vi.mock('@mimik/locales/zh-CN.yml', () => ({ default: {} }));
+
+import { mainI18n } from '../i18n';
+
+describe('mainI18n', () => {
+ it('matches a regional locale to its language and falls back to English per key', () => {
+ mainI18n.setLocale('pt-PT');
+ expect(mainI18n.t('desktop.trayQuit')).toBe('Sair do Mimik');
+ expect(mainI18n.t('desktop.later')).toBe('Later');
+ expect(mainI18n.t('desktop.upToDateMessage', ['1.2.0'])).toBe('Mimik 1.2.0 is current.');
+ expect(mainI18n.t('desktop.missing')).toBe('desktop.missing');
+
+ mainI18n.setLocale('ja-JP');
+ expect(mainI18n.t('desktop.trayQuit')).toBe('Quit Mimik');
+ });
+});
diff --git a/apps/desktop/src/main/i18n.ts b/apps/desktop/src/main/i18n.ts
new file mode 100644
index 0000000..3ef40f2
--- /dev/null
+++ b/apps/desktop/src/main/i18n.ts
@@ -0,0 +1,39 @@
+import de from '@mimik/locales/de.yml';
+import en from '@mimik/locales/en.yml';
+import es from '@mimik/locales/es.yml';
+import fr from '@mimik/locales/fr.yml';
+import ptBR from '@mimik/locales/pt-BR.yml';
+import zhCN from '@mimik/locales/zh-CN.yml';
+
+type Messages = { [key: string]: string | Messages };
+
+const LOCALES: Record<string, Messages> = {
+ en: en as Messages,
+ de: de as Messages,
+ es: es as Messages,
+ fr: fr as Messages,
+ 'pt-BR': ptBR as Messages,
+ 'zh-CN': zhCN as Messages,
+};
+const active = { locale: 'en' };
+
+function lookup(messages: Messages, key: string): string | undefined {
+ const found = key
+ .split('.')
+ .reduce<string | Messages | undefined>(
+ (node, part) => (typeof node === 'object' ? node[part] : undefined),
+ messages,
+ );
+ return typeof found === 'string' ? found : undefined;
+}
+
+export const mainI18n = {
+ setLocale(code: string): void {
+ const language = code.split('-')[0];
+ active.locale = LOCALES[code] ? code : (Object.keys(LOCALES).find((l) => l.split('-')[0] === language) ?? 'en');
+ },
+ t(key: string, substitutions: string[] = []): string {
+ const text = lookup(LOCALES[active.locale], key) ?? lookup(LOCALES.en, key) ?? key;
+ return substitutions.reduce((out, value, i) => out.replaceAll(`$${i + 1}`, value), text);
+ },
+};
diff --git a/apps/desktop/src/main/index.ts b/apps/desktop/src/main/index.ts
index b0c0bf8..2e11ca6 100644
--- a/apps/desktop/src/main/index.ts
+++ b/apps/desktop/src/main/index.ts
@@ -7,6 +7,7 @@ import type { CaptureInsert } from './capture/insert';
import { DesktopRecorder, frameFor } from './capture/recorder';
import { registerScreenshotProtocol, SCREENSHOT_SCHEME, sweepScreenshots } from './capture/screenshot-store';
import { type CaptureMode, type CaptureSettings, loadSettings, saveSettings } from './capture/settings';
+import { mainI18n } from './i18n';
import { CaptureOverlay, type OverlayAiFailure, type OverlayCommand, type OverlayStep } from './overlay';
import { bindShortcuts, type ShortcutName, shortcutMap, unbindShortcuts } from './shortcuts';
import { checkForUpdates } from './updater';
@@ -62,7 +63,7 @@ function refreshTray(): void {
if (!tray) return;
const recording = isCapturing();
tray.setImage(trayIcon(recording));
- tray.setToolTip(recording ? 'Mimik is recording. Click to finish.' : 'Mimik');
+ tray.setToolTip(recording ? mainI18n.t('desktop.trayRecording') : 'Mimik');
}
function showWindow(): void {
@@ -174,9 +175,9 @@ function refreshTrayMenu(): void {
if (!tray) return;
tray.setContextMenu(
Menu.buildFromTemplate([
- { label: 'Open Mimik', click: () => showWindow() },
+ { label: mainI18n.t('onboarding.openMimik'), click: () => showWindow() },
{
- label: 'Set capture area',
+ label: mainI18n.t('desktop.traySetArea'),
click: () => {
if (!isCapturing()) {
insert = null;
@@ -187,14 +188,14 @@ function refreshTrayMenu(): void {
},
{ type: 'separator' },
{
- label: 'Start at login',
+ label: mainI18n.t('desktop.startAtLogin'),
type: 'checkbox',
checked: opensAtLogin(),
click: (item) => setOpenAtLogin(item.checked),
},
- { label: 'Check for updates', click: () => checkForUpdates({ notifyWhenUpToDate: true }) },
+ { label: mainI18n.t('desktop.checkUpdates'), click: () => checkForUpdates({ notifyWhenUpToDate: true }) },
{ type: 'separator' },
- { label: 'Quit Mimik', click: () => quit() },
+ { label: mainI18n.t('desktop.trayQuit'), click: () => quit() },
]),
);
}
@@ -263,14 +264,14 @@ async function onOverlayCommand(command: OverlayCommand): Promise<void> {
guideId = await ask<string>(mainWindow?.webContents ?? null, 'mimik:capture:startGuide', insert !== null);
} catch (error) {
overlay?.hide();
- dialog.showErrorBox('Mimik cannot record', error instanceof Error ? error.message : String(error));
+ dialog.showErrorBox(mainI18n.t('desktop.cannotRecord'), error instanceof Error ? error.message : String(error));
return;
}
const started = await recorder?.start();
if (started && !started.ok) {
guideId = null;
overlay?.hide();
- dialog.showErrorBox('Mimik cannot record', started.detail);
+ dialog.showErrorBox(mainI18n.t('desktop.cannotRecord'), started.detail);
return;
}
} else if (command === 'pause') {
@@ -323,6 +324,7 @@ if (!app.requestSingleInstanceLock()) {
app.on('second-instance', () => showWindow());
app.whenReady().then(() => {
+ mainI18n.setLocale(app.getLocale());
if (!app.getLoginItemSettings().wasOpenedAsHidden) openSplash();
registerScreenshotProtocol();
registerAiFetch();
@@ -337,6 +339,11 @@ if (!app.requestSingleInstanceLock()) {
ipcMain.on('mimik:app:relocalise', () => {
for (const win of BrowserWindow.getAllWindows()) win.webContents.reload();
});
+ ipcMain.on('mimik:app:locale', (_event, code: string) => {
+ mainI18n.setLocale(code);
+ refreshTrayMenu();
+ refreshTray();
+ });
captureSettings = loadSettings();
const shortcutLabel = (accelerator: string | null) =>
diff --git a/apps/desktop/src/main/updater.ts b/apps/desktop/src/main/updater.ts
index c1b7bfc..0f7438f 100644
--- a/apps/desktop/src/main/updater.ts
+++ b/apps/desktop/src/main/updater.ts
@@ -1,5 +1,6 @@
import { app, dialog } from 'electron';
import electronUpdater from 'electron-updater';
+import { mainI18n } from './i18n';
const { autoUpdater } = electronUpdater;
@@ -14,17 +15,21 @@ export function checkForUpdates(opts: { notifyWhenUpToDate: boolean }): void {
autoUpdater.on('update-downloaded', async (info) => {
const { response } = await dialog.showMessageBox({
type: 'info',
- buttons: ['Restart now', 'Later'],
+ buttons: [mainI18n.t('desktop.restartNow'), mainI18n.t('desktop.later')],
defaultId: 0,
cancelId: 1,
- title: 'Update ready',
- message: `Mimik ${info.version} is ready to install.`,
+ title: mainI18n.t('desktop.updateReady'),
+ message: mainI18n.t('desktop.updateReadyMessage', [info.version]),
});
if (response === 0) autoUpdater.quitAndInstall();
});
autoUpdater.on('error', (err) => {
if (opts.notifyWhenUpToDate) {
- dialog.showMessageBox({ type: 'error', title: 'Update check failed', message: String(err?.message ?? err) });
+ dialog.showMessageBox({
+ type: 'error',
+ title: mainI18n.t('desktop.updateFailed'),
+ message: String(err?.message ?? err),
+ });
}
});
}
@@ -33,7 +38,11 @@ export function checkForUpdates(opts: { notifyWhenUpToDate: boolean }): void {
.checkForUpdates()
.then((result) => {
if (opts.notifyWhenUpToDate && !result?.updateInfo) {
- dialog.showMessageBox({ type: 'info', title: 'Up to date', message: `Mimik ${app.getVersion()} is current.` });
+ dialog.showMessageBox({
+ type: 'info',
+ title: mainI18n.t('desktop.upToDate'),
+ message: mainI18n.t('desktop.upToDateMessage', [app.getVersion()]),
+ });
}
})
.catch(() => {});
diff --git a/apps/desktop/src/preload/index.ts b/apps/desktop/src/preload/index.ts
index 2e68f32..d7b08bc 100644
--- a/apps/desktop/src/preload/index.ts
+++ b/apps/desktop/src/preload/index.ts
@@ -44,6 +44,7 @@ const api = {
});
},
relocalise: (): void => ipcRenderer.send('mimik:app:relocalise'),
+ locale: (code: string): void => ipcRenderer.send('mimik:app:locale', code),
updates: {
check: (): Promise<void> => ipcRenderer.invoke('mimik:updates:check'),
},
diff --git a/apps/desktop/src/renderer/core-env.ts b/apps/desktop/src/renderer/core-env.ts
index b725c39..007da28 100644
--- a/apps/desktop/src/renderer/core-env.ts
+++ b/apps/desktop/src/renderer/core-env.ts
@@ -34,6 +34,7 @@ const MESSAGES: Record<AppLocale, Messages> = {
};
const locale = appLocale(window.localStorage.getItem('appLanguage')?.replace(/^"|"$/g, ''), navigator.language);
+window.mimik?.locale(locale);
configureCore({
client: 'desktop',
diff --git a/src/locales/de.yml b/src/locales/de.yml
index 1b6ed87..a5e56e8 100644
--- a/src/locales/de.yml
+++ b/src/locales/de.yml
@@ -183,6 +183,17 @@ desktop:
version: "Version $1"
versionHint: "Mimik sucht bei jedem Start nach Updates."
checkUpdates: "Nach Updates suchen"
+ traySetArea: "Aufnahmebereich festlegen"
+ trayQuit: "Mimik beenden"
+ trayRecording: "Mimik nimmt auf. Zum Beenden klicken."
+ cannotRecord: "Mimik kann nicht aufnehmen"
+ updateReady: "Update bereit"
+ updateReadyMessage: "Mimik $1 kann installiert werden."
+ restartNow: "Jetzt neu starten"
+ later: "Später"
+ updateFailed: "Suche nach Updates fehlgeschlagen"
+ upToDate: "Auf dem neuesten Stand"
+ upToDateMessage: "Mimik $1 ist aktuell."
cardScreenshots: "Screenshots"
cardKeyboard: "Tippen und Tasten"
cardGlobalKeys: "Globale Tasten"
diff --git a/src/locales/en.yml b/src/locales/en.yml
index 7da3af1..74895a0 100644
--- a/src/locales/en.yml
+++ b/src/locales/en.yml
@@ -183,6 +183,17 @@ desktop:
version: "Version $1"
versionHint: "Mimik looks for updates each time it starts."
checkUpdates: "Check for updates"
+ traySetArea: "Set capture area"
+ trayQuit: "Quit Mimik"
+ trayRecording: "Mimik is recording. Click to finish."
+ cannotRecord: "Mimik cannot record"
+ updateReady: "Update ready"
+ updateReadyMessage: "Mimik $1 is ready to install."
+ restartNow: "Restart now"
+ later: "Later"
+ updateFailed: "Update check failed"
+ upToDate: "Up to date"
+ upToDateMessage: "Mimik $1 is current."
cardScreenshots: "Screenshots"
cardKeyboard: "Typing and keys"
cardGlobalKeys: "Global keys"
diff --git a/src/locales/es.yml b/src/locales/es.yml
index 0b0e2a0..3a31549 100644
--- a/src/locales/es.yml
+++ b/src/locales/es.yml
@@ -183,6 +183,17 @@ desktop:
version: "Versión $1"
versionHint: "Mimik busca actualizaciones cada vez que se inicia."
checkUpdates: "Buscar actualizaciones"
+ traySetArea: "Definir el área de captura"
+ trayQuit: "Salir de Mimik"
+ trayRecording: "Mimik está grabando. Haz clic para terminar."
+ cannotRecord: "Mimik no puede grabar"
+ updateReady: "Actualización lista"
+ updateReadyMessage: "Mimik $1 está listo para instalarse."
+ restartNow: "Reiniciar ahora"
+ later: "Más tarde"
+ updateFailed: "No se pudieron buscar actualizaciones"
+ upToDate: "Actualizado"
+ upToDateMessage: "Mimik $1 es la versión más reciente."
cardScreenshots: "Capturas de pantalla"
cardKeyboard: "Escritura y teclas"
cardGlobalKeys: "Teclas globales"
diff --git a/src/locales/fr.yml b/src/locales/fr.yml
index de35a34..15d167b 100644
--- a/src/locales/fr.yml
+++ b/src/locales/fr.yml
@@ -183,6 +183,17 @@ desktop:
version: "Version $1"
versionHint: "Mimik recherche les mises à jour à chaque démarrage."
checkUpdates: "Rechercher des mises à jour"
+ traySetArea: "Définir la zone de capture"
+ trayQuit: "Quitter Mimik"
+ trayRecording: "Mimik enregistre. Cliquez pour terminer."
+ cannotRecord: "Mimik ne peut pas enregistrer"
+ updateReady: "Mise à jour prête"
+ updateReadyMessage: "Mimik $1 est prêt à être installé."
+ restartNow: "Redémarrer maintenant"
+ later: "Plus tard"
+ updateFailed: "La recherche de mises à jour a échoué"
+ upToDate: "À jour"
+ upToDateMessage: "Mimik $1 est la dernière version."
cardScreenshots: "Captures d’écran"
cardKeyboard: "Saisie et touches"
cardGlobalKeys: "Touches globales"
diff --git a/src/locales/pt-BR.yml b/src/locales/pt-BR.yml
index 34f0433..7f62ab7 100644
--- a/src/locales/pt-BR.yml
+++ b/src/locales/pt-BR.yml
@@ -183,6 +183,17 @@ desktop:
version: "Versão $1"
versionHint: "O Mimik procura atualizações sempre que é iniciado."
checkUpdates: "Procurar atualizações"
+ traySetArea: "Definir a área de captura"
+ trayQuit: "Sair do Mimik"
+ trayRecording: "O Mimik está gravando. Clique para terminar."
+ cannotRecord: "O Mimik não consegue gravar"
+ updateReady: "Atualização pronta"
+ updateReadyMessage: "O Mimik $1 está pronto para instalar."
+ restartNow: "Reiniciar agora"
+ later: "Mais tarde"
+ updateFailed: "Não foi possível procurar atualizações"
+ upToDate: "Atualizado"
+ upToDateMessage: "O Mimik $1 é a versão mais recente."
cardScreenshots: "Capturas de tela"
cardKeyboard: "Digitação e teclas"
cardGlobalKeys: "Teclas globais"
diff --git a/src/locales/zh-CN.yml b/src/locales/zh-CN.yml
index 5fb196d..2e64acc 100644
--- a/src/locales/zh-CN.yml
+++ b/src/locales/zh-CN.yml
@@ -183,6 +183,17 @@ desktop:
version: "版本 $1"
versionHint: "Mimik 每次启动时都会检查更新。"
checkUpdates: "检查更新"
+ traySetArea: "设置捕获区域"
+ trayQuit: "退出 Mimik"
+ trayRecording: "Mimik 正在录制。点击即可完成。"
+ cannotRecord: "Mimik 无法录制"
+ updateReady: "更新已就绪"
+ updateReadyMessage: "Mimik $1 已可安装。"
+ restartNow: "立即重启"
+ later: "稍后"
+ updateFailed: "检查更新失败"
+ upToDate: "已是最新版本"
+ upToDateMessage: "Mimik $1 已是最新版本。"
cardScreenshots: "屏幕截图"
cardKeyboard: "输入与按键"
cardGlobalKeys: "全局快捷键"