mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 07:57:46 +00:00
LibJS: Allow "approximately" results to differ in plural form
This is a normative change in the Intl.NumberFormat V3 spec. See:
08f599b
Note that this didn't seem to actually affect our implementation. The
Unicode spec states:
https://www.unicode.org/reports/tr35/tr35-53/tr35-numbers.html#Plural_Ranges
"If there is no value for a <start,end> pair, the default result is end"
Therefore, our implementation did not have the behavior noted by the
issue this normative change addressed:
const pr = new Intl.PluralRules("en-US");
pr.selectRange(1, 1); // Is "other", should be "one"
Our implementation already returned "one" here because there is no such
<start=one, end=one> value in the CLDR for en-US. Thus, we already
returned the end value of "one".
This commit is contained in:
parent
5c1038e54f
commit
e74e8381d5
6 changed files with 36 additions and 17 deletions
|
@ -6,6 +6,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/String.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <LibJS/Runtime/Completion.h>
|
||||
#include <LibJS/Runtime/Intl/NumberFormat.h>
|
||||
|
@ -30,10 +31,15 @@ private:
|
|||
::Locale::PluralForm m_type { ::Locale::PluralForm::Cardinal }; // [[Type]]
|
||||
};
|
||||
|
||||
struct ResolvedPlurality {
|
||||
::Locale::PluralCategory plural_category; // [[PluralCategory]]
|
||||
String formatted_string; // [[FormattedString]]
|
||||
};
|
||||
|
||||
::Locale::PluralOperands get_operands(StringView string);
|
||||
::Locale::PluralCategory plural_rule_select(StringView locale, ::Locale::PluralForm type, Value number, ::Locale::PluralOperands operands);
|
||||
ThrowCompletionOr<::Locale::PluralCategory> resolve_plural(VM&, PluralRules const&, Value number);
|
||||
ThrowCompletionOr<::Locale::PluralCategory> resolve_plural(VM&, NumberFormatBase const& number_format, ::Locale::PluralForm type, Value number);
|
||||
ThrowCompletionOr<ResolvedPlurality> resolve_plural(VM&, PluralRules const&, Value number);
|
||||
ThrowCompletionOr<ResolvedPlurality> resolve_plural(VM&, NumberFormatBase const& number_format, ::Locale::PluralForm type, Value number);
|
||||
::Locale::PluralCategory plural_rule_select_range(StringView locale, ::Locale::PluralForm, ::Locale::PluralCategory start, ::Locale::PluralCategory end);
|
||||
ThrowCompletionOr<::Locale::PluralCategory> resolve_plural_range(VM&, PluralRules const&, Value start, Value end);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue