Skip to content

Commit

Permalink
fr: Format /web/javascript using Prettier (part 4) (#14642)
Browse files Browse the repository at this point in the history
  • Loading branch information
queengooborg committed Jul 28, 2023
1 parent 5154dc2 commit 0c35400
Show file tree
Hide file tree
Showing 100 changed files with 802 additions and 651 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ La méthode **`Intl.DateTimeFormat.prototype.formatRange()`** permet de formater
## Syntaxe

```js
formatRange(dateDébut, dateFin)
formatRange(dateDébut, dateFin);
```

## Exemples
Expand All @@ -31,11 +31,11 @@ let date3 = new Date(Date.UTC(2007, 0, 20, 10, 0, 0));
// > 'Sat, 20 Jan 2007 10:00:00 GMT'

let fmt1 = new Intl.DateTimeFormat("en", {
year: '2-digit',
month: 'numeric',
day: 'numeric',
hour: 'numeric',
minute: 'numeric'
year: "2-digit",
month: "numeric",
day: "numeric",
hour: "numeric",
minute: "numeric",
});
console.log(fmt1.format(date1));
console.log(fmt1.formatRange(date1, date2));
Expand All @@ -45,9 +45,9 @@ console.log(fmt1.formatRange(date1, date3));
// > '1/10/07, 10:00 AM – 1/20/07, 10:00 AM'

let fmt2 = new Intl.DateTimeFormat("en", {
year: 'numeric',
month: 'short',
day: 'numeric'
year: "numeric",
month: "short",
day: "numeric",
});
console.log(fmt2.format(date1));
console.log(fmt2.formatRange(date1, date2));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ La fonction **`Intl.DateTimeFormat.prototype.formatRangeToParts()`** permet, sel
## Syntaxe

```js
Intl.DateTimeFormat.prototype.formatRangeToParts(dateDebut, dateFin)
Intl.DateTimeFormat.prototype.formatRangeToParts(dateDebut, dateFin);
```

## Exemples
Expand All @@ -27,8 +27,8 @@ let date2 = new Date(Date.UTC(2007, 0, 10, 11, 0, 0));
// > 'Wed, 10 Jan 2007 11:00:00 GMT'

let fmt = new Intl.DateTimeFormat("en", {
hour: 'numeric',
minute: 'numeric'
hour: "numeric",
minute: "numeric",
});

console.log(fmt.formatRange(date1, date2));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ La méthode **`Intl.DateTimeFormat.prototype.formatToParts()`** permet de mettre
## Syntaxe

```js
Intl.DateTimeFormat.prototype.formatToParts(date)
Intl.DateTimeFormat.prototype.formatToParts(date);
```

### Paramètres
Expand Down Expand Up @@ -67,15 +67,15 @@ Les types possibles sont :
var date = Date.UTC(2012, 11, 17, 3, 0, 42);

var formatter = new Intl.DateTimeFormat("en-us", {
weekday: 'long',
year: 'numeric',
month: 'numeric',
day: 'numeric',
hour: 'numeric',
minute: 'numeric',
second: 'numeric',
weekday: "long",
year: "numeric",
month: "numeric",
day: "numeric",
hour: "numeric",
minute: "numeric",
second: "numeric",
hour12: true,
timeZone: "UTC"
timeZone: "UTC",
});

formatter.format(date);
Expand All @@ -89,33 +89,38 @@ formatter.formatToParts(date);

// return value:
[
{ type: 'weekday', value: 'Monday' },
{ type: 'separator', value: ', ' },
{ type: 'month', value: '12' },
{ type: 'literal', value: '/' },
{ type: 'day', value: '17' },
{ type: 'literal', value: '/' },
{ type: 'year', value: '2012' },
{ type: 'literal', value: ', ' },
{ type: 'hour', value: '3' },
{ type: 'literal', value: ':' },
{ type: 'minute', value: '00' },
{ type: 'literal', value: ':' },
{ type: 'second', value: '42' },
{ type: 'literal', value: ' ' },
{ type: 'dayPeriod', value: 'AM' }
]
{ type: "weekday", value: "Monday" },
{ type: "separator", value: ", " },
{ type: "month", value: "12" },
{ type: "literal", value: "/" },
{ type: "day", value: "17" },
{ type: "literal", value: "/" },
{ type: "year", value: "2012" },
{ type: "literal", value: ", " },
{ type: "hour", value: "3" },
{ type: "literal", value: ":" },
{ type: "minute", value: "00" },
{ type: "literal", value: ":" },
{ type: "second", value: "42" },
{ type: "literal", value: " " },
{ type: "dayPeriod", value: "AM" },
];
```

L'information étant décomposée, on peut alors la mettre en forme et la recomposée de façon adaptée :

```js
var dateString = formatter.formatToParts(date).map(({type, value}) => {
switch (type) {
case 'dayPeriod': return `<strong>${value}</strong>`;
default : return value;
}
}).reduce((string, part) => string + part);
var dateString = formatter
.formatToParts(date)
.map(({ type, value }) => {
switch (type) {
case "dayPeriod":
return `<strong>${value}</strong>`;
default:
return value;
}
})
.reduce((string, part) => string + part);

