-
Notifications
You must be signed in to change notification settings - Fork 8k
/
index.md
60 lines (38 loc) · 1.87 KB
/
index.md
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
---
title: Constructeur Intl.Locale()
slug: Web/JavaScript/Reference/Global_Objects/Intl/Locale/Locale
---
{{JSRef}}
Le constructeur **`Intl.Locale`** est une propriété native de l'objet `Intl` qui permet de créer des objets qui représentent des locales Unicode.
{{EmbedInteractiveExample("pages/js/intl-locale.html")}}
## Syntaxe
```js
new Intl.Locale(tag);
new Intl.Locale(tag, options);
```
### Paramètres
- `tag`
- : La balise Unicode qui représente une locale.
- `options`
- : Un objet qui contient la configuration à utiliser pour la locale. Les propriétés sont des balises de locale Unicode et les valeurs de ces propriétés sont les valeurs autorisées pour ces balises.
## Exemples
### Usage simple
Sous sa forme la plus simple, le constructeur [`Intl.Locale`] prend comme argument une chaîne de caractères représentant un identifiant de locale :
```js
let us = new Intl.Locale("en-US");
```
### Utiliser le constructeur Locale avec un objet options
Le constructeur prend un deuxième argument qui permet de configurer la locale et d'indiquer plusieurs types d'extensions. Ainsi, la propriété [`hourCycle`](/fr/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/hourCycle) utilisée sur l'objet de configuration permettra d'indiquer le type de cycle horaire souhaité :
```js
let locale = new Intl.Locale("en-US", { hourCycle: "h12" });
console.log(locale.hourCycle); // affiche "h12"
```
## Prothèse d'émulation (<i lang="en">polyfill</i>)
[Prothèse formatjs pour `Intl.Locale`](https://formatjs.io/docs/polyfills/intl-locale)
## Spécifications
{{Specifications}}
## Compatibilité des navigateurs
{{Compat}}
## Voir aussi
- [`Intl.Collator`](/fr/docs/Web/JavaScript/Reference/Global_Objects/Intl/Collator)
- [Spécification Unicode sur les identifiants de locale](https://www.unicode.org/reports/tr35/#Canonical_Unicode_Locale_Identifiers)