BazingaJsTranslationBundle
BazingaJsTranslationBundle copied to clipboard
Integration with React, Redux and Webpack
I would like to integrate this solution with React and Redux. Is there any possibility to change the current solution so it can be more adaptable to other libraries / frameworks?
The current solution uses an object to store all the messages, but I would like to have the messages stored in a React component state or in the Redux store. And would also prefer to import this as a module instead of a global variable.
Thank you!
It is really not the purpose of this bundle because the Translator
is a JS implementation of the Symfony translator. It does not only expose messages to JS, it provides a very similar "Symfony experience" for translations in JS, so it is not really possible to "have the messages stored in a React component state".
It is however possible to import the Translator
as a module (it supports AMD for instance), it is already a plain old JS module actually. You can configure Webpack too. The JS lib integrates well with many frameworks, including Backbone and Ember.
So question is, what would you do?
Got the same problem, mainly because the dump command regenerates some file without requiring Translator but using it as a global variable.
I solved this like this:
resolve: {
alias: {
translator: path.join(__dirname, './vendor/willdurand/js-translation-bundle/Bazinga/Bundle/JsTranslationBundle/Resources/public/js/translator.min.js'),
},
},
plugins: [
new webpack.ProvidePlugin({
Translator: 'translator',
}),
]
What could be done though is adding a way to configure the translation files to be a JS module too.