From f58e2dd095e2e9e4e42e6d7af229f87e70fd5427 Mon Sep 17 00:00:00 2001 From: Christian Blais Date: Sun, 4 Mar 2018 21:29:54 -0500 Subject: `ActiveSupport::Inflector#ordinal` and `ActiveSupport::Inflector#ordinalize` now support translations through I18n. { fr: { number: { nth: { ordinals: lambda do |_key, number:, **_options| if number.to_i.abs == 1 'er' else 'e' end end, ordinalized: lambda do |_key, number:, **_options| "#{number}#{ActiveSupport::Inflector.ordinal(number)}" end } } } } --- activesupport/lib/active_support/locale/en.rb | 28 +++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 activesupport/lib/active_support/locale/en.rb (limited to 'activesupport/lib/active_support/locale/en.rb') diff --git a/activesupport/lib/active_support/locale/en.rb b/activesupport/lib/active_support/locale/en.rb new file mode 100644 index 0000000000..26c2280c95 --- /dev/null +++ b/activesupport/lib/active_support/locale/en.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +{ + en: { + number: { + nth: { + ordinals: lambda do |_key, number:, **_options| + abs_number = number.to_i.abs + + if (11..13).cover?(abs_number % 100) + "th" + else + case abs_number % 10 + when 1 then "st" + when 2 then "nd" + when 3 then "rd" + else "th" + end + end + end, + + ordinalized: lambda do |_key, number:, **_options| + "#{number}#{ActiveSupport::Inflector.ordinal(number)}" + end + } + } + } +} -- cgit v1.2.3