@intlayer/docs 5.5.8 → 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.
Files changed (172) hide show
  1. package/ar/autoFill.md +1 -2
  2. package/ar/intlayer_with_create_react_app.md +1 -14
  3. package/ar/intlayer_with_nextjs_14.md +1 -14
  4. package/ar/intlayer_with_nextjs_15.md +1 -14
  5. package/ar/intlayer_with_nextjs_page_router.md +1 -13
  6. package/ar/intlayer_with_nuxt.md +792 -0
  7. package/ar/intlayer_with_react_native+expo.md +6 -3
  8. package/ar/intlayer_with_vite+preact.md +7 -18
  9. package/ar/intlayer_with_vite+react.md +7 -17
  10. package/ar/intlayer_with_vite+vue.md +25 -5
  11. package/ar/packages/nuxt-intlayer/index.md +29 -0
  12. package/ar/roadmap.md +11 -11
  13. package/de/autoFill.md +1 -2
  14. package/de/how_works_intlayer.md +1 -1
  15. package/de/intlayer_with_create_react_app.md +1 -14
  16. package/de/intlayer_with_nextjs_14.md +1 -14
  17. package/de/intlayer_with_nextjs_15.md +1 -14
  18. package/de/intlayer_with_nextjs_page_router.md +1 -13
  19. package/de/intlayer_with_nuxt.md +791 -0
  20. package/de/intlayer_with_react_native+expo.md +6 -3
  21. package/de/intlayer_with_vite+preact.md +7 -18
  22. package/de/intlayer_with_vite+react.md +7 -17
  23. package/de/intlayer_with_vite+vue.md +84 -62
  24. package/de/packages/nuxt-intlayer/index.md +29 -0
  25. package/de/roadmap.md +11 -11
  26. package/en/autoFill.md +1 -2
  27. package/en/how_works_intlayer.md +17 -3
  28. package/en/intlayer_with_angular.md +535 -6
  29. package/en/intlayer_with_create_react_app.md +1 -14
  30. package/en/intlayer_with_nextjs_14.md +193 -59
  31. package/en/intlayer_with_nextjs_15.md +192 -61
  32. package/en/intlayer_with_nextjs_page_router.md +396 -61
  33. package/en/intlayer_with_nuxt.md +737 -0
  34. package/en/intlayer_with_react_native+expo.md +6 -3
  35. package/en/intlayer_with_vite+preact.md +8 -27
  36. package/en/intlayer_with_vite+react.md +7 -17
  37. package/en/intlayer_with_vite+solid.md +6 -3
  38. package/en/intlayer_with_vite+svelte.md +6 -3
  39. package/en/intlayer_with_vite+vue.md +17 -6
  40. package/en/packages/nuxt-intlayer/index.md +31 -0
  41. package/en/roadmap.md +13 -13
  42. package/en/t.md +5 -5
  43. package/en-GB/how_works_intlayer.md +16 -4
  44. package/en-GB/intlayer_with_create_react_app.md +1 -14
  45. package/en-GB/intlayer_with_nextjs_14.md +1 -14
  46. package/en-GB/intlayer_with_nextjs_15.md +1 -14
  47. package/en-GB/intlayer_with_nextjs_page_router.md +1 -13
  48. package/en-GB/intlayer_with_nuxt.md +795 -0
  49. package/en-GB/intlayer_with_react_native+expo.md +6 -3
  50. package/en-GB/intlayer_with_vite+preact.md +7 -18
  51. package/en-GB/intlayer_with_vite+react.md +6 -9
  52. package/en-GB/intlayer_with_vite+vue.md +65 -59
  53. package/en-GB/packages/nuxt-intlayer/index.md +31 -0
  54. package/en-GB/roadmap.md +11 -11
  55. package/es/autoFill.md +1 -2
  56. package/es/how_works_intlayer.md +1 -1
  57. package/es/intlayer_with_create_react_app.md +1 -14
  58. package/es/intlayer_with_nextjs_14.md +1 -14
  59. package/es/intlayer_with_nextjs_15.md +1 -14
  60. package/es/intlayer_with_nextjs_page_router.md +1 -13
  61. package/es/intlayer_with_nuxt.md +731 -0
  62. package/es/intlayer_with_react_native+expo.md +6 -3
  63. package/es/intlayer_with_vite+preact.md +7 -18
  64. package/es/intlayer_with_vite+react.md +7 -17
  65. package/es/intlayer_with_vite+vue.md +64 -51
  66. package/es/packages/nuxt-intlayer/index.md +29 -0
  67. package/fr/autoFill.md +1 -2
  68. package/fr/how_works_intlayer.md +1 -1
  69. package/fr/intlayer_with_create_react_app.md +1 -14
  70. package/fr/intlayer_with_nextjs_14.md +1 -14
  71. package/fr/intlayer_with_nextjs_15.md +1 -14
  72. package/fr/intlayer_with_nextjs_page_router.md +1 -13
  73. package/fr/intlayer_with_nuxt.md +731 -0
  74. package/fr/intlayer_with_react_native+expo.md +6 -3
  75. package/fr/intlayer_with_vite+preact.md +7 -18
  76. package/fr/intlayer_with_vite+react.md +7 -17
  77. package/fr/intlayer_with_vite+vue.md +30 -15
  78. package/fr/packages/nuxt-intlayer/index.md +29 -0
  79. package/fr/roadmap.md +11 -11
  80. package/hi/autoFill.md +1 -2
  81. package/hi/how_works_intlayer.md +1 -1
  82. package/hi/intlayer_with_create_react_app.md +1 -14
  83. package/hi/intlayer_with_nextjs_14.md +1 -14
  84. package/hi/intlayer_with_nextjs_15.md +1 -14
  85. package/hi/intlayer_with_nextjs_page_router.md +1 -13
  86. package/hi/intlayer_with_nuxt.md +784 -0
  87. package/hi/intlayer_with_react_native+expo.md +6 -3
  88. package/hi/intlayer_with_vite+preact.md +7 -18
  89. package/hi/intlayer_with_vite+react.md +7 -17
  90. package/hi/intlayer_with_vite+vue.md +59 -47
  91. package/hi/packages/nuxt-intlayer/index.md +29 -0
  92. package/hi/roadmap.md +11 -11
  93. package/index.cjs +30 -0
  94. package/index.d.ts +2 -0
  95. package/it/autoFill.md +1 -2
  96. package/it/how_works_intlayer.md +1 -1
  97. package/it/intlayer_with_create_react_app.md +0 -6
  98. package/it/intlayer_with_nextjs_14.md +1 -14
  99. package/it/intlayer_with_nextjs_15.md +1 -14
  100. package/it/intlayer_with_nextjs_page_router.md +1 -13
  101. package/it/intlayer_with_nuxt.md +793 -0
  102. package/it/intlayer_with_react_native+expo.md +6 -3
  103. package/it/intlayer_with_vite+preact.md +7 -18
  104. package/it/intlayer_with_vite+react.md +7 -17
  105. package/it/intlayer_with_vite+vue.md +26 -17
  106. package/it/packages/nuxt-intlayer/index.md +29 -0
  107. package/it/roadmap.md +11 -11
  108. package/ja/autoFill.md +1 -2
  109. package/ja/how_works_intlayer.md +1 -1
  110. package/ja/intlayer_with_create_react_app.md +1 -14
  111. package/ja/intlayer_with_nextjs_14.md +1 -14
  112. package/ja/intlayer_with_nextjs_15.md +1 -14
  113. package/ja/intlayer_with_nextjs_page_router.md +1 -13
  114. package/ja/intlayer_with_nuxt.md +792 -0
  115. package/ja/intlayer_with_react_native+expo.md +6 -3
  116. package/ja/intlayer_with_vite+preact.md +7 -18
  117. package/ja/intlayer_with_vite+react.md +7 -17
  118. package/ja/intlayer_with_vite+vue.md +68 -63
  119. package/ja/packages/nuxt-intlayer/index.md +29 -0
  120. package/ja/roadmap.md +11 -11
  121. package/ko/autoFill.md +1 -2
  122. package/ko/how_works_intlayer.md +1 -1
  123. package/ko/intlayer_with_create_react_app.md +1 -14
  124. package/ko/intlayer_with_nextjs_14.md +1 -14
  125. package/ko/intlayer_with_nextjs_15.md +1 -14
  126. package/ko/intlayer_with_nextjs_page_router.md +1 -13
  127. package/ko/intlayer_with_nuxt.md +784 -0
  128. package/ko/intlayer_with_react_native+expo.md +6 -3
  129. package/ko/intlayer_with_vite+preact.md +7 -18
  130. package/ko/intlayer_with_vite+react.md +7 -17
  131. package/ko/intlayer_with_vite+vue.md +69 -59
  132. package/ko/packages/nuxt-intlayer/index.md +31 -0
  133. package/ko/roadmap.md +11 -11
  134. package/package.json +4 -4
  135. package/pt/autoFill.md +1 -2
  136. package/pt/how_works_intlayer.md +1 -1
  137. package/pt/intlayer_with_create_react_app.md +1 -14
  138. package/pt/intlayer_with_nextjs_14.md +1 -14
  139. package/pt/intlayer_with_nextjs_15.md +1 -14
  140. package/pt/intlayer_with_nextjs_page_router.md +1 -13
  141. package/pt/intlayer_with_nuxt.md +792 -0
  142. package/pt/intlayer_with_react_native+expo.md +6 -3
  143. package/pt/intlayer_with_vite+preact.md +7 -18
  144. package/pt/intlayer_with_vite+react.md +7 -17
  145. package/pt/intlayer_with_vite+vue.md +23 -19
  146. package/pt/packages/nuxt-intlayer/index.md +29 -0
  147. package/pt/roadmap.md +11 -11
  148. package/ru/autoFill.md +1 -2
  149. package/ru/how_works_intlayer.md +1 -1
  150. package/ru/intlayer_with_create_react_app.md +1 -14
  151. package/ru/intlayer_with_nextjs_14.md +1 -14
  152. package/ru/intlayer_with_nextjs_15.md +1 -14
  153. package/ru/intlayer_with_nextjs_page_router.md +1 -13
  154. package/ru/intlayer_with_nuxt.md +792 -0
  155. package/ru/intlayer_with_react_native+expo.md +6 -3
  156. package/ru/intlayer_with_vite+preact.md +7 -18
  157. package/ru/intlayer_with_vite+react.md +7 -17
  158. package/ru/intlayer_with_vite+vue.md +25 -17
  159. package/ru/packages/nuxt-intlayer/index.md +31 -0
  160. package/ru/roadmap.md +11 -11
  161. package/zh/autoFill.md +1 -2
  162. package/zh/intlayer_with_create_react_app.md +1 -14
  163. package/zh/intlayer_with_nextjs_14.md +1 -14
  164. package/zh/intlayer_with_nextjs_15.md +1 -14
  165. package/zh/intlayer_with_nextjs_page_router.md +1 -13
  166. package/zh/intlayer_with_nuxt.md +784 -0
  167. package/zh/intlayer_with_react_native+expo.md +6 -3
  168. package/zh/intlayer_with_vite+preact.md +7 -18
  169. package/zh/intlayer_with_vite+react.md +7 -17
  170. package/zh/intlayer_with_vite+vue.md +68 -57
  171. package/zh/packages/nuxt-intlayer/index.md +31 -0
  172. package/zh/roadmap.md +11 -11
@@ -529,67 +529,393 @@ const ComponentExample = () => {
529
529
  > value of the function as follows:
530
530
 
531
531
  > ```jsx
532
- >
533
- > ```
534
-
535
532
  > <img src={content.image.src.value} alt={content.image.value} />
536
-
537
- > ```
538
- >
539
533
  > ```
540
534
 
541
535
  > 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).
542
536
 
543
- ### (Optional) Step 8: Internationalize Your Metadata
537
+ ### (Optional) Step 8: Internationalization of your metadata
544
538
 
545
- To internationalize metadata such as page titles and descriptions, use the `getStaticProps` function in conjunction with Intlayer's `getTranslation` function.
539
+ In the case you want to internationalize your metadata, such as the title of your page, you can use the `getStaticProps` function provided by Next.js Page Router. Inside, you can retrieve the content from the `getIntlayer` function to translate your metadata.
546
540
 
547
- ```tsx fileName="src/pages/[locale]/index.tsx" codeFormat="typescript"
541
+ ```typescript fileName="src/pages/[locale]/metadata.content.ts" contentDeclarationFormat="typescript"
542
+ import { type Dictionary, t } from "intlayer";
543
+ import { type Metadata } from "next";
544
+
545
+ const metadataContent = {
546
+ key: "page-metadata",
547
+ content: {
548
+ title: t({
549
+ en: "Create Next App",
550
+ fr: "Créer une application Next.js",
551
+ es: "Crear una aplicación Next.js",
552
+ }),
553
+ description: t({
554
+ en: "Generated by create next app",
555
+ fr: "Généré par create next app",
556
+ es: "Generado por create next app",
557
+ }),
558
+ },
559
+ } satisfies Dictionary<Metadata>;
560
+
561
+ export default metadataContent;
562
+ ```
563
+
564
+ ```javascript fileName="src/pages/[locale]/metadata.content.mjs" contentDeclarationFormat="esm"
565
+ import { t } from "intlayer";
566
+
567
+ /** @type {import('intlayer').Dictionary<import('next').Metadata>} */
568
+ const metadataContent = {
569
+ key: "page-metadata",
570
+ content: {
571
+ title: t({
572
+ en: "Create Next App",
573
+ fr: "Créer une application Next.js",
574
+ es: "Crear una aplicación Next.js",
575
+ }),
576
+ description: t({
577
+ en: "Generated by create next app",
578
+ fr: "Généré par create next app",
579
+ es: "Generado por create next app",
580
+ }),
581
+ },
582
+ };
583
+
584
+ export default metadataContent;
585
+ ```
586
+
587
+ ```javascript fileName="src/pages/[locale]/metadata.content.cjs" contentDeclarationFormat="commonjs"
588
+ const { t } = require("intlayer");
589
+
590
+ /** @type {import('intlayer').Dictionary<import('next').Metadata>} */
591
+ const metadataContent = {
592
+ key: "page-metadata",
593
+ content: {
594
+ title: t({
595
+ en: "Create Next App",
596
+ fr: "Créer une application Next.js",
597
+ es: "Crear una aplicación Next.js",
598
+ }),
599
+ description: t({
600
+ en: "Generated by create next app",
601
+ fr: "Généré par create next app",
602
+ es: "Generado por create next app",
603
+ }),
604
+ },
605
+ };
606
+
607
+ module.exports = metadataContent;
608
+ ```
609
+
610
+ ```json fileName="src/pages/[locale]/metadata.content.json" contentDeclarationFormat="json"
611
+ {
612
+ "key": "page-metadata",
613
+ "content": {
614
+ "title": {
615
+ "nodeType": "translation",
616
+ "translation": {
617
+ "en": "Preact logo",
618
+ "fr": "Logo Preact",
619
+ "es": "Logo Preact",
620
+ },
621
+ },
622
+ "description": {
623
+ "nodeType": "translation",
624
+ "translation": {
625
+ "en": "Generated by create next app",
626
+ "fr": "Généré par create next app",
627
+ "es": "Generado por create next app",
628
+ },
629
+ },
630
+ },
631
+ };
632
+ ```
633
+
634
+ ````tsx fileName="src/pages/[locale]/index.tsx" codeFormat="typescript"
548
635
  import { GetStaticPaths, GetStaticProps } from "next";
549
- import { type IConfigLocales, getTranslation, Locales } from "intlayer";
636
+ import { getIntlayer, getMultilingualUrls } from "intlayer";
550
637
  import { useIntlayer } from "next-intlayer";
638
+ import Head from "next/head";
639
+ import type { FC } from "react";
551
640
 
552
641
  interface HomePageProps {
553
642
  locale: string;
554
- metadata: Metadata;
643
+ metadata: {
644
+ title: string;
645
+ description: string;
646
+ };
647
+ multilingualUrls: Record<string, string>;
555
648
  }
556
649
 
557
- const HomePage = ({ metadata }: HomePageProps) => {
558
- // Metadata can be used in the head or other components as needed
650
+ const HomePage: FC<HomePageProps> = ({
651
+ metadata,
652
+ multilingualUrls,
653
+ locale,
654
+ }) => {
655
+ const content = useIntlayer("page");
656
+
559
657
  return (
560
658
  <div>
561
659
  <Head>
562
660
  <title>{metadata.title}</title>
563
661
  <meta name="description" content={metadata.description} />
662
+ {/* Generate hreflang tags for SEO */}
663
+ {Object.entries(multilingualUrls).map(([lang, url]) => (
664
+ <link key={lang} rel="alternate" hrefLang={lang} href={url} />
665
+ ))}
666
+ <link rel="canonical" href={multilingualUrls[locale]} />
564
667
  </Head>
565
668
 
566
- {/* Additional content */}
669
+ {/* Page content */}
670
+ <main>{/* Your page content here */}</main>
567
671
  </div>
568
672
  );
569
673
  };
570
674
 
571
- export const getStaticProps: GetStaticProps = async ({ params }) => {
675
+ export const getStaticProps: GetStaticProps<HomePageProps> = async ({
676
+ params,
677
+ }) => {
572
678
  const locale = params?.locale as string;
573
679
 
574
- const t = <T,>(content: IConfigLocales<T>) => getTranslation(content, locale);
680
+ const metadata = getIntlayer("page-metadata", locale);
681
+
682
+ /**
683
+ * Generates an object containing all url for each locale.
684
+ *
685
+ * Example:
686
+ * ```ts
687
+ * getMultilingualUrls('/about');
688
+ *
689
+ * // Returns
690
+ * // {
691
+ * // en: '/about',
692
+ * // fr: '/fr/about',
693
+ * // es: '/es/about',
694
+ * // }
695
+ * ```
696
+ */
697
+ const multilingualUrls = getMultilingualUrls("/");
698
+
699
+ return {
700
+ props: {
701
+ locale,
702
+ metadata,
703
+ multilingualUrls,
704
+ },
705
+ };
706
+ };
707
+
708
+ export default HomePage;
709
+
710
+ // ... Rest of the code including getStaticPaths
711
+ ````
712
+
713
+ ````jsx fileName="src/pages/[locale]/index.mjx" codeFormat="esm"
714
+ import { getIntlayer, getMultilingualUrls } from "intlayer";
715
+ import { useIntlayer } from "next-intlayer";
716
+ import Head from "next/head";
717
+
718
+ const HomePage = ({ metadata, multilingualUrls, locale }) => {
719
+ const content = useIntlayer("page");
720
+
721
+ return (
722
+ <div>
723
+ <Head>
724
+ <title>{metadata.title}</title>
725
+ <meta name="description" content={metadata.description} />
726
+ {/* Generate hreflang tags for SEO */}
727
+ {Object.entries(multilingualUrls).map(([lang, url]) => (
728
+ <link key={lang} rel="alternate" hrefLang={lang} href={url} />
729
+ ))}
730
+ <link rel="canonical" href={multilingualUrls[locale]} />
731
+ </Head>
732
+
733
+ {/* Page content */}
734
+ <main>{/* Your page content here */}</main>
735
+ </div>
736
+ );
737
+ };
738
+
739
+ export const getStaticProps = async ({ params }) => {
740
+ const locale = params?.locale;
741
+
742
+ const metadata = getIntlayer("page-metadata", locale);
743
+
744
+ /**
745
+ * Generates an object containing all url for each locale.
746
+ *
747
+ * Example:
748
+ * ```ts
749
+ * getMultilingualUrls('/about');
750
+ *
751
+ * // Returns
752
+ * // {
753
+ * // en: '/about',
754
+ * // fr: '/fr/about',
755
+ * // es: '/es/about',
756
+ * // }
757
+ * ```
758
+ */
759
+ const multilingualUrls = getMultilingualUrls("/");
760
+
761
+ return {
762
+ props: {
763
+ locale,
764
+ metadata,
765
+ multilingualUrls,
766
+ },
767
+ };
768
+ };
769
+
770
+ export default HomePage;
771
+
772
+ // ... Rest of the code including getStaticPaths
773
+ ````
774
+
775
+ ````jsx fileName="src/pages/[locale]/index.csx" codeFormat="commonjs"
776
+ const { getIntlayer, getMultilingualUrls } = require("intlayer");
777
+ const { useIntlayer } = require("next-intlayer");
778
+ const Head = require("next/head");
779
+
780
+ const HomePage = ({ metadata, multilingualUrls, locale }) => {
781
+ const content = useIntlayer("page");
782
+
783
+ return (
784
+ <div>
785
+ <Head>
786
+ <title>{metadata.title}</title>
787
+ <meta name="description" content={metadata.description} />
788
+ {/* Generate hreflang tags for SEO */}
789
+ {Object.entries(multilingualUrls).map(([lang, url]) => (
790
+ <link key={lang} rel="alternate" hrefLang={lang} href={url} />
791
+ ))}
792
+ <link rel="canonical" href={multilingualUrls[locale]} />
793
+ </Head>
794
+
795
+ {/* Page content */}
796
+ <main>{/* Your page content here */}</main>
797
+ </div>
798
+ );
799
+ };
800
+
801
+ const getStaticProps = async ({ params }) => {
802
+ const locale = params?.locale;
803
+
804
+ const metadata = getIntlayer("page-metadata", locale);
805
+
806
+ /**
807
+ * Generates an object containing all url for each locale.
808
+ *
809
+ * Example:
810
+ * ```ts
811
+ * getMultilingualUrls('/about');
812
+ *
813
+ * // Returns
814
+ * // {
815
+ * // en: '/about',
816
+ * // fr: '/fr/about',
817
+ * // es: '/es/about',
818
+ * // }
819
+ * ```
820
+ */
821
+ const multilingualUrls = getMultilingualUrls("/");
822
+
823
+ return {
824
+ props: {
825
+ locale,
826
+ metadata,
827
+ multilingualUrls,
828
+ },
829
+ };
830
+ };
831
+
832
+ module.exports = {
833
+ getStaticProps,
834
+ getStaticPaths,
835
+ default: HomePage,
836
+ };
837
+
838
+ // ... Rest of the code including getStaticPaths
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
+ ```tsx fileName="src/pages/[locale]/index.tsx" codeFormat="typescript"
846
+ import { GetStaticPaths, GetStaticProps } from "next";
847
+ import {
848
+ type IConfigLocales,
849
+ getTranslation,
850
+ getMultilingualUrls,
851
+ } from "intlayer";
852
+ import { useIntlayer } from "next-intlayer";
853
+ import Head from "next/head";
854
+ import type { FC } from "react";
855
+
856
+ interface HomePageProps {
857
+ locale: string;
858
+ metadata: {
859
+ title: string;
860
+ description: string;
861
+ };
862
+ multilingualUrls: Record<string, string>;
863
+ }
864
+
865
+ const HomePage: FC<HomePageProps> = ({ metadata, multilingualUrls, locale }) => {
866
+ const content = useIntlayer("page");
867
+
868
+ return (
869
+ <div>
870
+ <Head>
871
+ <title>{metadata.title}</title>
872
+ <meta name="description" content={metadata.description} />
873
+ {/* Generate hreflang tags for SEO */}
874
+ {Object.entries(multilingualUrls).map(([lang, url]) => (
875
+ <link
876
+ key={lang}
877
+ rel="alternate"
878
+ hrefLang={lang}
879
+ href={url}
880
+ />
881
+ ))}
882
+ <link rel="canonical" href={multilingualUrls[locale]} />
883
+ </Head>
884
+
885
+ {/* Page content */}
886
+ <main>
887
+ {/* Your page content here */}
888
+ </main>
889
+ </div>
890
+ );
891
+ };
892
+
893
+ export const getStaticProps: GetStaticProps<HomePageProps> = async ({
894
+ params
895
+ }) => {
896
+ const locale = params?.locale as string;
897
+ const t = <T>(content: IConfigLocales<T>) => getTranslation(content, locale);
575
898
 
576
899
  const metadata = {
577
- title: t({
578
- en: "My Website",
579
- fr: "Mon Site Web",
580
- es: "Mi Sitio Web",
900
+ title: t<string>({
901
+ en: "My title",
902
+ fr: "Mon titre",
903
+ es: "Mi título",
581
904
  }),
582
905
  description: t({
583
- en: "Welcome to my website.",
584
- fr: "Bienvenue sur mon site Web.",
585
- es: "Bienvenido a mi sitio web.",
906
+ en: "My description",
907
+ fr: "Ma description",
908
+ es: "Mi descripción",
586
909
  }),
587
910
  };
588
911
 
912
+ const multilingualUrls = getMultilingualUrls("/");
913
+
589
914
  return {
590
915
  props: {
591
916
  locale,
592
917
  metadata,
918
+ multilingualUrls,
593
919
  },
594
920
  };
595
921
  };
@@ -600,49 +926,55 @@ export default HomePage;
600
926
  ```
601
927
 
602
928
  ```jsx fileName="src/pages/[locale]/index.mjx" codeFormat="esm"
603
- import { GetStaticPaths, GetStaticProps } from "next";
604
- import { type IConfigLocales, getTranslation, Locales } from "intlayer";
929
+ import { getTranslation, getMultilingualUrls } from "intlayer";
605
930
  import { useIntlayer } from "next-intlayer";
931
+ import Head from "next/head";
606
932
 
933
+ const HomePage = ({ metadata, multilingualUrls, locale }) => {
934
+ const content = useIntlayer("page");
607
935
 
608
-
609
- const HomePage = ({ metadata }) => {
610
- // Metadata can be used in the head or other components as needed
611
936
  return (
612
937
  <div>
613
938
  <Head>
614
939
  <title>{metadata.title}</title>
615
940
  <meta name="description" content={metadata.description} />
941
+ {/* Generate hreflang tags for SEO */}
942
+ {Object.entries(multilingualUrls).map(([lang, url]) => (
943
+ <link key={lang} rel="alternate" hrefLang={lang} href={url} />
944
+ ))}
945
+ <link rel="canonical" href={multilingualUrls[locale]} />
616
946
  </Head>
617
947
 
618
- {/* Additional content */}
948
+ {/* Page content */}
949
+ <main>{/* Your page content here */}</main>
619
950
  </div>
620
951
  );
621
952
  };
622
953
 
623
954
  export const getStaticProps = async ({ params }) => {
624
- const locale = params?.locale as string;
625
-
626
- const t = (content) =>
627
- getTranslation(content, locale);
955
+ const locale = params?.locale;
956
+ const t = (content) => getTranslation(content, locale);
628
957
 
629
958
  const metadata = {
630
959
  title: t({
631
- en: "My Website",
632
- fr: "Mon Site Web",
633
- es: "Mi Sitio Web",
960
+ en: "My title",
961
+ fr: "Mon titre",
962
+ es: "Mi título",
634
963
  }),
635
964
  description: t({
636
- en: "Welcome to my website.",
637
- fr: "Bienvenue sur mon site Web.",
638
- es: "Bienvenido a mi sitio web.",
965
+ en: "My description",
966
+ fr: "Ma description",
967
+ es: "Mi descripción",
639
968
  }),
640
969
  };
641
970
 
971
+ const multilingualUrls = getMultilingualUrls("/");
972
+
642
973
  return {
643
974
  props: {
644
975
  locale,
645
976
  metadata,
977
+ multilingualUrls,
646
978
  },
647
979
  };
648
980
  };
@@ -653,48 +985,55 @@ export default HomePage;
653
985
  ```
654
986
 
655
987
  ```jsx fileName="src/pages/[locale]/index.csx" codeFormat="commonjs"
656
- const { GetStaticPaths, GetStaticProps } = require("next");
657
- const { type IConfigLocales, getTranslation, Locales } = require("intlayer");
988
+ const { getTranslation, getMultilingualUrls } = require("intlayer");
658
989
  const { useIntlayer } = require("next-intlayer");
990
+ const Head = require("next/head");
659
991
 
992
+ const HomePage = ({ metadata, multilingualUrls, locale }) => {
993
+ const content = useIntlayer("page");
660
994
 
661
- const HomePage = ({ metadata }) => {
662
- // Metadata can be used in the head or other components as needed
663
995
  return (
664
996
  <div>
665
997
  <Head>
666
998
  <title>{metadata.title}</title>
667
999
  <meta name="description" content={metadata.description} />
1000
+ {/* Generate hreflang tags for SEO */}
1001
+ {Object.entries(multilingualUrls).map(([lang, url]) => (
1002
+ <link key={lang} rel="alternate" hrefLang={lang} href={url} />
1003
+ ))}
1004
+ <link rel="canonical" href={multilingualUrls[locale]} />
668
1005
  </Head>
669
1006
 
670
- {/* Additional content */}
1007
+ {/* Page content */}
1008
+ <main>{/* Your page content here */}</main>
671
1009
  </div>
672
1010
  );
673
1011
  };
674
1012
 
675
1013
  const getStaticProps = async ({ params }) => {
676
1014
  const locale = params?.locale;
677
-
678
- const t = (content) =>
679
- getTranslation(content, locale);
1015
+ const t = (content) => getTranslation(content, locale);
680
1016
 
681
1017
  const metadata = {
682
1018
  title: t({
683
- en: "My Website",
684
- fr: "Mon Site Web",
685
- es: "Mi Sitio Web",
1019
+ en: "My title",
1020
+ fr: "Mon titre",
1021
+ es: "Mi título",
686
1022
  }),
687
1023
  description: t({
688
- en: "Welcome to my website.",
689
- fr: "Bienvenue sur mon site Web.",
690
- es: "Bienvenido a mi sitio web.",
1024
+ en: "My description",
1025
+ fr: "Ma description",
1026
+ es: "Mi descripción",
691
1027
  }),
692
1028
  };
693
1029
 
1030
+ const multilingualUrls = getMultilingualUrls("/");
1031
+
694
1032
  return {
695
1033
  props: {
696
1034
  locale,
697
1035
  metadata,
1036
+ multilingualUrls,
698
1037
  },
699
1038
  };
700
1039
  };
@@ -708,7 +1047,9 @@ module.exports = {
708
1047
  // ... Rest of the code including getStaticPaths
709
1048
  ```
710
1049
 
711
- ### (Optional) Step 9: Change the Language of Your Content
1050
+ > Learn more about the metadata optimization [on the official Next.js documentation](https://nextjs.org/docs/pages/building-your-application/optimizing/metadata).
1051
+
1052
+ ### (Optional) Step 9: Change the language of your content
712
1053
 
713
1054
  To change the language of your content in Next.js, the recommended way is to use the `Link` component to redirect users to the appropriate localized page. The `Link` component enables prefetching of the page, which helps avoid a full page reload.
714
1055
 
@@ -889,19 +1230,13 @@ return (
889
1230
  > The `useLocalePageRouter` API is the same as `useLocale`. To Learn more about the `useLocale` hook, refer to the [documentation](https://github.com/aymericzip/intlayer/blob/main/docs/en/packages/next-intlayer/useLocale.md).
890
1231
 
891
1232
  > Documentation references:
892
-
1233
+ >
893
1234
  > - [`getLocaleName` hook](https://github.com/aymericzip/intlayer/blob/main/docs/en/packages/intlayer/getLocaleName.md)
894
-
895
1235
  > - [`getLocalizedUrl` hook](https://github.com/aymericzip/intlayer/blob/main/docs/en/packages/intlayer/getLocalizedUrl.md)
896
-
897
1236
  > - [`getHTMLTextDir` hook](https://github.com/aymericzip/intlayer/blob/main/docs/en/packages/intlayer/getHTMLTextDir.md)
898
-
899
1237
  > - [`hrefLang` attribute](https://developers.google.com/search/docs/specialty/international/localized-versions?hl=fr)
900
-
901
1238
  > - [`lang` attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/lang)
902
-
903
1239
  > - [`dir` attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/dir)
904
-
905
1240
  > - [`aria-current` attribute](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-current)
906
1241
 
907
1242
  ### (Optional) Step 10: Creating a Localized Link Component