Skip to content

Instantly share code, notes, and snippets.

@ooflorent
Created November 20, 2015 08:12
Show Gist options
  • Save ooflorent/915b145e58bbed00623f to your computer and use it in GitHub Desktop.
Save ooflorent/915b145e58bbed00623f to your computer and use it in GitHub Desktop.
import { applyMiddleware, compose, createStore } from "redux"
import { reduxReactIntl } from "redux-react-intl"
import thunk from "redux-thunk"
import rootReducer from "./reducers"
const createStoreFactory = compose(
applyMiddleware(thunk),
reduxReactRouter({ routes, createHistory })
)
const finalCreateStore = createStoreFactory(createStore)
export default function configureStore(initialState) {
const store = finalCreateStore(rootReducer, initialState)
return store
}
import { setIntlState } from "redux-react-intl"
import { addLocaleData } from "react-intl"
import __intlEN from "react-intl/lib/locale-data/en"
import __intlFR from "react-intl/lib/locale-data/fr"
addLocaleData(__intlEN)
addLocaleData(__intlFR)
import localeEN from "translations/en.json"
import localeFR from "translations/fr.json"
function compileLocale(locale, { messages, formats = {} }) {
return { locale, messages, formats }
}
const LOCALES = {
"en": compileLocale("en", localeEN),
"fr": compileLocale("fr", localeFR),
}
export function setLocale(locale) {
return setIntlState(LOCALES[locale])
}
import React from "react"
import { render } from "react-dom"
import { Provider } from "react-redux"
import { ReduxIntl } from "redux-react-intl"
import { setLocale } from "./intlActions"
import configureStore from "./configureStore"
const store = configureStore()
store.dispatch((dispatch) => {
dispatch(setLocale("fr"))
})
const app = (
<Provider store={ store }>
<ReduxIntl>
{/* Your app, or router */}
</ReduxIntl>
</Provider>
)
render(app, document.getElementById("root"))
import { combineReducers } from "redux"
import { intlStateReducer as intl } from "redux-react-intl"
export default combineReducers({
// Other reducers go here
intl
})
@nicolechung
Copy link

I have some questions:

  1. reduxReactIntl in configureStore.js doesn't appear to be used in this file?
  2. where does intlActions.js go since I don't see it being imported into any of the files above?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment