1、 Reference number ECMA-123:2009 Ecma International 2009 ECMA-402 2nd Edition / June 2015 ECMAScript 2015 Internationalization API Specification COPYRIGHT PROTECTED DOCUMENT Ecma International 2015 Ecma International 2015 i Copyright notice Copyright 2015 Ecma International Ecma International Rue du
2、Rhone 114 CH-1204 Geneva Tel: +41 22 849 6000 Fax: +41 22 849 6001 Web: http:/www.ecma-international.org This document and possible translations of it may be copied and furnished to others, and derivative works that comment on or otherwise explain it or assist in its implementation may be prepared,
3、copied, published, and distributed, in whole or in part, without restriction of any kind, provided that the above copyright notice and this section are included on all such copies and derivative works. However, this document itself may not be modified in any way, including by removing the copyright
4、notice or references to Ecma International, except as needed for the purpose of developing any document or deliverable produced by Ecma International (in which case the rules applied to copyrights must be followed) or as required to translate it into languages other than English. The limited permiss
5、ions granted above are perpetual and will not be revoked by Ecma International or its successors or assigns. This document and the information contained herein is provided on an “AS IS“ basis and ECMA INTERNATIONAL DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRAN
6、TY THAT THE USE OF THE INFORMATION HEREIN WILL NOT INFRINGE ANY OWNERSHIP RIGHTS OR ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.“ Software License All Software contained in this document (“Software)“ is protected by copyright and is being made available under the “B
7、SD 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 Internation
8、al. SEE THE ECMA CODE OF CONDUCT IN PATENT MATTERS AVAILABLE AT http:/www.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
9、 without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list
10、of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the authors nor Ecma International may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTW
11、ARE 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,
12、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 OT
13、HERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ii Ecma International 2015 Ecma International 2015 iii Contents Page Copyright notice i 1 Scope 1 2 Conformance . 1 3 Normative References . 1 4 Overview . 2 4.1 Internationalization, Loca
14、lization, and Globalization 2 4.2 API Overview 2 4.3 Implementation Dependencies 3 5 Notational Conventions 3 5.1 Well-Known Intrinsic Objects . 4 6 Identification of Locales, Currencies, and Time Zones . 5 6.1 Case Sensitivity and Case Mapping 5 6.2 Language Tags 5 6.2.1 Unicode Locale Extension Se
15、quences 5 6.2.2 IsStructurallyValidLanguageTag (locale) 5 6.2.3 CanonicalizeLanguageTag (locale) . 6 6.2.4 DefaultLocale () 6 6.3 Currency Codes . 6 6.3.1 IsWellFormedCurrencyCode (currency) . 6 6.4 Time Zone Names 6 6.4.1 IsValidTimeZoneName (timeZone) . 7 6.4.2 CanonicalizeTimeZoneName (timeZone)
16、7 6.4.3 DefaultTimeZone () 7 7 Requirements for Standard Built-in ECMAScript Objects 7 8 The Intl Object 7 8.1 Properties of the Intl Object . 7 9 Locale and Parameter Negotiation 8 9.1 Internal slots of Service Constructors 8 9.2 Abstract Operations 8 9.2.1 CanonicalizeLocaleList (locales) . 8 9.2.
17、2 BestAvailableLocale (availableLocales, locale) . 9 9.2.3 LookupMatcher (availableLocales, requestedLocales) . 9 9.2.4 BestFitMatcher (availableLocales, requestedLocales) 10 9.2.5 ResolveLocale (availableLocales, requestedLocales, options, relevantExtensionKeys, localeData) . 10 9.2.6 LookupSupport
18、edLocales (availableLocales, requestedLocales) . 11 9.2.7 BestFitSupportedLocales (availableLocales, requestedLocales) 12 9.2.8 SupportedLocales (availableLocales, requestedLocales, options) . 12 9.2.9 GetOption (options, property, type, values, fallback) 12 9.2.10 GetNumberOption (options, property
19、, minimum, maximum, fallback) 13 10 Collator Objects . 13 10.1 The Intl.Collator Constructor 13 10.1.1 InitializeCollator (collator, locales, options) . 13 10.1.2 Intl.Collator( locales , options) 15 10.2 Properties of the Intl.Collator Constructor . 15 10.2.1 Intl.Collator.prototype . 15 10.2.2 Int
20、l.Collator.supportedLocalesOf (locales , options ) . 15 iv Ecma International 2015 10.2.3 Internal slots 15 10.3 Properties of the Intl.Collator Prototype Object 16 10.3.1 Intl.Collator.prototype.constructor . 16 10.3.2 Intl.Collator.prototypetoStringTag 16 10.3.3 Intl.Cpare 16 10.3.4 Collator Compa
21、re Functions . 16 10.3.5 Intl.Collator.prototype.resolvedOptions () . 17 10.4 Properties of Intl.Collator Instances . 17 11 NumberFormat Objects 18 11.1 The Intl.NumberFormat Constructor. 18 11.1.1 InitializeNumberFormat (numberFormat, locales, options) . 18 11.1.2 Intl.NumberFormat( locales , optio
22、ns) . 19 11.2 Properties of the Intl.NumberFormat Constructor 20 11.2.1 Intl.NumberFormat.prototype 20 11.2.2 Intl.NumberFormat.supportedLocalesOf (locales , options ) 20 11.2.3 Internal slots 20 11.3 Properties of the Intl.NumberFormat Prototype Object 20 11.3.1 Intl.NumberFormat.prototype.construc
23、tor . 21 11.3.2 Intl.NumberFormat.prototypetoStringTag 21 11.3.3 Intl.NumberFormat.prototype.format 21 11.3.4 Number Format Functions . 21 11.3.5 Intl.NumberFormat.prototype.resolvedOptions () . 24 11.4 Properties of Intl.NumberFormat Instances . 24 12 DateTimeFormat Objects . 25 12.1 The Intl.DateT
24、imeFormat Constructor 25 12.1.1 InitializeDateTimeFormat (dateTimeFormat, locales, options) 25 12.1.2 Intl.DateTimeFormat( locales , options ) . 28 12.2 Properties of the Intl.DateTimeFormat Constructor 28 12.2.1 Intl.DateTimeFormat.prototype . 28 12.2.2 Intl.DateTimeFormat.supportedLocalesOf (local
25、es , options ) 28 12.2.3 Internal slots 29 12.3 Properties of the Intl.DateTimeFormat Prototype Object . 29 12.3.1 Intl.DateTimeFormat.prototype.constructor 29 12.3.2 Intl.DateTimeFormat.prototypetoStringTag 30 12.3.3 Intl.DateTimeFormat.prototype.format . 30 12.3.4 DateTime Format Functions 30 12.3
26、.5 Intl.DateTimeFormat.prototype.resolvedOptions () 31 12.4 Properties of Intl.DateTimeFormat Instances 32 13 Locale Sensitive Functions of the ECMAScript Language Specification . 32 13.1 Properties of the String Prototype Object 32 13.1.1 String.prototype.localeCompare (that , locales , options ) 3
27、2 13.1.2 String.prototype.toLocaleLowerCase (locales) . 33 13.1.3 String.prototype.toLocaleUpperCase (locales ) 33 13.2 Properties of the Number Prototype Object 34 13.2.1 Number.prototype.toLocaleString (locales , options ) . 34 13.3 Properties of the Date Prototype Object 34 13.3.1 Date.prototype.
28、toLocaleString (locales , options ) . 34 13.3.2 Date.prototype.toLocaleDateString (locales , options ) . 34 13.3.3 Date.prototype.toLocaleTimeString (locales , options ) 35 13.4 Properties of the Array Prototype Object . 35 13.4.1 Array.prototype.toLocaleString(locales , options ) 35 Annex A (inform
29、ative) Implementation Dependent Behaviour 37 Annex B (informative) Additions and Changes That Introduce Incompatibilities with Prior Editions . 39 Ecma International 2015 v Introduction The ECMAScript 2015 Internationalization API Specification (ECMA-402 2nd Edition), provides key language-sensitive
30、 functionality as a complement to the ECMAScript 2015 Language Specification (ECMA-262 6th Edition or successor). Its functionality has been selected from that of well-established internationalization APIs such as those of the Internationalization Components for Unicode (ICU) library, of the .NET fr
31、amework, or of the Java platform. The 1st Edition API was developed by an ad-hoc group established by Ecma TC39 in September 2010 based on a proposal by Neboja iri and Jungshik Shin. Internationalization of software is never complete. We expect significant enhancements in future editions of this spe
32、cification. Editor, 2nd Edition Rick Waldron Contributors Norbert Lindenberg Allen Wirfs-Brock Andr Bargull Steven R. Loomis Editor, 1st Edition Norbert Lindenberg Contributors Eric Albright Neboja iri Peter Constable Mark Davis Richard Gillam Steven Loomis Mihai Nita Addison Phillips Roozbeh Pourna
33、der Jungshik Shin Shawn Steele Allen Wirfs-Brock Feedback provided by Erik Arvidsson, John J. Barton, Zbigniew Braniecki, Marcos Cceres, Brendan Eich, John Emmons, Gordon P. Hemsley, David Herman, Luke Hoban, Oliver Hunt, Suresh Jayabalan, Yehuda Katz, Mark S. Miller, Andrew Paprocki, Adam Peller, A
34、xel Rauschmayer, Andreas Rossberg, Alex Russell, Markus Scherer, Dmitry Soshnikov, Yusuke Suzuki, John Tamplin, Rick Waldron, Anton Yatsenko, Nicholas Zakas. This Ecma Standard has been adopted by the General Assembly of June 2015. vi Ecma International 2015 Ecma International 2015 1 ECMAScript 2015
35、 Internationalization API Specification 1 Scope This Standard defines the application programming interface for ECMAScript objects that support programs that need to adapt to the linguistic and cultural conventions used by different human languages and countries. 2 Conformance A conforming implement
36、ation of the ECMAScript 2015 Internationalization API Specification must conform to the ECMAScript 2015 Language Specification (ECMA-262 6th Edition, or successor), and must provide and support all the objects, properties, functions, and program semantics described in this specification. A conformin
37、g implementation of the ECMAScript 2015 Internationalization API Specification is permitted to provide additional objects, properties, and functions beyond those described in this specification. In particular, a conforming implementation of the ECMAScript 2015 Internationalization API Specification
38、is permitted to provide properties not described in this specification, and values for those properties, for objects that are described in this specification. A conforming implementation is not permitted to add optional arguments to the functions defined in this specification. A conforming implement
39、ation is permitted to accept additional values, and then have implementation-defined behaviour instead of throwing a RangeError, for the following properties of options arguments: The options property localeMatcher in all constructors and supportedLocalesOf methods. The options properties usage and
40、sensitivity in the Collator constructor. The options properties style and currencyDisplay in the NumberFormat constructor. The options properties minimumIntegerDigits, minimumFractionDigits, maximumFractionDigits, minimumSignificantDigits, and maximumSignificantDigits in the NumberFormat constructor
41、, provided that the additional values are interpreted as integer values higher than the specified limits. The options properties listed in table 3 in the DateTimeFormat constructor. The options property formatMatcher in the DateTimeFormat constructor. 3 Normative References The following referenced
42、documents are required for the application of this document. For dated references, only the edition cited applies. For undated references, the latest edition of the referenced document (including any amendments) applies. ECMAScript 2015 Language Specification (ECMA-262 6th Edition, or successor). ht
43、tp:/www.ecma-international.org/publications/standards/Ecma-262.htm NOTE Throughout this document, the phrase “ES2015, x” (where x is a sequence of numbers separated by periods) may be used as shorthand for “ECMAScript 2015 Language Specification (ECMA-262 6th Edition, sub clause x)”. ISO/IEC 10646:2
44、003: Information Technology Universal Multiple-Octet Coded Character Set (UCS) plus Amendment 1:2005 and Amendment 2:2006, Amendment 3:2008, and Amendment 4:2008, plus additional amendments and corrigenda, or successor http:/www.iso.org/iso/catalogue_detail.htm?csnumber=39921 http:/www.iso.org/iso/c
45、atalogue_detail.htm?csnumber=40755 http:/www.iso.org/iso/catalogue_detail.htm?csnumber=41419 http:/www.iso.org/iso/catalogue_detail.htm?csnumber=44871 2 Ecma International 2015 http:/www.iso.org/iso/catalogue_detail.htm?csnumber=46311 ISO 4217:2008, Codes for the representation of currencies and fun
46、ds, or successor http:/www.iso.org/iso/iso_catalogue/catalogue_tc/catalogue_detail.htm?csnumber=46121 IETF BCP 47: RFC 5646, Tags for Identifying Languages, or successor http:/tools.ietf.org/html/rfc5646 RFC 4647, Matching of Language Tags, or successor http:/tools.ietf.org/html/rfc4647 IETF RFC 606
47、7, BCP 47 Extension U, or successor http:/tools.ietf.org/html/rfc6067 IANA Time Zone Database http:/www.iana.org/time-zones/ The Unicode Standard, Version 5.1, or successor http:/www.unicode.org/versions/latest Unicode Technical Standard 35, Unicode Locale Data Markup Language, version 21.0.1 or suc
48、cessor http:/unicode.org/reports/tr35/ 4 Overview This section contains a non-normative overview of the ECMAScript 2015 Internationalization API Specification. 4.1 Internationalization, Localization, and Globalization Internationalization of software means designing it such that it supports or can b
49、e easily adapted to support the needs of users speaking different languages and having different cultural expectations, and enables worldwide communication between them. Localization then is the actual adaptation to a specific language and culture. Globalization of software is commonly understood to be the combination of internationalization and localization. Globalization starts at the lowest level by using a text representation that supports al