Skip to content

Commit 643675f

Browse files
authored
Merge pull request #5 from derzunov/develop
- Action types constants added - `'SET_CURRENT'` renamed to `'SET_CURRENT_LANGUAGE'` - `'setCurrent'` action creator renamed to `'setCurrentLanguage'`
2 parents fb6f19d + da46689 commit 643675f

File tree

9 files changed

+43
-19
lines changed

9 files changed

+43
-19
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ npm i redux-react-i18n
9595
- LocPresentational ( Presentational Component )
9696

9797
### Actions
98-
- setCurrent( languageCode )
98+
- setCurrentLanguage( languageCode )
9999
- setLanguages( languageCode )
100100
- addDictionary( languageCode, dictionary )
101101
- setDictionaries( dictionaries )
@@ -155,7 +155,7 @@ store.dispatch( i18nActions.setLanguages( languages ) )
155155
// / Set languages (simpliest exapmple) ------------------------------------------------------------------------------------------------
156156

157157
// Set current language code (you can map this action to select component or somth like this)
158-
store.dispatch( i18nActions.setCurrent( 'ru-RU' ) )
158+
store.dispatch( i18nActions.setCurrentLanguage( 'ru-RU' ) )
159159
```
160160

161161
#### And now you can use "Loc" container component

example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"react-redux": "^4.4.5",
2828
"redux": "^3.5.2",
2929
"redux-form": "^6.2.0",
30-
"redux-react-i18n": "^1.0.2",
30+
"redux-react-i18n": "^1.1.0",
3131
"redux-thunk": "^2.0.1",
3232
"run-sequence": "^1.2.2",
3333
"stream-combiner2": "^1.1.1",

example/src/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,4 @@ store.dispatch( i18nActions.setDictionaries(
8585
}
8686
) );
8787

88-
store.dispatch( i18nActions.setCurrent( 'ru-RU' ) );
88+
store.dispatch( i18nActions.setCurrentLanguage( 'ru-RU' ) );

example/src/components/LanguageSwitcher.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const mapStateToProps = ( { i18n: { currentLanguage } }, ownProps ) => ( {
77
} )
88

99
const mapDispatchToProps = ( dispatch ) => ( {
10-
switchLanguage: ( code ) => dispatch( i18nActions.setCurrent( code ) )
10+
switchLanguage: ( code ) => dispatch( i18nActions.setCurrentLanguage( code ) )
1111
} )
1212

1313
const LanguageSwitcher = ( {currentLanguage, switchLanguage} ) => {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "redux-react-i18n",
3-
"version": "1.0.2",
3+
"version": "1.1.0",
44
"description": "i18n solution for react/redux",
55
"main": "lib/index.js",
66
"scripts": {

src/action-types.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const SET_CURRENT_LANGUAGE = 'SET_CURRENT_LANGUAGE'
2+
export const SET_LANGUAGES = 'SET_LANGUAGES'
3+
export const SET_DICTIONARIES = 'SET_DICTIONARIES'
4+
export const ADD_DICTIONARY = 'ADD_DICTIONARY'

src/actions.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
export const setCurrent = ( languageCode ) => ( { type: "SET_CURRENT", data: languageCode } )
2-
export const setLanguages = ( languageCode ) => ( { type: "SET_LANGUAGES", data: languageCode } )
3-
export const addDictionary = ( languageCode, dictionary ) => ( { type: "ADD_DICTIONARY", data: { languageCode, dictionary } } )
4-
export const setDictionaries = ( dictionaries ) => ( { type: "SET_DICTIONARIES", data: dictionaries } )
1+
import {
2+
SET_CURRENT_LANGUAGE,
3+
SET_LANGUAGES,
4+
SET_DICTIONARIES,
5+
ADD_DICTIONARY
6+
} from './action-types'
7+
8+
export const setCurrentLanguage = ( languageCode ) => ( { type: SET_CURRENT_LANGUAGE, data: languageCode } )
9+
export const setLanguages = ( languageCode ) => ( { type: SET_LANGUAGES, data: languageCode } )
10+
export const addDictionary = ( languageCode, dictionary ) => ( { type: ADD_DICTIONARY, data: { languageCode, dictionary } } )
11+
export const setDictionaries = ( dictionaries ) => ( { type: SET_DICTIONARIES, data: dictionaries } )

src/reducer.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,38 @@
1+
import {
2+
SET_CURRENT_LANGUAGE,
3+
SET_LANGUAGES,
4+
SET_DICTIONARIES,
5+
ADD_DICTIONARY
6+
} from './action-types'
7+
18
import initialState from './initialState'
29

310
const i18n = ( state, action ) => {
411

512
switch ( action.type ) {
613

7-
case 'SET_CURRENT': {
14+
case SET_CURRENT_LANGUAGE: {
815

916
let newState = Object.assign( {}, state )
1017
newState.currentLanguage = action.data
1118
return newState
1219
}
1320

14-
case 'SET_LANGUAGES': {
21+
case SET_LANGUAGES: {
1522

1623
let newState = Object.assign( {}, state )
1724
newState.languages = action.data
1825
return newState
1926
}
2027

21-
case 'SET_DICTIONARIES': {
28+
case SET_DICTIONARIES: {
2229

2330
let newState = Object.assign( {}, state )
2431
newState.dictionaries = action.data
2532
return newState
2633
}
2734

28-
case 'ADD_DICTIONARY': {
35+
case ADD_DICTIONARY: {
2936

3037
if ( action.data && action.data.languageCode && action.data.dictionary ) {
3138

tests/reducer.test.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import reducer from '../src/reducer'
22
import initialState from '../src/initialState'
3+
import {
4+
SET_CURRENT_LANGUAGE,
5+
SET_LANGUAGES,
6+
SET_DICTIONARIES,
7+
ADD_DICTIONARY
8+
} from '../src/action-types'
39

410
describe('i18n reducer', () => {
511
it( 'should return the initial state', () => {
@@ -8,12 +14,12 @@ describe('i18n reducer', () => {
814
).toEqual( initialState )
915
} )
1016

11-
it( 'should handle SET_CURRENT', () => {
17+
it( 'should handle SET_CURRENT_LANGUAGE', () => {
1218
let newState = Object.assign( {}, initialState )
1319
newState.currentLanguage = 'en-US'
1420
expect(
1521
reducer( initialState, {
16-
type: 'SET_CURRENT',
22+
type: SET_CURRENT_LANGUAGE,
1723
data: 'en-US'
1824
} )
1925
).toEqual(
@@ -36,7 +42,7 @@ describe('i18n reducer', () => {
3642
]
3743
expect(
3844
reducer( initialState, {
39-
type: 'SET_LANGUAGES',
45+
type: SET_LANGUAGES,
4046
data: [
4147
{
4248
code: 'car-CAR',
@@ -68,7 +74,7 @@ describe('i18n reducer', () => {
6874
}
6975
expect(
7076
reducer( initialState, {
71-
type: 'SET_DICTIONARIES',
77+
type: SET_DICTIONARIES,
7278
data: {
7379
'car-CAR': {
7480
'key_1': 'Первый дефолтный ключ птичьего языка для теста',
@@ -95,7 +101,7 @@ describe('i18n reducer', () => {
95101

96102
expect(
97103
reducer( initialState, {
98-
type: 'ADD_DICTIONARY',
104+
type: ADD_DICTIONARY,
99105
data: {
100106
languageCode: 'new-NEW',
101107
dictionary: {

0 commit comments

Comments
 (0)