Skip to content

Commit

Permalink
Add initial translation support
Browse files Browse the repository at this point in the history
Attempt to add support for translations, with an initial pseudo-language translation

Uses l10n, which is the recommended latest tooling for VS Code localization
  • Loading branch information
will-v-pi committed Jan 8, 2025
1 parent c5541f8 commit 887998e
Show file tree
Hide file tree
Showing 28 changed files with 944 additions and 398 deletions.
256 changes: 256 additions & 0 deletions l10n/bundle.l10n.json

Large diffs are not rendered by default.

256 changes: 256 additions & 0 deletions l10n/bundle.l10n.qps-ploc.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"ms-python.python"
],
"main": "./dist/extension.cjs",
"l10n": "./l10n",
"markdown": "github",
"minimumNodeVersion": 20,
"capabilities": {
Expand Down
23 changes: 23 additions & 0 deletions scripts/genTranslations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import shutil
import subprocess
import os


def copyMtsToTs(src, dst):
# Copy but change mts to ts
dst = dst.replace(".mts", ".ts")
shutil.copyfile(src, dst)


dir_path = os.path.dirname(os.path.realpath(__file__))
os.chdir(f"{dir_path}/..")

shutil.copytree("./src", "./tmp-translate", copy_function=copyMtsToTs)

os.system("vscode-l10n-dev export --debug --verbose --outDir ./l10n ./tmp-translate")

os.system(
"vscode-l10n-dev generate-pseudo --debug --verbose --outDir ./l10n ./l10n/bundle.l10n.json ./package.nls.json"
)

shutil.rmtree("./tmp-translate")
4 changes: 2 additions & 2 deletions src/commands/clearGithubApiCache.mts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Command } from "./command.mjs";
import Logger from "../logger.mjs";
import GithubApiCache from "../utils/githubApiCache.mjs";
import { window } from "vscode";
import { window, l10n } from "vscode";

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

await GithubApiCache.getInstance().clear();

await window.showInformationMessage("Github API cache cleared.");
await window.showInformationMessage(l10n.t("Github API cache cleared."));
}
}
4 changes: 2 additions & 2 deletions src/commands/compileProject.mts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { commands, tasks, window } from "vscode";
import { commands, tasks, window, l10n } from "vscode";
import { EventEmitter } from "events";
import { CommandWithResult } from "./command.mjs";
import Logger from "../logger.mjs";
Expand Down Expand Up @@ -72,7 +72,7 @@ export default class CompileProjectCommand extends CommandWithResult<boolean> {
} else {
// Task not found
this._logger.error("Task 'Compile Project' not found.");
void window.showErrorMessage("Task 'Compile Project' not found.");
void window.showErrorMessage(l10n.t("Task {0} not found.", 'Compile Project'));

Check warning on line 75 in src/commands/compileProject.mts

View workflow job for this annotation

GitHub Actions / build

This line has a length of 85. Maximum allowed is 80

return false;
}
Expand Down
22 changes: 10 additions & 12 deletions src/commands/configureCmake.mts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Command } from "./command.mjs";
import Logger from "../logger.mjs";
import { window, workspace } from "vscode";
import { window, workspace, l10n } from "vscode";
import { configureCmakeNinja } from "../utils/cmakeUtil.mjs";
import Settings, { SettingsKey } from "../settings.mjs";
import { join } from "path";
Expand All @@ -22,7 +22,7 @@ export default class ConfigureCmakeCommand extends Command {
// check if is a pico project
if (workspaceFolder === undefined) {
this._logger.warn("No workspace folder found.");
void window.showWarningMessage("No workspace folder found.");
void window.showWarningMessage(l10n.t("No workspace folder found."));

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

Check warning on line 37 in src/commands/configureCmake.mts

View workflow job for this annotation

GitHub Actions / build

This line has a length of 146. Maximum allowed is 80
);

return;
}

