@intlayer/docs 7.3.8 → 7.3.10

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.
Files changed (35) hide show
  1. package/docs/ar/intlayer_with_tanstack.md +73 -1
  2. package/docs/ar/intlayer_with_vite+vue.md +37 -34
  3. package/docs/de/intlayer_with_tanstack.md +73 -1
  4. package/docs/de/intlayer_with_vite+vue.md +37 -34
  5. package/docs/en/intlayer_with_tanstack.md +63 -1
  6. package/docs/en/intlayer_with_vite+vue.md +27 -34
  7. package/docs/en-GB/intlayer_with_tanstack.md +73 -1
  8. package/docs/en-GB/intlayer_with_vite+vue.md +37 -34
  9. package/docs/es/intlayer_with_tanstack.md +73 -1
  10. package/docs/es/intlayer_with_vite+vue.md +37 -36
  11. package/docs/fr/intlayer_with_tanstack.md +73 -1
  12. package/docs/fr/intlayer_with_vite+vue.md +37 -36
  13. package/docs/hi/intlayer_with_tanstack.md +73 -1
  14. package/docs/hi/intlayer_with_vite+vue.md +37 -34
  15. package/docs/id/intlayer_with_tanstack.md +63 -1
  16. package/docs/id/intlayer_with_vite+vue.md +28 -35
  17. package/docs/it/intlayer_with_tanstack.md +73 -1
  18. package/docs/it/intlayer_with_vite+vue.md +37 -34
  19. package/docs/ja/intlayer_with_tanstack.md +73 -1
  20. package/docs/ja/intlayer_with_vite+vue.md +37 -34
  21. package/docs/ko/intlayer_with_tanstack.md +73 -1
  22. package/docs/ko/intlayer_with_vite+vue.md +37 -34
  23. package/docs/pl/intlayer_with_tanstack.md +63 -1
  24. package/docs/pl/intlayer_with_vite+vue.md +33 -34
  25. package/docs/pt/intlayer_with_tanstack.md +73 -1
  26. package/docs/pt/intlayer_with_vite+vue.md +37 -34
  27. package/docs/ru/intlayer_with_tanstack.md +73 -1
  28. package/docs/ru/intlayer_with_vite+vue.md +37 -34
  29. package/docs/tr/intlayer_with_tanstack.md +73 -1
  30. package/docs/tr/intlayer_with_vite+vue.md +37 -34
  31. package/docs/vi/intlayer_with_tanstack.md +63 -1
  32. package/docs/vi/intlayer_with_vite+vue.md +33 -34
  33. package/docs/zh/intlayer_with_tanstack.md +73 -1
  34. package/docs/zh/intlayer_with_vite+vue.md +37 -34
  35. package/package.json +6 -6
@@ -18,6 +18,9 @@ slugs:
18
18
  - tanstack-start
19
19
  applicationTemplate: https://github.com/aymericzip/intlayer-tanstack-start-template
20
20
  history:
21
+ - version: 7.3.9
22
+ date: 2025-12-05
23
+ changes: Add step 13: Retrieve the locale in your server actions (Optional)
21
24
  - version: 6.5.2
22
25
  date: 2025-10-03
23
26
  changes: Update doc
@@ -50,6 +53,27 @@ With Intlayer, you can:
50
53
 
51
54
  ## Step-by-Step Guide to Set Up Intlayer in a Tanstack Start Application
52
55
 
56
+ <Tab defaultTab="video">
57
+ <TabItem label="Video" value="video">
58
+
59
+ <iframe title="The best i18n solution for Tanstack Start? Discover Intlayer" class="m-auto aspect-[16/9] w-full overflow-hidden rounded-lg border-0" allow="autoplay; gyroscope;" loading="lazy" width="1080" height="auto" src="https://www.youtube.com/embed/_XTdKVWaeqg?autoplay=0&amp;origin=http://intlayer.org&amp;controls=0&amp;rel=1"/>
60
+
61
+ </TabItem>
62
+ <TabItem label="Code" value="code">
63
+
64
+ <iframe
65
+ src="https://stackblitz.com/github/aymericzip/intlayer-tanstack-start-template?embed=1&ctl=1&file=intlayer.config.ts"
66
+ className="m-auto overflow-hidden rounded-lg border-0 max-md:size-full max-md:h-[700px] md:aspect-16/9 md:w-full"
67
+ title="Demo CodeSandbox - How to Internationalize your application using Intlayer"
68
+ sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"
69
+ loading="lazy"
70
+ />
71
+
72
+ </TabItem>
73
+ </Tab>
74
+
75
+ See [Application Template](https://github.com/aymericzip/intlayer-tanstack-start-template) on GitHub.
76
+
53
77
  ### Step 1: Create Project
54
78
 
55
79
  Start by creating a new TanStack Start project by following the [Start new project](https://tanstack.com/start/latest/docs/framework/react/quick-start) guide on the Tanstack Start website.
@@ -540,7 +564,55 @@ export const Route = createFileRoute("/{-$locale}/")({
540
564
 
541
565
  ---
542
566
 
543
- ### Step 13: Configure TypeScript (Optional)
567
+ ### Step 13: Retrieve the locale in your server actions (Optional)
568
+
569
+ You may want to access the current locale from inside your server actions or API endpoints.
570
+ You can do this using the `getLocale` helper from `intlayer`.
571
+
572
+ Here's an example using TanStack Start's server functions:
573
+
574
+ ```tsx fileName="src/routes/{-$locale}/index.tsx"
575
+ import { createServerFn } from "@tanstack/react-start";
576
+ import {
577
+ getRequestHeader,
578
+ getRequestHeaders,
579
+ } from "@tanstack/react-start/server";
580
+ import { getCookie, getIntlayer, getLocale } from "intlayer";
581
+
582
+ export const getLocaleServer = createServerFn().handler(async () => {
583
+ const locale = await getLocale({
584
+ // Get the cookie from the request (default: 'INTLAYER_LOCALE')
585
+ getCookie: (name) => {
586
+ const cookieString = getRequestHeader("cookie");
587
+
588
+ return getCookie(name, cookieString);
589
+ },
590
+ // Get the header from the request (default: 'x-intlayer-locale')
591
+ getHeader: (name) => getRequestHeader(name),
592
+ // Fallback using Accept-Language negotiation
593
+ getAllHeaders: async () => {
594
+ const headers = getRequestHeaders();
595
+ const result: Record<string, string> = {};
596
+
597
+ // Convert the TypedHeaders into a plain Record<string, string>
598
+ for (const [key, value] of headers.entries()) {
599
+ result[key] = value;
600
+ }
601
+
602
+ return result;
603
+ },
604
+ });
605
+
606
+ // Retrieve some content using getIntlayer()
607
+ const content = getIntlayer("app", locale);
608
+
609
+ return { locale, content };
610
+ });
611
+ ```
612
+
613
+ ---
614
+
615
+ ### Step 14: Configure TypeScript (Optional)
544
616
 
545
617
  Intlayer uses module augmentation to benefit from TypeScript and strengthen your codebase.
546
618
 
@@ -40,6 +40,27 @@ With Intlayer, you can:
40
40
 
41
41
  ## Step-by-Step Guide to Set Up Intlayer in a Vite and Vue Application
42
42
 
43
+ <Tab defaultTab="video">
44
+ <TabItem label="Video" value="video">
45
+
46
+ <iframe title="The best i18n solution for Vite and Vue? Discover Intlayer" class="m-auto aspect-[16/9] w-full overflow-hidden rounded-lg border-0" allow="autoplay; gyroscope;" loading="lazy" width="1080" height="auto" src="https://www.youtube.com/embed/IE3XWkZ6a5U?autoplay=0&amp;origin=http://intlayer.org&amp;controls=0&amp;rel=1"/>
47
+
48
+ </TabItem>
49
+ <TabItem label="Code" value="code">
50
+
51
+ <iframe
52
+ src="https://stackblitz.com/github/aymericzip/intlayer-vite-vue-template?embed=1&ctl=1&file=intlayer.config.ts"
53
+ className="m-auto overflow-hidden rounded-lg border-0 max-md:size-full max-md:h-[700px] md:aspect-16/9 md:w-full"
54
+ title="Demo CodeSandbox - How to Internationalize your application using Intlayer"
55
+ sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"
56
+ loading="lazy"
57
+ />
58
+
59
+ </TabItem>
60
+ </Tab>
61
+
62
+ See [Application Template](https://github.com/aymericzip/intlayer-vite-vue-template) on GitHub.
63
+
43
64
  ### Step 1: Install Dependencies
44
65
 
45
66
  Install the necessary packages using npm:
@@ -561,53 +582,47 @@ Example:
561
582
  First, install Vue Router:
562
583
 
563
584
  ```bash packageManager="npm"
564
- npm install intlayer vue-router
585
+ npm install vue-router
565
586
  ```
566
587
 
567
588
  ```bash packageManager="pnpm"
568
- pnpm add intlayer vue-router
589
+ pnpm add vue-router
569
590
  ```
570
591
 
571
592
  ```bash packageManager="yarn"
572
- yarn add intlayer vue-router
593
+ yarn add vue-router
573
594
  ```
574
595
 
575
596
  Then, create a router configuration that handles locale-based routing:
576
597
 
577
598
  ```js fileName="src/router/index.ts"
578
599
  import {
579
- configuration,
580
- getPathWithoutLocale,
581
600
  localeFlatMap,
582
- type Locales,
601
+ type Locale,
583
602
  } from 'intlayer';
584
603
  import { createIntlayerClient } from 'vue-intlayer';
585
604
  import { createRouter, createWebHistory } from 'vue-router';
586
605
  import HomeView from './views/home/HomeView.vue';
587
606
  import RootView from './views/root/Root.vue';
588
607
 
589
- // Get internationalisation configuration
590
- const { internationalization, middleware } = configuration;
591
- const { defaultLocale } = internationalization;
592
-
593
608
  /**
594
609
  * Declare the routes with locale-specific paths and metadata.
595
610
  */
596
- const routes = localeFlatMap((localizedData) => [
611
+ const routes = localeFlatMap(({ urlPrefix, locale }) => [
597
612
  {
598
- path: `${localizedData.urlPrefix}/`,
599
- name: `Root-${localizedData.locale}`,
613
+ path: `${urlPrefix}/`,
614
+ name: `Root-${locale}`,
600
615
  component: RootView,
601
616
  meta: {
602
- locale: localizedData.locale,
617
+ locale,
603
618
  },
604
619
  },
605
620
  {
606
- path: `${localizedData.urlPrefix}/home`,
607
- name: `Home-${localizedData.locale}`,
621
+ path: `${urlPrefix}/home`,
622
+ name: `Home-${locale}`,
608
623
  component: HomeView,
609
624
  meta: {
610
- locale: localizedData.locale,
625
+ locale,
611
626
  },
612
627
  },
613
628
  ]);
@@ -622,23 +637,11 @@ export const router = createRouter({
622
637
  router.beforeEach((to, _from, next) => {
623
638
  const client = createIntlayerClient();
624
639
 
625
- const metaLocale = to.meta.locale as Locales | undefined;
640
+ const metaLocale = to.meta.locale as Locale;
626
641
 
627
- if (metaLocale) {
628
- // Reuse the locale defined in the route meta
629
- client.setLocale(metaLocale);
630
- next();
631
- } else {
632
- // Fallback: no locale in meta, possibly unmatched route
633
- // Optional: handle 404 or redirect to default locale
634
- client.setLocale(defaultLocale);
635
-
636
- if (middleware.prefixDefault) {
637
- next(`/${defaultLocale}${getPathWithoutLocale(to.path)}`);
638
- } else {
639
- next(getPathWithoutLocale(to.path));
640
- }
641
- }
642
+ // Reuse the locale defined in the route meta
643
+ client.setLocale(metaLocale);
644
+ next();
642
645
  });
643
646
  ```
644
647
 
@@ -788,7 +791,7 @@ watch(
788
791
  Tip: For improved SEO and accessibility, use tags such as `<a href="/fr/home" hreflang="fr">` to link to localised pages, as demonstrated in Step 10. This enables search engines to discover and index language-specific URLs correctly. To maintain SPA behaviour, you can prevent the default navigation with @click.prevent, change the locale using useLocale, and programmatically navigate using Vue Router.
789
792
 
790
793
  ```html
791
- <ol class="divide-text/20 divide-y divide-dashed overflow-y-auto p-1">
794
+ <ol>
792
795
  <li>
793
796
  <a
794
797
  hreflang="x-default"
@@ -18,6 +18,9 @@ slugs:
18
18
  - tanstack-start
19
19
  applicationTemplate: https://github.com/aymericzip/intlayer-tanstack-start-template
20
20
  history:
21
+ - version: 7.3.9
22
+ date: 2025-12-05
23
+ changes: Add step 13: Retrieve the locale in your server actions (Optional)
21
24
  - version: 5.8.1
22
25
  date: 2025-09-09
23
26
  changes: Añadido para Tanstack Start
@@ -47,6 +50,27 @@ Con Intlayer, puedes:
47
50
 
48
51
  ## Guía paso a paso para configurar Intlayer en una aplicación Tanstack Start
49
52
 
53
+ <Tab defaultTab="video">
54
+ <TabItem label="Video" value="video">
55
+
56
+ <iframe title="¿La mejor solución i18n para Tanstack Start? Descubre Intlayer" class="m-auto aspect-[16/9] w-full overflow-hidden rounded-lg border-0" allow="autoplay; gyroscope;" loading="lazy" width="1080" height="auto" src="https://www.youtube.com/embed/_XTdKVWaeqg?autoplay=0&amp;origin=http://intlayer.org&amp;controls=0&amp;rel=1"/>
57
+
58
+ </TabItem>
59
+ <TabItem label="Code" value="code">
60
+
61
+ <iframe
62
+ src="https://stackblitz.com/github/aymericzip/intlayer-tanstack-start-template?embed=1&ctl=1&file=intlayer.config.ts"
63
+ className="m-auto overflow-hidden rounded-lg border-0 max-md:size-full max-md:h-[700px] md:aspect-16/9 md:w-full"
64
+ title="Demo CodeSandbox - Cómo internacionalizar tu aplicación usando Intlayer"
65
+ sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"
66
+ loading="lazy"
67
+ />
68
+
69
+ </TabItem>
70
+ </Tab>
71
+
72
+ Ver la [Plantilla de aplicación](https://github.com/aymericzip/intlayer-tanstack-start-template) en GitHub.
73
+
50
74
  ### Paso 1: Crear proyecto
51
75
 
52
76
  Comienza creando un nuevo proyecto TanStack Start siguiendo la guía [Start new project](https://tanstack.com/start/latest/docs/framework/react/quick-start) en el sitio web de TanStack Start.
@@ -532,7 +556,55 @@ export const Route = createFileRoute("/{-$locale}/")({
532
556
 
533
557
  ---
534
558
 
535
- ### Paso 13: Configurar TypeScript (Opcional)
559
+ ### Paso 13: Recuperar la configuración regional en sus acciones del servidor (Opcional)
560
+
561
+ Es posible que desee acceder a la configuración regional actual desde dentro de sus acciones del servidor o endpoints de API.
562
+ Puede hacerlo utilizando el asistente `getLocale` de `intlayer`.
563
+
564
+ Aquí hay un ejemplo usando las funciones del servidor de TanStack Start:
565
+
566
+ ```tsx fileName="src/routes/{-$locale}/index.tsx"
567
+ import { createServerFn } from "@tanstack/react-start";
568
+ import {
569
+ getRequestHeader,
570
+ getRequestHeaders,
571
+ } from "@tanstack/react-start/server";
572
+ import { getCookie, getIntlayer, getLocale } from "intlayer";
573
+
574
+ export const getLocaleServer = createServerFn().handler(async () => {
575
+ const locale = await getLocale({
576
+ // Obtener la cookie de la solicitud (por defecto: 'INTLAYER_LOCALE')
577
+ getCookie: (name) => {
578
+ const cookieString = getRequestHeader("cookie");
579
+
580
+ return getCookie(name, cookieString);
581
+ },
582
+ // Obtener el encabezado de la solicitud (por defecto: 'x-intlayer-locale')
583
+ getHeader: (name) => getRequestHeader(name),
584
+ // Respaldo usando negociación Accept-Language
585
+ getAllHeaders: async () => {
586
+ const headers = getRequestHeaders();
587
+ const result: Record<string, string> = {};
588
+
589
+ // Convertir TypedHeaders en un simple Record<string, string>
590
+ for (const [key, value] of headers.entries()) {
591
+ result[key] = value;
592
+ }
593
+
594
+ return result;
595
+ },
596
+ });
597
+
598
+ // Recuperar algún contenido usando getIntlayer()
599
+ const content = getIntlayer("app", locale);
600
+
601
+ return { locale, content };
602
+ });
603
+ ```
604
+
605
+ ---
606
+
607
+ ### Paso 14: Configurar TypeScript (Opcional)
536
608
 
537
609
  Intlayer utiliza la ampliación de módulos para aprovechar las ventajas de TypeScript y fortalecer tu base de código.
538
610
 
@@ -23,8 +23,6 @@ history:
23
23
 
24
24
  # Traduce tu Vite and Vue con Intlayer | Internacionalización (i18n)
25
25
 
26
- Consulta la [Plantilla de Aplicación](https://github.com/aymericzip/intlayer-vite-vue-template) en GitHub.
27
-
28
26
  ## ¿Qué es Intlayer?
29
27
 
30
28
  **Intlayer** es una biblioteca innovadora y de código abierto para la internacionalización (i18n) diseñada para simplificar el soporte multilingüe en aplicaciones web modernas.
@@ -40,6 +38,27 @@ Con Intlayer, puedes:
40
38
 
41
39
  ## Guía paso a paso para configurar Intlayer en una aplicación Vite y Vue
42
40
 
41
+ <Tab defaultTab="video">
42
+ <TabItem label="Vídeo" value="video">
43
+
44
+ <iframe title="The best i18n solution for Vite and Vue? Discover Intlayer" class="m-auto aspect-[16/9] w-full overflow-hidden rounded-lg border-0" allow="autoplay; gyroscope;" loading="lazy" width="1080" height="auto" src="https://www.youtube.com/embed/IE3XWkZ6a5U?autoplay=0&amp;origin=http://intlayer.org&amp;controls=0&amp;rel=1"/>
45
+
46
+ </TabItem>
47
+ <TabItem label="Código" value="code">
48
+
49
+ <iframe
50
+ src="https://stackblitz.com/github/aymericzip/intlayer-vite-vue-template?embed=1&ctl=1&file=intlayer.config.ts"
51
+ className="m-auto overflow-hidden rounded-lg border-0 max-md:size-full max-md:h-[700px] md:aspect-16/9 md:w-full"
52
+ title="Demo CodeSandbox - How to Internationalize your application using Intlayer"
53
+ sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"
54
+ loading="lazy"
55
+ />
56
+
57
+ </TabItem>
58
+ </Tab>
59
+
60
+ Consulta la [Plantilla de Aplicación](https://github.com/aymericzip/intlayer-vite-vue-template) en GitHub.
61
+
43
62
  ### Paso 1: Instalar dependencias
44
63
 
45
64
  Instala los paquetes necesarios usando npm:
@@ -586,53 +605,47 @@ Ejemplo:
586
605
  Primero, instala Vue Router:
587
606
 
588
607
  ```bash packageManager="npm"
589
- npm install intlayer vue-router
608
+ npm install vue-router
590
609
  ```
591
610
 
592
611
  ```bash packageManager="pnpm"
593
- pnpm add intlayer vue-router
612
+ pnpm add vue-router
594
613
  ```
595
614
 
596
615
  ```bash packageManager="yarn"
597
- yarn add intlayer vue-router
616
+ yarn add vue-router
598
617
  ```
599
618
 
600
619
  Luego, crea una configuración de enrutador que maneje el enrutamiento basado en la localidad:
601
620
 
602
621
  ```js fileName="src/router/index.ts"
603
622
  import {
604
- configuration,
605
- getPathWithoutLocale,
606
623
  localeFlatMap,
607
- type Locales,
624
+ type Locale,
608
625
  } from 'intlayer';
609
626
  import { createIntlayerClient } from 'vue-intlayer';
610
627
  import { createRouter, createWebHistory } from 'vue-router';
611
628
  import HomeView from './views/home/HomeView.vue';
612
629
  import RootView from './views/root/Root.vue';
613
630
 
614
- // Obtener la configuración de internacionalización
615
- const { internationalization, middleware } = configuration;
616
- const { defaultLocale } = internationalization;
617
-
618
631
  /**
619
632
  * Declarar las rutas con rutas específicas por localidad y metadatos.
620
633
  */
621
- const routes = localeFlatMap((localizedData) => [
634
+ const routes = localeFlatMap(({ urlPrefix, locale }) => [
622
635
  {
623
- path: `${localizedData.urlPrefix}/`,
624
- name: `Root-${localizedData.locale}`,
636
+ path: `${urlPrefix}/`,
637
+ name: `Root-${locale}`,
625
638
  component: RootView,
626
639
  meta: {
627
- locale: localizedData.locale,
640
+ locale,
628
641
  },
629
642
  },
630
643
  {
631
- path: `${localizedData.urlPrefix}/home`,
632
- name: `Home-${localizedData.locale}`,
644
+ path: `${urlPrefix}/home`,
645
+ name: `Home-${locale}`,
633
646
  component: HomeView,
634
647
  meta: {
635
- locale: localizedData.locale,
648
+ locale,
636
649
  },
637
650
  },
638
651
  ]);
@@ -647,23 +660,11 @@ export const router = createRouter({
647
660
  router.beforeEach((to, _from, next) => {
648
661
  const client = createIntlayerClient();
649
662
 
650
- const metaLocale = to.meta.locale as Locales | undefined;
663
+ const metaLocale = to.meta.locale as Locale;
651
664
 
652
- if (metaLocale) {
653
- // Reutilizar el locale definido en los metadatos de la ruta
654
- client.setLocale(metaLocale);
655
- next();
656
- } else {
657
- // Alternativa: sin locale en los metadatos, posiblemente ruta no coincidente
658
- // Opcional: manejar 404 o redirigir al locale por defecto
659
- client.setLocale(defaultLocale);
660
-
661
- if (middleware.prefixDefault) {
662
- next(`/${defaultLocale}${getPathWithoutLocale(to.path)}`);
663
- } else {
664
- next(getPathWithoutLocale(to.path));
665
- }
666
- }
665
+ // Reutilizar el locale definido en los metadatos de la ruta
666
+ client.setLocale(metaLocale);
667
+ next();
667
668
  });
668
669
  ```
669
670
 
@@ -805,7 +806,7 @@ watch(
805
806
  Consejo: Para un mejor SEO y accesibilidad, use etiquetas como `<a href="/fr/home" hreflang="fr">` para enlazar a páginas localizadas, como se muestra en el Paso 10. Esto permite que los motores de búsqueda descubran e indexen correctamente las URLs específicas por idioma. Para preservar el comportamiento SPA, puede prevenir la navegación predeterminada con @click.prevent, cambiar la configuración regional usando useLocale y navegar programáticamente usando Vue Router.
806
807
 
807
808
  ```html
808
- <ol class="divide-text/20 divide-y divide-dashed overflow-y-auto p-1">
809
+ <ol>
809
810
  <li>
810
811
  <a
811
812
  hreflang="x-default"
@@ -18,6 +18,9 @@ slugs:
18
18
  - tanstack-start
19
19
  applicationTemplate: https://github.com/aymericzip/intlayer-tanstack-start-template
20
20
  history:
21
+ - version: 7.3.9
22
+ date: 2025-12-05
23
+ changes: Add step 13: Retrieve the locale in your server actions (Optional)
21
24
  - version: 5.8.1
22
25
  date: 2025-09-09
23
26
  changes: Ajout pour Tanstack Start
@@ -47,6 +50,27 @@ Avec Intlayer, vous pouvez :
47
50
 
48
51
  ## Guide étape par étape pour configurer Intlayer dans une application Tanstack Start
49
52
 
53
+ <Tab defaultTab="video">
54
+ <TabItem label="Video" value="video">
55
+
56
+ <iframe title="La meilleure solution i18n pour Tanstack Start ? Découvrez Intlayer" class="m-auto aspect-[16/9] w-full overflow-hidden rounded-lg border-0" allow="autoplay; gyroscope;" loading="lazy" width="1080" height="auto" src="https://www.youtube.com/embed/_XTdKVWaeqg?autoplay=0&amp;origin=http://intlayer.org&amp;controls=0&amp;rel=1"/>
57
+
58
+ </TabItem>
59
+ <TabItem label="Code" value="code">
60
+
61
+ <iframe
62
+ src="https://stackblitz.com/github/aymericzip/intlayer-tanstack-start-template?embed=1&ctl=1&file=intlayer.config.ts"
63
+ className="m-auto overflow-hidden rounded-lg border-0 max-md:size-full max-md:h-[700px] md:aspect-16/9 md:w-full"
64
+ title="Demo CodeSandbox - Comment internationaliser votre application en utilisant Intlayer"
65
+ sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"
66
+ loading="lazy"
67
+ />
68
+
69
+ </TabItem>
70
+ </Tab>
71
+
72
+ Voir le [Template d'application](https://github.com/aymericzip/intlayer-tanstack-start-template) sur GitHub.
73
+
50
74
  ### Étape 1 : Créer le projet
51
75
 
52
76
  Commencez par créer un nouveau projet TanStack Start en suivant le guide [Démarrer un nouveau projet](https://tanstack.com/start/latest/docs/framework/react/quick-start) sur le site de TanStack Start.
@@ -536,7 +560,55 @@ export const Route = createFileRoute("/{-$locale}/")({
536
560
 
537
561
  ---
538
562
 
539
- ### Étape 13 : Configurer TypeScript (Optionnel)
563
+ ### Étape 13 : Récupérer la locale dans vos actions serveur (Optionnel)
564
+
565
+ Vous voudrez peut-être accéder à la locale actuelle depuis l'intérieur de vos actions serveur ou points de terminaison API.
566
+ Vous pouvez le faire en utilisant l'assistant `getLocale` de `intlayer`.
567
+
568
+ Voici un exemple utilisant les fonctions serveur de TanStack Start :
569
+
570
+ ```tsx fileName="src/routes/{-$locale}/index.tsx"
571
+ import { createServerFn } from "@tanstack/react-start";
572
+ import {
573
+ getRequestHeader,
574
+ getRequestHeaders,
575
+ } from "@tanstack/react-start/server";
576
+ import { getCookie, getIntlayer, getLocale } from "intlayer";
577
+
578
+ export const getLocaleServer = createServerFn().handler(async () => {
579
+ const locale = await getLocale({
580
+ // Récupérer le cookie depuis la requête (défaut : 'INTLAYER_LOCALE')
581
+ getCookie: (name) => {
582
+ const cookieString = getRequestHeader("cookie");
583
+
584
+ return getCookie(name, cookieString);
585
+ },
586
+ // Récupérer l'en-tête depuis la requête (défaut : 'x-intlayer-locale')
587
+ getHeader: (name) => getRequestHeader(name),
588
+ // Repli utilisant la négociation Accept-Language
589
+ getAllHeaders: async () => {
590
+ const headers = getRequestHeaders();
591
+ const result: Record<string, string> = {};
592
+
593
+ // Convertir les TypedHeaders en un simple Record<string, string>
594
+ for (const [key, value] of headers.entries()) {
595
+ result[key] = value;
596
+ }
597
+
598
+ return result;
599
+ },
600
+ });
601
+
602
+ // Récupérer du contenu en utilisant getIntlayer()
603
+ const content = getIntlayer("app", locale);
604
+
605
+ return { locale, content };
606
+ });
607
+ ```
608
+
609
+ ---
610
+
611
+ ### Étape 14 : Configurer TypeScript (Optionnel)
540
612
 
541
613
  Intlayer utilise l'augmentation de module pour bénéficier de TypeScript et renforcer votre base de code.
542
614