Skip to content
This repository was archived by the owner on Dec 23, 2021. It is now read-only.

Commit 6dde19f

Browse files
authored
Add support for localization in extension (#24)
PBI: 29016 Task: 29017, 29018
1 parent afdef2a commit 6dde19f

10 files changed

Lines changed: 2161 additions & 86 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
# Compiled JS code
77
out/
8+
!locales/**/out/
9+
package.nls.*.json
810

911
# User-specific files
1012
*.suo

.vscode/tasks.json

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
11
// See https://go.microsoft.com/fwlink/?LinkId=733558
22
// for the documentation about the tasks.json format
33
{
4-
"version": "2.0.0",
5-
"tasks": [
6-
{
7-
"type": "npm",
8-
"script": "watch",
9-
"problemMatcher": "$tsc-watch",
10-
"isBackground": true,
11-
"presentation": {
12-
"reveal": "never"
13-
},
14-
"group": {
15-
"kind": "build",
16-
"isDefault": true
17-
}
18-
}
19-
]
4+
"version": "2.0.0",
5+
"tasks": [
6+
{
7+
"type": "npm",
8+
"script": "watch",
9+
"problemMatcher": "$tsc-watch",
10+
"isBackground": true,
11+
"presentation": {
12+
"reveal": "never"
13+
},
14+
"group": {
15+
"kind": "build",
16+
"isDefault": true
17+
}
18+
},
19+
{
20+
"type": "gulp",
21+
"task": "add-locales",
22+
"problemMatcher": []
23+
}
24+
]
2025
}

gulpfile.js

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
const gulp = require("gulp");
7+
8+
const ts = require("gulp-typescript");
9+
const sourcemaps = require("gulp-sourcemaps");
10+
const typescript = require("typescript");
11+
const del = require("del");
12+
const es = require("event-stream");
13+
const vsce = require("vsce");
14+
const nls = require("vscode-nls-dev");
15+
16+
const tsProject = ts.createProject("./tsconfig.json", { typescript });
17+
18+
const inlineMap = true;
19+
const inlineSource = false;
20+
const outDest = "out";
21+
22+
// A list of all locales supported by VSCode can be found here: https://code.visualstudio.com/docs/getstarted/locales
23+
const languages = [{ folderName: "en", id: "en" }];
24+
25+
gulp.task("clean", () => {
26+
return del(
27+
["out/**", "package.nls.*.json", "../../dist/*0.0.0-UNTRACKEDVERSION.vsix"],
28+
{ force: true }
29+
);
30+
});
31+
32+
const pythonToMove = ["./src/adafruit_circuitplayground/*.*", "./src/*.py"];
33+
34+
gulp.task("python-compile", () => {
35+
// the base option sets the relative root for the set of files,
36+
// preserving the folder structure
37+
return gulp.src(pythonToMove, { base: "./src/" }).pipe(gulp.dest("out"));
38+
});
39+
40+
gulp.task("internal-compile", () => {
41+
return compile(false);
42+
});
43+
44+
gulp.task("internal-nls-compile", () => {
45+
return compile(true);
46+
});
47+
48+
gulp.task("add-locales", () => {
49+
return gulp
50+
.src(["package.nls.json"])
51+
.pipe(nls.createAdditionalLanguageFiles(languages, "locales"))
52+
.pipe(gulp.dest("."));
53+
});
54+
55+
gulp.task("vsce:publish", () => {
56+
return vsce.publish();
57+
});
58+
59+
gulp.task("vsce:package", () => {
60+
return vsce.createVSIX({
61+
packagePath: "../../dist/pacifica-0.0.0-UNTRACKEDVERSION.vsix"
62+
});
63+
});
64+
65+
gulp.task(
66+
"compile",
67+
gulp.series("clean", "internal-compile", "python-compile", callback => {
68+
callback();
69+
})
70+
);
71+
72+
gulp.task(
73+
"build",
74+
gulp.series(
75+
"clean",
76+
"internal-nls-compile",
77+
"python-compile",
78+
"add-locales",
79+
callback => {
80+
callback();
81+
}
82+
)
83+
);
84+
85+
gulp.task(
86+
"publish",
87+
gulp.series("compile", "vsce:publish", callback => {
88+
callback();
89+
})
90+
);
91+
92+
gulp.task(
93+
"package",
94+
gulp.series("compile", "vsce:package", callback => {
95+
callback();
96+
})
97+
);
98+
99+
//---- internal
100+
101+
function compile(buildNls) {
102+
var r = tsProject
103+
.src()
104+
.pipe(sourcemaps.init())
105+
.pipe(tsProject())
106+
.js.pipe(buildNls ? nls.rewriteLocalizeCalls() : es.through())
107+
.pipe(
108+
buildNls
109+
? nls.createAdditionalLanguageFiles(languages, "locales", "out")
110+
: es.through()
111+
);
112+
113+
if (inlineMap && inlineSource) {
114+
r = r.pipe(sourcemaps.write());
115+
} else {
116+
r = r.pipe(
117+
sourcemaps.write("../out", {
118+
// no inlined source
119+
includeContent: inlineSource,
120+
// Return relative source map root directories per file.
121+
sourceRoot: "../src"
122+
})
123+
);
124+
}
125+
126+
return r.pipe(gulp.dest(outDest));
127+
}

locales/en/out/constants.i18n.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"error.stderr": "[ERROR] {0} \n",
3+
"error.unexpectedMessage": "Webview sent an unexpected message",
4+
"info.deployOutput": "\n[INFO] Deploying code to the simulator...\n",
5+
"info.extensionActivated": "Congratulations, your extension Adafruit_Simulator is now active!",
6+
"info.runningCode": "Running user code",
7+
"info.welcomeOutputTab": "Welcome to the Adafruit Simulator output tab !\n\n",
8+
"label.webviewPanel": "Adafruit CPX",
9+
"name": "Adafruit Simulator"
10+
}

locales/en/package.i18n.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"pacificaExtension.commands.label": "Adafruit",
3+
"pacificaExtension.commands.openSimulator": "Open Simulator",
4+
"pacificaExtension.commands.runSimulator": "Run Simulator"
5+
}

0 commit comments

Comments
 (0)