Skip to content

Commit

Permalink
Merge pull request #640 from movermeyer/movermeyer/date_meridian_indi…
Browse files Browse the repository at this point in the history
…cators

Add support for meridian indicators on `Date` objects
  • Loading branch information
radar authored Nov 13, 2022
2 parents 15e59ef + 9071340 commit 1d886ea
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/i18n/backend/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions lib/i18n/tests/localization/date.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1d886ea

Please sign in to comment.