@intlayer/docs 7.3.14 → 7.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/blog/ar/intlayer_with_i18next.md +3 -0
- package/blog/ar/intlayer_with_next-i18next.md +3 -0
- package/blog/ar/intlayer_with_next-intl.md +3 -0
- package/blog/ar/intlayer_with_react-i18next.md +3 -0
- package/blog/ar/intlayer_with_react-intl.md +3 -0
- package/blog/ar/intlayer_with_vue-i18n.md +3 -0
- package/blog/de/intlayer_with_i18next.md +3 -0
- package/blog/de/intlayer_with_next-i18next.md +3 -0
- package/blog/de/intlayer_with_next-intl.md +3 -0
- package/blog/de/intlayer_with_react-i18next.md +3 -0
- package/blog/de/intlayer_with_react-intl.md +3 -0
- package/blog/de/intlayer_with_vue-i18n.md +3 -0
- package/blog/en/intlayer_with_i18next.md +7 -0
- package/blog/en/intlayer_with_next-i18next.md +3 -0
- package/blog/en/intlayer_with_next-intl.md +7 -0
- package/blog/en/intlayer_with_react-i18next.md +3 -0
- package/blog/en/intlayer_with_react-intl.md +3 -0
- package/blog/en/intlayer_with_vue-i18n.md +3 -0
- package/blog/en-GB/intlayer_with_i18next.md +3 -0
- package/blog/en-GB/intlayer_with_next-i18next.md +3 -0
- package/blog/en-GB/intlayer_with_next-intl.md +3 -0
- package/blog/en-GB/intlayer_with_react-i18next.md +3 -0
- package/blog/en-GB/intlayer_with_react-intl.md +3 -0
- package/blog/en-GB/intlayer_with_vue-i18n.md +3 -0
- package/blog/es/intlayer_with_i18next.md +3 -0
- package/blog/es/intlayer_with_next-i18next.md +3 -0
- package/blog/es/intlayer_with_next-intl.md +3 -0
- package/blog/es/intlayer_with_react-i18next.md +3 -0
- package/blog/es/intlayer_with_react-intl.md +3 -0
- package/blog/es/intlayer_with_vue-i18n.md +3 -0
- package/blog/fr/intlayer_with_i18next.md +3 -0
- package/blog/fr/intlayer_with_next-i18next.md +3 -0
- package/blog/fr/intlayer_with_next-intl.md +3 -0
- package/blog/fr/intlayer_with_react-i18next.md +3 -0
- package/blog/fr/intlayer_with_react-intl.md +3 -0
- package/blog/fr/intlayer_with_vue-i18n.md +3 -0
- package/blog/hi/intlayer_with_i18next.md +3 -0
- package/blog/hi/intlayer_with_next-i18next.md +3 -0
- package/blog/hi/intlayer_with_next-intl.md +3 -0
- package/blog/hi/intlayer_with_react-i18next.md +3 -0
- package/blog/hi/intlayer_with_react-intl.md +3 -0
- package/blog/hi/intlayer_with_vue-i18n.md +3 -0
- package/blog/id/intlayer_with_i18next.md +3 -0
- package/blog/id/intlayer_with_next-i18next.md +3 -0
- package/blog/id/intlayer_with_next-intl.md +3 -0
- package/blog/id/intlayer_with_react-i18next.md +3 -0
- package/blog/id/intlayer_with_react-intl.md +3 -0
- package/blog/id/intlayer_with_vue-i18n.md +3 -0
- package/blog/it/intlayer_with_i18next.md +3 -0
- package/blog/it/intlayer_with_next-i18next.md +3 -0
- package/blog/it/intlayer_with_next-intl.md +3 -0
- package/blog/it/intlayer_with_react-i18next.md +3 -0
- package/blog/it/intlayer_with_react-intl.md +3 -0
- package/blog/it/intlayer_with_vue-i18n.md +3 -0
- package/blog/ja/intlayer_with_i18next.md +3 -0
- package/blog/ja/intlayer_with_next-i18next.md +3 -0
- package/blog/ja/intlayer_with_next-intl.md +3 -0
- package/blog/ja/intlayer_with_react-i18next.md +3 -0
- package/blog/ja/intlayer_with_react-intl.md +3 -0
- package/blog/ja/intlayer_with_vue-i18n.md +3 -0
- package/blog/ko/intlayer_with_i18next.md +3 -0
- package/blog/ko/intlayer_with_next-i18next.md +3 -0
- package/blog/ko/intlayer_with_next-intl.md +3 -0
- package/blog/ko/intlayer_with_react-i18next.md +3 -0
- package/blog/ko/intlayer_with_react-intl.md +3 -0
- package/blog/ko/intlayer_with_vue-i18n.md +3 -0
- package/blog/pl/intlayer_with_i18next.md +3 -0
- package/blog/pl/intlayer_with_next-i18next.md +3 -0
- package/blog/pl/intlayer_with_next-intl.md +3 -0
- package/blog/pl/intlayer_with_react-i18next.md +3 -0
- package/blog/pl/intlayer_with_react-intl.md +3 -0
- package/blog/pl/intlayer_with_vue-i18n.md +3 -0
- package/blog/pt/intlayer_with_i18next.md +3 -0
- package/blog/pt/intlayer_with_next-i18next.md +3 -0
- package/blog/pt/intlayer_with_next-intl.md +3 -0
- package/blog/pt/intlayer_with_react-i18next.md +3 -0
- package/blog/pt/intlayer_with_react-intl.md +3 -0
- package/blog/pt/intlayer_with_vue-i18n.md +3 -0
- package/blog/ru/intlayer_with_i18next.md +3 -0
- package/blog/ru/intlayer_with_next-i18next.md +3 -0
- package/blog/ru/intlayer_with_next-intl.md +3 -0
- package/blog/ru/intlayer_with_react-i18next.md +3 -0
- package/blog/ru/intlayer_with_react-intl.md +3 -0
- package/blog/ru/intlayer_with_vue-i18n.md +3 -0
- package/blog/tr/intlayer_with_i18next.md +3 -0
- package/blog/tr/intlayer_with_next-i18next.md +3 -0
- package/blog/tr/intlayer_with_next-intl.md +3 -0
- package/blog/tr/intlayer_with_react-i18next.md +3 -0
- package/blog/tr/intlayer_with_vue-i18n.md +3 -0
- package/blog/vi/intlayer_with_i18next.md +3 -0
- package/blog/vi/intlayer_with_next-i18next.md +3 -0
- package/blog/vi/intlayer_with_next-intl.md +3 -0
- package/blog/vi/intlayer_with_react-i18next.md +3 -0
- package/blog/vi/intlayer_with_react-intl.md +3 -0
- package/blog/vi/intlayer_with_vue-i18n.md +3 -0
- package/blog/zh/intlayer_with_i18next.md +3 -0
- package/blog/zh/intlayer_with_next-i18next.md +3 -0
- package/blog/zh/intlayer_with_next-intl.md +3 -0
- package/blog/zh/intlayer_with_react-i18next.md +3 -0
- package/blog/zh/intlayer_with_react-intl.md +3 -0
- package/blog/zh/intlayer_with_vue-i18n.md +3 -0
- package/docs/ar/intlayer_with_lynx+react.md +1 -1
- package/docs/ar/intlayer_with_tanstack.md +132 -2
- package/docs/ar/intlayer_with_vite+react.md +99 -331
- package/docs/ar/plugins/sync-json.md +3 -0
- package/docs/de/intlayer_with_lynx+react.md +1 -1
- package/docs/de/intlayer_with_tanstack.md +132 -2
- package/docs/de/intlayer_with_vite+react.md +116 -380
- package/docs/de/plugins/sync-json.md +3 -0
- package/docs/en/intlayer_with_tanstack.md +131 -1
- package/docs/en/intlayer_with_vite+react.md +6 -10
- package/docs/en/plugins/sync-json.md +3 -0
- package/docs/en-GB/intlayer_with_tanstack.md +131 -1
- package/docs/en-GB/intlayer_with_vite+react.md +62 -74
- package/docs/en-GB/plugins/sync-json.md +3 -0
- package/docs/es/intlayer_with_tanstack.md +132 -2
- package/docs/es/intlayer_with_vite+react.md +101 -333
- package/docs/es/plugins/sync-json.md +3 -0
- package/docs/fr/intlayer_with_tanstack.md +132 -2
- package/docs/fr/intlayer_with_vite+react.md +101 -357
- package/docs/fr/plugins/sync-json.md +3 -0
- package/docs/hi/intlayer_with_tanstack.md +132 -2
- package/docs/hi/intlayer_with_vite+react.md +120 -333
- package/docs/hi/plugins/sync-json.md +3 -0
- package/docs/id/intlayer_with_tanstack.md +132 -2
- package/docs/id/intlayer_with_vite+react.md +7 -13
- package/docs/id/plugins/sync-json.md +3 -0
- package/docs/it/intlayer_with_lynx+react.md +1 -1
- package/docs/it/intlayer_with_tanstack.md +132 -2
- package/docs/it/intlayer_with_vite+react.md +121 -393
- package/docs/it/plugins/sync-json.md +3 -0
- package/docs/ja/intlayer_with_tanstack.md +132 -2
- package/docs/ja/intlayer_with_vite+react.md +106 -378
- package/docs/ja/plugins/sync-json.md +3 -0
- package/docs/ko/intlayer_with_lynx+react.md +1 -1
- package/docs/ko/intlayer_with_tanstack.md +132 -2
- package/docs/ko/intlayer_with_vite+react.md +90 -322
- package/docs/ko/plugins/sync-json.md +3 -0
- package/docs/pl/intlayer_with_tanstack.md +132 -2
- package/docs/pl/intlayer_with_vite+react.md +25 -21
- package/docs/pl/plugins/sync-json.md +3 -0
- package/docs/pt/intlayer_with_tanstack.md +132 -2
- package/docs/pt/intlayer_with_vite+react.md +96 -328
- package/docs/pt/plugins/sync-json.md +3 -0
- package/docs/ru/intlayer_with_lynx+react.md +1 -1
- package/docs/ru/intlayer_with_tanstack.md +132 -2
- package/docs/ru/intlayer_with_vite+react.md +109 -362
- package/docs/ru/plugins/sync-json.md +3 -0
- package/docs/tr/intlayer_with_tanstack.md +132 -2
- package/docs/tr/intlayer_with_vite+react.md +132 -366
- package/docs/tr/plugins/sync-json.md +3 -0
- package/docs/vi/intlayer_with_tanstack.md +132 -2
- package/docs/vi/intlayer_with_vite+react.md +16 -19
- package/docs/vi/plugins/sync-json.md +3 -0
- package/docs/zh/intlayer_with_tanstack.md +133 -3
- package/docs/zh/intlayer_with_vite+react.md +91 -374
- package/docs/zh/plugins/sync-json.md +3 -0
- package/frequent_questions/ar/customized_locale_list.md +1 -1
- package/frequent_questions/de/customized_locale_list.md +1 -1
- package/frequent_questions/en/customized_locale_list.md +1 -1
- package/frequent_questions/en-GB/customized_locale_list.md +1 -1
- package/frequent_questions/es/customized_locale_list.md +1 -1
- package/frequent_questions/fr/customized_locale_list.md +1 -1
- package/frequent_questions/hi/customized_locale_list.md +1 -1
- package/frequent_questions/id/customized_locale_list.md +1 -1
- package/frequent_questions/it/customized_locale_list.md +1 -1
- package/frequent_questions/ja/customized_locale_list.md +1 -1
- package/frequent_questions/ko/customized_locale_list.md +1 -1
- package/frequent_questions/pl/customized_locale_list.md +1 -1
- package/frequent_questions/pt/customized_locale_list.md +1 -1
- package/frequent_questions/ru/customized_locale_list.md +1 -1
- package/frequent_questions/tr/customized_locale_list.md +1 -1
- package/frequent_questions/vi/customized_locale_list.md +1 -1
- package/frequent_questions/zh/customized_locale_list.md +1 -1
- package/package.json +6 -6
|
@@ -19,9 +19,12 @@ slugs:
|
|
|
19
19
|
applicationTemplate: https://github.com/aymericzip/intlayer-tanstack-start-template
|
|
20
20
|
youtubeVideo: https://www.youtube.com/watch?v=_XTdKVWaeqg
|
|
21
21
|
history:
|
|
22
|
+
- version: 7.4.0
|
|
23
|
+
date: 2025-12-11
|
|
24
|
+
changes: Ajout de validatePrefix et étape 14 : gestion des pages 404 avec routes localisées.
|
|
22
25
|
- version: 7.3.9
|
|
23
26
|
date: 2025-12-05
|
|
24
|
-
changes:
|
|
27
|
+
changes: Ajout de l’étape 13 : récupération de la locale dans vos server actions (optionnel)
|
|
25
28
|
- version: 5.8.1
|
|
26
29
|
date: 2025-09-09
|
|
27
30
|
changes: Ajout pour Tanstack Start
|
|
@@ -609,7 +612,134 @@ export const getLocaleServer = createServerFn().handler(async () => {
|
|
|
609
612
|
|
|
610
613
|
---
|
|
611
614
|
|
|
612
|
-
### Étape 14 :
|
|
615
|
+
### Étape 14 : Gérer les pages non trouvées (Optionnel)
|
|
616
|
+
|
|
617
|
+
Lorsqu'un utilisateur visite une page inexistante, vous pouvez afficher une page personnalisée de non trouvée et le préfixe de locale peut affecter la façon dont la page de non trouvée est déclenchée.
|
|
618
|
+
|
|
619
|
+
#### Comprendre la gestion des 404 de TanStack Router avec les préfixes de locale
|
|
620
|
+
|
|
621
|
+
Dans TanStack Router, la gestion des pages 404 avec des routes localisées nécessite une approche multicouche :
|
|
622
|
+
|
|
623
|
+
1. **Route 404 dédiée** : Une route spécifique pour afficher l'interface utilisateur 404
|
|
624
|
+
2. **Validation au niveau de la route** : Valide les préfixes de locale et redirige ceux qui sont invalides vers 404
|
|
625
|
+
3. **Route catch-all** : Capture tous les chemins non correspondants dans le segment de locale
|
|
626
|
+
|
|
627
|
+
```tsx fileName="src/routes/{-$locale}/404.tsx"
|
|
628
|
+
import { createFileRoute } from "@tanstack/react-router";
|
|
629
|
+
|
|
630
|
+
// Ceci crée une route dédiée /[locale]/404
|
|
631
|
+
// Elle est utilisée à la fois comme route directe et importée comme composant dans d'autres fichiers
|
|
632
|
+
export const Route = createFileRoute("/{-$locale}/404")({
|
|
633
|
+
component: NotFoundComponent,
|
|
634
|
+
});
|
|
635
|
+
|
|
636
|
+
// Exporté séparément pour pouvoir être réutilisé dans notFoundComponent et les routes catch-all
|
|
637
|
+
export function NotFoundComponent() {
|
|
638
|
+
return (
|
|
639
|
+
<div>
|
|
640
|
+
<h1>404</h1>
|
|
641
|
+
</div>
|
|
642
|
+
);
|
|
643
|
+
}
|
|
644
|
+
```
|
|
645
|
+
|
|
646
|
+
```tsx fileName="src/routes/__root.tsx"
|
|
647
|
+
import { createRootRoute } from "@tanstack/react-router";
|
|
648
|
+
|
|
649
|
+
// La route racine sert de mise en page de niveau supérieur
|
|
650
|
+
// Elle ne gère pas les 404 directement - c'est délégué aux routes enfants
|
|
651
|
+
// Cela garde la racine simple et permet aux routes conscientes de la locale de gérer leur propre logique 404
|
|
652
|
+
export const Route = createRootRoute({
|
|
653
|
+
component: Outlet,
|
|
654
|
+
});
|
|
655
|
+
```
|
|
656
|
+
|
|
657
|
+
```tsx fileName="src/routes/{-$locale}/route.tsx"
|
|
658
|
+
import { createFileRoute, Outlet, redirect } from "@tanstack/react-router";
|
|
659
|
+
import { validatePrefix } from "intlayer";
|
|
660
|
+
import { IntlayerProvider, useLocale } from "react-intlayer";
|
|
661
|
+
|
|
662
|
+
import { LocaleSwitcher } from "@/components/locale-switcher";
|
|
663
|
+
import { NotFoundComponent } from "./404";
|
|
664
|
+
|
|
665
|
+
export const Route = createFileRoute("/{-$locale}")({
|
|
666
|
+
// beforeLoad s'exécute avant que la route ne soit rendue (à la fois sur le serveur et le client)
|
|
667
|
+
// C'est l'endroit idéal pour valider le préfixe de locale
|
|
668
|
+
beforeLoad: ({ params }) => {
|
|
669
|
+
// Obtenir la locale depuis les paramètres de route (pas depuis les en-têtes du serveur, car beforeLoad s'exécute à la fois sur le client et le serveur)
|
|
670
|
+
const localeParam = params.locale;
|
|
671
|
+
|
|
672
|
+
// validatePrefix vérifie si la locale est valide selon votre configuration intlayer
|
|
673
|
+
// Retourne : { isValid: boolean, localePrefix: string }
|
|
674
|
+
// - isValid: true si le préfixe correspond à une locale configurée (ou est vide lorsque le préfixe est optionnel)
|
|
675
|
+
// - localePrefix: le préfixe validé ou le préfixe de locale par défaut pour les redirections
|
|
676
|
+
const { isValid, localePrefix } = validatePrefix(localeParam);
|
|
677
|
+
|
|
678
|
+
if (isValid) {
|
|
679
|
+
// La locale est valide, permettre à la route de se rendre normalement
|
|
680
|
+
return;
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
// Préfixe de locale invalide (p. ex., /xyz/about où "xyz" n'est pas une locale valide)
|
|
684
|
+
// Rediriger vers la page 404 avec un préfixe de locale valide
|
|
685
|
+
// Cela garantit que la page 404 est toujours correctement localisée
|
|
686
|
+
throw redirect({
|
|
687
|
+
to: "/{-$locale}/404",
|
|
688
|
+
params: { locale: localePrefix },
|
|
689
|
+
});
|
|
690
|
+
},
|
|
691
|
+
component: RouteComponent,
|
|
692
|
+
// notFoundComponent est appelé lorsqu'une route enfant n'existe pas
|
|
693
|
+
// p. ex., /en/page-inexistante déclenche ceci dans la mise en page /en
|
|
694
|
+
notFoundComponent: NotFoundLayout,
|
|
695
|
+
});
|
|
696
|
+
|
|
697
|
+
function RouteComponent() {
|
|
698
|
+
const { defaultLocale } = useLocale();
|
|
699
|
+
const { locale } = Route.useParams();
|
|
700
|
+
|
|
701
|
+
return (
|
|
702
|
+
// Envelopper tout le segment de locale avec IntlayerProvider
|
|
703
|
+
// Revient à defaultLocale lorsque le paramètre locale est undefined (mode préfixe optionnel)
|
|
704
|
+
<IntlayerProvider locale={locale ?? defaultLocale}>
|
|
705
|
+
<Outlet />
|
|
706
|
+
</IntlayerProvider>
|
|
707
|
+
);
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
// NotFoundLayout enveloppe le composant 404 avec IntlayerProvider
|
|
711
|
+
// Cela garantit que les traductions fonctionnent toujours sur la page 404
|
|
712
|
+
function NotFoundLayout() {
|
|
713
|
+
const { defaultLocale } = useLocale();
|
|
714
|
+
const { locale } = Route.useParams();
|
|
715
|
+
|
|
716
|
+
return (
|
|
717
|
+
<IntlayerProvider locale={locale ?? defaultLocale}>
|
|
718
|
+
<NotFoundComponent />
|
|
719
|
+
{/* Inclure LocaleSwitcher pour que les utilisateurs puissent changer de langue même sur 404 */}
|
|
720
|
+
<LocaleSwitcher />
|
|
721
|
+
</IntlayerProvider>
|
|
722
|
+
);
|
|
723
|
+
}
|
|
724
|
+
```
|
|
725
|
+
|
|
726
|
+
```tsx fileName="src/routes/{-$locale}/$.tsx"
|
|
727
|
+
import { createFileRoute } from "@tanstack/react-router";
|
|
728
|
+
|
|
729
|
+
import { NotFoundComponent } from "./404";
|
|
730
|
+
|
|
731
|
+
// La route $ (splat/catch-all) correspond à tout chemin qui ne correspond pas à d'autres routes
|
|
732
|
+
// p. ex., /en/quelque/chemin/profond/imbriqué/invalide
|
|
733
|
+
// Cela garantit que TOUS les chemins non correspondants dans une locale affichent la page 404
|
|
734
|
+
// Sans cela, les chemins profonds non correspondants pourraient afficher une page blanche ou une erreur
|
|
735
|
+
export const Route = createFileRoute("/{-$locale}/$")({
|
|
736
|
+
component: NotFoundComponent,
|
|
737
|
+
});
|
|
738
|
+
```
|
|
739
|
+
|
|
740
|
+
---
|
|
741
|
+
|
|
742
|
+
### Étape 15 : Configurer TypeScript (Optionnel)
|
|
613
743
|
|
|
614
744
|
Intlayer utilise l'augmentation de module pour bénéficier de TypeScript et renforcer votre base de code.
|
|
615
745
|
|