Closed myriamboure closed 4 years ago
I investigated this curious bug.
We have duplicated code to define display_as value of variants, it's called option_value_namer.
We have a version in ruby on the backend and a very similar (must have been copied) version of it in angular 🤕 Ruby: http://github.com/openfoodfoundation/openfoodnetwork/tree/master/lib/open_food_network/option_value_namer.rb Angular: https://github.com/openfoodfoundation/openfoodnetwork/blob/master/app/assets/javascripts/admin/products/services/option_value_namer.js.coffee
The problem is that they are not exactly the same, i.e., the required pluralization is only done on the Ruby code. We must have been using the ruby code before and now we are using the angular code (I confirmed that we are indeed using the angular code now).
There's a TODO entry to add pluralization to the angular code: that's exactly what this issue is!
I am tagging this a good first issue, note: javascript/coffeescript
I was trying to find a way to make this pluralized unit name come from the server again and remove this code but it's too much trouble, it's complicated. I think we can just add the pluralization logic to the angular code as is. Maybe we can use this library: https://github.com/blakeembrey/pluralize
Hm, that pluralize library seems to only know English. Trying to apply English pluralisation rules to German words would make this worse.
Using server side translations may not help either:
You must define your own inflection rules for languages other than English. https://api.rubyonrails.org/classes/String.html
I had a good look into this and found:
My conclusions are that we can't rely on a library to get this right and that it may be harmful if it tries to pluralise things it doesn't know. Requiring a developer to program new inflection rules or add irregular words is too much maintenance for this little feature.
I came up with a relatively simple way to manage plurals within Transifex. We take the most popular unit names and add them to our language file as singular and plural. Both singular and plural can then get translated. Our code can look up if a unit name is in the dictionary and choose the right word. If it doesn't find it in the dictionary, it just leaves it as is.
@RachL
I extracted all used unit names from the French server. Can you check which ones are the most important to be pluralised? We can then cross-check with the English words to see if we need to add more.
I realised that the Javascript is only used for the preview how the unit will be displayed. The result is not saved and not used in the shop or reports. The similar Ruby code is doing that and it hasn't been very good at that. For example, it's wrong in German:
It should say 30 Stück
or 30 Stücke
but not 30 Stücks
. That's not a word. So, in order to be consistent, we need a solution for Ruby and Javascript. I included that in my pull request.
@mkllnk here they are with their plural:
"pièce"=> pièces "paquet"=> paquets "pot"=> pots "botte"=> bottes "bouteille"=>bouteilles "flacon"=> flacons "Pièce"=> Pièces "sachet"=> sachets "panier"=> paniers "boite"=> boites "sac"=>sacs "bouquet"=> bouquets "Botte"=> Bottes "bocal"=> bocaux "Panier"=> Paniers "caisse"=> caisses "barquette"=> barquettes "unité"=> unités "boîte"=> boîtes
Ah, great @RachL. Can you also tell me what the English translation is?
@mkllnk
hehe I even learned a few things :)
"pièce"=> pièces pieces "paquet"=> paquets pack "pot"=> pots pot => but the stuff you use to put cream or plant inside, not the second meaning right ;) "botte"=> bottes bundles "bouteille"=>bouteilles bottles "flacon"=> flacons flacks "Pièce"=> Pièces pieces "sachet"=> sachets bags "panier"=> paniers baskets "boite"=> boites boxes "sac"=>sacs bags "bouquet"=> bouquets bunch "Botte"=> Bottes bundles "bocal"=> bocaux jars "Panier"=> Paniers baskets "caisse"=> caisses crates "barquette"=> barquettes trays "unité"=> unités units "boîte"=> boîtes boxes
@RachL
"flacon"=> flacons flacks
Do you mean flask?
@mkllnk ahem. Yes. 🤦♂
Description
I remember that before v2, when a product was sold per "item", if the variant was for example "2 items", and the name of the item was "piece", it was displayed as "2 pieces" by default (with a s for plural). It is not anymore in v2.
Expected Behavior
If sold per item, if quantity more than 1, plural should be applied automatically
Actual Behaviour
It is not
Steps to Reproduce
Animated Gif/Screenshot
Context
I saw that when doing customer support via skype screen sharing and noticed it.
Severity
bug-s3: a feature is broken but there is a workaround : we can manually write the display as field but we need to do it for every plural quantity, need to think about it...
Your Environment
Possible Fix