车船税是什么意思每年都交吗| 尿常规阳性是什么意思| cook是什么意思| 鹿参膏有什么作用和功效| 洗纹身去医院挂什么科| 眩晕吃什么药| 男人忽冷忽热说明什么| 草木皆兵是什么意思| 麝牛是什么动物| 黄芪最佳搭配是什么| 千年等一回是什么生肖| 往生净土是什么意思| 冠脉ct和冠脉造影有什么区别| 行动派是什么意思| 什么孩子该看心理医生| 嫡母是什么意思| 吃了牛肉不能吃什么| 老蒯是什么意思| 世事无常什么意思| 氧气湿化瓶里加什么水| 肝不好吃什么药效果好| 人类是什么时候出现的| 嗣是什么意思| 九月二十二是什么星座| 五月二十日是什么星座| 鸡眼用什么药| 什么蛇没毒| bdsm什么意思| 贵妇是什么意思| 梦见自己刷牙是什么意思| 稼字五行属什么| 股骨头坏死有什么症状| 政协是干什么的| 什么是发票抬头| 胃炎吃什么食物好得快| 布吉岛什么意思| 六月份生日是什么星座| 什么都想吃| 急性支气管炎吃什么药| 乙肝看什么指标| 纳采是什么意思| 圣母娘娘是什么神| 蚊子为什么会咬人| 口腔溃疡缺什么| 鸡属相和什么属相最配| 早醒是什么原因造成的| 鼻子旁边有痣代表什么| 腺瘤型息肉是什么意思| 亲子鉴定挂什么科| 为什么会紫外线过敏| 绿萝叶子发黄是什么原因| 矫正度数是什么意思| camel什么意思| 杨枝甘露是什么意思| 什么水果是降火的| 女人是什么| d二聚体偏高说明什么| 看十全十美是什么生肖| 护理专业是做什么的| 芋圆用什么粉做的| 表现优异是什么意思| 割包皮是什么意思| 淋巴结用什么药效果好| 檀是什么意思| 五根手指叫什么| 原配是什么意思| epa是什么| 糖化血糖是什么意思| 心脏除颤是什么意思| 纪元是什么意思| 可乐加味精女人喝了什么效果| 结婚15年是什么婚| 包拯属什么生肖| 狗狗拉稀是什么原因| 什么是跨境电商| 茄子有什么营养| 女性口苦是什么原因引起的| 半边脸疼是什么原因| 针对性是什么意思| 怀孕前有什么症状| 尿酸高要注意什么饮食| 小便多吃什么药好| 变色龙指什么人| 什么原因引起低压高| 恐龙灭绝的原因是什么| 欲壑难填是什么意思| 做完人流可以吃什么| 微信加入黑名单和删除有什么区别| 嘴角长水泡是什么原因| 下腹痛挂什么科| 法界是什么意思| 性激素检查是查什么| 盛情款待是什么意思| 什么是收缩压和舒张压| 天行健下一句是什么| 胆红素高是什么意思| 吃什么可以补阳气| 润什么意思| 成熟是什么意思| 鸡打瞌睡吃什么药| leslie什么意思| 韩语欧巴是什么意思| 寒湿重吃什么药| 参谋长是什么级别| 慈禧为什么要毒死光绪| 游戏黑洞是什么意思| 黄金为什么这么贵| 玉兔是什么意思| 转网是什么意思| 睡觉吹气是什么原因| 无限极是干什么的| bag是什么意思| 万言万当不如一默是什么意思| 经常长溃疡是什么原因引起的| 梅毒吃什么药好得快| 血虚吃什么中成药| 云肖是什么生肖| 化疗期间吃什么好| 冷战的男人是什么心理| 吃了龙虾后不能吃什么| 散瞳是什么意思| 口腔起血泡是什么原因| 什么是龙骨| 率的部首是什么| 玫瑰金是什么颜色| 相濡以沫是什么意思| 轻度高血压吃什么食物可以降压| 怀孕六个月出血是什么原因| 什么的芦苇| 乌豆是什么| 榴莲为什么苦| nsfw是什么意思| 什么生肖不认识路| 产后复查挂什么科| 陈字五行属什么| 胳膊脱臼是什么症状| 滑膜炎吃什么药最好| 男孩学什么专业有前途| 氯化钠注射液是什么| 海带排骨汤海带什么时候放| 沙肝是什么| 射手属于什么象星座| 阴毛的作用是什么| 女人打呼噜是什么原因| 女人怕冷是什么原因| 前列腺增生吃什么药见效快| 靓仔是什么意思| 泌尿系统由什么组成| 什么时候做人流才是最佳时间| 梦见佛像是什么意思| 大学是什么学历| 短裙配什么上衣好看| 蜘蛛代表什么生肖| 晚霞是什么颜色的| 7月22日是什么星座| 空代表什么生肖| 什么是核糖核酸| skin是什么意思| 晴雨表是什么意思| 肚脐左侧是什么器官| 行云流水是什么意思| 金铃子是什么昆虫| 胆固醇高是什么病| 高筋面粉适合做什么| 成吉思汗姓什么| 用什么泡水喝补肾| 什么话| 奶阵是什么意思| 弯弯是什么意思| 一什么湖面| 大白刁是什么鱼| 康熙是乾隆的什么人| 游泳比赛中wj是什么意思| 星期狗什么意思| 里长是什么官| 叶酸在什么食物里最多| 钦字五行属什么| 贼是什么生肖| 身上为什么会长小肉球| 西瓜虫吃什么食物| 妇科检查bv阳性是什么意思| 什么药可以催月经来| 宰相和丞相有什么区别| 长孙是什么意思| 冰岛说什么语言| 国印贵人是什么意思| 牛油果是什么味道的| 熬夜为什么会胖| 刷屏是什么意思| 股长是什么职位| 青蟹什么季节吃最好| 我到底是什么| qcy是什么牌子| 血管属于什么组织| 苯甲酸钠是什么东西| 茶学专业学什么| 什么情况下需要做喉镜检查| 梦见自己牙齿掉光了是什么征兆| 宝宝爱出汗是什么原因| 珏字五行属什么| 坐卧针毡是什么生肖| wz是什么意思| 梦到谈恋爱预示着什么| 金星原名叫什么| 5月1日什么星座| 什么时候喝咖啡最好| 人子是什么意思| 师范类是什么意思| 狐臭用什么药最好| 做梦捡到钱是什么意思| 小孩子长白头发是什么原因| 鸳鸯浴是什么意思| 梦见自己会开车了是什么意思| 衣服36码相当于什么码| 下一个台风什么时候来| 什么是奇门遁甲| 男人山根有痣代表什么| 疴是什么意思| 秦始皇为什么叫祖龙| 头疼发烧是什么原因| 梦见狼是什么预兆| 内膜厚吃什么药掉内膜| 法克油是什么意思| 山药长什么样| 排尿少是什么原因| 白膜是什么东西| 结婚五周年是什么婚| 已故是什么意思| 曼珠沙华是什么意思| 牙龈疼是什么原因| 2月20日是什么星座| 人体电解质是什么| 固精是什么意思| 什么平稳| espresso是什么咖啡| 什么时辰出生的人命好| 夜阑珊是什么意思| 什么是公共场所| mi什么意思| 三班两倒是什么意思| 百年灵手表什么档次| 酸萝卜别吃什么意思| 素金是什么意思| 支气管炎能吃什么水果| 梭织面料是什么面料| 1921年是什么年| 五味是什么| 才高八斗是什么意思| 逼是什么| 尿出红色的尿是什么原因| 有胃火口臭怎么办吃什么药| 尿蛋白高是什么病| 春天有什么| 屎为什么是黑色的| 尖酸刻薄什么意思| 什么食物含锌最多| 乙肝核心抗体偏高是什么意思| 甘露茶叶属于什么茶| 侃大山什么意思| 心脏右束支传导阻滞是什么意思| 蜂蜜可以做什么美食| 博爱是什么意思| 膝盖痛吃什么药好| 扁桃体2度是什么意思| 百度
Norbert’s Corner

