aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/locale/en.rb
blob: 26c2280c95e116a55355d5cbcc3fd01ba51eef4e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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
      }
    }
  }
}