De-duplicate language select state
This commit is contained in:
parent
e873ffc994
commit
caadae2704
|
@ -1,5 +1,4 @@
|
|||
// @flow
|
||||
import { setLanguage } from 'translations';
|
||||
|
||||
export type ChangeNodeAction = {
|
||||
type: 'CONFIG_NODE_CHANGE',
|
||||
|
@ -15,7 +14,6 @@ export type ChangeLanguageAction = {
|
|||
export type ConfigAction = ChangeNodeAction | ChangeLanguageAction;
|
||||
|
||||
export function changeLanguage(sign: string) {
|
||||
setLanguage(sign);
|
||||
return {
|
||||
type: 'CONFIG_LANGUAGE_CHANGE',
|
||||
value: sign
|
||||
|
|
|
@ -1,72 +1,14 @@
|
|||
import React from 'react';
|
||||
import { render } from 'react-dom';
|
||||
import { syncHistoryWithStore, routerMiddleware } 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 { syncHistoryWithStore } from 'react-router-redux';
|
||||
|
||||
import { Root } from 'components';
|
||||
import { Routing, history } from './routing';
|
||||
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 { store } from './store';
|
||||
// application styles
|
||||
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 => {
|
||||
let store = configureStore();
|
||||
let syncedHistory = syncHistoryWithStore(history, store);
|
||||
render(
|
||||
<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
|
||||
import { markupToReact } from './markup';
|
||||
let activeLanguage = 'en';
|
||||
import { store } from '../store';
|
||||
let fallbackLanguage = 'en';
|
||||
let repository = {};
|
||||
|
||||
|
@ -31,11 +31,8 @@ languages.forEach(l => {
|
|||
repository[l.code] = l.data;
|
||||
});
|
||||
|
||||
export function setLanguage(code: string) {
|
||||
activeLanguage = code;
|
||||
}
|
||||
|
||||
export default function translate(key: string) {
|
||||
let activeLanguage = store.getState().config.languageSelection;
|
||||
return markupToReact(
|
||||
(repository[activeLanguage] && repository[activeLanguage][key]) ||
|
||||
repository[fallbackLanguage][key] ||
|
||||
|
|
Loading…
Reference in New Issue