Skip to content

DEV: Also hide the globe when post is recently updated #278

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

Merged
merged 2 commits into from
Apr 16, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/discourse_translator/extensions/guardian_extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def can_translate?(post)

# we want to return false if the post is created within a short buffer ago,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might want to change this comment too

# this prevents the 🌐from appearing and then disappearing if the lang is same as user's lang
return false if post.created_at > POST_DETECTION_BUFFER.ago && post.detected_locale.blank?
return false if post.updated_at > POST_DETECTION_BUFFER.ago && post.detected_locale.blank?

if SiteSetting.experimental_inline_translation
locale = DiscourseTranslator::InlineTranslation.effective_locale
Expand Down
8 changes: 4 additions & 4 deletions spec/lib/guardian_extension_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
describe "#can_translate?" do
fab!(:group)
fab!(:user) { Fabricate(:user, locale: "en", groups: [group]) }
fab!(:post) { Fabricate(:post, created_at: 5.minutes.ago) }
fab!(:post) { Fabricate(:post, updated_at: 5.minutes.ago) }

let(:guardian) { Guardian.new(user) }

Expand Down Expand Up @@ -160,16 +160,16 @@
expect(guardian.can_translate?(post)).to eq(false)
end

it "allows translation depending on when the post is created" do
it "allows translation depending on when the post is updated" do
SiteSetting.restrict_translation_by_group = "#{group.id}"

post.update(created_at: Time.now)
post.update(updated_at: Time.now)
expect(guardian.can_translate?(post)).to eq(false)

post.set_detected_locale("jp")
expect(guardian.can_translate?(post)).to eq(true)

post.update(created_at: 5.minutes.ago)
post.update(updated_at: 5.minutes.ago)
expect(guardian.can_translate?(post)).to eq(true)

post.set_detected_locale("pt")
Expand Down
Loading