discourse/app/helpers/embed_helper.rb
锦心 dfd4da9656
UX: Use localized time format in embedded comments (#28014)
Previously, the time format for embedded comments was hardcoded. This
commit changes it to the time format defined in I18n.

Related meta topic: https://meta.discourse.org/t/embed-dates-are-not-localized/27997/
2024-07-22 18:42:36 +08:00

25 lines
587 B
Ruby

# frozen_string_literal: true
module EmbedHelper
def embed_post_date(dt)
current = Time.now
if dt >= 1.day.ago
distance_of_time_in_words(dt, current)
else
if dt.year == current.year
dt.strftime I18n.t("datetime_formats.formats.short_no_year")
else
dt.strftime I18n.t("datetime_formats.formats.no_day")
end
end
end
def get_html(post)
key = "js.action_codes.#{post.action_code}"
cooked = post.cooked.blank? ? I18n.t(key, when: nil).humanize : post.cooked
raw PrettyText.format_for_email(cooked, post)
end
end