-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(i18n): add react-intl and local state
- Loading branch information
Showing
12 changed files
with
177 additions
and
17 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,4 @@ | ||
{ | ||
"layerSelector.main": "Haupt", | ||
"layerSelector.compare": "Vergleich" | ||
} |
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,4 @@ | ||
{ | ||
"layerSelector.main": "Main", | ||
"layerSelector.compare": "Compare" | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,31 @@ | ||
import {ThunkDispatch} from 'redux-thunk'; | ||
|
||
import {State} from '../reducers/index'; | ||
import fetchLayers, {FetchLayersActions} from './fetch-layers'; | ||
|
||
export const SET_LOCALE = 'SET_LOCALE'; | ||
|
||
export enum Locale { | ||
EN = 'en', | ||
DE = 'de' | ||
} | ||
|
||
export interface SetLocaleAction { | ||
type: typeof SET_LOCALE; | ||
locale: Locale; | ||
} | ||
|
||
type AllThunkActions = SetLocaleAction | FetchLayersActions; | ||
|
||
const setLocaleAction = (locale: Locale) => ( | ||
dispatch: ThunkDispatch<State, void, AllThunkActions> | ||
) => { | ||
dispatch({ | ||
type: SET_LOCALE, | ||
locale | ||
}); | ||
|
||
dispatch(fetchLayers()); | ||
}; | ||
|
||
export default setLocaleAction; |
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,25 +1,40 @@ | ||
import React, {FunctionComponent} from 'react'; | ||
import {createStore, applyMiddleware} from 'redux'; | ||
import {Provider} from 'react-redux'; | ||
import {Provider as StoreProvider, useSelector} from 'react-redux'; | ||
import thunk from 'redux-thunk'; | ||
import logger from 'redux-logger'; | ||
import {IntlProvider} from 'react-intl'; | ||
|
||
import rootReducer from '../../reducers/index'; | ||
import LayerSelector from '../layer-selector/layer-selector'; | ||
import Globe from '../globe/globe'; | ||
import Menu from '../menu/menu'; | ||
|
||
import {localeSelector} from '../../reducers/locale'; | ||
import translations from '../../i18n'; | ||
|
||
import styles from './app.styl'; | ||
|
||
const store = createStore(rootReducer, applyMiddleware(thunk, logger)); | ||
|
||
const App: FunctionComponent<{}> = () => ( | ||
<Provider store={store}> | ||
<div className={styles.app}> | ||
<Globe /> | ||
<LayerSelector /> | ||
<Menu /> | ||
</div> | ||
</Provider> | ||
<StoreProvider store={store}> | ||
<TranslatedApp /> | ||
</StoreProvider> | ||
); | ||
|
||
const TranslatedApp: FunctionComponent<{}> = () => { | ||
const locale = useSelector(localeSelector); | ||
|
||
return ( | ||
<IntlProvider locale={locale} messages={translations[locale]}> | ||
<div className={styles.app}> | ||
<Globe /> | ||
<LayerSelector /> | ||
<Menu /> | ||
</div> | ||
</IntlProvider> | ||
); | ||
}; | ||
|
||
export default App; |
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,7 @@ | ||
import en from '../../i18n/en.json'; | ||
import de from '../../i18n/de.json'; | ||
|
||
export default { | ||
en, | ||
de | ||
}; |
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,22 @@ | ||
import {State} from './index'; | ||
import {SET_LOCALE, Locale, SetLocaleAction} from '../actions/set-locale'; | ||
|
||
const initialState: Locale = Locale.EN; | ||
|
||
function localeReducer( | ||
localeState: Locale = initialState, | ||
action: SetLocaleAction | ||
): Locale { | ||
switch (action.type) { | ||
case SET_LOCALE: | ||
return action.locale; | ||
default: | ||
return localeState; | ||
} | ||
} | ||
|
||
export function localeSelector(state: State): Locale { | ||
return state.locale; | ||
} | ||
|
||
export default localeReducer; |
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