Skip to content
Open
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
48 changes: 48 additions & 0 deletions apps/pi-extension/i18n.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
type Locale = "en" | "es" | "fr" | "pt-BR";
type Params = Record<string, string | number>;

const translations: Record<Exclude<Locale, "en">, Record<string, string>> = {
es: {
"status.phase": "Fase: {phase}",
"status.planFile": "Archivo del plan: {path}",
"status.progress": "Progreso: {done}/{total}",
},
fr: {
"status.phase": "Phase : {phase}",
"status.planFile": "Fichier du plan : {path}",
"status.progress": "Progression : {done}/{total}",
},
"pt-BR": {
"status.phase": "Fase: {phase}",
"status.planFile": "Arquivo do plano: {path}",
"status.progress": "Progresso: {done}/{total}",
},
};

let currentLocale: Locale = "en";

export function initI18n(pi: { events?: { emit?: (event: string, payload: unknown) => void } }): void {
pi.events?.emit?.("pi-core/i18n/registerBundle", {
namespace: "plannotator",
defaultLocale: "en",
locales: translations,
});
pi.events?.emit?.("pi-core/i18n/requestApi", {
onReady: (api: { getLocale?: () => string; onLocaleChange?: (cb: (locale: string) => void) => void }) => {
const locale = api.getLocale?.();
if (isLocale(locale)) currentLocale = locale;
api.onLocaleChange?.((next) => {
if (isLocale(next)) currentLocale = next;
});
},
});
}

export function t(key: string, fallback: string, params: Params = {}): string {
const template = currentLocale === "en" ? fallback : translations[currentLocale]?.[key] ?? fallback;
return template.replace(/\{(\w+)\}/g, (_, name) => String(params[name] ?? `{${name}}`));
}

function isLocale(locale: string | undefined): locale is Locale {
return locale === "en" || locale === "es" || locale === "fr" || locale === "pt-BR";
}
11 changes: 7 additions & 4 deletions apps/pi-extension/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import type {
} from "@mariozechner/pi-coding-agent";
import { Key } from "@mariozechner/pi-tui";
import { buildPromptVariables, formatTodoList, loadPlannotatorConfig, renderTemplate, resolvePhaseProfile } from "./config.js";
import { initI18n, t } from "./i18n.js";
import {
type ChecklistItem,
markCompletedSteps,
Expand Down Expand Up @@ -116,6 +117,8 @@ function getPlanReviewAvailabilityWarning(options: { hasUI: boolean; hasPlanHtml
}

export default function plannotator(pi: ExtensionAPI): void {
initI18n(pi);

let phase: Phase = "idle";
void registerPlannotatorEventListeners(pi);
let lastSubmittedPath: string | null = null;
Expand Down Expand Up @@ -292,13 +295,13 @@ export default function plannotator(pi: ExtensionAPI): void {
pi.registerCommand("plannotator-status", {
description: "Show plannotator status",
handler: async (_args, ctx) => {
const parts = [`Phase: ${phase}`];
const parts = [t("status.phase", "Phase: {phase}", { phase })];
if (lastSubmittedPath) {
parts.push(`Plan file: ${lastSubmittedPath}`);
parts.push(t("status.planFile", "Plan file: {path}", { path: lastSubmittedPath }));
}
if (checklistItems.length > 0) {
const done = checklistItems.filter((t) => t.completed).length;
parts.push(`Progress: ${done}/${checklistItems.length}`);
const done = checklistItems.filter((item) => item.completed).length;
parts.push(t("status.progress", "Progress: {done}/{total}", { done, total: checklistItems.length }));
}
ctx.ui.notify(parts.join("\n"), "info");
},
Expand Down
1 change: 1 addition & 0 deletions apps/pi-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
},
"files": [
"index.ts",
"i18n.ts",
"plannotator-browser.ts",
"plannotator-events.ts",
"server.ts",
Expand Down