Skip to content

Commit 4e708cb

Browse files
committed
🌐 update i18n method
1 parent fee8d6c commit 4e708cb

File tree

5 files changed

+19
-6
lines changed

5 files changed

+19
-6
lines changed

.eslintrc.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
"plugin:@typescript-eslint/recommended"
1313
],
1414
"rules": {
15-
"@typescript-eslint/class-name-casing": "warn",
1615
"@typescript-eslint/semi": "warn",
1716
"curly": "warn",
1817
"eqeqeq": "warn",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"displayName": "MASM/TASM",
44
"publisher": "xsro",
55
"description": "run MASM/TASM assembly in DOSBox 汇编语言开发插件",
6-
"version": "0.8.6",
6+
"version": "0.9.0",
77
"keywords": [
88
"dosbox",
99
"16位",

src/emulator/JS-Dos.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ interface JsdosAsmConfig {
1313
export class JSdosVSCodeConfig {
1414
private static get _target(): vscode.WorkspaceConfiguration {
1515
return vscode.workspace.getConfiguration('masmtasm.jsdos');
16-
};
16+
}
1717
public static get viewColumn(): vscode.ViewColumn {
1818
switch (JSdosVSCodeConfig._target.get("viewColumn")) {
1919
case 'Beside':

src/extension.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import * as vscode from 'vscode';
2-
import { localize } from './i18n';
2+
import { localize, loadI18n } from './i18n';
33

44
import { provider } from './language/provider';
55
import { AsmCommands } from './ASM/main';
66

77
export function activate(context: vscode.ExtensionContext): void {
8-
console.log(localize("activate.hello", 'Congratulations, your extension "masm-tasm" is now active!'));
8+
loadI18n(context);
99
//provide programmaic language features like hover,references,outline(symbol)
1010
provider(context);
1111
//run and debug the code in dosbox or msdos-player by TASM ot MASM
1212
AsmCommands(context);
13+
console.log(localize("activate.hello", 'Congratulations, your extension "masm-tasm" is now active!'));
1314
}
1415

1516
// this method is called when your extension is deactivated

src/i18n.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
1-
import { workspace } from "vscode";
1+
import { workspace, ExtensionContext, env, Uri } from "vscode";
22
const fs = workspace.fs;
33

4+
let text: { [id: string]: string } | null = null;
5+
6+
export async function loadI18n(context: ExtensionContext): Promise<void> {
7+
if (env.language === 'zh-cn') {
8+
const uri = Uri.joinPath(context.extensionUri, '/i18n/i18n.zh-cn.json');
9+
const data = await fs.readFile(uri);
10+
text = JSON.parse(data.toString());
11+
}
12+
}
13+
414
export function localize(key: string, value: string, ...args: string[]): string {
15+
if (text && Object.keys(text).includes(key)) {
16+
value = text[key];
17+
}
518
for (const argidx in args) {
619
value = value.replace(`{${argidx}}`, args[argidx]);
720
}

0 commit comments

Comments
 (0)