Skip to content

Commit 07b3e54

Browse files
author
Ryan Johnson
authored
update to React 16 (#28)
* update dependencies and unit tests to work with React 16 * fix broken links in docs * add enhanced type definitions for single and multiple translation data
1 parent bc25f4f commit 07b3e54

15 files changed

+372
-164
lines changed

docs/api/action-creators.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ name | Type | Default | Description
1616
defaultLanguage | string | languages[0] | The language code for the language you'd like to set as the defualt.
1717
renderInnerHtml | boolean | true | Controls whether HTML in your translations will be rendered or returned as a plain string.
1818
showMissingTranslationMsg | boolean | true | Controls whether missing translation message will be rendered when translation is undefined.
19-
missingTranslationCallback | function | undefined | A function that will be called when attempting to get an undefined translation. See [Handle missing translations](../features/#handle-missing-translations) for details.
20-
translationTransform | function | undefined | A transformation function that will be applied to translation data. See [Custom data format](../formatting-translation-data#custom-data-format) for details.
19+
missingTranslationCallback | function | undefined | A function that will be called when attempting to get an undefined translation. See [Handle missing translations](/features/#handle-missing-translations) for details.
20+
translationTransform | function | undefined | A transformation function that will be applied to translation data. See [Custom data format](/formatting-translation-data#custom-data-format) for details.
2121

2222
<div class="admonition important">
2323
<p class="first admonition-title">Important</p>
@@ -73,13 +73,13 @@ store.dispatch(setLanguages(languages, 'fr'));
7373

7474
## addTranslation(data)
7575

76-
Dispatch this action to add translation data for multiple languages from a json file, or vanilla JS to your redux store. Please see [formatting transaltion data](../formatting-translation-data#multiple-language-format) to ensure your data is in the proper format.
76+
Dispatch this action to add translation data for multiple languages from a json file, or vanilla JS to your redux store. Please see [formatting transaltion data](/formatting-translation-data#multiple-language-format) to ensure your data is in the proper format.
7777

7878
** Arguments **
7979

8080
name | Type | Description
8181
--------- | ----------| ------------
82-
data | json \| object | Translation data in the [required format](../formatting-translation-data#multiple-language-format)
82+
data | json \| object | Translation data in the [required format](/formatting-translation-data#multiple-language-format)
8383

8484
** Usage: **
8585

@@ -100,13 +100,13 @@ store.dispatch(addTranslation(welcomePageTranslations));
100100

101101
## addTranslationForLanguage(data, language)
102102

103-
Dispatch this action to add translation data for a single language from a json file, or vanilla JS to your redux store. Please see [formatting transaltion data](../formatting-translation-data#single-language-format) to ensure your data is in the proper format.
103+
Dispatch this action to add translation data for a single language from a json file, or vanilla JS to your redux store. Please see [formatting transaltion data](/formatting-translation-data#single-language-format) to ensure your data is in the proper format.
104104

105105
** Arguments **
106106

107107
name | Type | Description
108108
--------- | ----------| ------------
109-
data | json \| object | Translation data in the [required format](../formatting-translation-data#single-language-format)
109+
data | json \| object | Translation data in the [required format](/formatting-translation-data#single-language-format)
110110
language | string | The language code this translation data belongs to
111111

112112
** Usage: **

docs/api/higher-order-component.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<div class="admonition important">
44
<p class="first admonition-title">Important</p>
5-
<p class="last">if your component is already using <a href="https://github.com/reactjs/react-redux/blob/master/docs/api.md#connectmapstatetoprops-mapdispatchtoprops-mergeprops-options" target="_blank">connect</a> then you should use the <a href="../selectors/#gettranslatestate">getTranslate</a>, and <a href="../selectors#getactivelanguagestate">getActiveLanguage</a> selectors instead of <code>localize</code>.</p>
5+
<p class="last">if your component is already using <a href="https://github.com/reactjs/react-redux/blob/master/docs/api.md#connectmapstatetoprops-mapdispatchtoprops-mergeprops-options" target="_blank">connect</a> then you should use the <a href="/selectors/#gettranslatestate">getTranslate</a>, and <a href="/selectors#getactivelanguagestate">getActiveLanguage</a> selectors instead of <code>localize</code>.</p>
66
</div>
77

88
If you have a component that just needs access to translations, and nothing else then you can use the `localize` higher-order function. When you pass your Component to localize it will automatically add [translate](selectors.md#translatekey-string-string-data) and `currentLanguage` to props.

docs/api/selectors.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ name | Type | Description
3636
--------- | ----------| ------------
3737
key | string \| string [] | Pass a single key or multiple keys from your translation data.
3838
[data] | object | Optional data to be used in your localized strings for [variable replacement]().
39-
[options]| object | Optional local override for `renderInnerHtml` option passed to the [initialize](../action-creators/#initializelanguages-options) action creator.
39+
[options]| object | Optional local override for `renderInnerHtml` option passed to the [initialize](/action-creators/#initializelanguages-options) action creator.
4040

4141
** Returns: **
4242

docs/features.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
## Pass multiple translations to components
22

33
To avoid connecting every single component that needs translations you should instead pass translations down to child components.
4-
To retrieve multiple translations using [translate](../api/selectors#translatekey-string-string-data) pass an array of translation keys instead of a single key. This will return an object with translated strings mapped to translation keys.
4+
To retrieve multiple translations using [translate](/api/selectors#translatekey-string-string-data) pass an array of translation keys instead of a single key. This will return an object with translated strings mapped to translation keys.
55

66
Since `translate` returns an object we can use the object spread operator to pass the translations as props for the `<Article>` component.
77

@@ -49,7 +49,7 @@ Insert dynamic content into your translation strings by inserting placeholders w
4949
}
5050
```
5151

52-
Then pass in the data you want to swap in for placeholders to the [translate](../api/selectors#translatekey-string-string-data) function.
52+
Then pass in the data you want to swap in for placeholders to the [translate](/api/selectors#translatekey-string-string-data) function.
5353

5454
```javascript
5555
<h1>{ translate('greeting', { name: 'Testy McTest' }) }</h1>
@@ -81,7 +81,7 @@ Include HTML in your translation strings and it will be rendered in your compone
8181

8282
### Handle custom translation data
8383

84-
Does react-localize-redux's supported translation data formats not work for you? That's ok - there is a way for you to use your own custom trnaslation data format. See [Formatting Transltion Data - Custom data format](../formatting-translation-data/#custom-data-format) for full documentation.
84+
Does react-localize-redux's supported translation data formats not work for you? That's ok - there is a way for you to use your own custom trnaslation data format. See [Formatting Transltion Data - Custom data format](/formatting-translation-data/#custom-data-format) for full documentation.
8585

8686

8787

@@ -134,7 +134,7 @@ Does react-localize-redux's supported translation data formats not work for you?
134134

135135
## Handle missing translations
136136

137-
If you need a way to detect missing translations you can set the [missingTranslationCallback](../api/action-creators/#initialize-options) option. When set this callback will be triggered anytime the [translate](../api/selectors/#translatekey-string-string-data-options) function detects an `undefined` translation.
137+
If you need a way to detect missing translations you can set the [missingTranslationCallback](/api/action-creators/#initialize-options) option. When set this callback will be triggered anytime the [translate](/api/selectors/#translatekey-string-string-data-options) function detects an `undefined` translation.
138138

139139
** Example **
140140

docs/formatting-translation-data.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ The translation data for you application will either come from json or vanilla J
22

33
## Multiple language format
44

5-
> Use **[addTranslation](../api/action-creators#addtranslationdata)** to add data in this format.
5+
> Use **[addTranslation](/api/action-creators#addtranslationdata)** to add data in this format.
66
77
The data is an object where the property name is your translation key, and the value is an array of translations. The translation key is used to identify the translation, and the value is an array that enforces the following...
88

99
* Includes a translation for each language your app supports.
10-
* The order of the translation strings in the array matters! The order **MUST** follow the order of the languages array passed to [setLanguages]([addTranslationForLanguage](../api/action-creators#addtranslationforlanguagedata-language)).
10+
* The order of the translation strings in the array matters! The order **MUST** follow the order of the languages array passed to [setLanguages]([addTranslationForLanguage](/api/action-creators#addtranslationforlanguagedata-language)).
1111

1212
Assuming your application has dispatched `setLanguages('en', 'fr', 'es')`:
1313

@@ -34,7 +34,7 @@ Assuming your application has dispatched `setLanguages('en', 'fr', 'es')`:
3434

3535
## Single language format
3636

37-
> Use **[addTranslationForLanguage](../api/action-creators#addtranslationforlanguagedata-language)** to add data in this format.
37+
> Use **[addTranslationForLanguage](/api/action-creators#addtranslationforlanguagedata-language)** to add data in this format.
3838
3939
The data is an object where the property name is your translation key, and the value is the translation for the language. With the single language format you would dispatch `addTranslationForLanguage` for each language you support.
4040

@@ -71,19 +71,19 @@ Assuming your application `setLanguages('en', 'fr', 'es')`:
7171

7272
## Custom data format
7373

74-
If you cannot use the supported data formats there is a way to instruct react-localize-redux on how to handle your custom data. To do this you must pass the [translationTransform](../api/action-creators#initialize-options) option when dispatching the [intialize](../api/action-creators#initializelanguages-options) action, which takes a function in the following format:
74+
If you cannot use the supported data formats there is a way to instruct react-localize-redux on how to handle your custom data. To do this you must pass the [translationTransform](/api/action-creators#initialize-options) option when dispatching the [intialize](/api/action-creators#initializelanguages-options) action, which takes a function in the following format:
7575

7676
```javascript
7777
const transformationFunction = (translationData: Object, languagesCodes: string[]) => {
7878
// Your transformation logic goes here...
7979
};
8080
```
8181

82-
This function is responsible for taking your custom data, and transforming it into the format required by react-localize-redux. You are responsible for writing the transformation logic, but after that the function will be run automatically whenever dispatching [addTranslation](../api/action-creators#addtranslationdata).
82+
This function is responsible for taking your custom data, and transforming it into the format required by react-localize-redux. You are responsible for writing the transformation logic, but after that the function will be run automatically whenever dispatching [addTranslation](/api/action-creators#addtranslationdata).
8383

8484
<div class="admonition note">
8585
<p class="first admonition-title">Note</p>
86-
<p class="last">The transformation function will not be run if you use the <code><a href="../api/action-creators/#addtranslationforlanguagedata-language">addTranslationForLanguage</a></code> action.</p>
86+
<p class="last">The transformation function will not be run if you use the <code><a href="/api/action-creators/#addtranslationforlanguagedata-language">addTranslationForLanguage</a></code> action.</p>
8787
</div>
8888

8989
** Example **
@@ -133,7 +133,7 @@ const transformFunction = (translationData, languageCodes) => {
133133
};
134134
```
135135

136-
Now when you dispatch the [intialize](../api/action-creators#initializelanguages-options) action make sure you set the [translationTransform](../api/action-creators#initialize-options) option equal to the `transformFunction`. Now anytime you dispatch the [addTranslation](../api/action-creators#addtranslationdata) action the `transformFunction` will run on the translation data you are adding.
136+
Now when you dispatch the [intialize](/api/action-creators#initializelanguages-options) action make sure you set the [translationTransform](/api/action-creators#initialize-options) option equal to the `transformFunction`. Now anytime you dispatch the [addTranslation](/api/action-creators#addtranslationdata) action the `transformFunction` will run on the translation data you are adding.
137137

138138
```javascript
139139
const languages = ['en', 'fr'];

docs/getting-started.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ store.dispatch(initialize(languages, { defaultLanguage: 'fr' }));
5353

5454
Typically you will store your translation data in json files, but the data can also be a vanilla JS object.
5555

56-
In order to add translation data to your application there are two action creators available - [addTranslation](../api/action-creators#addtranslationdata) and [addTranslationForLanguage](../api/action-creators#addtranslationforlanguagedata-language). Which one you use will depend on which format your translation data is in - see [formatting transaltion data]() for more information.
56+
In order to add translation data to your application there are two action creators available - [addTranslation](/api/action-creators#addtranslationdata) and [addTranslationForLanguage](/api/action-creators#addtranslationforlanguagedata-language). Which one you use will depend on which format your translation data is in - see [formatting transaltion data]() for more information.
5757

5858
<div class="admonition note">
5959
<p class="first admonition-title">Note</p>
@@ -86,7 +86,7 @@ store.dispatch(addTranslationForLanguage(json, 'en'));
8686

8787
## 4. Change language
8888

89-
Dispatch [setActiveLanguage](../api/action-creators#setactivelanguagelanguage) and pass the language.
89+
Dispatch [setActiveLanguage](/api/action-creators#setactivelanguagelanguage) and pass the language.
9090

9191
```javascript
9292
import { setActiveLanguage } from 'react-localize-redux';
@@ -101,7 +101,7 @@ store.dispatch(setActiveLanguage('fr'));
101101

102102
## 5. Translate components
103103

104-
If you have a component that is already using [connect](https://github.com/reactjs/react-redux/blob/master/docs/api.md#connectmapstatetoprops-mapdispatchtoprops-mergeprops-options) use [getTranslate](../api/selectors#gettranslatestate) in your `mapStateToProps` to add the [translate](../api/selectors#translatekey-string-string-data) function to your component's props.
104+
If you have a component that is already using [connect](https://github.com/reactjs/react-redux/blob/master/docs/api.md#connectmapstatetoprops-mapdispatchtoprops-mergeprops-options) use [getTranslate](/api/selectors#gettranslatestate) in your `mapStateToProps` to add the [translate](/api/selectors#translatekey-string-string-data) function to your component's props.
105105

106106
```javascript
107107
import { getTranslate } from 'react-localize-redux';
@@ -121,11 +121,11 @@ const mapStateToProps = state => ({
121121
export default connect(mapStateToProps)(Greeting);
122122
```
123123

124-
For components where you only need access to [translate](../api/selectors#translatekey-string-string-data) and `currentLanguage` you can use [localize](../api/higher-order-component#localizecomponent-reducername). This will automatically connect your component with the `translate` function and `currentLanguage` prop.
124+
For components where you only need access to [translate](/api/selectors#translatekey-string-string-data) and `currentLanguage` you can use [localize](/api/higher-order-component#localizecomponent-reducername). This will automatically connect your component with the `translate` function and `currentLanguage` prop.
125125

126126
<div class="admonition warning">
127127
<p class="first admonition-title">Warning</p>
128-
<p class="last">Components that use <strong>localize</strong> still use <a href="https://github.com/reactjs/react-redux/blob/master/docs/api.md#connectmapstatetoprops-mapdispatchtoprops-mergeprops-options" target="_blank">connect</a> behind the scenes, which means you will want to avoid overusing <strong>localize</strong>. Instead <a href="../features#pass-multiple-translations-to-components">pass multiple translations to components</a> when possible.</p>
128+
<p class="last">Components that use <strong>localize</strong> still use <a href="https://github.com/reactjs/react-redux/blob/master/docs/api.md#connectmapstatetoprops-mapdispatchtoprops-mergeprops-options" target="_blank">connect</a> behind the scenes, which means you will want to avoid overusing <strong>localize</strong>. Instead <a href="/features#pass-multiple-translations-to-components">pass multiple translations to components</a> when possible.</p>
129129
</div>
130130

131131
```javascript

docs/index.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<p align="center">
2+
<img alt="React Localize Redux" src="https://cdn-images-1.medium.com/max/600/1*3Hg5LMvLmWCmEg-ICeUtjg.png">
3+
</p>
4+
5+
<p align="center">
6+
Localization library for <a href="https://facebook.github.io/react">React</a>/<a href="http://redux.js.org/">Redux</a>.
7+
</p>
8+
9+
<p align="center">
10+
<a href="https://www.npmjs.com/package/react-localize-redux"><img src="https://img.shields.io/npm/dm/react-localize-redux.svg?style=flat-square"></a>
11+
<a href="https://travis-ci.org/ryandrewjohnson/react-localize-redux"><img src="https://img.shields.io/travis/ryandrewjohnson/react-localize-redux/master.svg?style=flat-square"></a>
12+
</p>
13+
14+
## Installation
15+
16+
```bash
17+
npm install react-localize-redux --save
18+
```

mkdocs.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
site_name: react-localize-redux
22
repo_url: https://github.com/ryandrewjohnson/react-localize-redux
3+
site_description: 'Localization library for React/Redux.'
4+
site_author: Ryan Johnson
35

46
pages:
7+
- index.md
58
- Getting Started: getting-started.md
69
- Formatting Translation Data: formatting-translation-data.md
710
- Features: features.md

0 commit comments

Comments
 (0)