Update frontend-i18n version and use scripts. (#203)
This commit is contained in:
2
.babelrc
2
.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"
|
||||
}]
|
||||
]
|
||||
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -7,6 +7,7 @@ coverage
|
||||
|
||||
dist/
|
||||
src/i18n/transifex_input.json
|
||||
temp/babel-plugin-react-intl
|
||||
|
||||
### pyenv ###
|
||||
.python-version
|
||||
|
||||
17
Makefile
17
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)
|
||||
|
||||
6
package-lock.json
generated
6
package-lock.json
generated
@@ -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",
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
Reference in New Issue
Block a user