From e3abee660a1686308e4649eecf178c7e268ae2e5 Mon Sep 17 00:00:00 2001 From: Michael Kohl Date: Sat, 9 Oct 2021 02:08:56 +0700 Subject: [PATCH] Add I18n date format example (#14973) --- app/helpers/date_helper.rb | 3 ++- config/locales/en.yml | 4 ++++ config/locales/fr.yml | 28 ++++++++++++++++------------ 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/app/helpers/date_helper.rb b/app/helpers/date_helper.rb index f1cf013ca..7269f5088 100644 --- a/app/helpers/date_helper.rb +++ b/app/helpers/date_helper.rb @@ -1,9 +1,10 @@ module DateHelper def local_date(datetime, show_year: true) datetime = Time.zone.parse(datetime) if datetime.is_a?(String) + format = show_year ? :short_with_year : :short tag.time( - datetime.strftime("%b %-e#{', %Y' if show_year}"), + l(datetime, format: format), datetime: datetime.utc.iso8601, class: "date#{'-no-year' unless show_year}", ) diff --git a/config/locales/en.yml b/config/locales/en.yml index dc6c7abf3..03f95ee1c 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -112,3 +112,7 @@ en: billing: "Billing" organization: "Organization" extensions: "Extensions" + time: + formats: + short: "%b %-e" + short_with_year: "%b %-e, %Y" diff --git a/config/locales/fr.yml b/config/locales/fr.yml index f75555ec6..ae4f78f94 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -67,18 +67,18 @@ fr: date: abbr_month_names: - - - Janv - - Fevr - - Mars - - Avril - - Mai - - Juin - - Juil - - Aout - - Sept - - Oct - - Nov - - Dec + - janv + - févr + - mars + - avril + - mai + - juin + - juil + - aout + - sept + - oct + - nov + - déc errors: messages: accepted: doit être accepté @@ -135,3 +135,7 @@ fr: billing: Facturation organization: Organisation extensions: Extensions + time: + formats: + short: "%-e %b" + short_with_year: "%-e %b, %Y"