From 0453d7fbaaf72393d329528960d17529f27df5aa Mon Sep 17 00:00:00 2001 From: albemarle <45690905+albemarle@users.noreply.github.com> Date: Tue, 9 Apr 2019 15:33:55 -0400 Subject: [PATCH] fix(i18n): use up-to-date i18n-concat.js --- src/i18n/i18n-concat.js | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/src/i18n/i18n-concat.js b/src/i18n/i18n-concat.js index 0ac0aa98..33c03e90 100755 --- a/src/i18n/i18n-concat.js +++ b/src/i18n/i18n-concat.js @@ -1,7 +1,7 @@ #!/usr/bin/env node + /** - * This code originally came from https://github.com/efischer19/reactifex/blob/master/main.js, - * which should be edx/reactifex. It is temporarily being copied here until we find it a new home. + * See the Makefile for how the required hash file is downloaded from Transifex. */ // NOTE: This script is called from Jenkins using devDependencies, so eslint is being @@ -23,28 +23,36 @@ function gatherJson(dir) { return ret; } +// the hash file returns ids whose periods are "escaped" (sort of), like this: +// "key": "profile\\.sociallinks\\.social\\.links" +// so our regular messageIds won't match them out of the box +function escapeDots(messageId) { + return messageId.replace(/\./g, '\\.'); +} + const jsonDir = process.argv[2]; const messageObjects = gatherJson(jsonDir); if (process.argv[3] === '--comments') { // prepare to handle the translator notes - const thisFile = path.basename(`${__filename}`); + const loggingPrefix = path.basename(`${__filename}`); // the name of this JS file const bashScriptsPath = './node_modules/reactifex/bash_scripts'; - process.stdout.write(`${thisFile}: generating bash scripts...\n`); - process.stdout.write(`${thisFile}: info file at ${bashScriptsPath}/hashmap.json\n`); + const hashFile = `${bashScriptsPath}/hashmap.json`; + process.stdout.write(`${loggingPrefix}: reading hash file ${hashFile}\n`); + const messageInfo = JSON.parse(fs.readFileSync(hashFile)); - const messageInfo = JSON.parse(fs.readFileSync(`${bashScriptsPath}/hashmap.json`)); - const dataPath = `${bashScriptsPath}/hashed_data.txt`; - - process.stdout.write(`${thisFile}: data path is ${dataPath}\n`); - fs.writeFileSync(dataPath, ''); + const outputFile = `${bashScriptsPath}/hashed_data.txt`; + process.stdout.write(`${loggingPrefix}: writing to output file ${outputFile}\n`); + fs.writeFileSync(outputFile, ''); messageObjects.forEach((message) => { - const info = messageInfo.find(mi => mi.key === message.id); + const transifexFormatId = escapeDots(message.id); + + const info = messageInfo.find(mi => mi.key === transifexFormatId); if (info) { - fs.appendFileSync(dataPath, `${info.string_hash}|${message.description}\n`); + fs.appendFileSync(outputFile, `${info.string_hash}|${message.description}\n`); } else { - process.stdout.write(`${thisFile}: string ${message.id} does not yet exist on transifex!\n`); + process.stdout.write(`${loggingPrefix}: string ${message.id} does not yet exist on transifex!\n`); } }); } else {