if (await configureCmakeNinja(workspaceFolder.uri)) {
void window.showInformationMessage("CMake has configured your build.");
void window.showInformationMessage(l10n.t("CMake has configured your build."));

Check warning on line 44 in src/commands/configureCmake.mts

View workflow job for this annotation

GitHub Actions / build

This line has a length of 85. Maximum allowed is 80
} else {
void window.showWarningMessage("CMake failed to configure your build.");
void window.showWarningMessage(l10n.t("CMake failed to configure your build."));

Check warning on line 46 in src/commands/configureCmake.mts

View workflow job for this annotation

GitHub Actions / build

This line has a length of 86. Maximum allowed is 80
}
}
}
Expand All @@ -63,7 +62,7 @@ export class CleanCMakeCommand extends Command {

if (workspaceFolder === undefined) {
this._logger.warn("No workspace folder found.");
void window.showWarningMessage("No workspace folder found.");
void window.showWarningMessage(l10n.t("No workspace folder found."));

return;
}
Expand All @@ -75,8 +74,7 @@ export class CleanCMakeCommand extends Command {
settings.getBoolean(SettingsKey.useCmakeTools)
) {
void window.showErrorMessage(
"You must use the CMake Tools extension to clean your build. " +
"To use this extension instead, change the useCmakeTools setting."
l10n.t("You must use the CMake Tools extension to clean your build. To use this extension instead, change the useCmakeTools setting.")

Check warning on line 77 in src/commands/configureCmake.mts

View workflow job for this annotation

GitHub Actions / build

This line has a length of 142. Maximum allowed is 80
);

return;
Expand All @@ -91,18 +89,18 @@ export class CleanCMakeCommand extends Command {
"Error cleaning build directory.",
unknownErrorToString(error)
);
void window.showErrorMessage("Error cleaning build directory.");
void window.showErrorMessage(l10n.t("Error cleaning build directory."));

return;
}

if (await configureCmakeNinja(workspaceFolder.uri)) {
void window.showInformationMessage(
"CMake has been cleaned and reconfigured."
l10n.t("CMake has been cleaned and reconfigured.")
);
} else {
void window.showWarningMessage(
"CMake could not be reconfigured. See log for details."
l10n.t("CMake could not be reconfigured. See log for details.")
);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/commands/flashProjectSwd.mts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CommandWithResult } from "./command.mjs";
import Logger from "../logger.mjs";
import { tasks, window } from "vscode";
import { tasks, window, l10n } from "vscode";
import { EventEmitter } from "stream";

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

return false;
}
Expand Down
6 changes: 3 additions & 3 deletions src/commands/launchTargetPath.mts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { readFileSync } from "fs";
import { CommandWithResult } from "./command.mjs";
import { commands, window, workspace } from "vscode";
import { commands, window, workspace, l10n } from "vscode";
import { join } from "path";
import Settings, { SettingsKey } from "../settings.mjs";

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

if (matchBg && matchPoll) {
// For examples with both background and poll, let user pick which to run
const quickPickItems = ["Threadsafe Background", "Poll"];
const quickPickItems = [l10n.t("Threadsafe Background"), l10n.t("Poll")];

Check warning on line 34 in src/commands/launchTargetPath.mts

View workflow job for this annotation

GitHub Actions / build

This line has a length of 81. Maximum allowed is 80
const backgroundOrPoll = await window.showQuickPick(quickPickItems, {
placeHolder: "Select PicoW Architecture",
placeHolder: l10n.t("Select PicoW Architecture"),
});
if (backgroundOrPoll === undefined) {
return projectName;
Expand Down
6 changes: 3 additions & 3 deletions src/commands/newProject.mts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CommandWithArgs } from "./command.mjs";
import Logger from "../logger.mjs";
import { window, type Uri } from "vscode";
import { window, type Uri, l10n } from "vscode";
import { NewProjectPanel } from "../webview/newProjectPanel.mjs";
// eslint-disable-next-line max-len
import { NewMicroPythonProjectPanel } from "../webview/newMicroPythonProjectPanel.mjs";
Expand Down Expand Up @@ -44,10 +44,10 @@ export default class NewProjectCommand extends CommandWithArgs {
(await window.showQuickPick(
[NewProjectCommand.cCppOption, NewProjectCommand.micropythonOption],
{
placeHolder: "Select which language to use for your new project",
placeHolder: l10n.t("Select which language to use for your new project"),

Check warning on line 47 in src/commands/newProject.mts

View workflow job for this annotation

GitHub Actions / build

This line has a length of 83. Maximum allowed is 80
canPickMany: false,
ignoreFocusOut: false,
title: "New Pico Project",
title: l10n.t("New Pico Project"),
}
));

Expand Down
13 changes: 7 additions & 6 deletions src/commands/openSdkDocumentation.mts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
window,
Uri,
type WebviewPanel,
l10n
} from "vscode";
import { readFileSync } from "fs";

Expand All @@ -18,10 +19,10 @@ export enum DocumentationId {
}

export const DOCUMENTATION_LABEL_BY_ID: string[] = [
"Hardware APIs",
"High Level APIs",
"Networking Libraries",
"Runtime Infrastructure",
l10n.t("Hardware APIs"),
l10n.t("High Level APIs"),
l10n.t("Networking Libraries"),
l10n.t("Runtime Infrastructure"),
];

// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand Down Expand Up @@ -65,7 +66,7 @@ export default class OpenSdkDocumentationCommand extends CommandWithArgs {
);

