Skip to content

Instantly share code, notes, and snippets.

@nnarhinen
Created December 30, 2015 13:19
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nnarhinen/6ce238c7fe2b46ec7c55 to your computer and use it in GitHub Desktop.
Save nnarhinen/6ce238c7fe2b46ec7c55 to your computer and use it in GitHub Desktop.
i18n in redux react app
//omitted a lot
translations.fi().then(i18n => {
let initialState = {
locales: {
currentLocale: 'fi',
i18n
}
};
const store = am(createStore)(reducer, initialState);
const historyImpl = createBrowserHistory();
ReactDOM.render(
<Provider store={store}>
<Router history={historyImpl}>
</Router>
</Provider>
, document.getElementById('app')
);
});
import Jed from 'jed';
const promiseJed = lang => () => new Promise(resolve => {
let messages = require(`bundle?lazy!../locale/${lang}/LC_MESSAGES/messages.po`);
messages(msgs => resolve(new Jed(msgs)));
});
export default {
en: promiseJed('en'),
fi: promiseJed('fi')
};
module.exports = {
entry: {
app: './app.js'
},
module: {
//other conf
loaders: [
//other loaders
{
test: /\.jsx?$/,
exclude: /node_modules/,
loaders: [
'jsxgettext-loader?' + JSON.stringify({outputDir: './locale/templates/LC_MESSAGES', output: 'messages.pot'}),
'babel?' + JSON.stringify({presets: ['react', 'es2015']})
]
},
}
{
test: /\.po$/,
loader: 'json!po?format=jed1.x'
}]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment