De-duplicate language select state
This commit is contained in:
parent
e873ffc994
commit
caadae2704
|
@ -1,5 +1,4 @@
|
||||||
// @flow
|
// @flow
|
||||||
import { setLanguage } from 'translations';
|
|
||||||
|
|
||||||
export type ChangeNodeAction = {
|
export type ChangeNodeAction = {
|
||||||
type: 'CONFIG_NODE_CHANGE',
|
type: 'CONFIG_NODE_CHANGE',
|
||||||
|
@ -15,7 +14,6 @@ export type ChangeLanguageAction = {
|
||||||
export type ConfigAction = ChangeNodeAction | ChangeLanguageAction;
|
export type ConfigAction = ChangeNodeAction | ChangeLanguageAction;
|
||||||
|
|
||||||
export function changeLanguage(sign: string) {
|
export function changeLanguage(sign: string) {
|
||||||
setLanguage(sign);
|
|
||||||
return {
|
return {
|
||||||
type: 'CONFIG_LANGUAGE_CHANGE',
|
type: 'CONFIG_LANGUAGE_CHANGE',
|
||||||
value: sign
|
value: sign
|
||||||
|
|
|
@ -1,72 +1,14 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { render } from 'react-dom';
|
import { render } from 'react-dom';
|
||||||
import { syncHistoryWithStore, routerMiddleware } from 'react-router-redux';
|
import { syncHistoryWithStore } from 'react-router-redux';
|
||||||
import { composeWithDevTools } from 'redux-devtools-extension';
|
|
||||||
import Perf from 'react-addons-perf';
|
|
||||||
import { createStore, applyMiddleware } from 'redux';
|
|
||||||
import RootReducer from './reducers';
|
|
||||||
import { Root } from 'components';
|
import { Root } from 'components';
|
||||||
import { Routing, history } from './routing';
|
import { Routing, history } from './routing';
|
||||||
import { createLogger } from 'redux-logger';
|
import { store } from './store';
|
||||||
import createSagaMiddleware from 'redux-saga';
|
|
||||||
import notificationsSaga from './sagas/notifications';
|
|
||||||
import ensSaga from './sagas/ens';
|
|
||||||
import walletSaga from './sagas/wallet';
|
|
||||||
import { initialState as configInitialState } from 'reducers/config';
|
|
||||||
import throttle from 'lodash/throttle';
|
|
||||||
// application styles
|
// application styles
|
||||||
import 'assets/styles/etherwallet-master.less';
|
import 'assets/styles/etherwallet-master.less';
|
||||||
import { saveState, loadStatePropertyOrEmptyObject } from 'utils/localStorage';
|
|
||||||
|
|
||||||
let store;
|
|
||||||
|
|
||||||
const configureStore = () => {
|
|
||||||
const logger = createLogger({
|
|
||||||
collapsed: true
|
|
||||||
});
|
|
||||||
const sagaMiddleware = createSagaMiddleware();
|
|
||||||
let middleware;
|
|
||||||
|
|
||||||
if (process.env.NODE_ENV !== 'production') {
|
|
||||||
window.Perf = Perf;
|
|
||||||
middleware = composeWithDevTools(
|
|
||||||
applyMiddleware(sagaMiddleware, logger, routerMiddleware(history))
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
middleware = applyMiddleware(sagaMiddleware, routerMiddleware(history));
|
|
||||||
}
|
|
||||||
|
|
||||||
const persistedConfigInitialState = {
|
|
||||||
config: {
|
|
||||||
...configInitialState,
|
|
||||||
...loadStatePropertyOrEmptyObject('config')
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const completePersistedInitialState = {
|
|
||||||
...persistedConfigInitialState
|
|
||||||
};
|
|
||||||
|
|
||||||
store = createStore(RootReducer, completePersistedInitialState, middleware);
|
|
||||||
sagaMiddleware.run(notificationsSaga);
|
|
||||||
sagaMiddleware.run(ensSaga);
|
|
||||||
sagaMiddleware.run(walletSaga);
|
|
||||||
|
|
||||||
store.subscribe(
|
|
||||||
throttle(() => {
|
|
||||||
saveState({
|
|
||||||
config: {
|
|
||||||
languageSelection: store.getState().config.languageSelection
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}),
|
|
||||||
1000
|
|
||||||
);
|
|
||||||
return store;
|
|
||||||
};
|
|
||||||
|
|
||||||
const renderRoot = Root => {
|
const renderRoot = Root => {
|
||||||
let store = configureStore();
|
|
||||||
let syncedHistory = syncHistoryWithStore(history, store);
|
let syncedHistory = syncHistoryWithStore(history, store);
|
||||||
render(
|
render(
|
||||||
<Root
|
<Root
|
||||||
|
|
|
@ -0,0 +1,61 @@
|
||||||
|
import { saveState, loadStatePropertyOrEmptyObject } from 'utils/localStorage';
|
||||||
|
import { createLogger } from 'redux-logger';
|
||||||
|
import createSagaMiddleware from 'redux-saga';
|
||||||
|
import notificationsSaga from './sagas/notifications';
|
||||||
|
import ensSaga from './sagas/ens';
|
||||||
|
import walletSaga from './sagas/wallet';
|
||||||
|
import { initialState as configInitialState } from 'reducers/config';
|
||||||
|
import throttle from 'lodash/throttle';
|
||||||
|
import { composeWithDevTools } from 'redux-devtools-extension';
|
||||||
|
import Perf from 'react-addons-perf';
|
||||||
|
import { createStore, applyMiddleware } from 'redux';
|
||||||
|
import RootReducer from './reducers';
|
||||||
|
import { routerMiddleware } from 'react-router-redux';
|
||||||
|
|
||||||
|
const configureStore = () => {
|
||||||
|
const logger = createLogger({
|
||||||
|
collapsed: true
|
||||||
|
});
|
||||||
|
const sagaMiddleware = createSagaMiddleware();
|
||||||
|
let middleware;
|
||||||
|
let store;
|
||||||
|
|
||||||
|
if (process.env.NODE_ENV !== 'production') {
|
||||||
|
window.Perf = Perf;
|
||||||
|
middleware = composeWithDevTools(
|
||||||
|
applyMiddleware(sagaMiddleware, logger, routerMiddleware(history))
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
middleware = applyMiddleware(sagaMiddleware, routerMiddleware(history));
|
||||||
|
}
|
||||||
|
|
||||||
|
const persistedConfigInitialState = {
|
||||||
|
config: {
|
||||||
|
...configInitialState,
|
||||||
|
...loadStatePropertyOrEmptyObject('config')
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const completePersistedInitialState = {
|
||||||
|
...persistedConfigInitialState
|
||||||
|
};
|
||||||
|
|
||||||
|
store = createStore(RootReducer, completePersistedInitialState, middleware);
|
||||||
|
sagaMiddleware.run(notificationsSaga);
|
||||||
|
sagaMiddleware.run(ensSaga);
|
||||||
|
sagaMiddleware.run(walletSaga);
|
||||||
|
|
||||||
|
store.subscribe(
|
||||||
|
throttle(() => {
|
||||||
|
saveState({
|
||||||
|
config: {
|
||||||
|
languageSelection: store.getState().config.languageSelection
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
1000
|
||||||
|
);
|
||||||
|
return store;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const store = configureStore();
|
|
@ -1,6 +1,6 @@
|
||||||
// @flow
|
// @flow
|
||||||
import { markupToReact } from './markup';
|
import { markupToReact } from './markup';
|
||||||
let activeLanguage = 'en';
|
import { store } from '../store';
|
||||||
let fallbackLanguage = 'en';
|
let fallbackLanguage = 'en';
|
||||||
let repository = {};
|
let repository = {};
|
||||||
|
|
||||||
|
@ -31,11 +31,8 @@ languages.forEach(l => {
|
||||||
repository[l.code] = l.data;
|
repository[l.code] = l.data;
|
||||||
});
|
});
|
||||||
|
|
||||||
export function setLanguage(code: string) {
|
|
||||||
activeLanguage = code;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function translate(key: string) {
|
export default function translate(key: string) {
|
||||||
|
let activeLanguage = store.getState().config.languageSelection;
|
||||||
return markupToReact(
|
return markupToReact(
|
||||||
(repository[activeLanguage] && repository[activeLanguage][key]) ||
|
(repository[activeLanguage] && repository[activeLanguage][key]) ||
|
||||||
repository[fallbackLanguage][key] ||
|
repository[fallbackLanguage][key] ||
|
||||||
|
|
Loading…
Reference in New Issue