This proposal enhances the Intl.DisplayNames API and cover more display names for weekday, month, time zone, unit, calendar, numbering system, etc. See the README for more context.
The CanonicalCodeForDisplayNames abstract operation is called with arguments type, code. It verifies that the code argument represents a well-formed code according to the type argument and returns the case-regularized form of the code. The algorithm refers to UTS 35's Unicode Language and Locale Identifiers grammar. The following steps are taken:
"language"
, thenunicode_language_id
production, throw a "region"
, thenunicode_region_subtag
production, throw a "script"
, thenunicode_script_subtag
production, throw a "calendar"
, thentype
nonterminal, throw a "dateTimeField"
, then"currency"
.The IsValidDateTimeFieldCode abstract operation is called with argument field. It verifies that the field argument represents a valid date time field code. The following steps are taken:
Code | Description |
---|---|
"era" |
The field indicating the era, e.g. AD or BC in the Gregorian (Julian) calendar. |
"year" |
The field indicating the year. |
"quarter" |
The field indicating the quarter, e.g. Q2, 2nd quarter, etc. |
"month" |
The field indicating the month, e.g. Sep, September, etc. |
"weekOfYear" |
The field indicating the week number within the current year. |
"weekday" |
The field indicating the day of week, e.g. Tue, Tuesday, etc. |
"day" |
The field indicating the day in month. |
"dayPeriod" |
The field indicating the day period, either am/pm marker or others, e.g. noon, evening. |
"hour" |
The field indicating the hour. |
"minute" |
The field indicating the minute. |
"second" |
The field indicating the second. |
"timeZoneName" |
The field indicating the time zone name, e.g. PDT, Pacific Daylight Time, etc. |
The DisplayNames
When the
"%DisplayNamesPrototype%"
, « [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[LanguageDisplay]], [[Fields]] »)."localeMatcher"
, "string"
, « "lookup"
, "best fit"
», "best fit"
)."style"
, "string"
, « "narrow"
, "short"
, "long"
», "long"
)."type"
, "string"
, « "language"
, "region"
, "script"
, "currency"
, "calendar"
, "dateTimeField"
», "fallback"
, "string"
, « "code"
, "none"
», "code"
)."languageDisplay"
, "string"
, « "dialect"
, "standard"
», "dialect"
)."language"
, then
The Intl.DisplayNames
The value of
This property has the attributes { [[Writable]]:
When the
The value of the [[AvailableLocales]] internal slot is implementation defined within the constraints described in
The value of the [[RelevantExtensionKeys]] internal slot is « ».
The value of the [[LocaleData]] internal slot is implementation defined within the constraints described in
"language"
, "region"
, "script"
, "currency"
, "calendar"
, and "dateTimeField"
."language"
must be a "dialect"
and "standard"
."language"
should contain Records which must have fields with the names of one of the valid display name styles: "narrow"
, "short"
, and "long"
."language"
, "region"
, "script"
, "currency"
, "calendar"
, and "dateTimeField"
must be a "narrow"
, "short"
, and "long"
."language"
should contain Records, with keys corresponding to language codes according to unicode_language_id
production. The value of these fields must be string values."region"
should contain Records, with keys corresponding to region codes. The value of these fields must be string values."script"
should contain Records, with keys corresponding to script codes. The value of these fields must be string values."currency"
should contain Records, with keys corresponding to currency codes. The value of these fields must be string values."calendar"
should contain Records, with keys corresponding to a String value with the type
given in Unicode Technical Standard 35 for the calendar used for formatting. The value of these fields must be string values."dateTimeField"
should contain Records, with keys corresponding to codes listed in
The Intl.DisplayNames prototype object, referred to as
The initial value of
The initial value of the @@toStringTag property is the string value "Intl.DisplayNames"
.
This property has the attributes { [[Writable]]:
When the
"code"
, return code.This function provides access to the locale and options computed during initialization of the object.
Internal Slot | Property |
---|---|
[[Locale]] | "locale" |
[[Style]] | "style" |
[[Type]] | "type" |
[[Fallback]] | "fallback" |
[[LanguageDisplay]] | "languageDisplay" |
Intl.DisplayNames instances are ordinary objects that inherit properties from %DisplayNamesPrototype%.
Intl.DisplayNames instances have an [[InitializedDisplayNames]] internal slot.
Intl.DisplayNames instances also have several internal slots that are computed by the
"narrow"
, "short"
, or "long"
, identifying the display names style used."language"
, "region"
, "script"
, "currency"
, "calendar"
, or "dateTimeField"
, identifying the type of the display names requested."code"
, or "none"
, identifying the fallback return when the system does not have the requested display name."dialect"
or "standard"
, identifying the language display kind. It is only used when [[Type]] has the value "language"
.© 2021 Google, Ecma International
All Software contained in this document ("Software") is protected by copyright and is being made available under the "BSD License", included below. This Software may be subject to third party rights (rights from parties other than Ecma International), including patent rights, and no licenses under such third party rights are granted under this license even if the third party concerned is a member of Ecma International. SEE THE ECMA CODE OF CONDUCT IN PATENT MATTERS AVAILABLE AT https://ecma-international.org/memento/codeofconduct.htm FOR INFORMATION REGARDING THE LICENSING OF PATENT CLAIMS THAT ARE REQUIRED TO IMPLEMENT ECMA INTERNATIONAL STANDARDS.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
THIS SOFTWARE IS PROVIDED BY THE ECMA INTERNATIONAL "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ECMA INTERNATIONAL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.