From a4dc1bcdf86645ea435e136845c859c61e8d2d3b Mon Sep 17 00:00:00 2001 From: David Joy Date: Fri, 7 Jun 2019 11:13:58 -0400 Subject: [PATCH] Update frontend-i18n version and use scripts. (#203) --- .babelrc | 2 +- .gitignore | 1 + Makefile | 17 +++++------ package-lock.json | 6 ++-- package.json | 2 +- src/i18n/i18n-concat.js | 63 ----------------------------------------- 6 files changed, 13 insertions(+), 78 deletions(-) delete mode 100755 src/i18n/i18n-concat.js diff --git a/.babelrc b/.babelrc index ec4eddd..3803109 100755 --- a/.babelrc +++ b/.babelrc @@ -32,7 +32,7 @@ "i18n": { "plugins": [ ["react-intl", { - "messagesDir": "./babel-plugin-react-intl-temp", + "messagesDir": "./temp/babel-plugin-react-intl", "moduleSourceName": "@edx/frontend-i18n" }] ] diff --git a/.gitignore b/.gitignore index d50c62e..c861989 100755 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ coverage dist/ src/i18n/transifex_input.json +temp/babel-plugin-react-intl ### pyenv ### .python-version diff --git a/Makefile b/Makefile index c76c4d5..3313844 100755 --- a/Makefile +++ b/Makefile @@ -1,27 +1,24 @@ -# For more details about the translation jobs, see https://github.com/edx/frontend-i18n/blob/master/docs/how_tos/i18n.rst - transifex_resource = frontend-app-profile -langs = "ar,fr,es_419,zh_CN" - -transifex_utils = ./src/i18n/i18n-concat.js +transifex_langs = "ar,fr,es_419,zh_CN" +transifex_utils = ./node_modules/.bin/transifex-utils.js transifex_input = ./src/i18n/transifex_input.json tx_url1 = https://www.transifex.com/api/2/project/edx-platform/resource/$(transifex_resource)/translation/en/strings/ tx_url2 = https://www.transifex.com/api/2/project/edx-platform/resource/$(transifex_resource)/source/ # this directory must match .babelrc -temp = ./babel-plugin-react-intl-temp +transifex_temp = ./temp/babel-plugin-react-intl requirements: npm install i18n.extract: # Pulling display strings from .jsx files into .json files... - rm -rf $(temp) + rm -rf $(transifex_temp) npm run-script i18n_extract i18n.concat: # Gathering JSON messages into one file... - $(transifex_utils) $(temp) $(transifex_input) + $(transifex_utils) $(transifex_temp) $(transifex_input) extract_translations: | requirements i18n.extract i18n.concat @@ -40,10 +37,10 @@ push_translations: # Fetching hashes from Transifex... ./node_modules/reactifex/bash_scripts/get_hashed_strings.sh $(tx_url1) # Writing out comments to file... - $(transifex_utils) $(temp) --comments + $(transifex_utils) $(transifex_temp) --comments # Pushing comments to Transifex... ./node_modules/reactifex/bash_scripts/put_comments.sh $(tx_url2) # Pull translations from Transifex pull_translations: - tx pull -f --mode reviewed --language=$(langs) + tx pull -f --mode reviewed --language=$(transifex_langs) diff --git a/package-lock.json b/package-lock.json index 50ba1e3..3bf7fbb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2619,9 +2619,9 @@ } }, "@edx/frontend-i18n": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/@edx/frontend-i18n/-/frontend-i18n-2.0.0.tgz", - "integrity": "sha512-rXhfKh6VfDqzwKGx9pm+Jmd8QKtG62mA/McGgF6jSSdwMBwlcGUSXqcxff5XckwQF5Kpzn44jR0Daf/9vED6BQ==", + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/@edx/frontend-i18n/-/frontend-i18n-2.1.0.tgz", + "integrity": "sha512-TmaxNNAFFRWT0EkRxy7gQrnnIzJuFn+HO8HOaYoO4vWJhvvfr++G+0ysgyNLuxms9CdFB1LuB64yEGupFSqcVA==", "requires": { "@cospired/i18n-iso-languages": "^2.0.2", "glob": "^7.1.4", diff --git a/package.json b/package.json index 4ee75e1..3a0549d 100755 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "@edx/frontend-auth": "^5.3.3", "@edx/frontend-component-footer": "^6.0.2", "@edx/frontend-component-site-header": "^2.2.0", - "@edx/frontend-i18n": "^2.0.0", + "@edx/frontend-i18n": "^2.1.0", "@edx/frontend-logging": "^2.0.2", "@edx/paragon": "^4.2.4", "@fortawesome/fontawesome-svg-core": "^1.2.14", diff --git a/src/i18n/i18n-concat.js b/src/i18n/i18n-concat.js deleted file mode 100755 index 255537a..0000000 --- a/src/i18n/i18n-concat.js +++ /dev/null @@ -1,63 +0,0 @@ -#!/usr/bin/env node - -/** - * See the Makefile for how the required hash file is downloaded from Transifex. - */ - -const fs = require('fs'); -const glob = require('glob'); -const path = require('path'); - -// Expected input: a directory, possibly containing subdirectories, with .json files. Each .json -// file is an array of translation triplets (id, description, defaultMessage). -function gatherJson(dir) { - const ret = []; - const files = glob.sync(`${dir}/**/*.json`); - - files.forEach((filename) => { - const messages = JSON.parse(fs.readFileSync(filename)); - ret.push(...messages); - }); - 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 loggingPrefix = path.basename(`${__filename}`); // the name of this JS file - const bashScriptsPath = './node_modules/reactifex/bash_scripts'; - - const hashFile = `${bashScriptsPath}/hashmap.json`; - process.stdout.write(`${loggingPrefix}: reading hash file ${hashFile}\n`); - const messageInfo = JSON.parse(fs.readFileSync(hashFile)); - - const outputFile = `${bashScriptsPath}/hashed_data.txt`; - process.stdout.write(`${loggingPrefix}: writing to output file ${outputFile}\n`); - fs.writeFileSync(outputFile, ''); - - messageObjects.forEach((message) => { - const transifexFormatId = escapeDots(message.id); - - const info = messageInfo.find(mi => mi.key === transifexFormatId); - if (info) { - fs.appendFileSync(outputFile, `${info.string_hash}|${message.description}\n`); - } else { - process.stdout.write(`${loggingPrefix}: string ${message.id} does not yet exist on transifex!\n`); - } - }); -} else { - const output = {}; - - messageObjects.forEach((message) => { - output[message.id] = message.defaultMessage; - }); - fs.writeFileSync(process.argv[3], JSON.stringify(output, null, 2)); -}