Skip to content

Commit c18d6e0

Browse files
committed
Add translation generation to build.mjs
1 parent 887998e commit c18d6e0

File tree

7 files changed

+807
-340
lines changed

7 files changed

+807
-340
lines changed

l10n/bundle.l10n.json

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

l10n/bundle.l10n.qps-ploc.json

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

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@
306306
"@types/uuid": "^10.0.0",
307307
"@types/vscode": "^1.92.0",
308308
"@types/which": "^3.0.4",
309+
"@vscode/l10n-dev": "^0.0.35",
309310
"eslint": "^9.17.0",
310311
"eslint-config-prettier": "^9.1.0",
311312
"globals": "^15.9.0",

scripts/build.mjs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,47 @@
11
import { execSync } from 'child_process';
2+
import { readFileSync, readdirSync, lstatSync, writeFileSync } from 'fs';
3+
import { getL10nJson } from '@vscode/l10n-dev';
4+
import { join } from 'path';
25

36
const buildEnv = process.env.BUILD_ENV || 'production';
47
const sourcemap = buildEnv === 'production' ? 'hidden' : 'true';
58

9+
console.debug("Generating updated English translation files")
10+
11+
const files = readdirSync("./src", { recursive: true });
12+
const fileContents = files.filter(filename => lstatSync(join("./src", filename)).isFile()).map(filename => ({
13+
extension: ".ts",
14+
contents: readFileSync(join("./src", filename), 'utf8')
15+
}));
16+
console.debug(`Found ${fileContents.length} TypeScript files`);
17+
18+
const result = await getL10nJson(fileContents);
19+
console.debug(`Extracted ${Object.keys(result).length} strings`);
20+
21+
console.debug(`Writing extracted strings`);
22+
writeFileSync(join("./l10n", 'bundle.l10n.json'), JSON.stringify(result, undefined, 2));
23+
24+
console.debug("Checking other translation files for missing translations");
25+
const translations = readdirSync("./l10n").filter(filename => filename !== "bundle.l10n.json").map(filename => ({
26+
language: filename.match(/bundle\.l10n\.(.*)\.json/)[1],
27+
json: JSON.parse(readFileSync(join("./l10n", filename), 'utf8'))
28+
}));
29+
const allStrings = Object.getOwnPropertyNames(result);
30+
translations.forEach(translation => {
31+
allStrings.forEach(str => {
32+
if (!(str in translation.json)) {
33+
console.warn(`${translation.language} is missing "${str}"`);
34+
}
35+
});
36+
Object.getOwnPropertyNames(translation.json).forEach(str => {
37+
if (!(str in result)) {
38+
console.warn(`${translation.language} has extra "${str}"`);
39+
}
40+
});
41+
});
42+
43+
44+
645
console.debug("Building with:\nenvironment =", buildEnv, "\nsourcemap =", sourcemap, "(out of order, always true)");
746

847
const command = `rollup -c --environment BUILD:${buildEnv}`;

scripts/genTranslations.py

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/utils/pythonHelper.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ export default async function findPython(): Promise<string | undefined> {
121121
process.arch
122122
);
123123
void window.showErrorMessage(
124-
l10n.t("Unsupported architecture for Windows: ") + process.arch
124+
l10n.t("Unsupported architecture for Windows: {0}", process.arch)
125125
);
126126

127127
return undefined;

0 commit comments

Comments
 (0)