Skip to content

Commit 3bac6dd

Browse files
author
Adam Butterworth
authored
Merge pull request #1 from edx/abutterworth/add-i18n-pipeline-tools
feat: add i18n pipeline tools
2 parents afe6705 + 1ab3049 commit 3bac6dd

File tree

15 files changed

+154
-11
lines changed

15 files changed

+154
-11
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33
coverage
44
dist
55
node_modules
6+
temp
7+
src/i18n/transifex_input.json

.tx/config

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[main]
2+
host = https://www.transifex.com
3+
4+
[edx-platform.frontend-component-header]
5+
file_filter = src/i18n/messages/<lang>.json
6+
source_file = src/i18n/transifex_input.json
7+
source_lang = en
8+
type = KEYVALUEJSON

Makefile

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,58 @@
1+
transifex_resource = frontend-component-header
2+
transifex_langs = "ar,fr,es_419,zh_CN"
3+
4+
transifex_utils = ./node_modules/.bin/transifex-utils.js
5+
i18n = ./src/i18n
6+
transifex_input = $(i18n)/transifex_input.json
7+
tx_url1 = https://www.transifex.com/api/2/project/edx-platform/resource/$(transifex_resource)/translation/en/strings/
8+
tx_url2 = https://www.transifex.com/api/2/project/edx-platform/resource/$(transifex_resource)/source/
9+
10+
# This directory must match .babelrc .
11+
transifex_temp = ./temp/babel-plugin-react-intl
12+
113
build:
214
rm -rf ./dist
315
./node_modules/.bin/babel src --out-dir dist --source-maps --ignore **/*.test.jsx,**/__mocks__,**/__snapshots__,**/setupTest.js --copy-files
4-
# --copy-files will bring in everything else that wasn't processed by babel. Remove what we don't want.
5-
rm -rf dist/**/*.test.jsx
6-
rm -rf dist/**/__snapshots__
7-
rm -rf dist/__mocks__
16+
@# --copy-files will bring in everything else that wasn't processed by babel. Remove what we don't want.
17+
@rm -rf dist/**/*.test.jsx
18+
@rm -rf dist/**/__snapshots__
19+
@rm -rf dist/__mocks__
20+
21+
requirements:
22+
npm install
23+
24+
i18n.extract:
25+
# Pulling display strings from .jsx files into .json files...
26+
rm -rf $(transifex_temp)
27+
npm run-script i18n_extract
28+
29+
i18n.concat:
30+
# Gathering JSON messages into one file...
31+
$(transifex_utils) $(transifex_temp) $(transifex_input)
32+
33+
extract_translations: | requirements i18n.extract i18n.concat
34+
35+
# Despite the name, we actually need this target to detect changes in the incoming translated message files as well.
36+
detect_changed_source_translations:
37+
# Checking for changed translations...
38+
git diff --exit-code $(i18n)
39+
40+
# Pushes translations to Transifex. You must run make extract_translations first.
41+
push_translations:
42+
# Pushing strings to Transifex...
43+
tx push -s
44+
# Fetching hashes from Transifex...
45+
./node_modules/reactifex/bash_scripts/get_hashed_strings.sh $(tx_url1)
46+
# Writing out comments to file...
47+
$(transifex_utils) $(transifex_temp) --comments
48+
# Pushing comments to Transifex...
49+
./node_modules/reactifex/bash_scripts/put_comments.sh $(tx_url2)
50+
51+
# Pulls translations from Transifex.
52+
pull_translations:
53+
tx pull -f --mode reviewed --language=$(transifex_langs)
54+
55+
# This target is used by Travis.
56+
validate-no-uncommitted-package-lock-changes:
57+
# Checking for package-lock.json changes...
58+
git diff --exit-code package-lock.json

README.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ frontend-component-header
33

44
|Build Status| |Codecov| |npm_version| |npm_downloads| |license| |semantic-release|
55

6-
This repository is a work in progress. Nothing found here is at all production-ready.
6+
This is the standard Open edX header for use in React applications. It has two exports:
7+
- **default**: The Header Component
8+
- **messages**: for i18n in the form of ``{ locale: { key: translatedString } }``
79

810
.. |Build Status| image:: https://api.travis-ci.org/edx/frontend-component-header.svg?branch=master-edx
911
:target: https://travis-ci.org/edx/frontend-component-header

babel.config.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@ module.exports = {
1313
'@babel/plugin-proposal-class-properties',
1414
],
1515
env: {
16+
i18n: {
17+
plugins: [
18+
[
19+
'react-intl',
20+
{
21+
messagesDir: './temp/babel-plugin-react-intl',
22+
moduleSourceName: '@edx/frontend-i18n',
23+
},
24+
],
25+
],
26+
},
1627
test: {
1728
presets: [
1829
'@babel/preset-env',

openedx.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# openedx.yaml
2+
3+
---
4+
owner: edx/fedx-team
5+
tags:
6+
- library
7+
- component
8+
- react

package-lock.json

Lines changed: 31 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"main": "dist/index.js",
99
"scripts": {
1010
"build": "make build",
11+
"i18n_extract": "BABEL_ENV=i18n babel src --quiet > /dev/null",
1112
"lint": "eslint --ext .js --ext .jsx .",
1213
"semantic-release": "semantic-release",
1314
"start": "parcel ./example/index.html --no-source-maps --out-dir example/dist",
@@ -36,11 +37,12 @@
3637
"@babel/preset-react": "^7.0.0",
3738
"@edx/frontend-analytics": "^2.0.0",
3839
"@edx/frontend-auth": "^6.0.1",
39-
"@edx/frontend-base": "^1.1.0",
40+
"@edx/frontend-base": "^1.1.1",
4041
"@edx/frontend-i18n": "^3.0.2",
4142
"@edx/frontend-logging": "^3.0.1",
4243
"@edx/paragon": "^7.1.2",
4344
"babel-eslint": "^10.0.3",
45+
"babel-plugin-react-intl": "^4.1.18",
4446
"dotenv": "^8.1.0",
4547
"enzyme": "^3.10.0",
4648
"eslint": "^6.3.0",
@@ -53,13 +55,15 @@
5355
"react-redux": "^7.1.1",
5456
"react-router-dom": "^5.0.1",
5557
"react-test-renderer": "^16.9.0",
58+
"reactifex": "^1.1.1",
5659
"redux": "^4.0.4",
5760
"redux-saga": "^1.0.5",
5861
"sass": "^1.22.12",
5962
"semantic-release": "^15.13.24"
6063
},
6164
"peerDependencies": {
62-
"@edx/frontend-base": "^1.1.0",
65+
"@edx/frontend-analytics": "^2.0.0",
66+
"@edx/frontend-base": "^1.1.1",
6367
"@edx/frontend-i18n": "^3.0.2",
6468
"prop-types": "^15.7.2",
6569
"react": "^16.9.0"

src/i18n/index.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import arMessages from './messages/ar.json';
2+
// no need to import en messages-- they are in the defaultMessage field
3+
import es419Messages from './messages/es_419.json';
4+
import frMessages from './messages/fr.json';
5+
import kokrMessages from './messages/ko_KR.json';
6+
import ptbrMessages from './messages/pt_BR.json';
7+
import zhcnMessages from './messages/zh_CN.json';
8+
9+
const messages = {
10+
ar: arMessages,
11+
'es-419': es419Messages,
12+
fr: frMessages,
13+
'zh-cn': zhcnMessages,
14+
'ko-kr': kokrMessages,
15+
'pt-br': ptbrMessages,
16+
};
17+
18+
export default messages;

src/i18n/messages/ar.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{
2+
}

0 commit comments

Comments
 (0)