From 9071340a4c19da81aba924dc78623d8f7c04cded Mon Sep 17 00:00:00 2001 From: Michael Overmeyer Date: Fri, 7 Oct 2022 11:26:45 -0400 Subject: [PATCH] Add support for meridian indicators on `Date` objects --- lib/i18n/backend/base.rb | 4 ++-- lib/i18n/tests/localization/date.rb | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/i18n/backend/base.rb b/lib/i18n/backend/base.rb index 4cbcc3c0..ca12c227 100644 --- a/lib/i18n/backend/base.rb +++ b/lib/i18n/backend/base.rb @@ -282,8 +282,8 @@ def translate_localization_format(locale, object, format, options) when '%^b' then I18n.t!(:"date.abbr_month_names", :locale => locale, :format => format)[object.mon].upcase when '%B' then I18n.t!(:"date.month_names", :locale => locale, :format => format)[object.mon] when '%^B' then I18n.t!(:"date.month_names", :locale => locale, :format => format)[object.mon].upcase - when '%p' then I18n.t!(:"time.#{object.hour < 12 ? :am : :pm}", :locale => locale, :format => format).upcase if object.respond_to? :hour - when '%P' then I18n.t!(:"time.#{object.hour < 12 ? :am : :pm}", :locale => locale, :format => format).downcase if object.respond_to? :hour + when '%p' then I18n.t!(:"time.#{(object.respond_to?(:hour) ? object.hour : 0) < 12 ? :am : :pm}", :locale => locale, :format => format).upcase + when '%P' then I18n.t!(:"time.#{(object.respond_to?(:hour) ? object.hour : 0) < 12 ? :am : :pm}", :locale => locale, :format => format).downcase end end rescue MissingTranslationData => e diff --git a/lib/i18n/tests/localization/date.rb b/lib/i18n/tests/localization/date.rb index 2a44371b..c06b7ece 100644 --- a/lib/i18n/tests/localization/date.rb +++ b/lib/i18n/tests/localization/date.rb @@ -34,6 +34,11 @@ def setup assert_equal 'Sa', I18n.l(@date, :format => '%a', :locale => :de) end + test "localize Date: given an meridian indicator format it returns the correct meridian indicator" do + assert_equal 'AM', I18n.l(@date, :format => '%p', :locale => :de) + assert_equal 'am', I18n.l(@date, :format => '%P', :locale => :de) + end + test "localize Date: given an abbreviated and uppercased day name format it returns the correct abbreviated day name in upcase" do assert_equal 'sa'.upcase, I18n.l(@date, :format => '%^a', :locale => :de) end