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

Commit

Permalink
Add support for localization in extension (#24)
Browse files Browse the repository at this point in the history
PBI: 29016
Task: 29017, 29018
  • Loading branch information
LukeSlev authored Jun 25, 2019
1 parent afdef2a commit 6dde19f
Show file tree
Hide file tree
Showing 10 changed files with 2,161 additions and 86 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

# Compiled JS code
out/
!locales/**/out/
package.nls.*.json

# User-specific files
*.suo
Expand Down
37 changes: 21 additions & 16 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
{
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "watch",
"problemMatcher": "$tsc-watch",
"isBackground": true,
"presentation": {
"reveal": "never"
},
"group": {
"kind": "build",
"isDefault": true
}
}
]
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "watch",
"problemMatcher": "$tsc-watch",
"isBackground": true,
"presentation": {
"reveal": "never"
},
"group": {
"kind": "build",
"isDefault": true
}
},
{
"type": "gulp",
"task": "add-locales",
"problemMatcher": []
}
]
}
127 changes: 127 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

const gulp = require("gulp");

const ts = require("gulp-typescript");
const sourcemaps = require("gulp-sourcemaps");
const typescript = require("typescript");
const del = require("del");
const es = require("event-stream");
const vsce = require("vsce");
const nls = require("vscode-nls-dev");

const tsProject = ts.createProject("./tsconfig.json", { typescript });

const inlineMap = true;
const inlineSource = false;
const outDest = "out";

// A list of all locales supported by VSCode can be found here: https://code.visualstudio.com/docs/getstarted/locales
const languages = [{ folderName: "en", id: "en" }];

gulp.task("clean", () => {
return del(
["out/**", "package.nls.*.json", "../../dist/*0.0.0-UNTRACKEDVERSION.vsix"],
{ force: true }
);
});

const pythonToMove = ["./src/adafruit_circuitplayground/*.*", "./src/*.py"];

gulp.task("python-compile", () => {
// the base option sets the relative root for the set of files,
// preserving the folder structure
return gulp.src(pythonToMove, { base: "./src/" }).pipe(gulp.dest("out"));
});

gulp.task("internal-compile", () => {
return compile(false);
});

gulp.task("internal-nls-compile", () => {
return compile(true);
});

gulp.task("add-locales", () => {
return gulp
.src(["package.nls.json"])
.pipe(nls.createAdditionalLanguageFiles(languages, "locales"))
.pipe(gulp.dest("."));
});

gulp.task("vsce:publish", () => {
return vsce.publish();
});

gulp.task("vsce:package", () => {
return vsce.createVSIX({
packagePath: "../../dist/pacifica-0.0.0-UNTRACKEDVERSION.vsix"
});
});

gulp.task(
"compile",
gulp.series("clean", "internal-compile", "python-compile", callback => {
callback();
})
);

gulp.task(
"build",
gulp.series(
"clean",
"internal-nls-compile",
"python-compile",
"add-locales",
callback => {
callback();
}
)
);

gulp.task(
"publish",
gulp.series("compile", "vsce:publish", callback => {
callback();
})
);

gulp.task(
"package",
gulp.series("compile", "vsce:package", callback => {
callback();
})
);

//---- internal

function compile(buildNls) {
var r = tsProject
.src()
.pipe(sourcemaps.init())
.pipe(tsProject())
.js.pipe(buildNls ? nls.rewriteLocalizeCalls() : es.through())
.pipe(
buildNls
? nls.createAdditionalLanguageFiles(languages, "locales", "out")
: es.through()
);

if (inlineMap && inlineSource) {
r = r.pipe(sourcemaps.write());
} else {
r = r.pipe(
sourcemaps.write("../out", {
// no inlined source
includeContent: inlineSource,
// Return relative source map root directories per file.
sourceRoot: "../src"
})
);
}

return r.pipe(gulp.dest(outDest));
}
10 changes: 10 additions & 0 deletions locales/en/out/constants.i18n.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"error.stderr": "[ERROR] {0} \n",
"error.unexpectedMessage": "Webview sent an unexpected message",
"info.deployOutput": "\n[INFO] Deploying code to the simulator...\n",
"info.extensionActivated": "Congratulations, your extension Adafruit_Simulator is now active!",
"info.runningCode": "Running user code",
"info.welcomeOutputTab": "Welcome to the Adafruit Simulator output tab !\n\n",
"label.webviewPanel": "Adafruit CPX",
"name": "Adafruit Simulator"
}
5 changes: 5 additions & 0 deletions locales/en/package.i18n.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"pacificaExtension.commands.label": "Adafruit",
"pacificaExtension.commands.openSimulator": "Open Simulator",
"pacificaExtension.commands.runSimulator": "Run Simulator"
}
Loading

0 comments on commit 6dde19f

Please sign in to comment.