diff --git a/CHANGELOG.md b/CHANGELOG.md index 8332d59976..1da8dfdb1c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ Contributors: please follow the recommendations outlined at [keepachangelog.com] ## [Unreleased] *Please add entries here for your pull requests.* +### Added +- Allow using rake task to generate javascript locale files. [#717](https://github.com/shakacode/react_on_rails/pull/717) by [JasonYCHuang](https://github.com/JasonYCHuang). + ## [6.6.0] - 2017-02-18 ### Added - Switched to yarn! [#715](https://github.com/shakacode/react_on_rails/pull/715) by [squadette](https://github.com/squadette). diff --git a/docs/basics/i18n.md b/docs/basics/i18n.md index 12a29f78f6..767c01652d 100644 --- a/docs/basics/i18n.md +++ b/docs/basics/i18n.md @@ -44,17 +44,32 @@ You can refer to [react-webpack-rails-tutorial](https://github.com/shakacode/rea config.i18n_dir = Rails.root.join("PATH_TO", "YOUR_JS_I18N_FOLDER") ``` - Add following lines to `config/application.rb`, this will help you to generate `translations.js` & `default.js` automatically when you starts the server. +4. Javascript locale files must be generated before `npm build`. - ```js - module YourModule - class Application < Rails::Application + To ensure this: + + For __test__ and __production__, add `pre-hook` into `client/package.json` to invoke build-in rake task. + + ```javascript + { + ... + "scripts": { + ... + // Assume that the following two lines are your original build script. + "build:test": "webpack --config webpack.config.js", + "build:production": "NODE_ENV=production webpack --config webpack.config.js", + // You need to add pre-hook for them. + "prebuild:test": "rake react_on_rails:locale", + "prebuild:production": "rake react_on_rails:locale", ... - config.after_initialize do - ReactOnRails::LocalesToJs.new - end - end - end + } + } + ``` + + For __dev__, add `bundle exec rake react_on_rails:locale` to `Procfile.dev` before `npm build`. + + ```ruby + client: sh -c 'rm app/assets/webpack/* || true && bundle exec rake react_on_rails:locale && cd client && npm run build:development' ``` 5. In React, you need to initialize `react-intl`, and set parameters for it.