Skip to content

Commit

Permalink
feat: add i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
l1shen committed Dec 9, 2024
1 parent 1da936b commit b6030f5
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 53 deletions.
64 changes: 19 additions & 45 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "oopilot",
"displayName": "OOMOL Flexpilot",
"description": "Open-Source, Native and a True GitHub Copilot Alternative for VS Code",
"version": "0.1.3",
"version": "0.1.4",
"icon": "assets/logo.png",
"license": "GPL-3.0-only",
"pricing": "Free",
Expand Down Expand Up @@ -225,7 +225,7 @@
"id": "flexpilot.panel.default",
"name": "oopilot",
"fullName": "oopilot",
"description": "Ask oomol or type / for commands",
"description": "Ask OOMOL or type / for commands",
"isDefault": true,
"locations": [
"panel"
Expand All @@ -235,7 +235,7 @@
"id": "flexpilot.editor.default",
"name": "oopilot",
"fullName": "oopilot",
"description": "Ask oomol or type / for commands",
"description": "Ask OOMOL or type / for commands",
"isDefault": true,
"locations": [
"editor"
Expand Down Expand Up @@ -341,15 +341,14 @@
"axios": "^1.7.2",
"comment-json": "^4.2.4",
"groq-sdk": "^0.5.0",
"inversify": "^6.0.3",
"markdown-it": "^14.1.0",
"openai": "^4.67.3",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"reflect-metadata": "^0.2.2",
"turndown": "^7.2.0",
"turndown-plugin-gfm": "^1.0.2",
"uuid": "^10.0.0",
"val-i18n": "^0.1.13",
"zod": "^3.23.8"
},
"lint-staged": {
Expand Down
4 changes: 4 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as vscode from "vscode";
import { I18nManager } from "./locales";
import { logger } from "./logger";
import { storage } from "./storage";

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

await I18nManager.crate(vscode.env.language);
logger.info("I18nManager initialized with locale:", vscode.env.language);

// Register the logger with the context
context.subscriptions.push(logger);

Expand Down
4 changes: 4 additions & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"welcome": "Welcome",
"welcomeTips": "I'm your pair programmer and I'm here to help you get things done faster."
}
22 changes: 22 additions & 0 deletions src/locales/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { I18n, Locale } from "val-i18n";

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const interop = (p: Promise<any>) => p.then((mod) => mod.default || mod);

export const locales: Record<string, Promise<Locale>> = {
en: interop(import("./en.json")),
"zh-cn": interop(import("./zh-cn.json")),
};

export const createI18n = async (locale: string) => {
return I18n.preload(locale, (lang) => locales[lang]);
};

export class I18nManager {
public static i18n: I18n;

public static async crate(locale: string) {
const i18n = await createI18n(locale);
this.i18n = i18n;
}
}
4 changes: 4 additions & 0 deletions src/locales/zh-CN.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"welcome": "欢迎",
"welcomeTips": "我是你的编程伙伴,我在这里帮助你更快地完成工作。"
}
2 changes: 1 addition & 1 deletion src/panel-chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ class PanelChatParticipant {
private async provideWelcomeMessage(): Promise<vscode.ChatWelcomeMessageContent> {
return {
icon: new vscode.ThemeIcon("flexpilot-default"),
title: "Ask oomol",
title: "Ask OOMOL",
message: PanelChatPrompt.getWelcomeMessage(this.session.account.label),
};
}
Expand Down
6 changes: 4 additions & 2 deletions src/prompts/panel-chat.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { CoreMessage } from "ai";
import * as vscode from "vscode";
import { I18nManager } from "../locales";
import { logger } from "../logger";
import {
Code,
Expand Down Expand Up @@ -226,11 +227,12 @@ export class PanelChatPrompt {
*/
public static getWelcomeMessage(username: string): vscode.MarkdownString {
logger.debug(`Generating welcome message for user: ${username}`);
const i18n = I18nManager.i18n;

return jsxToMarkdown(
<Message role="user">
<p>
Welcome, <b>@{username}</b>, I'm your pair programmer and I'm here to
help you get things done faster.
{i18n.t("welcome")}, <b>@{username}</b>, {i18n.t("welcomeTips")}
</p>
</Message>,
);
Expand Down

0 comments on commit b6030f5

Please sign in to comment.