Skip to content

Commit 08f599b

Browse files
authored
Allow approximately results to differ in plural form (#137)
1 parent c24b33e commit 08f599b

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

pluralrules/diff.emu

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@
140140
1. Let _pr_ be the *this* value.
141141
1. Perform ? RequireInternalSlot(_pr_, [[InitializedPluralRules]]).
142142
1. Let _n_ be ? ToNumber(_value_).
143-
1. Return ! ResolvePlural(_pr_, _n_).
143+
1. Return ! ResolvePlural(_pr_, _n_)<ins>.[[PluralCategory]]</ins>.
144144
</emu-alg>
145145
</emu-clause>
146146

@@ -373,7 +373,7 @@
373373
<emu-clause id="sec-resolveplural" aoid="ResolvePlural">
374374
<h1>ResolvePlural ( _pluralRules_, _n_ )</h1>
375375
<p>
376-
When the ResolvePlural abstract operation is called with arguments _pluralRules_ (which must be an object initialized as a PluralRules) and _n_ (which must be a Number value), it returns a String value representing the plural form of _n_ according to the effective locale and the options of _pluralRules_. The following steps are taken:
376+
When the ResolvePlural abstract operation is called with arguments _pluralRules_ (which must be an object initialized as a PluralRules) and _n_ (which must be a Number value), it returns <ins>a Record containing two values:</ins> a String value representing the plural form of _n_ according to the effective locale and the options of _pluralRules_ <ins>in the field [[PluralCategory]], and _n_ as a formatted string in the field [[FormattedString]]</ins>. The following steps are taken:
377377
</p>
378378

379379
<emu-alg>
@@ -387,7 +387,8 @@
387387
1. Let _res_ be ! FormatNumericToString(_pluralRules_, _n_).
388388
1. Let _s_ be _res_.[[FormattedString]].
389389
1. Let _operands_ be ! GetOperands(_s_).
390-
1. Return ! PluralRuleSelect(_locale_, _type_, _n_, _operands_).
390+
1. <del>Return</del> <ins>Let _p_ be</ins> ! PluralRuleSelect(_locale_, _type_, _n_, _operands_).
391+
1. <ins class="block">Return the Record { [[PluralCategory]]: _p_, [[FormattedString]]: _s_ }.</ins>
391392
</emu-alg>
392393
</emu-clause>
393394

@@ -414,9 +415,11 @@
414415
1. If _x_ is *NaN* or _y_ is *NaN*, throw a *RangeError* exception.
415416
1. Let _xp_ be ! ResolvePlural(_pluralRules_, _x_).
416417
1. Let _yp_ be ! ResolvePlural(_pluralRules_, _y_).
418+
1. If _xp_.[[FormattedString]] is _yp_.[[FormattedString]], then
419+
1. Return _xp_.[[PluralCategory]].
417420
1. Let _locale_ be _pluralRules_.[[Locale]].
418421
1. Let _type_ be _pluralRules_.[[Type]].
419-
1. Return ! PluralRuleSelectRange(_locale_, _type_, _xp_, _yp_).
422+
1. Return ! PluralRuleSelectRange(_locale_, _type_, _xp_.[[PluralCategory]], _yp_.[[PluralCategory]]).
420423
</emu-alg>
421424
</emu-clause>
422425
</ins>

pluralrules/proposed.emu

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@
140140
1. Let _pr_ be the *this* value.
141141
1. Perform ? RequireInternalSlot(_pr_, [[InitializedPluralRules]]).
142142
1. Let _n_ be ? ToNumber(_value_).
143-
1. Return ! ResolvePlural(_pr_, _n_).
143+
1. Return ! ResolvePlural(_pr_, _n_).[[PluralCategory]].
144144
</emu-alg>
145145
</emu-clause>
146146

@@ -371,7 +371,7 @@
371371
<emu-clause id="sec-resolveplural" aoid="ResolvePlural">
372372
<h1>ResolvePlural ( _pluralRules_, _n_ )</h1>
373373
<p>
374-
When the ResolvePlural abstract operation is called with arguments _pluralRules_ (which must be an object initialized as a PluralRules) and _n_ (which must be a Number value), it returns a String value representing the plural form of _n_ according to the effective locale and the options of _pluralRules_. The following steps are taken:
374+
When the ResolvePlural abstract operation is called with arguments _pluralRules_ (which must be an object initialized as a PluralRules) and _n_ (which must be a Number value), it returns a Record containing two values: a String value representing the plural form of _n_ according to the effective locale and the options of _pluralRules_ in the field [[PluralCategory]], and _n_ as a formatted string in the field [[FormattedString]]. The following steps are taken:
375375
</p>
376376

377377
<emu-alg>
@@ -385,7 +385,8 @@
385385
1. Let _res_ be ! FormatNumericToString(_pluralRules_, _n_).
386386
1. Let _s_ be _res_.[[FormattedString]].
387387
1. Let _operands_ be ! GetOperands(_s_).
388-
1. Return ! PluralRuleSelect(_locale_, _type_, _n_, _operands_).
388+
1. Let _p_ be ! PluralRuleSelect(_locale_, _type_, _n_, _operands_).
389+
1. Return the Record { [[PluralCategory]]: _p_, [[FormattedString]]: _s_ }.
389390
</emu-alg>
390391
</emu-clause>
391392

@@ -411,9 +412,11 @@
411412
1. If _x_ is *NaN* or _y_ is *NaN*, throw a *RangeError* exception.
412413
1. Let _xp_ be ! ResolvePlural(_pluralRules_, _x_).
413414
1. Let _yp_ be ! ResolvePlural(_pluralRules_, _y_).
415+
1. If _xp_.[[FormattedString]] is _yp_.[[FormattedString]], then
416+
1. Return _xp_.[[PluralCategory]].
414417
1. Let _locale_ be _pluralRules_.[[Locale]].
415418
1. Let _type_ be _pluralRules_.[[Type]].
416-
1. Return ! PluralRuleSelectRange(_locale_, _type_, _xp_, _yp_).
419+
1. Return ! PluralRuleSelectRange(_locale_, _type_, _xp_.[[PluralCategory]], _yp_.[[PluralCategory]]).
417420
</emu-alg>
418421
</emu-clause>
419422
</emu-clause>

0 commit comments

Comments
 (0)