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(i18n): add AI language picker and localize dates

Luis Ortiz0c555b8ca612
diff --git a/src/core/capture/ai/description.ts b/src/core/capture/ai/description.ts
index 18446fe..38acf26 100644
--- a/src/core/capture/ai/description.ts
+++ b/src/core/capture/ai/description.ts
@@ -1,8 +1,9 @@
import { generateText } from 'ai';
+import { localStorage } from '@/lib/browser-api';
import { logger } from '@/lib/logger';
import type { DOMContext } from '../dom/context';
import { serializeDOMContext } from '../dom/context';
-import { STEP_DESCRIPTION_PROMPT } from './prompts';
+import { getLanguageSuffix, STEP_DESCRIPTION_PROMPT } from './prompts';
import { createModel } from './provider';
export async function getAIDescription(
@@ -12,9 +13,12 @@ export async function getAIDescription(
apiKey: string,
): Promise<string | null> {
try {
+ const settings = await localStorage.get(['aiLanguage']);
+ const locale = (settings.aiLanguage as string) || 'en';
const { text } = await generateText({
model: createModel(provider, model, apiKey),
- prompt: STEP_DESCRIPTION_PROMPT.replace('{{context}}', serializeDOMContext(domContext)),
+ prompt:
+ STEP_DESCRIPTION_PROMPT.replace('{{context}}', serializeDOMContext(domContext)) + getLanguageSuffix(locale),
maxOutputTokens: 50,
});
return text.trim().replace(/^"|"$/g, '') || null;
diff --git a/src/core/capture/ai/prompts.ts b/src/core/capture/ai/prompts.ts
index 23edef6..6b7d980 100644
--- a/src/core/capture/ai/prompts.ts
+++ b/src/core/capture/ai/prompts.ts
@@ -25,3 +25,28 @@ Examples:
- "Create Repository in GitHub Organization"
Just the title, no quotes, no preamble. Under 60 characters.`;
+
+export const AI_LANGUAGES = [
+ { code: 'en', label: 'English' },
+ { code: 'es', label: 'Español' },
+ { code: 'pt-BR', label: 'Português (Brasil)' },
+ { code: 'fr', label: 'Français' },
+] as const;
+
+export type AILanguageCode = (typeof AI_LANGUAGES)[number]['code'];
+
+const LANGUAGE_NAMES: Record<string, string> = {
+ es: 'Spanish',
+ fr: 'French',
+ pt: 'Brazilian Portuguese',
+ de: 'German',
+ ja: 'Japanese',
+ ko: 'Korean',
+ zh: 'Chinese',
+};
+
+export function getLanguageSuffix(locale: string): string {
+ if (locale.startsWith('en')) return '';
+ const lang = LANGUAGE_NAMES[locale.split('-')[0]] || locale;
+ return `\nIMPORTANT: Write the description in ${lang}.`;
+}
diff --git a/src/core/capture/ai/title.ts b/src/core/capture/ai/title.ts
index 836f72a..3ac462a 100644
--- a/src/core/capture/ai/title.ts
+++ b/src/core/capture/ai/title.ts
@@ -1,6 +1,7 @@
import { generateText } from 'ai';
+import { localStorage } from '@/lib/browser-api';
import { logger } from '@/lib/logger';
-import { GUIDE_TITLE_PROMPT } from './prompts';
+import { GUIDE_TITLE_PROMPT, getLanguageSuffix } from './prompts';
import { createModel } from './provider';
export async function generateGuideTitle(
@@ -14,9 +15,11 @@ export async function generateGuideTitle(
const formatted = steps.map((s, i) => `${i + 1}. [${s.url}] ${s.description}`).join('\n');
try {
+ const settings = await localStorage.get(['aiLanguage']);
+ const locale = (settings.aiLanguage as string) || 'en';
const { text } = await generateText({
model: createModel(provider, model, apiKey),
- prompt: GUIDE_TITLE_PROMPT.replace('{{steps}}', formatted),
+ prompt: GUIDE_TITLE_PROMPT.replace('{{steps}}', formatted) + getLanguageSuffix(locale),
maxOutputTokens: 30,
});
let title = text.trim().replace(/^"|"$/g, '');
diff --git a/src/lib/utils.ts b/src/lib/utils.ts
index d01885c..069ef8f 100644
--- a/src/lib/utils.ts
+++ b/src/lib/utils.ts
@@ -1,24 +1,50 @@
import { type ClassValue, clsx } from 'clsx';
import dayjs from 'dayjs';
import relativeTime from 'dayjs/plugin/relativeTime';
+import 'dayjs/locale/es';
+import 'dayjs/locale/pt-br';
+import 'dayjs/locale/fr';
import { twMerge } from 'tailwind-merge';
+import { i18n } from '#imports';
dayjs.extend(relativeTime);
+const DAYJS_LOCALE_MAP: Record<string, string> = {
+ es: 'es',
+ 'pt-BR': 'pt-br',
+ pt: 'pt-br',
+ fr: 'fr',
+};
+
+function getDayjsLocale(): string | undefined {
+ try {
+ const locale = i18n.t('meta.locale');
+ if (locale && DAYJS_LOCALE_MAP[locale]) return DAYJS_LOCALE_MAP[locale];
+ const key = locale?.split(/[-_]/)[0]?.toLowerCase();
+ if (key && DAYJS_LOCALE_MAP[key]) return DAYJS_LOCALE_MAP[key];
+ } catch {}
+ return undefined;
+}
+
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}
export function formatDate(ts: number): string {
- return dayjs(ts).format('MMM D, YYYY');
+ const locale = getDayjsLocale();
+ const d = locale ? dayjs(ts).locale(locale) : dayjs(ts);
+ return d.format('MMM D, YYYY');
}
export function formatDateShort(ts: number): string {
- return dayjs(ts).format('MMM D');
+ const locale = getDayjsLocale();
+ const d = locale ? dayjs(ts).locale(locale) : dayjs(ts);
+ return d.format('MMM D');
}
export function formatRelativeTime(ts: number): string {
- return dayjs(ts).fromNow();
+ const locale = getDayjsLocale();
+ return locale ? dayjs(ts).locale(locale).fromNow() : dayjs(ts).fromNow();
}
export function extractDomain(url: string): string {