()
| 402 | }; |
| 403 | |
| 404 | const generateLocalizedJsonSchemaFiles = () => { |
| 405 | return es.through(function (file) { |
| 406 | let jsonTree = JSON.parse(file.contents.toString()); |
| 407 | languages.map((language) => { |
| 408 | let stringTable = {}; |
| 409 | // Try to open i18n file for this file |
| 410 | let relativePath = removePathPrefix(file.path, file.cwd); |
| 411 | let locFile = path.join("./i18n", language.folderName, relativePath + ".i18n.json"); |
| 412 | if (fs.existsSync(locFile)) { |
| 413 | stringTable = jsonc.parse(fs.readFileSync(locFile).toString()); |
| 414 | } |
| 415 | // Entire file is scanned and modified, then serialized for that language. |
| 416 | // Even if no translations are available, we still write new files to dist/schema/... |
| 417 | let keyPrefix = relativePath + "."; |
| 418 | keyPrefix = keyPrefix.replace(/\\/g, "/"); |
| 419 | let descriptionCallback = (path, value, parent) => { |
| 420 | if (stringTable[keyPrefix + path]) { |
| 421 | if (!parent.markdownDescription) |
| 422 | parent.description = stringTable[keyPrefix + path]; |
| 423 | else |
| 424 | parent.markdownDescription = stringTable[keyPrefix + path]; |
| 425 | } |
| 426 | }; |
| 427 | traverseJson(jsonTree, descriptionCallback, ""); |
| 428 | let newContent = JSON.stringify(jsonTree, null, '\t'); |
| 429 | this.queue(new vinyl({ |
| 430 | path: path.join("schema", language.id, relativePath), |
| 431 | contents: Buffer.from(newContent, 'utf8') |
| 432 | })); |
| 433 | }); |
| 434 | }); |
| 435 | }; |
| 436 | |
| 437 | // Generate localized versions of JSON schema files |
| 438 | // Check for corresponding localized json file in i18n |
no test coverage detected