-
-
Notifications
You must be signed in to change notification settings - Fork 730
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
Pluralize common variant unit names #4709
Pluralize common variant unit names #4709
Conversation
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.
It's a ingenious solution Maikel. I am just afraid this will not be easy to understand by future devs. I am not seeing a better alternative, let's go for it!
To confirm I understood correctly (this question is a sign this solution is not obvious to understand), the en.yml file will only contain the english version of the most used unit_name in all languages, right? if in Portugal we have a common unit_name "fardo", we need to add the English version "bale/bales" to en.yml and then translate, right?
Can you add a js unit test to the new js pluralizer?
I think both pluralizers (js and ruby) must be on classes of their own and not inside the option_value_namers.
config/locales/en.yml
Outdated
# puts " other: \"#{name}s\""; | ||
# } | ||
unit_names: | ||
# Used 379 times. |
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.
I dont think we need to keep these numbers in this file. The numbers are useful to see what keys to have here but we I think we should remove these "statistics" for here.
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.
Okay, I thought it could be interesting to compare if we update it one day. But I'll remove them.
# Provides efficient access to unit name inflections. | ||
# The singleton property ensures that the init code is run once only. | ||
# The OptionValueNamer is instantiated in loops. | ||
class I18nUnitNames |
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.
I think this breaks the single responsibility rule. We should have this in a separate class.
UnitNamePlural or Pluralizer or I18nUnitNames.
This (including option_value_names) should all go to something like app/services/naming
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.
I agree, I will move it.
@luisramos0 Did you see the js spec covering the pluralizer? If we move the pluralizer code (js and ruby) to their own classes, should we make the solution independent of variant_unit_name? In that case, we should not use the scope |
yeah, I'd generalize it. but only if it doesnt add even more complexity. |
@luisramos0 This is ready for review again.
|
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.
Nice, I dont think it added too much complexity from the initial solution 👍
I think we should extract pluralize from option_value_namer.js.coffee. Maybe next time around.
Otherwise, I think this is enough effort for the "small but not easy" problem we are trying to solve here.
Great job Maikel!
This adds the most popular unit names as singular and plural to our locale for translation. The added Javascript performs a reverse lookup to find the right singular/plural form of a unit name in that language.
This code will be used for the shop front and reports.
I considered moving the code to a service but I think that this code can be completely independent of the Open Food Network use case. It would be easy to move to a gem. The downcasing may need reconsidering for general use.
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.
Nice! 😄
@mkllnk I staged this on 2 different staging servers, but I still end up with an error when trying to test
I've tried this on Melon Farm and Suma Whole Foods (Cocoa powder) on Uk staging. And my latest release test Kimchi Farm 2 on staging FR |
@RachL when you change to items you must specific the variant name |
btw PR #4780 will bring meaningful error messages back to this page! |
@luisramos0 ah indeed this is working if I add a unit name before saving. 🤦♀ Moving to ready to go! |
What? Why?
Closes #4172
This adds the most popular unit names as singular and plural to our
locale for translation. The added Javascript performs a reverse lookup
to find the right singular/plural form of a unit name in that language.
I explained why I chose this solution on the issue: #4172 (comment)
What should we test?
Test in English because we haven't translated this yet.
bunch
orloaf
.0
,1
and2
of the variant and observe the change in the description.Release notes
Unit descriptions like "1 bunch" or "4 boxes" can now be translated more accurately. The previous logic would sometimes fail to find the right plural, especially in languages other than English.
Changelog Category: Changed