plots2
plots2 copied to clipboard
Two translation helper errors on profile pages (one left)
The Translation helper is supposed to insert a little globe icon for some users, where you can contribute missing translations.
Learn about the translation system at:
- https://publiclab.org/wiki/translation
- https://github.com/publiclab/plots2/blob/main/doc/Translation_System.md
Unfortunately it is broken in a few places:

To see this yourself, you have to log in, join the translation team at https://publiclab.org/wiki/translation, and visit https://publiclab.org/profile/warren or another profile page.
What's wrong?
Note that to the right side it says Joined %{time_ago} - something must be going wrong with this line of code:
https://github.com/publiclab/plots2/blob/7de0bb0eab2e7e63d0143244b76c211f4498d042/app/views/users/profile.html.erb#L63
Also, in the left column under "Remembering Tonawanda" it says:
{:one=>"1 note", :other=>"%{count} notes"} | {:one=>"1 question", :other=>"%{count} questions"} | {:one=>"1 comment", :other=>"%{count} comments"} by @warren
That leads to this line of code:
https://github.com/publiclab/plots2/blob/7de0bb0eab2e7e63d0143244b76c211f4498d042/app/views/tag/_profileCard.html.erb#L27-L30
There, I think we are passing back a hash instead of a number... somehow we're misusing the helper, which can be found here:
https://github.com/publiclab/plots2/blob/a54bf46102c1951734ab94966b4f9e867b0b2762/app/helpers/application_helper.rb#L157-L170
This is a pretty complex pair of issues. I'm not sure how easy they will be to fix -- so we're hoping for someone with a little Ruby experience to help out here! Thanks!
@jywarren I am unable to see this error on https://publiclab.org/profile/warren (screenshot below), even though I've joined the translation team.

@KarishmaVanwari You need to change the site's language to one that doesn't have a lot of translations. For example: Deutsch
Okay, thank you @TildaDares
Hey @TildaDares, can I try my hands on this issue?
Go ahead @KarishmaVanwari
Hi @KarishmaVanwari how did that go, were you able to reproduce this? I can try to help if not!
Hey @jywarren, I was still unable to reproduce the error, could you please help me out?
@KarishmaVanwari Was if on the live site or your local environment that you couldn’t reproduce the bug?
@TildaDares On the live site. I've successfully reproduced the bug locally.
Hi @jywarren, @KarishmaVanwari, distance_of_time_in_words can translate on its own when you pass in the scope method. So we don't need to pass that method into the translate function. I created an FTO to fix that in #10849. Also, some of the translation file keys use distance_in_words instead of time_ago_in_words so I created an issue in #10850 to resolve that too. I think when these issues are resolved, the first translation problem will be solved.
@KarishmaVanwari I think with this solution you should be able to resolve the second error.
Great work figuring this all out! Very much appreciated @TildaDares and @KarishmaVanwari 🎉
Just noting that the topic card bug shown here is now resolved in stable:
The second bug, near "Joined" is also resolved!
Thank you all very much for your help!!!
Hi @KarishmaVanwari - I noticed this small error on profile pages with translations: https://publiclab.org/profile/carmen2x

I think it's returning a more structured associative array (or hash, i think the Ruby term is) of counts per type, instead of just a number. The code is here:
https://github.com/publiclab/plots2/blame/main/app/views/tag/_profileCard.html.erb#L27-L29
I'm not sure we fixed that one... @TildaDares what do you think? Maybe when I confirmed it in stable, it didn't have a translation turned on? Stable is offline right now but will be back up pretty soon so we can check, but locally we can check by changing the language and looking at that page.
If the issue persists, I think we may need to do something like: translation(...)[:one] -- but maybe something more complicated with pluralization is going on -- maybe it'll take a little experimenting to get it right.
@jywarren I think that line works fine, it's a lack of translation for those phrases that causes that issue. If you change the language to French, everything works great and that's because we only have translations for those phrases in French.
https://github.com/publiclab/plots2/blob/112f78925df2c03f5422179f4572210781035006/config/locales/fr.yml#L342-L350
That was the same thing that happened to the joined error I fixed earlier.
Ah, thanks @TildaDares and sorry to miss this. I think we need to fix the logic for when there is no translation:
https://github.com/publiclab/plots2/blob/3b7222e5655e41ea4e7102ddbdcb1510932b6228/app/views/tag/_profileCard.html.erb#L27-L29
See how it looks here: