BazingaJsTranslationBundle icon indicating copy to clipboard operation
BazingaJsTranslationBundle copied to clipboard

Integration with React, Redux and Webpack

Open ghost opened this issue 8 years ago • 3 comments

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!

ghost avatar Jun 09 '16 12:06 ghost

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?

willdurand avatar Jun 09 '16 13:06 willdurand

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',
  }),
]

jdeniau avatar Nov 17 '16 10:11 jdeniau

What could be done though is adding a way to configure the translation files to be a JS module too.

stof avatar Nov 17 '16 10:11 stof