microsoft/vscode-react-native
Publicmirrored fromhttps://github.com/microsoft/vscode-react-nativeAvailable
gulp_scripts/translator.js
87lines · modecode
| 1 | const gulp = require("gulp"); |
| 2 | const log = require("fancy-log"); |
| 3 | const path = require("path"); |
| 4 | const nls = require("vscode-nls-dev"); |
| 5 | const es = require("event-stream"); |
| 6 | const minimist = require("minimist"); |
| 7 | |
| 8 | const getBuilder = require(appRoot + "/gulp_scripts/builder"); |
| 9 | |
| 10 | /** |
| 11 | * Whether we're running a nightly build. |
| 12 | */ |
| 13 | const isNightly = process.argv.includes("--nightly"); |
| 14 | |
| 15 | const fullExtensionName = isNightly |
| 16 | ? "msjsdiag.vscode-react-native-preview" |
| 17 | : "msjsdiag.vscode-react-native"; |
| 18 | |
| 19 | const translationProjectName = "vscode-extensions"; |
| 20 | |
| 21 | const defaultLanguages = [ |
| 22 | { id: "zh-tw", folderName: "cht", transifexId: "zh-hant" }, |
| 23 | { id: "zh-cn", folderName: "chs", transifexId: "zh-hans" }, |
| 24 | { id: "ja", folderName: "jpn" }, |
| 25 | { id: "ko", folderName: "kor" }, |
| 26 | { id: "de", folderName: "deu" }, |
| 27 | { id: "fr", folderName: "fra" }, |
| 28 | { id: "es", folderName: "esn" }, |
| 29 | { id: "ru", folderName: "rus" }, |
| 30 | { id: "it", folderName: "ita" }, |
| 31 | |
| 32 | // These language-pack languages are included for VS but excluded from the vscode package |
| 33 | { id: "cs", folderName: "csy" }, |
| 34 | { id: "tr", folderName: "trk" }, |
| 35 | { id: "pt-br", folderName: "ptb", transifexId: "pt-BR" }, |
| 36 | { id: "pl", folderName: "plk" }, |
| 37 | ]; |
| 38 | |
| 39 | function addi18n() { |
| 40 | return gulp |
| 41 | .src(["package.nls.json"]) |
| 42 | .pipe(nls.createAdditionalLanguageFiles(defaultLanguages, "i18n")) |
| 43 | .pipe(gulp.dest(".")); |
| 44 | } |
| 45 | |
| 46 | const translationsExport = gulp.series(getBuilder.buildTask, function runTranslationExport() { |
| 47 | return gulp |
| 48 | .src(["package.nls.json", "nls.metadata.header.json", "nls.metadata.json"]) |
| 49 | .pipe(nls.createXlfFiles(translationProjectName, fullExtensionName)) |
| 50 | .pipe(gulp.dest(path.join("..", `${translationProjectName}-localization-export`))); |
| 51 | }); |
| 52 | |
| 53 | const translationImport = gulp.series(done => { |
| 54 | var options = minimist(process.argv.slice(2), { |
| 55 | string: "location", |
| 56 | default: { |
| 57 | location: "../vscode-translations-import", |
| 58 | }, |
| 59 | }); |
| 60 | es.merge( |
| 61 | defaultLanguages.map(language => { |
| 62 | let id = language.transifexId || language.id; |
| 63 | log(path.join(options.location, id, "vscode-extensions", `${fullExtensionName}.xlf`)); |
| 64 | return gulp |
| 65 | .src( |
| 66 | path.join( |
| 67 | options.location, |
| 68 | id, |
| 69 | "vscode-extensions", |
| 70 | `${fullExtensionName}.xlf`, |
| 71 | ), |
| 72 | ) |
| 73 | .pipe(nls.prepareJsonFiles()) |
| 74 | .pipe(gulp.dest(path.join("./i18n", language.folderName))); |
| 75 | }), |
| 76 | ).pipe( |
| 77 | es.wait(() => { |
| 78 | done(); |
| 79 | }), |
| 80 | ); |
| 81 | }, addi18n); |
| 82 | |
| 83 | module.exports = { |
| 84 | addi18n, |
| 85 | translationImport, |
| 86 | translationsExport, |
| 87 | }; |
| 88 | |