Skip to content

Commit b6030f5

Browse files
committed
feat: add i18n
1 parent 1da936b commit b6030f5

8 files changed

Lines changed: 62 additions & 53 deletions

File tree

package-lock.json

Lines changed: 19 additions & 45 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"name": "oopilot",
44
"displayName": "OOMOL Flexpilot",
55
"description": "Open-Source, Native and a True GitHub Copilot Alternative for VS Code",
6-
"version": "0.1.3",
6+
"version": "0.1.4",
77
"icon": "assets/logo.png",
88
"license": "GPL-3.0-only",
99
"pricing": "Free",
@@ -225,7 +225,7 @@
225225
"id": "flexpilot.panel.default",
226226
"name": "oopilot",
227227
"fullName": "oopilot",
228-
"description": "Ask oomol or type / for commands",
228+
"description": "Ask OOMOL or type / for commands",
229229
"isDefault": true,
230230
"locations": [
231231
"panel"
@@ -235,7 +235,7 @@
235235
"id": "flexpilot.editor.default",
236236
"name": "oopilot",
237237
"fullName": "oopilot",
238-
"description": "Ask oomol or type / for commands",
238+
"description": "Ask OOMOL or type / for commands",
239239
"isDefault": true,
240240
"locations": [
241241
"editor"
@@ -341,15 +341,14 @@
341341
"axios": "^1.7.2",
342342
"comment-json": "^4.2.4",
343343
"groq-sdk": "^0.5.0",
344-
"inversify": "^6.0.3",
345344
"markdown-it": "^14.1.0",
346345
"openai": "^4.67.3",
347346
"react": "^18.3.1",
348347
"react-dom": "^18.3.1",
349-
"reflect-metadata": "^0.2.2",
350348
"turndown": "^7.2.0",
351349
"turndown-plugin-gfm": "^1.0.2",
352350
"uuid": "^10.0.0",
351+
"val-i18n": "^0.1.13",
353352
"zod": "^3.23.8"
354353
},
355354
"lint-staged": {

src/extension.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as vscode from "vscode";
2+
import { I18nManager } from "./locales";
23
import { logger } from "./logger";
34
import { storage } from "./storage";
45

@@ -25,6 +26,9 @@ export async function activate(context: vscode.ExtensionContext) {
2526
// Initialize the storage manager
2627
storage.setContext(context);
2728

29+
await I18nManager.crate(vscode.env.language);
30+
logger.info("I18nManager initialized with locale:", vscode.env.language);
31+
2832
// Register the logger with the context
2933
context.subscriptions.push(logger);
3034

src/locales/en.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"welcome": "Welcome",
3+
"welcomeTips": "I'm your pair programmer and I'm here to help you get things done faster."
4+
}

src/locales/index.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { I18n, Locale } from "val-i18n";
2+
3+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
4+
const interop = (p: Promise<any>) => p.then((mod) => mod.default || mod);
5+
6+
export const locales: Record<string, Promise<Locale>> = {
7+
en: interop(import("./en.json")),
8+
"zh-cn": interop(import("./zh-cn.json")),
9+
};
10+
11+
export const createI18n = async (locale: string) => {
12+
return I18n.preload(locale, (lang) => locales[lang]);
13+
};
14+
15+
export class I18nManager {
16+
public static i18n: I18n;
17+
18+
public static async crate(locale: string) {
19+
const i18n = await createI18n(locale);
20+
this.i18n = i18n;
21+
}
22+
}

src/locales/zh-CN.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"welcome": "欢迎",
3+
"welcomeTips": "我是你的编程伙伴,我在这里帮助你更快地完成工作。"
4+
}

src/panel-chat.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ class PanelChatParticipant {
224224
private async provideWelcomeMessage(): Promise<vscode.ChatWelcomeMessageContent> {
225225
return {
226226
icon: new vscode.ThemeIcon("flexpilot-default"),
227-
title: "Ask oomol",
227+
title: "Ask OOMOL",
228228
message: PanelChatPrompt.getWelcomeMessage(this.session.account.label),
229229
};
230230
}

src/prompts/panel-chat.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { CoreMessage } from "ai";
22
import * as vscode from "vscode";
3+
import { I18nManager } from "../locales";
34
import { logger } from "../logger";
45
import {
56
Code,
@@ -226,11 +227,12 @@ export class PanelChatPrompt {
226227
*/
227228
public static getWelcomeMessage(username: string): vscode.MarkdownString {
228229
logger.debug(`Generating welcome message for user: ${username}`);
230+
const i18n = I18nManager.i18n;
231+
229232
return jsxToMarkdown(
230233
<Message role="user">
231234
<p>
232-
Welcome, <b>@{username}</b>, I'm your pair programmer and I'm here to
233-
help you get things done faster.
235+
{i18n.t("welcome")}, <b>@{username}</b>, {i18n.t("welcomeTips")}
234236
</p>
235237
</Message>,
236238
);

0 commit comments

Comments
 (0)