aboutsummaryrefslogtreecommitdiff
path: root/files/de/web/javascript/reference/global_objects/intl/pluralrules/index.html
blob: fe646e477264056997d1c44eff0fec7083b1a6f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
---
title: Intl.PluralRules
slug: Web/JavaScript/Reference/Global_Objects/Intl/PluralRules
tags:
  - Internationalization
  - Intl
  - JavaScript
  - NeedsTranslation
  - PluralRules
  - TopicStub
translation_of: Web/JavaScript/Reference/Global_Objects/Intl/PluralRules
---
<div>{{JSRef}}</div>

<p>The <strong><code>Intl.PluralRules</code></strong> object is a constructor for objects that enable plural sensitive formatting and plural language language rules.</p>

<h2 id="Syntax">Syntax</h2>

<pre class="syntaxbox"><code>new Intl.PluralRules([<var>locales</var>[, <var>options</var>]])
Intl.PluralRules.call(<var>this</var>[, <var>locales</var>[, <var>options</var>]])
</code></pre>

<h3 id="Parameters">Parameters</h3>

<dl>
 <dt><code>locales</code></dt>
 <dd>
 <p>Optional. A string with a BCP 47 language tag, or an array of such strings. For the general form and interpretation of the <code>locales</code> argument, see the {{jsxref("Intl", "Intl page", "#Locale_identification_and_negotiation", 1)}}.</p>
 </dd>
 <dt><code>options</code></dt>
 <dd>
 <p>Optional. An object with some or all of the following properties:</p>

 <dl>
  <dt><code>localeMatcher</code></dt>
  <dd>The locale matching algorithm to use. Possible values are <code>"lookup"</code> and <code>"best fit"</code>; the default is <code>"best fit"</code>. For information about this option, see the {{jsxref("Global_Objects/Intl", "Intl page", "#Locale_negotiation", 1)}}.</dd>
  <dt><code>type</code></dt>
  <dd>The type to use. Possible values are:
  <ul>
   <li><code>"cardinal"</code> for cardinal numbers (refering to the quantity of things). This is the default value.</li>
   <li><code>"ordinal"</code> for ordinal number (refering to the ordering or ranking of things, e.g. "1st", "2nd", "3rd" in English).</li>
  </ul>
  </dd>
 </dl>
 </dd>
</dl>

<h2 id="Description">Description</h2>

<h3 id="Properties">Properties</h3>

<dl>
 <dt>{{jsxref("PluralRules.prototype", "Intl.PluralRules.prototype")}}</dt>
 <dd>Allows the addition of properties to all objects.</dd>
</dl>

<h3 id="Methods">Methods</h3>

<dl>
 <dt>{{jsxref("PluralRules.supportedLocalesOf", "Intl.PluralRules.supportedLocalesOf()")}}</dt>
 <dd>Returns an array containing those of the provided locales that are supported without having to fall back to the runtime's default locale.</dd>
</dl>

<h2 id="PluralRules_instances"><code>PluralRules</code> instances</h2>

<h3 id="Properties_2">Properties</h3>

<p><code>PluralRules</code> instances inherit the following properties from their prototype:</p>

<div>{{page('/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/prototype', 'Properties')}}</div>

<h3 id="Methods_2">Methods</h3>

<p><code>PluralRules</code> instances inherit the following methods from their prototype:</p>

<div>{{page('/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/prototype', 'Methods')}}</div>

<h2 id="Examples">Examples</h2>

<h3 id="Basic_usage">Basic usage</h3>

<p>In basic use without specifying a locale, a formatted string in the default locale and with default options is returned. This is useful to distinguish between singular and plural forms, e.g. "dog" and "dogs".</p>

<pre class="brush: js">var pr = new Intl.PluralRules();

pr.select(0);
// → 'other' if in US English locale

pr.select(1);
// → 'one' if in US English locale

pr.select(2);
// → 'other' if in US English locale
</pre>

<h3 id="Using_locales">Using <code>locales</code></h3>

<p>This example shows some of the variations in localized plural rules. In order to get the format of the language used in the user interface of your application, make sure to specify that language (and possibly some fallback languages) using the <code>locales</code> argument:</p>

<pre class="brush: js">// Arabic has different plural rules

new Intl.PluralRules('ar-EG').select(0);
// → 'zero'
new Intl.PluralRules('ar-EG').select(1);
// → 'one'
new Intl.PluralRules('ar-EG').select(2);
// → 'two'
new Intl.PluralRules('ar-EG').select(6);
// → 'few'
new Intl.PluralRules('ar-EG').select(18);
// → 'many'
</pre>

<h3 id="Using_options">Using <code>options</code></h3>

<p>The results can be customized using the <code>options</code> argument, which has one property called <code>type</code> which you can set to <code>ordinal</code>. This is useful to figure out the ordinal indicator, e.g. "1st", "2nd", "3rd", "4th", "42nd" and so forth.</p>

<pre class="brush: js">var pr = new Intl.PluralRules('en-US', { type: 'ordinal' });

pr.select(0);
// → 'other'
pr.select(1);
// → 'one'
pr.select(2);
// → 'two'
pr.select(3);
// → 'few'
pr.select(4);
// → 'other'
pr.select(42);
// → 'two'
</pre>

<h2 id="Specifications">Specifications</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><a href="https://rawgit.com/caridy/intl-plural-rules-spec/master/index.html">Intl Plural Rules Draft</a></td>
   <td>{{Spec2('ES Int Draft')}}</td>
   <td>Initial definition</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>

<div>


<p>{{Compat("javascript.builtins.Intl.PluralRules")}}</p>
</div>

<h2 id="See_also">See also</h2>

<div>{{page('/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl', 'See_also')}}</div>