rxaviers / react-globalize-webpack-plugin

react-globalize webpack plugin
Other
3 stars 8 forks source link

Production: Auto-generate the translation files #2

Open rxaviers opened 9 years ago

rxaviers commented 9 years ago

Goal

On production, when Globalize webpack plugin is generating the translation chunks, i.e., when globalize-before-compile-extracts is called with request === undefined, we generate the translation JSON files. Note, the files can be generated asynchronously and independently of the ongoing webpack workflow.

When locale === attributes.developmentLocale, use globalizeCompiler.generateDefaultTranslation to generate the base language JSON file. Otherwise, use globalizeCompiler.initOrUpdateTranslation to manage the other files.

Expect the translation filepath to be passed by attributes.messages (similar to this). The filepaths for the various locales is deduced by replacing the [locale] part.

Requirements:

alunny commented 9 years ago

Implementation idea sounds good - looks like much of it is in commented out form here: https://github.com/rxaviers/react-globalize-webpack-plugin/blob/master/ProductionModePlugin.js#L120

It might be good to have a callback/hook for manipulating the JSON object before it's written out. In our case, the translation files look like:

{
  "en": {
    "hello world": "hello world"
  }
}

instead of

{
  "hello world": "hello world"
}
rxaviers commented 9 years ago

It might be good to have a callback/hook for manipulating the JSON object before it's written out. In our case, the translation files look like:

Sounds good to me. I guess, then, you'll need a hook to convert after it's read in and before it's written out.

What do you think of first implementing this without the hook and then in a subsequent PR include the hooks?

alunny commented 9 years ago

Implementing without a hook sounds like a good start.

I actually think, if the phrase extraction doesn't take too long, it would be good to extract the default messages in development mode as well as production. This means that engineers can't accidentally commit code that introduces new messages without changing the default messages file (unless they didn't execute the code at all). That way, a CI hook can just watch messages/[defaultLocale].json for changes, and send things off to a translation service.

(the development thing would be a further enhancement, not part of this issue).