console.log(formatter.format(date));
// "Monday, 12/17/2012, 3:00:42 AM"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,30 +59,30 @@ var date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0));
// fuseau horaire CEST

// l'anglais américain utilise l'ordre mois-jour-année
console.log(new Intl.DateTimeFormat('en-US').format(date));
console.log(new Intl.DateTimeFormat("en-US").format(date));
// → "12/20/2012"

// l'anglais britannique utilise l'ordre jour-mois-année
console.log(new Intl.DateTimeFormat('en-GB').format(date));
console.log(new Intl.DateTimeFormat("en-GB").format(date));
// → "20/12/2012"

// le coréen utilise l'ordre année-mois-jour
console.log(new Intl.DateTimeFormat('ko-KR').format(date));
console.log(new Intl.DateTimeFormat("ko-KR").format(date));
// → "2012. 12. 20."

// l'arabe, dans la plupart des pays arabophones, utilise les chiffres arabes
console.log(new Intl.DateTimeFormat('ar-EG').format(date));
console.log(new Intl.DateTimeFormat("ar-EG").format(date));
// → "٢٠‏/١٢‏/٢٠١٢"

// en ce qui concerne le japonais, les applications peuvent
// souhaiter utiliser le calendrier japonais
// pour lequel 2012 était l'année 24 de l'ère Heisei
console.log(new Intl.DateTimeFormat('ja-JP-u-ca-japanese').format(date));
console.log(new Intl.DateTimeFormat("ja-JP-u-ca-japanese").format(date));
// → "24/12/20"

