Skip to content

Commit

Permalink
fix(i18n): use up-to-date i18n-concat.js
Browse files Browse the repository at this point in the history
  • Loading branch information
albemarle committed Apr 9, 2019
1 parent fa6d38f commit 0453d7f
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions src/i18n/i18n-concat.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 {
Expand Down

0 comments on commit 0453d7f

Please sign in to comment.