-
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 locale state (#130)
* feat(i18n): add react-intl and local state * feat(i18n): refetch layers when locale changes (#131)
- Loading branch information
1 parent
197fcb9
commit 549f3eb
Showing
16 changed files
with
205 additions
and
30 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
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import {Locale} from '../actions/set-locale'; | ||
import config from '../config/main'; | ||
|
||
export default function fetchLayers(locale: Locale) { | ||
const url = `${config.api.layers}-${locale.toLowerCase()}.json`; | ||
return fetch(url).then(res => res.json()); | ||
} |
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,29 +1,47 @@ | ||
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 {createLogger} from 'redux-logger'; | ||
import {IntlProvider} from 'react-intl'; | ||
|
||
import rootReducer from '../../reducers/index'; | ||
import {localeSelector} from '../../reducers/locale'; | ||
import LayerSelector from '../layer-selector/layer-selector'; | ||
import Globe from '../globe/globe'; | ||
import Menu from '../menu/menu'; | ||
import ProjectionMenu from '../projection-menu/projection-menu'; | ||
|
||
import translations from '../../i18n'; | ||
import styles from './app.styl'; | ||
|
||
const store = createStore(rootReducer, applyMiddleware(thunk, logger)); | ||
const store = createStore( | ||
rootReducer, | ||
applyMiddleware(thunk, createLogger({collapsed: true})) | ||
); | ||
|
||
const App: FunctionComponent<{}> = () => ( | ||
<Provider store={store}> | ||
<div className={styles.app}> | ||
<Globe /> | ||
<div className={styles.layoutContainer}> | ||
<Menu /> | ||
<div className={styles.timeslider} /> | ||
<ProjectionMenu /> | ||
<LayerSelector /> | ||
</div> | ||
</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 /> | ||
<div className={styles.layoutContainer}> | ||
<Menu /> | ||
<div className={styles.timeslider} /> | ||
<ProjectionMenu /> | ||
<LayerSelector /> | ||
</div> | ||
</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
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,5 +1,5 @@ | ||
export default { | ||
api: { | ||
layers: 'https://storage.googleapis.com/esa-cfs-storage/layers.json' | ||
layers: 'https://storage.googleapis.com/esa-cfs-storage/layers' | ||
} | ||
}; |
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; |
Oops, something went wrong.