Google Home智能扬声器闯祸了?疑被批传播假新闻

December 18, 2012
百度 1975年矶村英一出版了《城市学》一书。

The ECMAScript Internationalization API Specification provides collation (string comparison), number formatting, and date and time formatting for JavaScript applications, and lets applications choose the language and tailor the functionality to their needs. It is designed as an extension of the ECMAScript Language Specification, the standard underlying JavaScript, and can be added to JavaScript runtimes that implement the fifth edition of the ECMAScript Language Specification, without waiting for the sixth edition to be completed and implemented. The API was developed by a working group with members from Google, Microsoft, Mozilla, Amazon, and IBM, with myself joining first as an invited expert and then for Mozilla. The standard was approved by the Ecma General Assembly in December 2012 to become an official standard, ECMA-402. Implementations for several browsers are under way.

Like its big brother, the ECMAScript Language Specification, the Internationalization API Specification is written largely in the form of pseudocode, which makes it somewhat difficult to understand. This article provides background and a guide to the specification.

Why an Internationalization API?

The ECMAScript Language Specification offers little internationalization support. Strings are based on Unicode, which is a good start. There are a few locale sensitive functions, in particular String.prototype.localeCompare, Number.prototype.toLocaleString, and Date.prototype.toLocaleString with its date- and time-only variants. However, none of these functions let applications specify the language or control details of their behavior, so they’re pretty useless in practice. And that’s pretty much it.