const result = await window.showQuickPick(options, {
placeHolder: "Select Category",
placeHolder: l10n.t("Select Category"),
canPickMany: false,
ignoreFocusOut: false,
});
Expand All @@ -83,7 +84,7 @@ export default class OpenSdkDocumentationCommand extends CommandWithArgs {
Logger.log("New panel");
this._panel = window.createWebviewPanel(
"pico-sdk-documentation",
"Pico SDK Documentation",
l10n.t("Pico SDK Documentation"),
{ viewColumn: ViewColumn.Two, preserveFocus: false },
{
enableScripts: true,
Expand Down
4 changes: 2 additions & 2 deletions src/commands/runProject.mts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { tasks, window } from "vscode";
import { tasks, window, l10n } from "vscode";
import { EventEmitter } from "events";
import { CommandWithResult } from "./command.mjs";
import Logger from "../logger.mjs";
Expand Down Expand Up @@ -60,7 +60,7 @@ export default class RunProjectCommand extends CommandWithResult<boolean> {
} else {
// Task not found
this._logger.error("Task 'Run Project' not found.");
void window.showErrorMessage("Task 'Run Project' not found.");
void window.showErrorMessage(l10n.t("Task {0} not found.", 'Run Project'));

Check warning on line 63 in src/commands/runProject.mts

View workflow job for this annotation

GitHub Actions / build

This line has a length of 81. Maximum allowed is 80

return false;
}
Expand Down
33 changes: 19 additions & 14 deletions src/commands/switchBoard.mts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Command } from "./command.mjs";
import Logger from "../logger.mjs";
import {
commands, ProgressLocation, window, workspace, type Uri
commands, ProgressLocation, window, workspace, type Uri, l10n
} from "vscode";
import { existsSync, readdirSync, readFileSync } from "fs";
import {
Expand Down Expand Up @@ -108,7 +108,7 @@ export default class SwitchBoardCommand extends Command {

// show quick pick for board type
const board = await window.showQuickPick(quickPickItems, {
placeHolder: "Select Board",
placeHolder: l10n.t("Select Board"),
});

if (board === undefined) {
Expand All @@ -124,8 +124,8 @@ export default class SwitchBoardCommand extends Command {
return [board, false];
}

const useRiscV = await window.showQuickPick(["No", "Yes"], {
placeHolder: "Use Risc-V?",
const useRiscV = await window.showQuickPick([l10n.t("No"), l10n.t("Yes")], {
placeHolder: l10n.t("Use Risc-V?"),
});

if (useRiscV === undefined) {
Expand Down Expand Up @@ -153,7 +153,7 @@ export default class SwitchBoardCommand extends Command {

if (versions === null) {
void window.showErrorMessage(
"Failed to get sdk version - cannot update board"
l10n.t("Failed to get sdk version - cannot update board")
);

return;
Expand All @@ -178,7 +178,9 @@ export default class SwitchBoardCommand extends Command {

if (versionBundle === undefined) {
void window.showErrorMessage(
`Cannot switch board automatically with SDK version ${versions[0]}`
l10n.t(
"Cannot switch board automatically with SDK version {0}", versions[0]
)
);

return;
Expand All @@ -196,8 +198,8 @@ export default class SwitchBoardCommand extends Command {
// internet is not required if locally cached version bundles are available
// but in this case a use shouldn't see this message
void window.showErrorMessage(
"Failed to get supported toolchain versions. " +
"Make sure you are connected to the internet."
l10n.t("Failed to get supported toolchain versions.") + " " +
l10n.t("Make sure you are connected to the internet.")
);

return;
Expand All @@ -209,7 +211,7 @@ export default class SwitchBoardCommand extends Command {

if (selectedToolchain === undefined) {
void window.showErrorMessage(
"Error switching to Risc-V toolchain"
l10n.t("Error switching to Risc-V toolchain")
);

return;
Expand All @@ -218,7 +220,7 @@ export default class SwitchBoardCommand extends Command {
await window.withProgress(
{
title:
`Installing toolchain ${selectedToolchain.version} `,
l10n.t("Installing toolchain {0}", selectedToolchain.version),
location: ProgressLocation.Notification,
},
async progress => {
Expand Down Expand Up @@ -248,7 +250,9 @@ export default class SwitchBoardCommand extends Command {

if (!cmakeUpdateResult) {
void window.showWarningMessage(
"Failed to update CMakeLists.txt for new toolchain version."
l10n.t(
"Failed to update CMakeLists.txt for new toolchain version."
)
);
}
}
Expand All @@ -260,12 +264,13 @@ export default class SwitchBoardCommand extends Command {
if (success) {
this._ui.updateBoard(board);

const reloadWindowBtn = "Reload Window";
const reloadWindowBtn = l10n.t("Reload Window");
// notify user that reloading the window is
// recommended to update intellisense
const reload = await window.showInformationMessage(
"It is recommended to reload the window to update intellisense " +
"with the new board.",
l10n.t(
"Reload the window to update intellisense with the new board."
),
reloadWindowBtn
);

Expand Down
Loading

0 comments on commit 887998e

Please sign in to comment.