@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
|
@@ -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: أضيف لـ Tanstack Start
|
|
@@ -47,6 +50,27 @@ history:
|
|
|
47
50
|
|
|
48
51
|
## دليل خطوة بخطوة لإعداد Intlayer في تطبيق Tanstack Start
|
|
49
52
|
|
|
53
|
+
<Tab defaultTab="video">
|
|
54
|
+
<TabItem label="Video" value="video">
|
|
55
|
+
|
|
56
|
+
<iframe title="أفضل حل i18n لـ Tanstack Start؟ اكتشف 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"/>
|
|
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 - كيفية تدويل تطبيقك باستخدام 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
|
+
راجع [قالب التطبيق](https://github.com/aymericzip/intlayer-tanstack-start-template) على GitHub.
|
|
73
|
+
|
|
50
74
|
### الخطوة 1: إنشاء المشروع
|
|
51
75
|
|
|
52
76
|
ابدأ بإنشاء مشروع TanStack Start جديد باتباع دليل [بدء مشروع جديد](https://tanstack.com/start/latest/docs/framework/react/quick-start) على موقع TanStack Start.
|
|
@@ -537,7 +561,55 @@ export const Route = createFileRoute("/{-$locale}/")({
|
|
|
537
561
|
|
|
538
562
|
---
|
|
539
563
|
|
|
540
|
-
###
|
|
564
|
+
### Step 13: Retrieve the locale in your server actions (Optional)
|
|
565
|
+
|
|
566
|
+
You may want to access the current locale from inside your server actions or API endpoints.
|
|
567
|
+
You can do this using the `getLocale` helper from `intlayer`.
|
|
568
|
+
|
|
569
|
+
Here's an example using TanStack Start's server functions:
|
|
570
|
+
|
|
571
|
+
```tsx fileName="src/routes/{-$locale}/index.tsx"
|
|
572
|
+
import { createServerFn } from "@tanstack/react-start";
|
|
573
|
+
import {
|
|
574
|
+
getRequestHeader,
|
|
575
|
+
getRequestHeaders,
|
|
576
|
+
} from "@tanstack/react-start/server";
|
|
577
|
+
import { getCookie, getIntlayer, getLocale } from "intlayer";
|
|
578
|
+
|
|
579
|
+
export const getLocaleServer = createServerFn().handler(async () => {
|
|
580
|
+
const locale = await getLocale({
|
|
581
|
+
// Get the cookie from the request (default: 'INTLAYER_LOCALE')
|
|
582
|
+
getCookie: (name) => {
|
|
583
|
+
const cookieString = getRequestHeader("cookie");
|
|
584
|
+
|
|
585
|
+
return getCookie(name, cookieString);
|
|
586
|
+
},
|
|
587
|
+
// Get the header from the request (default: 'x-intlayer-locale')
|
|
588
|
+
getHeader: (name) => getRequestHeader(name),
|
|
589
|
+
// Fallback using Accept-Language negotiation
|
|
590
|
+
getAllHeaders: async () => {
|
|
591
|
+
const headers = getRequestHeaders();
|
|
592
|
+
const result: Record<string, string> = {};
|
|
593
|
+
|
|
594
|
+
// Convert the TypedHeaders into a plain Record<string, string>
|
|
595
|
+
for (const [key, value] of headers.entries()) {
|
|
596
|
+
result[key] = value;
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
return result;
|
|
600
|
+
},
|
|
601
|
+
});
|
|
602
|
+
|
|
603
|
+
// Retrieve some content using getIntlayer()
|
|
604
|
+
const content = getIntlayer("app", locale);
|
|
605
|
+
|
|
606
|
+
return { locale, content };
|
|
607
|
+
});
|
|
608
|
+
```
|
|
609
|
+
|
|
610
|
+
---
|
|
611
|
+
|
|
612
|
+
### الخطوة 14: تكوين TypeScript (اختياري)
|
|
541
613
|
|
|
542
614
|
يستخدم Intlayer توسيع الوحدات (module augmentation) للاستفادة من TypeScript وجعل قاعدة الشيفرة الخاصة بك أقوى.
|
|
543
615
|
|
|
@@ -40,6 +40,27 @@ history:
|
|
|
40
40
|
|
|
41
41
|
## دليل خطوة بخطوة لإعداد Intlayer في تطبيق Vite و Vue
|
|
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
|
+
راجع [قالب التطبيق](https://github.com/aymericzip/intlayer-vite-vue-template) على GitHub.
|
|
63
|
+
|
|
43
64
|
### الخطوة 1: تثبيت التبعيات
|
|
44
65
|
|
|
45
66
|
قم بتثبيت الحزم اللازمة باستخدام npm:
|
|
@@ -542,53 +563,47 @@ const content = useIntlayer("app"); // أنشئ ملف إعلان intlayer ال
|
|
|
542
563
|
أولاً، قم بتثبيت Vue Router:
|
|
543
564
|
|
|
544
565
|
```bash packageManager="npm"
|
|
545
|
-
npm install
|
|
566
|
+
npm install vue-router
|
|
546
567
|
```
|
|
547
568
|
|
|
548
569
|
```bash packageManager="pnpm"
|
|
549
|
-
pnpm add
|
|
570
|
+
pnpm add vue-router
|
|
550
571
|
```
|
|
551
572
|
|
|
552
573
|
```bash packageManager="yarn"
|
|
553
|
-
yarn add
|
|
574
|
+
yarn add vue-router
|
|
554
575
|
```
|
|
555
576
|
|
|
556
577
|
ثم، قم بإنشاء تكوين جهاز التوجيه الذي يتعامل مع التوجيه بناءً على اللغة:
|
|
557
578
|
|
|
558
579
|
```js fileName="src/router/index.ts"
|
|
559
580
|
import {
|
|
560
|
-
configuration,
|
|
561
|
-
getPathWithoutLocale,
|
|
562
581
|
localeFlatMap,
|
|
563
|
-
type
|
|
582
|
+
type Locale,
|
|
564
583
|
} from 'intlayer';
|
|
565
584
|
import { createIntlayerClient } from 'vue-intlayer';
|
|
566
585
|
import { createRouter, createWebHistory } from 'vue-router';
|
|
567
586
|
import HomeView from './views/home/HomeView.vue';
|
|
568
587
|
import RootView from './views/root/Root.vue';
|
|
569
588
|
|
|
570
|
-
// الحصول على إعدادات التدويل
|
|
571
|
-
const { internationalization, middleware } = configuration;
|
|
572
|
-
const { defaultLocale } = internationalization;
|
|
573
|
-
|
|
574
589
|
/**
|
|
575
590
|
* إعلان المسارات مع مسارات وبيانات وصفية خاصة بكل لغة.
|
|
576
591
|
*/
|
|
577
|
-
const routes = localeFlatMap((
|
|
592
|
+
const routes = localeFlatMap(({ urlPrefix, locale }) => [
|
|
578
593
|
{
|
|
579
|
-
path: `${
|
|
580
|
-
name: `Root-${
|
|
594
|
+
path: `${urlPrefix}/`,
|
|
595
|
+
name: `Root-${locale}`,
|
|
581
596
|
component: RootView,
|
|
582
597
|
meta: {
|
|
583
|
-
locale
|
|
598
|
+
locale,
|
|
584
599
|
},
|
|
585
600
|
},
|
|
586
601
|
{
|
|
587
|
-
path: `${
|
|
588
|
-
name: `Home-${
|
|
602
|
+
path: `${urlPrefix}/home`,
|
|
603
|
+
name: `Home-${locale}`,
|
|
589
604
|
component: HomeView,
|
|
590
605
|
meta: {
|
|
591
|
-
locale
|
|
606
|
+
locale,
|
|
592
607
|
},
|
|
593
608
|
},
|
|
594
609
|
]);
|
|
@@ -603,23 +618,11 @@ export const router = createRouter({
|
|
|
603
618
|
router.beforeEach((to, _from, next) => {
|
|
604
619
|
const client = createIntlayerClient();
|
|
605
620
|
|
|
606
|
-
const metaLocale = to.meta.locale as
|
|
621
|
+
const metaLocale = to.meta.locale as Locale;
|
|
607
622
|
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
next();
|
|
612
|
-
} else {
|
|
613
|
-
// الحالة الافتراضية: لا توجد لغة في البيانات، ربما مسار غير مطابق
|
|
614
|
-
// اختياري: التعامل مع خطأ 404 أو إعادة التوجيه إلى اللغة الافتراضية
|
|
615
|
-
client.setLocale(defaultLocale);
|
|
616
|
-
|
|
617
|
-
if (middleware.prefixDefault) {
|
|
618
|
-
next(`/${defaultLocale}${getPathWithoutLocale(to.path)}`);
|
|
619
|
-
} else {
|
|
620
|
-
next(getPathWithoutLocale(to.path));
|
|
621
|
-
}
|
|
622
|
-
}
|
|
623
|
+
// إعادة استخدام اللغة المعرفة في بيانات الراوتر
|
|
624
|
+
client.setLocale(metaLocale);
|
|
625
|
+
next();
|
|
623
626
|
});
|
|
624
627
|
```
|
|
625
628
|
|
|
@@ -757,7 +760,7 @@ watch(
|
|
|
757
760
|
نصيحة: لتحسين تحسين محركات البحث (SEO) وسهولة الوصول، استخدم الوسوم مثل `<a href="/fr/home" hreflang="fr">` للربط بالصفحات المترجمة، كما هو موضح في الخطوة 10. هذا يسمح لمحركات البحث باكتشاف وفهرسة عناوين URL الخاصة بكل لغة بشكل صحيح. للحفاظ على سلوك تطبيق الصفحة الواحدة (SPA)، يمكنك منع التنقل الافتراضي باستخدام @click.prevent، وتغيير اللغة باستخدام useLocale، والتنقل برمجياً باستخدام Vue Router.
|
|
758
761
|
|
|
759
762
|
```html
|
|
760
|
-
<ol
|
|
763
|
+
<ol>
|
|
761
764
|
<li>
|
|
762
765
|
<a
|
|
763
766
|
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: Hinzugefügt für Tanstack Start
|
|
@@ -47,6 +50,27 @@ Mit Intlayer können Sie:
|
|
|
47
50
|
|
|
48
51
|
## Schritt-für-Schritt-Anleitung zur Einrichtung von Intlayer in einer Tanstack Start-Anwendung
|
|
49
52
|
|
|
53
|
+
<Tab defaultTab="video">
|
|
54
|
+
<TabItem label="Video" value="video">
|
|
55
|
+
|
|
56
|
+
<iframe title="Die beste i18n-Lösung für Tanstack Start? Entdecken Sie 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"/>
|
|
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 - So internationalisieren Sie Ihre Anwendung mit 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
|
+
Siehe [Anwendungsvorlage](https://github.com/aymericzip/intlayer-tanstack-start-template) auf GitHub.
|
|
73
|
+
|
|
50
74
|
### Schritt 1: Projekt erstellen
|
|
51
75
|
|
|
52
76
|
Beginnen Sie mit der Erstellung eines neuen TanStack Start-Projekts, indem Sie der Anleitung [Neues Projekt starten](https://tanstack.com/start/latest/docs/framework/react/quick-start) auf der TanStack Start-Website folgen.
|
|
@@ -541,7 +565,55 @@ export const Route = createFileRoute("/{-$locale}/")({
|
|
|
541
565
|
|
|
542
566
|
---
|
|
543
567
|
|
|
544
|
-
### Schritt 13:
|
|
568
|
+
### Schritt 13: Abrufen der Locale in Ihren Serveraktionen (Optional)
|
|
569
|
+
|
|
570
|
+
Möglicherweise möchten Sie von Ihren Serveraktionen oder API-Endpunkten aus auf die aktuelle Locale zugreifen.
|
|
571
|
+
Sie können dies mit dem Helfer `getLocale` aus `intlayer` tun.
|
|
572
|
+
|
|
573
|
+
Hier ist ein Beispiel mit den Serverfunktionen von TanStack Start:
|
|
574
|
+
|
|
575
|
+
```tsx fileName="src/routes/{-$locale}/index.tsx"
|
|
576
|
+
import { createServerFn } from "@tanstack/react-start";
|
|
577
|
+
import {
|
|
578
|
+
getRequestHeader,
|
|
579
|
+
getRequestHeaders,
|
|
580
|
+
} from "@tanstack/react-start/server";
|
|
581
|
+
import { getCookie, getIntlayer, getLocale } from "intlayer";
|
|
582
|
+
|
|
583
|
+
export const getLocaleServer = createServerFn().handler(async () => {
|
|
584
|
+
const locale = await getLocale({
|
|
585
|
+
// Holen Sie sich das Cookie aus der Anfrage (Standard: 'INTLAYER_LOCALE')
|
|
586
|
+
getCookie: (name) => {
|
|
587
|
+
const cookieString = getRequestHeader("cookie");
|
|
588
|
+
|
|
589
|
+
return getCookie(name, cookieString);
|
|
590
|
+
},
|
|
591
|
+
// Holen Sie sich den Header aus der Anfrage (Standard: 'x-intlayer-locale')
|
|
592
|
+
getHeader: (name) => getRequestHeader(name),
|
|
593
|
+
// Fallback mit Accept-Language-Aushandlung
|
|
594
|
+
getAllHeaders: async () => {
|
|
595
|
+
const headers = getRequestHeaders();
|
|
596
|
+
const result: Record<string, string> = {};
|
|
597
|
+
|
|
598
|
+
// Konvertieren Sie die TypedHeaders in ein einfaches Record<string, string>
|
|
599
|
+
for (const [key, value] of headers.entries()) {
|
|
600
|
+
result[key] = value;
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
return result;
|
|
604
|
+
},
|
|
605
|
+
});
|
|
606
|
+
|
|
607
|
+
// Rufen Sie Inhalte mit getIntlayer() ab
|
|
608
|
+
const content = getIntlayer("app", locale);
|
|
609
|
+
|
|
610
|
+
return { locale, content };
|
|
611
|
+
});
|
|
612
|
+
```
|
|
613
|
+
|
|
614
|
+
---
|
|
615
|
+
|
|
616
|
+
### Schritt 14: TypeScript konfigurieren (optional)
|
|
545
617
|
|
|
546
618
|
Intlayer verwendet Module Augmentation, um die Vorteile von TypeScript zu nutzen und Ihren Code robuster zu machen.
|
|
547
619
|
|
|
@@ -40,6 +40,27 @@ Mit Intlayer können Sie:
|
|
|
40
40
|
|
|
41
41
|
## Schritt-für-Schritt-Anleitung zur Einrichtung von Intlayer in einer Vite- und Vue-Anwendung
|
|
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&origin=http://intlayer.org&controls=0&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
|
+
Siehe [Application Template](https://github.com/aymericzip/intlayer-vite-vue-template) auf GitHub.
|
|
63
|
+
|
|
43
64
|
### Schritt 1: Abhängigkeiten installieren
|
|
44
65
|
|
|
45
66
|
Installieren Sie die notwendigen Pakete mit npm:
|
|
@@ -587,53 +608,47 @@ Beispiel:
|
|
|
587
608
|
Zuerst installieren Sie Vue Router:
|
|
588
609
|
|
|
589
610
|
```bash packageManager="npm"
|
|
590
|
-
npm install
|
|
611
|
+
npm install vue-router
|
|
591
612
|
```
|
|
592
613
|
|
|
593
614
|
```bash packageManager="pnpm"
|
|
594
|
-
pnpm add
|
|
615
|
+
pnpm add vue-router
|
|
595
616
|
```
|
|
596
617
|
|
|
597
618
|
```bash packageManager="yarn"
|
|
598
|
-
yarn add
|
|
619
|
+
yarn add vue-router
|
|
599
620
|
```
|
|
600
621
|
|
|
601
622
|
Dann erstellen Sie eine Router-Konfiguration, die die sprachspezifische Navigation behandelt:
|
|
602
623
|
|
|
603
624
|
```js fileName="src/router/index.ts"
|
|
604
625
|
import {
|
|
605
|
-
configuration,
|
|
606
|
-
getPathWithoutLocale,
|
|
607
626
|
localeFlatMap,
|
|
608
|
-
type
|
|
627
|
+
type Locale,
|
|
609
628
|
} from 'intlayer';
|
|
610
629
|
import { createIntlayerClient } from 'vue-intlayer';
|
|
611
630
|
import { createRouter, createWebHistory } from 'vue-router';
|
|
612
631
|
import HomeView from './views/home/HomeView.vue';
|
|
613
632
|
import RootView from './views/root/Root.vue';
|
|
614
633
|
|
|
615
|
-
// Holen Sie die Internationalisierungskonfiguration
|
|
616
|
-
const { internationalization, middleware } = configuration;
|
|
617
|
-
const { defaultLocale } = internationalization;
|
|
618
|
-
|
|
619
634
|
/**
|
|
620
635
|
* Deklarieren Sie die Routen mit sprachspezifischen Pfaden und Metadaten.
|
|
621
636
|
*/
|
|
622
|
-
const routes = localeFlatMap((
|
|
637
|
+
const routes = localeFlatMap(({ urlPrefix, locale }) => [
|
|
623
638
|
{
|
|
624
|
-
path: `${
|
|
625
|
-
name: `Root-${
|
|
639
|
+
path: `${urlPrefix}/`,
|
|
640
|
+
name: `Root-${locale}`,
|
|
626
641
|
component: RootView,
|
|
627
642
|
meta: {
|
|
628
|
-
locale
|
|
643
|
+
locale,
|
|
629
644
|
},
|
|
630
645
|
},
|
|
631
646
|
{
|
|
632
|
-
path: `${
|
|
633
|
-
name: `Home-${
|
|
647
|
+
path: `${urlPrefix}/home`,
|
|
648
|
+
name: `Home-${locale}`,
|
|
634
649
|
component: HomeView,
|
|
635
650
|
meta: {
|
|
636
|
-
locale
|
|
651
|
+
locale,
|
|
637
652
|
},
|
|
638
653
|
},
|
|
639
654
|
]);
|
|
@@ -648,23 +663,11 @@ export const router = createRouter({
|
|
|
648
663
|
router.beforeEach((to, _from, next) => {
|
|
649
664
|
const client = createIntlayerClient();
|
|
650
665
|
|
|
651
|
-
const metaLocale = to.meta.locale as
|
|
666
|
+
const metaLocale = to.meta.locale as Locale;
|
|
652
667
|
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
next();
|
|
657
|
-
} else {
|
|
658
|
-
// Fallback: keine Sprache in Meta, möglicherweise keine passende Route
|
|
659
|
-
// Optional: Behandle 404 oder leite zur Standard-Sprache weiter
|
|
660
|
-
client.setLocale(defaultLocale);
|
|
661
|
-
|
|
662
|
-
if (middleware.prefixDefault) {
|
|
663
|
-
next(`/${defaultLocale}${getPathWithoutLocale(to.path)}`);
|
|
664
|
-
} else {
|
|
665
|
-
next(getPathWithoutLocale(to.path));
|
|
666
|
-
}
|
|
667
|
-
}
|
|
668
|
+
// Verwende die in den Routen-Meta definierten Sprache wieder
|
|
669
|
+
client.setLocale(metaLocale);
|
|
670
|
+
next();
|
|
668
671
|
});
|
|
669
672
|
```
|
|
670
673
|
|
|
@@ -802,7 +805,7 @@ watch(
|
|
|
802
805
|
Tipp: Für eine bessere SEO und Barrierefreiheit verwenden Sie Tags wie `<a href="/fr/home" hreflang="fr">`, um auf lokalisierte Seiten zu verlinken, wie in Schritt 10 gezeigt. Dies ermöglicht Suchmaschinen, sprachspezifische URLs korrekt zu entdecken und zu indexieren. Um das SPA-Verhalten beizubehalten, können Sie die Standardnavigation mit @click.prevent verhindern, die Sprache mit useLocale ändern und programmgesteuert mit Vue Router navigieren.
|
|
803
806
|
|
|
804
807
|
```html
|
|
805
|
-
<ol
|
|
808
|
+
<ol>
|
|
806
809
|
<li>
|
|
807
810
|
<a
|
|
808
811
|
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: 7.2.3
|
|
22
25
|
date: 2025-11-18
|
|
23
26
|
changes: Add step 13: Adapt Nitro
|
|
@@ -56,6 +59,14 @@ With Intlayer, you can:
|
|
|
56
59
|
|
|
57
60
|
## Step-by-Step Guide to Set Up Intlayer in a Tanstack Start Application
|
|
58
61
|
|
|
62
|
+
<Tab defaultTab="video">
|
|
63
|
+
<TabItem label="Video" value="video">
|
|
64
|
+
|
|
65
|
+
<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&origin=http://intlayer.org&controls=0&rel=1"/>
|
|
66
|
+
|
|
67
|
+
</TabItem>
|
|
68
|
+
<TabItem label="Code" value="code">
|
|
69
|
+
|
|
59
70
|
<iframe
|
|
60
71
|
src="https://stackblitz.com/github/aymericzip/intlayer-tanstack-start-template?embed=1&ctl=1&file=intlayer.config.ts"
|
|
61
72
|
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,6 +75,9 @@ With Intlayer, you can:
|
|
|
64
75
|
loading="lazy"
|
|
65
76
|
/>
|
|
66
77
|
|
|
78
|
+
</TabItem>
|
|
79
|
+
</Tab>
|
|
80
|
+
|
|
67
81
|
See [Application Template](https://github.com/aymericzip/intlayer-tanstack-start-template) on GitHub.
|
|
68
82
|
|
|
69
83
|
### Step 1: Create Project
|
|
@@ -559,7 +573,55 @@ export const Route = createFileRoute("/{-$locale}/")({
|
|
|
559
573
|
|
|
560
574
|
---
|
|
561
575
|
|
|
562
|
-
### Step 13:
|
|
576
|
+
### Step 13: Retrieve the locale in your server actions (Optional)
|
|
577
|
+
|
|
578
|
+
You may want to access the current locale from inside your server actions or API endpoints.
|
|
579
|
+
You can do this using the `getLocale` helper from `intlayer`.
|
|
580
|
+
|
|
581
|
+
Here's an example using TanStack Start's server functions:
|
|
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
|
+
// Get the cookie from the request (default: 'INTLAYER_LOCALE')
|
|
594
|
+
getCookie: (name) => {
|
|
595
|
+
const cookieString = getRequestHeader("cookie");
|
|
596
|
+
|
|
597
|
+
return getCookie(name, cookieString);
|
|
598
|
+
},
|
|
599
|
+
// Get the header from the request (default: 'x-intlayer-locale')
|
|
600
|
+
getHeader: (name) => getRequestHeader(name),
|
|
601
|
+
// Fallback using Accept-Language negotiation
|
|
602
|
+
getAllHeaders: async () => {
|
|
603
|
+
const headers = getRequestHeaders();
|
|
604
|
+
const result: Record<string, string> = {};
|
|
605
|
+
|
|
606
|
+
// Convert the TypedHeaders into a plain Record<string, string>
|
|
607
|
+
for (const [key, value] of headers.entries()) {
|
|
608
|
+
result[key] = value;
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
return result;
|
|
612
|
+
},
|
|
613
|
+
});
|
|
614
|
+
|
|
615
|
+
// Retrieve some content using getIntlayer()
|
|
616
|
+
const content = getIntlayer("app", locale);
|
|
617
|
+
|
|
618
|
+
return { locale, content };
|
|
619
|
+
});
|
|
620
|
+
```
|
|
621
|
+
|
|
622
|
+
---
|
|
623
|
+
|
|
624
|
+
### Step 14: Configure TypeScript (Optional)
|
|
563
625
|
|
|
564
626
|
Intlayer uses module augmentation to get benefits of TypeScript and make your codebase stronger.
|
|
565
627
|
|
|
@@ -42,6 +42,14 @@ With Intlayer, you can:
|
|
|
42
42
|
|
|
43
43
|
## Step-by-Step Guide to Set Up Intlayer in a Vite and Vue Application
|
|
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="Code" 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"
|
|
@@ -50,6 +58,9 @@ With Intlayer, you can:
|
|
|
50
58
|
loading="lazy"
|
|
51
59
|
/>
|
|
52
60
|
|
|
61
|
+
</TabItem>
|
|
62
|
+
</Tab>
|
|
63
|
+
|
|
53
64
|
See [Application Template](https://github.com/aymericzip/intlayer-vite-vue-template) on GitHub.
|
|
54
65
|
|
|
55
66
|
### Step 1: Install Dependencies
|
|
@@ -546,53 +557,47 @@ Example:
|
|
|
546
557
|
First, install Vue Router:
|
|
547
558
|
|
|
548
559
|
```bash packageManager="npm"
|
|
549
|
-
npm install
|
|
560
|
+
npm install vue-router
|
|
550
561
|
```
|
|
551
562
|
|
|
552
563
|
```bash packageManager="pnpm"
|
|
553
|
-
pnpm add
|
|
564
|
+
pnpm add vue-router
|
|
554
565
|
```
|
|
555
566
|
|
|
556
567
|
```bash packageManager="yarn"
|
|
557
|
-
yarn add
|
|
568
|
+
yarn add vue-router
|
|
558
569
|
```
|
|
559
570
|
|
|
560
571
|
Then, create a router configuration that handles locale-based routing:
|
|
561
572
|
|
|
562
573
|
```js fileName="src/router/index.ts"
|
|
563
574
|
import {
|
|
564
|
-
configuration,
|
|
565
|
-
getPathWithoutLocale,
|
|
566
575
|
localeFlatMap,
|
|
567
|
-
type
|
|
576
|
+
type Locale,
|
|
568
577
|
} from 'intlayer';
|
|
569
578
|
import { createIntlayerClient } from 'vue-intlayer';
|
|
570
579
|
import { createRouter, createWebHistory } from 'vue-router';
|
|
571
580
|
import HomeView from './views/home/HomeView.vue';
|
|
572
581
|
import RootView from './views/root/Root.vue';
|
|
573
582
|
|
|
574
|
-
// Get internationalization configuration
|
|
575
|
-
const { internationalization, middleware } = configuration;
|
|
576
|
-
const { defaultLocale } = internationalization;
|
|
577
|
-
|
|
578
583
|
/**
|
|
579
584
|
* Declare the routes with locale-specific paths and metadata.
|
|
580
585
|
*/
|
|
581
|
-
const routes = localeFlatMap((
|
|
586
|
+
const routes = localeFlatMap(({ urlPrefix, locale }) => [
|
|
582
587
|
{
|
|
583
|
-
path: `${
|
|
584
|
-
name: `Root-${
|
|
588
|
+
path: `${urlPrefix}/`,
|
|
589
|
+
name: `Root-${locale}`,
|
|
585
590
|
component: RootView,
|
|
586
591
|
meta: {
|
|
587
|
-
locale
|
|
592
|
+
locale,
|
|
588
593
|
},
|
|
589
594
|
},
|
|
590
595
|
{
|
|
591
|
-
path: `${
|
|
592
|
-
name: `Home-${
|
|
596
|
+
path: `${urlPrefix}/home`,
|
|
597
|
+
name: `Home-${locale}`,
|
|
593
598
|
component: HomeView,
|
|
594
599
|
meta: {
|
|
595
|
-
locale
|
|
600
|
+
locale,
|
|
596
601
|
},
|
|
597
602
|
},
|
|
598
603
|
]);
|
|
@@ -607,23 +612,11 @@ export const router = createRouter({
|
|
|
607
612
|
router.beforeEach((to, _from, next) => {
|
|
608
613
|
const client = createIntlayerClient();
|
|
609
614
|
|
|
610
|
-
const metaLocale = to.meta.locale as
|
|
615
|
+
const metaLocale = to.meta.locale as Locale;
|
|
611
616
|
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
next();
|
|
616
|
-
} else {
|
|
617
|
-
// Fallback: no locale in meta, possibly unmatched route
|
|
618
|
-
// Optional: handle 404 or redirect to default locale
|
|
619
|
-
client.setLocale(defaultLocale);
|
|
620
|
-
|
|
621
|
-
if (middleware.prefixDefault) {
|
|
622
|
-
next(`/${defaultLocale}${getPathWithoutLocale(to.path)}`);
|
|
623
|
-
} else {
|
|
624
|
-
next(getPathWithoutLocale(to.path));
|
|
625
|
-
}
|
|
626
|
-
}
|
|
617
|
+
// Reuse the locale defined in the route meta
|
|
618
|
+
client.setLocale(metaLocale);
|
|
619
|
+
next();
|
|
627
620
|
});
|
|
628
621
|
```
|
|
629
622
|
|
|
@@ -755,7 +748,7 @@ watch(
|
|
|
755
748
|
Tip: For better SEO and accessibility, use tags as `<a href="/fr/home" hreflang="fr">` to link to localized pages, as shown in Step 10. This allows search engines to discover and index language-specific URLs properly. To preserve SPA behavior, you can prevent the default navigation with @click.prevent, change the locale using useLocale, and programmatically navigate using Vue Router.
|
|
756
749
|
|
|
757
750
|
```html
|
|
758
|
-
<ol
|
|
751
|
+
<ol>
|
|
759
752
|
<li>
|
|
760
753
|
<a
|
|
761
754
|
hreflang="x-default"
|