Some JavaScript libraries, such as Dojo, Closure, Globalize, YUI, or Moment, have filled in some of the gaps by providing their own number and date formatting as well as mechanisms for loading localized resources. Collation, however, requires large tables and complicated algorithms, and so the typical solution has been to send string lists back to a server with a good internationalization library and have them sorted there. This introduces delays, and doesn’t work at all for code that’s not connected to a server, such as JavaScript-based user interface extensions.

At the same time, ECMAScript implementations, whether they’re part of browsers, servers, or other systems, run on top of operating systems that already include comprehensive internationalization libraries. The goal of the ECMAScript Internationalization API is to provide JavaScript applications with a standard interface to these internationalization libraries.

Functionality of the API

The functionality of the first version of the API is fairly limited and mirrors the functionality of the core language: Collation (string comparison), number formatting, and date and time formatting. However, it lets applications specify languages, assisting with language negotiation, as well as control details of the behavior. One major omission even in the provided functionality is comprehensive time zone support: Not all internationalization libraries offer this yet, so for now only UTC and the “host environment’s current time zone” (in a browser, that’s usually the time zone the user has set for the operating system) are supported. Of other common internationalization functionality, resource loading is missing because ECMAScript doesn’t have an I/O system to build on, message construction is missing because the working group couldn’t converge on a solution fast enough, and normalization and other functionality are missing because their priority is lower than that of the chosen three.

The existing locale sensitive methods String.prototype.localeCompare, Number.prototype.toLocaleString, and Date.prototype.toLocaleString with its date- and time-only variants were respecified to take locale and other parameters and interpret them in the same way as the new API introduced by the Internationalization API Specification.

The API can be used in two ways:

Identification of Locales, Currencies, and Time Zones

The API relies on widely used standards to identify locales and currencies: IETF Best Current Practice (BCP) 47, and ISO 4217.

BCP 47 consists of two RFCs, currently 5646 and 4647, and the IANA Language Subtag Registry. The language tags it defines are used in HTML, CSS, XML, HTTP, and other standard formats and protocols. In most cases, language tags are straightforward: A language code, possibly a script code, possibly a country code, all separated by hyphens: "de" for German, "zh-Hans" for simplified Chinese, "zh-Hans-SG" for simplified Chinese as used in Singapore. However, BCP 47 allows for extensions, and so far two have been defined. The newer one of these, the "t" or Transformed Content extension defined in RFC 6497, can be safely ignored by the Internationalization API. On the other hand, the "u" or Unicode extension, defined in RFC 6067 and Unicode Technical Standard 35, matters a lot. This extension allows the specification of additional parameters for collation, number formatting, and date and time formatting as part of a language tag, and so it has to be taken into consideration in the design of language and parameter negotiation in the API, as discussed below. The possibility of parameters that are not related to languages is the reason why the more generic term “locale” is used.

ISO 4217 defines both numeric and alphabetic codes for currencies, of which the Internationalization API uses only the alphabetic 3-letter codes. The code list also provides information on the number of digits typically used to represent the minor units of a currency, e.g. 2 for the euro (which has 100 cents), or 0 for the yen (whose minor unit sen isn’t used anymore).

For time zones, there isn’t much to identify: This version of the API only supports UTC and the host environment’s current time zone. The first is identified by "UTC". There is no identifier for the second; it’s used when the time zone is left undefined.

The Intl Object

The Intl object provides a namespace for the constructors of the Internationalization API – we expect that over time the API will add more constructors, and want to minimize the risk of name collisions. Its name started out as Internationalization or its uglified form i18n; for a while we used Globalization; finally we switched to Intl because it’s shorter. Other candidates were Text, Presentation, Format, World, or 国际化 (nothing beats Chinese for brevity!).

Locale Lists

The constructors in the Internationalization API as well as the updated locale sensitive methods on String, Number, and Date accept either single language tags or locale lists, which should reflect the user’s language preferences. Locale lists are represented as simple arrays of language tags. For a while, we were planning to have specialized LocaleList objects in the API, array-like objects that verified during their construction that all their elements were well-formed language tags, and canonicalized them for easier processing by other API. However, there wasn’t enough evidence that they really make processing that much easier and faster, and so the API now uses normal arrays throughout. Language tags are now verified and canonicalized by the constructors and methods that accept arrays of language tags.

The working group discussed extensively whether there should be an API to set a default locale list that would then be used throughout the Internationalization API. Two issues prevent this: First, a settable default locale list would create a global communication channel between different scripts running within the same environment, which is considered a security risk. Second, an application may include different components, such as embedded apps, that need different default locales. ECMAScript has no knowledge of these components and no way to manage appropriate contexts for them. We decided therefore that a default locale is better left to higher-level systems. For example, the YUI library already includes an Intl module which manages a list of requested locales that is scoped to the containing YUI object and used for loading resource bundles. This module could easily be modified to keep a locale list object so that it can be used as a default within the scope of the containing YUI object.

Locale and Parameter Negotiation

The constructors for the three locale sensitive services, Collator, NumberFormat, and DateTimeFormat, as well as the respecified locale sensitive functions in String, Number, and Date each take a language tag or locale list and an options argument. Together, these arguments form a request, which the constructors compare against the capabilities of their implementations to determine the actual locale and parameter settings to be used (a somewhat one-sided “negotiation”). Applications can find out about the result of the negotiation for constructed objects through the resolvedOptions method. The request passed to the API may be fixed by the application (an application that only supports one language will request exactly that language), or may be the result of a higher-level negotiation between user preferences and application capabilities. The API does not deal with such higher-level negotiations.

For language negotiation, BCP 47 provides a simple “lookup” algorithm, which compares a request consisting of a prioritized list of language tags with a set of available languages. It takes the language tags of the request in sequence and checks for each one whether it can be matched with one of the available languages either directly or with a fallback, where the fallback simply strips off subtags from the end, e.g., from "zh-Hans-SG" to "zh-Hans". The first match wins.

The lookup algorithm doesn’t always provide the best possible results. For example, if "es-GT" (Spanish for Guatemala) is requested, but not available, it falls back to "es", which is typically implemented as Spanish for Spain. A better choice might be the Spanish variant used in Guatemala’s neighbor Mexico, "es-MX". The API specification therefore allows implementations to provide a better “best fit” algorithm, and makes this algorithm the default.

As mentioned earlier, the Unicode extension of BCP 47 allows a number of parameters to be set as part of a language tag. For example, the use of the euro with a simplified Chinese currency format can be specified as "zh-Hans-u-cu-eur", the use of the sort order for German phone books as "de-u-co-phonebk". Multiple parameters can be combined in one language tag, e.g., "de-u-co-phonebk-cu-usd" for German with phone book sorting and the U.S. dollar as currency.

The Unicode extension creates two issues:

The algorithms involved in locale and parameter negotiation solve these issues in two ways:

The need to decide for each key in the Unicode extension how it should be treated in the API unfortunately means that the specification cannot allow implementations to support newly added keys.

The options object can contain not only properties corresponding to some of the keys of the Unicode extension, but also properties for other parameters that let the application control the behavior of the constructed object. Most parameters have default values (either provided by the specification or locale and implementation dependent), so that for the most common use cases the options object can be omitted.

Applications can get information about the results of locale and parameter negotiation for constructed objects through the resolvedOptions method, which returns an object with properties for all parameters except the matcher parameters. The locale property contains a language tag with the locale that was selected among the implementation’s available locales, plus those Unicode extension parameters that were requested and are supported by the implementation. Applications can also use the supportedLocalesOf functions to determine which subset of a list of locales is supported by an implementation, possibly through fallbacks. There’s no function to get a list of all locales supported by an implementation as this list could be huge.

Collation

Collator objects and String.prototype.localeCompare support two usage scenarios: Sorting the strings in a list, and searching for matching strings in a set of strings. Sorting generally needs to be sensitive to minor differences in strings, such as diacritical marks or casing, so that it is clear whether pêche sorts before or after péché. In searching, on the other hand, such minor differences are often ignored. (Some languages, however, treat certain characters with diacritical marks as separate characters, thus considering the marks major differences.) For some languages, collation may define several sort orders, such as the dictionary and phone book sort orders for German, which differ in their handling of umlauted characters. In some applications, punctuation should be ignored in comparison.

The Unicode extension defines a number of additional parameters. Some of these parameters require special handling:

Collator and String.prototype.localeCompare use the following parameters:

?Pa-ram-e-ter ?Lan-guage Tag ?Options Values
locale ? BCP 47 lan-guage tag
locale-Matcher ? "best fit", "lookup"
usage (collation) co ? "sort", "search"
sensitivity (strength) ks ? "base", "accent", "case", "variant"
ignore-Punctua-tion (alternate handling) ka ? true, false
collation co ? see UTS 35, except "standard", "search"
numeric kn ? ? true, false
case-First kf ? ? "upper", "lower", "false"

Usage Examples

Sort array a according to the rules of the host environment’s current locale (the compare method is bound to its Collator so it can be passed directly to functions such as Array.prototype.sort):

var collator = new Intl?.Collator?();

a?.sort?(collator?.compare);

Sort array a according to the rules for German phone books:

var collator = new Intl?.Collator?("de-u-co-phonebk");

a?.sort?(collator?.compare);

The same could be done with String.prototype.localeCompare, but that doesn’t actually simplify the code because localeCompare cannot be passed directly to sort, and is less efficient because locale negotiation has to be repeated for each string comparison:

a?.sort?(function (x, y) {

return x?.localeCompare?(y, "de-u-co-phonebk");

});

Extract those elements from array a that are similar to string s according to the rules of language lang:

var collator = new Intl?.Collator?(lang, {usage: "search"});

var matches = a?.filter?(function (v) {

return collator?.compare?(v, s) === 0;

});

Check whether a newly constructed Collator object supports numeric sorting; if not, use a function that enhances the collator’s behavior with this feature:

var collator = new Intl?.Collator?(locales, {numeric: true});

var f;

if (collator?.resolvedOptions?().numeric) {

f = collator?.compare;

} else {

f = makeNumericCompare?(collator);

}

a?.sort?(f);

Number Formatting

NumberFormat objects and Number.prototype.toLocaleString support three format styles: plain decimal formatting, currency formatting, and percent formatting. For currency formatting the currency must be specified by the application because currency use depends on business requirements that NumberFormat cannot know about. Different numbering systems can be used, depending on implementation and locale: Western (“ASCII”) digits, (real) Arabic digits, Thai digits, Roman numerals, and more. The number of digits used to represent a number can be constrained, subject to the same limitations as for Number.prototype.toFixed and Number.prototype.toPrecision; defaults depend on the format style and, in the case of currency formatting, the currency being used. The use of grouping separators can be disabled.

NumberFormat and Number.prototype.toLocaleString use the following parameters:

?Pa-ram-e-ter ?Lan-guage Tag ?Options Values
locale ? BCP 47 lan-guage tag
locale-Matcher ? "best fit", "lookup"
numbering-System nu ? see UTS 35
style ? "decimal", "currency", "percent"
currency cu ? ISO 4217 alphabetic code
currency-Display ? "code", "symbol", "name"
minimum-Integer-Digits ? 1..21
minimum-Fraction-Digits ? 0..20
maximum-Fraction-Digits ? 0..20
minimum-Significant-Digits ? 1..21
maximum-Significant-Digits ? 1..21
use-Grouping ? true, false

Usage Examples

Format number n in decimal style with grouping separators according to the rules of the host environment’s current locale:

var result = n?.toLocaleString?();

Format number n in decimal style with grouping separators according to the rules of language lang:

var result = n?.toLocaleString?(lang);

Find the best available language among Marathi, Hindi, and English as used in India, and format number n in decimal style with grouping separators according to the rules of the selected language:

var result = n?.toLocaleString?(["mr", "hi", "en-IN"]);

Format number n in currency style with grouping separators, with the localized currency symbol for Korean won, but with no fraction digits (the default for Korean won), according to the rules of language lang:

var result = n?.toLocaleString?(lang, {style: "currency", currency: "KRW"});

Apply the same format to a large array of numbers n, where reusing a NumberFormat object is likely to yield better performance (the format method is bound to its NumberFormat object, so it can be passed directly to functions such as Array.prototype.map):

var format = new Intl?.NumberFormat?(lang, {style: "currency", currency: "KRW"});

var result = n?.map?(format?.format);

Format number n in percent style with grouping separators, with at least 4 significant digits, according to Thai rules and with Thai digits:

var result = n?.toLocaleString?("th-u-nu-thai", {style: "percent", minimumSignificantDigits: 4});

Check whether a newly constructed NumberFormat object supports Tamil digits; if not, use a post-processing function:

var format = new Intl?.NumberFormat?("ta-u-nu-tamldec");

var result = format?.format?(n);

if (format?.resolvedOptions?().numberingSystem !== "tamldec") {

result = convertToTamilDigits?(result);

}

Date and Time Formatting

DateTimeFormat objects and Date.prototype.toLocaleString with its date- and time-only variants format a time value into a string using a subset of the following date and time components: weekday, era, year, month, day, hour, minute, second, and time zone name. Different representations of these components are available: unconstrained or 2-digit numeric; narrow, short, or long text. Implementations are required to support at least the following subsets:

Implementations may support other subsets, and requests will be negotiated against all available subset-representation combinations to find the best match. Two algorithms are available for this negotiation: A fully specified “basic” algorithm and an implementation dependent “best fit” algorithm (the latter is the default). Different numbering systems can be used, as with NumberFormat. Hour representations can be forced from a locale-dependent default to 12-hour or 24-hour format. Implementations may support multiple calendars per locale; for time zones, they’re limited to UTC and the host environment’s current time zone.

DateTimeFormat and Date.prototype.toLocaleString with its date- and time-only variants use the following parameters:

?Pa-ram-e-ter ?Lan-guage Tag ?Options Values
locale ? BCP 47 lan-guage tag
locale-Matcher ? "best fit", "lookup"
format-Matcher ? "best fit", "basic"
calendar ca ? see UTS 35
numbering-System nu ? see UTS 35
time-Zone tz ? "UTC"
hour12 ? true, false
weekday ? "narrow", "short", "long"
era ? "narrow", "short", "long"
year ? "2-digit", "numeric"
month ? "2-digit", "numeric", "narrow", "short", "long"
day ? "2-digit", "numeric"
hour ? "2-digit", "numeric"
minute ? "2-digit", "numeric"
second ? "2-digit", "numeric"
time-Zone-Name ? "short", "long"

Usage Examples

Format the current date with year, month, and day components in numeric format for the host environment’s current locale and time zone:

var result = (new Date?()).toLocaleDateString?();

Format time t with weekday, year, month, and day components in long format for the host environment’s current time zone according to Thai conventions with the Thai Buddhist calendar and Thai digits:

var result = (new Date?(t)).toLocaleDateString?("th-u-ca-buddhist-nu-thai", {weekday: "long", year: "long", month: "long", day: "long"});

Format the current time with hour, minute, and second components in 2-digit format and 24-hour time for the UTC time zone and the best available locale from list locales:

var result = (new Date?()).toLocaleTimeString?(locales, {hour: "2-digit", minute: "2-digit", second: "2-digit", hour12: false, timeZone: "UTC"});

Check whether a newly constructed DateTimeFormat object supports the Islamic calendar; if not, use a function that does:

var format = new Intl?.DateTimeFormat?("ar-EG-u-ca-islamicc");

var result;

if (format?.resolvedOptions?().calendar === "islamicc") {

result = format?.format?(new Date?());

} else {

result = formatWithIslamicCalendar?(new Date?());

}

Initializing Subclass Objects

ECMAScript is not a class-based language, but developers have invented several ways of simulating class hierarchies. In this context it’s necessary to call the superclass constructor while actually constructing a subclass instance, and so use the superclass constructor as a function, not within a new expression. Unlike the constructors in the ECMAScript Language Specification, the constructors in the Internationalization API are designed to allow this usage:

function MyCollator?(locales, options) {

Intl?.Collator?.call?(this, locales, options);

// initialize MyCollator properties

}

MyCollator?.prototype = Object?.create?(Intl?.Collator?.prototype);

MyCollator?.prototype?.constructor = MyCollator;

// add methods to MyCollator?.prototype

?

var collator = new MyCollator?("de-u-co-phonebk");

a?.sort?(collator?.compare);

Detecting the Internationalization API

Detecting whether the new Intl object and its constructors are available is easy:

var hasIntl = this?.hasOwnProperty?("Intl") && typeof Intl === "object";

var hasCollator = hasIntl && Intl?.hasOwnProperty?("Collator");

Detecting whether the old methods of String, Number, and Date follow the new specification is a bit trickier. Their return values depend on the language they select and on the specific implementation of that language, so they’re hard to predict. You could use an indirect test to detect Intl and assume that if it’s there the old methods will have been updated as well, but that’s, well, a bit indirect. Now, there’s one aspect where the new specification requires predictable results: Rejection of invalid values for the new arguments. For example, "i" is an invalid language tag and must be rejected with a RangeError exception.

function hasNewLocaleCompare?() {

try {

"a".localeCompare?("b", "i");

} catch (e) {

return e?.name === "RangeError";

}

return false;

}

Can I Try?

You can: Google Chrome version 24, currently in beta, implements the API with Collator, NumberFormat, and DateTimeFormat objects as described above. Be aware though that it still fails quite a few tests of the ECMA-402 conformance test suite.

Changes from the Previous Version

Earlier versions of this article were published in October 2012, June 2012, February 2012, and November 2011. The following significant changes were made since the October version:

诺贝尔奖为什么没有数学奖 10月11是什么星座 什么事每人每天都必须认真的做 夏天为什么容易拉肚子 月关是什么意思
龙眼和桂圆有什么区别 肋下未及是什么意思 英国的全称是什么 鸡项是什么鸡 腰疼不能弯腰是什么原因引起的
18k金是什么 十月十三是什么星座 胃反酸水是什么原因 什么是善 肚子胀疼是什么原因
锁阳是什么东西 当演员有什么要求 醍醐灌顶什么意思 指甲有竖纹是什么病 凉瓜是什么瓜
月子里可以吃什么蔬菜hcv8jop4ns4r.cn 肺部ct挂什么科hcv8jop2ns5r.cn 蚱蜢吃什么食物liaochangning.com 领袖是什么意思hcv9jop0ns4r.cn 母子健康手册有什么用hcv9jop7ns2r.cn
云仓是什么hcv8jop0ns3r.cn 肝胃不和吃什么中成药zsyouku.com 丙肝是什么病严重吗liaochangning.com 什么时候打仗hcv9jop5ns4r.cn 苹果a1660是什么型号hcv7jop6ns5r.cn
新生儿不睡觉是什么原因hcv8jop5ns6r.cn pd999是什么金hcv9jop0ns6r.cn 菩提什么意思hcv9jop2ns7r.cn 什么是环切手术hcv8jop8ns9r.cn 闭口粉刺是什么原因引起的hcv9jop2ns7r.cn
牙齿什么时候换完hcv8jop2ns6r.cn 电轴右偏什么意思hcv9jop6ns2r.cn 消化不良吃什么药最好hcv9jop1ns6r.cn 资生堂适合什么年龄段hcv9jop8ns3r.cn 黄金茶属于什么茶hcv8jop7ns5r.cn
百度