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

Two translation helper errors on profile pages (one left) #10765

Open
jywarren opened this issue Mar 8, 2022 · 15 comments
Open

Two translation helper errors on profile pages (one left) #10765

jywarren opened this issue Mar 8, 2022 · 15 comments
Labels
bug the issue is regarding one of our programs which faces problems when a certain task is executed hard help wanted requires help by anyone willing to contribute Ruby Translation System issues which involve adding new translations, improving the translation system

Comments

@jywarren
Copy link
Member

jywarren commented Mar 8, 2022

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:

Unfortunately it is broken in a few places:

image

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:

<span style = "font-size:24px;"><small> <%= raw translation('users.profile.joined_time_ago', :time_ago => distance_of_time_in_words(@profile_user.created_at, Time.current, { include_seconds: false, scope: 'datetime.time_ago_in_words' })) %></small></span>

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:

<a href="/tag/<%= tag.name %>/author/<%= @profile_user.name %>"><%= translation('tag.index.notes', count: Node.find_by_tag_and_author(tag.name, @profile_user.id, 'notes').size) %></a> |
<a href="/questions/tag/<%= tag.name %>/author/<%= @profile_user.name %>"><%= translation('tag.index.questions', count: Node.find_by_tag_and_author(tag.name, @profile_user.id, 'questions').size) %></a> |
<a href="/profile/comments/<%= @profile_user.name %>/tag/<%= tag.name %>"><%= translation('tag.index.comments', count: Comment.find_by_tag_and_author(tag.name, @profile_user.id).size) %></a>
by @<%= @profile_user.name %>

There, I think we are passing back a hash instead of a number... somehow we're misusing the helper, which can be found here:

def translation(key, options = {}, html = true)
translated_string = t(key, options)
options[:fallback] = false
translated_string2 = t(key, options)
english_translation = t(key, locale: :en)
if html && current_user&.has_tag('translation-helper') && (translated_string2.include?("translation missing") || translated_string === "") && !translated_string.include?("<")
raw(%(<span>#{english_translation} <a class="translationIcon" style='display: none; padding-left: 3px;' href="https://www.transifex.com/publiclab/publiclaborg/translate/#de/$?q=text%3A#{translated_string}">
<i data-toggle='tooltip' data-placement='top' title='Needs translation? Click to help translate the text \" #{translated_string} \" .' style='position:relative; right:2px; color:#bbb; font-size: 15px;' class='fa fa-globe'></i></a>
</span>))
else
raw(translated_string)
end
end

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 jywarren added bug the issue is regarding one of our programs which faces problems when a certain task is executed hard Ruby Translation System issues which involve adding new translations, improving the translation system labels Mar 8, 2022
@KarishmaVanwari
Copy link
Contributor

@jywarren I am unable to see this error on https://publiclab.org/profile/warren (screenshot below), even though I've joined the translation team.
image

@TildaDares
Copy link
Member

@KarishmaVanwari You need to change the site's language to one that doesn't have a lot of translations. For example: Deutsch

@KarishmaVanwari
Copy link
Contributor

Okay, thank you @TildaDares

@KarishmaVanwari
Copy link
Contributor

Hey @TildaDares, can I try my hands on this issue?

@TildaDares
Copy link
Member

Go ahead @KarishmaVanwari

@jywarren
Copy link
Member Author

Hi @KarishmaVanwari how did that go, were you able to reproduce this? I can try to help if not!

@KarishmaVanwari
Copy link
Contributor

Hey @jywarren, I was still unable to reproduce the error, could you please help me out?

@TildaDares
Copy link
Member

@KarishmaVanwari Was if on the live site or your local environment that you couldn’t reproduce the bug?

@KarishmaVanwari
Copy link
Contributor

@TildaDares On the live site. I've successfully reproduced the bug locally.

@TildaDares
Copy link
Member

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.

@jywarren
Copy link
Member Author

Great work figuring this all out! Very much appreciated @TildaDares and @KarishmaVanwari 🎉

@jywarren
Copy link
Member Author

Just noting that the topic card bug shown here is now resolved in stable:

image

The second bug, near "Joined" is also resolved!

image

Thank you all very much for your help!!!

@jywarren
Copy link
Member Author

Hi @KarishmaVanwari - I noticed this small error on profile pages with translations: https://publiclab.org/profile/carmen2x

image

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 jywarren reopened this Jun 23, 2022
@TildaDares
Copy link
Member

@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.

notes:
one: "1 note"
other: "%{count} notes"
questions:
one: "1 question"
other: "%{count} questions"
comments:
one: "1 commentaire"
other: "%{count} commentaires"

That was the same thing that happened to the joined error I fixed earlier.

@jywarren
Copy link
Member Author

jywarren commented Aug 2, 2022

Ah, thanks @TildaDares and sorry to miss this. I think we need to fix the logic for when there is no translation:

<a href="/questions/tag/<%= tag.name %>/author/<%= @profile_user.name %>"><i class="fa fa-question-circle"></i>&nbsp;<%= translation('tag.index.questions', count: Node.find_by_tag_and_author(tag.name, @profile_user.id, 'questions').size) %></a> |
<a href="/profile/comments/<%= @profile_user.name %>/tag/<%= tag.name %>"><i class="fa fa-comments"></i>&nbsp;<%= translation('tag.index.comments', count: Comment.find_by_tag_and_author(tag.name, @profile_user.id).size) %></a>
by @<%= @profile_user.name %>

See how it looks here:

image

@jywarren jywarren changed the title Two translation helper errors on profile pages Two translation helper errors on profile pages (one left) Aug 2, 2022
@jywarren jywarren added the help wanted requires help by anyone willing to contribute label Aug 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug the issue is regarding one of our programs which faces problems when a certain task is executed hard help wanted requires help by anyone willing to contribute Ruby Translation System issues which involve adding new translations, improving the translation system
Projects
None yet
Development

No branches or pull requests

3 participants