// quand une locale non prise en charge est demandée (par exemple le balinais)
// il est possible de fournir une locale de recours (ici l'indonésien)
console.log(new Intl.DateTimeFormat(['ban', 'id']).format(date));
console.log(new Intl.DateTimeFormat(["ban", "id"]).format(date));
// → "20/12/2012"
```

Expand All @@ -94,49 +94,64 @@ Les formats de la date et de l'heure peuvent être personnalisés en utilisant l
var date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0));

// fournir le jour de la semaine avec une date longue
var options = {weekday: "long", year: "numeric", month: "long", day: "numeric"};
console.log(new Intl.DateTimeFormat('de-DE', options).format(date));
var options = {
weekday: "long",
year: "numeric",
month: "long",
day: "numeric",
};
console.log(new Intl.DateTimeFormat("de-DE", options).format(date));
// → "Donnerstag, 20. Dezember 2012"

// une application peut vouloir utiliser UTC et le rendre visible
options.timeZone = 'UTC';
options.timeZoneName = 'short';
console.log(new Intl.DateTimeFormat('en-US', options).format(date));
options.timeZone = "UTC";
options.timeZoneName = "short";
console.log(new Intl.DateTimeFormat("en-US", options).format(date));
// → "Thursday, December 20, 2012, GMT"

// parfois, il faut plus de précision
options = {hour: "numeric", minute: "numeric", second: "numeric",
timeZoneName: "short"};
console.log(new Intl.DateTimeFormat('en-AU', options).format(date));
options = {
hour: "numeric",
minute: "numeric",
second: "numeric",
timeZoneName: "short",
};
console.log(new Intl.DateTimeFormat("en-AU", options).format(date));
// → "2:00:00 pm AEDT"

// voire beaucoup plus de précision
options.fractionalSecondDigits = 3; // le nombre de chiffres décimaux pour les fractions de secondes
console.log(new Intl.DateTimeFormat('en-AU', options).format(date));
console.log(new Intl.DateTimeFormat("en-AU", options).format(date));
// → "2:00:00.200 pm AEDT"

// parfois, même les USA ont besoin d'afficher une heure sur 24h
options = {year: "numeric", month: "numeric", day: "numeric",
hour: "numeric", minute: "numeric", second: "numeric",
hour12: false};
console.log(new Intl.DateTimeFormat('en-US', options));
options = {
year: "numeric",
month: "numeric",
day: "numeric",
hour: "numeric",
minute: "numeric",
second: "numeric",
hour12: false,
};
console.log(new Intl.DateTimeFormat("en-US", options));
// → "12/19/2012, 19:00:00"

// pour utiliser la locale par défaut du navigateur, on utilise default
console.log(new Intl.DateTimeFormat('default', options).format(date));
console.log(new Intl.DateTimeFormat("default", options).format(date));
// → "12/19/2012, 19:00:00" (peut varier selon la locale du navigateur)

// on peut aussi inclure la période du jour
options = {hour: "numeric", dayPeriod: "short"};
console.log(new Intl.DateTimeFormat('en-US', options).format(date));
options = { hour: "numeric", dayPeriod: "short" };
console.log(new Intl.DateTimeFormat("en-US", options).format(date));
// → "4 at night"
```

Le calendrier et la numération utilisés peuvent être choisis indépendamment avec l'argument `options`&nbsp;:

```js
var options = {calendar: 'chinese', numberingSystem: 'arab'};
var dateFormat = new Intl.DateTimeFormat('default', options);
var options = { calendar: "chinese", numberingSystem: "arab" };
var dateFormat = new Intl.DateTimeFormat("default", options);
var usedOptions = dateFormat.resolvedOptions();

console.log(usedOptions.calendar);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ La méthode **`Intl.DateTimeFormat.prototype.resolvedOptions()`** renvoie un nou
## Syntaxe

```js
resolvedOptions()
resolvedOptions();
```

### Valeur de retour
Expand Down Expand Up @@ -45,11 +45,11 @@ La valeur renvoyée par cette méthode contient les propriétés suivantes :
var germanFakeRegion = new Intl.DateTimeFormat("de-XX", { timeZone: "UTC" });
var usedOptions = germanFakeRegion.resolvedOptions();

usedOptions.locale; // "de"
usedOptions.calendar; // "gregory"
usedOptions.locale; // "de"
usedOptions.calendar; // "gregory"
usedOptions.numberingSystem; // "latn"
usedOptions.timeZone; // "UTC"
usedOptions.month; // "numeric"
usedOptions.timeZone; // "UTC"
usedOptions.month; // "numeric"
```

## Spécifications
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ Si on dispose d'un environnement qui supporte les locales indonésienne et allem

```js
var locales = ["ban", "id-u-co-pinyin", "de-ID"];
var options = {localeMatcher: "lookup"};
console.log(Intl.DateTimeFormat.supportedLocalesOf(locales, options).join(", "));
var options = { localeMatcher: "lookup" };
console.log(
Intl.DateTimeFormat.supportedLocalesOf(locales, options).join(", "),
);
// → "id-u-co-pinyin, de-ID"
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ new Intl.DisplayNames([langues[, options]])
Dans son utilisation simple, sans spécifier de langue, une chaine dans la langue locale par défaut et avec les options par défaut sera retournée.

```js
console.log((new Intl.DisplayNames()).of('US'));
console.log(new Intl.DisplayNames().of("US"));
// Expected output: 'us'
```

Expand Down
Loading

0 comments on commit 0c35400

Please sign in to comment.