diff --git a/lib/i18n/backend/base.rb b/lib/i18n/backend/base.rb index 4cbcc3c..ca12c22 100644 --- a/lib/i18n/backend/base.rb +++ b/lib/i18n/backend/base.rb @@ -282,8 +282,8 @@ module I18n 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 2a44371..c06b7ec 100644 --- a/lib/i18n/tests/localization/date.rb +++ b/lib/i18n/tests/localization/date.rb @@ -34,6 +34,11 @@ module I18n 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