Skip to content

Instantly share code, notes, and snippets.

@ooflorent
Created November 20, 2015 08:12
Show Gist options
  • Select an option

  • Save ooflorent/915b145e58bbed00623f to your computer and use it in GitHub Desktop.

Select an option

Save ooflorent/915b145e58bbed00623f to your computer and use it in GitHub Desktop.

Revisions

  1. ooflorent created this gist Nov 20, 2015.
    16 changes: 16 additions & 0 deletions configureStore.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    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
    }
    23 changes: 23 additions & 0 deletions intlActions.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    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])
    }
    22 changes: 22 additions & 0 deletions main.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    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"))
    7 changes: 7 additions & 0 deletions reducers.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    import { combineReducers } from "redux"
    import { intlStateReducer as intl } from "redux-react-intl"

    export default combineReducers({
    // Other reducers go here
    intl
    })