Skip to content

Commit

Permalink
Add the c and e plural operands
Browse files Browse the repository at this point in the history
  • Loading branch information
movermeyer committed Apr 21, 2022
1 parent 809a304 commit 24dd7b0
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions lib/cldr/export/data/plurals/rules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def parse(code)
code = scrub_code(code)

code = code.split("@").first.to_s
operand = /(n|i|f|t|v|w)/i
operand = /(n|i|v|w|f|t|c|e)/i # Ordered as they appear in the spec.
expr = /#{operand}(?:\s+(?:mod|%)\s+([\d]+))?/i
range = /(?:\d+\.\.\d+|\d+)/i
range_list = /(#{range}(?:\s*,\s*#{range})*)/i
Expand Down Expand Up @@ -142,12 +142,19 @@ def initialize(operator = nil, mod = nil, negate = nil, operand = nil, type = ni
end

# Symbol Value
# n absolute value of the source number (integer and decimals).
# i integer digits of n.
# v number of visible fraction digits in n, with trailing zeros.
# w number of visible fraction digits in n, without trailing zeros.
# f visible fractional digits in n, with trailing zeros.
# t visible fractional digits in n, without trailing zeros.
# n the absolute value of N.*
# i the integer digits of N.*
# v the number of visible fraction digits in N, _with_ trailing zeros.*
# w the number of visible fraction digits in N, _without_ trailing zeros.*
# f the visible fraction digits in N, _with_ trailing zeros, expressed as an integer.*
# t the visible fraction digits in N, _without_ trailing zeros, expressed as an integer.*
# c compact decimal exponent value: exponent of the power of 10 used in compact decimal formatting.
# e a deprecated synonym for ‘c’. Note: it may be redefined in the future.
#
# * If there is a compact decimal exponent value (‘c’), then the n, i, f, t, v, and w values are computed
# after shifting the decimal point in the original by the ‘c’ value. So for 1.2c3, the n, i, f, t, v,
# and w values are the same as those of 1200: i=1200 and f=0. Similarly, 1.2005c3 has i=1200 and
# f=5 (corresponding to 1200.5).
#
# http://www.unicode.org/reports/tr35/tr35-numbers.html#Language_Plural_Rules
def to_ruby
Expand All @@ -171,6 +178,13 @@ def to_ruby
when "w"
op = '(w = n.to_s.split(".")[1]) ? w.gsub(/0+$/, "").length : 0'
enclose = true
when "c", "e"
# We don't support numbers in the "compact decimal" format.
# Since `c`/`e` are always 0 for non-"compact decimal" format
# numbers, we just hardcode it to 0 for now.
# TODO: https://github.com/ruby-i18n/ruby-cldr/issues/131
op = "#{@type} = 0"
enclose = true
else
fraction = true
op = "n.to_f"
Expand Down

0 comments on commit 24dd7b0

Please sign in to comment.