Skip to content

Commit

Permalink
feat: initial localization of footer
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Now requires containing app to use `react-intl`. See
update to README for details.

ARCH-460
  • Loading branch information
robrap committed Mar 20, 2019
1 parent 349a458 commit 8f35487
Show file tree
Hide file tree
Showing 14 changed files with 870 additions and 239 deletions.
49 changes: 16 additions & 33 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,43 +1,26 @@
{
"presets": [
["env", {
"targets": {
"browsers": ["last 2 versions", "ie 11"]
}
}],
"babel-preset-react"
],
"plugins": [
"transform-object-rest-spread"
],
"env": {
"development": {
"presets": [
["env", {
"targets": {
"browsers": ["last 2 versions", "ie 11"]
}
}],
"babel-preset-react"
],
"plugins": [
"transform-object-rest-spread"
]
},
"test": {
"presets": [
["env", {
"targets": {
"browsers": ["last 2 versions", "ie 11"]
}
}],
"babel-preset-react"
],
"plugins": [
"rewire",
"transform-object-rest-spread"
"rewire"
]
},
"production": {
"presets": [
["env", {
"targets": {
"browsers": ["last 2 versions", "ie 11"]
}
}],
"babel-preset-react"
],
"i18n": {
"plugins": [
"transform-object-rest-spread"
["react-intl", {
"messagesDir": "./temp"
}]
]
}
}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
coverage
dist
node_modules
temp

.idea/
8 changes: 8 additions & 0 deletions .tx/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[main]
host = https://www.transifex.com

[edx-platform.frontend-component-footer]
file_filter = "src/i18n/messages/<lang>.json"
source_file = "src/i18n/transifex_input.json"
source_lang = en
type = KEYVALUEJSON
36 changes: 36 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
extract_translations: ## no prerequisites so we can control order of operations
echo "We have to define this target due to tooling assumptions"
echo "Also we have to npm install using this hook b/c there's no other place for it in the current setup"
npm install
npm run-script i18n_extract

i18n.extract:
# Pulling display strings from .jsx files into .json files...
npm run-script i18n_extract

i18n.concat:
# Gathering JSON messages into one file...
./src/i18n/i18n-concat.js ./temp/src ./src/i18n/transifex_input.json

i18n.pre_validate: | i18n.extract i18n.concat
git diff --exit-code ./src/i18n/transifex_input.json

tx_url1 = https://www.transifex.com/api/2/project/edx-platform/resource/frontend-component-footer/translation/en/strings/
tx_url2 = https://www.transifex.com/api/2/project/edx-platform/resource/frontend-component-footer/source/

# push translations to Transifex, doing magic so we can include the translator comments
push_translations: | i18n.extract
# Adding translator comments...
# Fetching strings from Transifex...
./node_modules/reactifex/bash_scripts/get_hashed_strings.sh $(tx_url1)
# Writing out comments to file...
./src/i18n/i18n-concat.js ./temp/src --comments
# Adding comments to Transifex...
./node_modules/reactifex/bash_scripts/put_comments.sh $(tx_url2)

# pull translations from Transifex
pull_translations: ## must be exactly this name for edx tooling support, see ecommerce-scripts/transifex/pull.py
tx pull -f --mode reviewed --language="ar,fr,es_419,zh_CN"

validate-no-uncommitted-package-lock-changes:
git diff --exit-code package-lock.json
10 changes: 7 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ frontend-component-footer
frontend-component-footer is a library containing a site footer
component for use when building edX frontend applications.

At this time, this componenet is hard-coded to match the legacy LMS site footer, including all of its links.
Note: As implemented, it should really be called the ``frontend-component-lms-footer``.
At this time, this component is hard-coded to match the legacy LMS site footer, including all of its links. As implemented, this component should probably be called the ``frontend-component-lms-footer``.

Usage
-----
Expand All @@ -18,9 +17,14 @@ To install frontend-component-footer into your project::
npm i --save @edx/frontend-component-footer

The component expects properties specifying the various URLs that are
linked in the footer. See the sample app in src/index.jsx for an example
linked in the footer. See the sample app in `src/index.jsx <src/index.jsx>`__ for an example
of how the SiteFooter component can be specified.

Requirements
------------

This component uses ``react-intl``. Any containing app must provide ``react-intl`` as a peer dependency, and be wrapped inside an ``IntlProvider`` element, whether or not your consuming application is actually localized. For a basic default locale (English) version, follow the ``IntlProvider`` example in the sample application in `src/index.jsx <src/index.jsx>`__.

Development
-----------

Expand Down
83 changes: 83 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"gc": "commit",
"commitmsg": "commitlint -e $GIT_PARAMS",
"coveralls": "cat ./coverage/lcov.info | coveralls",
"i18n_extract": "BABEL_ENV=i18n babel src --quiet > /dev/null",
"lint": "eslint --ext .js --ext .jsx .",
"precommit": "npm run lint",
"prepublishOnly": "npm run build",
Expand All @@ -37,33 +38,37 @@
"@commitlint/config-angular": "^6.0.2",
"@commitlint/prompt": "^6.0.2",
"@commitlint/prompt-cli": "^6.0.2",
"@edx/paragon": "^3.8.0",
"babel-cli": "^6.26.0",
"babel-core": "^6.26.3",
"babel-loader": "^7.1.5",
"babel-plugin-react-intl": "^3.0.1",
"babel-plugin-rewire": "^1.2.0",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-preset-env": "^1.7.0",
"babel-preset-react": "^6.24.1",
"clean-webpack-plugin": "^0.1.19",
"coveralls": "^3.0.0",
"css-loader": "^0.28.9",
"@edx/paragon": "^3.8.0",
"enzyme": "^3.3.0",
"enzyme-adapter-react-16": "^1.1.1",
"eslint": "^5.2.0",
"eslint-config-edx": "^4.0.4",
"eslint-plugin-jsx-a11y": "^6.1.2",
"file-loader": "^1.1.9",
"glob": "^7.1.3",
"html-webpack-plugin": "^3.2.0",
"image-webpack-loader": "^4.2.0",
"husky": "^0.14.3",
"image-webpack-loader": "^4.2.0",
"jest": "23.6.0",
"node-sass": "^4.7.2",
"prop-types": "^15.5.10",
"react": "^16.4.2",
"react-dom": "^16.2.0",
"react-dev-utils": "^5.0.0",
"react-dom": "^16.2.0",
"react-intl": "^2.8.0",
"react-test-renderer": "^16.6.0",
"reactifex": "^1.1.1",
"sass-loader": "^6.0.6",
"semantic-release": "^15.1.7",
"source-map-loader": "^0.2.1",
Expand All @@ -82,6 +87,7 @@
"prop-types": "^15.5.10",
"react": "^16.4.2",
"react-dom": "^16.2.0",
"react-intl": "2.x",
"webpack": "^4.19.1",
"webpack-merge": "^4.2.1"
},
Expand Down
57 changes: 57 additions & 0 deletions src/i18n/i18n-concat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/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.
*/

// NOTE: This script is called from Jenkins using devDependencies, so eslint is being
// disabled so it doesn't force you to make these real dependencies.
const fs = require('fs'); // eslint-disable-line import/no-extraneous-dependencies
const glob = require('glob'); // eslint-disable-line import/no-extraneous-dependencies
const path = require('path'); // eslint-disable-line import/no-extraneous-dependencies

// 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;
}

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 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 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, '');

messageObjects.forEach((message) => {
const info = messageInfo.find(mi => mi.key === message.id);
if (info) {
fs.appendFileSync(dataPath, `${info.string_hash}|${message.description}\n`);
} else {
process.stdout.write(`${thisFile}: 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));
}
Loading

0 comments on commit 8f35487

Please sign in to comment.