@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.
- package/docs/ar/intlayer_with_tanstack.md +73 -1
- package/docs/ar/intlayer_with_vite+vue.md +37 -34
- package/docs/de/intlayer_with_tanstack.md +73 -1
- package/docs/de/intlayer_with_vite+vue.md +37 -34
- package/docs/en/intlayer_with_tanstack.md +63 -1
- package/docs/en/intlayer_with_vite+vue.md +27 -34
- package/docs/en-GB/intlayer_with_tanstack.md +73 -1
- package/docs/en-GB/intlayer_with_vite+vue.md +37 -34
- package/docs/es/intlayer_with_tanstack.md +73 -1
- package/docs/es/intlayer_with_vite+vue.md +37 -36
- package/docs/fr/intlayer_with_tanstack.md +73 -1
- package/docs/fr/intlayer_with_vite+vue.md +37 -36
- package/docs/hi/intlayer_with_tanstack.md +73 -1
- package/docs/hi/intlayer_with_vite+vue.md +37 -34
- package/docs/id/intlayer_with_tanstack.md +63 -1
- package/docs/id/intlayer_with_vite+vue.md +28 -35
- package/docs/it/intlayer_with_tanstack.md +73 -1
- package/docs/it/intlayer_with_vite+vue.md +37 -34
- package/docs/ja/intlayer_with_tanstack.md +73 -1
- package/docs/ja/intlayer_with_vite+vue.md +37 -34
- package/docs/ko/intlayer_with_tanstack.md +73 -1
- package/docs/ko/intlayer_with_vite+vue.md +37 -34
- package/docs/pl/intlayer_with_tanstack.md +63 -1
- package/docs/pl/intlayer_with_vite+vue.md +33 -34
- package/docs/pt/intlayer_with_tanstack.md +73 -1
- package/docs/pt/intlayer_with_vite+vue.md +37 -34
- package/docs/ru/intlayer_with_tanstack.md +73 -1
- package/docs/ru/intlayer_with_vite+vue.md +37 -34
- package/docs/tr/intlayer_with_tanstack.md +73 -1
- package/docs/tr/intlayer_with_vite+vue.md +37 -34
- package/docs/vi/intlayer_with_tanstack.md +63 -1
- package/docs/vi/intlayer_with_vite+vue.md +33 -34
- package/docs/zh/intlayer_with_tanstack.md +73 -1
- package/docs/zh/intlayer_with_vite+vue.md +37 -34
- package/package.json +6 -6
|
@@ -23,8 +23,6 @@ history:
|
|
|
23
23
|
|
|
24
24
|
# Traduire votre Vite and Vue avec Intlayer | Internationalisation (i18n)
|
|
25
25
|
|
|
26
|
-
Voir le [Modèle d'application](https://github.com/aymericzip/intlayer-vite-vue-template) sur GitHub.
|
|
27
|
-
|
|
28
26
|
## Qu'est-ce que Intlayer ?
|
|
29
27
|
|
|
30
28
|
**Intlayer** est une bibliothèque d'internationalisation (i18n) innovante et open-source conçue pour simplifier la prise en charge multilingue dans les applications web modernes.
|
|
@@ -40,6 +38,27 @@ Avec Intlayer, vous pouvez :
|
|
|
40
38
|
|
|
41
39
|
## Guide étape par étape pour configurer Intlayer dans une application Vite et Vue
|
|
42
40
|
|
|
41
|
+
<Tab defaultTab="video">
|
|
42
|
+
<TabItem label="Vidéo" 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&origin=http://intlayer.org&controls=0&rel=1"/>
|
|
45
|
+
|
|
46
|
+
</TabItem>
|
|
47
|
+
<TabItem label="Code" 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
|
+
Voir le [Modèle d'application](https://github.com/aymericzip/intlayer-vite-vue-template) sur GitHub.
|
|
61
|
+
|
|
43
62
|
### Étape 1 : Installer les dépendances
|
|
44
63
|
|
|
45
64
|
Installez les paquets nécessaires avec npm :
|
|
@@ -537,53 +556,47 @@ Exemple :
|
|
|
537
556
|
Tout d'abord, installez Vue Router :
|
|
538
557
|
|
|
539
558
|
```bash packageManager="npm"
|
|
540
|
-
npm install
|
|
559
|
+
npm install vue-router
|
|
541
560
|
```
|
|
542
561
|
|
|
543
562
|
```bash packageManager="pnpm"
|
|
544
|
-
pnpm add
|
|
563
|
+
pnpm add vue-router
|
|
545
564
|
```
|
|
546
565
|
|
|
547
566
|
```bash packageManager="yarn"
|
|
548
|
-
yarn add
|
|
567
|
+
yarn add vue-router
|
|
549
568
|
```
|
|
550
569
|
|
|
551
570
|
Ensuite, créez une configuration de routeur qui gère le routage basé sur la locale :
|
|
552
571
|
|
|
553
572
|
```js fileName="src/router/index.ts"
|
|
554
573
|
import {
|
|
555
|
-
configuration,
|
|
556
|
-
getPathWithoutLocale,
|
|
557
574
|
localeFlatMap,
|
|
558
|
-
type
|
|
575
|
+
type Locale,
|
|
559
576
|
} from 'intlayer';
|
|
560
577
|
import { createIntlayerClient } from 'vue-intlayer';
|
|
561
578
|
import { createRouter, createWebHistory } from 'vue-router';
|
|
562
579
|
import HomeView from './views/home/HomeView.vue';
|
|
563
580
|
import RootView from './views/root/Root.vue';
|
|
564
581
|
|
|
565
|
-
// Obtenir la configuration d'internationalisation
|
|
566
|
-
const { internationalization, middleware } = configuration;
|
|
567
|
-
const { defaultLocale } = internationalization;
|
|
568
|
-
|
|
569
582
|
/**
|
|
570
583
|
* Déclarez les routes avec des chemins et des métadonnées spécifiques à la locale.
|
|
571
584
|
*/
|
|
572
|
-
const routes = localeFlatMap((
|
|
585
|
+
const routes = localeFlatMap(({ urlPrefix, locale }) => [
|
|
573
586
|
{
|
|
574
|
-
path: `${
|
|
575
|
-
name: `Root-${
|
|
587
|
+
path: `${urlPrefix}/`,
|
|
588
|
+
name: `Root-${locale}`,
|
|
576
589
|
component: RootView,
|
|
577
590
|
meta: {
|
|
578
|
-
locale
|
|
591
|
+
locale,
|
|
579
592
|
},
|
|
580
593
|
},
|
|
581
594
|
{
|
|
582
|
-
path: `${
|
|
583
|
-
name: `Home-${
|
|
595
|
+
path: `${urlPrefix}/home`,
|
|
596
|
+
name: `Home-${locale}`,
|
|
584
597
|
component: HomeView,
|
|
585
598
|
meta: {
|
|
586
|
-
locale
|
|
599
|
+
locale,
|
|
587
600
|
},
|
|
588
601
|
},
|
|
589
602
|
]);
|
|
@@ -598,23 +611,11 @@ export const router = createRouter({
|
|
|
598
611
|
router.beforeEach((to, _from, next) => {
|
|
599
612
|
const client = createIntlayerClient();
|
|
600
613
|
|
|
601
|
-
const metaLocale = to.meta.locale as
|
|
614
|
+
const metaLocale = to.meta.locale as Locale;
|
|
602
615
|
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
next();
|
|
607
|
-
} else {
|
|
608
|
-
// Repli : pas de locale dans les métadonnées, route possiblement non trouvée
|
|
609
|
-
// Optionnel : gérer les erreurs 404 ou rediriger vers la locale par défaut
|
|
610
|
-
client.setLocale(defaultLocale);
|
|
611
|
-
|
|
612
|
-
if (middleware.prefixDefault) {
|
|
613
|
-
next(`/${defaultLocale}${getPathWithoutLocale(to.path)}`);
|
|
614
|
-
} else {
|
|
615
|
-
next(getPathWithoutLocale(to.path));
|
|
616
|
-
}
|
|
617
|
-
}
|
|
616
|
+
// Réutiliser la locale définie dans les métadonnées de la route
|
|
617
|
+
client.setLocale(metaLocale);
|
|
618
|
+
next();
|
|
618
619
|
});
|
|
619
620
|
```
|
|
620
621
|
|
|
@@ -752,7 +753,7 @@ watch(
|
|
|
752
753
|
Astuce : Pour un meilleur SEO et une meilleure accessibilité, utilisez des balises telles que `<a href="/fr/home" hreflang="fr">` pour lier les pages localisées, comme montré à l'étape 10. Cela permet aux moteurs de recherche de découvrir et d'indexer correctement les URL spécifiques à chaque langue. Pour préserver le comportement SPA, vous pouvez empêcher la navigation par défaut avec @click.prevent, changer la locale en utilisant useLocale, et naviguer de manière programmatique avec Vue Router.
|
|
753
754
|
|
|
754
755
|
```html
|
|
755
|
-
<ol
|
|
756
|
+
<ol>
|
|
756
757
|
<li>
|
|
757
758
|
<a
|
|
758
759
|
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: 6.5.2
|
|
22
25
|
date: 2025-10-03
|
|
23
26
|
changes: दस्तावेज़ अपडेट
|
|
@@ -50,6 +53,27 @@ Intlayer के साथ, आप कर सकते हैं:
|
|
|
50
53
|
|
|
51
54
|
## Tanstack Start एप्लिकेशन में Intlayer सेटअप करने के लिए चरण-दर-चरण मार्गदर्शिका
|
|
52
55
|
|
|
56
|
+
<Tab defaultTab="video">
|
|
57
|
+
<TabItem label="Video" value="video">
|
|
58
|
+
|
|
59
|
+
<iframe title="Tanstack Start के लिए सर्वश्रेष्ठ i18n समाधान? 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&origin=http://intlayer.org&controls=0&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 - 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
|
+
GitHub पर [एप्लिकेशन टेम्पलेट](https://github.com/aymericzip/intlayer-tanstack-start-template) देखें।
|
|
76
|
+
|
|
53
77
|
### चरण 1: प्रोजेक्ट बनाएं
|
|
54
78
|
|
|
55
79
|
TanStack Start वेबसाइट पर उपलब्ध [Start new project](https://tanstack.com/start/latest/docs/framework/react/quick-start) गाइड का पालन करके एक नया TanStack Start प्रोजेक्ट बनाएं।
|
|
@@ -528,7 +552,55 @@ export const Route = createFileRoute("/{-$locale}/")({
|
|
|
528
552
|
|
|
529
553
|
---
|
|
530
554
|
|
|
531
|
-
###
|
|
555
|
+
### Step 13: Retrieve the locale in your server actions (Optional)
|
|
556
|
+
|
|
557
|
+
You may want to access the current locale from inside your server actions or API endpoints.
|
|
558
|
+
You can do this using the `getLocale` helper from `intlayer`.
|
|
559
|
+
|
|
560
|
+
Here's an example using TanStack Start's server functions:
|
|
561
|
+
|
|
562
|
+
```tsx fileName="src/routes/{-$locale}/index.tsx"
|
|
563
|
+
import { createServerFn } from "@tanstack/react-start";
|
|
564
|
+
import {
|
|
565
|
+
getRequestHeader,
|
|
566
|
+
getRequestHeaders,
|
|
567
|
+
} from "@tanstack/react-start/server";
|
|
568
|
+
import { getCookie, getIntlayer, getLocale } from "intlayer";
|
|
569
|
+
|
|
570
|
+
export const getLocaleServer = createServerFn().handler(async () => {
|
|
571
|
+
const locale = await getLocale({
|
|
572
|
+
// Get the cookie from the request (default: 'INTLAYER_LOCALE')
|
|
573
|
+
getCookie: (name) => {
|
|
574
|
+
const cookieString = getRequestHeader("cookie");
|
|
575
|
+
|
|
576
|
+
return getCookie(name, cookieString);
|
|
577
|
+
},
|
|
578
|
+
// Get the header from the request (default: 'x-intlayer-locale')
|
|
579
|
+
getHeader: (name) => getRequestHeader(name),
|
|
580
|
+
// Fallback using Accept-Language negotiation
|
|
581
|
+
getAllHeaders: async () => {
|
|
582
|
+
const headers = getRequestHeaders();
|
|
583
|
+
const result: Record<string, string> = {};
|
|
584
|
+
|
|
585
|
+
// Convert the TypedHeaders into a plain Record<string, string>
|
|
586
|
+
for (const [key, value] of headers.entries()) {
|
|
587
|
+
result[key] = value;
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
return result;
|
|
591
|
+
},
|
|
592
|
+
});
|
|
593
|
+
|
|
594
|
+
// Retrieve some content using getIntlayer()
|
|
595
|
+
const content = getIntlayer("app", locale);
|
|
596
|
+
|
|
597
|
+
return { locale, content };
|
|
598
|
+
});
|
|
599
|
+
```
|
|
600
|
+
|
|
601
|
+
---
|
|
602
|
+
|
|
603
|
+
### चरण 14: टाइपस्क्रिप्ट कॉन्फ़िगर करें (वैकल्पिक)
|
|
532
604
|
|
|
533
605
|
Intlayer टाइपस्क्रिप्ट के लाभ प्राप्त करने और आपके कोडबेस को मजबूत बनाने के लिए मॉड्यूल ऑगमेंटेशन का उपयोग करता है।
|
|
534
606
|
|
|
@@ -40,6 +40,27 @@ Intlayer के साथ, आप कर सकते हैं:
|
|
|
40
40
|
|
|
41
41
|
## Vite और Vue एप्लिकेशन में Intlayer सेटअप करने के लिए चरण-दर-चरण मार्गदर्शिका
|
|
42
42
|
|
|
43
|
+
<Tab defaultTab="video">
|
|
44
|
+
<TabItem label="वीडियो" 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&origin=http://intlayer.org&controls=0&rel=1"/>
|
|
47
|
+
|
|
48
|
+
</TabItem>
|
|
49
|
+
<TabItem label="कोड" 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
|
+
GitHub पर [एप्लिकेशन टेम्पलेट](https://github.com/aymericzip/intlayer-vite-vue-template) देखें।
|
|
63
|
+
|
|
43
64
|
### चरण 1: निर्भरताएँ स्थापित करें
|
|
44
65
|
|
|
45
66
|
npm का उपयोग करके आवश्यक पैकेज स्थापित करें:
|
|
@@ -545,53 +566,47 @@ Vue एप्लिकेशन में स्थानीयकृत रा
|
|
|
545
566
|
सबसे पहले, Vue Router इंस्टॉल करें:
|
|
546
567
|
|
|
547
568
|
```bash packageManager="npm"
|
|
548
|
-
npm install
|
|
569
|
+
npm install vue-router
|
|
549
570
|
```
|
|
550
571
|
|
|
551
572
|
```bash packageManager="pnpm"
|
|
552
|
-
pnpm add
|
|
573
|
+
pnpm add vue-router
|
|
553
574
|
```
|
|
554
575
|
|
|
555
576
|
```bash packageManager="yarn"
|
|
556
|
-
yarn add
|
|
577
|
+
yarn add vue-router
|
|
557
578
|
```
|
|
558
579
|
|
|
559
580
|
फिर, एक राउटर कॉन्फ़िगरेशन बनाएं जो स्थानीय-आधारित रूटिंग को संभालता है:
|
|
560
581
|
|
|
561
582
|
```js fileName="src/router/index.ts"
|
|
562
583
|
import {
|
|
563
|
-
configuration,
|
|
564
|
-
getPathWithoutLocale,
|
|
565
584
|
localeFlatMap,
|
|
566
|
-
type
|
|
585
|
+
type Locale,
|
|
567
586
|
} from 'intlayer';
|
|
568
587
|
import { createIntlayerClient } from 'vue-intlayer';
|
|
569
588
|
import { createRouter, createWebHistory } from 'vue-router';
|
|
570
589
|
import HomeView from './views/home/HomeView.vue';
|
|
571
590
|
import RootView from './views/root/Root.vue';
|
|
572
591
|
|
|
573
|
-
// अंतरराष्ट्रीयकरण कॉन्फ़िगरेशन प्राप्त करें
|
|
574
|
-
const { internationalization, middleware } = configuration;
|
|
575
|
-
const { defaultLocale } = internationalization;
|
|
576
|
-
|
|
577
592
|
/**
|
|
578
593
|
* स्थानीय-विशिष्ट पथ और मेटाडेटा के साथ रूट्स घोषित करें।
|
|
579
594
|
*/
|
|
580
|
-
const routes = localeFlatMap((
|
|
595
|
+
const routes = localeFlatMap(({ urlPrefix, locale }) => [
|
|
581
596
|
{
|
|
582
|
-
path: `${
|
|
583
|
-
name: `Root-${
|
|
597
|
+
path: `${urlPrefix}/`,
|
|
598
|
+
name: `Root-${locale}`,
|
|
584
599
|
component: RootView,
|
|
585
600
|
meta: {
|
|
586
|
-
locale
|
|
601
|
+
locale,
|
|
587
602
|
},
|
|
588
603
|
},
|
|
589
604
|
{
|
|
590
|
-
path: `${
|
|
591
|
-
name: `Home-${
|
|
605
|
+
path: `${urlPrefix}/home`,
|
|
606
|
+
name: `Home-${locale}`,
|
|
592
607
|
component: HomeView,
|
|
593
608
|
meta: {
|
|
594
|
-
locale
|
|
609
|
+
locale,
|
|
595
610
|
},
|
|
596
611
|
},
|
|
597
612
|
]);
|
|
@@ -606,23 +621,11 @@ export const router = createRouter({
|
|
|
606
621
|
router.beforeEach((to, _from, next) => {
|
|
607
622
|
const client = createIntlayerClient();
|
|
608
623
|
|
|
609
|
-
const metaLocale = to.meta.locale as
|
|
624
|
+
const metaLocale = to.meta.locale as Locale;
|
|
610
625
|
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
next();
|
|
615
|
-
} else {
|
|
616
|
-
// फॉलबैक: मेटा में कोई स्थानीयता नहीं, संभवतः अनमिलित रूट
|
|
617
|
-
// वैकल्पिक: 404 को संभालें या डिफ़ॉल्ट स्थानीयता पर पुनः निर्देशित करें
|
|
618
|
-
client.setLocale(defaultLocale);
|
|
619
|
-
|
|
620
|
-
if (middleware.prefixDefault) {
|
|
621
|
-
next(`/${defaultLocale}${getPathWithoutLocale(to.path)}`);
|
|
622
|
-
} else {
|
|
623
|
-
next(getPathWithoutLocale(to.path));
|
|
624
|
-
}
|
|
625
|
-
}
|
|
626
|
+
// रूट मेटा में परिभाषित स्थानीयता का पुन: उपयोग करें
|
|
627
|
+
client.setLocale(metaLocale);
|
|
628
|
+
next();
|
|
626
629
|
});
|
|
627
630
|
```
|
|
628
631
|
|
|
@@ -760,7 +763,7 @@ watch(
|
|
|
760
763
|
टिप: बेहतर SEO और पहुँच के लिए, स्थानीयकृत पृष्ठों से लिंक करने के लिए `<a href="/fr/home" hreflang="fr">` जैसे टैग का उपयोग करें, जैसा कि चरण 10 में दिखाया गया है। इससे खोज इंजन भाषा-विशिष्ट URL को सही ढंग से खोज और अनुक्रमित कर सकते हैं। SPA व्यवहार बनाए रखने के लिए, आप @click.prevent के साथ डिफ़ॉल्ट नेविगेशन को रोक सकते हैं, useLocale का उपयोग करके स्थानीयता बदल सकते हैं, और Vue Router का उपयोग करके प्रोग्रामेटिक रूप से नेविगेट कर सकते हैं।
|
|
761
764
|
|
|
762
765
|
```html
|
|
763
|
-
<ol
|
|
766
|
+
<ol>
|
|
764
767
|
<li>
|
|
765
768
|
<a
|
|
766
769
|
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: 6.5.2
|
|
22
25
|
date: 2025-10-03
|
|
23
26
|
changes: Memperbarui dokumen
|
|
@@ -50,6 +53,14 @@ Dengan Intlayer, Anda dapat:
|
|
|
50
53
|
|
|
51
54
|
## Panduan Langkah demi Langkah untuk Mengatur Intlayer dalam Aplikasi Tanstack Start
|
|
52
55
|
|
|
56
|
+
<Tab defaultTab="video">
|
|
57
|
+
<TabItem label="Video" value="video">
|
|
58
|
+
|
|
59
|
+
<iframe title="Solusi i18n terbaik untuk Tanstack Start? Temukan 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&origin=http://intlayer.org&controls=0&rel=1"/>
|
|
60
|
+
|
|
61
|
+
</TabItem>
|
|
62
|
+
<TabItem label="Code" value="code">
|
|
63
|
+
|
|
53
64
|
<iframe
|
|
54
65
|
src="https://stackblitz.com/github/aymericzip/intlayer-tanstack-start-template?embed=1&ctl=1&file=intlayer.config.ts"
|
|
55
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"
|
|
@@ -58,6 +69,9 @@ Dengan Intlayer, Anda dapat:
|
|
|
58
69
|
loading="lazy"
|
|
59
70
|
/>
|
|
60
71
|
|
|
72
|
+
</TabItem>
|
|
73
|
+
</Tab>
|
|
74
|
+
|
|
61
75
|
Lihat [Template Aplikasi](https://github.com/aymericzip/intlayer-tanstack-start-template) di GitHub.
|
|
62
76
|
|
|
63
77
|
### Langkah 1: Buat Proyek
|
|
@@ -540,7 +554,55 @@ export const Route = createFileRoute("/{-$locale}/")({
|
|
|
540
554
|
|
|
541
555
|
---
|
|
542
556
|
|
|
543
|
-
###
|
|
557
|
+
### Step 13: Retrieve the locale in your server actions (Optional)
|
|
558
|
+
|
|
559
|
+
You may want to access the current locale from inside your server actions or API endpoints.
|
|
560
|
+
You can do this using the `getLocale` helper from `intlayer`.
|
|
561
|
+
|
|
562
|
+
Here's an example using TanStack Start's server functions:
|
|
563
|
+
|
|
564
|
+
```tsx fileName="src/routes/{-$locale}/index.tsx"
|
|
565
|
+
import { createServerFn } from "@tanstack/react-start";
|
|
566
|
+
import {
|
|
567
|
+
getRequestHeader,
|
|
568
|
+
getRequestHeaders,
|
|
569
|
+
} from "@tanstack/react-start/server";
|
|
570
|
+
import { getCookie, getIntlayer, getLocale } from "intlayer";
|
|
571
|
+
|
|
572
|
+
export const getLocaleServer = createServerFn().handler(async () => {
|
|
573
|
+
const locale = await getLocale({
|
|
574
|
+
// Get the cookie from the request (default: 'INTLAYER_LOCALE')
|
|
575
|
+
getCookie: (name) => {
|
|
576
|
+
const cookieString = getRequestHeader("cookie");
|
|
577
|
+
|
|
578
|
+
return getCookie(name, cookieString);
|
|
579
|
+
},
|
|
580
|
+
// Get the header from the request (default: 'x-intlayer-locale')
|
|
581
|
+
getHeader: (name) => getRequestHeader(name),
|
|
582
|
+
// Fallback using Accept-Language negotiation
|
|
583
|
+
getAllHeaders: async () => {
|
|
584
|
+
const headers = getRequestHeaders();
|
|
585
|
+
const result: Record<string, string> = {};
|
|
586
|
+
|
|
587
|
+
// Convert the TypedHeaders into a plain Record<string, string>
|
|
588
|
+
for (const [key, value] of headers.entries()) {
|
|
589
|
+
result[key] = value;
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
return result;
|
|
593
|
+
},
|
|
594
|
+
});
|
|
595
|
+
|
|
596
|
+
// Retrieve some content using getIntlayer()
|
|
597
|
+
const content = getIntlayer("app", locale);
|
|
598
|
+
|
|
599
|
+
return { locale, content };
|
|
600
|
+
});
|
|
601
|
+
```
|
|
602
|
+
|
|
603
|
+
---
|
|
604
|
+
|
|
605
|
+
### Langkah 14: Konfigurasi TypeScript (Opsional)
|
|
544
606
|
|
|
545
607
|
Intlayer menggunakan module augmentation untuk mendapatkan manfaat dari TypeScript dan membuat codebase Anda lebih kuat.
|
|
546
608
|
|
|
@@ -42,14 +42,25 @@ Dengan Intlayer, Anda dapat:
|
|
|
42
42
|
|
|
43
43
|
## Panduan Langkah demi Langkah untuk Mengatur Intlayer dalam Aplikasi Vite dan Vue
|
|
44
44
|
|
|
45
|
+
<Tab defaultTab="video">
|
|
46
|
+
<TabItem label="Video" value="video">
|
|
47
|
+
|
|
48
|
+
<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&origin=http://intlayer.org&controls=0&rel=1"/>
|
|
49
|
+
|
|
50
|
+
</TabItem>
|
|
51
|
+
<TabItem label="Kode" value="code">
|
|
52
|
+
|
|
45
53
|
<iframe
|
|
46
54
|
src="https://stackblitz.com/github/aymericzip/intlayer-vite-vue-template?embed=1&ctl=1&file=intlayer.config.ts"
|
|
47
55
|
className="m-auto overflow-hidden rounded-lg border-0 max-md:size-full max-md:h-[700px] md:aspect-16/9 md:w-full"
|
|
48
|
-
title="Demo CodeSandbox -
|
|
56
|
+
title="Demo CodeSandbox - How to Internationalize your application using Intlayer"
|
|
49
57
|
sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"
|
|
50
58
|
loading="lazy"
|
|
51
59
|
/>
|
|
52
60
|
|
|
61
|
+
</TabItem>
|
|
62
|
+
</Tab>
|
|
63
|
+
|
|
53
64
|
Lihat [Template Aplikasi](https://github.com/aymericzip/intlayer-vite-vue-template) di GitHub.
|
|
54
65
|
|
|
55
66
|
### Langkah 1: Instalasi Dependensi
|
|
@@ -584,53 +595,47 @@ Contoh:
|
|
|
584
595
|
Pertama, instal Vue Router:
|
|
585
596
|
|
|
586
597
|
```bash packageManager="npm"
|
|
587
|
-
npm install
|
|
598
|
+
npm install vue-router
|
|
588
599
|
```
|
|
589
600
|
|
|
590
601
|
```bash packageManager="pnpm"
|
|
591
|
-
pnpm add
|
|
602
|
+
pnpm add vue-router
|
|
592
603
|
```
|
|
593
604
|
|
|
594
605
|
```bash packageManager="yarn"
|
|
595
|
-
yarn add
|
|
606
|
+
yarn add vue-router
|
|
596
607
|
```
|
|
597
608
|
|
|
598
609
|
Lalu, buat konfigurasi router yang menangani routing berbasis locale:
|
|
599
610
|
|
|
600
611
|
```js fileName="src/router/index.ts"
|
|
601
612
|
import {
|
|
602
|
-
configuration,
|
|
603
|
-
getPathWithoutLocale,
|
|
604
613
|
localeFlatMap,
|
|
605
|
-
type
|
|
614
|
+
type Locale,
|
|
606
615
|
} from 'intlayer';
|
|
607
616
|
import { createIntlayerClient } from 'vue-intlayer';
|
|
608
617
|
import { createRouter, createWebHistory } from 'vue-router';
|
|
609
618
|
import HomeView from './views/home/HomeView.vue';
|
|
610
619
|
import RootView from './views/root/Root.vue';
|
|
611
620
|
|
|
612
|
-
// Mendapatkan konfigurasi internasionalisasi
|
|
613
|
-
const { internationalization, middleware } = configuration;
|
|
614
|
-
const { defaultLocale } = internationalization;
|
|
615
|
-
|
|
616
621
|
/**
|
|
617
622
|
* Mendeklarasikan routes dengan path dan metadata spesifik locale.
|
|
618
623
|
*/
|
|
619
|
-
const routes = localeFlatMap((
|
|
624
|
+
const routes = localeFlatMap(({ urlPrefix, locale }) => [
|
|
620
625
|
{
|
|
621
|
-
path: `${
|
|
622
|
-
name: `Root-${
|
|
626
|
+
path: `${urlPrefix}/`,
|
|
627
|
+
name: `Root-${locale}`,
|
|
623
628
|
component: RootView,
|
|
624
629
|
meta: {
|
|
625
|
-
locale
|
|
630
|
+
locale,
|
|
626
631
|
},
|
|
627
632
|
},
|
|
628
633
|
{
|
|
629
|
-
path: `${
|
|
630
|
-
name: `Home-${
|
|
634
|
+
path: `${urlPrefix}/home`,
|
|
635
|
+
name: `Home-${locale}`,
|
|
631
636
|
component: HomeView,
|
|
632
637
|
meta: {
|
|
633
|
-
locale
|
|
638
|
+
locale,
|
|
634
639
|
},
|
|
635
640
|
},
|
|
636
641
|
]);
|
|
@@ -645,23 +650,11 @@ export const router = createRouter({
|
|
|
645
650
|
router.beforeEach((to, _from, next) => {
|
|
646
651
|
const client = createIntlayerClient();
|
|
647
652
|
|
|
648
|
-
const metaLocale = to.meta.locale as
|
|
653
|
+
const metaLocale = to.meta.locale as Locale;
|
|
649
654
|
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
next();
|
|
654
|
-
} else {
|
|
655
|
-
// Cadangan: tidak ada locale di meta, kemungkinan route tidak cocok
|
|
656
|
-
// Opsional: tangani 404 atau redirect ke locale default
|
|
657
|
-
client.setLocale(defaultLocale);
|
|
658
|
-
|
|
659
|
-
if (middleware.prefixDefault) {
|
|
660
|
-
next(`/${defaultLocale}${getPathWithoutLocale(to.path)}`);
|
|
661
|
-
} else {
|
|
662
|
-
next(getPathWithoutLocale(to.path));
|
|
663
|
-
}
|
|
664
|
-
}
|
|
655
|
+
// Gunakan kembali locale yang didefinisikan di meta route
|
|
656
|
+
client.setLocale(metaLocale);
|
|
657
|
+
next();
|
|
665
658
|
});
|
|
666
659
|
```
|
|
667
660
|
|
|
@@ -793,7 +786,7 @@ watch(
|
|
|
793
786
|
Tip: Untuk SEO dan aksesibilitas yang lebih baik, gunakan tag seperti `<a href="/fr/home" hreflang="fr">` untuk menautkan ke halaman yang dilokalkan, seperti yang ditunjukkan pada Langkah 10. Ini memungkinkan mesin pencari menemukan dan mengindeks URL spesifik bahasa dengan benar. Untuk mempertahankan perilaku SPA, Anda dapat mencegah navigasi default dengan @click.prevent, mengubah locale menggunakan useLocale, dan menavigasi secara programatik menggunakan Vue Router.
|
|
794
787
|
|
|
795
788
|
```html
|
|
796
|
-
<ol
|
|
789
|
+
<ol>
|
|
797
790
|
<li>
|
|
798
791
|
<a
|
|
799
792
|
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: 6.5.2
|
|
22
25
|
date: 2025-10-03
|
|
23
26
|
changes: Aggiornamento documentazione
|
|
@@ -50,6 +53,27 @@ Con Intlayer, puoi:
|
|
|
50
53
|
|
|
51
54
|
## Guida passo-passo per configurare Intlayer in un'applicazione Tanstack Start
|
|
52
55
|
|
|
56
|
+
<Tab defaultTab="video">
|
|
57
|
+
<TabItem label="Video" value="video">
|
|
58
|
+
|
|
59
|
+
<iframe title="La migliore soluzione i18n per Tanstack Start? Scopri 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&origin=http://intlayer.org&controls=0&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 - Come internazionalizzare la tua applicazione usando 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
|
+
Vedi il [Template dell'applicazione](https://github.com/aymericzip/intlayer-tanstack-start-template) su GitHub.
|
|
76
|
+
|
|
53
77
|
### Passo 1: Creare il progetto
|
|
54
78
|
|
|
55
79
|
Inizia creando un nuovo progetto TanStack Start seguendo la guida [Start new project](https://tanstack.com/start/latest/docs/framework/react/quick-start) sul sito di TanStack Start.
|
|
@@ -549,7 +573,55 @@ export const Route = createFileRoute("/{-$locale}/")({
|
|
|
549
573
|
|
|
550
574
|
---
|
|
551
575
|
|
|
552
|
-
### Passo 13:
|
|
576
|
+
### Passo 13: Recuperare la locale nelle azioni del server (Opzionale)
|
|
577
|
+
|
|
578
|
+
Potresti voler accedere alla locale corrente dall'interno delle tue azioni server o endpoint API.
|
|
579
|
+
Puoi farlo usando l'helper `getLocale` da `intlayer`.
|
|
580
|
+
|
|
581
|
+
Ecco un esempio utilizzando le funzioni server di TanStack Start:
|
|
582
|
+
|
|
583
|
+
```tsx fileName="src/routes/{-$locale}/index.tsx"
|
|
584
|
+
import { createServerFn } from "@tanstack/react-start";
|
|
585
|
+
import {
|
|
586
|
+
getRequestHeader,
|
|
587
|
+
getRequestHeaders,
|
|
588
|
+
} from "@tanstack/react-start/server";
|
|
589
|
+
import { getCookie, getIntlayer, getLocale } from "intlayer";
|
|
590
|
+
|
|
591
|
+
export const getLocaleServer = createServerFn().handler(async () => {
|
|
592
|
+
const locale = await getLocale({
|
|
593
|
+
// Ottieni il cookie dalla richiesta (default: 'INTLAYER_LOCALE')
|
|
594
|
+
getCookie: (name) => {
|
|
595
|
+
const cookieString = getRequestHeader("cookie");
|
|
596
|
+
|
|
597
|
+
return getCookie(name, cookieString);
|
|
598
|
+
},
|
|
599
|
+
// Ottieni l'header dalla richiesta (default: 'x-intlayer-locale')
|
|
600
|
+
getHeader: (name) => getRequestHeader(name),
|
|
601
|
+
// Fallback utilizzando la negoziazione Accept-Language
|
|
602
|
+
getAllHeaders: async () => {
|
|
603
|
+
const headers = getRequestHeaders();
|
|
604
|
+
const result: Record<string, string> = {};
|
|
605
|
+
|
|
606
|
+
// Converti TypedHeaders in un semplice Record<string, string>
|
|
607
|
+
for (const [key, value] of headers.entries()) {
|
|
608
|
+
result[key] = value;
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
return result;
|
|
612
|
+
},
|
|
613
|
+
});
|
|
614
|
+
|
|
615
|
+
// Recupera alcuni contenuti usando getIntlayer()
|
|
616
|
+
const content = getIntlayer("app", locale);
|
|
617
|
+
|
|
618
|
+
return { locale, content };
|
|
619
|
+
});
|
|
620
|
+
```
|
|
621
|
+
|
|
622
|
+
---
|
|
623
|
+
|
|
624
|
+
### Passo 14: Configurare TypeScript (Opzionale)
|
|
553
625
|
|
|
554
626
|
Intlayer utilizza l'augmentation dei moduli per sfruttare i vantaggi di TypeScript e rendere il tuo codice più robusto.
|
|
555
627
|
|