Skip to content

Commit 887998e

Browse files
committed
Add initial translation support
Attempt to add support for translations, with an initial pseudo-language translation Uses l10n, which is the recommended latest tooling for VS Code localization
1 parent c5541f8 commit 887998e

28 files changed

+944
-398
lines changed

l10n/bundle.l10n.json

Lines changed: 256 additions & 0 deletions
Large diffs are not rendered by default.

l10n/bundle.l10n.qps-ploc.json

Lines changed: 256 additions & 0 deletions
Large diffs are not rendered by default.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"ms-python.python"
5252
],
5353
"main": "./dist/extension.cjs",
54+
"l10n": "./l10n",
5455
"markdown": "github",
5556
"minimumNodeVersion": 20,
5657
"capabilities": {

scripts/genTranslations.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import shutil
2+
import subprocess
3+
import os
4+
5+
6+
def copyMtsToTs(src, dst):
7+
# Copy but change mts to ts
8+
dst = dst.replace(".mts", ".ts")
9+
shutil.copyfile(src, dst)
10+
11+
12+
dir_path = os.path.dirname(os.path.realpath(__file__))
13+
os.chdir(f"{dir_path}/..")
14+
15+
shutil.copytree("./src", "./tmp-translate", copy_function=copyMtsToTs)
16+
17+
os.system("vscode-l10n-dev export --debug --verbose --outDir ./l10n ./tmp-translate")
18+
19+
os.system(
20+
"vscode-l10n-dev generate-pseudo --debug --verbose --outDir ./l10n ./l10n/bundle.l10n.json ./package.nls.json"
21+
)
22+
23+
shutil.rmtree("./tmp-translate")

src/commands/clearGithubApiCache.mts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Command } from "./command.mjs";
22
import Logger from "../logger.mjs";
33
import GithubApiCache from "../utils/githubApiCache.mjs";
4-
import { window } from "vscode";
4+
import { window, l10n } from "vscode";
55

66
export default class ClearGithubApiCacheCommand extends Command {
77
private _logger: Logger = new Logger("ClearGithubApiCacheCommand");
@@ -17,6 +17,6 @@ export default class ClearGithubApiCacheCommand extends Command {
1717

1818
await GithubApiCache.getInstance().clear();
1919

20-
await window.showInformationMessage("Github API cache cleared.");
20+
await window.showInformationMessage(l10n.t("Github API cache cleared."));
2121
}
2222
}

src/commands/compileProject.mts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { commands, tasks, window } from "vscode";
1+
import { commands, tasks, window, l10n } from "vscode";
22
import { EventEmitter } from "events";
33
import { CommandWithResult } from "./command.mjs";
44
import Logger from "../logger.mjs";
@@ -72,7 +72,7 @@ export default class CompileProjectCommand extends CommandWithResult<boolean> {
7272
} else {
7373
// Task not found
7474
this._logger.error("Task 'Compile Project' not found.");
75-
void window.showErrorMessage("Task 'Compile Project' not found.");
75+
void window.showErrorMessage(l10n.t("Task {0} not found.", 'Compile Project'));
7676

7777
return false;
7878
}

