-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add internationalization support
- Loading branch information
Showing
19 changed files
with
420 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"menu": { | ||
"introduction": "Introduction" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
export const appActions = { | ||
INIT_APP: 'INIT_APP', | ||
|
||
init: ({ token, key }) => ({ | ||
init: ({ token, key, locale }) => ({ | ||
type: appActions.INIT_APP, | ||
payload: { | ||
token, | ||
key | ||
key, | ||
locale | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export const i18nActions = { | ||
CHANGE_LOCALE: 'CHANGE_LOCALE', | ||
|
||
change_locale: (locale) => ({ | ||
type: i18nActions.CHANGE_LOCALE, | ||
payload: { | ||
locale | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export { i18nActions } from './actions' | ||
export { i18nReducer } from './reducer' | ||
export { i18nSagas } from './sagas' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Record } from 'immutable' | ||
|
||
import { i18nActions } from './actions' | ||
|
||
const initialState = new Record({ | ||
locale: 'en' | ||
}) | ||
|
||
export function i18nReducer(state = initialState(), { payload, type }) { | ||
switch (type) { | ||
case i18nActions.CHANGE_LOCALE: | ||
return state.set('locale', payload.locale) | ||
|
||
default: | ||
return state | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { takeLatest, put, fork } from 'redux-saga/effects' | ||
import i18n from 'i18next' | ||
|
||
import { localStorageAdapter } from '@core/utils' | ||
import { appActions } from '@core/app/actions' | ||
import { i18nActions } from './actions' | ||
|
||
export function* init({ payload }) { | ||
if (payload.locale) { | ||
yield put(i18nActions.change_locale(payload.locale)) | ||
} | ||
|
||
// TODO detect user locale | ||
} | ||
|
||
export function ChangeLocale({ payload }) { | ||
localStorageAdapter.setItem('locale', payload.locale) | ||
i18n.changeLanguage(payload.locale) | ||
} | ||
|
||
//= ==================================== | ||
// WATCHERS | ||
// ------------------------------------- | ||
|
||
export function* watchInitApp() { | ||
yield takeLatest(appActions.INIT_APP, init) | ||
} | ||
|
||
export function* watchChangeLocale() { | ||
yield takeLatest(i18nActions.CHANGE_LOCALE, ChangeLocale) | ||
} | ||
|
||
//= ==================================== | ||
// ROOT | ||
// ------------------------------------- | ||
|
||
export const i18nSagas = [fork(watchInitApp), fork(watchChangeLocale)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { initReactI18next } from 'react-i18next' | ||
import i18n from 'i18next' | ||
import HttpBackend from 'i18next-http-backend' | ||
|
||
i18n | ||
.use(HttpBackend) | ||
.use(initReactI18next) | ||
.init({ | ||
// detection | ||
debug: true, | ||
backend: { | ||
// Configuration options for the backend plugin | ||
loadPath: '/locales/{{lng}}.json' // Path to the translation files | ||
}, | ||
lng: 'en', | ||
fallbackLng: 'en' | ||
// supportedLngs | ||
}) | ||
|
||
export default i18n |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
import FormControl from '@material-ui/core/FormControl' | ||
import Select from '@material-ui/core/Select' | ||
import MenuItem from '@material-ui/core/MenuItem' | ||
|
||
import './change-locale.styl' | ||
|
||
export default function ChangeLocale({ change_locale, locale }) { | ||
return ( | ||
<FormControl className='change-locale'> | ||
<Select | ||
labelId='change-locale' | ||
id='change-locale' | ||
value={locale} | ||
onChange={(event) => change_locale(event.target.value)}> | ||
<MenuItem value='en'>English</MenuItem> | ||
<MenuItem value='es'>Español</MenuItem> | ||
<MenuItem value='fr'>Français</MenuItem> | ||
<MenuItem value='it'>Italiano</MenuItem> | ||
<MenuItem value='de'>Deutsch</MenuItem> | ||
<MenuItem value='nl'>Nederlands</MenuItem> | ||
<MenuItem value='ru'>Русский</MenuItem> | ||
</Select> | ||
</FormControl> | ||
) | ||
} | ||
|
||
ChangeLocale.propTypes = { | ||
change_locale: PropTypes.func.isRequired, | ||
locale: PropTypes.string.isRequired | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { connect } from 'react-redux' | ||
import { createSelector } from 'reselect' | ||
|
||
import { i18nActions } from '@core/i18n' | ||
|
||
import ChangeLocale from './change-locale' | ||
|
||
const mapStateToProps = createSelector( | ||
(state) => state.getIn(['i18n', 'locale']), | ||
(locale) => ({ locale }) | ||
) | ||
|
||
const mapDispatchToProps = { | ||
change_locale: i18nActions.change_locale | ||
} | ||
|
||
export default connect(mapStateToProps, mapDispatchToProps)(ChangeLocale) |
Oops, something went wrong.