@intlayer/docs 5.5.9 → 5.5.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/ar/autoFill.md +1 -2
- package/ar/intlayer_with_create_react_app.md +1 -14
- package/ar/intlayer_with_nextjs_14.md +1 -14
- package/ar/intlayer_with_nextjs_15.md +1 -14
- package/ar/intlayer_with_nextjs_page_router.md +1 -13
- package/ar/intlayer_with_nuxt.md +792 -0
- package/ar/intlayer_with_react_native+expo.md +6 -3
- package/ar/intlayer_with_vite+preact.md +7 -18
- package/ar/intlayer_with_vite+react.md +7 -17
- package/ar/intlayer_with_vite+vue.md +25 -5
- package/ar/packages/nuxt-intlayer/index.md +29 -0
- package/ar/roadmap.md +11 -11
- package/de/autoFill.md +1 -2
- package/de/how_works_intlayer.md +1 -1
- package/de/intlayer_with_create_react_app.md +1 -14
- package/de/intlayer_with_nextjs_14.md +1 -14
- package/de/intlayer_with_nextjs_15.md +1 -14
- package/de/intlayer_with_nextjs_page_router.md +1 -13
- package/de/intlayer_with_nuxt.md +791 -0
- package/de/intlayer_with_react_native+expo.md +6 -3
- package/de/intlayer_with_vite+preact.md +7 -18
- package/de/intlayer_with_vite+react.md +7 -17
- package/de/intlayer_with_vite+vue.md +84 -62
- package/de/packages/nuxt-intlayer/index.md +29 -0
- package/de/roadmap.md +11 -11
- package/en/autoFill.md +1 -2
- package/en/how_works_intlayer.md +17 -3
- package/en/intlayer_with_angular.md +535 -6
- package/en/intlayer_with_create_react_app.md +1 -14
- package/en/intlayer_with_nextjs_14.md +193 -59
- package/en/intlayer_with_nextjs_15.md +192 -61
- package/en/intlayer_with_nextjs_page_router.md +396 -61
- package/en/intlayer_with_nuxt.md +737 -0
- package/en/intlayer_with_react_native+expo.md +6 -3
- package/en/intlayer_with_vite+preact.md +8 -27
- package/en/intlayer_with_vite+react.md +7 -17
- package/en/intlayer_with_vite+solid.md +6 -3
- package/en/intlayer_with_vite+svelte.md +6 -3
- package/en/intlayer_with_vite+vue.md +17 -6
- package/en/packages/nuxt-intlayer/index.md +31 -0
- package/en/roadmap.md +13 -13
- package/en/t.md +5 -5
- package/en-GB/how_works_intlayer.md +16 -4
- package/en-GB/intlayer_with_create_react_app.md +1 -14
- package/en-GB/intlayer_with_nextjs_14.md +1 -14
- package/en-GB/intlayer_with_nextjs_15.md +1 -14
- package/en-GB/intlayer_with_nextjs_page_router.md +1 -13
- package/en-GB/intlayer_with_nuxt.md +795 -0
- package/en-GB/intlayer_with_react_native+expo.md +6 -3
- package/en-GB/intlayer_with_vite+preact.md +7 -18
- package/en-GB/intlayer_with_vite+react.md +6 -9
- package/en-GB/intlayer_with_vite+vue.md +65 -59
- package/en-GB/packages/nuxt-intlayer/index.md +31 -0
- package/en-GB/roadmap.md +11 -11
- package/es/autoFill.md +1 -2
- package/es/how_works_intlayer.md +1 -1
- package/es/intlayer_with_create_react_app.md +1 -14
- package/es/intlayer_with_nextjs_14.md +1 -14
- package/es/intlayer_with_nextjs_15.md +1 -14
- package/es/intlayer_with_nextjs_page_router.md +1 -13
- package/es/intlayer_with_nuxt.md +731 -0
- package/es/intlayer_with_react_native+expo.md +6 -3
- package/es/intlayer_with_vite+preact.md +7 -18
- package/es/intlayer_with_vite+react.md +7 -17
- package/es/intlayer_with_vite+vue.md +64 -51
- package/es/packages/nuxt-intlayer/index.md +29 -0
- package/fr/autoFill.md +1 -2
- package/fr/how_works_intlayer.md +1 -1
- package/fr/intlayer_with_create_react_app.md +1 -14
- package/fr/intlayer_with_nextjs_14.md +1 -14
- package/fr/intlayer_with_nextjs_15.md +1 -14
- package/fr/intlayer_with_nextjs_page_router.md +1 -13
- package/fr/intlayer_with_nuxt.md +731 -0
- package/fr/intlayer_with_react_native+expo.md +6 -3
- package/fr/intlayer_with_vite+preact.md +7 -18
- package/fr/intlayer_with_vite+react.md +7 -17
- package/fr/intlayer_with_vite+vue.md +30 -15
- package/fr/packages/nuxt-intlayer/index.md +29 -0
- package/fr/roadmap.md +11 -11
- package/hi/autoFill.md +1 -2
- package/hi/how_works_intlayer.md +1 -1
- package/hi/intlayer_with_create_react_app.md +1 -14
- package/hi/intlayer_with_nextjs_14.md +1 -14
- package/hi/intlayer_with_nextjs_15.md +1 -14
- package/hi/intlayer_with_nextjs_page_router.md +1 -13
- package/hi/intlayer_with_nuxt.md +784 -0
- package/hi/intlayer_with_react_native+expo.md +6 -3
- package/hi/intlayer_with_vite+preact.md +7 -18
- package/hi/intlayer_with_vite+react.md +7 -17
- package/hi/intlayer_with_vite+vue.md +59 -47
- package/hi/packages/nuxt-intlayer/index.md +29 -0
- package/hi/roadmap.md +11 -11
- package/index.cjs +30 -0
- package/index.d.ts +2 -0
- package/it/autoFill.md +1 -2
- package/it/how_works_intlayer.md +1 -1
- package/it/intlayer_with_create_react_app.md +0 -6
- package/it/intlayer_with_nextjs_14.md +1 -14
- package/it/intlayer_with_nextjs_15.md +1 -14
- package/it/intlayer_with_nextjs_page_router.md +1 -13
- package/it/intlayer_with_nuxt.md +793 -0
- package/it/intlayer_with_react_native+expo.md +6 -3
- package/it/intlayer_with_vite+preact.md +7 -18
- package/it/intlayer_with_vite+react.md +7 -17
- package/it/intlayer_with_vite+vue.md +26 -17
- package/it/packages/nuxt-intlayer/index.md +29 -0
- package/it/roadmap.md +11 -11
- package/ja/autoFill.md +1 -2
- package/ja/how_works_intlayer.md +1 -1
- package/ja/intlayer_with_create_react_app.md +1 -14
- package/ja/intlayer_with_nextjs_14.md +1 -14
- package/ja/intlayer_with_nextjs_15.md +1 -14
- package/ja/intlayer_with_nextjs_page_router.md +1 -13
- package/ja/intlayer_with_nuxt.md +792 -0
- package/ja/intlayer_with_react_native+expo.md +6 -3
- package/ja/intlayer_with_vite+preact.md +7 -18
- package/ja/intlayer_with_vite+react.md +7 -17
- package/ja/intlayer_with_vite+vue.md +68 -63
- package/ja/packages/nuxt-intlayer/index.md +29 -0
- package/ja/roadmap.md +11 -11
- package/ko/autoFill.md +1 -2
- package/ko/how_works_intlayer.md +1 -1
- package/ko/intlayer_with_create_react_app.md +1 -14
- package/ko/intlayer_with_nextjs_14.md +1 -14
- package/ko/intlayer_with_nextjs_15.md +1 -14
- package/ko/intlayer_with_nextjs_page_router.md +1 -13
- package/ko/intlayer_with_nuxt.md +784 -0
- package/ko/intlayer_with_react_native+expo.md +6 -3
- package/ko/intlayer_with_vite+preact.md +7 -18
- package/ko/intlayer_with_vite+react.md +7 -17
- package/ko/intlayer_with_vite+vue.md +69 -59
- package/ko/packages/nuxt-intlayer/index.md +31 -0
- package/ko/roadmap.md +11 -11
- package/package.json +5 -5
- package/pt/autoFill.md +1 -2
- package/pt/how_works_intlayer.md +1 -1
- package/pt/intlayer_with_create_react_app.md +1 -14
- package/pt/intlayer_with_nextjs_14.md +1 -14
- package/pt/intlayer_with_nextjs_15.md +1 -14
- package/pt/intlayer_with_nextjs_page_router.md +1 -13
- package/pt/intlayer_with_nuxt.md +792 -0
- package/pt/intlayer_with_react_native+expo.md +6 -3
- package/pt/intlayer_with_vite+preact.md +7 -18
- package/pt/intlayer_with_vite+react.md +7 -17
- package/pt/intlayer_with_vite+vue.md +23 -19
- package/pt/packages/nuxt-intlayer/index.md +29 -0
- package/pt/roadmap.md +11 -11
- package/ru/autoFill.md +1 -2
- package/ru/how_works_intlayer.md +1 -1
- package/ru/intlayer_with_create_react_app.md +1 -14
- package/ru/intlayer_with_nextjs_14.md +1 -14
- package/ru/intlayer_with_nextjs_15.md +1 -14
- package/ru/intlayer_with_nextjs_page_router.md +1 -13
- package/ru/intlayer_with_nuxt.md +792 -0
- package/ru/intlayer_with_react_native+expo.md +6 -3
- package/ru/intlayer_with_vite+preact.md +7 -18
- package/ru/intlayer_with_vite+react.md +7 -17
- package/ru/intlayer_with_vite+vue.md +25 -17
- package/ru/packages/nuxt-intlayer/index.md +31 -0
- package/ru/roadmap.md +11 -11
- package/zh/autoFill.md +1 -2
- package/zh/intlayer_with_create_react_app.md +1 -14
- package/zh/intlayer_with_nextjs_14.md +1 -14
- package/zh/intlayer_with_nextjs_15.md +1 -14
- package/zh/intlayer_with_nextjs_page_router.md +1 -13
- package/zh/intlayer_with_nuxt.md +784 -0
- package/zh/intlayer_with_react_native+expo.md +6 -3
- package/zh/intlayer_with_vite+preact.md +7 -18
- package/zh/intlayer_with_vite+react.md +7 -17
- package/zh/intlayer_with_vite+vue.md +68 -57
- package/zh/packages/nuxt-intlayer/index.md +31 -0
- package/zh/roadmap.md +11 -11
|
@@ -568,34 +568,117 @@ const ServerComponentExample = () => {
|
|
|
568
568
|
> If you want to use your content in a `string` attribute, such as `alt`, `title`, `href`, `aria-label`, etc., you must call the value of the function, like:
|
|
569
569
|
|
|
570
570
|
> ```jsx
|
|
571
|
-
>
|
|
572
|
-
> ```
|
|
573
|
-
|
|
574
571
|
> <img src={content.image.src.value} alt={content.image.value} />
|
|
575
|
-
|
|
576
|
-
> ```
|
|
577
|
-
>
|
|
578
572
|
> ```
|
|
579
573
|
|
|
580
574
|
> To Learn more about the `useIntlayer` hook, refer to the [documentation](https://github.com/aymericzip/intlayer/blob/main/docs/en/packages/next-intlayer/useIntlayer.md).
|
|
581
575
|
|
|
582
576
|
### (Optional) Step 8: Internationalization of your metadata
|
|
583
577
|
|
|
584
|
-
In the case you want to internationalize your metadata, such as the title of your page, you can use the `generateMetadata` function provided by Next.js. Inside the
|
|
578
|
+
In the case you want to internationalize your metadata, such as the title of your page, you can use the `generateMetadata` function provided by Next.js. Inside, you can retrieve the content from the `getIntlayer` function to translate your metadata.
|
|
579
|
+
|
|
580
|
+
```typescript fileName="src/app/[locale]/metadata.content.ts" contentDeclarationFormat="typescript"
|
|
581
|
+
import { type Dictionary, t } from "intlayer";
|
|
582
|
+
import { Metadata } from "next";
|
|
583
|
+
|
|
584
|
+
const metadataContent = {
|
|
585
|
+
key: "page-metadata",
|
|
586
|
+
content: {
|
|
587
|
+
title: t({
|
|
588
|
+
en: "Create Next App",
|
|
589
|
+
fr: "Créer une application Next.js",
|
|
590
|
+
es: "Crear una aplicación Next.js",
|
|
591
|
+
}),
|
|
592
|
+
description: t({
|
|
593
|
+
en: "Generated by create next app",
|
|
594
|
+
fr: "Généré par create next app",
|
|
595
|
+
es: "Generado por create next app",
|
|
596
|
+
}),
|
|
597
|
+
},
|
|
598
|
+
} satisfies Dictionary<Metadata>;
|
|
599
|
+
|
|
600
|
+
export default metadataContent;
|
|
601
|
+
```
|
|
602
|
+
|
|
603
|
+
```javascript fileName="src/app/[locale]/metadata.content.mjs" contentDeclarationFormat="esm"
|
|
604
|
+
import { t } from "intlayer";
|
|
605
|
+
|
|
606
|
+
/** @type {import('intlayer').Dictionary<import('next').Metadata>} */
|
|
607
|
+
const metadataContent = {
|
|
608
|
+
key: "page-metadata",
|
|
609
|
+
content: {
|
|
610
|
+
title: t({
|
|
611
|
+
en: "Create Next App",
|
|
612
|
+
fr: "Créer une application Next.js",
|
|
613
|
+
es: "Crear una aplicación Next.js",
|
|
614
|
+
}),
|
|
615
|
+
description: t({
|
|
616
|
+
en: "Generated by create next app",
|
|
617
|
+
fr: "Généré par create next app",
|
|
618
|
+
es: "Generado por create next app",
|
|
619
|
+
}),
|
|
620
|
+
},
|
|
621
|
+
};
|
|
622
|
+
|
|
623
|
+
export default metadataContent;
|
|
624
|
+
```
|
|
625
|
+
|
|
626
|
+
```javascript fileName="src/app/[locale]/metadata.content.cjs" contentDeclarationFormat="commonjs"
|
|
627
|
+
const { t } = require("intlayer");
|
|
628
|
+
|
|
629
|
+
/** @type {import('intlayer').Dictionary<import('next').Metadata>} */
|
|
630
|
+
const metadataContent = {
|
|
631
|
+
key: "page-metadata",
|
|
632
|
+
content: {
|
|
633
|
+
title: t({
|
|
634
|
+
en: "Create Next App",
|
|
635
|
+
fr: "Créer une application Next.js",
|
|
636
|
+
es: "Crear una aplicación Next.js",
|
|
637
|
+
}),
|
|
638
|
+
description: t({
|
|
639
|
+
en: "Generated by create next app",
|
|
640
|
+
fr: "Généré par create next app",
|
|
641
|
+
es: "Generado por create next app",
|
|
642
|
+
}),
|
|
643
|
+
},
|
|
644
|
+
};
|
|
645
|
+
|
|
646
|
+
module.exports = metadataContent;
|
|
647
|
+
```
|
|
648
|
+
|
|
649
|
+
```json fileName="src/app/[locale]/metadata.content.json" contentDeclarationFormat="json"
|
|
650
|
+
{
|
|
651
|
+
"key": "page-metadata",
|
|
652
|
+
"content": {
|
|
653
|
+
"title": {
|
|
654
|
+
"nodeType": "translation",
|
|
655
|
+
"translation": {
|
|
656
|
+
"en": "Preact logo",
|
|
657
|
+
"fr": "Logo Preact",
|
|
658
|
+
"es": "Logo Preact",
|
|
659
|
+
},
|
|
660
|
+
},
|
|
661
|
+
"description": {
|
|
662
|
+
"nodeType": "translation",
|
|
663
|
+
"translation": {
|
|
664
|
+
"en": "Generated by create next app",
|
|
665
|
+
"fr": "Généré par create next app",
|
|
666
|
+
"es": "Generado por create next app",
|
|
667
|
+
},
|
|
668
|
+
},
|
|
669
|
+
},
|
|
670
|
+
};
|
|
671
|
+
```
|
|
585
672
|
|
|
586
673
|
````typescript fileName="src/app/[locale]/layout.tsx or src/app/[locale]/page.tsx" codeFormat="typescript"
|
|
587
|
-
import {
|
|
588
|
-
type IConfigLocales,
|
|
589
|
-
getTranslation,
|
|
590
|
-
getMultilingualUrls,
|
|
591
|
-
} from "intlayer";
|
|
674
|
+
import { getIntlayer, getMultilingualUrls } from "intlayer";
|
|
592
675
|
import type { Metadata } from "next";
|
|
593
676
|
import type { LocalParams } from "next-intlayer";
|
|
594
677
|
|
|
595
678
|
export const generateMetadata = ({
|
|
596
679
|
params: { locale },
|
|
597
680
|
}: LocalParams): Metadata => {
|
|
598
|
-
const
|
|
681
|
+
const metadata = getIntlayer("page-metadata", locale);
|
|
599
682
|
|
|
600
683
|
/**
|
|
601
684
|
* Generates an object containing all url for each locale.
|
|
@@ -615,16 +698,7 @@ export const generateMetadata = ({
|
|
|
615
698
|
const multilingualUrls = getMultilingualUrls("/");
|
|
616
699
|
|
|
617
700
|
return {
|
|
618
|
-
|
|
619
|
-
en: "My title",
|
|
620
|
-
fr: "Mon titre",
|
|
621
|
-
es: "Mi título",
|
|
622
|
-
}),
|
|
623
|
-
description: t({
|
|
624
|
-
en: "My description",
|
|
625
|
-
fr: "Ma description",
|
|
626
|
-
es: "Mi descripción",
|
|
627
|
-
}),
|
|
701
|
+
...metadata,
|
|
628
702
|
alternates: {
|
|
629
703
|
canonical: multilingualUrls[locale as keyof typeof multilingualUrls],
|
|
630
704
|
languages: { ...multilingualUrls, "x-default": "/" },
|
|
@@ -638,11 +712,11 @@ export const generateMetadata = ({
|
|
|
638
712
|
// ... Rest of the code
|
|
639
713
|
````
|
|
640
714
|
|
|
641
|
-
````javascript fileName="src/app/[locale]/layout.
|
|
642
|
-
import {
|
|
715
|
+
````javascript fileName="src/app/[locale]/layout.mjs or src/app/[locale]/page.mjs" codeFormat="esm"
|
|
716
|
+
import { getIntlayer, getMultilingualUrls } from "intlayer";
|
|
643
717
|
|
|
644
718
|
export const generateMetadata = ({ params: { locale } }) => {
|
|
645
|
-
const
|
|
719
|
+
const metadata = getIntlayer("page-metadata", locale);
|
|
646
720
|
|
|
647
721
|
/**
|
|
648
722
|
* Generates an object containing all url for each locale.
|
|
@@ -655,23 +729,14 @@ export const generateMetadata = ({ params: { locale } }) => {
|
|
|
655
729
|
* // {
|
|
656
730
|
* // en: '/about',
|
|
657
731
|
* // fr: '/fr/about',
|
|
658
|
-
* // es: '/es/about'
|
|
732
|
+
* // es: '/es/about'
|
|
659
733
|
* // }
|
|
660
734
|
* ```
|
|
661
735
|
*/
|
|
662
736
|
const multilingualUrls = getMultilingualUrls("/");
|
|
663
737
|
|
|
664
738
|
return {
|
|
665
|
-
|
|
666
|
-
en: "My title",
|
|
667
|
-
fr: "Mon titre",
|
|
668
|
-
es: "Mi título",
|
|
669
|
-
}),
|
|
670
|
-
description: t({
|
|
671
|
-
en: "My description",
|
|
672
|
-
fr: "Ma description",
|
|
673
|
-
es: "Mi descripción",
|
|
674
|
-
}),
|
|
739
|
+
...metadata,
|
|
675
740
|
alternates: {
|
|
676
741
|
canonical: multilingualUrls[locale],
|
|
677
742
|
languages: { ...multilingualUrls, "x-default": "/" },
|
|
@@ -685,11 +750,11 @@ export const generateMetadata = ({ params: { locale } }) => {
|
|
|
685
750
|
// ... Rest of the code
|
|
686
751
|
````
|
|
687
752
|
|
|
688
|
-
````javascript fileName="src/app/[locale]/layout.cjs or src/app/[locale]/page.cjs" codeFormat="
|
|
689
|
-
const {
|
|
753
|
+
````javascript fileName="src/app/[locale]/layout.cjs or src/app/[locale]/page.cjs" codeFormat="commonjs"
|
|
754
|
+
const { getIntlayer, getMultilingualUrls } = require("intlayer");
|
|
690
755
|
|
|
691
|
-
|
|
692
|
-
const
|
|
756
|
+
const generateMetadata = ({ params: { locale } }) => {
|
|
757
|
+
const metadata = getIntlayer("page-metadata", locale);
|
|
693
758
|
|
|
694
759
|
/**
|
|
695
760
|
* Generates an object containing all url for each locale.
|
|
@@ -702,12 +767,70 @@ module.exports.generateMetadata = ({ params: { locale } }) => {
|
|
|
702
767
|
* // {
|
|
703
768
|
* // en: '/about',
|
|
704
769
|
* // fr: '/fr/about',
|
|
705
|
-
* // es: '/es/about'
|
|
770
|
+
* // es: '/es/about'
|
|
706
771
|
* // }
|
|
707
772
|
* ```
|
|
708
773
|
*/
|
|
709
774
|
const multilingualUrls = getMultilingualUrls("/");
|
|
710
775
|
|
|
776
|
+
return {
|
|
777
|
+
...metadata,
|
|
778
|
+
alternates: {
|
|
779
|
+
canonical: multilingualUrls[locale],
|
|
780
|
+
languages: { ...multilingualUrls, "x-default": "/" },
|
|
781
|
+
},
|
|
782
|
+
openGraph: {
|
|
783
|
+
url: multilingualUrls[locale],
|
|
784
|
+
},
|
|
785
|
+
};
|
|
786
|
+
};
|
|
787
|
+
|
|
788
|
+
module.exports = { generateMetadata };
|
|
789
|
+
|
|
790
|
+
// ... Rest of the code
|
|
791
|
+
````
|
|
792
|
+
|
|
793
|
+
> Note that the `getIntlayer` function imported from `next-intlayer` returns your content wrapped in an `IntlayerNode`, allowing integration with the visual editor. In contrast, the `getIntlayer` function imported from `intlayer` returns your content directly without additional properties.
|
|
794
|
+
|
|
795
|
+
Alternatively, you can use the `getTranslation` function to declare your metadata. However, using content declaration files is recommended to automate the translation of your metadata and externalize the content at some point.
|
|
796
|
+
|
|
797
|
+
```typescript fileName="src/app/[locale]/layout.tsx or src/app/[locale]/page.tsx" codeFormat="typescript"
|
|
798
|
+
import {
|
|
799
|
+
type IConfigLocales,
|
|
800
|
+
getTranslation,
|
|
801
|
+
getMultilingualUrls,
|
|
802
|
+
} from "intlayer";
|
|
803
|
+
import type { Metadata } from "next";
|
|
804
|
+
import type { LocalParams } from "next-intlayer";
|
|
805
|
+
|
|
806
|
+
export const generateMetadata = ({
|
|
807
|
+
params: { locale },
|
|
808
|
+
}: LocalParams): Metadata => {
|
|
809
|
+
const t = <T>(content: IConfigLocales<T>) => getTranslation(content, locale);
|
|
810
|
+
|
|
811
|
+
return {
|
|
812
|
+
title: t<string>({
|
|
813
|
+
en: "My title",
|
|
814
|
+
fr: "Mon titre",
|
|
815
|
+
es: "Mi título",
|
|
816
|
+
}),
|
|
817
|
+
description: t({
|
|
818
|
+
en: "My description",
|
|
819
|
+
fr: "Ma description",
|
|
820
|
+
es: "Mi descripción",
|
|
821
|
+
}),
|
|
822
|
+
};
|
|
823
|
+
};
|
|
824
|
+
|
|
825
|
+
// ... Rest of the code
|
|
826
|
+
```
|
|
827
|
+
|
|
828
|
+
```javascript fileName="src/app/[locale]/layout.mjs or src/app/[locale]/page.mjs" codeFormat="esm"
|
|
829
|
+
import { getTranslation, getMultilingualUrls } from "intlayer";
|
|
830
|
+
|
|
831
|
+
export const generateMetadata = ({ params: { locale } }) => {
|
|
832
|
+
const t = (content) => getTranslation(content, locale);
|
|
833
|
+
|
|
711
834
|
return {
|
|
712
835
|
title: t({
|
|
713
836
|
en: "My title",
|
|
@@ -719,20 +842,38 @@ module.exports.generateMetadata = ({ params: { locale } }) => {
|
|
|
719
842
|
fr: "Ma description",
|
|
720
843
|
es: "Mi descripción",
|
|
721
844
|
}),
|
|
722
|
-
alternates: {
|
|
723
|
-
canonical: multilingualUrls[locale],
|
|
724
|
-
languages: { ...multilingualUrls, "x-default": "/" },
|
|
725
|
-
},
|
|
726
|
-
openGraph: {
|
|
727
|
-
url: multilingualUrls[locale],
|
|
728
|
-
},
|
|
729
845
|
};
|
|
730
846
|
};
|
|
731
847
|
|
|
732
848
|
// ... Rest of the code
|
|
733
|
-
|
|
849
|
+
```
|
|
850
|
+
|
|
851
|
+
```javascript fileName="src/app/[locale]/layout.cjs or src/app/[locale]/page.cjs" codeFormat="commonjs"
|
|
852
|
+
const { getTranslation, getMultilingualUrls } = require("intlayer");
|
|
853
|
+
|
|
854
|
+
const generateMetadata = ({ params: { locale } }) => {
|
|
855
|
+
const t = (content) => getTranslation(content, locale);
|
|
856
|
+
|
|
857
|
+
return {
|
|
858
|
+
title: t({
|
|
859
|
+
en: "My title",
|
|
860
|
+
fr: "Mon titre",
|
|
861
|
+
es: "Mi título",
|
|
862
|
+
}),
|
|
863
|
+
description: t({
|
|
864
|
+
en: "My description",
|
|
865
|
+
fr: "Ma description",
|
|
866
|
+
es: "Mi descripción",
|
|
867
|
+
}),
|
|
868
|
+
};
|
|
869
|
+
};
|
|
870
|
+
|
|
871
|
+
module.exports = { generateMetadata };
|
|
872
|
+
|
|
873
|
+
// ... Rest of the code
|
|
874
|
+
```
|
|
734
875
|
|
|
735
|
-
>
|
|
876
|
+
> Learn more about the metadata optimization [on the official Next.js documentation](https://nextjs.org/docs/app/building-your-application/optimizing/metadata).
|
|
736
877
|
|
|
737
878
|
### (Optional) Step 9: Internationalization of your sitemap.xml and robots.txt
|
|
738
879
|
|
|
@@ -1067,21 +1208,14 @@ return (
|
|
|
1067
1208
|
```
|
|
1068
1209
|
|
|
1069
1210
|
> Documentation references:
|
|
1070
|
-
|
|
1211
|
+
>
|
|
1071
1212
|
> - [`useLocale` hook](https://github.com/aymericzip/intlayer/blob/main/docs/en/packages/next-intlayer/useLocale.md)
|
|
1072
|
-
|
|
1073
1213
|
> - [`getLocaleName` hook](https://github.com/aymericzip/intlayer/blob/main/docs/en/packages/intlayer/getLocaleName.md)
|
|
1074
|
-
|
|
1075
1214
|
> - [`getLocalizedUrl` hook](https://github.com/aymericzip/intlayer/blob/main/docs/en/packages/intlayer/getLocalizedUrl.md)
|
|
1076
|
-
|
|
1077
1215
|
> - [`getHTMLTextDir` hook](https://github.com/aymericzip/intlayer/blob/main/docs/en/packages/intlayer/getHTMLTextDir.md)
|
|
1078
|
-
|
|
1079
1216
|
> - [`hrefLang` attribute](https://developers.google.com/search/docs/specialty/international/localized-versions?hl=fr)
|
|
1080
|
-
|
|
1081
1217
|
> - [`lang` attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/lang)
|
|
1082
|
-
|
|
1083
1218
|
> - [`dir` attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/dir)
|
|
1084
|
-
|
|
1085
1219
|
> - [`aria-current` attribute](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-current)
|
|
1086
1220
|
|
|
1087
1221
|
### (Optional) Step 11: Creating a Localized Link Component
|
|
@@ -352,14 +352,7 @@ module.exports = pageContent;
|
|
|
352
352
|
"es": "Comience por editar"
|
|
353
353
|
}
|
|
354
354
|
},
|
|
355
|
-
"pageLink":
|
|
356
|
-
"nodeType": "translation",
|
|
357
|
-
"translation": {
|
|
358
|
-
"en": "src/app/page.tsx",
|
|
359
|
-
"fr": "src/app/page.tsx",
|
|
360
|
-
"es": "src/app/page.tsx"
|
|
361
|
-
}
|
|
362
|
-
}
|
|
355
|
+
"pageLink": "src/app/page.tsx"
|
|
363
356
|
}
|
|
364
357
|
}
|
|
365
358
|
```
|
|
@@ -582,13 +575,7 @@ const ServerComponentExample = () => {
|
|
|
582
575
|
> If you want to use your content in a `string` attribute, such as `alt`, `title`, `href`, `aria-label`, etc., you must call the value of the function, like:
|
|
583
576
|
|
|
584
577
|
> ```jsx
|
|
585
|
-
>
|
|
586
|
-
> ```
|
|
587
|
-
|
|
588
578
|
> <img src={content.image.src.value} alt={content.image.value} />
|
|
589
|
-
|
|
590
|
-
> ```
|
|
591
|
-
>
|
|
592
579
|
> ```
|
|
593
580
|
|
|
594
581
|
> To Learn more about the `useIntlayer` hook, refer to the [documentation](https://github.com/aymericzip/intlayer/blob/main/docs/en/packages/next-intlayer/useIntlayer.md).
|
|
@@ -630,14 +617,103 @@ module.exports = { middleware: intlayerMiddleware, config };
|
|
|
630
617
|
|
|
631
618
|
### (Optional) Step 8: Internationalization of your metadata
|
|
632
619
|
|
|
633
|
-
In the case you want to internationalize your metadata, such as the title of your page, you can use the `generateMetadata` function provided by Next.js. Inside the
|
|
620
|
+
In the case you want to internationalize your metadata, such as the title of your page, you can use the `generateMetadata` function provided by Next.js. Inside, you can retrieve the content from the `getIntlayer` function to translate your metadata.
|
|
621
|
+
|
|
622
|
+
```typescript fileName="src/app/[locale]/metadata.content.ts" contentDeclarationFormat="typescript"
|
|
623
|
+
import { type Dictionary, t } from "intlayer";
|
|
624
|
+
import { Metadata } from "next";
|
|
625
|
+
|
|
626
|
+
const metadataContent = {
|
|
627
|
+
key: "page-metadata",
|
|
628
|
+
content: {
|
|
629
|
+
title: t({
|
|
630
|
+
en: "Create Next App",
|
|
631
|
+
fr: "Créer une application Next.js",
|
|
632
|
+
es: "Crear una aplicación Next.js",
|
|
633
|
+
}),
|
|
634
|
+
description: t({
|
|
635
|
+
en: "Generated by create next app",
|
|
636
|
+
fr: "Généré par create next app",
|
|
637
|
+
es: "Generado por create next app",
|
|
638
|
+
}),
|
|
639
|
+
},
|
|
640
|
+
} satisfies Dictionary<Metadata>;
|
|
641
|
+
|
|
642
|
+
export default metadataContent;
|
|
643
|
+
```
|
|
644
|
+
|
|
645
|
+
```javascript fileName="src/app/[locale]/metadata.content.mjs" contentDeclarationFormat="esm"
|
|
646
|
+
import { t } from "intlayer";
|
|
647
|
+
|
|
648
|
+
/** @type {import('intlayer').Dictionary<import('next').Metadata>} */
|
|
649
|
+
const metadataContent = {
|
|
650
|
+
key: "page-metadata",
|
|
651
|
+
content: {
|
|
652
|
+
title: t({
|
|
653
|
+
en: "Create Next App",
|
|
654
|
+
fr: "Créer une application Next.js",
|
|
655
|
+
es: "Crear una aplicación Next.js",
|
|
656
|
+
}),
|
|
657
|
+
description: t({
|
|
658
|
+
en: "Generated by create next app",
|
|
659
|
+
fr: "Généré par create next app",
|
|
660
|
+
es: "Generado por create next app",
|
|
661
|
+
}),
|
|
662
|
+
},
|
|
663
|
+
};
|
|
664
|
+
|
|
665
|
+
export default metadataContent;
|
|
666
|
+
```
|
|
667
|
+
|
|
668
|
+
```javascript fileName="src/app/[locale]/metadata.content.cjs" contentDeclarationFormat="commonjs"
|
|
669
|
+
const { t } = require("intlayer");
|
|
670
|
+
|
|
671
|
+
/** @type {import('intlayer').Dictionary<import('next').Metadata>} */
|
|
672
|
+
const metadataContent = {
|
|
673
|
+
key: "page-metadata",
|
|
674
|
+
content: {
|
|
675
|
+
title: t({
|
|
676
|
+
en: "Create Next App",
|
|
677
|
+
fr: "Créer une application Next.js",
|
|
678
|
+
es: "Crear una aplicación Next.js",
|
|
679
|
+
}),
|
|
680
|
+
description: t({
|
|
681
|
+
en: "Generated by create next app",
|
|
682
|
+
fr: "Généré par create next app",
|
|
683
|
+
es: "Generado por create next app",
|
|
684
|
+
}),
|
|
685
|
+
},
|
|
686
|
+
};
|
|
687
|
+
|
|
688
|
+
module.exports = metadataContent;
|
|
689
|
+
```
|
|
690
|
+
|
|
691
|
+
```json fileName="src/app/[locale]/metadata.content.json" contentDeclarationFormat="json"
|
|
692
|
+
{
|
|
693
|
+
"key": "page-metadata",
|
|
694
|
+
"content": {
|
|
695
|
+
"title": {
|
|
696
|
+
"nodeType": "translation",
|
|
697
|
+
"translation": {
|
|
698
|
+
"en": "Preact logo",
|
|
699
|
+
"fr": "Logo Preact",
|
|
700
|
+
"es": "Logo Preact",
|
|
701
|
+
},
|
|
702
|
+
},
|
|
703
|
+
"description": {
|
|
704
|
+
"nodeType": "translation",
|
|
705
|
+
"translation": {
|
|
706
|
+
"en": "Generated by create next app",
|
|
707
|
+
"fr": "Généré par create next app",
|
|
708
|
+
"es": "Generado por create next app",
|
|
709
|
+
},
|
|
710
|
+
},
|
|
711
|
+
},
|
|
712
|
+
};
|
|
713
|
+
```
|
|
634
714
|
|
|
635
715
|
````typescript fileName="src/app/[locale]/layout.tsx or src/app/[locale]/page.tsx" codeFormat="typescript"
|
|
636
|
-
import {
|
|
637
|
-
type IConfigLocales,
|
|
638
|
-
getTranslation,
|
|
639
|
-
getMultilingualUrls,
|
|
640
|
-
} from "intlayer";
|
|
716
|
+
import { getIntlayer, getMultilingualUrls } from "intlayer";
|
|
641
717
|
import type { Metadata } from "next";
|
|
642
718
|
import type { LocalPromiseParams } from "next-intlayer";
|
|
643
719
|
|
|
@@ -645,7 +721,8 @@ export const generateMetadata = async ({
|
|
|
645
721
|
params,
|
|
646
722
|
}: LocalPromiseParams): Promise<Metadata> => {
|
|
647
723
|
const { locale } = await params;
|
|
648
|
-
|
|
724
|
+
|
|
725
|
+
const metadata = getIntlayer("page-metadata", locale);
|
|
649
726
|
|
|
650
727
|
/**
|
|
651
728
|
* Generates an object containing all url for each locale.
|
|
@@ -665,16 +742,7 @@ export const generateMetadata = async ({
|
|
|
665
742
|
const multilingualUrls = getMultilingualUrls("/");
|
|
666
743
|
|
|
667
744
|
return {
|
|
668
|
-
|
|
669
|
-
en: "My title",
|
|
670
|
-
fr: "Mon titre",
|
|
671
|
-
es: "Mi título",
|
|
672
|
-
}),
|
|
673
|
-
description: t({
|
|
674
|
-
en: "My description",
|
|
675
|
-
fr: "Ma description",
|
|
676
|
-
es: "Mi descripción",
|
|
677
|
-
}),
|
|
745
|
+
...metadata,
|
|
678
746
|
alternates: {
|
|
679
747
|
canonical: multilingualUrls[locale as keyof typeof multilingualUrls],
|
|
680
748
|
languages: { ...multilingualUrls, "x-default": "/" },
|
|
@@ -689,11 +757,12 @@ export const generateMetadata = async ({
|
|
|
689
757
|
````
|
|
690
758
|
|
|
691
759
|
````javascript fileName="src/app/[locale]/layout.mjs or src/app/[locale]/page.mjs" codeFormat="esm"
|
|
692
|
-
import {
|
|
760
|
+
import { getIntlayer, getMultilingualUrls } from "intlayer";
|
|
693
761
|
|
|
694
762
|
export const generateMetadata = async ({ params }) => {
|
|
695
763
|
const { locale } = await params;
|
|
696
|
-
|
|
764
|
+
|
|
765
|
+
const metadata = getIntlayer("page-metadata", locale);
|
|
697
766
|
|
|
698
767
|
/**
|
|
699
768
|
* Generates an object containing all url for each locale.
|
|
@@ -713,16 +782,7 @@ export const generateMetadata = async ({ params }) => {
|
|
|
713
782
|
const multilingualUrls = getMultilingualUrls("/");
|
|
714
783
|
|
|
715
784
|
return {
|
|
716
|
-
|
|
717
|
-
en: "My title",
|
|
718
|
-
fr: "Mon titre",
|
|
719
|
-
es: "Mi título",
|
|
720
|
-
}),
|
|
721
|
-
description: t({
|
|
722
|
-
en: "My description",
|
|
723
|
-
fr: "Ma description",
|
|
724
|
-
es: "Mi descripción",
|
|
725
|
-
}),
|
|
785
|
+
...metadata,
|
|
726
786
|
alternates: {
|
|
727
787
|
canonical: multilingualUrls[locale],
|
|
728
788
|
languages: { ...multilingualUrls, "x-default": "/" },
|
|
@@ -737,12 +797,12 @@ export const generateMetadata = async ({ params }) => {
|
|
|
737
797
|
````
|
|
738
798
|
|
|
739
799
|
````javascript fileName="src/app/[locale]/layout.cjs or src/app/[locale]/page.cjs" codeFormat="commonjs"
|
|
740
|
-
const {
|
|
800
|
+
const { getIntlayer, getMultilingualUrls } = require("intlayer");
|
|
741
801
|
|
|
742
802
|
const generateMetadata = async ({ params }) => {
|
|
743
803
|
const { locale } = await params;
|
|
744
804
|
|
|
745
|
-
const
|
|
805
|
+
const metadata = getIntlayer("page-metadata", locale);
|
|
746
806
|
|
|
747
807
|
/**
|
|
748
808
|
* Generates an object containing all url for each locale.
|
|
@@ -761,6 +821,91 @@ const generateMetadata = async ({ params }) => {
|
|
|
761
821
|
*/
|
|
762
822
|
const multilingualUrls = getMultilingualUrls("/");
|
|
763
823
|
|
|
824
|
+
return {
|
|
825
|
+
...metadata,
|
|
826
|
+
alternates: {
|
|
827
|
+
canonical: multilingualUrls[locale],
|
|
828
|
+
languages: { ...multilingualUrls, "x-default": "/" },
|
|
829
|
+
},
|
|
830
|
+
openGraph: {
|
|
831
|
+
url: multilingualUrls[locale],
|
|
832
|
+
},
|
|
833
|
+
};
|
|
834
|
+
};
|
|
835
|
+
|
|
836
|
+
module.exports = { generateMetadata };
|
|
837
|
+
|
|
838
|
+
// ... Rest of the code
|
|
839
|
+
````
|
|
840
|
+
|
|
841
|
+
> Note that the `getIntlayer` function imported from `next-intlayer` returns your content wrapped in an `IntlayerNode`, allowing integration with the visual editor. In contrast, the `getIntlayer` function imported from `intlayer` returns your content directly without additional properties.
|
|
842
|
+
|
|
843
|
+
Alternatively, you can use the `getTranslation` function to declare your metadata. However, using content declaration files is recommended to automate the translation of your metadata and externalize the content at some point.
|
|
844
|
+
|
|
845
|
+
```typescript fileName="src/app/[locale]/layout.tsx or src/app/[locale]/page.tsx" codeFormat="typescript"
|
|
846
|
+
import {
|
|
847
|
+
type IConfigLocales,
|
|
848
|
+
getTranslation,
|
|
849
|
+
getMultilingualUrls,
|
|
850
|
+
} from "intlayer";
|
|
851
|
+
import type { Metadata } from "next";
|
|
852
|
+
import type { LocalPromiseParams } from "next-intlayer";
|
|
853
|
+
|
|
854
|
+
export const generateMetadata = async ({
|
|
855
|
+
params,
|
|
856
|
+
}: LocalPromiseParams): Promise<Metadata> => {
|
|
857
|
+
const { locale } = await params;
|
|
858
|
+
const t = <T>(content: IConfigLocales<T>) => getTranslation(content, locale);
|
|
859
|
+
|
|
860
|
+
return {
|
|
861
|
+
title: t<string>({
|
|
862
|
+
en: "My title",
|
|
863
|
+
fr: "Mon titre",
|
|
864
|
+
es: "Mi título",
|
|
865
|
+
}),
|
|
866
|
+
description: t({
|
|
867
|
+
en: "My description",
|
|
868
|
+
fr: "Ma description",
|
|
869
|
+
es: "Mi descripción",
|
|
870
|
+
}),
|
|
871
|
+
};
|
|
872
|
+
};
|
|
873
|
+
|
|
874
|
+
// ... Rest of the code
|
|
875
|
+
```
|
|
876
|
+
|
|
877
|
+
```javascript fileName="src/app/[locale]/layout.mjs or src/app/[locale]/page.mjs" codeFormat="esm"
|
|
878
|
+
import { getTranslation, getMultilingualUrls } from "intlayer";
|
|
879
|
+
|
|
880
|
+
export const generateMetadata = async ({ params }) => {
|
|
881
|
+
const { locale } = await params;
|
|
882
|
+
const t = (content) => getTranslation(content, locale);
|
|
883
|
+
|
|
884
|
+
return {
|
|
885
|
+
title: t({
|
|
886
|
+
en: "My title",
|
|
887
|
+
fr: "Mon titre",
|
|
888
|
+
es: "Mi título",
|
|
889
|
+
}),
|
|
890
|
+
description: t({
|
|
891
|
+
en: "My description",
|
|
892
|
+
fr: "Ma description",
|
|
893
|
+
es: "Mi descripción",
|
|
894
|
+
}),
|
|
895
|
+
};
|
|
896
|
+
};
|
|
897
|
+
|
|
898
|
+
// ... Rest of the code
|
|
899
|
+
```
|
|
900
|
+
|
|
901
|
+
```javascript fileName="src/app/[locale]/layout.cjs or src/app/[locale]/page.cjs" codeFormat="commonjs"
|
|
902
|
+
const { getTranslation, getMultilingualUrls } = require("intlayer");
|
|
903
|
+
|
|
904
|
+
const generateMetadata = async ({ params }) => {
|
|
905
|
+
const { locale } = await params;
|
|
906
|
+
|
|
907
|
+
const t = (content) => getTranslation(content, locale);
|
|
908
|
+
|
|
764
909
|
return {
|
|
765
910
|
title: t({
|
|
766
911
|
en: "My title",
|
|
@@ -772,20 +917,13 @@ const generateMetadata = async ({ params }) => {
|
|
|
772
917
|
fr: "Ma description",
|
|
773
918
|
es: "Mi descripción",
|
|
774
919
|
}),
|
|
775
|
-
alternates: {
|
|
776
|
-
canonical: multilingualUrls[locale],
|
|
777
|
-
languages: { ...multilingualUrls, "x-default": "/" },
|
|
778
|
-
},
|
|
779
|
-
openGraph: {
|
|
780
|
-
url: multilingualUrls[locale],
|
|
781
|
-
},
|
|
782
920
|
};
|
|
783
921
|
};
|
|
784
922
|
|
|
785
923
|
module.exports = { generateMetadata };
|
|
786
924
|
|
|
787
925
|
// ... Rest of the code
|
|
788
|
-
|
|
926
|
+
```
|
|
789
927
|
|
|
790
928
|
> Learn more about the metadata optimization [on the official Next.js documentation](https://nextjs.org/docs/app/building-your-application/optimizing/metadata).
|
|
791
929
|
|
|
@@ -1121,21 +1259,14 @@ return (
|
|
|
1121
1259
|
```
|
|
1122
1260
|
|
|
1123
1261
|
> Documentation references:
|
|
1124
|
-
|
|
1262
|
+
>
|
|
1125
1263
|
> - [`useLocale` hook](https://github.com/aymericzip/intlayer/blob/main/docs/en/packages/next-intlayer/useLocale.md)
|
|
1126
|
-
|
|
1127
1264
|
> - [`getLocaleName` hook](https://github.com/aymericzip/intlayer/blob/main/docs/en/packages/intlayer/getLocaleName.md)
|
|
1128
|
-
|
|
1129
1265
|
> - [`getLocalizedUrl` hook](https://github.com/aymericzip/intlayer/blob/main/docs/en/packages/intlayer/getLocalizedUrl.md)
|
|
1130
|
-
|
|
1131
1266
|
> - [`getHTMLTextDir` hook](https://github.com/aymericzip/intlayer/blob/main/docs/en/packages/intlayer/getHTMLTextDir.md)
|
|
1132
|
-
|
|
1133
1267
|
> - [`hrefLang` attribute](https://developers.google.com/search/docs/specialty/international/localized-versions?hl=fr)
|
|
1134
|
-
|
|
1135
1268
|
> - [`lang` attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/lang)
|
|
1136
|
-
|
|
1137
1269
|
> - [`dir` attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/dir)
|
|
1138
|
-
|
|
1139
1270
|
> - [`aria-current` attribute](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-current)
|
|
1140
1271
|
|
|
1141
1272
|
### (Optional) Step 11: Creating a Localized Link Component
|