]> git.openstreetmap.org Git - rails.git/commitdiff
Rework browse pages to avoid raw html in translations
authorAndy Allan <git@gravitystorm.co.uk>
Wed, 22 Mar 2023 18:36:13 +0000 (18:36 +0000)
committerAndy Allan <git@gravitystorm.co.uk>
Wed, 29 Mar 2023 17:52:45 +0000 (18:52 +0100)
app/helpers/changesets_helper.rb
app/views/browse/_common_details.html.erb
config/locales/en.yml
test/helpers/changesets_helper_test.rb

index 5773240ff1d64fbce02d99dc0ac2695c45bf594d..9d46de12009ca89a8e80f71f341a754a4078e82e 100644 (file)
@@ -21,14 +21,10 @@ module ChangesetsHelper
     end
 
     if params.key?(:display_name)
-      t "browse.#{action}_html",
-        :time => time,
-        :title => title
+      t "browse.#{action}_ago_html", :time_ago => tag.abbr(time, :title => title)
     else
-      t "browse.#{action}_by_html",
-        :time => time,
-        :title => title,
-        :user => changeset_user_link(changeset)
+      t "browse.#{action}_ago_by_html", :time_ago => tag.abbr(time, :title => title),
+                                        :user => changeset_user_link(changeset)
     end
   end
 
index 8aa5b64c7b91245f43621598a01262d8e1557650..9eb6b5bfe55988f76d99e1487012cb9c3b619158 100644 (file)
 
 <ul class="list-unstyled">
   <li>
-    <%= t "browse.#{common_details.visible? ? :edited : :deleted}_by_html",
-          :time => time_ago_in_words(common_details.timestamp, :scope => :"datetime.distance_in_words_ago"),
-          :user => changeset_user_link(common_details.changeset),
-          :title => l(common_details.timestamp) %>
+    <%= t "browse.#{common_details.visible? ? :edited : :deleted}_ago_by_html",
+          :time_ago => tag.abbr(time_ago_in_words(common_details.timestamp, :scope => :"datetime.distance_in_words_ago"),
+                                :title => l(common_details.timestamp)),
+          :user => changeset_user_link(common_details.changeset) %>
   </li>
   <li>
     <%= t "browse.in_changeset" %>
index fd84a48bf0fd93872e120cc9a3dc0f6024680f60..f431ccde7896b1f05d3225e393457db64b4c3ecf 100644 (file)
@@ -300,12 +300,12 @@ en:
   browse:
     created: "Created"
     closed: "Closed"
-    created_html: "Created <abbr title='%{title}'>%{time}</abbr>"
-    closed_html: "Closed <abbr title='%{title}'>%{time}</abbr>"
-    created_by_html: "Created <abbr title='%{title}'>%{time}</abbr> by %{user}"
-    deleted_by_html: "Deleted <abbr title='%{title}'>%{time}</abbr> by %{user}"
-    edited_by_html: "Edited <abbr title='%{title}'>%{time}</abbr> by %{user}"
-    closed_by_html: "Closed <abbr title='%{title}'>%{time}</abbr> by %{user}"
+    created_ago_html: "Created %{time_ago}"
+    closed_ago_html: "Closed %{time_ago}"
+    created_ago_by_html: "Created %{time_ago} by %{user}"
+    closed_ago_by_html: "Closed %{time_ago} by %{user}"
+    deleted_ago_by_html: "Deleted %{time_ago} by %{user}"
+    edited_ago_by_html: "Edited %{time_ago} by %{user}"
     version: "Version"
     in_changeset: "Changeset"
     anonymous: "anonymous"
index a25eed6fae2fac1dcad79a769ef655564a0b72ba..f6cfb3c0679a467490926adfa21fcfbc83f0aee1 100644 (file)
@@ -17,11 +17,11 @@ class ChangesetsHelperTest < ActionView::TestCase
     # We need to explicitly reset the closed_at to some point in the future, and avoid the before_save callback
     changeset.update_column(:closed_at, Time.now.utc + 1.day) # rubocop:disable Rails/SkipsModelValidations
 
-    assert_match %r{^Created <abbr title='Mon, 01 Jan 2007 00:00:00 \+0000'>.*</abbr> by anonymous$}, changeset_details(changeset)
+    assert_match %r{^Created <abbr title="Mon, 01 Jan 2007 00:00:00 \+0000">.*</abbr> by anonymous$}, changeset_details(changeset)
 
     changeset = create(:changeset, :created_at => Time.utc(2007, 1, 1, 0, 0, 0), :closed_at => Time.utc(2007, 1, 2, 0, 0, 0))
     user_link = %(<a href="/user/#{ERB::Util.u(changeset.user.display_name)}">#{changeset.user.display_name}</a>)
 
-    assert_match %r{^Closed <abbr title='Created: Mon, 01 Jan 2007 00:00:00 \+0000&#10;Closed: Tue, 02 Jan 2007 00:00:00 \+0000'>.*</abbr> by #{user_link}$}, changeset_details(changeset)
+    assert_match %r{^Closed <abbr title="Created: Mon, 01 Jan 2007 00:00:00 \+0000&#10;Closed: Tue, 02 Jan 2007 00:00:00 \+0000">.*</abbr> by #{user_link}$}, changeset_details(changeset)
   end
 end