Skip to content
This repository was archived by the owner on Jan 10, 2024. It is now read-only.

Commit 0a5da3b

Browse files
Merge pull request #8 from eugene-manuilov/release/0.3.2
Release/0.3.2
2 parents e1d938a + e378b31 commit 0a5da3b

File tree

23 files changed

+8345
-4
lines changed

23 files changed

+8345
-4
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22
/node_modules/
33
/lib/
44
/dist/
5-
/npm-debug.log
5+
/npm-debug.log
6+
/examples/poedit/node_modules/
7+
/examples/poedit/**/*.mo

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Change Log
22

3+
## v0.3.2 (2017-08-04)
4+
5+
**Implemented enhancements:**
6+
7+
- Added a sample application which shows how to use Poedit and React/React-Router conjunction to make translatable applications.
8+
- Added ability to import Textdomain component directly.
9+
310
## v0.3.1 (2017-06-28)
411

512
**Fixed issues:**

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# react-gettext 0.3.1
1+
# react-gettext 0.3.2
22

33
[![Build Status](https://travis-ci.org/eugene-manuilov/react-gettext.svg?branch=master)](https://travis-ci.org/eugene-manuilov/react-gettext)
44

@@ -100,6 +100,8 @@ After doing it you can start using `gettext`, `ngettext`, `xgettext` and `nxgett
100100
+ };
101101
```
102102

103+
See an [example](https://github.com/eugene-manuilov/react-gettext/tree/master/examples) application to get better understanding how to use it.
104+
103105
## Documentation
104106

105107
### withGettext(translations, pluralForms)
@@ -158,6 +160,8 @@ const HOC = withGettext()(App);
158160
ReactDOM.render(<HOC translations={getTranslations} plural={getPluralForms}>...</HOC>, ...);
159161
```
160162

163+
One more alternative is to not create HOC, but use Textdomain component directly. You can import it using `import { Textdomain } from 'react-gettext'` and use it as a regular component which will provide context functions to translate your messages. Just don't forget to pass `translations` and `plural` props to this component when you render it.
164+
161165

162166
### gettext(message)
163167

__tests__/hoc.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Component } from 'react';
22
import PropTypes from 'prop-types';
33
import faker from 'faker';
44

5-
import withGettext from '../lib/index';
5+
import withGettext, { Textdomain } from '../lib/index';
66

77
describe('Higher-order-component', () => {
88
class baseComponent extends Component {
@@ -41,3 +41,9 @@ describe('Higher-order-component', () => {
4141
expect(instance.getPluralForm(5)).toBe(2);
4242
});
4343
});
44+
45+
describe('Textdomain', () => {
46+
test('named export', () => {
47+
expect(typeof Textdomain).toBe('function');
48+
});
49+
});

examples/poedit/.eslintrc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"extends": "airbnb",
3+
"rules": {
4+
"import/no-dynamic-require": 0,
5+
"global-require": 0,
6+
"max-len": 0,
7+
"no-tabs": 0,
8+
"indent": [2, "tab", { "SwitchCase": 1 }],
9+
"react/jsx-indent": [2, "tab"],
10+
"react/jsx-filename-extension": 0
11+
},
12+
"globals": {
13+
"document": false
14+
}
15+
}

examples/poedit/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Poedit example
2+
3+
This example uses POT, PO and MO files generated by Poedit to collect and translate static copies in the React components. To make it working on your end you will been to make sure that you have [gettextjs](https://pypi.python.org/pypi/gettextjs) (python package) installed on your computer. To do it you will need to run following command:
4+
5+
```
6+
pip3 install gettextjs
7+
```
8+
9+
## Start example
10+
11+
To launch this example on your computer, you will need to install all dependencies by running `npm i` in the example root folder and then start local dev server by running `npm start` command. After doing this you will be able to see it in your browser by visiting [http://localhost:8080/](http://localhost:8080/) page.
12+
13+
## Translations workflow with Poedit
14+
15+
Whenever you make a change in your static copy inside of your React components, you will need to update your po files and translations in it. You can find all po files in the `languages/LC_MESSAGES` directory. Use [Poedit](https://poedit.net/) application to work with po files on your computer.
16+
17+
Once you finish updating your translations, you need to generate json files from mo files created by Poedit. To do it you will need to run `gettextjs --json ./ ./src/` command and it will convert all mo files into json files. Restart your local dev server and your translations will appear in your browser.
18+
19+
There are two commands in the package.json file which you can use to generate mo files from po files and to generate json files from mo files. It is `gettext:compile` and `gettext:convert` which you can run using npm: `npm run gettext:compile` and `npm run gettext:convert`.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# smartling.placeholder_format_custom = %s
2+
#, fuzzy
3+
msgid ""
4+
msgstr ""
5+
"Project-Id-Version: \n"
6+
"POT-Creation-Date: 2017-08-03 14:52+0300\n"
7+
"PO-Revision-Date: 2017-03-22 20:58+0200\n"
8+
"Last-Translator: \n"
9+
"Language-Team: \n"
10+
"MIME-Version: 1.0\n"
11+
"Content-Type: text/plain; charset=UTF-8\n"
12+
"Content-Transfer-Encoding: 8bit\n"
13+
"X-Generator: Poedit 2.0.1\n"
14+
"X-Poedit-Basepath: ../../src\n"
15+
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
16+
"X-Poedit-KeywordsList: gettext;ngettext:1,2;xgettext:1,2c;nxgettext:1,2,4c\n"
17+
"X-Poedit-SourceCharset: UTF-8\n"
18+
"X-Poedit-SearchPath-0: components\n"
19+
20+
#: components/Page.js:37
21+
msgid "I watched the storm, so beautiful yet terrific."
22+
msgstr ""
23+
24+
#: components/Page.js:40
25+
msgctxt "A sample text from Google Fonts service"
26+
msgid "Almost before we knew it, we had left the ground."
27+
msgstr ""
28+
29+
#: components/Page.js:45
30+
msgid "hour"
31+
msgid_plural "hours"
32+
msgstr[0] ""
33+
msgstr[1] ""
34+
35+
#: components/Page.js:51
36+
msgctxt "Number of hours"
37+
msgid "minute"
38+
msgid_plural "minutes"
39+
msgstr[0] ""
40+
msgstr[1] ""
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# smartling.placeholder_format_custom = %s
2+
msgid ""
3+
msgstr ""
4+
"Project-Id-Version: \n"
5+
"POT-Creation-Date: 2017-08-03 14:53+0300\n"
6+
"PO-Revision-Date: 2017-08-03 14:58+0300\n"
7+
"Last-Translator: \n"
8+
"Language-Team: \n"
9+
"Language: de\n"
10+
"MIME-Version: 1.0\n"
11+
"Content-Type: text/plain; charset=UTF-8\n"
12+
"Content-Transfer-Encoding: 8bit\n"
13+
"X-Generator: Poedit 2.0.1\n"
14+
"X-Poedit-Basepath: ../../src\n"
15+
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
16+
"X-Poedit-KeywordsList: gettext;ngettext:1,2;xgettext:1,2c;nxgettext:1,2,4c\n"
17+
"X-Poedit-SourceCharset: UTF-8\n"
18+
"X-Poedit-SearchPath-0: components\n"
19+
20+
#: components/Page.js:37
21+
msgid "I watched the storm, so beautiful yet terrific."
22+
msgstr "Ich sah den Sturm so schön und doch schrecklich an."
23+
24+
#: components/Page.js:40
25+
msgctxt "A sample text from Google Fonts service"
26+
msgid "Almost before we knew it, we had left the ground."
27+
msgstr "Fast bevor wir es wussten, hatten wir den Boden verlassen."
28+
29+
#: components/Page.js:45
30+
msgid "hour"
31+
msgid_plural "hours"
32+
msgstr[0] "stunde"
33+
msgstr[1] "stunden"
34+
35+
#: components/Page.js:51
36+
msgctxt "Number of hours"
37+
msgid "minute"
38+
msgid_plural "minutes"
39+
msgstr[0] "minute"
40+
msgstr[1] "minuten"
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# smartling.placeholder_format_custom = %s
2+
msgid ""
3+
msgstr ""
4+
"Project-Id-Version: \n"
5+
"POT-Creation-Date: 2017-08-03 14:54+0300\n"
6+
"PO-Revision-Date: 2017-08-03 14:59+0300\n"
7+
"Last-Translator: \n"
8+
"Language-Team: \n"
9+
"Language: fr\n"
10+
"MIME-Version: 1.0\n"
11+
"Content-Type: text/plain; charset=UTF-8\n"
12+
"Content-Transfer-Encoding: 8bit\n"
13+
"X-Generator: Poedit 2.0.1\n"
14+
"X-Poedit-Basepath: ../../src\n"
15+
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
16+
"X-Poedit-KeywordsList: gettext;ngettext:1,2;xgettext:1,2c;nxgettext:1,2,4c\n"
17+
"X-Poedit-SourceCharset: UTF-8\n"
18+
"X-Poedit-SearchPath-0: components\n"
19+
20+
#: components/Page.js:37
21+
msgid "I watched the storm, so beautiful yet terrific."
22+
msgstr "J'ai regardé la tempête, si belle mais formidable."
23+
24+
#: components/Page.js:40
25+
msgctxt "A sample text from Google Fonts service"
26+
msgid "Almost before we knew it, we had left the ground."
27+
msgstr "Presque avant nous le savions, nous avions quitté le sol."
28+
29+
#: components/Page.js:45
30+
msgid "hour"
31+
msgid_plural "hours"
32+
msgstr[0] "heure"
33+
msgstr[1] "heures"
34+
35+
#: components/Page.js:51
36+
msgctxt "Number of hours"
37+
msgid "minute"
38+
msgid_plural "minutes"
39+
msgstr[0] "minute"
40+
msgstr[1] "minutes"

0 commit comments

Comments
 (0)