Skip to content

Commit 621bb07

Browse files
i18n(fr): update modules/astro-i18n.mdx (#12680)
Co-authored-by: Thomas Bonnet <[email protected]>
1 parent 28e0c4d commit 621bb07

File tree

1 file changed

+117
-0
lines changed

1 file changed

+117
-0
lines changed

src/content/docs/fr/reference/modules/astro-i18n.mdx

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ import {
4040
notFound,
4141
middleware,
4242
requestHasLocale,
43+
normalizeTheLocale,
44+
pathHasLocale,
45+
toCodes,
46+
toPaths
4347
} from 'astro:i18n';
4448
```
4549

@@ -337,3 +341,116 @@ export const onRequest = defineMiddleware(async (context, next) => {
337341
return new Response("Non trouvée", { status: 404 });
338342
})
339343
```
344+
345+
### `normalizeTheLocale()`
346+
347+
<p>
348+
349+
**Type :** `(locale: string) => string`
350+
</p>
351+
352+
Remplace les traits de soulignement (`_`) par des tirets (`-`) dans les paramètres régionaux donnés avant de renvoyer une version en minuscules.
353+
354+
```astro title="src/pages/index.astro"
355+
---
356+
import { normalizeTheLocale } from "astro:i18n";
357+
358+
normalizeTheLocale("it_VT") // renvoie `it-vt`
359+
// En supposant que les paramètres régionaux actuels soient `"pt-PT"` :
360+
normalizeTheLocale(Astro.currentLocale) // renvoie `pt-pt`
361+
---
362+
```
363+
364+
### `pathHasLocale()`
365+
366+
<p>
367+
368+
**Type :** `(path: string) => boolean`<br />
369+
<Since v="4.6.0" />
370+
</p>
371+
372+
Vérifie si le chemin d'accès spécifié contient l'un des paramètres régionaux configurés.
373+
374+
Cela permet d'éviter des erreurs avant d'utiliser un utilitaire i18n qui dépend d'un paramètre régional contenu dans le chemin d'une URL.
375+
376+
```js title="astro.config.mjs"
377+
export default defineConfig({
378+
i18n: {
379+
locales: [
380+
{ codes: ["it-VT", "it"], path: "italiano" },
381+
"es"
382+
]
383+
}
384+
})
385+
```
386+
387+
```astro title="src/pages/index.astro"
388+
---
389+
import { pathHasLocale } from "astro:i18n";
390+
391+
pathHasLocale("italiano"); // renvoie `true`
392+
pathHasLocale("es"); // renvoie `true`
393+
pathHasLocale('/es/blog/'); // renvoie `true`
394+
pathHasLocale("it-VT"); // renvoie `false`
395+
---
396+
```
397+
398+
### `toCodes()`
399+
400+
<p>
401+
402+
**Type :** `(locales: Locales) => string[]`<br />
403+
<Since v="4.0.0" />
404+
</p>
405+
406+
Récupère les codes de paramètres régionaux configurés pour chaque paramètre régional défini dans votre configuration. Lorsqu'il existe plusieurs codes associés à un paramètre régional, seul le premier sera ajouté au tableau.
407+
408+
```js title="astro.config.mjs"
409+
export default defineConfig({
410+
i18n: {
411+
locales: [
412+
{ codes: ["it-VT", "it"], path: "italiano" },
413+
"es"
414+
]
415+
}
416+
})
417+
```
418+
419+
```astro title="src/pages/index.astro"
420+
---
421+
import { i18n } from "astro:config/client";
422+
import { toCodes } from "astro:i18n";
423+
424+
toCodes(i18n!.locales); // ["it-VT", "es"]
425+
---
426+
```
427+
428+
### `toPaths()`
429+
430+
<p>
431+
432+
**Type :** `(locales: Locales) => string[]`<br />
433+
<Since v="4.0.0" />
434+
</p>
435+
436+
Récupère les chemins des paramètres régionaux configurés pour chaque paramètre régional défini dans votre configuration.
437+
438+
```js title="astro.config.mjs"
439+
export default defineConfig({
440+
i18n: {
441+
locales: [
442+
{ codes: ["it-VT", "it"], path: "italiano" },
443+
"es"
444+
]
445+
}
446+
})
447+
```
448+
449+
```astro title="src/pages/index.astro"
450+
---
451+
import { i18n } from "astro:config/client";
452+
import { toPaths } from "astro:i18n";
453+
454+
toPaths(i18n!.locales); // ["italiano", "es"]
455+
---
456+
```

0 commit comments

Comments
 (0)