|
1 | 1 | 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'; |
2 | 5 |
|
3 | 6 | const buildEnv = process.env.BUILD_ENV || 'production'; |
4 | 7 | const sourcemap = buildEnv === 'production' ? 'hidden' : 'true'; |
5 | 8 |
|
| 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 | + |
6 | 45 | console.debug("Building with:\nenvironment =", buildEnv, "\nsourcemap =", sourcemap, "(out of order, always true)"); |
7 | 46 |
|
8 | 47 | const command = `rollup -c --environment BUILD:${buildEnv}`; |
|
0 commit comments