Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add locale.rake #717

Merged
merged 4 commits into from
Mar 1, 2017
Merged

add locale.rake #717

merged 4 commits into from
Mar 1, 2017

Conversation

JasonYCHuang
Copy link
Contributor

@JasonYCHuang JasonYCHuang commented Feb 15, 2017

Solve travis CI problem in shakacode/react-webpack-rails-tutorial#340


This change is Reviewable

@coveralls
Copy link

coveralls commented Feb 15, 2017

Coverage Status

Coverage remained the same at 99.329% when pulling 1cfc293 on JasonYCHuang:rake-locale into 2b8ee6a on shakacode:master.

@coveralls
Copy link

coveralls commented Feb 15, 2017

Coverage Status

Coverage remained the same at 99.329% when pulling b3b70ce on JasonYCHuang:rake-locale into 2b8ee6a on shakacode:master.

@justin808
Copy link
Member

@JasonYCHuang This looks fine. If we have this, then it's optional to add the locale building to the application startup. It would be really slick if we checked for the locale files being current at the same place migrations are confirmed on controller requests....

In order to merge this:

  1. Doc updates (i18n file? README?)
  2. Please see Task description containing a space after a period. ruby/rake#7 for the long description on the rake task. I'd put in a link to the i18n doc file in the GitHub repo.
  3. Changelog entry

@JasonYCHuang JasonYCHuang force-pushed the rake-locale branch 4 times, most recently from af03d3f to 1cfc293 Compare February 17, 2017 15:50
@JasonYCHuang
Copy link
Contributor Author

@justin808 I will update documents.

I am confused about Travis CI failure. It only fails in Ruby2.3.1.
So far, I didn't find any clue.
Do you have suggestions on this?

@justin808
Copy link
Member

Travis.ci is consistently failing for at least one ruby version and I just restart it for just that version.

@justin808
Copy link
Member

@JasonYCHuang See my comment above: #717 (comment)

Do you need any help from me? I'd like to wrap this one up this weekend!

@JasonYCHuang
Copy link
Contributor Author

@justin808 Yes, I need some advice.

I am going to update i18n doc.
If we will use rake task, instead of ReactOnRails::LocalesToJs.new in config/application.rb, to trigger generating locale js files, where should I put this rake script.

In package.json, we can use prebuild hook to make sure this happens before all the build, but we have several build scripts, like build:client, build:server. It is not smart to set rake task in all of them. Where should I put the task?

@JasonYCHuang
Copy link
Contributor Author

@justin808 What do you mean: Please see ruby/rake#7 for the long description on the rake task. I'd put in a link to the i18n doc file in the GitHub repo.?

Should I add more information to desc? or only add a link to i18n.md pointing this rake file?

@justin808
Copy link
Member

@JasonYCHuang I sent you invites to Screen Hero and Slack. Let's get this locale stuff resolved! Awesome work!

Should I add more information to desc? or only add a link to i18n.md pointing this rake file?
The more docs the better! Remember this is some plain text. I type rake -D and get a good description of this!

Overall:

  1. Running the build task in config/application.rb is a bit awkward for a production deploy, because the assets should have been precompiled.
  2. Yes, I think the npm scripts should be responsible for ensuring that the rake task runs at the appropriate time. Ideally, during development, we'd have a "watch" version of that task. The alternative is to have a middleware check on requests to see if the locales are outdated. Even better would be if we could have webpack ensure this! All that being said, I think the locales files will change only occasionally outside of the main language. Most of that work is done by separate teams that will do this in a batch.

http://www.marcusoft.net/2015/08/pre-and-post-hooks-for-npm-scripting.html#pre-and-post-hooks-for-custom-script

@justin808
Copy link
Member

@coveralls
Copy link

coveralls commented Feb 20, 2017

Coverage Status

Coverage remained the same at 99.329% when pulling 724eba8 on JasonYCHuang:rake-locale into b20b34d on shakacode:master.

2 similar comments
@coveralls
Copy link

Coverage Status

Coverage remained the same at 99.329% when pulling 724eba8 on JasonYCHuang:rake-locale into b20b34d on shakacode:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 99.329% when pulling 724eba8 on JasonYCHuang:rake-locale into b20b34d on shakacode:master.

