Skip to content

Commit f2c8f7a

Browse files
authored
DEV: Also hide the globe when post is recently updated (#278)
In #229 we added a buffer to not show the 🌐 within 10 seconds of post creation. We need to extend this to post edits as well to allow the edited post to be translated automatically and prevent the user from seeing the flash of 🌐
1 parent 5c4de36 commit f2c8f7a

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

lib/discourse_translator/extensions/guardian_extension.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ def can_translate?(post)
2727
return false if post.user&.bot?
2828
return false if !user_group_allow_translate?
2929

30-
# we want to return false if the post is created within a short buffer ago,
30+
# we want to return false if the post is updated within a short buffer ago,
3131
# this prevents the 🌐from appearing and then disappearing if the lang is same as user's lang
32-
return false if post.created_at > POST_DETECTION_BUFFER.ago && post.detected_locale.blank?
32+
return false if post.updated_at > POST_DETECTION_BUFFER.ago && post.detected_locale.blank?
3333

3434
if SiteSetting.experimental_inline_translation
3535
locale = DiscourseTranslator::InlineTranslation.effective_locale

spec/lib/guardian_extension_spec.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@
117117
describe "#can_translate?" do
118118
fab!(:group)
119119
fab!(:user) { Fabricate(:user, locale: "en", groups: [group]) }
120-
fab!(:post) { Fabricate(:post, created_at: 5.minutes.ago) }
120+
fab!(:post) { Fabricate(:post, updated_at: 5.minutes.ago) }
121121

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

@@ -160,16 +160,16 @@
160160
expect(guardian.can_translate?(post)).to eq(false)
161161
end
162162

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

166-
post.update(created_at: Time.now)
166+
post.update(updated_at: Time.now)
167167
expect(guardian.can_translate?(post)).to eq(false)
168168

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

172-
post.update(created_at: 5.minutes.ago)
172+
post.update(updated_at: 5.minutes.ago)
173173
expect(guardian.can_translate?(post)).to eq(true)
174174

175175
post.set_detected_locale("pt")

0 commit comments

Comments
 (0)