@intlayer/docs 7.3.5 → 7.3.7
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/en/compiler_vs_declarative_i18n.md +2 -0
- package/docs/ar/intlayer_with_tanstack.md +39 -40
- package/docs/de/intlayer_with_tanstack.md +39 -40
- package/docs/en/intlayer_with_tanstack.md +43 -43
- package/docs/en-GB/intlayer_with_tanstack.md +39 -40
- package/docs/es/intlayer_with_tanstack.md +39 -40
- package/docs/fr/intlayer_with_tanstack.md +39 -40
- package/docs/hi/intlayer_with_tanstack.md +39 -40
- package/docs/id/intlayer_with_tanstack.md +39 -40
- package/docs/it/intlayer_with_tanstack.md +39 -40
- package/docs/ja/intlayer_with_tanstack.md +39 -40
- package/docs/ko/intlayer_with_tanstack.md +39 -40
- package/docs/pl/intlayer_with_tanstack.md +39 -40
- package/docs/pt/intlayer_with_tanstack.md +39 -40
- package/docs/ru/intlayer_with_tanstack.md +39 -40
- package/docs/tr/intlayer_with_tanstack.md +40 -41
- package/docs/vi/intlayer_with_tanstack.md +39 -40
- package/docs/zh/intlayer_with_tanstack.md +42 -43
- package/package.json +6 -6
|
@@ -177,6 +177,8 @@ Compilers often hash the text (e.g., `"Hello World"` -> `x7f2a`). Your translati
|
|
|
177
177
|
|
|
178
178
|
By choosing a compiler-based approach, you lock yourself into the underlying platform. For example, certain compilers are not available for all bundlers (such as Vite, Turbopack, or Metro). This can make future migrations difficult, and you may need to adopt multiple solutions to cover all your applications.
|
|
179
179
|
|
|
180
|
+
But more broadly, even without the constraints of a specific bundler, every i18n solution introduces its own conventions for declaring and managing content. As a result, any i18n approach inherently creates some level of vendor lock-in to that particular solution. In addition, several major i18n libraries are sponsored, funded, or backed by companies operating in the localization industry.
|
|
181
|
+
|
|
180
182
|
## The Other Side: Risks of the Declarative Approach
|
|
181
183
|
|
|
182
184
|
To be fair, the traditional declarative way isn't perfect either. It has its own set of "footguns."
|
|
@@ -132,7 +132,7 @@ export default config;
|
|
|
132
132
|
#### التخطيط الجذري
|
|
133
133
|
|
|
134
134
|
```tsx fileName="src/routes/{-$locale}/route.tsx"
|
|
135
|
-
import { createFileRoute,
|
|
135
|
+
import { createFileRoute, Outlet } from "@tanstack/react-router";
|
|
136
136
|
import { IntlayerProvider, useLocale } from "react-intlayer";
|
|
137
137
|
|
|
138
138
|
import { useI18nHTMLAttributes } from "@/hooks/useI18nHTMLAttributes";
|
|
@@ -389,16 +389,16 @@ import {
|
|
|
389
389
|
getLocaleName,
|
|
390
390
|
getPathWithoutLocale,
|
|
391
391
|
getPrefix,
|
|
392
|
+
Locales,
|
|
392
393
|
} from "intlayer";
|
|
393
|
-
import {
|
|
394
|
+
import { useLocale } from "react-intlayer";
|
|
394
395
|
|
|
395
396
|
import { LocalizedLink, To } from "./localized-link";
|
|
396
397
|
|
|
397
398
|
export const LocaleSwitcher: FC = () => {
|
|
398
|
-
const { localeSwitcherLabel } = useIntlayer("locale-switcher");
|
|
399
399
|
const { pathname } = useLocation();
|
|
400
400
|
|
|
401
|
-
const { availableLocales, locale } = useLocale();
|
|
401
|
+
const { availableLocales, locale, setLocale } = useLocale();
|
|
402
402
|
|
|
403
403
|
const pathWithoutLocale = getPathWithoutLocale(pathname);
|
|
404
404
|
|
|
@@ -408,25 +408,24 @@ export const LocaleSwitcher: FC = () => {
|
|
|
408
408
|
<li key={localeEl}>
|
|
409
409
|
<LocalizedLink
|
|
410
410
|
aria-current={localeEl === locale ? "page" : undefined}
|
|
411
|
-
|
|
412
|
-
onClick={() => setLocaleInStorage(localeEl)}
|
|
411
|
+
onClick={() => setLocale(localeEl)}
|
|
413
412
|
params={{ locale: getPrefix(localeEl).localePrefix }}
|
|
414
413
|
>
|
|
415
414
|
<span>
|
|
416
415
|
{/* اللغة المحلية - مثل FR */}
|
|
417
|
-
{
|
|
416
|
+
{localeEl}
|
|
418
417
|
</span>
|
|
419
418
|
<span>
|
|
420
419
|
{/* اللغة بلغتها المحلية - مثل Français */}
|
|
421
|
-
{getLocaleName(
|
|
420
|
+
{getLocaleName(localeEl, locale)}
|
|
422
421
|
</span>
|
|
423
|
-
<span dir={getHTMLTextDir(
|
|
422
|
+
<span dir={getHTMLTextDir(localeEl)} lang={localeEl}>
|
|
424
423
|
{/* اللغة في اللغة الحالية - مثل Francés مع تعيين اللغة الحالية إلى Locales.SPANISH */}
|
|
425
|
-
{getLocaleName(
|
|
424
|
+
{getLocaleName(localeEl)}
|
|
426
425
|
</span>
|
|
427
426
|
<span dir="ltr" lang={Locales.ENGLISH}>
|
|
428
427
|
{/* اللغة بالإنجليزية - مثل French */}
|
|
429
|
-
{getLocaleName(
|
|
428
|
+
{getLocaleName(localeEl, Locales.ENGLISH)}
|
|
430
429
|
</span>
|
|
431
430
|
</LocalizedLink>
|
|
432
431
|
</li>
|
|
@@ -461,7 +460,7 @@ export const useI18nHTMLAttributes = () => {
|
|
|
461
460
|
ثم استخدمه في مكون الجذر الخاص بك:
|
|
462
461
|
|
|
463
462
|
```tsx fileName="src/routes/{-$locale}/index.tsx"
|
|
464
|
-
import { createFileRoute,
|
|
463
|
+
import { createFileRoute, Outlet } from "@tanstack/react-router";
|
|
465
464
|
import { IntlayerProvider, useLocale } from "react-intlayer";
|
|
466
465
|
|
|
467
466
|
import { useI18nHTMLAttributes } from "@/hooks/useI18nHTMLAttributes"; // استيراد الخطاف
|
|
@@ -501,18 +500,44 @@ import tsconfigPaths from "vite-tsconfig-paths";
|
|
|
501
500
|
|
|
502
501
|
export default defineConfig({
|
|
503
502
|
plugins: [
|
|
503
|
+
intlayerProxy(), // يجب وضع الوكيل قبل الخادم إذا كنت تستخدم Nitro
|
|
504
504
|
tailwindcss(),
|
|
505
505
|
reactRouter(),
|
|
506
506
|
tsconfigPaths(),
|
|
507
507
|
intlayer(),
|
|
508
|
-
intlayerProxy(),
|
|
509
508
|
],
|
|
510
509
|
});
|
|
511
510
|
```
|
|
512
511
|
|
|
513
512
|
---
|
|
514
513
|
|
|
515
|
-
### الخطوة 12:
|
|
514
|
+
### الخطوة 12: تدويل البيانات الوصفية (اختياري)
|
|
515
|
+
|
|
516
|
+
يمكنك أيضًا استخدام الخطاف `getIntlayer` للوصول إلى قواميس المحتوى الخاصة بك في جميع أنحاء التطبيق:
|
|
517
|
+
|
|
518
|
+
```tsx fileName="src/routes/{-$locale}/index.tsx"
|
|
519
|
+
import { createFileRoute } from "@tanstack/react-router";
|
|
520
|
+
import { getIntlayer } from "intlayer";
|
|
521
|
+
|
|
522
|
+
export const Route = createFileRoute("/{-$locale}/")({
|
|
523
|
+
component: RouteComponent,
|
|
524
|
+
head: ({ params }) => {
|
|
525
|
+
const { locale } = params;
|
|
526
|
+
const metaContent = getIntlayer("page-metadata", locale);
|
|
527
|
+
|
|
528
|
+
return {
|
|
529
|
+
meta: [
|
|
530
|
+
{ title: metaContent.title },
|
|
531
|
+
{ content: metaContent.description, name: "description" },
|
|
532
|
+
],
|
|
533
|
+
};
|
|
534
|
+
},
|
|
535
|
+
});
|
|
536
|
+
```
|
|
537
|
+
|
|
538
|
+
---
|
|
539
|
+
|
|
540
|
+
### الخطوة 13: تكوين TypeScript (اختياري)
|
|
516
541
|
|
|
517
542
|
يستخدم Intlayer توسيع الوحدات (module augmentation) للاستفادة من TypeScript وجعل قاعدة الشيفرة الخاصة بك أقوى.
|
|
518
543
|
|
|
@@ -530,32 +555,6 @@ export default defineConfig({
|
|
|
530
555
|
|
|
531
556
|
---
|
|
532
557
|
|
|
533
|
-
### الخطوة 13: تكييف Nitro (اختياري)
|
|
534
|
-
|
|
535
|
-
إذا كنت تستخدم Nitro لإخراج الإنتاج الخاص بك، فلن يقوم nitro بتضمين دليل `.intlayer` في دليل الإخراج. تحتاج إلى نسخه يدويًا.
|
|
536
|
-
|
|
537
|
-
مثال باستخدام سكريبت البناء:
|
|
538
|
-
|
|
539
|
-
```json5 fileName="package.json"
|
|
540
|
-
{
|
|
541
|
-
"scripts": {
|
|
542
|
-
"dev": "vite dev --port 3000",
|
|
543
|
-
"build": "vite build && cpr .intlayer .output/.intlayer", // نسخ مجلد .intlayer
|
|
544
|
-
"serve": "vite preview",
|
|
545
|
-
},
|
|
546
|
-
}
|
|
547
|
-
```
|
|
548
|
-
|
|
549
|
-
> يُستخدم cpr لتكييف الأمر لجعله يعمل على Windows.
|
|
550
|
-
> ستحتاج إلى تثبيت أداة `cpr` لاستخدام هذا الأمر.
|
|
551
|
-
>
|
|
552
|
-
> - `npm install --save-dev cpr`
|
|
553
|
-
> - `yarn add --dev cpr`
|
|
554
|
-
> - `pnpm add --save-dev cpr`
|
|
555
|
-
> - `bun add --save-dev cpr`
|
|
556
|
-
|
|
557
|
-
---
|
|
558
|
-
|
|
559
558
|
### تكوين Git
|
|
560
559
|
|
|
561
560
|
يوصى بتجاهل الملفات التي تم إنشاؤها بواسطة Intlayer. هذا يسمح لك بتجنب الالتزام بها في مستودع Git الخاص بك.
|
|
@@ -136,7 +136,7 @@ Richten Sie Ihr Root-Layout und sprachspezifische Layouts ein:
|
|
|
136
136
|
#### Root-Layout
|
|
137
137
|
|
|
138
138
|
```tsx fileName="src/routes/{-$locale}/route.tsx"
|
|
139
|
-
import { createFileRoute,
|
|
139
|
+
import { createFileRoute, Outlet } from "@tanstack/react-router";
|
|
140
140
|
import { IntlayerProvider, useLocale } from "react-intlayer";
|
|
141
141
|
|
|
142
142
|
import { useI18nHTMLAttributes } from "@/hooks/useI18nHTMLAttributes";
|
|
@@ -393,16 +393,16 @@ import {
|
|
|
393
393
|
getLocaleName,
|
|
394
394
|
getPathWithoutLocale,
|
|
395
395
|
getPrefix,
|
|
396
|
+
Locales,
|
|
396
397
|
} from "intlayer";
|
|
397
|
-
import {
|
|
398
|
+
import { useLocale } from "react-intlayer";
|
|
398
399
|
|
|
399
400
|
import { LocalizedLink, To } from "./localized-link";
|
|
400
401
|
|
|
401
402
|
export const LocaleSwitcher: FC = () => {
|
|
402
|
-
const { localeSwitcherLabel } = useIntlayer("locale-switcher");
|
|
403
403
|
const { pathname } = useLocation();
|
|
404
404
|
|
|
405
|
-
const { availableLocales, locale } = useLocale();
|
|
405
|
+
const { availableLocales, locale, setLocale } = useLocale();
|
|
406
406
|
|
|
407
407
|
const pathWithoutLocale = getPathWithoutLocale(pathname);
|
|
408
408
|
|
|
@@ -412,25 +412,24 @@ export const LocaleSwitcher: FC = () => {
|
|
|
412
412
|
<li key={localeEl}>
|
|
413
413
|
<LocalizedLink
|
|
414
414
|
aria-current={localeEl === locale ? "page" : undefined}
|
|
415
|
-
|
|
416
|
-
onClick={() => setLocaleInStorage(localeEl)}
|
|
415
|
+
onClick={() => setLocale(localeEl)}
|
|
417
416
|
params={{ locale: getPrefix(localeEl).localePrefix }}
|
|
418
417
|
>
|
|
419
418
|
<span>
|
|
420
419
|
{/* Gebietsschema - z.B. FR */}
|
|
421
|
-
{
|
|
420
|
+
{localeEl}
|
|
422
421
|
</span>
|
|
423
422
|
<span>
|
|
424
423
|
{/* Sprache in ihrem eigenen Gebietsschema - z.B. Français */}
|
|
425
|
-
{getLocaleName(
|
|
424
|
+
{getLocaleName(localeEl, locale)}
|
|
426
425
|
</span>
|
|
427
|
-
<span dir={getHTMLTextDir(
|
|
426
|
+
<span dir={getHTMLTextDir(localeEl)} lang={localeEl}>
|
|
428
427
|
{/* Sprache im aktuellen Gebietsschema - z.B. Francés mit aktuellem Gebietsschema auf Locales.SPANISH gesetzt */}
|
|
429
|
-
{getLocaleName(
|
|
428
|
+
{getLocaleName(localeEl)}
|
|
430
429
|
</span>
|
|
431
430
|
<span dir="ltr" lang={Locales.ENGLISH}>
|
|
432
431
|
{/* Sprache auf Englisch - z.B. French */}
|
|
433
|
-
{getLocaleName(
|
|
432
|
+
{getLocaleName(localeEl, Locales.ENGLISH)}
|
|
434
433
|
</span>
|
|
435
434
|
</LocalizedLink>
|
|
436
435
|
</li>
|
|
@@ -465,7 +464,7 @@ export const useI18nHTMLAttributes = () => {
|
|
|
465
464
|
Dann verwende ihn in deiner Root-Komponente:
|
|
466
465
|
|
|
467
466
|
```tsx fileName="src/routes/{-$locale}/index.tsx"
|
|
468
|
-
import { createFileRoute,
|
|
467
|
+
import { createFileRoute, Outlet } from "@tanstack/react-router";
|
|
469
468
|
import { IntlayerProvider, useLocale } from "react-intlayer";
|
|
470
469
|
|
|
471
470
|
import { useI18nHTMLAttributes } from "@/hooks/useI18nHTMLAttributes"; // importiere den Hook
|
|
@@ -505,18 +504,44 @@ import tsconfigPaths from "vite-tsconfig-paths";
|
|
|
505
504
|
|
|
506
505
|
export default defineConfig({
|
|
507
506
|
plugins: [
|
|
507
|
+
intlayerProxy(), // Der Proxy sollte vor dem Server platziert werden, wenn Sie Nitro verwenden
|
|
508
508
|
tailwindcss(),
|
|
509
509
|
reactRouter(),
|
|
510
510
|
tsconfigPaths(),
|
|
511
511
|
intlayer(),
|
|
512
|
-
intlayerProxy(),
|
|
513
512
|
],
|
|
514
513
|
});
|
|
515
514
|
```
|
|
516
515
|
|
|
517
516
|
---
|
|
518
517
|
|
|
519
|
-
### Schritt 12:
|
|
518
|
+
### Schritt 12: Metadaten internationalisieren (optional)
|
|
519
|
+
|
|
520
|
+
Sie können auch den `getIntlayer` Hook verwenden, um in Ihrer gesamten Anwendung auf Ihre Inhaltswörterbücher zuzugreifen:
|
|
521
|
+
|
|
522
|
+
```tsx fileName="src/routes/{-$locale}/index.tsx"
|
|
523
|
+
import { createFileRoute } from "@tanstack/react-router";
|
|
524
|
+
import { getIntlayer } from "intlayer";
|
|
525
|
+
|
|
526
|
+
export const Route = createFileRoute("/{-$locale}/")({
|
|
527
|
+
component: RouteComponent,
|
|
528
|
+
head: ({ params }) => {
|
|
529
|
+
const { locale } = params;
|
|
530
|
+
const metaContent = getIntlayer("page-metadata", locale);
|
|
531
|
+
|
|
532
|
+
return {
|
|
533
|
+
meta: [
|
|
534
|
+
{ title: metaContent.title },
|
|
535
|
+
{ content: metaContent.description, name: "description" },
|
|
536
|
+
],
|
|
537
|
+
};
|
|
538
|
+
},
|
|
539
|
+
});
|
|
540
|
+
```
|
|
541
|
+
|
|
542
|
+
---
|
|
543
|
+
|
|
544
|
+
### Schritt 13: TypeScript konfigurieren (optional)
|
|
520
545
|
|
|
521
546
|
Intlayer verwendet Module Augmentation, um die Vorteile von TypeScript zu nutzen und Ihren Code robuster zu machen.
|
|
522
547
|
|
|
@@ -534,32 +559,6 @@ Stellen Sie sicher, dass Ihre TypeScript-Konfiguration die automatisch generiert
|
|
|
534
559
|
|
|
535
560
|
---
|
|
536
561
|
|
|
537
|
-
### Schritt 13: Nitro anpassen (Optional)
|
|
538
|
-
|
|
539
|
-
Wenn Sie Nitro für Ihre Produktionsausgabe verwenden, wird nitro das Verzeichnis `.intlayer` nicht in das Ausgabeverzeichnis einschließen. Sie müssen es manuell kopieren.
|
|
540
|
-
|
|
541
|
-
Beispiel mit Build-Skript:
|
|
542
|
-
|
|
543
|
-
```json5 fileName="package.json"
|
|
544
|
-
{
|
|
545
|
-
"scripts": {
|
|
546
|
-
"dev": "vite dev --port 3000",
|
|
547
|
-
"build": "vite build && cpr .intlayer .output/.intlayer", // .intlayer-Ordner kopieren
|
|
548
|
-
"serve": "vite preview",
|
|
549
|
-
},
|
|
550
|
-
}
|
|
551
|
-
```
|
|
552
|
-
|
|
553
|
-
> cpr wird verwendet, um den Befehl anzupassen, damit er unter Windows funktioniert.
|
|
554
|
-
> Sie müssen das `cpr`-Dienstprogramm installieren, um diesen Befehl zu verwenden.
|
|
555
|
-
>
|
|
556
|
-
> - `npm install --save-dev cpr`
|
|
557
|
-
> - `yarn add --dev cpr`
|
|
558
|
-
> - `pnpm add --save-dev cpr`
|
|
559
|
-
> - `bun add --save-dev cpr`
|
|
560
|
-
|
|
561
|
-
---
|
|
562
|
-
|
|
563
562
|
### Git-Konfiguration
|
|
564
563
|
|
|
565
564
|
Es wird empfohlen, die von Intlayer generierten Dateien zu ignorieren. So vermeiden Sie, diese versehentlich in Ihr Git-Repository zu committen.
|
|
@@ -151,7 +151,7 @@ Set up your root layout and locale-specific layouts:
|
|
|
151
151
|
#### Root Layout
|
|
152
152
|
|
|
153
153
|
```tsx fileName="src/routes/{-$locale}/route.tsx"
|
|
154
|
-
import { createFileRoute,
|
|
154
|
+
import { createFileRoute, Outlet } from "@tanstack/react-router";
|
|
155
155
|
import { IntlayerProvider, useLocale } from "react-intlayer";
|
|
156
156
|
|
|
157
157
|
import { useI18nHTMLAttributes } from "@/hooks/useI18nHTMLAttributes";
|
|
@@ -408,17 +408,17 @@ import {
|
|
|
408
408
|
getLocaleName,
|
|
409
409
|
getPathWithoutLocale,
|
|
410
410
|
getPrefix,
|
|
411
|
+
Locales,
|
|
411
412
|
} from "intlayer";
|
|
412
413
|
import type { FC } from "react";
|
|
413
|
-
import {
|
|
414
|
+
import { useLocale } from "react-intlayer";
|
|
414
415
|
|
|
415
416
|
import { LocalizedLink, type To } from "./localized-link";
|
|
416
417
|
|
|
417
418
|
export const LocaleSwitcher: FC = () => {
|
|
418
|
-
const { localeSwitcherLabel } = useIntlayer("locale-switcher");
|
|
419
419
|
const { pathname } = useLocation();
|
|
420
420
|
|
|
421
|
-
const { availableLocales, locale } = useLocale();
|
|
421
|
+
const { availableLocales, locale, setLocale } = useLocale();
|
|
422
422
|
|
|
423
423
|
const pathWithoutLocale = getPathWithoutLocale(pathname);
|
|
424
424
|
|
|
@@ -428,26 +428,25 @@ export const LocaleSwitcher: FC = () => {
|
|
|
428
428
|
<li key={localeEl}>
|
|
429
429
|
<LocalizedLink
|
|
430
430
|
aria-current={localeEl === locale ? "page" : undefined}
|
|
431
|
-
|
|
432
|
-
onClick={() => setLocaleInStorage(localeEl)}
|
|
431
|
+
onClick={() => setLocale(localeEl)}
|
|
433
432
|
params={{ locale: getPrefix(localeEl).localePrefix }}
|
|
434
433
|
to={pathWithoutLocale as To}
|
|
435
434
|
>
|
|
436
435
|
<span>
|
|
437
436
|
{/* Locale - e.g. FR */}
|
|
438
|
-
{
|
|
437
|
+
{localeEl}
|
|
439
438
|
</span>
|
|
440
439
|
<span>
|
|
441
440
|
{/* Language in its own Locale - e.g. Français */}
|
|
442
|
-
{getLocaleName(
|
|
441
|
+
{getLocaleName(localeEl, locale)}
|
|
443
442
|
</span>
|
|
444
|
-
<span dir={getHTMLTextDir(
|
|
443
|
+
<span dir={getHTMLTextDir(localeEl)} lang={localeEl}>
|
|
445
444
|
{/* Language in current Locale - e.g. Francés with current locale set to Locales.SPANISH */}
|
|
446
|
-
{getLocaleName(
|
|
445
|
+
{getLocaleName(localeEl)}
|
|
447
446
|
</span>
|
|
448
447
|
<span dir="ltr" lang={Locales.ENGLISH}>
|
|
449
448
|
{/* Language in English - e.g. French */}
|
|
450
|
-
{getLocaleName(
|
|
449
|
+
{getLocaleName(localeEl, Locales.ENGLISH)}
|
|
451
450
|
</span>
|
|
452
451
|
</LocalizedLink>
|
|
453
452
|
</li>
|
|
@@ -482,8 +481,8 @@ export const useI18nHTMLAttributes = () => {
|
|
|
482
481
|
Then use it in your root component:
|
|
483
482
|
|
|
484
483
|
```tsx fileName="src/routes/{-$locale}/index.tsx"
|
|
485
|
-
import { createFileRoute,
|
|
486
|
-
import { IntlayerProvider
|
|
484
|
+
import { createFileRoute, Outlet } from "@tanstack/react-router";
|
|
485
|
+
import { IntlayerProvider } from "react-intlayer";
|
|
487
486
|
|
|
488
487
|
import { useI18nHTMLAttributes } from "@/hooks/useI18nHTMLAttributes"; // import the hook
|
|
489
488
|
|
|
@@ -494,11 +493,12 @@ export const Route = createFileRoute("/{-$locale}")({
|
|
|
494
493
|
function LayoutComponent() {
|
|
495
494
|
useI18nHTMLAttributes(); // add this line
|
|
496
495
|
|
|
497
|
-
const { defaultLocale } = useLocale();
|
|
498
496
|
const { locale } = Route.useParams();
|
|
499
497
|
|
|
500
498
|
return (
|
|
501
|
-
<IntlayerProvider
|
|
499
|
+
<IntlayerProvider
|
|
500
|
+
locale={locale} // If no locale included as a parameter, the default locale will be used
|
|
501
|
+
>
|
|
502
502
|
<Outlet />
|
|
503
503
|
</IntlayerProvider>
|
|
504
504
|
);
|
|
@@ -522,18 +522,44 @@ import tsconfigPaths from "vite-tsconfig-paths";
|
|
|
522
522
|
|
|
523
523
|
export default defineConfig({
|
|
524
524
|
plugins: [
|
|
525
|
+
intlayerProxy(), // The proxy should be placed before server if you use Nitro
|
|
525
526
|
tailwindcss(),
|
|
526
527
|
reactRouter(),
|
|
527
528
|
tsconfigPaths(),
|
|
528
529
|
intlayer(),
|
|
529
|
-
intlayerProxy(),
|
|
530
530
|
],
|
|
531
531
|
});
|
|
532
532
|
```
|
|
533
533
|
|
|
534
534
|
---
|
|
535
535
|
|
|
536
|
-
### Step 12:
|
|
536
|
+
### Step 12: Internationalize your Metadata (Optional)
|
|
537
|
+
|
|
538
|
+
You can also use the `getIntlayer` hook to access your content dictionaries throughout your application:
|
|
539
|
+
|
|
540
|
+
```tsx fileName="src/routes/{-$locale}/index.tsx"
|
|
541
|
+
import { createFileRoute } from "@tanstack/react-router";
|
|
542
|
+
import { getIntlayer } from "intlayer";
|
|
543
|
+
|
|
544
|
+
export const Route = createFileRoute("/{-$locale}/")({
|
|
545
|
+
component: RouteComponent,
|
|
546
|
+
head: ({ params }) => {
|
|
547
|
+
const { locale } = params;
|
|
548
|
+
const metaContent = getIntlayer("page-metadata", locale);
|
|
549
|
+
|
|
550
|
+
return {
|
|
551
|
+
meta: [
|
|
552
|
+
{ title: metaContent.title },
|
|
553
|
+
{ content: metaContent.description, name: "description" },
|
|
554
|
+
],
|
|
555
|
+
};
|
|
556
|
+
},
|
|
557
|
+
});
|
|
558
|
+
```
|
|
559
|
+
|
|
560
|
+
---
|
|
561
|
+
|
|
562
|
+
### Step 13: Configure TypeScript (Optional)
|
|
537
563
|
|
|
538
564
|
Intlayer uses module augmentation to get benefits of TypeScript and make your codebase stronger.
|
|
539
565
|
|
|
@@ -551,32 +577,6 @@ Ensure your TypeScript configuration includes the autogenerated types:
|
|
|
551
577
|
|
|
552
578
|
---
|
|
553
579
|
|
|
554
|
-
### Step 13: Adapt Nitro (Optional)
|
|
555
|
-
|
|
556
|
-
If you are using Nitro for your production output, nitro will not include the `.intlayer` directory in the output directory. You need to copy it manually.
|
|
557
|
-
|
|
558
|
-
Example using build script:
|
|
559
|
-
|
|
560
|
-
```json5 fileName="package.json"
|
|
561
|
-
{
|
|
562
|
-
"scripts": {
|
|
563
|
-
"dev": "vite dev --port 3000",
|
|
564
|
-
"build": "vite build && cpr .intlayer .output/.intlayer", // Copy .intlayer folder
|
|
565
|
-
"serve": "vite preview",
|
|
566
|
-
},
|
|
567
|
-
}
|
|
568
|
-
```
|
|
569
|
-
|
|
570
|
-
> cpr is used to adapt the command to make it work on Windows.
|
|
571
|
-
> You will have to install the `cpr` utility to use this command.
|
|
572
|
-
>
|
|
573
|
-
> - `npm install --save-dev cpr`
|
|
574
|
-
> - `yarn add --dev cpr`
|
|
575
|
-
> - `pnpm add --save-dev cpr`
|
|
576
|
-
> - `bun add --save-dev cpr`
|
|
577
|
-
|
|
578
|
-
---
|
|
579
|
-
|
|
580
580
|
### Git Configuration
|
|
581
581
|
|
|
582
582
|
It is recommended to ignore the files generated by Intlayer. This allows you to avoid committing them to your Git repository.
|
|
@@ -135,7 +135,7 @@ Set up your root layout and locale-specific layouts:
|
|
|
135
135
|
#### Root Layout
|
|
136
136
|
|
|
137
137
|
```tsx fileName="src/routes/{-$locale}/route.tsx"
|
|
138
|
-
import { createFileRoute,
|
|
138
|
+
import { createFileRoute, Outlet } from "@tanstack/react-router";
|
|
139
139
|
import { IntlayerProvider, useLocale } from "react-intlayer";
|
|
140
140
|
|
|
141
141
|
import { useI18nHTMLAttributes } from "@/hooks/useI18nHTMLAttributes";
|
|
@@ -392,16 +392,16 @@ import {
|
|
|
392
392
|
getLocaleName,
|
|
393
393
|
getPathWithoutLocale,
|
|
394
394
|
getPrefix,
|
|
395
|
+
Locales,
|
|
395
396
|
} from "intlayer";
|
|
396
|
-
import {
|
|
397
|
+
import { useLocale } from "react-intlayer";
|
|
397
398
|
|
|
398
399
|
import { LocalizedLink, To } from "./localized-link";
|
|
399
400
|
|
|
400
401
|
export const LocaleSwitcher: FC = () => {
|
|
401
|
-
const { localeSwitcherLabel } = useIntlayer("locale-switcher");
|
|
402
402
|
const { pathname } = useLocation();
|
|
403
403
|
|
|
404
|
-
const { availableLocales, locale } = useLocale();
|
|
404
|
+
const { availableLocales, locale, setLocale } = useLocale();
|
|
405
405
|
|
|
406
406
|
const pathWithoutLocale = getPathWithoutLocale(pathname);
|
|
407
407
|
|
|
@@ -411,25 +411,24 @@ export const LocaleSwitcher: FC = () => {
|
|
|
411
411
|
<li key={localeEl}>
|
|
412
412
|
<LocalizedLink
|
|
413
413
|
aria-current={localeEl === locale ? "page" : undefined}
|
|
414
|
-
|
|
415
|
-
onClick={() => setLocaleInStorage(localeEl)}
|
|
414
|
+
onClick={() => setLocale(localeEl)}
|
|
416
415
|
params={{ locale: getPrefix(localeEl).localePrefix }}
|
|
417
416
|
>
|
|
418
417
|
<span>
|
|
419
418
|
{/* Locale - e.g. FR */}
|
|
420
|
-
{
|
|
419
|
+
{localeEl}
|
|
421
420
|
</span>
|
|
422
421
|
<span>
|
|
423
422
|
{/* Language in its own Locale - e.g. Français */}
|
|
424
|
-
{getLocaleName(
|
|
423
|
+
{getLocaleName(localeEl, locale)}
|
|
425
424
|
</span>
|
|
426
|
-
<span dir={getHTMLTextDir(
|
|
425
|
+
<span dir={getHTMLTextDir(localeEl)} lang={localeEl}>
|
|
427
426
|
{/* Language in current Locale - e.g. Francés with current locale set to Locales.SPANISH */}
|
|
428
|
-
{getLocaleName(
|
|
427
|
+
{getLocaleName(localeEl)}
|
|
429
428
|
</span>
|
|
430
429
|
<span dir="ltr" lang={Locales.ENGLISH}>
|
|
431
430
|
{/* Language in English - e.g. French */}
|
|
432
|
-
{getLocaleName(
|
|
431
|
+
{getLocaleName(localeEl, Locales.ENGLISH)}
|
|
433
432
|
</span>
|
|
434
433
|
</LocalizedLink>
|
|
435
434
|
</li>
|
|
@@ -464,7 +463,7 @@ export const useI18nHTMLAttributes = () => {
|
|
|
464
463
|
Then use it in your root component:
|
|
465
464
|
|
|
466
465
|
```tsx fileName="src/routes/{-$locale}/index.tsx"
|
|
467
|
-
import { createFileRoute,
|
|
466
|
+
import { createFileRoute, Outlet } from "@tanstack/react-router";
|
|
468
467
|
import { IntlayerProvider, useLocale } from "react-intlayer";
|
|
469
468
|
|
|
470
469
|
import { useI18nHTMLAttributes } from "@/hooks/useI18nHTMLAttributes"; // import the hook
|
|
@@ -504,18 +503,44 @@ import tsconfigPaths from "vite-tsconfig-paths";
|
|
|
504
503
|
|
|
505
504
|
export default defineConfig({
|
|
506
505
|
plugins: [
|
|
506
|
+
intlayerProxy(), // The proxy should be placed before server if you use Nitro
|
|
507
507
|
tailwindcss(),
|
|
508
508
|
reactRouter(),
|
|
509
509
|
tsconfigPaths(),
|
|
510
510
|
intlayer(),
|
|
511
|
-
intlayerProxy(),
|
|
512
511
|
],
|
|
513
512
|
});
|
|
514
513
|
```
|
|
515
514
|
|
|
516
515
|
---
|
|
517
516
|
|
|
518
|
-
### Step 12:
|
|
517
|
+
### Step 12: Internationalise your Metadata (Optional)
|
|
518
|
+
|
|
519
|
+
You can also use the `getIntlayer` hook to access your content dictionaries throughout your application:
|
|
520
|
+
|
|
521
|
+
```tsx fileName="src/routes/{-$locale}/index.tsx"
|
|
522
|
+
import { createFileRoute } from "@tanstack/react-router";
|
|
523
|
+
import { getIntlayer } from "intlayer";
|
|
524
|
+
|
|
525
|
+
export const Route = createFileRoute("/{-$locale}/")({
|
|
526
|
+
component: RouteComponent,
|
|
527
|
+
head: ({ params }) => {
|
|
528
|
+
const { locale } = params;
|
|
529
|
+
const metaContent = getIntlayer("page-metadata", locale);
|
|
530
|
+
|
|
531
|
+
return {
|
|
532
|
+
meta: [
|
|
533
|
+
{ title: metaContent.title },
|
|
534
|
+
{ content: metaContent.description, name: "description" },
|
|
535
|
+
],
|
|
536
|
+
};
|
|
537
|
+
},
|
|
538
|
+
});
|
|
539
|
+
```
|
|
540
|
+
|
|
541
|
+
---
|
|
542
|
+
|
|
543
|
+
### Step 13: Configure TypeScript (Optional)
|
|
519
544
|
|
|
520
545
|
Intlayer uses module augmentation to benefit from TypeScript and strengthen your codebase.
|
|
521
546
|
|
|
@@ -533,32 +558,6 @@ Ensure your TypeScript configuration includes the autogenerated types:
|
|
|
533
558
|
|
|
534
559
|
---
|
|
535
560
|
|
|
536
|
-
### Step 13: Adapt Nitro (Optional)
|
|
537
|
-
|
|
538
|
-
If you are using Nitro for your production output, nitro will not include the `.intlayer` directory in the output directory. You need to copy it manually.
|
|
539
|
-
|
|
540
|
-
Example using build script:
|
|
541
|
-
|
|
542
|
-
```json5 fileName="package.json"
|
|
543
|
-
{
|
|
544
|
-
"scripts": {
|
|
545
|
-
"dev": "vite dev --port 3000",
|
|
546
|
-
"build": "vite build && cpr -r .intlayer .output/.intlayer", // Copy .intlayer folder
|
|
547
|
-
"serve": "vite preview",
|
|
548
|
-
},
|
|
549
|
-
}
|
|
550
|
-
```
|
|
551
|
-
|
|
552
|
-
> cpr is used to adapt the command to make it work on Windows.
|
|
553
|
-
> You will have to install the `cpr` utility to use this command.
|
|
554
|
-
>
|
|
555
|
-
> - `npm install --save-dev cpr`
|
|
556
|
-
> - `yarn add --dev cpr`
|
|
557
|
-
> - `pnpm add --save-dev cpr`
|
|
558
|
-
> - `bun add --save-dev cpr`
|
|
559
|
-
|
|
560
|
-
---
|
|
561
|
-
|
|
562
561
|
### Git Configuration
|
|
563
562
|
|
|
564
563
|
It is recommended to ignore the files generated by Intlayer. This prevents you from committing them to your Git repository.
|