diff options
| author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
|---|---|---|
| committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
| commit | 33058f2b292b3a581333bdfb21b8f671898c5060 (patch) | |
| tree | 51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/javascript/reference/global_objects/intl/collator | |
| parent | 8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff) | |
| download | translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2 translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip | |
initial commit
Diffstat (limited to 'files/zh-cn/web/javascript/reference/global_objects/intl/collator')
| -rw-r--r-- | files/zh-cn/web/javascript/reference/global_objects/intl/collator/index.html | 177 |
1 files changed, 177 insertions, 0 deletions
diff --git a/files/zh-cn/web/javascript/reference/global_objects/intl/collator/index.html b/files/zh-cn/web/javascript/reference/global_objects/intl/collator/index.html new file mode 100644 index 0000000000..640bb0b9e4 --- /dev/null +++ b/files/zh-cn/web/javascript/reference/global_objects/intl/collator/index.html @@ -0,0 +1,177 @@ +--- +title: Intl.Collator +slug: Web/JavaScript/Reference/Global_Objects/Intl/Collator +translation_of: Web/JavaScript/Reference/Global_Objects/Intl/Collator +--- +<div>{{JSRef}}</div> + +<p><strong><code>Intl.Collator<font face="Open Sans, Arial, sans-serif"> </font></code></strong><code>是用于语言敏感字符串比较的 collators构造函数。</code></p> + +<div>{{EmbedInteractiveExample("pages/js/intl-collator.html")}}</div> + + + +<h2 id="语法">语法</h2> + +<pre class="syntaxbox"><code>new Intl.Collator([<var>locales</var>[, <var>options</var>]]) +Intl.Collator.call(<var>this</var>[, <var>locales</var>[, <var>options</var>]])</code></pre> + +<h3 id="参数">参数</h3> + +<dl> + <dt><code>locales</code></dt> + <dd> + <p>可选. 缩写语言代码 (BCP 47 language tag, 例如: cmn-Hans-CN) 的字符串或者这些字符串组成的数组. 关于参数 locales 的一般形式和解释请参见{{jsxref("Global_Objects/Intl", "Intl page", "#Locale_identification_and_negotiation", 1)}}. 下面的这些 Unicode 扩展键也是被允许的:</p> + + <dl> + <dt><code>co</code></dt> + <dd>某些区域设置的变体归类。 可能的值包括:“big5han”,“dict”,“direct”,“ducet”,“gb2312”,“phonebk”,“phonetic”,“pinyin”,“reformed”,“searchjl”,“stroke” “,”unihan“。值“<code>standard</code>” 和 “<code>search</code>” 被忽略; 它们被 options 属性用法替换(详见下文)。</dd> + <dt><code>kn</code></dt> + <dd>是否应使用数字对照,使得 “1”<“2”<“10”。 可能的值为 “true” 和 “false”。 此选项可以通过 options 属性或通过 Unicode 扩展 key 设置; 如果两者都提供,options 属性优先。</dd> + <dt><code>kf</code></dt> + <dd><code>首先排序大写或者小写。可能的值为 “upper”,“lower” 或 “false”(使用区域设置的默认值)。 </code> 此选项可以通过 options 属性或通过 Unicode 扩展 key 设置; 如果两者都提供,options 属性优先。</dd> + </dl> + </dd> + <dt><code>options</code></dt> + <dd> + <p>可选. 包含一些或所有的下面属性的对象:</p> + + <dl> + <dt><code>localeMatcher</code></dt> + <dd>使用的 local 的匹配算法. 可能的值有 "lookup" 和 "best fit"; 默认值是 <code>"best fit"</code>. 有关此选项的信息, 请参见{{jsxref("Global_Objects/Intl", "Intl page", "#Locale_negotiation", 1)}}.</dd> + <dt><code>usage</code></dt> + <dd>比较是用于排序还是用于搜索匹配的字符串。 可能的值为 “sort” 和 “search”; 默认为 “sort”。</dd> + <dt><code>sensitivity</code></dt> + <dd> + <p>字符串中的哪些差异应导致结果值为非零(non-zero)。 可能的值有:</p> + + <ul> + <li><code>"base"</code>: 只有字母不同的字母比较不相等。例子: <code>a ≠ b</code>, <code>a = á</code>, <code>a = A。</code></li> + <li><code>"accent"</code>: 只有不同的基本字母或重音符号和其他变音符号的字符串比较为不相等。 例如: <code>a ≠ b</code>, <code>a ≠ á</code>, <code>a = A。</code></li> + <li><code>"case"</code>: 只有不同的基本字母或大小写的字符串比较不相等。 Examples: <code>a ≠ b</code>, <code>a = á</code>, <code>a ≠ A。</code></li> + <li><code>"variant"</code>: 字符串的字母,口音和其他变音符号、或不同大小写比较不相等。 也可以考虑其他差异。例如: <code>a ≠ b</code>, <code>a ≠ á</code>, <code>a ≠ A</code>.</li> + </ul> + + <p><code>"variant" 的默认值使用<font face="Open Sans, Arial, sans-serif"> </font></code><code>"sort"</code>; 它的 locale 依赖于使用 <code>"search"</code>.</p> + </dd> + <dt><code>ignorePunctuation</code></dt> + <dd>是否应忽略标点。 可能的值为 true 和 false; 默认值为 false。</dd> + <dt><code>numeric</code></dt> + <dd>是否应使用数字对照,使得 “1”<“2”<“10”。 可能的值为 “true” 和 “false”。默认值为 “false” 。 此选项可以通过 options 属性或通过 Unicode 扩展 key 设置; 如果两者都提供,options 属性优先。实现不需要支持此属性。</dd> + <dt><code>caseFirst</code></dt> + <dd><code>首先排序大写或者小写。可能的值为 “upper”,“lower” 或 “false”(使用区域设置的默认值)。 </code> 此选项可以通过 options 属性或通过 Unicode 扩展 key 设置; 如果两者都提供,options 属性优先。实现不需要支持此属性。</dd> + </dl> + </dd> +</dl> + +<h2 id="描述">描述</h2> + +<p><code>Intl.Collator</code> 类有一下属性和方法</p> + +<h3 id="属性">属性</h3> + +<dl> + <dt>{{jsxref("Collator.prototype", "Intl.Collator.prototype")}}</dt> + <dd>允许向所有对象添加属性。</dd> +</dl> + +<h3 id="方法">方法</h3> + +<dl> + <dt>{{jsxref("Collator.supportedLocalesOf", "Intl.Collator.supportedLocalesOf()")}}</dt> + <dd>返回包含所支持的所提供语言环境的数组的数组,而不必回退到运行时的默认语言环境。</dd> +</dl> + +<h2 id="Collator_实例"><code>Collator 实例</code></h2> + +<h3 id="属性_2">属性</h3> + +<p><code>Collator 实例从其原型继承以下属性:</code></p> + +<div>{{page('en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/prototype', 'Properties')}}</div> + +<h3 id="方法_2">方法</h3> + +<h3 id="Collator_实例从其原型继承以下方法:">Collator 实例从其原型继承以下方法:</h3> + +<div>{{page('en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/prototype', 'Methods')}}</div> + +<h2 id="例子">例子</h2> + +<h3 id="基本用法">基本用法</h3> + +<p>以下示例演示在另一个之前,之后或同级别发生的字符串的不同潜在结果:</p> + +<pre class="brush: js">console.log(new Intl.Collator().compare('a', 'c')); // → a negative value +console.log(new Intl.Collator().compare('c', 'a')); // → a positive value +console.log(new Intl.Collator().compare('a', 'a')); // → 0 +</pre> + +<p>请注意,上述代码中显示的结果可能会因浏览器和浏览器版本而异。 这是因为值是实现特定的。 也就是说,规范仅需要前后值为负和正。</p> + +<h3 id="使用_locales">使用 <code>locales</code></h3> + +<p>{{jsxref("Collator.prototype.compare()")}} 提供的结果在不同语言之间有所不同。为了获得用于您的应用程序的用户界面的语言格式,请确保设定了语言(可能还有一些回退语言)参数:</p> + +<pre class="brush: js">// 德语中, ä 使用 a 的排序 +console.log(new Intl.Collator('de').compare('ä', 'z')); +// → 一个负值 + +// 瑞典语中, ä 在 z 的后面 +console.log(new Intl.Collator('sv').compare('ä', 'z')); +// → 一个正值 +</pre> + +<h3 id="使用_options">使用 <code>options</code></h3> + +<p>{{jsxref("Collator.prototype.compare()")}} 提供的结果可以使用 options 参数自定义:</p> + +<pre class="brush: js">// 德语中, ä 使用 a 作为基本字母 +console.log(new Intl.Collator('de', { sensitivity: 'base' }).compare('ä', 'a')); +// → 0 + +// 瑞典语中, ä 和 a 是单独的基本字母 +console.log(new Intl.Collator('sv', { sensitivity: 'base' }).compare('ä', 'a')); +// → 一个正值 +</pre> + +<h2 id="规范">规范</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>{{SpecName('ES Int 1.0', '#sec-10.1', 'Intl.Collator')}}</td> + <td>{{Spec2('ES Int 1.0')}}</td> + <td>Initial definition.</td> + </tr> + <tr> + <td>{{SpecName('ES Int 2.0', '#sec-10.1', 'Intl.Collator')}}</td> + <td>{{Spec2('ES Int 2.0')}}</td> + <td> </td> + </tr> + <tr> + <td>{{SpecName('ES Int Draft', '#collator-objects', 'Intl.Collator')}}</td> + <td>{{Spec2('ES Int Draft')}}</td> + <td> </td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + +<div> +<div> + + +<p>{{Compat("javascript.builtins.Intl.Collator")}}</p> +</div> +</div> + +<h2 id="参见">参见</h2> + +<div>{{page('/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl', 'See_also')}}</div> |
