Skip to content

Commit 0df3821

Browse files
author
Gertjan Reynaert
committed
docs(Update): Make docs up to date with latest changes
1 parent 19e36c3 commit 0df3821

File tree

1 file changed

+78
-16
lines changed

1 file changed

+78
-16
lines changed

README.md

Lines changed: 78 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,28 +33,29 @@ now you know what messages you still need to update.
3333
## Installing
3434

3535
```
36-
npm install --save-dev react-intl-translations-manager
36+
yarn add --dev react-intl-translations-manager
3737
```
3838

3939
## Setup
4040
### Basic
4141

42-
Since you need the `babel-plugin-react-intl` to extract the messages, I'll assume you're using babel in your project.
43-
4442
This is an example of the most basic usage of this plugin, in the API documentation below you can find more options.
4543

4644
Create a script in your package.json
4745
```json
4846
{
4947
"scripts": {
50-
"manage:translations": "babel-node ./translationRunner.js"
48+
"manage:translations": "node ./translationRunner.js"
5149
}
5250
}
5351
```
5452
Create a file with your config you can run with the npm script
5553
```js
5654
// translationRunner.js
57-
import manageTranslations from 'react-intl-translations-manager';
55+
const manageTranslations = require('react-intl-translations-manager');
56+
57+
// es2015 import
58+
// import manageTranslations from 'react-intl-translations-manager';
5859

5960
manageTranslations({
6061
messagesDirectory: 'src/translations/extractedMessages',
@@ -69,11 +70,6 @@ Run the translation manager with your new npm script
6970
npm run manage:translations
7071
```
7172

72-
### Advanced
73-
74-
Build your own translationManager based on the core of this package, or it's
75-
exposed helper methods.
76-
7773
## Usage
7874

7975
Now you can check the status of your translations by just running the script. Then
@@ -89,9 +85,13 @@ checking the translations status.
8985

9086
### manageTranslations
9187

92-
This will maintain all translation files. Based on your config you will get output for duplicate ids, and per specified language you will get the deleted translations, added messages (new messages that need to be translated), and not yet translated messages. It will also maintain a whitelist file per language where you can specify translation keys where the translation is identical to the default message. This way you can avoid untranslated message warnings for these messages.
93-
94-
You can optionally pass a printer object to this method. This way you can override the console logging with your own logging logic. If you want custom file writing logic, it is advised to roll your own translationManager based on the core.
88+
This will maintain all translation files. Based on your config you will get
89+
output for duplicate ids, and per specified language you will get the deleted
90+
translations, added messages (new messages that need to be translated), and not
91+
yet translated messages. It will also maintain a whitelist file per language
92+
where you can specify translation keys where the translation is identical to
93+
the default message. This way you can avoid untranslated message warnings for
94+
these messages.
9595

9696
#### Config
9797

@@ -104,15 +104,17 @@ You can optionally pass a printer object to this method. This way you can overri
104104
- example: `src/locales/lang`
105105
- `whitelistsDirectory` (optional, default: `translationsDirectory`)
106106
- Directory of the whitelist files the translation manager needs to maintain.
107-
These files contain the key of translations that have the exact same text in a specific language as the defaultMessage. Specifying this key will suppress
107+
These files contain the key of translations that have the exact same text in
108+
a specific language as the defaultMessage. Specifying this key will suppress
108109
`unmaintained translation` warnings.
109110
- example: `Dashboard` in english is also accepted as a valid translation for
110111
dutch.
111112
- `languages` (optional, default: `[]`)
112113
- What languages the translation manager needs to maintain. Specifying no
113114
languages actually doesn't make sense, but won't break the translationManager
114115
either.
115-
- example: for `['nl', 'fr']` the translation manager will maintain a `nl.json`, `fr.json`, `whitelist_nl.json` and a `whitelist_fr.json` file
116+
- example: for `['nl', 'fr']` the translation manager will maintain a
117+
`nl.json`, `fr.json`, `whitelist_nl.json` and a `whitelist_fr.json` file
116118
- `singleMessagesFile` (optional, default: `false`)
117119
- Option to output a single JSON file containing the aggregate of all extracted messages,
118120
grouped by the file they were extracted from.
@@ -135,7 +137,8 @@ You can optionally pass a printer object to this method. This way you can overri
135137
- If you want the translationManager to log duplicate message ids or not
136138
- `sortKeys` (optional, default: `true`)
137139
- If you want the translationManager to sort it's output, both json and console output
138-
- `printers` (optional, default: {})
140+
- `jsonOptions` (optional, default: { space: 2, trailingNewline: false })
141+
- `overridePrinters` (optional, default: {})
139142
- Here you can specify custom logging methods. If not specified a default printer is used.
140143
- Possible printers to configure:
141144
```js
@@ -146,6 +149,65 @@ You can optionally pass a printer object to this method. This way you can overri
146149
printNoLanguageWhitelistFile: ( lang ) => { console.log(`No existing ${lang} file found. A new one is created.`) },
147150
};
148151
```
152+
- `overrideCoreMethods` (optional, default: {})
153+
- Here you can specify overrides for the core hooks. If not specified, the
154+
default methods will be used.
155+
- Possible overrides to configure:
156+
```js
157+
const overrideCoreMethods = {
158+
provideExtractedMessages: () => {},
159+
outputSingleFile: () => {},
160+
outputDuplicateKeys: () => {},
161+
beforeReporting: () => {},
162+
provideLangTemplate: () => {},
163+
provideTranslationsFile: () => {},
164+
provideWhitelistFile: () => {},
165+
reportLanguage: () => {},
166+
afterReporting: () => {},
167+
}
168+
```
169+
170+
#### Fully configured
171+
172+
This is the config with all options applied:
173+
174+
```js
175+
// import manageTranslations from 'react-intl-translations-manager';
176+
177+
manageTranslations({
178+
messagesDirectory: 'src/translations/extractedMessages',
179+
translationsDirectory: 'src/translations/locales/',
180+
whitelistsDirectory: 'src/translations/locales/whitelists/',
181+
languages: ['nl'], // any language you need
182+
singleMessagesFile: true,
183+
detectDuplicateIds: false,
184+
sortKeys: false,
185+
jsonOptions: {
186+
space: 4,
187+
trailingNewline: true,
188+
},
189+
overridePrinters: {
190+
printDuplicateIds: ( duplicateIds ) => { console.log(`You have ${duplicateIds.length } duplicate IDs`) },
191+
printLanguageReport: ( report ) => { console.log('Log report for a language') },
192+
printNoLanguageFile: ( lang ) => { console.log(`No existing ${lang} translation file found. A new one is created.`) },
193+
printNoLanguageWhitelistFile: ( lang ) => { console.log(`No existing ${lang} file found. A new one is created.`) },
194+
},
195+
overrideCoreMethods: {
196+
provideExtractedMessages: () => {},
197+
outputSingleFile: () => {},
198+
outputDuplicateKeys: () => {},
199+
beforeReporting: () => {},
200+
provideLangTemplate: () => {},
201+
provideTranslationsFile: () => {},
202+
provideWhitelistFile: () => {},
203+
reportLanguage: () => {},
204+
afterReporting: () => {},
205+
},
206+
});
207+
```
208+
209+
*This config is only as illustration for all possible options, these arent
210+
recommended configuration options.
149211

150212
### core
151213
```js

0 commit comments

Comments
 (0)