Skip to content

Commit 8b28709

Browse files
author
Gertjan Reynaert
committed
Merge branch 'gr-example'
2 parents b78c86e + e4c5b22 commit 8b28709

File tree

10 files changed

+156
-2
lines changed

10 files changed

+156
-2
lines changed

contributing.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,17 @@ Here are the steps required for contributing:
1313
5. Make sure eslint errors are fixed, if eslint errors don't show up in your editor you can always check them with
1414
> npm run eslint
1515
16-
6. Commit your changes according to the conventional changelog commit convention we use
17-
7. Create a pull request
16+
6. Check if everything works well by using the example application
17+
1. Create a build for the translation manager
18+
> npm run build
19+
2. Create a build for the example application
20+
> cd example
21+
22+
> npm run build
23+
3. Run the translation manager
24+
> npm run manage:translations
25+
26+
7. Commit your changes according to the conventional changelog commit convention we use
27+
8. Create a pull request
1828

1929
(If you encounter additional steps during your contribution, do not hesitate to update this document)

example/.babelrc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"presets": ["react", "es2015"],
3+
"plugins": [
4+
[
5+
"react-intl",
6+
{
7+
"messagesDir": "./src/locales/extractedMessages"
8+
}
9+
]
10+
]
11+
}

example/.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**/node_modules

example/.eslintrc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"extends": "airbnb",
3+
"parserOptions": {
4+
"ecmaVersion": 6,
5+
"sourceType": "module",
6+
"ecmaFeatures": {
7+
"jsx": true
8+
},
9+
},
10+
"env": {
11+
"mocha": true
12+
},
13+
"rules": {
14+
"arrow-parens": [2, "as-needed"],
15+
"no-multiple-empty-lines": [2, {"max": 1, "maxEOF": 1}],
16+
}
17+
}

example/index.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<meta http-equiv="x-ua-compatible" content="ie=edge">
6+
<title>React-intl-translations-manager</title>
7+
<meta name="description" content="">
8+
<meta name="viewport" content="width=device-width, initial-scale=1">
9+
</head>
10+
<body>
11+
<div id="app"></div>
12+
<script src="/dist/src.js"></script>
13+
</body>
14+
</html>

example/package.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "translation_manager_example",
3+
"version": "1.0.0",
4+
"description": "Example to test and demonstrate the usage of this plugin",
5+
"private": true,
6+
"scripts": {
7+
"build": "babel src --out-dir dist",
8+
"manage:translations": "babel-node ./translationRunner.js"
9+
},
10+
"license": "MIT",
11+
"dependencies": {
12+
"babel-cli": "^6.4.0",
13+
"babel-core": "^6.4.0",
14+
"babel-preset-es2015": "6.9.0",
15+
"babel-preset-react": "6.11.1",
16+
"babel-plugin-react-intl": "2.1.3",
17+
"eslint": "2.13.1",
18+
"eslint-config-airbnb": "9.0.1",
19+
"eslint-plugin-import": "1.10.0",
20+
"eslint-plugin-jsx-a11y": "1.5.3",
21+
"eslint-plugin-react": "5.2.2",
22+
"react": "^15.1.0",
23+
"react-dom": "^15.1.0",
24+
"react-intl": "^2.1.3"
25+
}
26+
}

example/src/Application.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React, { Component } from 'react';
2+
import ReactDOM from 'react-dom';
3+
4+
import HelloWorld from './HelloWorld';
5+
import nlMessages from './nlMessages';
6+
7+
class Application extends Component {
8+
render() {
9+
return (
10+
<IntlProvider locale="nl" messages={nlMessages}>
11+
<HelloWorld />
12+
</IntlProvider>
13+
);
14+
}
15+
}
16+
17+
ReactDOM.render(Application, document.getElementById('app'));

example/src/HelloWorld.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import React, { Component } from 'react';
2+
import { intlShape, defineMessages } from 'react-intl';
3+
4+
const t = defineMessages({
5+
helloWorld: {
6+
id: 'hello_world',
7+
description: 'A greeting to the world',
8+
defaultMessage: 'Hello {name}',
9+
},
10+
name: {
11+
id: 'hello_name',
12+
description: 'Name input field placeholder',
13+
defaultMessage: 'Your name',
14+
},
15+
});
16+
17+
class HelloWorld extends Component {
18+
constructor(props) {
19+
super(props);
20+
this.state = {
21+
name: '',
22+
};
23+
}
24+
25+
onNameChange(newName) {
26+
this.setState({ name: newName });
27+
}
28+
29+
render() {
30+
const { formatMessage } = this.context.intl;
31+
32+
return (
33+
<div>
34+
{ formatMessage(t.helloWorld, { name: this.state.name }) }
35+
<input
36+
type="text"
37+
onChange={e => this.onNameChange(e.target.value)}
38+
placeholder={formatMessage(t.name)}
39+
/>
40+
</div>
41+
);
42+
}
43+
}
44+
45+
HelloWorld.contextTypes = { intl: intlShape };
46+
47+
export default HelloWorld;

example/translationRunner.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import translationManager from '../dist/index';
2+
3+
translationManager({
4+
messagesDirectory: './src/locales/extractedMessages',
5+
translationsDirectory: './src/locales/lang/',
6+
whitelistsDirectory: './src/locales/whitelists/',
7+
languages: ['nl'],
8+
singleMessagesFile: true,
9+
});

src/createSingleMessagesFile.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Path from 'path';
22
import { writeFileSync } from 'fs';
3+
import { sync as mkdirpSync } from 'mkdirp';
34
import stringify from './stringify';
45

56
export default ({
@@ -19,6 +20,7 @@ export default ({
1920

2021
const DIR = Path.join(directory, fileName);
2122

23+
mkdirpSync(directory);
2224
writeFileSync(
2325
DIR,
2426
stringify(messages, { space: jsonSpaceIndentation, sortKeys })

0 commit comments

Comments
 (0)