Skip to content

Commit

Permalink
Revert "fix: use vscode.l10n API"
Browse files Browse the repository at this point in the history
This reverts commit 3556251.
  • Loading branch information
hyrious committed Dec 10, 2024
1 parent c3676e2 commit 58877ee
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 16 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ node_modules
launch_folder
extension.vsix
extension.hash
l10n/bundle.l10n.json
4 changes: 0 additions & 4 deletions l10n/bundle.l10n.zh-cn.json

This file was deleted.

4 changes: 2 additions & 2 deletions package-lock.json

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

5 changes: 2 additions & 3 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.7",
"version": "0.1.6",
"icon": "assets/logo.png",
"license": "GPL-3.0-only",
"pricing": "Free",
Expand Down Expand Up @@ -51,7 +51,6 @@
"onStartupFinished"
],
"main": "./out/extension.js",
"l10n": "./l10n",
"scripts": {
"compile": "webpack",
"watch": "webpack --watch",
Expand Down Expand Up @@ -374,4 +373,4 @@
"engines": {
"vscode": "1.95.x"
}
}
}
4 changes: 3 additions & 1 deletion 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,7 +26,8 @@ export async function activate(context: vscode.ExtensionContext) {
// Initialize the storage manager
storage.setContext(context);

logger.info("Language:", vscode.env.language);
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": "我是你的编程伙伴,我在这里帮助你更快地完成工作。"
}
8 changes: 3 additions & 5 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,15 +227,12 @@ export class PanelChatPrompt {
*/
public static getWelcomeMessage(username: string): vscode.MarkdownString {
logger.debug(`Generating welcome message for user: ${username}`);
const welcome = vscode.l10n.t("Welcome");
const welcomeTips = vscode.l10n.t(
"I'm your pair programmer and I'm here to help you get things done faster.",
);
const i18n = I18nManager.i18n;

return jsxToMarkdown(
<Message role="user">
<p>
{welcome}, <b>@{username}</b>, {welcomeTips}
{i18n.t("welcome")}, <b>@{username}</b>, {i18n.t("welcomeTips")}
</p>
</Message>,
);
Expand Down

0 comments on commit 58877ee

Please sign in to comment.