When "ReactOnRails.configuration.i18n_dir" is set, it indeicates that javascript locale files are needed.
This task generates javascript locale files: `translations.js` & `default.js`.
DESC
desc "Generate i18n javascript files"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting is not right See example above in this file.

 desc << Generate i18n javascript files
This task generates javascript locale files: `translations.js` & `default.js` and places them in
the "ReactOnRails.configuration.i18n_dir".
DESC

@coveralls
Copy link

Coverage Status

Coverage remained the same at 99.329% when pulling 6f06f7f on JasonYCHuang:rake-locale into b20b34d on shakacode:master.

2 similar comments
@coveralls
Copy link

Coverage Status

Coverage remained the same at 99.329% when pulling 6f06f7f on JasonYCHuang:rake-locale into b20b34d on shakacode:master.

@coveralls
Copy link

coveralls commented Feb 21, 2017

Coverage Status

Coverage remained the same at 99.329% when pulling 6f06f7f on JasonYCHuang:rake-locale into b20b34d on shakacode:master.

@JasonYCHuang JasonYCHuang force-pushed the rake-locale branch 2 times, most recently from 1fac7bb to 23162e7 Compare February 21, 2017 13:27
@coveralls
Copy link

coveralls commented Feb 21, 2017

Coverage Status

Coverage remained the same at 99.329% when pulling 23162e7 on JasonYCHuang:rake-locale into b20b34d on shakacode:master.

@coveralls
Copy link

coveralls commented Feb 21, 2017

Coverage Status

Coverage remained the same at 99.329% when pulling 178cc72 on JasonYCHuang:rake-locale into b20b34d on shakacode:master.

@JasonYCHuang
Copy link
Contributor Author

Review status: 2 of 3 files reviewed at latest revision, 1 unresolved discussion, some commit checks failed.


docs/basics/i18n.md, line 58 at r3 (raw file):

Previously, justin808 (Justin Gordon) wrote…

assume is still mispelled

and in the react-webpack-rails-tutorial

you do a prebuild:dev

updated


Comments from Reviewable

@coveralls
Copy link

coveralls commented Feb 23, 2017

Coverage Status

Coverage remained the same at 99.329% when pulling 5f502c7 on JasonYCHuang:rake-locale into 3106b4b on shakacode:master.

@JasonYCHuang JasonYCHuang force-pushed the rake-locale branch 2 times, most recently from 4537752 to 1132e9d Compare February 27, 2017 13:02
@coveralls
Copy link

Coverage Status

Coverage remained the same at 99.329% when pulling 27fc9be on JasonYCHuang:rake-locale into 8e47c79 on shakacode:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage remained the same at 99.329% when pulling 27fc9be on JasonYCHuang:rake-locale into 8e47c79 on shakacode:master.

@coveralls
Copy link

coveralls commented Feb 27, 2017

Coverage Status

Coverage remained the same at 99.329% when pulling cb75a4f on JasonYCHuang:rake-locale into 8e47c79 on shakacode:master.

@JasonYCHuang
Copy link
Contributor Author

No pre-hook needed in package.json

  1. to get js locale files in dev: https://github.com/shakacode/react_on_rails/pull/717/files#diff-51a05a5d3f0a0c62b9452b7596e2a82cR2

  2. to get js locale files in test & production: https://github.com/shakacode/react_on_rails/pull/717/files#diff-52cfe83d7f9f1c952a7995dfb0f99341R53

  3. Since config.i18n_dir will be the key to decide whether to generate locale files or not, I comment it for default. When users need i18n, they need to uncomment it. https://github.com/shakacode/react_on_rails/pull/717/files#diff-391d7a2ed038bee9f49a7e7adefc133eR66


Review status: 1 of 6 files reviewed at latest revision, 1 unresolved discussion.


Comments from Reviewable

@justin808
Copy link
Member

Very nice.

For testing, we should have a call to generate the i18n task here:

https://github.com/shakacode/react_on_rails/blob/master/lib/react_on_rails/test_helper/ensure_assets_compiled.rb#L29


Reviewed 1 of 1 files at r5, 3 of 5 files at r6, 2 of 2 files at r7.
Review status: all files reviewed at latest revision, 5 unresolved discussions.


CHANGELOG.md, line 10 at r7 (raw file):

### 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).

Allow using rake task to generate javascript locale files. The test helper automatically creates the localization files when needed.


docs/basics/i18n.md, line 49 at r7 (raw file):

