From 82938e28bfd10230df4e504a0552366e52dcc4ec Mon Sep 17 00:00:00 2001 From: Adrian Marin Date: Fri, 17 Jan 2025 16:31:27 +0200 Subject: [PATCH] refactor i18n --- lib/avo/discreet_information.rb | 13 ++++++++++++- spec/dummy/config/locales/avo.en.yml | 3 ++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/avo/discreet_information.rb b/lib/avo/discreet_information.rb index 0c534a57b1..4269d35999 100644 --- a/lib/avo/discreet_information.rb +++ b/lib/avo/discreet_information.rb @@ -1,5 +1,6 @@ class Avo::DiscreetInformation extend PropInitializer::Properties + include ActionView::Helpers::TagHelper prop :resource, reader: :public @@ -18,12 +19,22 @@ def items private def timestamp_item(item) + return if record.created_at.blank? && record.updated_at.blank? + time_format = "%Y-%m-%d %H:%M:%S" created_at = record.created_at.strftime(time_format) updated_at = record.updated_at.strftime(time_format) + created_at_tag = if record.created_at.present? + I18n.t("avo.created_at_timestamp", created_at:) + end + + updated_at_tag = if record.updated_at.present? + I18n.t("avo.updated_at_timestamp", updated_at:) + end + DiscreetInformationItem.new( - tooltip: I18n.t("avo.discreet_information_timestamps_html", created_at:, updated_at:), + tooltip: tag.div([created_at_tag, updated_at_tag].compact.join(tag.br), style: "text-align: right;"), icon: "heroicons/outline/clock" ) end diff --git a/spec/dummy/config/locales/avo.en.yml b/spec/dummy/config/locales/avo.en.yml index d09fb3bff1..daba5030b8 100644 --- a/spec/dummy/config/locales/avo.en.yml +++ b/spec/dummy/config/locales/avo.en.yml @@ -35,7 +35,8 @@ en: delete_item: Delete %{item} detach_item: detach %{item} details: details - discreet_information_timestamps_html: "
Created at %{created_at}
Updated at %{updated_at}
" + created_at_timestamp: "Created at %{created_at}" + updated_at_timestamp: "Updated at %{updated_at}" download: Download download_file: Download file download_item: Download %{item}