src/commands/configureCmake.mts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Command } from "./command.mjs";
22
import Logger from "../logger.mjs";
3-
import { window, workspace } from "vscode";
3+
import { window, workspace, l10n } from "vscode";
44
import { configureCmakeNinja } from "../utils/cmakeUtil.mjs";
55
import Settings, { SettingsKey } from "../settings.mjs";
66
import { join } from "path";
@@ -22,7 +22,7 @@ export default class ConfigureCmakeCommand extends Command {
2222
// check if is a pico project
2323
if (workspaceFolder === undefined) {
2424
this._logger.warn("No workspace folder found.");
25-
void window.showWarningMessage("No workspace folder found.");
25+
void window.showWarningMessage(l10n.t("No workspace folder found."));
2626

2727
return;
2828
}
@@ -34,17 +34,16 @@ export default class ConfigureCmakeCommand extends Command {
3434
settings.getBoolean(SettingsKey.useCmakeTools)
3535
) {
3636
void window.showErrorMessage(
37-
"You must use the CMake Tools extension to configure your build. " +
38-
"To use this extension instead, change the useCmakeTools setting."
37+
l10n.t("You must use the CMake Tools extension to configure your build. To use this extension instead, change the useCmakeTools setting.")
3938
);
4039

4140
return;
4241
}
4342

4443
if (await configureCmakeNinja(workspaceFolder.uri)) {
45-
void window.showInformationMessage("CMake has configured your build.");
44+
void window.showInformationMessage(l10n.t("CMake has configured your build."));
4645
} else {
47-
void window.showWarningMessage("CMake failed to configure your build.");
46+
void window.showWarningMessage(l10n.t("CMake failed to configure your build."));
4847
}
4948
}
5049
}
@@ -63,7 +62,7 @@ export class CleanCMakeCommand extends Command {
6362

6463
if (workspaceFolder === undefined) {
6564
this._logger.warn("No workspace folder found.");
66-
void window.showWarningMessage("No workspace folder found.");
65+
void window.showWarningMessage(l10n.t("No workspace folder found."));
6766

6867
return;
6968
}
@@ -75,8 +74,7 @@ export class CleanCMakeCommand extends Command {
7574
settings.getBoolean(SettingsKey.useCmakeTools)
7675
) {
7776
void window.showErrorMessage(
78-
"You must use the CMake Tools extension to clean your build. " +
79-
"To use this extension instead, change the useCmakeTools setting."
77+
l10n.t("You must use the CMake Tools extension to clean your build. To use this extension instead, change the useCmakeTools setting.")
8078
);
8179

8280
return;
@@ -91,18 +89,18 @@ export class CleanCMakeCommand extends Command {
9189
"Error cleaning build directory.",
9290
unknownErrorToString(error)
9391
);
94-
void window.showErrorMessage("Error cleaning build directory.");
92+
void window.showErrorMessage(l10n.t("Error cleaning build directory."));
9593

9694
return;
9795
}
9896

9997
if (await configureCmakeNinja(workspaceFolder.uri)) {
10098
void window.showInformationMessage(
101-
"CMake has been cleaned and reconfigured."
99+
l10n.t("CMake has been cleaned and reconfigured.")
102100
);
103101
} else {
104102
void window.showWarningMessage(
105-
"CMake could not be reconfigured. See log for details."
103+
l10n.t("CMake could not be reconfigured. See log for details.")
106104
);
107105
}
108106
}

src/commands/flashProjectSwd.mts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { CommandWithResult } from "./command.mjs";
22
import Logger from "../logger.mjs";
3-
import { tasks, window } from "vscode";
3+
import { tasks, window, l10n } from "vscode";
44
import { EventEmitter } from "stream";
55

66
export default class FlashProjectSWDCommand extends CommandWithResult<boolean> {
@@ -62,7 +62,7 @@ export default class FlashProjectSWDCommand extends CommandWithResult<boolean> {
6262
} else {
6363
// Task not found
6464
this._logger.error("Task 'Flash' not found.");
65-
void window.showErrorMessage("Task 'Flash' not found.");
65+
void window.showErrorMessage(l10n.t("Task {0} not found.", 'Flash'));
6666

6767
return false;
6868
}

src/commands/launchTargetPath.mts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { readFileSync } from "fs";
22
import { CommandWithResult } from "./command.mjs";
3-
import { commands, window, workspace } from "vscode";
3+
import { commands, window, workspace, l10n } from "vscode";
44
import { join } from "path";
55
import Settings, { SettingsKey } from "../settings.mjs";
66

@@ -31,9 +31,9 @@ export default class LaunchTargetPathCommand extends CommandWithResult<string> {
3131

3232
if (matchBg && matchPoll) {
3333
// For examples with both background and poll, let user pick which to run
34-
const quickPickItems = ["Threadsafe Background", "Poll"];
34+
const quickPickItems = [l10n.t("Threadsafe Background"), l10n.t("Poll")];
3535
const backgroundOrPoll = await window.showQuickPick(quickPickItems, {
36-
placeHolder: "Select PicoW Architecture",
36+
placeHolder: l10n.t("Select PicoW Architecture"),
3737
});
3838
if (backgroundOrPoll === undefined) {
3939
return projectName;

src/commands/newProject.mts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { CommandWithArgs } from "./command.mjs";
22
import Logger from "../logger.mjs";
3-
import { window, type Uri } from "vscode";
3+
import { window, type Uri, l10n } from "vscode";
44
import { NewProjectPanel } from "../webview/newProjectPanel.mjs";
55
// eslint-disable-next-line max-len
66
import { NewMicroPythonProjectPanel } from "../webview/newMicroPythonProjectPanel.mjs";
@@ -44,10 +44,10 @@ export default class NewProjectCommand extends CommandWithArgs {
4444
(await window.showQuickPick(
4545
[NewProjectCommand.cCppOption, NewProjectCommand.micropythonOption],
4646
{
47-
placeHolder: "Select which language to use for your new project",
47+
placeHolder: l10n.t("Select which language to use for your new project"),
4848
canPickMany: false,
4949
ignoreFocusOut: false,
50-
title: "New Pico Project",
50+
title: l10n.t("New Pico Project"),
5151
}
5252
));
5353

0 commit comments

Comments
 (0)