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
Uk/1562 add i18n js gem #1564
Uk/1562 add i18n js gem #1564
Conversation
Nice! 👏 |
@enricostano you ok to review this before we push it over to Australia for final test/merge? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Hey @oeoeaio I reckon this one is going to be a quick push through yourself and Sally to get it merged. Will leave you to it :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this PR I see a lot of cases where we try implementing something one way and then switch to doing it another way in a later commit. To me that reads a bit like research / experimentation rather than building. That's a necessary and important part about developing something, but a side-effect is that any developer looking back on this feature will have to understand all the side investigations to understand what's going on in the feature. We'd like to make it as easy as possible for other people to look over this code and understand what's going on.
To achieve that, sometimes in this situation I'd recommend editing the git history to clean up a few things. But in this case there are several changes happening in each commit, which makes it harder to work with. Therefore, it seems like it'd be quicker to treat this branch as a spike and re-implement it fresh in another branch. With the knowledge developed in this one I expect it would fall out quite quickly.
Thanks for all your work on this one, and sorry to add more to your plate. Let me know if you have any questions!
text = text.split("%{#{name}}").join(value) | ||
text | ||
I18n.t(key, options) | ||
# dict = I18n |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Committed comments later removed.
@@ -9,6 +9,7 @@ | |||
remove_method :options_text if instance_methods(false).include? :options_text | |||
include OpenFoodNetwork::VariantAndLineItemNaming | |||
|
|||
acts_as_taggable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this belong in this commit (or even this PR)? It seems like it might be a separate concern.
@@ -9,7 +9,6 @@ | |||
remove_method :options_text if instance_methods(false).include? :options_text | |||
include OpenFoodNetwork::VariantAndLineItemNaming | |||
|
|||
acts_as_taggable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aha, I see that this has been removed. In this sort of case I'd recommend editing history to remove the introduction in the first place. But see above for comments about treating this as a spike.
config/application.rb
Outdated
@@ -108,7 +109,5 @@ class Application < Rails::Application | |||
config.assets.precompile += ['qz/*'] | |||
|
|||
config.active_support.escape_html_entities_in_json = true | |||
|
|||
config.middleware.use I18n::JS::Middleware |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line was added and then removed - I take it that we don't need it? In this sort of case I'd recommend editing history to remove the introduction in the first place. But see above for comments about treating this as a spike.
config/i18n-js.yml
Outdated
@@ -1,35 +0,0 @@ | |||
# Split context in several files. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change looks like another case of trying one approach in one commit, then switching to another in a later commit. See above for comments about treating this PR as a spike.
@@ -13,6 +13,7 @@ | |||
//= require textAngular-sanitize.min.js | |||
//= require textAngular.min.js | |||
//= require moment | |||
//= require i18n |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this change related to Karma? If not, I'd suggest moving this change to a separate commit. But see above for comments about treating this as a spike.
@RohanM, You are totally right it felt like a spike :) At some point it felt right to leave it with that commit history as it would help to understand what is necessary to use from gem's documentation. But apparently not. Fair enough :) |
@RohanM Are you happy to sign this off now ready for merge at next opportunity? |
Hi @jeronimo, Unfortunately, squashing the commits puts the entire 22 file, 150 line diff in a single commit - that's too much code for someone to easily absorb, especially when that one commit is accomplishing many distinct things. Having the code in one commit obscures the steps that went into achieving the feature. Additionally, in the future we might discover a problem that involves this code. If it's in a single commit, the we're not able to use Because of those reasons, it's useful to break the code down into smaller commits (both for a reviewer and for any future developers who might work with this code). Preferably each commit introduces one part of the change, comes with its own specs, and those specs pass. That way a developer can read the commit message and glance at the code and confirm that the code does indeed do what the commit message says. And because the specs build green at most if not all commits along the way, we can bisect over it and get useful results. Finally, a comment on the situation where a branch is broken down into multiple commits but changes one thing and then changes it back later. Although this can be useful in describing the process taken to arrive at a feature, it can result in unnecessary conflicts when rebasing. And when multiple changes back and fourth are combined in a single commit, it can be hard to pick apart what's happening. So I'd see this situation as a trade-off, and unless I really wanted to illustrate a path that didn't work out, I'd tend to the side of simply removing those changes from the code, and writing about it in the PR description (which a future developer could look up from the merge commit). For those reasons, would you be able to rewrite this PR step by step? |
@RohanM, actually I do not agree. Nearly 60% of added code is test coverage. 20% of code is a workaround until Spree gets upgrade. The rest of the code is used from Rails guides and READMEs and this whole commit is like a small feature, which is great for But, if you still do think it is necessary to split, maybe you could give an example with this code for the future reference we could follow? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @jeronimo. I agree with Rohan that smaller commits are easier to read. Your commit is not huge, but it could be nicer. Below I commented on a few things that could be separated, in my opinion. Ideally, you read one commit at a time like pages of a book. And that includes test cases.
Anyway, that's great work. I have a question. We include all supported translations in all.js
, right? Can you tell how big each locale is? How much longer does it need to load with e.g. five locales?
I had in mind that each locale might be available as separate js file (except the default locale). Each user wouldn't need to load all the unused locales then. I'm just imagining a platform that wants to support a lot of languages.
@@ -4,6 +4,7 @@ ruby "2.1.5" | |||
gem 'rails', '3.2.21' | |||
gem 'rails-i18n', '~> 3.0.0' | |||
gem 'i18n', '~> 0.6.11' | |||
gem 'i18n-js', '~> 3.0.0' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding a gem can be in a single commit.
config/application.rb
Outdated
@@ -71,6 +71,7 @@ class Application < Rails::Application | |||
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. | |||
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] | |||
config.i18n.default_locale = ENV["LOCALE"] | |||
config.i18n.available_locales = ENV["AVAILABLE_LOCALES"].andand.split(',').andand.map(&:strip) || [config.i18n.default_locale] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Support for multiple locales can be seen as a feature on it's own. It can be in a separate commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow. This is much easier to read. Excellent.
# no: "No" | ||
# yes: "Yes" | ||
# Which become to true and false and those have no #to_sym method | ||
# TODO - remove this after spree core locales are fixed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great. This way it will be super easy to see what needs to be changed after the Spree upgrade.
I think before we merge this, we need to update our deploy scripts. @jeronimo Have a look at: https://github.com/openfoodfoundation/ofn-install/blob/master/roles/app/templates/post-receive.j2 We need to add the line: $BUNDLE exec rake tmp:cache:clear Can that happen any time or do we need to do it before the asset compilation? |
@mkllnk It seems it has to be before Note: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great. This is ready for testing now.
This makes sure there is a value in `config.i18n.available_locales` so that i18n-js doesn't crash.
@sstead This adds a feature to provide more than one language. Currently, our staging server is configured to show only English. Nothing should change. And we don't have a UI element for language switching yet. That comes later. |
Looks fine. |
Great work @jeronimo. I needed to add a fall-back strategy for old |
Task - #1562
Comments on steps:
Did not create precompiled separate files because:
config.i18n.available_locales
translations are not that big anymore.It falls back to default translation and doesn't break javascript. The problem is still with back-end translations inside
placeholders
for input fields if translation is still missing.