Skip to content
Snippets Groups Projects
Commit 9d91faa5 authored by chrisgarrity's avatar chrisgarrity Committed by GitHub
Browse files

Merge pull request #515 from chrisgarrity/gh507-generate-l10n

Gh507 generate l10n
parents 809661f0 7e64c897
No related branches found
No related tags found
No related merge requests found
{
"plugins": [
"transform-object-rest-spread",
["react-intl", {
"messagesDir": "./translations/messages/"
}]],
"presets": ["es2015", "react"]
}
......@@ -12,3 +12,6 @@ npm-*
# Build
/build
/.opt-in
# generated/external transifex translation files per language
/translations
......@@ -7,6 +7,7 @@
"build": "npm run clean && webpack --progress --colors --bail",
"clean": "rimraf ./build && mkdirp build",
"deploy": "touch build/.nojekyll && gh-pages -t -d build -m \"Build for $(git log --pretty=format:%H -n1)\"",
"i18n:src": "babel src > tmp.js && rimraf tmp.js && ./scripts/build-i18n-source.js ./translations/messages/ ./translations/",
"lint": "eslint . --ext .js,.jsx",
"start": "webpack-dev-server",
"test": "npm run lint && npm run build",
......@@ -25,9 +26,11 @@
},
"devDependencies": {
"autoprefixer": "7.1.2",
"babel-cli": "6.24.1",
"babel-core": "^6.23.1",
"babel-eslint": "^7.1.1",
"babel-loader": "^7.0.0",
"babel-plugin-react-intl": "2.3.1",
"babel-plugin-transform-object-rest-spread": "^6.22.0",
"babel-preset-es2015": "^6.22.0",
"babel-preset-react": "^6.22.0",
......@@ -55,8 +58,8 @@
"react": "15.5.4",
"react-dom": "15.5.4",
"react-draggable": "2.2.6",
"react-modal": "2.2.1",
"react-intl": "2.3.0",
"react-modal": "2.2.1",
"react-redux": "5.0.5",
"react-style-proptype": "3.0.0",
"react-tabs": "1.1.0",
......
#!/usr/bin/env node
const fs = require('fs');
const glob = require('glob');
const path = require('path');
const mkdirp = require('mkdirp');
var args = process.argv.slice(2);
if (!args.length) {
process.stdout.write('You must specify the messages dir generated by babel-plugin-react-intl.\n');
process.exit(1);
}
const MESSAGES_PATTERN = args.shift() + '/**/*.json';
if (!args.length) {
process.stdout.write('A destination directory must be specified.\n');
process.exit(1);
}
const LANG_DIR = args.shift();
// Aggregates the default messages that were extracted from the example app's
// React components via the React Intl Babel plugin. An error will be thrown if
// there are messages in different components that use the same `id`. The result
// is a chromei18n format collection of `id: {message: defaultMessage,
// description: description}` pairs for the app's default locale.
let defaultMessages = glob.sync(MESSAGES_PATTERN)
.map((filename) => fs.readFileSync(filename, 'utf8'))
.map((file) => JSON.parse(file))
.reduce((collection, descriptors) => {
descriptors.forEach(({id, defaultMessage, description}) => {
if (collection.hasOwnProperty(id)) {
throw new Error(`Duplicate message id: ${id}`);
}
collection[id] = {message: defaultMessage, description: description};
});
return collection;
}, {});
mkdirp.sync(LANG_DIR);
fs.writeFileSync(path.join(LANG_DIR, 'en.json'), JSON.stringify(defaultMessages, null, 2));
......@@ -35,7 +35,11 @@ module.exports = {
loader: 'babel-loader',
include: path.resolve(__dirname, 'src'),
options: {
plugins: ['transform-object-rest-spread'],
plugins: [
'transform-object-rest-spread',
['react-intl', {
messagesDir: './translations/messages/'
}]],
presets: ['es2015', 'react']
}
},
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment