Intl.Locale
åºçº¿
广æ³å¯ç¨
*
èª 2020å¹´9æ èµ·ï¼æ¤ç¹æ§å·²å¨ä¸»æµæµè§å¨ä¸å¾å°æ¯æï¼å¯å¨å¤§å¤æ°è®¾å¤åæµè§å¨çæ¬ä¸æ£å¸¸ä½¿ç¨ã
* æ¤ç¹æ§çæäºé¨åçæ¯æç¨åº¦å¯è½ææä¸åã
Intl.Locale å¯¹è±¡æ¯ Intl å¯¹è±¡çæ åå
ç½®å±æ§ï¼ç¨äºè¡¨ç¤º Unicode åºåæ è¯ã
å°è¯ä¸ä¸
const korean = new Intl.Locale("ko", {
script: "Kore",
region: "KR",
hourCycle: "h23",
calendar: "gregory",
});
const japanese = new Intl.Locale("ja-Jpan-JP-u-ca-japanese-hc-h12");
console.log(korean.baseName, japanese.baseName);
// Expected output: "ko-Kore-KR" "ja-Jpan-JP"
console.log(korean.hourCycle, japanese.hourCycle);
// Expected output: "h23" "h12"
æè¿°
Intl.Locale 对象æ¯ä¸ºäºæ´ä¾¿æ·å°å¤ç Unicode åºå设置ãUnicode 使ç¨å符串ä½ä¸ºåºåè¯å«æ è¯ãåºåæ è¯ç¬¦ç±è¯è¨æ è¯ç¬¦åæ©å±æ è®°ç»æãè¯è¨æ è¯ç¬¦æ¯åºå (locale) çæ ¸å¿ï¼å
å«äºè¯è¨ãèæ¬åå°ååæ è®° (region subtags)ãæå
³åºå设置çå
¶ä»ä¿¡æ¯ä½ç°å¨å¯éçæ©å±æ è®°ä¸ãæ©å±æ è®°ä¿åæå
³åºå设置æ¹é¢çä¿¡æ¯ï¼ä¾å¦æ¥åç±»åãæ¶éç±»ååç¼å·ç³»ç»ç±»åã
ä¼ ç»ä¸ï¼Intl æ¥å£å Unicode 䏿 ·ä½¿ç¨å符串æ¥è¡¨ç¤ºåºå设置ï¼è¿æ¯ä¸ä¸ªç®åèè½»é䏿æå¥½çè§£å³æ¹æ¡ã使¯ï¼æ·»å ä¸ä¸ª Locale ç±»å¯ä»¥æ´å®¹æå°è§£æåæä½è¯è¨ãèæ¬ãåºå以忩屿 è®°ã
æé 彿°
Intl.Locale()-
å®ä¾åä¸ä¸ª
Locale对象ã
å®ä¾å±æ§
Intl.Locale.prototype.baseName-
Returns basic, core information about the
Localein the form of a substring of the complete data string. Intl.Locale.prototype.calendar-
Returns the part of the
Localethat indicates the Locale's calendar era. Intl.Locale.prototype.caseFirst-
Returns whether case is taken into account for the locale's collation rules.
Intl.Locale.prototype.collation-
Returns the collation type for the
Locale, which is used to order strings according to the locale's rules. Intl.Locale.prototype.hourCycle-
Returns the time keeping format convention used by the locale.
Intl.Locale.prototype.language-
Returns the language associated with the locale.
Intl.Locale.prototype.numberingSystem-
Returns the numeral system used by the locale.
Intl.Locale.prototype.numeric-
Returns whether the locale has special collation handling for numeric characters.
Intl.Locale.prototype.region-
Returns the region of the world (usually a country) associated with the locale.
Intl.Locale.prototype.script-
Returns the script used for writing the particular language used in the locale.
å®ä¾æ¹æ³
Intl.Locale.prototype.maximize()-
Gets the most likely values for the language, script, and region of the locale based on existing values.
Intl.Locale.prototype.minimize()-
Gets the most likely values for the language, script, and region of the locale based on existing values.
Intl.Locale.prototype.toString()-
Returns the Locale's full locale identifier string.
èä¾
>åºæ¬ä½¿ç¨
å¾ç®åï¼å°±æ¯éè¦ç»Intl.Locale æé 彿°ä¼ å
¥ä¸ä¸ª locale æ è¯å符串ä½ä¸ºåæ°ï¼
let us = new Intl.Locale("zh-Hans-CN");
使ç¨é ç½®å®ä¾å
æé 彿°æ¯æä¼ å
¥ object ä½ä¸ºé
ç½®ï¼object ä¸å¯å
å«å¤ä¸ªé
ç½®å±æ§ãä¾å¦ï¼è®¾ç½® hourCycle 屿§ï¼ç¨äºè®¾ç½®ä½ æéè¦çå°æ¶å¨æç±»åï¼
let zh12hour = new Intl.Locale("zh-Hans-CN", { hourCycle: "h12" });
console.log(zh12hour.hourCycle); // Prints "h12"
è§è
| è§è |
|---|
| ECMAScript® 2027 Internationalization API Specification> # locale-objects> |