-
Notifications
You must be signed in to change notification settings - Fork 50
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
FIX: Ensure old feature works with new and show translate button in correct scenarios #215
Conversation
spec/lib/guardian_extension_spec.rb
Outdated
expect(guardian.can_translate?(post)).to eq(true) | ||
end | ||
|
||
it "can translate when post does not have translation" do |
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.
The setup for this test is exactly the same as the test before it. I think the set up for this test should be clearing out the post's translation?
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.
The post will not have translation if I don't explicitly add post.set_translation(locale, text)
It's exactly the same setup, but my intent is that the test description is the documentation of the behaviour not the implementation.
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.
Thank you for clarifying 👍 Perhaps we can just combine the two test cases into one? Technically we can only translate when post's detected locale does not match i18n locale and also when the post does not have translation.
Might also be useful to assert that the post cannot be translated when the post's translation is present for the given 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.
the post cannot be translated when the post's translation is present for the given locale
Actually, "can_translate" is the bool that determines if the 🌐 appears on the post.
(Old feature) If the translation exists for the locale, the value should still be true, since the user will click on 🌐 and we will return the existing translation to the user. This is the old feature that we need to maintain, where viewing translations are manual, not the new feature where it is automatically rendered by default.
old feature
![Screenshot 2025-02-18 at 2 44 32 PM](https://private-user-images.githubusercontent.com/1555215/414126103-ed2b78c3-4661-4513-933f-bc10368241f6.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NDAxMjAxNzQsIm5iZiI6MTc0MDExOTg3NCwicGF0aCI6Ii8xNTU1MjE1LzQxNDEyNjEwMy1lZDJiNzhjMy00NjYxLTQ1MTMtOTMzZi1iYzEwMzY4MjQxZjYucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIyMSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMjFUMDYzNzU0WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9MTY1NzA2ODAzYzA0NWRjZjMyMjcxY2YwNDhhZmQyMjM3YzU3NzZkY2U1NmMxMzgxOTU5ZTBlZDFiNjlmZjU5ZSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.OZxvf0TBRx9RMnx8yw1jUVTZSB2PAFsPl_06gRrzZ4I)
new experimental feature
![Screenshot 2025-02-18 at 2 47 33 PM](https://private-user-images.githubusercontent.com/1555215/414127056-abc1b620-b260-4f42-a3fd-398164eeded5.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NDAxMjAxNzQsIm5iZiI6MTc0MDExOTg3NCwicGF0aCI6Ii8xNTU1MjE1LzQxNDEyNzA1Ni1hYmMxYjYyMC1iMjYwLTRmNDItYTNmZC0zOTgxNjRlZWRlZDUucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIyMSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMjFUMDYzNzU0WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9NzBjZWFkMWUxMzhjZjg2YTNlMmExZDUwN2E2MjQxNmUxMmVjMmM2ODJjOTA5NjM1MTNjNWYwOTgzNTU2Mzk4OSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.PhQMUUgo0bRi53H0QY9SvBmhNx3r2izKeOMUeWZg710)
return false if post.translation_for(I18n.locale).present? | ||
true | ||
else | ||
return false if post.locale_matches?(I18n.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.
Small one but this check is the same regardless of the conditional so we can technically pull this out of the conditional.
In the older implementation of translation, there exists these two site settings are part of the criteria that determines if 🌐 shows up per post
restrict translation by group
- Only allowed groups can translaterestrict translation by poster group
- Only allow translation of posts made by users in allowed groups. If empty, allow translations of posts from all users.In a recent update with experimental features, we updated the cases where 🌐 will show up and caused a regression where the 🌐 shows up for everyone in
restrict translation by group
, ignoringrestrict translation by poster group
.This PR makes sure these two site settings are adhered to when the experimental topic setting is turned off.