4. Javascript locale files must be generated before `yarn build`. 
  
  Once you setup `config.i18n_dir` as in the previous step, react_on_rails will help you to do this.

for testing and for production deployments. For development, you should adjust your Procfiles so that they run bundle exec rake react_on_rails:localebefore running theyarn run build:development` (webpack watch process)


lib/generators/react_on_rails/templates/base/base/Procfile.dev.tt, line 2 at r7 (raw file):

web: rails s -p 3000
client: sh -c 'rm app/assets/webpack/* || true && cd client && bundle exec rake react_on_rails:locale && yarn run build:development'

nice! Did you try the generator?


lib/tasks/assets.rake, line 53 at r7 (raw file):

sh "cd client && `ReactOnRails.configuration.npm_build_production_command`"
    DESC
    task webpack: :locale do

Nice!


Comments from Reviewable

@JasonYCHuang
Copy link
Contributor Author

done


Review status: 4 of 7 files reviewed at latest revision, 4 unresolved discussions.


CHANGELOG.md, line 10 at r7 (raw file):

Previously, justin808 (Justin Gordon) wrote…

Allow using rake task to generate javascript locale files. The test helper automatically creates the localization files when needed.

done


docs/basics/i18n.md, line 49 at r7 (raw file):

Previously, justin808 (Justin Gordon) wrote…

for testing and for production deployments. For development, you should adjust your Procfiles so that they run bundle exec rake react_on_rails:localebefore running theyarn run build:development` (webpack watch process)

done


lib/generators/react_on_rails/templates/base/base/Procfile.dev.tt, line 2 at r7 (raw file):

Previously, justin808 (Justin Gordon) wrote…

nice! Did you try the generator?

yes, I create a new rails project and install react_on_rails. It looks good.


Comments from Reviewable

@justin808
Copy link
Member

:lgtm:

@JasonYCHuang Please confirm that you manually verified checking the locales files works in the test helper and I'll merge.


Reviewed 4 of 4 files at r8.
Review status: all files reviewed at latest revision, 3 unresolved discussions, some commit checks failed.


lib/generators/react_on_rails/templates/base/base/Procfile.dev.tt, line 2 at r7 (raw file):

Previously, JasonYCHuang (Jason Huang) wrote…

yes, I create a new rails project and install react_on_rails. It looks good.

fabulous.


lib/react_on_rails/test_helper/ensure_assets_compiled.rb, line 30 at r8 (raw file):

        self.class.has_been_run = true

        ReactOnRails::LocalesToJs.new if ReactOnRails.configuration.i18n_dir.present?

This is awesome.

@robwise are you OK with us not adding a test here: https://github.com/shakacode/react_on_rails/blob/master/spec/react_on_rails/test_helper/ensure_assets_compiled_spec.rb#L8


Comments from Reviewable

@robwise
Copy link
Contributor

robwise commented Feb 28, 2017

Review status: all files reviewed at latest revision, 3 unresolved discussions, some commit checks failed.


lib/react_on_rails/test_helper/ensure_assets_compiled.rb, line 30 at r8 (raw file):

Previously, justin808 (Justin Gordon) wrote…

This is awesome.

@robwise are you OK with us not adding a test here: https://github.com/shakacode/react_on_rails/blob/master/spec/react_on_rails/test_helper/ensure_assets_compiled_spec.rb#L8

I would definitely write a test if you are introducing new logic


Comments from Reviewable

@JasonYCHuang
Copy link
Contributor Author

Yes, I manually run ReactOnRails::TestHelper::EnsureAssetsCompiled.new.call under rails console. Local files will be generated when config.i18n_dir is set.


Review status: 7 of 8 files reviewed at latest revision, 3 unresolved discussions.


Comments from Reviewable

@justin808 justin808 merged commit b966f8b into shakacode:master Mar 1, 2017
justin808 pushed a commit to shakacode/react-webpack-rails-tutorial that referenced this pull request Mar 2, 2017
@JasonYCHuang JasonYCHuang deleted the rake-locale branch March 6, 2017 17:02
@JasonYCHuang JasonYCHuang restored the rake-locale branch March 6, 2017 17:02
ryanbelke pushed a commit to ryanbelke/rails-react-yourtime that referenced this pull request Jan 4, 2019
joseph0919 pushed a commit to joseph0919/React_Webpack_Rails_Tutorial that referenced this pull request May 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants