Skip to content

Commit

Permalink
Add translation generation to build.mjs
Browse files Browse the repository at this point in the history
  • Loading branch information
will-v-pi committed Jan 9, 2025
1 parent fa3cba1 commit df16ef9
Show file tree
Hide file tree
Showing 7 changed files with 807 additions and 340 deletions.
298 changes: 149 additions & 149 deletions l10n/bundle.l10n.json

Large diffs are not rendered by default.

298 changes: 149 additions & 149 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 @@ -306,6 +306,7 @@
"@types/uuid": "^10.0.0",
"@types/vscode": "^1.92.0",
"@types/which": "^3.0.4",
"@vscode/l10n-dev": "^0.0.35",
"eslint": "^9.17.0",
"eslint-config-prettier": "^9.1.0",
"globals": "^15.9.0",
Expand Down
39 changes: 39 additions & 0 deletions scripts/build.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,47 @@
import { execSync } from 'child_process';
import { readFileSync, readdirSync, lstatSync, writeFileSync } from 'fs';
import { getL10nJson } from '@vscode/l10n-dev';
import { join } from 'path';

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

console.debug("Generating updated English translation files")

const files = readdirSync("./src", { recursive: true });
const fileContents = files.filter(filename => lstatSync(join("./src", filename)).isFile()).map(filename => ({
extension: ".ts",
contents: readFileSync(join("./src", filename), 'utf8')
}));
console.debug(`Found ${fileContents.length} TypeScript files`);

const result = await getL10nJson(fileContents);
console.debug(`Extracted ${Object.keys(result).length} strings`);

console.debug(`Writing extracted strings`);
writeFileSync(join("./l10n", 'bundle.l10n.json'), JSON.stringify(result, undefined, 2));

console.debug("Checking other translation files for missing translations");
const translations = readdirSync("./l10n").filter(filename => filename !== "bundle.l10n.json").map(filename => ({
language: filename.match(/bundle\.l10n\.(.*)\.json/)[1],
json: JSON.parse(readFileSync(join("./l10n", filename), 'utf8'))
}));
const allStrings = Object.getOwnPropertyNames(result);
translations.forEach(translation => {
allStrings.forEach(str => {
if (!(str in translation.json)) {
console.warn(`${translation.language} is missing "${str}"`);
}
});
Object.getOwnPropertyNames(translation.json).forEach(str => {
if (!(str in result)) {
console.warn(`${translation.language} has extra "${str}"`);
}
});
});



console.debug("Building with:\nenvironment =", buildEnv, "\nsourcemap =", sourcemap, "(out of order, always true)");

const command = `rollup -c --environment BUILD:${buildEnv}`;
Expand Down
23 changes: 0 additions & 23 deletions scripts/genTranslations.py

This file was deleted.

2 changes: 1 addition & 1 deletion src/utils/pythonHelper.mts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export default async function findPython(): Promise<string | undefined> {
process.arch
);
void window.showErrorMessage(
l10n.t("Unsupported architecture for Windows: ") + process.arch
l10n.t("Unsupported architecture for Windows: {0}", process.arch)
);

return undefined;
Expand Down
Loading

0 comments on commit df16ef9

Please sign in to comment.