@intlayer/docs 7.0.7 → 7.0.8
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/ar/i18n_using_next-i18next.md +1068 -0
- package/blog/ar/i18n_using_next-intl.md +768 -0
- package/blog/ar/intlayer_with_react-intl.md +0 -4
- package/blog/ar/next-i18next_vs_next-intl_vs_intlayer.md +5 -4
- package/blog/de/i18n_using_next-i18next.md +1107 -0
- package/blog/de/i18n_using_next-intl.md +760 -0
- package/blog/de/intlayer_with_react-intl.md +0 -4
- package/blog/de/next-i18next_vs_next-intl_vs_intlayer.md +2 -0
- package/blog/en/i18n_using_next-i18next.md +1073 -0
- package/blog/en/i18n_using_next-intl.md +757 -0
- package/blog/en/intlayer_with_i18next.md +71 -8
- package/blog/en/intlayer_with_next-i18next.md +71 -8
- package/blog/en/intlayer_with_next-intl.md +71 -8
- package/blog/en/intlayer_with_react-i18next.md +69 -8
- package/blog/en/intlayer_with_react-intl.md +68 -9
- package/blog/en/intlayer_with_vue-i18n.md +68 -7
- package/blog/en/react-i18next_vs_react-intl_vs_intlayer.md +2 -0
- package/blog/en/vue-i18n_vs_intlayer.md +2 -0
- package/blog/en-GB/i18n_using_next-i18next.md +1074 -0
- package/blog/en-GB/i18n_using_next-intl.md +757 -0
- package/blog/en-GB/intlayer_with_i18next.md +15 -6
- package/blog/en-GB/intlayer_with_next-i18next.md +16 -6
- package/blog/en-GB/intlayer_with_next-intl.md +16 -6
- package/blog/en-GB/intlayer_with_react-i18next.md +16 -7
- package/blog/en-GB/intlayer_with_react-intl.md +14 -9
- package/blog/en-GB/intlayer_with_vue-i18n.md +16 -7
- package/blog/en-GB/next-i18next_vs_next-intl_vs_intlayer.md +2 -0
- package/blog/en-GB/react-i18next_vs_react-intl_vs_intlayer.md +2 -0
- package/blog/en-GB/vue-i18n_vs_intlayer.md +2 -0
- package/blog/es/i18n_using_next-i18next.md +1066 -0
- package/blog/es/i18n_using_next-intl.md +757 -0
- package/blog/es/intlayer_with_react-intl.md +0 -4
- package/blog/es/next-i18next_vs_next-intl_vs_intlayer.md +2 -0
- package/blog/fr/i18n_using_next-i18next.md +1078 -0
- package/blog/fr/i18n_using_next-intl.md +759 -0
- package/blog/fr/intlayer_with_react-intl.md +0 -4
- package/blog/fr/next-i18next_vs_next-intl_vs_intlayer.md +2 -0
- package/blog/hi/i18n_using_next-i18next.md +1068 -0
- package/blog/hi/i18n_using_next-intl.md +758 -0
- package/blog/hi/intlayer_with_react-intl.md +0 -4
- package/blog/hi/next-i18next_vs_next-intl_vs_intlayer.md +2 -0
- package/blog/id/i18n_using_next-i18next.md +1078 -0
- package/blog/id/i18n_using_next-intl.md +757 -0
- package/blog/id/index.md +69 -0
- package/blog/id/internationalization_and_SEO.md +364 -0
- package/blog/id/intlayer_with_react-intl.md +0 -4
- package/blog/id/list_i18n_technologies/CMS/drupal.md +143 -0
- package/blog/id/list_i18n_technologies/CMS/wix.md +167 -0
- package/blog/id/list_i18n_technologies/CMS/wordpress.md +188 -0
- package/blog/id/list_i18n_technologies/frameworks/angular.md +125 -0
- package/blog/id/list_i18n_technologies/frameworks/flutter.md +150 -0
- package/blog/id/list_i18n_technologies/frameworks/react-native.md +217 -0
- package/blog/id/list_i18n_technologies/frameworks/react.md +155 -0
- package/blog/id/list_i18n_technologies/frameworks/svelte.md +131 -0
- package/blog/id/list_i18n_technologies/frameworks/vue.md +130 -0
- package/blog/id/next-i18next_vs_next-intl_vs_intlayer.md +1500 -0
- package/blog/id/nextjs-multilingual-seo-comparison.md +361 -0
- package/blog/id/rag_powered_documentation_assistant.md +288 -0
- package/blog/id/react-i18next_vs_react-intl_vs_intlayer.md +164 -0
- package/blog/id/vue-i18n_vs_intlayer.md +278 -0
- package/blog/id/what_is_internationalization.md +166 -0
- package/blog/it/i18n_using_next-i18next.md +1078 -0
- package/blog/it/i18n_using_next-intl.md +758 -0
- package/blog/it/intlayer_with_react-intl.md +0 -4
- package/blog/it/react-i18next_vs_react-intl_vs_intlayer.md +4 -0
- package/blog/it/vue-i18n_vs_intlayer.md +2 -0
- package/blog/ja/i18n_using_next-i18next.md +1078 -0
- package/blog/ja/i18n_using_next-intl.md +758 -0
- package/blog/ja/intlayer_with_react-intl.md +0 -4
- package/blog/ja/next-i18next_vs_next-intl_vs_intlayer.md +2 -0
- package/blog/ko/i18n_using_next-i18next.md +1075 -0
- package/blog/ko/i18n_using_next-intl.md +759 -0
- package/blog/ko/intlayer_with_react-intl.md +0 -4
- package/blog/ko/next-i18next_vs_next-intl_vs_intlayer.md +2 -0
- package/blog/pl/i18n_using_next-i18next.md +1078 -0
- package/blog/pl/i18n_using_next-intl.md +758 -0
- package/blog/pl/index.md +69 -0
- package/blog/pl/internationalization_and_SEO.md +363 -0
- package/blog/pl/intlayer_with_react-intl.md +0 -4
- package/blog/pl/list_i18n_technologies/CMS/drupal.md +143 -0
- package/blog/pl/list_i18n_technologies/CMS/wix.md +167 -0
- package/blog/pl/list_i18n_technologies/CMS/wordpress.md +196 -0
- package/blog/pl/list_i18n_technologies/frameworks/angular.md +125 -0
- package/blog/pl/list_i18n_technologies/frameworks/flutter.md +151 -0
- package/blog/pl/list_i18n_technologies/frameworks/react-native.md +217 -0
- package/blog/pl/list_i18n_technologies/frameworks/react.md +155 -0
- package/blog/pl/list_i18n_technologies/frameworks/svelte.md +131 -0
- package/blog/pl/list_i18n_technologies/frameworks/vue.md +130 -0
- package/blog/pl/next-i18next_vs_next-intl_vs_intlayer.md +1501 -0
- package/blog/pl/nextjs-multilingual-seo-comparison.md +362 -0
- package/blog/pl/rag_powered_documentation_assistant.md +288 -0
- package/blog/pl/react-i18next_vs_react-intl_vs_intlayer.md +164 -0
- package/blog/pl/vue-i18n_vs_intlayer.md +278 -0
- package/blog/pl/what_is_internationalization.md +167 -0
- package/blog/pt/i18n_using_next-i18next.md +1067 -0
- package/blog/pt/i18n_using_next-intl.md +760 -0
- package/blog/pt/next-i18next_vs_next-intl_vs_intlayer.md +2 -0
- package/blog/ru/i18n_using_next-i18next.md +1106 -0
- package/blog/ru/i18n_using_next-intl.md +759 -0
- package/blog/ru/intlayer_with_react-intl.md +0 -4
- package/blog/ru/next-i18next_vs_next-intl_vs_intlayer.md +2 -0
- package/blog/tr/i18n_using_next-i18next.md +1078 -0
- package/blog/tr/i18n_using_next-intl.md +760 -0
- package/blog/tr/intlayer_with_react-intl.md +0 -4
- package/blog/tr/next-i18next_vs_next-intl_vs_intlayer.md +2 -0
- package/blog/tr/react-i18next_vs_react-intl_vs_intlayer.md +2 -0
- package/blog/tr/vue-i18n_vs_intlayer.md +2 -0
- package/blog/vi/i18n_using_next-i18next.md +1080 -0
- package/blog/vi/i18n_using_next-intl.md +758 -0
- package/blog/vi/index.md +69 -0
- package/blog/vi/internationalization_and_SEO.md +363 -0
- package/blog/vi/intlayer_with_react-intl.md +0 -4
- package/blog/vi/list_i18n_technologies/CMS/drupal.md +143 -0
- package/blog/vi/list_i18n_technologies/CMS/wix.md +167 -0
- package/blog/vi/list_i18n_technologies/CMS/wordpress.md +188 -0
- package/blog/vi/list_i18n_technologies/frameworks/angular.md +125 -0
- package/blog/vi/list_i18n_technologies/frameworks/flutter.md +150 -0
- package/blog/vi/list_i18n_technologies/frameworks/react-native.md +217 -0
- package/blog/vi/list_i18n_technologies/frameworks/react.md +155 -0
- package/blog/vi/list_i18n_technologies/frameworks/svelte.md +131 -0
- package/blog/vi/list_i18n_technologies/frameworks/vue.md +130 -0
- package/blog/vi/next-i18next_vs_next-intl_vs_intlayer.md +1520 -0
- package/blog/vi/nextjs-multilingual-seo-comparison.md +362 -0
- package/blog/vi/rag_powered_documentation_assistant.md +288 -0
- package/blog/vi/react-i18next_vs_react-intl_vs_intlayer.md +164 -0
- package/blog/vi/vue-i18n_vs_intlayer.md +278 -0
- package/blog/vi/what_is_internationalization.md +168 -0
- package/blog/zh/i18n_using_next-i18next.md +1105 -0
- package/blog/zh/i18n_using_next-intl.md +758 -0
- package/blog/zh/intlayer_with_react-intl.md +0 -4
- package/blog/zh/next-i18next_vs_next-intl_vs_intlayer.md +2 -0
- package/blog/zh/react-i18next_vs_react-intl_vs_intlayer.md +2 -0
- package/dist/cjs/common.cjs +0 -4
- package/dist/cjs/common.cjs.map +1 -1
- package/dist/cjs/generated/blog.entry.cjs +38 -6
- package/dist/cjs/generated/blog.entry.cjs.map +1 -1
- package/dist/cjs/generated/docs.entry.cjs +0 -6
- package/dist/cjs/generated/docs.entry.cjs.map +1 -1
- package/dist/cjs/generated/frequentQuestions.entry.cjs +0 -6
- package/dist/cjs/generated/frequentQuestions.entry.cjs.map +1 -1
- package/dist/cjs/generated/legal.entry.cjs +0 -6
- package/dist/cjs/generated/legal.entry.cjs.map +1 -1
- package/dist/esm/generated/blog.entry.mjs +38 -0
- package/dist/esm/generated/blog.entry.mjs.map +1 -1
- package/dist/types/generated/blog.entry.d.ts +2 -0
- package/dist/types/generated/blog.entry.d.ts.map +1 -1
- package/docs/ar/component_i18n.md +1 -1
- package/docs/ar/configuration.md +6 -0
- package/docs/ar/intlayer_cli.md +8 -3
- package/docs/ar/intlayer_with_next-i18next.md +619 -0
- package/docs/ar/intlayer_with_next-intl.md +446 -0
- package/docs/ar/intlayer_with_nextjs_16.md +21 -0
- package/docs/ar/intlayer_with_tanstack.md +4 -0
- package/docs/ar/intlayer_with_vite+react.md +4 -0
- package/docs/de/component_i18n.md +1 -1
- package/docs/de/configuration.md +6 -0
- package/docs/de/intlayer_cli.md +8 -3
- package/docs/de/intlayer_with_next-i18next.md +627 -0
- package/docs/de/intlayer_with_next-intl.md +451 -0
- package/docs/de/intlayer_with_nextjs_16.md +21 -0
- package/docs/de/intlayer_with_tanstack.md +4 -0
- package/docs/de/intlayer_with_vite+react.md +4 -0
- package/docs/en/component_i18n.md +1 -1
- package/docs/en/intlayer_cli.md +8 -1
- package/docs/en/intlayer_with_astro.md +10 -2
- package/docs/en/intlayer_with_create_react_app.md +8 -0
- package/docs/en/intlayer_with_lynx+react.md +8 -0
- package/docs/en/intlayer_with_nestjs.md +10 -0
- package/docs/en/intlayer_with_nextjs_14.md +10 -2
- package/docs/en/intlayer_with_nextjs_15.md +21 -4
- package/docs/en/intlayer_with_nextjs_16.md +17 -0
- package/docs/en/intlayer_with_nuxt.md +8 -0
- package/docs/en/intlayer_with_react_native+expo.md +10 -2
- package/docs/en/intlayer_with_react_router_v7.md +8 -0
- package/docs/en/intlayer_with_tanstack.md +10 -0
- package/docs/en/intlayer_with_vite+preact.md +10 -2
- package/docs/en/intlayer_with_vite+react.md +21 -4
- package/docs/en/intlayer_with_vite+vue.md +10 -2
- package/docs/en-GB/component_i18n.md +1 -1
- package/docs/en-GB/configuration.md +6 -0
- package/docs/en-GB/intlayer_cli.md +8 -3
- package/docs/en-GB/intlayer_with_angular.md +4 -4
- package/docs/en-GB/intlayer_with_express.md +4 -4
- package/docs/en-GB/intlayer_with_lynx+react.md +12 -12
- package/{blog/en/_intlayer_with_next-i18next.md → docs/en-GB/intlayer_with_next-i18next.md} +241 -42
- package/{blog/en/_intlayer_with_next-intl.md → docs/en-GB/intlayer_with_next-intl.md} +144 -29
- package/docs/en-GB/intlayer_with_nextjs_16.md +21 -0
- package/docs/en-GB/intlayer_with_tanstack.md +5 -1
- package/docs/en-GB/intlayer_with_vite+react.md +4 -0
- package/docs/en-GB/packages/next-intlayer/t.md +2 -2
- package/docs/es/component_i18n.md +1 -1
- package/docs/es/configuration.md +6 -0
- package/docs/es/intlayer_cli.md +8 -3
- package/docs/es/intlayer_with_next-i18next.md +628 -0
- package/docs/es/intlayer_with_next-intl.md +446 -0
- package/docs/es/intlayer_with_nextjs_16.md +21 -0
- package/docs/es/intlayer_with_tanstack.md +4 -0
- package/docs/es/intlayer_with_vite+react.md +4 -0
- package/docs/fr/configuration.md +6 -0
- package/docs/fr/intlayer_cli.md +8 -3
- package/docs/fr/intlayer_with_next-i18next.md +628 -0
- package/docs/fr/intlayer_with_next-intl.md +446 -0
- package/docs/fr/intlayer_with_nextjs_16.md +23 -2
- package/docs/fr/intlayer_with_tanstack.md +4 -0
- package/docs/fr/intlayer_with_vite+react.md +4 -0
- package/docs/hi/component_i18n.md +1 -1
- package/docs/hi/configuration.md +6 -0
- package/docs/hi/intlayer_cli.md +8 -0
- package/docs/hi/intlayer_with_next-i18next.md +628 -0
- package/docs/hi/intlayer_with_next-intl.md +446 -0
- package/docs/hi/intlayer_with_nextjs_16.md +21 -0
- package/docs/hi/intlayer_with_tanstack.md +4 -0
- package/docs/hi/intlayer_with_vite+react.md +4 -0
- package/docs/id/CI_CD.md +198 -0
- package/docs/id/autoFill.md +284 -0
- package/docs/id/component_i18n.md +186 -0
- package/docs/id/configuration.md +710 -0
- package/docs/id/dictionary/condition.md +231 -0
- package/docs/id/dictionary/content_file.md +1092 -0
- package/docs/id/dictionary/enumeration.md +245 -0
- package/docs/id/dictionary/file.md +237 -0
- package/docs/id/dictionary/function_fetching.md +214 -0
- package/docs/id/dictionary/gender.md +273 -0
- package/docs/id/dictionary/insertion.md +192 -0
- package/docs/id/dictionary/markdown.md +381 -0
- package/docs/id/dictionary/nesting.md +273 -0
- package/docs/id/dictionary/translation.md +310 -0
- package/docs/id/formatters.md +596 -0
- package/docs/id/how_works_intlayer.md +256 -0
- package/docs/id/index.md +176 -0
- package/docs/id/interest_of_intlayer.md +293 -0
- package/docs/id/intlayer_CMS.md +549 -0
- package/docs/id/intlayer_cli.md +850 -0
- package/docs/id/intlayer_visual_editor.md +288 -0
- package/docs/id/intlayer_with_angular.md +694 -0
- package/docs/id/intlayer_with_astro.md +252 -0
- package/docs/id/intlayer_with_create_react_app.md +1233 -0
- package/docs/id/intlayer_with_express.md +411 -0
- package/docs/id/intlayer_with_lynx+react.md +518 -0
- package/docs/id/intlayer_with_nestjs.md +272 -0
- package/docs/id/intlayer_with_next-i18next.md +628 -0
- package/docs/id/intlayer_with_next-intl.md +446 -0
- package/docs/id/intlayer_with_nextjs_14.md +1617 -0
- package/docs/id/intlayer_with_nextjs_15.md +1698 -0
- package/docs/id/intlayer_with_nextjs_16.md +21 -0
- package/docs/id/intlayer_with_nextjs_page_router.md +1478 -0
- package/docs/id/intlayer_with_nuxt.md +808 -0
- package/docs/id/intlayer_with_react_native+expo.md +699 -0
- package/docs/id/intlayer_with_react_router_v7.md +496 -0
- package/docs/id/intlayer_with_tanstack.md +564 -0
- package/docs/id/intlayer_with_vite+preact.md +1737 -0
- package/docs/id/intlayer_with_vite+react.md +1413 -0
- package/docs/id/intlayer_with_vite+solid.md +289 -0
- package/docs/id/intlayer_with_vite+svelte.md +289 -0
- package/docs/id/intlayer_with_vite+vue.md +1088 -0
- package/docs/id/introduction.md +218 -0
- package/docs/id/locale_mapper.md +242 -0
- package/docs/id/mcp_server.md +211 -0
- package/docs/id/packages/express-intlayer/t.md +458 -0
- package/docs/id/packages/intlayer/getConfiguration.md +145 -0
- package/docs/id/packages/intlayer/getEnumeration.md +159 -0
- package/docs/id/packages/intlayer/getHTMLTextDir.md +122 -0
- package/docs/id/packages/intlayer/getLocaleLang.md +81 -0
- package/docs/id/packages/intlayer/getLocaleName.md +119 -0
- package/docs/id/packages/intlayer/getLocalizedUrl.md +309 -0
- package/docs/id/packages/intlayer/getMultilingualUrls.md +223 -0
- package/docs/id/packages/intlayer/getPathWithoutLocale.md +75 -0
- package/docs/id/packages/intlayer/getTranslation.md +190 -0
- package/docs/id/packages/intlayer/getTranslationContent.md +188 -0
- package/docs/id/packages/next-intlayer/t.md +352 -0
- package/docs/id/packages/next-intlayer/useDictionary.md +271 -0
- package/docs/id/packages/next-intlayer/useIntlayer.md +264 -0
- package/docs/id/packages/next-intlayer/useLocale.md +166 -0
- package/docs/id/packages/react-intlayer/t.md +303 -0
- package/docs/id/packages/react-intlayer/useDictionary.md +287 -0
- package/docs/id/packages/react-intlayer/useI18n.md +267 -0
- package/docs/id/packages/react-intlayer/useIntlayer.md +254 -0
- package/docs/id/packages/react-intlayer/useLocale.md +210 -0
- package/docs/id/per_locale_file.md +323 -0
- package/docs/id/readme.md +261 -0
- package/docs/id/releases/v6.md +305 -0
- package/docs/id/roadmap.md +362 -0
- package/docs/id/testing.md +202 -0
- package/docs/id/vs_code_extension.md +126 -0
- package/docs/it/component_i18n.md +1 -1
- package/docs/it/configuration.md +6 -0
- package/docs/it/intlayer_cli.md +8 -3
- package/docs/it/intlayer_with_next-i18next.md +628 -0
- package/docs/it/intlayer_with_next-intl.md +446 -0
- package/docs/it/intlayer_with_nextjs_16.md +21 -0
- package/docs/it/intlayer_with_tanstack.md +4 -0
- package/docs/it/intlayer_with_vite+react.md +4 -0
- package/docs/ja/component_i18n.md +1 -1
- package/docs/ja/configuration.md +6 -0
- package/docs/ja/intlayer_cli.md +8 -3
- package/docs/ja/intlayer_with_next-i18next.md +627 -0
- package/docs/ja/intlayer_with_next-intl.md +446 -0
- package/docs/ja/intlayer_with_nextjs_16.md +21 -0
- package/docs/ja/intlayer_with_tanstack.md +4 -0
- package/docs/ja/intlayer_with_vite+react.md +4 -0
- package/docs/ko/configuration.md +6 -0
- package/docs/ko/intlayer_cli.md +8 -3
- package/docs/ko/intlayer_with_next-i18next.md +627 -0
- package/docs/ko/intlayer_with_next-intl.md +446 -0
- package/docs/ko/intlayer_with_nextjs_16.md +21 -0
- package/docs/ko/intlayer_with_tanstack.md +4 -0
- package/docs/ko/intlayer_with_vite+react.md +4 -0
- package/docs/pl/CI_CD.md +198 -0
- package/docs/pl/autoFill.md +284 -0
- package/docs/pl/component_i18n.md +186 -0
- package/docs/pl/configuration.md +710 -0
- package/docs/pl/dictionary/condition.md +232 -0
- package/docs/pl/dictionary/content_file.md +1130 -0
- package/docs/pl/dictionary/enumeration.md +245 -0
- package/docs/pl/dictionary/file.md +234 -0
- package/docs/pl/dictionary/function_fetching.md +214 -0
- package/docs/pl/dictionary/gender.md +276 -0
- package/docs/pl/dictionary/insertion.md +188 -0
- package/docs/pl/dictionary/markdown.md +408 -0
- package/docs/pl/dictionary/nesting.md +273 -0
- package/docs/pl/dictionary/translation.md +310 -0
- package/docs/pl/formatters.md +596 -0
- package/docs/pl/how_works_intlayer.md +256 -0
- package/docs/pl/index.md +176 -0
- package/docs/pl/interest_of_intlayer.md +291 -0
- package/docs/pl/intlayer_CMS.md +549 -0
- package/docs/pl/intlayer_cli.md +857 -0
- package/docs/pl/intlayer_visual_editor.md +288 -0
- package/docs/pl/intlayer_with_angular.md +690 -0
- package/docs/pl/intlayer_with_astro.md +280 -0
- package/docs/pl/intlayer_with_create_react_app.md +1235 -0
- package/docs/pl/intlayer_with_express.md +411 -0
- package/docs/pl/intlayer_with_lynx+react.md +518 -0
- package/docs/pl/intlayer_with_nestjs.md +272 -0
- package/docs/pl/intlayer_with_next-i18next.md +628 -0
- package/docs/pl/intlayer_with_next-intl.md +446 -0
- package/docs/pl/intlayer_with_nextjs_14.md +1594 -0
- package/docs/pl/intlayer_with_nextjs_15.md +1701 -0
- package/docs/pl/intlayer_with_nextjs_16.md +21 -0
- package/docs/pl/intlayer_with_nextjs_page_router.md +1513 -0
- package/docs/pl/intlayer_with_nuxt.md +885 -0
- package/docs/pl/intlayer_with_react_native+expo.md +698 -0
- package/docs/pl/intlayer_with_react_router_v7.md +503 -0
- package/docs/pl/intlayer_with_tanstack.md +562 -0
- package/docs/pl/intlayer_with_vite+preact.md +1736 -0
- package/docs/pl/intlayer_with_vite+react.md +1438 -0
- package/docs/pl/intlayer_with_vite+solid.md +290 -0
- package/docs/pl/intlayer_with_vite+svelte.md +289 -0
- package/docs/pl/intlayer_with_vite+vue.md +1116 -0
- package/docs/pl/introduction.md +209 -0
- package/docs/pl/locale_mapper.md +242 -0
- package/docs/pl/mcp_server.md +211 -0
- package/docs/pl/packages/express-intlayer/t.md +458 -0
- package/docs/pl/packages/intlayer/getConfiguration.md +146 -0
- package/docs/pl/packages/intlayer/getEnumeration.md +160 -0
- package/docs/pl/packages/intlayer/getHTMLTextDir.md +121 -0
- package/docs/pl/packages/intlayer/getLocaleLang.md +81 -0
- package/docs/pl/packages/intlayer/getLocaleName.md +118 -0
- package/docs/pl/packages/intlayer/getLocalizedUrl.md +300 -0
- package/docs/pl/packages/intlayer/getMultilingualUrls.md +221 -0
- package/docs/pl/packages/intlayer/getPathWithoutLocale.md +75 -0
- package/docs/pl/packages/intlayer/getTranslation.md +190 -0
- package/docs/pl/packages/intlayer/getTranslationContent.md +189 -0
- package/docs/pl/packages/next-intlayer/t.md +353 -0
- package/docs/pl/packages/next-intlayer/useDictionary.md +270 -0
- package/docs/pl/packages/next-intlayer/useIntlayer.md +263 -0
- package/docs/pl/packages/next-intlayer/useLocale.md +166 -0
- package/docs/pl/packages/react-intlayer/t.md +303 -0
- package/docs/pl/packages/react-intlayer/useDictionary.md +289 -0
- package/docs/pl/packages/react-intlayer/useI18n.md +249 -0
- package/docs/pl/packages/react-intlayer/useIntlayer.md +256 -0
- package/docs/pl/packages/react-intlayer/useLocale.md +210 -0
- package/docs/pl/per_locale_file.md +321 -0
- package/docs/pl/readme.md +261 -0
- package/docs/pl/releases/v6.md +305 -0
- package/docs/pl/roadmap.md +362 -0
- package/docs/pl/testing.md +202 -0
- package/docs/pl/vs_code_extension.md +126 -0
- package/docs/pt/component_i18n.md +1 -1
- package/docs/pt/configuration.md +6 -0
- package/docs/pt/intlayer_cli.md +8 -3
- package/docs/pt/intlayer_with_next-i18next.md +627 -0
- package/docs/pt/intlayer_with_next-intl.md +446 -0
- package/docs/pt/intlayer_with_nextjs_16.md +21 -0
- package/docs/pt/intlayer_with_tanstack.md +4 -0
- package/docs/pt/intlayer_with_vite+react.md +4 -0
- package/docs/ru/component_i18n.md +1 -1
- package/docs/ru/configuration.md +6 -0
- package/docs/ru/intlayer_cli.md +301 -22
- package/docs/ru/intlayer_with_next-i18next.md +629 -0
- package/docs/ru/intlayer_with_next-intl.md +448 -0
- package/docs/ru/intlayer_with_nextjs_16.md +21 -0
- package/docs/ru/intlayer_with_tanstack.md +4 -0
- package/docs/ru/intlayer_with_vite+react.md +4 -0
- package/docs/tr/component_i18n.md +1 -1
- package/docs/tr/configuration.md +6 -0
- package/docs/tr/intlayer_cli.md +8 -0
- package/docs/tr/intlayer_with_next-i18next.md +627 -0
- package/docs/tr/intlayer_with_next-intl.md +446 -0
- package/docs/tr/intlayer_with_nextjs_16.md +21 -0
- package/docs/tr/intlayer_with_tanstack.md +4 -0
- package/docs/tr/intlayer_with_vite+react.md +4 -0
- package/docs/vi/CI_CD.md +198 -0
- package/docs/vi/autoFill.md +284 -0
- package/docs/vi/component_i18n.md +186 -0
- package/docs/vi/configuration.md +710 -0
- package/docs/vi/dictionary/condition.md +237 -0
- package/docs/vi/dictionary/content_file.md +1115 -0
- package/docs/vi/dictionary/enumeration.md +255 -0
- package/docs/vi/dictionary/file.md +234 -0
- package/docs/vi/dictionary/function_fetching.md +212 -0
- package/docs/vi/dictionary/gender.md +275 -0
- package/docs/vi/dictionary/insertion.md +191 -0
- package/docs/vi/dictionary/markdown.md +381 -0
- package/docs/vi/dictionary/nesting.md +273 -0
- package/docs/vi/dictionary/translation.md +309 -0
- package/docs/vi/formatters.md +595 -0
- package/docs/vi/how_works_intlayer.md +256 -0
- package/docs/vi/index.md +174 -0
- package/docs/vi/interest_of_intlayer.md +292 -0
- package/docs/vi/intlayer_CMS.md +549 -0
- package/docs/vi/intlayer_cli.md +850 -0
- package/docs/vi/intlayer_visual_editor.md +288 -0
- package/docs/vi/intlayer_with_angular.md +692 -0
- package/docs/vi/intlayer_with_astro.md +252 -0
- package/docs/vi/intlayer_with_create_react_app.md +1230 -0
- package/docs/vi/intlayer_with_express.md +409 -0
- package/docs/vi/intlayer_with_lynx+react.md +520 -0
- package/docs/vi/intlayer_with_nestjs.md +272 -0
- package/docs/vi/intlayer_with_next-i18next.md +628 -0
- package/docs/vi/intlayer_with_next-intl.md +446 -0
- package/docs/vi/intlayer_with_nextjs_14.md +1584 -0
- package/docs/vi/intlayer_with_nextjs_15.md +1738 -0
- package/docs/vi/intlayer_with_nextjs_16.md +21 -0
- package/docs/vi/intlayer_with_nextjs_page_router.md +1504 -0
- package/docs/vi/intlayer_with_nuxt.md +821 -0
- package/docs/vi/intlayer_with_react_native+expo.md +700 -0
- package/docs/vi/intlayer_with_react_router_v7.md +498 -0
- package/docs/vi/intlayer_with_tanstack.md +562 -0
- package/docs/vi/intlayer_with_vite+preact.md +1722 -0
- package/docs/vi/intlayer_with_vite+react.md +1407 -0
- package/docs/vi/intlayer_with_vite+solid.md +287 -0
- package/docs/vi/intlayer_with_vite+svelte.md +289 -0
- package/docs/vi/intlayer_with_vite+vue.md +1071 -0
- package/docs/vi/introduction.md +215 -0
- package/docs/vi/locale_mapper.md +242 -0
- package/docs/vi/mcp_server.md +211 -0
- package/docs/vi/packages/express-intlayer/t.md +457 -0
- package/docs/vi/packages/intlayer/getConfiguration.md +145 -0
- package/docs/vi/packages/intlayer/getEnumeration.md +162 -0
- package/docs/vi/packages/intlayer/getHTMLTextDir.md +121 -0
- package/docs/vi/packages/intlayer/getLocaleLang.md +81 -0
- package/docs/vi/packages/intlayer/getLocaleName.md +129 -0
- package/docs/vi/packages/intlayer/getLocalizedUrl.md +309 -0
- package/docs/vi/packages/intlayer/getMultilingualUrls.md +221 -0
- package/docs/vi/packages/intlayer/getPathWithoutLocale.md +75 -0
- package/docs/vi/packages/intlayer/getTranslation.md +201 -0
- package/docs/vi/packages/intlayer/getTranslationContent.md +188 -0
- package/docs/vi/packages/next-intlayer/t.md +352 -0
- package/docs/vi/packages/next-intlayer/useDictionary.md +273 -0
- package/docs/vi/packages/next-intlayer/useIntlayer.md +264 -0
- package/docs/vi/packages/next-intlayer/useLocale.md +166 -0
- package/docs/vi/packages/react-intlayer/t.md +304 -0
- package/docs/vi/packages/react-intlayer/useDictionary.md +288 -0
- package/docs/vi/packages/react-intlayer/useI18n.md +295 -0
- package/docs/vi/packages/react-intlayer/useIntlayer.md +256 -0
- package/docs/vi/packages/react-intlayer/useLocale.md +210 -0
- package/docs/vi/per_locale_file.md +326 -0
- package/docs/vi/readme.md +261 -0
- package/docs/vi/releases/v6.md +305 -0
- package/docs/vi/roadmap.md +346 -0
- package/docs/vi/testing.md +202 -0
- package/docs/vi/vs_code_extension.md +126 -0
- package/docs/zh/configuration.md +6 -0
- package/docs/zh/intlayer_cli.md +8 -3
- package/docs/zh/intlayer_with_next-i18next.md +628 -0
- package/docs/zh/intlayer_with_next-intl.md +448 -0
- package/docs/zh/intlayer_with_nextjs_16.md +21 -0
- package/docs/zh/intlayer_with_tanstack.md +4 -0
- package/docs/zh/intlayer_with_vite+react.md +4 -0
- package/frequent_questions/ar/SSR_Next_no_[locale].md +1 -2
- package/frequent_questions/ar/array_as_content_declaration.md +1 -2
- package/frequent_questions/ar/build_dictionaries.md +1 -2
- package/frequent_questions/ar/build_error_CI_CD.md +1 -2
- package/frequent_questions/ar/bun_set_up.md +1 -2
- package/frequent_questions/ar/customized_locale_list.md +1 -2
- package/frequent_questions/ar/domain_routing.md +1 -2
- package/frequent_questions/ar/esbuild_error.md +1 -2
- package/frequent_questions/ar/get_locale_cookie.md +1 -2
- package/frequent_questions/ar/intlayer_command_undefined.md +1 -2
- package/frequent_questions/ar/locale_incorect_in_url.md +1 -2
- package/frequent_questions/ar/static_rendering.md +1 -3
- package/frequent_questions/ar/translated_path_url.md +1 -2
- package/frequent_questions/ar/unknown_command.md +1 -2
- package/frequent_questions/de/SSR_Next_no_[locale].md +1 -2
- package/frequent_questions/de/array_as_content_declaration.md +1 -2
- package/frequent_questions/de/build_dictionaries.md +1 -2
- package/frequent_questions/de/build_error_CI_CD.md +1 -2
- package/frequent_questions/de/bun_set_up.md +1 -2
- package/frequent_questions/de/customized_locale_list.md +1 -2
- package/frequent_questions/de/domain_routing.md +1 -2
- package/frequent_questions/de/esbuild_error.md +1 -2
- package/frequent_questions/de/get_locale_cookie.md +1 -2
- package/frequent_questions/de/intlayer_command_undefined.md +1 -2
- package/frequent_questions/de/locale_incorect_in_url.md +1 -2
- package/frequent_questions/de/static_rendering.md +1 -3
- package/frequent_questions/de/translated_path_url.md +1 -2
- package/frequent_questions/de/unknown_command.md +1 -2
- package/frequent_questions/en/SSR_Next_no_[locale].md +1 -2
- package/frequent_questions/en/array_as_content_declaration.md +1 -2
- package/frequent_questions/en/build_dictionaries.md +1 -2
- package/frequent_questions/en/build_error_CI_CD.md +1 -2
- package/frequent_questions/en/bun_set_up.md +1 -2
- package/frequent_questions/en/customized_locale_list.md +1 -2
- package/frequent_questions/en/domain_routing.md +1 -2
- package/frequent_questions/en/esbuild_error.md +1 -2
- package/frequent_questions/en/get_locale_cookie.md +1 -2
- package/frequent_questions/en/intlayer_command_undefined.md +1 -2
- package/frequent_questions/en/locale_incorect_in_url.md +1 -2
- package/frequent_questions/en/static_rendering.md +1 -3
- package/frequent_questions/en/translated_path_url.md +1 -2
- package/frequent_questions/en/unknown_command.md +1 -2
- package/frequent_questions/en-GB/SSR_Next_no_[locale].md +1 -2
- package/frequent_questions/en-GB/array_as_content_declaration.md +1 -2
- package/frequent_questions/en-GB/build_dictionaries.md +1 -2
- package/frequent_questions/en-GB/build_error_CI_CD.md +1 -2
- package/frequent_questions/en-GB/bun_set_up.md +1 -2
- package/frequent_questions/en-GB/customized_locale_list.md +1 -2
- package/frequent_questions/en-GB/domain_routing.md +1 -2
- package/frequent_questions/en-GB/esbuild_error.md +1 -2
- package/frequent_questions/en-GB/get_locale_cookie.md +1 -2
- package/frequent_questions/en-GB/intlayer_command_undefined.md +1 -2
- package/frequent_questions/en-GB/locale_incorect_in_url.md +1 -2
- package/frequent_questions/en-GB/static_rendering.md +1 -3
- package/frequent_questions/en-GB/translated_path_url.md +1 -2
- package/frequent_questions/en-GB/unknown_command.md +1 -2
- package/frequent_questions/es/SSR_Next_no_[locale].md +1 -2
- package/frequent_questions/es/array_as_content_declaration.md +1 -2
- package/frequent_questions/es/build_dictionaries.md +1 -2
- package/frequent_questions/es/build_error_CI_CD.md +1 -2
- package/frequent_questions/es/bun_set_up.md +1 -2
- package/frequent_questions/es/customized_locale_list.md +1 -2
- package/frequent_questions/es/domain_routing.md +1 -2
- package/frequent_questions/es/esbuild_error.md +1 -2
- package/frequent_questions/es/get_locale_cookie.md +1 -2
- package/frequent_questions/es/intlayer_command_undefined.md +1 -2
- package/frequent_questions/es/locale_incorect_in_url.md +1 -2
- package/frequent_questions/es/static_rendering.md +1 -3
- package/frequent_questions/es/translated_path_url.md +1 -2
- package/frequent_questions/es/unknown_command.md +1 -2
- package/frequent_questions/fr/SSR_Next_no_[locale].md +1 -2
- package/frequent_questions/fr/array_as_content_declaration.md +1 -2
- package/frequent_questions/fr/build_dictionaries.md +1 -2
- package/frequent_questions/fr/build_error_CI_CD.md +1 -2
- package/frequent_questions/fr/bun_set_up.md +1 -2
- package/frequent_questions/fr/customized_locale_list.md +1 -2
- package/frequent_questions/fr/domain_routing.md +1 -2
- package/frequent_questions/fr/esbuild_error.md +1 -2
- package/frequent_questions/fr/get_locale_cookie.md +1 -2
- package/frequent_questions/fr/intlayer_command_undefined.md +1 -2
- package/frequent_questions/fr/locale_incorect_in_url.md +1 -2
- package/frequent_questions/fr/static_rendering.md +1 -3
- package/frequent_questions/fr/translated_path_url.md +1 -2
- package/frequent_questions/fr/unknown_command.md +1 -2
- package/frequent_questions/hi/SSR_Next_no_[locale].md +1 -2
- package/frequent_questions/hi/array_as_content_declaration.md +1 -2
- package/frequent_questions/hi/build_dictionaries.md +1 -2
- package/frequent_questions/hi/build_error_CI_CD.md +1 -2
- package/frequent_questions/hi/bun_set_up.md +1 -2
- package/frequent_questions/hi/customized_locale_list.md +1 -2
- package/frequent_questions/hi/domain_routing.md +1 -2
- package/frequent_questions/hi/esbuild_error.md +1 -2
- package/frequent_questions/hi/get_locale_cookie.md +1 -2
- package/frequent_questions/hi/intlayer_command_undefined.md +1 -2
- package/frequent_questions/hi/locale_incorect_in_url.md +1 -2
- package/frequent_questions/hi/static_rendering.md +1 -3
- package/frequent_questions/hi/translated_path_url.md +1 -2
- package/frequent_questions/hi/unknown_command.md +1 -2
- package/frequent_questions/id/SSR_Next_no_[locale].md +104 -0
- package/frequent_questions/id/array_as_content_declaration.md +71 -0
- package/frequent_questions/id/build_dictionaries.md +58 -0
- package/frequent_questions/id/build_error_CI_CD.md +74 -0
- package/frequent_questions/id/bun_set_up.md +53 -0
- package/frequent_questions/id/customized_locale_list.md +64 -0
- package/frequent_questions/id/domain_routing.md +113 -0
- package/frequent_questions/id/esbuild_error.md +29 -0
- package/frequent_questions/id/get_locale_cookie.md +142 -0
- package/frequent_questions/id/intlayer_command_undefined.md +155 -0
- package/frequent_questions/id/locale_incorect_in_url.md +73 -0
- package/frequent_questions/id/static_rendering.md +44 -0
- package/frequent_questions/id/translated_path_url.md +55 -0
- package/frequent_questions/id/unknown_command.md +97 -0
- package/frequent_questions/it/SSR_Next_no_[locale].md +1 -2
- package/frequent_questions/it/array_as_content_declaration.md +1 -2
- package/frequent_questions/it/build_dictionaries.md +1 -2
- package/frequent_questions/it/build_error_CI_CD.md +1 -2
- package/frequent_questions/it/bun_set_up.md +1 -2
- package/frequent_questions/it/customized_locale_list.md +1 -2
- package/frequent_questions/it/domain_routing.md +1 -2
- package/frequent_questions/it/esbuild_error.md +1 -2
- package/frequent_questions/it/get_locale_cookie.md +1 -2
- package/frequent_questions/it/intlayer_command_undefined.md +1 -2
- package/frequent_questions/it/locale_incorect_in_url.md +1 -2
- package/frequent_questions/it/static_rendering.md +1 -3
- package/frequent_questions/it/translated_path_url.md +1 -2
- package/frequent_questions/it/unknown_command.md +1 -2
- package/frequent_questions/ja/SSR_Next_no_[locale].md +1 -2
- package/frequent_questions/ja/array_as_content_declaration.md +1 -2
- package/frequent_questions/ja/build_dictionaries.md +1 -2
- package/frequent_questions/ja/build_error_CI_CD.md +1 -2
- package/frequent_questions/ja/bun_set_up.md +1 -2
- package/frequent_questions/ja/customized_locale_list.md +1 -2
- package/frequent_questions/ja/domain_routing.md +1 -2
- package/frequent_questions/ja/esbuild_error.md +1 -2
- package/frequent_questions/ja/get_locale_cookie.md +1 -2
- package/frequent_questions/ja/intlayer_command_undefined.md +1 -2
- package/frequent_questions/ja/locale_incorect_in_url.md +1 -2
- package/frequent_questions/ja/static_rendering.md +1 -3
- package/frequent_questions/ja/translated_path_url.md +1 -2
- package/frequent_questions/ja/unknown_command.md +1 -2
- package/frequent_questions/ko/SSR_Next_no_[locale].md +1 -2
- package/frequent_questions/ko/array_as_content_declaration.md +1 -2
- package/frequent_questions/ko/build_dictionaries.md +1 -2
- package/frequent_questions/ko/build_error_CI_CD.md +1 -2
- package/frequent_questions/ko/bun_set_up.md +1 -2
- package/frequent_questions/ko/customized_locale_list.md +1 -2
- package/frequent_questions/ko/domain_routing.md +1 -2
- package/frequent_questions/ko/esbuild_error.md +1 -2
- package/frequent_questions/ko/get_locale_cookie.md +1 -2
- package/frequent_questions/ko/intlayer_command_undefined.md +1 -2
- package/frequent_questions/ko/locale_incorect_in_url.md +1 -2
- package/frequent_questions/ko/static_rendering.md +1 -3
- package/frequent_questions/ko/translated_path_url.md +1 -2
- package/frequent_questions/ko/unknown_command.md +1 -2
- package/frequent_questions/pl/SSR_Next_no_[locale].md +104 -0
- package/frequent_questions/pl/array_as_content_declaration.md +71 -0
- package/frequent_questions/pl/build_dictionaries.md +58 -0
- package/frequent_questions/pl/build_error_CI_CD.md +74 -0
- package/frequent_questions/pl/bun_set_up.md +54 -0
- package/frequent_questions/pl/customized_locale_list.md +64 -0
- package/frequent_questions/pl/domain_routing.md +113 -0
- package/frequent_questions/pl/esbuild_error.md +29 -0
- package/frequent_questions/pl/get_locale_cookie.md +142 -0
- package/frequent_questions/pl/intlayer_command_undefined.md +155 -0
- package/frequent_questions/pl/locale_incorect_in_url.md +73 -0
- package/frequent_questions/pl/static_rendering.md +44 -0
- package/frequent_questions/pl/translated_path_url.md +55 -0
- package/frequent_questions/pl/unknown_command.md +97 -0
- package/frequent_questions/pt/SSR_Next_no_[locale].md +1 -2
- package/frequent_questions/pt/array_as_content_declaration.md +1 -2
- package/frequent_questions/pt/build_dictionaries.md +1 -2
- package/frequent_questions/pt/build_error_CI_CD.md +1 -2
- package/frequent_questions/pt/bun_set_up.md +1 -2
- package/frequent_questions/pt/customized_locale_list.md +1 -2
- package/frequent_questions/pt/domain_routing.md +1 -2
- package/frequent_questions/pt/esbuild_error.md +1 -2
- package/frequent_questions/pt/get_locale_cookie.md +1 -2
- package/frequent_questions/pt/intlayer_command_undefined.md +1 -2
- package/frequent_questions/pt/locale_incorect_in_url.md +1 -2
- package/frequent_questions/pt/static_rendering.md +1 -3
- package/frequent_questions/pt/translated_path_url.md +1 -2
- package/frequent_questions/pt/unknown_command.md +1 -2
- package/frequent_questions/ru/SSR_Next_no_[locale].md +1 -2
- package/frequent_questions/ru/array_as_content_declaration.md +1 -2
- package/frequent_questions/ru/build_dictionaries.md +1 -2
- package/frequent_questions/ru/build_error_CI_CD.md +1 -2
- package/frequent_questions/ru/bun_set_up.md +1 -2
- package/frequent_questions/ru/customized_locale_list.md +1 -2
- package/frequent_questions/ru/domain_routing.md +1 -2
- package/frequent_questions/ru/esbuild_error.md +1 -2
- package/frequent_questions/ru/get_locale_cookie.md +1 -2
- package/frequent_questions/ru/intlayer_command_undefined.md +1 -2
- package/frequent_questions/ru/locale_incorect_in_url.md +1 -2
- package/frequent_questions/ru/static_rendering.md +1 -2
- package/frequent_questions/ru/translated_path_url.md +1 -2
- package/frequent_questions/ru/unknown_command.md +1 -2
- package/frequent_questions/tr/SSR_Next_no_[locale].md +1 -2
- package/frequent_questions/tr/array_as_content_declaration.md +1 -2
- package/frequent_questions/tr/build_dictionaries.md +1 -2
- package/frequent_questions/tr/build_error_CI_CD.md +1 -2
- package/frequent_questions/tr/bun_set_up.md +1 -2
- package/frequent_questions/tr/customized_locale_list.md +1 -2
- package/frequent_questions/tr/domain_routing.md +1 -2
- package/frequent_questions/tr/esbuild_error.md +1 -2
- package/frequent_questions/tr/get_locale_cookie.md +1 -2
- package/frequent_questions/tr/intlayer_command_undefined.md +1 -2
- package/frequent_questions/tr/locale_incorect_in_url.md +1 -2
- package/frequent_questions/tr/static_rendering.md +1 -2
- package/frequent_questions/tr/translated_path_url.md +1 -2
- package/frequent_questions/tr/unknown_command.md +1 -2
- package/frequent_questions/vi/SSR_Next_no_[locale].md +106 -0
- package/frequent_questions/vi/array_as_content_declaration.md +71 -0
- package/frequent_questions/vi/build_dictionaries.md +58 -0
- package/frequent_questions/vi/build_error_CI_CD.md +74 -0
- package/frequent_questions/vi/bun_set_up.md +53 -0
- package/frequent_questions/vi/customized_locale_list.md +64 -0
- package/frequent_questions/vi/domain_routing.md +113 -0
- package/frequent_questions/vi/esbuild_error.md +29 -0
- package/frequent_questions/vi/get_locale_cookie.md +142 -0
- package/frequent_questions/vi/intlayer_command_undefined.md +155 -0
- package/frequent_questions/vi/locale_incorect_in_url.md +73 -0
- package/frequent_questions/vi/static_rendering.md +44 -0
- package/frequent_questions/vi/translated_path_url.md +55 -0
- package/frequent_questions/vi/unknown_command.md +97 -0
- package/frequent_questions/zh/SSR_Next_no_[locale].md +1 -2
- package/frequent_questions/zh/array_as_content_declaration.md +1 -2
- package/frequent_questions/zh/build_dictionaries.md +1 -2
- package/frequent_questions/zh/build_error_CI_CD.md +1 -2
- package/frequent_questions/zh/bun_set_up.md +1 -2
- package/frequent_questions/zh/customized_locale_list.md +1 -2
- package/frequent_questions/zh/domain_routing.md +1 -2
- package/frequent_questions/zh/esbuild_error.md +1 -2
- package/frequent_questions/zh/get_locale_cookie.md +1 -2
- package/frequent_questions/zh/intlayer_command_undefined.md +1 -2
- package/frequent_questions/zh/locale_incorect_in_url.md +1 -2
- package/frequent_questions/zh/static_rendering.md +1 -3
- package/frequent_questions/zh/translated_path_url.md +1 -2
- package/frequent_questions/zh/unknown_command.md +1 -2
- package/legal/id/privacy_notice.md +83 -0
- package/legal/id/terms_of_service.md +55 -0
- package/legal/pl/privacy_notice.md +83 -0
- package/legal/pl/terms_of_service.md +55 -0
- package/legal/vi/privacy_notice.md +83 -0
- package/legal/vi/terms_of_service.md +55 -0
- package/package.json +19 -18
- package/src/generated/blog.entry.ts +38 -0
|
@@ -0,0 +1,1584 @@
|
|
|
1
|
+
---
|
|
2
|
+
createdAt: 2024-12-06
|
|
3
|
+
updatedAt: 2025-09-22
|
|
4
|
+
title: Cách dịch trang web Next.js 14 và App Router của bạn – hướng dẫn i18n 2025
|
|
5
|
+
description: Khám phá cách làm cho trang web Next.js 14 App Router của bạn đa ngôn ngữ. Theo dõi tài liệu để quốc tế hóa (i18n) và dịch nó.
|
|
6
|
+
keywords:
|
|
7
|
+
- Quốc tế hóa
|
|
8
|
+
- Tài liệu
|
|
9
|
+
- Intlayer
|
|
10
|
+
- Next.js 14
|
|
11
|
+
- JavaScript
|
|
12
|
+
- React
|
|
13
|
+
slugs:
|
|
14
|
+
- doc
|
|
15
|
+
- environment
|
|
16
|
+
- nextjs
|
|
17
|
+
- 14
|
|
18
|
+
applicationTemplate: https://github.com/aymericzip/intlayer-next-14-template
|
|
19
|
+
history:
|
|
20
|
+
- version: 7.0.6
|
|
21
|
+
- version: 6.2.0
|
|
22
|
+
date: 2025-10-09
|
|
23
|
+
changes: Thêm tài liệu cho hook `useLocale` với tùy chọn `onLocaleChange`
|
|
24
|
+
- version: 5.6.6
|
|
25
|
+
date: 2025-10-02
|
|
26
|
+
changes: Thêm tài liệu cho hàm `getLocale` trên các hành động server
|
|
27
|
+
- version: 5.6.2
|
|
28
|
+
date: 2025-09-22
|
|
29
|
+
changes: Thêm tài liệu cho helper `multipleMiddlewares`
|
|
30
|
+
- version: 5.6.0
|
|
31
|
+
date: 2025-07-06
|
|
32
|
+
changes: Chuyển hàm `withIntlayer()` thành hàm dựa trên promise
|
|
33
|
+
- version: 5.5.10
|
|
34
|
+
date: 2025-06-29
|
|
35
|
+
changes: Khởi tạo lịch sử
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
# Dịch trang web Next.js 14 và App Router của bạn bằng Intlayer | Quốc tế hóa (i18n)
|
|
39
|
+
|
|
40
|
+
## Mục lục
|
|
41
|
+
|
|
42
|
+
<TOC/>
|
|
43
|
+
|
|
44
|
+
## Intlayer là gì?
|
|
45
|
+
|
|
46
|
+
**Intlayer** là một thư viện quốc tế hóa (i18n) mã nguồn mở sáng tạo, được thiết kế để đơn giản hóa việc hỗ trợ đa ngôn ngữ trong các ứng dụng web hiện đại. Intlayer tích hợp liền mạch với framework **Next.js 14** mới nhất, bao gồm cả **App Router** mạnh mẽ của nó. Nó được tối ưu để hoạt động với **Server Components** nhằm tăng hiệu quả render và hoàn toàn tương thích với [**Turbopack**](https://nextjs.org/docs/architecture/turbopack) (từ Next.js >= 15).
|
|
47
|
+
|
|
48
|
+
Với Intlayer, bạn có thể:
|
|
49
|
+
|
|
50
|
+
- **Dễ dàng quản lý bản dịch** bằng cách sử dụng các từ điển khai báo ở cấp độ component.
|
|
51
|
+
- **Địa phương hóa động metadata**, routes và nội dung.
|
|
52
|
+
- **Truy cập bản dịch trong cả component phía client và phía server**.
|
|
53
|
+
- **Đảm bảo hỗ trợ TypeScript** với các kiểu tự động tạo, cải thiện tính năng tự động hoàn thành và phát hiện lỗi.
|
|
54
|
+
- **Hưởng lợi từ các tính năng nâng cao**, như phát hiện và chuyển đổi locale động.
|
|
55
|
+
|
|
56
|
+
> Intlayer tương thích với Next.js 12, 13, 14 và 15. Nếu bạn đang sử dụng Next.js Page Router, bạn có thể tham khảo [hướng dẫn này](https://github.com/aymericzip/intlayer/blob/main/docs/docs/vi/intlayer_with_nextjs_page_router.md). Đối với Next.js 15 có hoặc không có turbopack, hãy tham khảo [hướng dẫn này](https://github.com/aymericzip/intlayer/blob/main/docs/docs/vi/intlayer_with_nextjs_15.md).
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## Hướng Dẫn Từng Bước Để Cài Đặt Intlayer Trong Ứng Dụng Next.js
|
|
61
|
+
|
|
62
|
+
<iframe
|
|
63
|
+
src="https://stackblitz.com/github/aymericzip/intlayer-next-14-template?embed=1&ctl=1&file=intlayer.config.ts"
|
|
64
|
+
className="m-auto overflow-hidden rounded-lg border-0 max-md:size-full max-md:h-[700px] md:aspect-16/9 md:w-full"
|
|
65
|
+
title="Demo CodeSandbox - Cách quốc tế hóa ứng dụng của bạn bằng Intlayer"
|
|
66
|
+
sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"
|
|
67
|
+
loading="lazy"
|
|
68
|
+
/>
|
|
69
|
+
|
|
70
|
+
Xem [Mẫu Ứng Dụng](https://github.com/aymericzip/intlayer-next-14-template) trên GitHub.
|
|
71
|
+
|
|
72
|
+
### Bước 1: Cài Đặt Các Phụ Thuộc
|
|
73
|
+
|
|
74
|
+
Cài đặt các gói cần thiết bằng npm:
|
|
75
|
+
|
|
76
|
+
```bash packageManager="npm"
|
|
77
|
+
npm install intlayer next-intlayer
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
```bash packageManager="pnpm"
|
|
81
|
+
pnpm add intlayer next-intlayer
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
```bash packageManager="yarn"
|
|
85
|
+
yarn add intlayer next-intlayer
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
- **intlayer**
|
|
89
|
+
|
|
90
|
+
Gói cốt lõi cung cấp các công cụ quốc tế hóa cho quản lý cấu hình, dịch thuật, [khai báo nội dung](https://github.com/aymericzip/intlayer/blob/main/docs/docs/vi/dictionary/content_file.md), biên dịch lại, và [các lệnh CLI](https://github.com/aymericzip/intlayer/blob/main/docs/docs/vi/intlayer_cli.md).
|
|
91
|
+
|
|
92
|
+
- **next-intlayer**
|
|
93
|
+
|
|
94
|
+
Gói tích hợp Intlayer với Next.js. Nó cung cấp các context provider và hook cho việc quốc tế hóa trong Next.js. Ngoài ra, nó bao gồm plugin Next.js để tích hợp Intlayer với [Webpack](https://webpack.js.org/) hoặc [Turbopack](https://nextjs.org/docs/app/api-reference/turbopack), cũng như middleware để phát hiện ngôn ngữ ưu tiên của người dùng, quản lý cookie, và xử lý chuyển hướng URL.
|
|
95
|
+
|
|
96
|
+
### Bước 2: Cấu hình Dự án của Bạn
|
|
97
|
+
|
|
98
|
+
Tạo một file cấu hình để cấu hình các ngôn ngữ cho ứng dụng của bạn:
|
|
99
|
+
|
|
100
|
+
```typescript fileName="intlayer.config.ts" codeFormat="typescript"
|
|
101
|
+
import { Locales, type IntlayerConfig } from "intlayer";
|
|
102
|
+
|
|
103
|
+
const config: IntlayerConfig = {
|
|
104
|
+
internationalization: {
|
|
105
|
+
locales: [
|
|
106
|
+
Locales.ENGLISH,
|
|
107
|
+
Locales.FRENCH,
|
|
108
|
+
Locales.SPANISH,
|
|
109
|
+
// Các ngôn ngữ khác của bạn
|
|
110
|
+
],
|
|
111
|
+
defaultLocale: Locales.ENGLISH,
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
export default config;
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
```javascript fileName="intlayer.config.mjs" codeFormat="esm"
|
|
119
|
+
import { Locales } from "intlayer";
|
|
120
|
+
|
|
121
|
+
/** @type {import('intlayer').IntlayerConfig} */
|
|
122
|
+
const config = {
|
|
123
|
+
internationalization: {
|
|
124
|
+
locales: [
|
|
125
|
+
Locales.ENGLISH,
|
|
126
|
+
Locales.FRENCH,
|
|
127
|
+
Locales.SPANISH,
|
|
128
|
+
// Các ngôn ngữ khác của bạn
|
|
129
|
+
],
|
|
130
|
+
defaultLocale: Locales.ENGLISH,
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
export default config;
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
```javascript fileName="intlayer.config.cjs" codeFormat="commonjs"
|
|
138
|
+
const { Locales } = require("intlayer");
|
|
139
|
+
|
|
140
|
+
/** @type {import('intlayer').IntlayerConfig} */
|
|
141
|
+
const config = {
|
|
142
|
+
internationalization: {
|
|
143
|
+
locales: [
|
|
144
|
+
Locales.ENGLISH,
|
|
145
|
+
Locales.FRENCH,
|
|
146
|
+
Locales.SPANISH,
|
|
147
|
+
// Các ngôn ngữ khác của bạn
|
|
148
|
+
],
|
|
149
|
+
defaultLocale: Locales.ENGLISH,
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
module.exports = config;
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
> Thông qua tệp cấu hình này, bạn có thể thiết lập URL địa phương hóa, chuyển hướng middleware, tên cookie, vị trí và phần mở rộng của các khai báo nội dung của bạn, tắt các bản ghi Intlayer trong console, và nhiều hơn nữa. Để xem danh sách đầy đủ các tham số có sẵn, hãy tham khảo [tài liệu cấu hình](https://github.com/aymericzip/intlayer/blob/main/docs/docs/vi/configuration.md).
|
|
157
|
+
|
|
158
|
+
### Bước 3: Tích hợp Intlayer vào Cấu hình Next.js của Bạn
|
|
159
|
+
|
|
160
|
+
Cấu hình thiết lập Next.js của bạn để sử dụng Intlayer:
|
|
161
|
+
|
|
162
|
+
```typescript fileName="next.config.mjs"
|
|
163
|
+
import { withIntlayer } from "next-intlayer/server";
|
|
164
|
+
|
|
165
|
+
/** @type {import('next').NextConfig} */
|
|
166
|
+
const nextConfig = {};
|
|
167
|
+
|
|
168
|
+
export default withIntlayer(nextConfig);
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
> Plugin `withIntlayer()` của Next.js được sử dụng để tích hợp Intlayer với Next.js. Nó đảm bảo việc xây dựng các tệp khai báo nội dung và giám sát chúng trong chế độ phát triển. Nó định nghĩa các biến môi trường Intlayer trong môi trường [Webpack](https://webpack.js.org/) hoặc [Turbopack](https://nextjs.org/docs/app/api-reference/turbopack). Ngoài ra, nó cung cấp các bí danh để tối ưu hiệu suất và đảm bảo tương thích với các thành phần server.
|
|
172
|
+
|
|
173
|
+
> Hàm `withIntlayer()` là một hàm promise. Nếu bạn muốn sử dụng nó cùng với các plugin khác, bạn có thể sử dụng await. Ví dụ:
|
|
174
|
+
>
|
|
175
|
+
> ```tsx
|
|
176
|
+
> const nextConfig = await withIntlayer(nextConfig);
|
|
177
|
+
> const nextConfigWithOtherPlugins = withOtherPlugins(nextConfig);
|
|
178
|
+
>
|
|
179
|
+
> export default nextConfigWithOtherPlugins;
|
|
180
|
+
> ```
|
|
181
|
+
|
|
182
|
+
### Bước 4: Cấu hình Middleware để Phát hiện Ngôn ngữ
|
|
183
|
+
|
|
184
|
+
Thiết lập middleware để phát hiện ngôn ngữ ưu tiên của người dùng:
|
|
185
|
+
|
|
186
|
+
```typescript fileName="src/middleware.ts" codeFormat="typescript"
|
|
187
|
+
export { intlayerMiddleware as middleware } from "next-intlayer/middleware";
|
|
188
|
+
|
|
189
|
+
export const config = {
|
|
190
|
+
matcher:
|
|
191
|
+
"/((?!api|static|assets|robots|sitemap|sw|service-worker|manifest|.*\\..*|_next).*)",
|
|
192
|
+
};
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
```javascript fileName="src/middleware.mjs" codeFormat="esm"
|
|
196
|
+
export { intlayerMiddleware as middleware } from "next-intlayer/middleware";
|
|
197
|
+
|
|
198
|
+
export const config = {
|
|
199
|
+
matcher:
|
|
200
|
+
"/((?!api|static|assets|robots|sitemap|sw|service-worker|manifest|.*\\..*|_next).*)",
|
|
201
|
+
};
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
```javascript fileName="src/middleware.cjs" codeFormat="commonjs"
|
|
205
|
+
const { intlayerMiddleware } = require("next-intlayer/middleware");
|
|
206
|
+
|
|
207
|
+
const config = {
|
|
208
|
+
matcher:
|
|
209
|
+
"/((?!api|static|assets|robots|sitemap|sw|service-worker|manifest|.*\\..*|_next).*)",
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
module.exports = { middleware: intlayerMiddleware, config };
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
> `intlayerMiddleware` được sử dụng để phát hiện ngôn ngữ ưu tiên của người dùng và chuyển hướng họ đến URL phù hợp như được chỉ định trong [cấu hình](https://github.com/aymericzip/intlayer/blob/main/docs/docs/vi/configuration.md). Ngoài ra, nó còn cho phép lưu ngôn ngữ ưu tiên của người dùng trong cookie.
|
|
216
|
+
|
|
217
|
+
> Điều chỉnh tham số `matcher` để phù hợp với các tuyến đường của ứng dụng của bạn. Để biết thêm chi tiết, hãy tham khảo [tài liệu Next.js về cấu hình matcher](https://nextjs.org/docs/app/building-your-application/routing/middleware).
|
|
218
|
+
|
|
219
|
+
> Nếu bạn cần kết hợp nhiều middleware với nhau (ví dụ, `intlayerMiddleware` cùng với xác thực hoặc các middleware tùy chỉnh), Intlayer hiện cung cấp một helper gọi là `multipleMiddlewares`.
|
|
220
|
+
|
|
221
|
+
```ts
|
|
222
|
+
import {
|
|
223
|
+
multipleMiddlewares,
|
|
224
|
+
intlayerMiddleware,
|
|
225
|
+
} from "next-intlayer/middleware";
|
|
226
|
+
import { customMiddleware } from "@utils/customMiddleware";
|
|
227
|
+
|
|
228
|
+
export const middleware = multipleMiddlewares([
|
|
229
|
+
intlayerMiddleware,
|
|
230
|
+
customMiddleware,
|
|
231
|
+
]);
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
### Bước 5: Định nghĩa các tuyến đường ngôn ngữ động
|
|
235
|
+
|
|
236
|
+
Xóa tất cả nội dung trong `RootLayout` và thay thế bằng đoạn mã sau:
|
|
237
|
+
|
|
238
|
+
```tsx fileName="src/app/layout.tsx" codeFormat="typescript"
|
|
239
|
+
import type { PropsWithChildren, FC } from "react";
|
|
240
|
+
import "./globals.css";
|
|
241
|
+
|
|
242
|
+
const RootLayout: FC<PropsWithChildren> = ({ children }) => (
|
|
243
|
+
// Bạn vẫn có thể bao bọc các children với các provider khác, như `next-themes`, `react-query`, `framer-motion`, v.v.
|
|
244
|
+
<>{children}</>
|
|
245
|
+
);
|
|
246
|
+
|
|
247
|
+
export default RootLayout;
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
```jsx fileName="src/app/layout.mjx" codeFormat="esm"
|
|
251
|
+
import "./globals.css";
|
|
252
|
+
|
|
253
|
+
const RootLayout = ({ children }) => (
|
|
254
|
+
// Bạn vẫn có thể bao bọc các children với các provider khác, như `next-themes`, `react-query`, `framer-motion`, v.v.
|
|
255
|
+
<>{children}</>
|
|
256
|
+
);
|
|
257
|
+
|
|
258
|
+
export default RootLayout;
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
```jsx fileName="src/app/layout.csx" codeFormat="commonjs"
|
|
262
|
+
require("./globals.css");
|
|
263
|
+
|
|
264
|
+
const RootLayout = ({ children }) => (
|
|
265
|
+
// Bạn vẫn có thể bao bọc các children với các provider khác, như `next-themes`, `react-query`, `framer-motion`, v.v.
|
|
266
|
+
<>{children}</>
|
|
267
|
+
);
|
|
268
|
+
|
|
269
|
+
module.exports = {
|
|
270
|
+
default: RootLayout,
|
|
271
|
+
generateStaticParams,
|
|
272
|
+
};
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
> Việc giữ cho component `RootLayout` trống cho phép thiết lập các thuộc tính [`lang`](https://developer.mozilla.org/fr/docs/Web/HTML/Global_attributes/lang) và [`dir`](https://developer.mozilla.org/fr/docs/Web/HTML/Global_attributes/dir) cho thẻ `<html>`.
|
|
276
|
+
|
|
277
|
+
Để triển khai dynamic routing, cung cấp đường dẫn cho locale bằng cách thêm một layout mới trong thư mục `[locale]` của bạn:
|
|
278
|
+
|
|
279
|
+
```tsx fileName="src/app/[locale]/layout.tsx" codeFormat="typescript"
|
|
280
|
+
import type { Next14LayoutIntlayer } from "next-intlayer";
|
|
281
|
+
import { Inter } from "next/font/google";
|
|
282
|
+
import { getHTMLTextDir } from "intlayer";
|
|
283
|
+
|
|
284
|
+
const inter = Inter({ subsets: ["latin"] });
|
|
285
|
+
|
|
286
|
+
const LocaleLayout: Next14LayoutIntlayer = ({
|
|
287
|
+
children,
|
|
288
|
+
params: { locale },
|
|
289
|
+
}) => (
|
|
290
|
+
<html lang={locale} dir={getHTMLTextDir(locale)}>
|
|
291
|
+
<body className={inter.className}>{children}</body>
|
|
292
|
+
</html>
|
|
293
|
+
);
|
|
294
|
+
|
|
295
|
+
export default LocaleLayout;
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
```jsx fileName="src/app/[locale]/layout.mjx" codeFormat="esm"
|
|
299
|
+
import { Inter } from "next/font/google";
|
|
300
|
+
import { getHTMLTextDir } from "intlayer";
|
|
301
|
+
|
|
302
|
+
const inter = Inter({ subsets: ["latin"] });
|
|
303
|
+
|
|
304
|
+
const LocaleLayout = ({ children, params: { locale } }) => (
|
|
305
|
+
<html lang={locale} dir={getHTMLTextDir(locale)}>
|
|
306
|
+
<body className={inter.className}>{children}</body>
|
|
307
|
+
</html>
|
|
308
|
+
);
|
|
309
|
+
|
|
310
|
+
export default LocaleLayout;
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
```jsx fileName="src/app/[locale]/layout.csx" codeFormat="commonjs"
|
|
314
|
+
const { Inter } = require("next/font/google");
|
|
315
|
+
const { getHTMLTextDir } = require("intlayer");
|
|
316
|
+
|
|
317
|
+
const inter = Inter({ subsets: ["latin"] });
|
|
318
|
+
|
|
319
|
+
const LocaleLayout = ({ children, params: { locale } }) => (
|
|
320
|
+
<html lang={locale} dir={getHTMLTextDir(locale)}>
|
|
321
|
+
<body className={inter.className}>{children}</body>
|
|
322
|
+
</html>
|
|
323
|
+
);
|
|
324
|
+
|
|
325
|
+
module.exports = LocaleLayout;
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
> Đoạn đường dẫn `[locale]` được sử dụng để xác định locale. Ví dụ: `/en-US/about` sẽ tham chiếu đến `en-US` và `/fr/about` sẽ tham chiếu đến `fr`.
|
|
329
|
+
|
|
330
|
+
> Ở giai đoạn này, bạn sẽ gặp lỗi: `Error: Missing <html> and <body> tags in the root layout.`. Điều này là bình thường vì file `/app/page.tsx` không còn được sử dụng và có thể bị xóa. Thay vào đó, đoạn đường dẫn `[locale]` sẽ kích hoạt trang `/app/[locale]/page.tsx`. Do đó, các trang sẽ có thể truy cập qua các đường dẫn như `/en`, `/fr`, `/es` trên trình duyệt của bạn. Để đặt locale mặc định làm trang gốc, hãy tham khảo phần thiết lập `middleware` trong bước 4.
|
|
331
|
+
|
|
332
|
+
Sau đó, triển khai hàm `generateStaticParams` trong Layout ứng dụng của bạn.
|
|
333
|
+
|
|
334
|
+
```tsx {1} fileName="src/app/[locale]/layout.tsx" codeFormat="typescript"
|
|
335
|
+
export { generateStaticParams } from "next-intlayer"; // Dòng cần chèn
|
|
336
|
+
|
|
337
|
+
const LocaleLayout: Next14LayoutIntlayer = ({
|
|
338
|
+
children,
|
|
339
|
+
params: { locale },
|
|
340
|
+
}) => {
|
|
341
|
+
/*... Phần còn lại của mã */
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
export default LocaleLayout;
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
```jsx {1} fileName="src/app/[locale]/layout.mjx" codeFormat="esm"
|
|
348
|
+
export { generateStaticParams } from "next-intlayer"; // Dòng cần chèn
|
|
349
|
+
|
|
350
|
+
const LocaleLayout = ({ children, params: { locale } }) => {
|
|
351
|
+
/*... Phần còn lại của mã */
|
|
352
|
+
};
|
|
353
|
+
|
|
354
|
+
export default LocaleLayout;
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
```jsx {1,7} fileName="src/app/[locale]/layout.csx" codeFormat="commonjs"
|
|
358
|
+
const { generateStaticParams } = require("next-intlayer"); // Dòng cần chèn
|
|
359
|
+
|
|
360
|
+
const LocaleLayout = ({ children, params: { locale } }) => {
|
|
361
|
+
/*... Phần còn lại của mã */
|
|
362
|
+
};
|
|
363
|
+
|
|
364
|
+
module.exports = LocaleLayout;
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
> `generateStaticParams` đảm bảo rằng ứng dụng của bạn sẽ tiền xây dựng các trang cần thiết cho tất cả các locale, giảm thiểu tính toán khi chạy và cải thiện trải nghiệm người dùng. Để biết thêm chi tiết, tham khảo [tài liệu Next.js về generateStaticParams](https://nextjs.org/docs/app/building-your-application/rendering/static-and-dynamic-rendering#generate-static-params).
|
|
368
|
+
|
|
369
|
+
### Bước 6: Khai báo Nội dung của Bạn
|
|
370
|
+
|
|
371
|
+
Tạo và quản lý các khai báo nội dung để lưu trữ bản dịch:
|
|
372
|
+
|
|
373
|
+
```typescript fileName="src/app/[locale]/page.content.ts" contentDeclarationFormat="typescript"
|
|
374
|
+
import { t, type Dictionary } from "intlayer";
|
|
375
|
+
|
|
376
|
+
const pageContent = {
|
|
377
|
+
key: "page",
|
|
378
|
+
content: {
|
|
379
|
+
getStarted: {
|
|
380
|
+
main: t({
|
|
381
|
+
en: "Get started by editing",
|
|
382
|
+
fr: "Commencez par éditer",
|
|
383
|
+
es: "Comience por editar",
|
|
384
|
+
}),
|
|
385
|
+
pageLink: "src/app/page.tsx",
|
|
386
|
+
},
|
|
387
|
+
},
|
|
388
|
+
} satisfies Dictionary;
|
|
389
|
+
|
|
390
|
+
export default pageContent;
|
|
391
|
+
```
|
|
392
|
+
|
|
393
|
+
```javascript fileName="src/app/[locale]/page.content.mjs" contentDeclarationFormat="esm"
|
|
394
|
+
import { t } from "intlayer";
|
|
395
|
+
|
|
396
|
+
/** @type {import('intlayer').Dictionary} */
|
|
397
|
+
const pageContent = {
|
|
398
|
+
key: "page",
|
|
399
|
+
content: {
|
|
400
|
+
getStarted: {
|
|
401
|
+
main: t({
|
|
402
|
+
en: "Bắt đầu bằng cách chỉnh sửa",
|
|
403
|
+
fr: "Commencez par éditer",
|
|
404
|
+
es: "Comience por editar",
|
|
405
|
+
}),
|
|
406
|
+
pageLink: "src/app/page.tsx",
|
|
407
|
+
},
|
|
408
|
+
},
|
|
409
|
+
};
|
|
410
|
+
|
|
411
|
+
export default pageContent;
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
```javascript fileName="src/app/[locale]/page.content.cjs" contentDeclarationFormat="commonjs"
|
|
415
|
+
const { t } = require("intlayer");
|
|
416
|
+
|
|
417
|
+
/** @type {import('intlayer').Dictionary} */
|
|
418
|
+
const pageContent = {
|
|
419
|
+
key: "page",
|
|
420
|
+
content: {
|
|
421
|
+
getStarted: {
|
|
422
|
+
main: t({
|
|
423
|
+
en: "Get started by editing",
|
|
424
|
+
fr: "Commencez par éditer",
|
|
425
|
+
es: "Comience por editar",
|
|
426
|
+
}),
|
|
427
|
+
pageLink: "src/app/page.tsx",
|
|
428
|
+
},
|
|
429
|
+
},
|
|
430
|
+
};
|
|
431
|
+
|
|
432
|
+
module.exports = pageContent;
|
|
433
|
+
```
|
|
434
|
+
|
|
435
|
+
```json fileName="src/app/[locale]/page.content.json" contentDeclarationFormat="json"
|
|
436
|
+
{
|
|
437
|
+
"$schema": "https://intlayer.org/schema.json",
|
|
438
|
+
"key": "page",
|
|
439
|
+
"content": {
|
|
440
|
+
"getStarted": {
|
|
441
|
+
"nodeType": "translation",
|
|
442
|
+
"translation": {
|
|
443
|
+
"en": "Bắt đầu bằng cách chỉnh sửa",
|
|
444
|
+
"fr": "Commencez par éditer",
|
|
445
|
+
"es": "Comience por editar"
|
|
446
|
+
}
|
|
447
|
+
},
|
|
448
|
+
"pageLink": {
|
|
449
|
+
"nodeType": "translation",
|
|
450
|
+
"translation": {
|
|
451
|
+
"en": "src/app/page.tsx",
|
|
452
|
+
"fr": "src/app/page.tsx",
|
|
453
|
+
"es": "src/app/page.tsx"
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
```
|
|
459
|
+
|
|
460
|
+
> Các khai báo nội dung của bạn có thể được định nghĩa ở bất kỳ đâu trong ứng dụng của bạn miễn là chúng được đưa vào thư mục `contentDir` (mặc định là `./src`). Và khớp với phần mở rộng của file khai báo nội dung (mặc định là `.content.{json,ts,tsx,js,jsx,mjs,mjx,cjs,cjx}`).
|
|
461
|
+
|
|
462
|
+
> Để biết thêm chi tiết, tham khảo [tài liệu khai báo nội dung](https://github.com/aymericzip/intlayer/blob/main/docs/docs/vi/dictionary/content_file.md).
|
|
463
|
+
|
|
464
|
+
### Bước 7: Sử dụng Nội dung trong Mã của Bạn
|
|
465
|
+
|
|
466
|
+
Truy cập các từ điển nội dung của bạn trong toàn bộ ứng dụng:
|
|
467
|
+
|
|
468
|
+
```tsx fileName="src/app/[locale]/page.tsx" codeFormat="typescript"
|
|
469
|
+
import { ClientComponentExample } from "@components/ClientComponentExample";
|
|
470
|
+
import { ServerComponentExample } from "@components/ServerComponentExample";
|
|
471
|
+
import { type Next14PageIntlayer, IntlayerClientProvider } from "next-intlayer";
|
|
472
|
+
import { IntlayerServerProvider, useIntlayer } from "next-intlayer/server";
|
|
473
|
+
|
|
474
|
+
const Page: Next14PageIntlayer = ({ params: { locale } }) => {
|
|
475
|
+
const content = useIntlayer("page", locale);
|
|
476
|
+
|
|
477
|
+
return (
|
|
478
|
+
<>
|
|
479
|
+
<p>
|
|
480
|
+
{content.getStarted.main}
|
|
481
|
+
<code>{content.getStarted.pageLink}</code>
|
|
482
|
+
</p>
|
|
483
|
+
|
|
484
|
+
<IntlayerServerProvider locale={locale}>
|
|
485
|
+
<IntlayerClientProvider locale={locale}>
|
|
486
|
+
<ServerComponentExample />
|
|
487
|
+
<ClientComponentExample />
|
|
488
|
+
</IntlayerClientProvider>
|
|
489
|
+
</IntlayerServerProvider>
|
|
490
|
+
</>
|
|
491
|
+
);
|
|
492
|
+
};
|
|
493
|
+
|
|
494
|
+
export default Page;
|
|
495
|
+
```
|
|
496
|
+
|
|
497
|
+
```jsx fileName="src/app/[locale]/page.mjx" codeFormat="esm"
|
|
498
|
+
import { ClientComponentExample } from "@components/ClientComponentExample";
|
|
499
|
+
import { ServerComponentExample } from "@components/ServerComponentExample";
|
|
500
|
+
import { IntlayerClientProvider } from "next-intlayer";
|
|
501
|
+
import { IntlayerServerProvider, useIntlayer } from "next-intlayer/server";
|
|
502
|
+
|
|
503
|
+
const Page = ({ params: { locale } }) => {
|
|
504
|
+
const content = useIntlayer("page", locale);
|
|
505
|
+
|
|
506
|
+
return (
|
|
507
|
+
<>
|
|
508
|
+
<p>
|
|
509
|
+
{content.getStarted.main}
|
|
510
|
+
<code>{content.getStarted.pageLink}</code>
|
|
511
|
+
</p>
|
|
512
|
+
|
|
513
|
+
<IntlayerClientProvider locale={locale}>
|
|
514
|
+
<IntlayerServerProvider locale={locale}>
|
|
515
|
+
<ClientComponentExample />
|
|
516
|
+
<ServerComponentExample />
|
|
517
|
+
</IntlayerServerProvider>
|
|
518
|
+
</IntlayerClientProvider>
|
|
519
|
+
</>
|
|
520
|
+
);
|
|
521
|
+
};
|
|
522
|
+
```
|
|
523
|
+
|
|
524
|
+
```jsx fileName="src/app/[locale]/page.csx" codeFormat="commonjs"
|
|
525
|
+
const { IntlayerClientProvider } = require("next-intlayer");
|
|
526
|
+
const { IntlayerServerProvider, useIntlayer } = require("next-intlayer/server");
|
|
527
|
+
|
|
528
|
+
const Page = ({ params: { locale } }) => {
|
|
529
|
+
const content = useIntlayer("page", locale);
|
|
530
|
+
|
|
531
|
+
return (
|
|
532
|
+
<>
|
|
533
|
+
<p>
|
|
534
|
+
{content.getStarted.main}
|
|
535
|
+
<code>{content.getStarted.pageLink}</code>
|
|
536
|
+
</p>
|
|
537
|
+
|
|
538
|
+
<IntlayerClientProvider locale={locale}>
|
|
539
|
+
<IntlayerServerProvider locale={locale}>
|
|
540
|
+
<ClientComponentExample />
|
|
541
|
+
<ServerComponentExample />
|
|
542
|
+
</IntlayerServerProvider>
|
|
543
|
+
</IntlayerClientProvider>
|
|
544
|
+
</>
|
|
545
|
+
);
|
|
546
|
+
};
|
|
547
|
+
```
|
|
548
|
+
|
|
549
|
+
- **`IntlayerClientProvider`** được sử dụng để cung cấp locale cho các component phía client. Nó có thể được đặt trong bất kỳ component cha nào, bao gồm cả layout. Tuy nhiên, việc đặt nó trong layout được khuyến nghị vì Next.js chia sẻ mã layout giữa các trang, giúp hiệu quả hơn. Bằng cách sử dụng `IntlayerClientProvider` trong layout, bạn tránh phải khởi tạo lại cho mỗi trang, cải thiện hiệu suất và duy trì ngữ cảnh localization nhất quán trong toàn bộ ứng dụng của bạn.
|
|
550
|
+
- **`IntlayerServerProvider`** được sử dụng để cung cấp locale cho các component con phía server. Nó không thể được đặt trong layout.
|
|
551
|
+
|
|
552
|
+
> Layout và trang không thể chia sẻ một ngữ cảnh server chung vì hệ thống ngữ cảnh server dựa trên kho dữ liệu theo từng yêu cầu (thông qua cơ chế [React’s cache](https://react.dev/reference/react/cache)), khiến mỗi “context” được tạo lại cho các phân đoạn khác nhau của ứng dụng. Việc đặt provider trong layout dùng chung sẽ phá vỡ sự cô lập này, ngăn cản việc truyền đúng giá trị ngữ cảnh server đến các component server của bạn.
|
|
553
|
+
|
|
554
|
+
> Layout và trang không thể chia sẻ một ngữ cảnh server chung vì hệ thống ngữ cảnh server dựa trên kho dữ liệu theo từng yêu cầu (qua cơ chế [React’s cache](https://react.dev/reference/react/cache)), khiến mỗi “ngữ cảnh” được tạo lại cho các phân đoạn khác nhau của ứng dụng. Việc đặt provider trong một layout dùng chung sẽ phá vỡ sự cô lập này, ngăn cản việc truyền đúng các giá trị ngữ cảnh server đến các component server của bạn.
|
|
555
|
+
|
|
556
|
+
```tsx {4,7} fileName="src/components/ClientComponentExample.tsx" codeFormat="typescript"
|
|
557
|
+
"use client";
|
|
558
|
+
|
|
559
|
+
import type { FC } from "react";
|
|
560
|
+
import { useIntlayer } from "next-intlayer";
|
|
561
|
+
|
|
562
|
+
const ClientComponentExample: FC = () => {
|
|
563
|
+
const content = useIntlayer("client-component-example"); // Tạo khai báo nội dung liên quan
|
|
564
|
+
|
|
565
|
+
return (
|
|
566
|
+
<div>
|
|
567
|
+
<h2>{content.title}</h2>
|
|
568
|
+
<p>{content.content}</p>
|
|
569
|
+
</div>
|
|
570
|
+
);
|
|
571
|
+
};
|
|
572
|
+
```
|
|
573
|
+
|
|
574
|
+
```jsx {3,6} fileName="src/components/ClientComponentExample.mjx" codeFormat="esm"
|
|
575
|
+
"use client";
|
|
576
|
+
|
|
577
|
+
import { useIntlayer } from "next-intlayer";
|
|
578
|
+
|
|
579
|
+
const ClientComponentExample = () => {
|
|
580
|
+
const content = useIntlayer("client-component-example"); // Tạo khai báo nội dung liên quan
|
|
581
|
+
|
|
582
|
+
return (
|
|
583
|
+
<div>
|
|
584
|
+
<h2>{content.title}</h2>
|
|
585
|
+
<p>{content.content}</p>
|
|
586
|
+
</div>
|
|
587
|
+
);
|
|
588
|
+
};
|
|
589
|
+
```
|
|
590
|
+
|
|
591
|
+
```jsx {3,6} fileName="src/components/ClientComponentExample.csx" codeFormat="commonjs"
|
|
592
|
+
"use client";
|
|
593
|
+
|
|
594
|
+
const { useIntlayer } = require("next-intlayer");
|
|
595
|
+
|
|
596
|
+
const ClientComponentExample = () => {
|
|
597
|
+
const content = useIntlayer("client-component-example"); // Tạo khai báo nội dung liên quan
|
|
598
|
+
|
|
599
|
+
return (
|
|
600
|
+
<div>
|
|
601
|
+
<h2>{content.title}</h2>
|
|
602
|
+
<p>{content.content}</p>
|
|
603
|
+
</div>
|
|
604
|
+
);
|
|
605
|
+
};
|
|
606
|
+
```
|
|
607
|
+
|
|
608
|
+
```tsx {2} fileName="src/components/ServerComponentExample.tsx" codeFormat="typescript"
|
|
609
|
+
import type { FC } from "react";
|
|
610
|
+
import { useIntlayer } from "next-intlayer/server";
|
|
611
|
+
|
|
612
|
+
const ServerComponentExample: FC = () => {
|
|
613
|
+
const content = useIntlayer("server-component-example"); // Tạo khai báo nội dung liên quan
|
|
614
|
+
|
|
615
|
+
return (
|
|
616
|
+
<div>
|
|
617
|
+
<h2>{content.title}</h2>
|
|
618
|
+
<p>{content.content}</p>
|
|
619
|
+
</div>
|
|
620
|
+
);
|
|
621
|
+
};
|
|
622
|
+
```
|
|
623
|
+
|
|
624
|
+
```jsx {1} fileName="src/components/ServerComponentExample.mjx" codeFormat="esm"
|
|
625
|
+
import { useIntlayer } from "next-intlayer/server";
|
|
626
|
+
|
|
627
|
+
const ServerComponentExample = () => {
|
|
628
|
+
const content = useIntlayer("server-component-example"); // Tạo khai báo nội dung liên quan
|
|
629
|
+
|
|
630
|
+
return (
|
|
631
|
+
<div>
|
|
632
|
+
<h2>{content.title}</h2>
|
|
633
|
+
<p>{content.content}</p>
|
|
634
|
+
</div>
|
|
635
|
+
);
|
|
636
|
+
};
|
|
637
|
+
```
|
|
638
|
+
|
|
639
|
+
```jsx {1} fileName="src/components/ServerComponentExample.csx" codeFormat="commonjs"
|
|
640
|
+
const { useIntlayer } = require("next-intlayer/server");
|
|
641
|
+
|
|
642
|
+
const ServerComponentExample = () => {
|
|
643
|
+
const content = useIntlayer("server-component-example"); // Tạo khai báo nội dung liên quan
|
|
644
|
+
|
|
645
|
+
return (
|
|
646
|
+
<div>
|
|
647
|
+
<h2>{content.title}</h2>
|
|
648
|
+
<p>{content.content}</p>
|
|
649
|
+
</div>
|
|
650
|
+
);
|
|
651
|
+
};
|
|
652
|
+
```
|
|
653
|
+
|
|
654
|
+
> Nếu bạn muốn sử dụng nội dung của mình trong một thuộc tính `string`, chẳng hạn như `alt`, `title`, `href`, `aria-label`, v.v., bạn phải gọi giá trị của hàm, như sau:
|
|
655
|
+
|
|
656
|
+
> ```jsx
|
|
657
|
+
> <img src={content.image.src.value} alt={content.image.value} />
|
|
658
|
+
> ```
|
|
659
|
+
|
|
660
|
+
> Để tìm hiểu thêm về hook `useIntlayer`, hãy tham khảo [tài liệu](https://github.com/aymericzip/intlayer/blob/main/docs/docs/vi/packages/next-intlayer/useIntlayer.md).
|
|
661
|
+
|
|
662
|
+
### (Tùy chọn) Bước 8: Quốc tế hóa metadata của bạn
|
|
663
|
+
|
|
664
|
+
Trong trường hợp bạn muốn quốc tế hóa metadata của mình, chẳng hạn như tiêu đề trang, bạn có thể sử dụng hàm `generateMetadata` do Next.js cung cấp. Bên trong, bạn có thể lấy nội dung từ hàm `getIntlayer` để dịch metadata của bạn.
|
|
665
|
+
|
|
666
|
+
```typescript fileName="src/app/[locale]/metadata.content.ts" contentDeclarationFormat="typescript"
|
|
667
|
+
import { type Dictionary, t } from "intlayer";
|
|
668
|
+
import { Metadata } from "next";
|
|
669
|
+
|
|
670
|
+
const metadataContent = {
|
|
671
|
+
key: "page-metadata",
|
|
672
|
+
content: {
|
|
673
|
+
title: t({
|
|
674
|
+
en: "Create Next App",
|
|
675
|
+
fr: "Créer une application Next.js",
|
|
676
|
+
es: "Crear una aplicación Next.js",
|
|
677
|
+
}),
|
|
678
|
+
description: t({
|
|
679
|
+
en: "Generated by create next app",
|
|
680
|
+
fr: "Généré par create next app",
|
|
681
|
+
es: "Generado por create next app",
|
|
682
|
+
}),
|
|
683
|
+
},
|
|
684
|
+
} satisfies Dictionary<Metadata>;
|
|
685
|
+
|
|
686
|
+
export default metadataContent;
|
|
687
|
+
```
|
|
688
|
+
|
|
689
|
+
```javascript fileName="src/app/[locale]/metadata.content.mjs" contentDeclarationFormat="esm"
|
|
690
|
+
import { t } from "intlayer";
|
|
691
|
+
|
|
692
|
+
/** @type {import('intlayer').Dictionary<import('next').Metadata>} */
|
|
693
|
+
const metadataContent = {
|
|
694
|
+
key: "page-metadata",
|
|
695
|
+
content: {
|
|
696
|
+
title: t({
|
|
697
|
+
en: "Create Next App",
|
|
698
|
+
fr: "Créer une application Next.js",
|
|
699
|
+
es: "Crear una aplicación Next.js",
|
|
700
|
+
}),
|
|
701
|
+
description: t({
|
|
702
|
+
en: "Generated by create next app",
|
|
703
|
+
fr: "Généré par create next app",
|
|
704
|
+
fr: "Généré par create next app",
|
|
705
|
+
es: "Generado por create next app",
|
|
706
|
+
}),
|
|
707
|
+
},
|
|
708
|
+
};
|
|
709
|
+
|
|
710
|
+
export default metadataContent;
|
|
711
|
+
```
|
|
712
|
+
|
|
713
|
+
```javascript fileName="src/app/[locale]/metadata.content.cjs" contentDeclarationFormat="commonjs"
|
|
714
|
+
const { t } = require("intlayer");
|
|
715
|
+
|
|
716
|
+
/** @type {import('intlayer').Dictionary<import('next').Metadata>} */
|
|
717
|
+
const metadataContent = {
|
|
718
|
+
key: "page-metadata",
|
|
719
|
+
content: {
|
|
720
|
+
title: t({
|
|
721
|
+
en: "Create Next App",
|
|
722
|
+
fr: "Créer une application Next.js",
|
|
723
|
+
es: "Crear una aplicación Next.js",
|
|
724
|
+
}),
|
|
725
|
+
description: t({
|
|
726
|
+
en: "Generated by create next app",
|
|
727
|
+
fr: "Généré par create next app",
|
|
728
|
+
es: "Generado por create next app",
|
|
729
|
+
}),
|
|
730
|
+
},
|
|
731
|
+
};
|
|
732
|
+
|
|
733
|
+
module.exports = metadataContent;
|
|
734
|
+
```
|
|
735
|
+
|
|
736
|
+
```json fileName="src/app/[locale]/metadata.content.json" contentDeclarationFormat="json"
|
|
737
|
+
{
|
|
738
|
+
"key": "page-metadata",
|
|
739
|
+
"content": {
|
|
740
|
+
"title": {
|
|
741
|
+
"nodeType": "translation",
|
|
742
|
+
"translation": {
|
|
743
|
+
"en": "Preact logo",
|
|
744
|
+
"fr": "Logo Preact",
|
|
745
|
+
"es": "Logo Preact",
|
|
746
|
+
"vi": "Logo Preact"
|
|
747
|
+
}
|
|
748
|
+
},
|
|
749
|
+
"description": {
|
|
750
|
+
"nodeType": "translation",
|
|
751
|
+
"translation": {
|
|
752
|
+
"en": "Generated by create next app",
|
|
753
|
+
"fr": "Généré par create next app",
|
|
754
|
+
"es": "Generado por create next app",
|
|
755
|
+
"vi": "Được tạo bởi create next app"
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
```
|
|
761
|
+
|
|
762
|
+
````typescript fileName="src/app/[locale]/layout.tsx or src/app/[locale]/page.tsx" codeFormat="typescript"
|
|
763
|
+
import { getIntlayer, getMultilingualUrls } from "intlayer";
|
|
764
|
+
import type { Metadata } from "next";
|
|
765
|
+
import type { LocalParams } from "next-intlayer";
|
|
766
|
+
|
|
767
|
+
export const generateMetadata = ({
|
|
768
|
+
params: { locale },
|
|
769
|
+
}: LocalParams): Metadata => {
|
|
770
|
+
const metadata = getIntlayer("page-metadata", locale);
|
|
771
|
+
|
|
772
|
+
/**
|
|
773
|
+
* Tạo một đối tượng chứa tất cả các url cho mỗi locale.
|
|
774
|
+
*
|
|
775
|
+
* Ví dụ:
|
|
776
|
+
* ```ts
|
|
777
|
+
* getMultilingualUrls('/about');
|
|
778
|
+
*
|
|
779
|
+
* // Trả về
|
|
780
|
+
* // {
|
|
781
|
+
* // en: '/about',
|
|
782
|
+
* // fr: '/fr/about',
|
|
783
|
+
* // es: '/es/about',
|
|
784
|
+
* // }
|
|
785
|
+
* ```
|
|
786
|
+
*/
|
|
787
|
+
const multilingualUrls = getMultilingualUrls("/");
|
|
788
|
+
const localizedUrl =
|
|
789
|
+
multilingualUrls[locale as keyof typeof multilingualUrls];
|
|
790
|
+
|
|
791
|
+
return {
|
|
792
|
+
...metadata,
|
|
793
|
+
alternates: {
|
|
794
|
+
canonical: localizedUrl,
|
|
795
|
+
languages: { ...multilingualUrls, "x-default": "/" },
|
|
796
|
+
},
|
|
797
|
+
openGraph: {
|
|
798
|
+
url: localizedUrl,
|
|
799
|
+
},
|
|
800
|
+
};
|
|
801
|
+
};
|
|
802
|
+
|
|
803
|
+
// ... Phần còn lại của mã
|
|
804
|
+
````
|
|
805
|
+
|
|
806
|
+
````javascript fileName="src/app/[locale]/layout.mjs or src/app/[locale]/page.mjs" codeFormat="esm"
|
|
807
|
+
import { getIntlayer, getMultilingualUrls } from "intlayer";
|
|
808
|
+
|
|
809
|
+
export const generateMetadata = ({ params: { locale } }) => {
|
|
810
|
+
const metadata = getIntlayer("page-metadata", locale);
|
|
811
|
+
|
|
812
|
+
/**
|
|
813
|
+
* Tạo một đối tượng chứa tất cả các url cho mỗi locale.
|
|
814
|
+
*
|
|
815
|
+
* Ví dụ:
|
|
816
|
+
* ```ts
|
|
817
|
+
* getMultilingualUrls('/about');
|
|
818
|
+
*
|
|
819
|
+
* // Trả về
|
|
820
|
+
* // {
|
|
821
|
+
* // en: '/about',
|
|
822
|
+
* // fr: '/fr/about',
|
|
823
|
+
* // es: '/es/about'
|
|
824
|
+
* // }
|
|
825
|
+
* ```
|
|
826
|
+
*/
|
|
827
|
+
const multilingualUrls = getMultilingualUrls("/");
|
|
828
|
+
const localizedUrl = multilingualUrls[locale];
|
|
829
|
+
|
|
830
|
+
return {
|
|
831
|
+
...metadata,
|
|
832
|
+
alternates: {
|
|
833
|
+
canonical: localizedUrl,
|
|
834
|
+
languages: { ...multilingualUrls, "x-default": "/" },
|
|
835
|
+
},
|
|
836
|
+
openGraph: {
|
|
837
|
+
url: localizedUrl,
|
|
838
|
+
},
|
|
839
|
+
};
|
|
840
|
+
};
|
|
841
|
+
|
|
842
|
+
// ... Phần còn lại của mã
|
|
843
|
+
````
|
|
844
|
+
|
|
845
|
+
````javascript fileName="src/app/[locale]/layout.cjs or src/app/[locale]/page.cjs" codeFormat="commonjs"
|
|
846
|
+
const { getIntlayer, getMultilingualUrls } = require("intlayer");
|
|
847
|
+
|
|
848
|
+
const generateMetadata = ({ params: { locale } }) => {
|
|
849
|
+
const metadata = getIntlayer("page-metadata", locale);
|
|
850
|
+
|
|
851
|
+
/**
|
|
852
|
+
* Tạo một đối tượng chứa tất cả các url cho mỗi locale.
|
|
853
|
+
*
|
|
854
|
+
* Ví dụ:
|
|
855
|
+
* ```ts
|
|
856
|
+
* getMultilingualUrls('/about');
|
|
857
|
+
*
|
|
858
|
+
* // Trả về
|
|
859
|
+
* // {
|
|
860
|
+
* // en: '/about',
|
|
861
|
+
* // fr: '/fr/about',
|
|
862
|
+
* // es: '/es/about'
|
|
863
|
+
* // }
|
|
864
|
+
* ```
|
|
865
|
+
*/
|
|
866
|
+
const multilingualUrls = getMultilingualUrls("/");
|
|
867
|
+
const localizedUrl = multilingualUrls[locale];
|
|
868
|
+
|
|
869
|
+
return {
|
|
870
|
+
...metadata,
|
|
871
|
+
alternates: {
|
|
872
|
+
canonical: localizedUrl,
|
|
873
|
+
languages: { ...multilingualUrls, "x-default": "/" },
|
|
874
|
+
},
|
|
875
|
+
openGraph: {
|
|
876
|
+
url: localizedUrl,
|
|
877
|
+
},
|
|
878
|
+
};
|
|
879
|
+
};
|
|
880
|
+
|
|
881
|
+
module.exports = { generateMetadata };
|
|
882
|
+
|
|
883
|
+
// ... Phần còn lại của mã
|
|
884
|
+
````
|
|
885
|
+
|
|
886
|
+
> Lưu ý rằng hàm `getIntlayer` được nhập từ `next-intlayer` trả về nội dung của bạn được bao bọc trong một `IntlayerNode`, cho phép tích hợp với trình chỉnh sửa trực quan. Ngược lại, hàm `getIntlayer` được nhập từ `intlayer` trả về nội dung của bạn trực tiếp mà không có các thuộc tính bổ sung.
|
|
887
|
+
|
|
888
|
+
Ngoài ra, bạn có thể sử dụng hàm `getTranslation` để khai báo metadata của mình. Tuy nhiên, việc sử dụng các file khai báo nội dung được khuyến nghị để tự động hóa việc dịch metadata và tách nội dung ra bên ngoài tại một thời điểm nào đó.
|
|
889
|
+
|
|
890
|
+
```typescript fileName="src/app/[locale]/layout.tsx or src/app/[locale]/page.tsx" codeFormat="typescript"
|
|
891
|
+
import {
|
|
892
|
+
type IConfigLocales,
|
|
893
|
+
getTranslation,
|
|
894
|
+
getMultilingualUrls,
|
|
895
|
+
} from "intlayer";
|
|
896
|
+
import type { Metadata } from "next";
|
|
897
|
+
import type { LocalParams } from "next-intlayer";
|
|
898
|
+
|
|
899
|
+
export const generateMetadata = ({
|
|
900
|
+
params: { locale },
|
|
901
|
+
}: LocalParams): Metadata => {
|
|
902
|
+
const t = <T>(content: IConfigLocales<T>) => getTranslation(content, locale);
|
|
903
|
+
|
|
904
|
+
return {
|
|
905
|
+
title: t<string>({
|
|
906
|
+
en: "My title",
|
|
907
|
+
fr: "Mon titre",
|
|
908
|
+
es: "Mi título",
|
|
909
|
+
}),
|
|
910
|
+
description: t({
|
|
911
|
+
en: "My description",
|
|
912
|
+
fr: "Ma description",
|
|
913
|
+
es: "Mi descripción",
|
|
914
|
+
}),
|
|
915
|
+
};
|
|
916
|
+
};
|
|
917
|
+
|
|
918
|
+
// ... Phần còn lại của mã
|
|
919
|
+
```
|
|
920
|
+
|
|
921
|
+
```javascript fileName="src/app/[locale]/layout.mjs or src/app/[locale]/page.mjs" codeFormat="esm"
|
|
922
|
+
import { getTranslation, getMultilingualUrls } from "intlayer";
|
|
923
|
+
|
|
924
|
+
export const generateMetadata = ({ params: { locale } }) => {
|
|
925
|
+
const t = (content) => getTranslation(content, locale);
|
|
926
|
+
|
|
927
|
+
return {
|
|
928
|
+
title: t({
|
|
929
|
+
en: "My title",
|
|
930
|
+
fr: "Mon titre",
|
|
931
|
+
es: "Mi título",
|
|
932
|
+
}),
|
|
933
|
+
description: t({
|
|
934
|
+
en: "My description",
|
|
935
|
+
fr: "Ma description",
|
|
936
|
+
es: "Mi descripción",
|
|
937
|
+
}),
|
|
938
|
+
};
|
|
939
|
+
};
|
|
940
|
+
|
|
941
|
+
// ... Phần còn lại của mã
|
|
942
|
+
```
|
|
943
|
+
|
|
944
|
+
```javascript fileName="src/app/[locale]/layout.cjs or src/app/[locale]/page.cjs" codeFormat="commonjs"
|
|
945
|
+
const { getTranslation, getMultilingualUrls } = require("intlayer");
|
|
946
|
+
|
|
947
|
+
const generateMetadata = ({ params: { locale } }) => {
|
|
948
|
+
const t = (content) => getTranslation(content, locale);
|
|
949
|
+
|
|
950
|
+
return {
|
|
951
|
+
title: t({
|
|
952
|
+
en: "My title",
|
|
953
|
+
fr: "Mon titre",
|
|
954
|
+
es: "Mi título",
|
|
955
|
+
}),
|
|
956
|
+
description: t({
|
|
957
|
+
en: "My description",
|
|
958
|
+
fr: "Ma description",
|
|
959
|
+
es: "Mi descripción",
|
|
960
|
+
}),
|
|
961
|
+
};
|
|
962
|
+
};
|
|
963
|
+
|
|
964
|
+
module.exports = { generateMetadata };
|
|
965
|
+
|
|
966
|
+
// ... Phần còn lại của mã
|
|
967
|
+
```
|
|
968
|
+
|
|
969
|
+
> Tìm hiểu thêm về tối ưu hóa metadata [trong tài liệu chính thức của Next.js](https://nextjs.org/docs/app/building-your-application/optimizing/metadata).
|
|
970
|
+
|
|
971
|
+
### (Tùy chọn) Bước 9: Quốc tế hóa sitemap.xml và robots.txt của bạn
|
|
972
|
+
|
|
973
|
+
Để quốc tế hóa `sitemap.xml` và `robots.txt` của bạn, bạn có thể sử dụng hàm `getMultilingualUrls` do Intlayer cung cấp. Hàm này cho phép bạn tạo các URL đa ngôn ngữ cho sitemap của mình.
|
|
974
|
+
|
|
975
|
+
```tsx fileName="src/app/sitemap.ts" codeFormat="typescript"
|
|
976
|
+
import { getMultilingualUrls } from "intlayer";
|
|
977
|
+
import type { MetadataRoute } from "next";
|
|
978
|
+
|
|
979
|
+
const sitemap = (): MetadataRoute.Sitemap => [
|
|
980
|
+
{
|
|
981
|
+
url: "https://example.com",
|
|
982
|
+
alternates: {
|
|
983
|
+
languages: {
|
|
984
|
+
...getMultilingualUrls("https://example.com"),
|
|
985
|
+
"x-default": "https://example.com",
|
|
986
|
+
},
|
|
987
|
+
},
|
|
988
|
+
},
|
|
989
|
+
{
|
|
990
|
+
url: "https://example.com/login",
|
|
991
|
+
alternates: {
|
|
992
|
+
languages: {
|
|
993
|
+
...getMultilingualUrls("https://example.com/login"),
|
|
994
|
+
"x-default": "https://example.com/login",
|
|
995
|
+
},
|
|
996
|
+
},
|
|
997
|
+
},
|
|
998
|
+
{
|
|
999
|
+
url: "https://example.com/register",
|
|
1000
|
+
alternates: {
|
|
1001
|
+
languages: {
|
|
1002
|
+
...getMultilingualUrls("https://example.com/register"),
|
|
1003
|
+
"x-default": "https://example.com/register",
|
|
1004
|
+
},
|
|
1005
|
+
},
|
|
1006
|
+
},
|
|
1007
|
+
];
|
|
1008
|
+
|
|
1009
|
+
export default sitemap;
|
|
1010
|
+
```
|
|
1011
|
+
|
|
1012
|
+
```jsx fileName="src/app/sitemap.mjx" codeFormat="esm"
|
|
1013
|
+
import { getMultilingualUrls } from "intlayer";
|
|
1014
|
+
|
|
1015
|
+
const sitemap = () => [
|
|
1016
|
+
{
|
|
1017
|
+
url: "https://example.com",
|
|
1018
|
+
alternates: {
|
|
1019
|
+
languages: {
|
|
1020
|
+
...getMultilingualUrls("https://example.com"),
|
|
1021
|
+
"x-default": "https://example.com",
|
|
1022
|
+
},
|
|
1023
|
+
},
|
|
1024
|
+
},
|
|
1025
|
+
{
|
|
1026
|
+
url: "https://example.com/login",
|
|
1027
|
+
alternates: {
|
|
1028
|
+
languages: {
|
|
1029
|
+
...getMultilingualUrls("https://example.com/login"),
|
|
1030
|
+
"x-default": "https://example.com/login",
|
|
1031
|
+
},
|
|
1032
|
+
},
|
|
1033
|
+
},
|
|
1034
|
+
{
|
|
1035
|
+
url: "https://example.com/register",
|
|
1036
|
+
alternates: {
|
|
1037
|
+
languages: {
|
|
1038
|
+
...getMultilingualUrls("https://example.com/register"),
|
|
1039
|
+
"x-default": "https://example.com/register",
|
|
1040
|
+
},
|
|
1041
|
+
},
|
|
1042
|
+
},
|
|
1043
|
+
];
|
|
1044
|
+
|
|
1045
|
+
export default sitemap;
|
|
1046
|
+
```
|
|
1047
|
+
|
|
1048
|
+
```jsx fileName="src/app/sitemap.csx" codeFormat="commonjs"
|
|
1049
|
+
const { getMultilingualUrls } = require("intlayer");
|
|
1050
|
+
|
|
1051
|
+
const sitemap = () => [
|
|
1052
|
+
{
|
|
1053
|
+
url: "https://example.com",
|
|
1054
|
+
alternates: {
|
|
1055
|
+
languages: {
|
|
1056
|
+
...getMultilingualUrls("https://example.com"),
|
|
1057
|
+
"x-default": "https://example.com",
|
|
1058
|
+
},
|
|
1059
|
+
},
|
|
1060
|
+
},
|
|
1061
|
+
{
|
|
1062
|
+
url: "https://example.com/login",
|
|
1063
|
+
alternates: {
|
|
1064
|
+
languages: {
|
|
1065
|
+
...getMultilingualUrls("https://example.com/login"),
|
|
1066
|
+
"x-default": "https://example.com/login",
|
|
1067
|
+
},
|
|
1068
|
+
},
|
|
1069
|
+
},
|
|
1070
|
+
{
|
|
1071
|
+
url: "https://example.com/register",
|
|
1072
|
+
alternates: {
|
|
1073
|
+
languages: {
|
|
1074
|
+
...getMultilingualUrls("https://example.com/register"),
|
|
1075
|
+
"x-default": "https://example.com/register",
|
|
1076
|
+
},
|
|
1077
|
+
},
|
|
1078
|
+
},
|
|
1079
|
+
];
|
|
1080
|
+
|
|
1081
|
+
module.exports = sitemap;
|
|
1082
|
+
```
|
|
1083
|
+
|
|
1084
|
+
```tsx fileName="src/app/robots.ts" codeFormat="typescript"
|
|
1085
|
+
import type { MetadataRoute } from "next";
|
|
1086
|
+
import { getMultilingualUrls } from "intlayer";
|
|
1087
|
+
|
|
1088
|
+
// Lấy tất cả các URL đa ngôn ngữ từ một danh sách URL
|
|
1089
|
+
const getAllMultilingualUrls = (urls: string[]) =>
|
|
1090
|
+
urls.flatMap((url) => Object.values(getMultilingualUrls(url)) as string[]);
|
|
1091
|
+
|
|
1092
|
+
// Định nghĩa cấu hình robots.txt
|
|
1093
|
+
const robots = (): MetadataRoute.Robots => ({
|
|
1094
|
+
rules: {
|
|
1095
|
+
userAgent: "*",
|
|
1096
|
+
allow: ["/"],
|
|
1097
|
+
disallow: getAllMultilingualUrls(["/login", "/register"]), // Không cho phép truy cập các trang đăng nhập và đăng ký
|
|
1098
|
+
},
|
|
1099
|
+
host: "https://example.com",
|
|
1100
|
+
sitemap: `https://example.com/sitemap.xml`,
|
|
1101
|
+
});
|
|
1102
|
+
|
|
1103
|
+
export default robots;
|
|
1104
|
+
```
|
|
1105
|
+
|
|
1106
|
+
```jsx fileName="src/app/robots.mjx" codeFormat="esm"
|
|
1107
|
+
import { getMultilingualUrls } from "intlayer";
|
|
1108
|
+
|
|
1109
|
+
const getAllMultilingualUrls = (urls) =>
|
|
1110
|
+
urls.flatMap((url) => Object.values(getMultilingualUrls(url)));
|
|
1111
|
+
|
|
1112
|
+
const robots = () => ({
|
|
1113
|
+
rules: {
|
|
1114
|
+
userAgent: "*",
|
|
1115
|
+
allow: ["/"],
|
|
1116
|
+
disallow: getAllMultilingualUrls(["/login", "/register"]),
|
|
1117
|
+
},
|
|
1118
|
+
host: "https://example.com",
|
|
1119
|
+
sitemap: `https://example.com/sitemap.xml`,
|
|
1120
|
+
});
|
|
1121
|
+
|
|
1122
|
+
export default robots;
|
|
1123
|
+
```
|
|
1124
|
+
|
|
1125
|
+
```jsx fileName="src/app/robots.csx" codeFormat="commonjs"
|
|
1126
|
+
const { getMultilingualUrls } = require("intlayer");
|
|
1127
|
+
|
|
1128
|
+
const getAllMultilingualUrls = (urls) =>
|
|
1129
|
+
urls.flatMap((url) => Object.values(getMultilingualUrls(url)));
|
|
1130
|
+
|
|
1131
|
+
const robots = () => ({
|
|
1132
|
+
rules: {
|
|
1133
|
+
userAgent: "*",
|
|
1134
|
+
allow: ["/"],
|
|
1135
|
+
disallow: getAllMultilingualUrls(["/login", "/register"]),
|
|
1136
|
+
},
|
|
1137
|
+
host: "https://example.com",
|
|
1138
|
+
sitemap: `https://example.com/sitemap.xml`,
|
|
1139
|
+
});
|
|
1140
|
+
|
|
1141
|
+
module.exports = robots;
|
|
1142
|
+
```
|
|
1143
|
+
|
|
1144
|
+
> Tìm hiểu thêm về tối ưu hóa sitemap [trong tài liệu chính thức của Next.js](https://nextjs.org/docs/app/api-reference/file-conventions/metadata/sitemap). Tìm hiểu thêm về tối ưu hóa robots.txt [trong tài liệu chính thức của Next.js](https://nextjs.org/docs/app/api-reference/file-conventions/metadata/robots).
|
|
1145
|
+
|
|
1146
|
+
### (Tùy chọn) Bước 10: Thay đổi ngôn ngữ nội dung của bạn
|
|
1147
|
+
|
|
1148
|
+
Để thay đổi ngôn ngữ của nội dung trong Next.js, cách được khuyến nghị là sử dụng component `Link` để chuyển hướng người dùng đến trang đã được địa phương hóa phù hợp. Component `Link` cho phép tải trước trang, giúp tránh việc tải lại toàn bộ trang.
|
|
1149
|
+
|
|
1150
|
+
```tsx fileName="src/components/LocaleSwitcher.tsx" codeFormat="typescript"
|
|
1151
|
+
"use client";
|
|
1152
|
+
|
|
1153
|
+
import {
|
|
1154
|
+
Locales,
|
|
1155
|
+
getHTMLTextDir,
|
|
1156
|
+
getLocaleName,
|
|
1157
|
+
getLocalizedUrl,
|
|
1158
|
+
} from "intlayer";
|
|
1159
|
+
import { useLocale } from "next-intlayer";
|
|
1160
|
+
import { type FC } from "react";
|
|
1161
|
+
import Link from "next/link";
|
|
1162
|
+
|
|
1163
|
+
const LocaleSwitcher: FC = () => {
|
|
1164
|
+
const { locale, pathWithoutLocale, availableLocales, setLocale } =
|
|
1165
|
+
useLocale();
|
|
1166
|
+
|
|
1167
|
+
return (
|
|
1168
|
+
<div>
|
|
1169
|
+
<button popoverTarget="localePopover">{getLocaleName(locale)}</button>
|
|
1170
|
+
<div id="localePopover" popover="auto">
|
|
1171
|
+
{availableLocales.map((localeItem) => (
|
|
1172
|
+
<Link
|
|
1173
|
+
href={getLocalizedUrl(pathWithoutLocale, localeItem)}
|
|
1174
|
+
hrefLang={localeItem}
|
|
1175
|
+
key={localeItem}
|
|
1176
|
+
aria-current={locale === localeItem ? "page" : undefined}
|
|
1177
|
+
onClick={() => setLocale(localeItem)}
|
|
1178
|
+
replace // Sẽ đảm bảo rằng nút "quay lại" trên trình duyệt sẽ chuyển hướng về trang trước đó
|
|
1179
|
+
>
|
|
1180
|
+
<span>
|
|
1181
|
+
{/* Locale - ví dụ: FR */}
|
|
1182
|
+
{localeItem}
|
|
1183
|
+
</span>
|
|
1184
|
+
<span>
|
|
1185
|
+
{/* Ngôn ngữ theo Locale của chính nó - ví dụ: Français */}
|
|
1186
|
+
{getLocaleName(localeItem, locale)}
|
|
1187
|
+
</span>
|
|
1188
|
+
<span dir={getHTMLTextDir(localeItem)} lang={localeItem}>
|
|
1189
|
+
{/* Ngôn ngữ trong Locale hiện tại - ví dụ Francés với locale hiện tại được đặt thành Locales.SPANISH */}
|
|
1190
|
+
{getLocaleName(localeItem)}
|
|
1191
|
+
</span>
|
|
1192
|
+
<span dir="ltr" lang={Locales.ENGLISH}>
|
|
1193
|
+
{/* Ngôn ngữ bằng tiếng Anh - ví dụ French */}
|
|
1194
|
+
{getLocaleName(localeItem, Locales.ENGLISH)}
|
|
1195
|
+
</span>
|
|
1196
|
+
</Link>
|
|
1197
|
+
))}
|
|
1198
|
+
</div>
|
|
1199
|
+
</div>
|
|
1200
|
+
);
|
|
1201
|
+
};
|
|
1202
|
+
```
|
|
1203
|
+
|
|
1204
|
+
```jsx fileName="src/components/LocaleSwitcher.msx" codeFormat="esm"
|
|
1205
|
+
"use client";
|
|
1206
|
+
|
|
1207
|
+
import {
|
|
1208
|
+
Locales,
|
|
1209
|
+
getHTMLTextDir,
|
|
1210
|
+
getLocaleName,
|
|
1211
|
+
getLocalizedUrl,
|
|
1212
|
+
} from "intlayer";
|
|
1213
|
+
import { useLocale } from "next-intlayer";
|
|
1214
|
+
import Link from "next/link";
|
|
1215
|
+
|
|
1216
|
+
const LocaleSwitcher = () => {
|
|
1217
|
+
const { locale, pathWithoutLocale, availableLocales, setLocale } =
|
|
1218
|
+
useLocale();
|
|
1219
|
+
|
|
1220
|
+
return (
|
|
1221
|
+
<div>
|
|
1222
|
+
<button popoverTarget="localePopover">{getLocaleName(locale)}</button>
|
|
1223
|
+
<div id="localePopover" popover="auto">
|
|
1224
|
+
{availableLocales.map((localeItem) => (
|
|
1225
|
+
<Link
|
|
1226
|
+
href={getLocalizedUrl(pathWithoutLocale, localeItem)}
|
|
1227
|
+
hrefLang={localeItem}
|
|
1228
|
+
key={localeItem}
|
|
1229
|
+
aria-current={locale === localeItem ? "page" : undefined}
|
|
1230
|
+
onClick={() => setLocale(localeItem)}
|
|
1231
|
+
replace // Sẽ đảm bảo nút "quay lại" trên trình duyệt sẽ chuyển hướng về trang trước đó
|
|
1232
|
+
>
|
|
1233
|
+
<span>
|
|
1234
|
+
{/* Locale - ví dụ: FR */}
|
|
1235
|
+
{localeItem}
|
|
1236
|
+
</span>
|
|
1237
|
+
<span>
|
|
1238
|
+
{/* Ngôn ngữ theo Locale riêng của nó - ví dụ: Français */}
|
|
1239
|
+
{getLocaleName(localeItem, locale)}
|
|
1240
|
+
</span>
|
|
1241
|
+
<span dir={getHTMLTextDir(localeItem)} lang={localeItem}>
|
|
1242
|
+
{/* Ngôn ngữ theo Locale hiện tại - ví dụ: Francés với locale hiện tại được đặt là Locales.SPANISH */}
|
|
1243
|
+
{getLocaleName(localeItem)}
|
|
1244
|
+
</span>
|
|
1245
|
+
<span dir="ltr" lang={Locales.ENGLISH}>
|
|
1246
|
+
{/* Ngôn ngữ bằng tiếng Anh - ví dụ: French */}
|
|
1247
|
+
{getLocaleName(localeItem, Locales.ENGLISH)}
|
|
1248
|
+
</span>
|
|
1249
|
+
</Link>
|
|
1250
|
+
))}
|
|
1251
|
+
</div>
|
|
1252
|
+
</div>
|
|
1253
|
+
);
|
|
1254
|
+
};
|
|
1255
|
+
```
|
|
1256
|
+
|
|
1257
|
+
```jsx fileName="src/components/LocaleSwitcher.csx" codeFormat="commonjs"
|
|
1258
|
+
"use client";
|
|
1259
|
+
|
|
1260
|
+
const {
|
|
1261
|
+
Locales,
|
|
1262
|
+
getHTMLTextDir,
|
|
1263
|
+
getLocaleName,
|
|
1264
|
+
getLocalizedUrl,
|
|
1265
|
+
} = require("intlayer");
|
|
1266
|
+
const { useLocale } = require("next-intlayer");
|
|
1267
|
+
const Link = require("next/link");
|
|
1268
|
+
|
|
1269
|
+
const LocaleSwitcher = () => {
|
|
1270
|
+
const { locale, pathWithoutLocale, availableLocales, setLocale } =
|
|
1271
|
+
useLocale();
|
|
1272
|
+
|
|
1273
|
+
return (
|
|
1274
|
+
<div>
|
|
1275
|
+
<button popoverTarget="localePopover">{getLocaleName(locale)}</button>
|
|
1276
|
+
<div id="localePopover" popover="auto">
|
|
1277
|
+
{availableLocales.map((localeItem) => (
|
|
1278
|
+
<Link
|
|
1279
|
+
href={getLocalizedUrl(pathWithoutLocale, localeItem)}
|
|
1280
|
+
hrefLang={localeItem}
|
|
1281
|
+
key={localeItem}
|
|
1282
|
+
aria-current={locale === localeItem ? "page" : undefined}
|
|
1283
|
+
onClick={() => setLocale(localeItem)}
|
|
1284
|
+
replace // Sẽ đảm bảo nút "quay lại" trên trình duyệt sẽ chuyển hướng về trang trước đó
|
|
1285
|
+
>
|
|
1286
|
+
<span>
|
|
1287
|
+
{/* Mã ngôn ngữ - ví dụ: FR */}
|
|
1288
|
+
{localeItem}
|
|
1289
|
+
</span>
|
|
1290
|
+
<span>
|
|
1291
|
+
{/* Ngôn ngữ theo mã ngôn ngữ của chính nó - ví dụ: Français */}
|
|
1292
|
+
{getLocaleName(localeItem, locale)}
|
|
1293
|
+
</span>
|
|
1294
|
+
<span dir={getHTMLTextDir(localeItem)} lang={localeItem}>
|
|
1295
|
+
{/* Ngôn ngữ theo mã ngôn ngữ hiện tại - ví dụ: Francés khi mã ngôn ngữ hiện tại là Locales.SPANISH */}
|
|
1296
|
+
{getLocaleName(localeItem)}
|
|
1297
|
+
</span>
|
|
1298
|
+
<span dir="ltr" lang={Locales.ENGLISH}>
|
|
1299
|
+
{/* Ngôn ngữ bằng tiếng Anh - ví dụ: French */}
|
|
1300
|
+
{getLocaleName(localeItem, Locales.ENGLISH)}
|
|
1301
|
+
</span>
|
|
1302
|
+
</Link>
|
|
1303
|
+
))}
|
|
1304
|
+
</div>
|
|
1305
|
+
</div>
|
|
1306
|
+
);
|
|
1307
|
+
};
|
|
1308
|
+
```
|
|
1309
|
+
|
|
1310
|
+
> Một cách thay thế là sử dụng hàm `setLocale` được cung cấp bởi hook `useLocale`. Hàm này sẽ không cho phép prefetch trang. Xem thêm chi tiết trong [tài liệu hook `useLocale`](https://github.com/aymericzip/intlayer/blob/main/docs/docs/vi/packages/next-intlayer/useLocale.md).
|
|
1311
|
+
|
|
1312
|
+
> Bạn cũng có thể thiết lập một hàm trong tùy chọn `onLocaleChange` để kích hoạt một hàm tùy chỉnh khi locale thay đổi.
|
|
1313
|
+
|
|
1314
|
+
```tsx fileName="src/components/LocaleSwitcher.tsx"
|
|
1315
|
+
"use client";
|
|
1316
|
+
|
|
1317
|
+
import { useRouter } from "next/navigation";
|
|
1318
|
+
import { useLocale } from "next-intlayer";
|
|
1319
|
+
import { getLocalizedUrl } from "intlayer";
|
|
1320
|
+
|
|
1321
|
+
// ... Phần còn lại của code
|
|
1322
|
+
|
|
1323
|
+
const router = useRouter();
|
|
1324
|
+
const { setLocale } = useLocale({
|
|
1325
|
+
onLocaleChange: (locale) => {
|
|
1326
|
+
router.push(getLocalizedUrl(pathWithoutLocale, locale));
|
|
1327
|
+
},
|
|
1328
|
+
});
|
|
1329
|
+
|
|
1330
|
+
return (
|
|
1331
|
+
<button onClick={() => setLocale(Locales.FRENCH)}>
|
|
1332
|
+
Chuyển sang tiếng Pháp
|
|
1333
|
+
</button>
|
|
1334
|
+
);
|
|
1335
|
+
```
|
|
1336
|
+
|
|
1337
|
+
> Tham khảo tài liệu:
|
|
1338
|
+
>
|
|
1339
|
+
> - [`useLocale` hook](https://github.com/aymericzip/intlayer/blob/main/docs/docs/vi/packages/next-intlayer/useLocale.md)
|
|
1340
|
+
> - [`getLocaleName` hook](https://github.com/aymericzip/intlayer/blob/main/docs/docs/vi/packages/intlayer/getLocaleName.md)
|
|
1341
|
+
> - [`getLocalizedUrl` hook](https://github.com/aymericzip/intlayer/blob/main/docs/docs/vi/packages/intlayer/getLocalizedUrl.md)
|
|
1342
|
+
> - [`getHTMLTextDir` hook](https://github.com/aymericzip/intlayer/blob/main/docs/docs/vi/packages/intlayer/getHTMLTextDir.md)
|
|
1343
|
+
> - [`hrefLang` attribute](https://developers.google.com/search/docs/specialty/international/localized-versions?hl=fr)
|
|
1344
|
+
> - [`thuộc tính lang`](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/lang)
|
|
1345
|
+
> - [`thuộc tính dir`](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/dir)
|
|
1346
|
+
> - [`thuộc tính aria-current`](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-current)
|
|
1347
|
+
|
|
1348
|
+
### (Tùy chọn) Bước 11: Tạo một Component Link Đa Ngôn Ngữ
|
|
1349
|
+
|
|
1350
|
+
Để đảm bảo rằng điều hướng trong ứng dụng của bạn tuân thủ ngôn ngữ hiện tại, bạn có thể tạo một component `Link` tùy chỉnh. Component này tự động thêm tiền tố ngôn ngữ hiện tại vào các URL nội bộ. Ví dụ, khi một người dùng nói tiếng Pháp nhấp vào liên kết đến trang "About", họ sẽ được chuyển hướng đến `/fr/about` thay vì `/about`.
|
|
1351
|
+
|
|
1352
|
+
Hành vi này hữu ích vì một số lý do sau:
|
|
1353
|
+
|
|
1354
|
+
- **SEO và Trải nghiệm Người dùng**: URL được địa phương hóa giúp các công cụ tìm kiếm lập chỉ mục chính xác các trang theo ngôn ngữ và cung cấp nội dung cho người dùng theo ngôn ngữ ưu tiên của họ.
|
|
1355
|
+
- **Tính nhất quán**: Bằng cách sử dụng liên kết được địa phương hóa trong toàn bộ ứng dụng của bạn, bạn đảm bảo rằng điều hướng luôn nằm trong ngữ cảnh ngôn ngữ hiện tại, tránh việc chuyển đổi ngôn ngữ không mong muốn.
|
|
1356
|
+
- **Dễ bảo trì**: Tập trung logic địa phương hóa trong một component duy nhất giúp đơn giản hóa việc quản lý URL, làm cho codebase của bạn dễ bảo trì và mở rộng khi ứng dụng phát triển.
|
|
1357
|
+
|
|
1358
|
+
Dưới đây là triển khai của một component `Link` được địa phương hóa bằng TypeScript:
|
|
1359
|
+
|
|
1360
|
+
```tsx fileName="src/components/Link.tsx" codeFormat="typescript"
|
|
1361
|
+
"use client";
|
|
1362
|
+
|
|
1363
|
+
import { getLocalizedUrl } from "intlayer";
|
|
1364
|
+
import NextLink, { type LinkProps as NextLinkProps } from "next/link";
|
|
1365
|
+
import { useLocale } from "next-intlayer";
|
|
1366
|
+
import { forwardRef, PropsWithChildren, type ForwardedRef } from "react";
|
|
1367
|
+
|
|
1368
|
+
/**
|
|
1369
|
+
* Hàm tiện ích để kiểm tra xem một URL có phải là liên kết bên ngoài hay không.
|
|
1370
|
+
* Nếu URL bắt đầu bằng http:// hoặc https://, nó được coi là liên kết bên ngoài.
|
|
1371
|
+
*/
|
|
1372
|
+
export const checkIsExternalLink = (href?: string): boolean =>
|
|
1373
|
+
/^https?:\/\//.test(href ?? "");
|
|
1374
|
+
|
|
1375
|
+
/**
|
|
1376
|
+
* Một component Link tùy chỉnh điều chỉnh thuộc tính href dựa trên locale hiện tại.
|
|
1377
|
+
* Đối với các liên kết nội bộ, nó sử dụng `getLocalizedUrl` để thêm tiền tố locale vào URL (ví dụ: /fr/about).
|
|
1378
|
+
* Điều này đảm bảo điều hướng luôn nằm trong cùng ngữ cảnh locale.
|
|
1379
|
+
*/
|
|
1380
|
+
export const Link = forwardRef<
|
|
1381
|
+
HTMLAnchorElement,
|
|
1382
|
+
PropsWithChildren<NextLinkProps>
|
|
1383
|
+
>(({ href, children, ...props }, ref: ForwardedRef<HTMLAnchorElement>) => {
|
|
1384
|
+
const { locale } = useLocale();
|
|
1385
|
+
const isExternalLink = checkIsExternalLink(href.toString());
|
|
1386
|
+
|
|
1387
|
+
// Nếu liên kết là nội bộ và href hợp lệ được cung cấp, lấy URL đã được địa phương hóa.
|
|
1388
|
+
const hrefI18n: NextLinkProps["href"] =
|
|
1389
|
+
href && !isExternalLink ? getLocalizedUrl(href.toString(), locale) : href;
|
|
1390
|
+
|
|
1391
|
+
return (
|
|
1392
|
+
<NextLink href={hrefI18n} ref={ref} {...props}>
|
|
1393
|
+
{children}
|
|
1394
|
+
</NextLink>
|
|
1395
|
+
);
|
|
1396
|
+
});
|
|
1397
|
+
|
|
1398
|
+
Link.displayName = "Link";
|
|
1399
|
+
```
|
|
1400
|
+
|
|
1401
|
+
```jsx fileName="src/components/Link.mjx" codeFormat="esm"
|
|
1402
|
+
'use client';
|
|
1403
|
+
|
|
1404
|
+
import { getLocalizedUrl } from 'intlayer';
|
|
1405
|
+
import NextLink, { type LinkProps as NextLinkProps } from 'next/link';
|
|
1406
|
+
import { useLocale } from 'next-intlayer';
|
|
1407
|
+
import { forwardRef, PropsWithChildren, type ForwardedRef } from 'react';
|
|
1408
|
+
|
|
1409
|
+
/**
|
|
1410
|
+
* Hàm tiện ích để kiểm tra xem một URL có phải là liên kết bên ngoài hay không.
|
|
1411
|
+
* Nếu URL bắt đầu bằng http:// hoặc https://, nó được coi là liên kết bên ngoài.
|
|
1412
|
+
*/
|
|
1413
|
+
export const checkIsExternalLink = (href) =>
|
|
1414
|
+
/^https?:\/\//.test(href ?? '');
|
|
1415
|
+
|
|
1416
|
+
/**
|
|
1417
|
+
* Một component Link tùy chỉnh điều chỉnh thuộc tính href dựa trên locale hiện tại.
|
|
1418
|
+
* Đối với các liên kết nội bộ, nó sử dụng `getLocalizedUrl` để thêm tiền tố locale vào URL (ví dụ: /fr/about).
|
|
1419
|
+
* Điều này đảm bảo rằng việc điều hướng vẫn giữ trong cùng ngữ cảnh locale.
|
|
1420
|
+
*/
|
|
1421
|
+
export const Link = forwardRef(({ href, children, ...props }, ref) => {
|
|
1422
|
+
const { locale } = useLocale();
|
|
1423
|
+
const isExternalLink = checkIsExternalLink(href.toString());
|
|
1424
|
+
|
|
1425
|
+
// Nếu liên kết là nội bộ và href hợp lệ được cung cấp, lấy URL đã được địa phương hóa.
|
|
1426
|
+
const hrefI18n =
|
|
1427
|
+
href && !isExternalLink ? getLocalizedUrl(href.toString(), locale) : href;
|
|
1428
|
+
|
|
1429
|
+
return (
|
|
1430
|
+
<NextLink href={hrefI18n} ref={ref} {...props}>
|
|
1431
|
+
{children}
|
|
1432
|
+
</NextLink>
|
|
1433
|
+
);
|
|
1434
|
+
});
|
|
1435
|
+
|
|
1436
|
+
Link.displayName = 'Link';
|
|
1437
|
+
```
|
|
1438
|
+
|
|
1439
|
+
```jsx fileName="src/components/Link.csx" codeFormat="commonjs"
|
|
1440
|
+
'use client';
|
|
1441
|
+
|
|
1442
|
+
const { getLocalizedUrl } = require("intlayer");
|
|
1443
|
+
const NextLink = require("next/link");
|
|
1444
|
+
const { useLocale } = require("next-intlayer");
|
|
1445
|
+
const { forwardRef } = require("react");
|
|
1446
|
+
|
|
1447
|
+
/**
|
|
1448
|
+
* Hàm tiện ích để kiểm tra xem một URL có phải là liên kết ngoài hay không.
|
|
1449
|
+
* Nếu URL bắt đầu bằng http:// hoặc https://, nó được coi là liên kết ngoài.
|
|
1450
|
+
*/
|
|
1451
|
+
const checkIsExternalLink = (href) =>
|
|
1452
|
+
/^https?:\/\//.test(href ?? '');
|
|
1453
|
+
|
|
1454
|
+
|
|
1455
|
+
const Link = forwardRef(({ href, children, ...props }, ref) => {
|
|
1456
|
+
const { locale } = useLocale();
|
|
1457
|
+
const isExternalLink = checkIsExternalLink(href.toString());
|
|
1458
|
+
|
|
1459
|
+
// Nếu liên kết là nội bộ và href hợp lệ được cung cấp, lấy URL đã được địa phương hóa.
|
|
1460
|
+
const hrefI18n: NextLinkProps['href'] =
|
|
1461
|
+
href && !isExternalLink ? getLocalizedUrl(href.toString(), locale) : href;
|
|
1462
|
+
|
|
1463
|
+
return (
|
|
1464
|
+
<NextLink href={hrefI18n} ref={ref} {...props}>
|
|
1465
|
+
{children}
|
|
1466
|
+
</NextLink>
|
|
1467
|
+
);
|
|
1468
|
+
});
|
|
1469
|
+
|
|
1470
|
+
Link.displayName = 'Link';
|
|
1471
|
+
```
|
|
1472
|
+
|
|
1473
|
+
#### Cách Hoạt Động
|
|
1474
|
+
|
|
1475
|
+
- **Phát hiện Liên kết Ngoài**:
|
|
1476
|
+
Hàm trợ giúp `checkIsExternalLink` xác định xem một URL có phải là liên kết ngoài hay không. Các liên kết ngoài được giữ nguyên vì không cần địa phương hóa.
|
|
1477
|
+
|
|
1478
|
+
- **Lấy Locale Hiện Tại**:
|
|
1479
|
+
- **Lấy URL theo ngôn ngữ**:
|
|
1480
|
+
Đối với các liên kết nội bộ (tức là không phải liên kết ngoài), `getLocalizedUrl` được sử dụng để tự động thêm tiền tố URL với ngôn ngữ hiện tại. Điều này có nghĩa là nếu người dùng của bạn đang dùng tiếng Pháp, việc truyền `/about` làm `href` sẽ chuyển thành `/fr/about`.
|
|
1481
|
+
|
|
1482
|
+
- **Trả về liên kết**:
|
|
1483
|
+
Component trả về một phần tử `<a>` với URL đã được địa phương hóa, đảm bảo điều hướng nhất quán với ngôn ngữ.
|
|
1484
|
+
|
|
1485
|
+
Bằng cách tích hợp component `Link` này trong toàn bộ ứng dụng của bạn, bạn duy trì trải nghiệm người dùng nhất quán và nhận biết ngôn ngữ đồng thời cải thiện SEO và khả năng sử dụng.
|
|
1486
|
+
|
|
1487
|
+
### (Tùy chọn) Bước 12: Lấy ngôn ngữ hiện tại trong Server Actions
|
|
1488
|
+
|
|
1489
|
+
Nếu bạn cần lấy locale đang hoạt động bên trong một Server Action (ví dụ: để địa phương hóa email hoặc chạy logic nhận biết locale), hãy gọi `getLocale` từ `next-intlayer/server`:
|
|
1490
|
+
|
|
1491
|
+
```tsx fileName="src/app/actions/getLocale.ts" codeFormat="typescript"
|
|
1492
|
+
"use server";
|
|
1493
|
+
|
|
1494
|
+
import { getLocale } from "next-intlayer/server";
|
|
1495
|
+
|
|
1496
|
+
export const myServerAction = async () => {
|
|
1497
|
+
const locale = await getLocale();
|
|
1498
|
+
|
|
1499
|
+
// Thực hiện một số việc với locale
|
|
1500
|
+
};
|
|
1501
|
+
```
|
|
1502
|
+
|
|
1503
|
+
> Hàm `getLocale` tuân theo chiến lược phân tầng để xác định locale của người dùng:
|
|
1504
|
+
>
|
|
1505
|
+
> 1. Đầu tiên, nó kiểm tra các header của yêu cầu để tìm giá trị locale có thể đã được middleware thiết lập
|
|
1506
|
+
> 2. Nếu không tìm thấy locale trong header, nó sẽ tìm locale được lưu trong cookie
|
|
1507
|
+
> 3. Nếu không tìm thấy cookie, nó sẽ cố gắng phát hiện ngôn ngữ ưu tiên của người dùng từ cài đặt trình duyệt của họ
|
|
1508
|
+
> 4. Trong trường hợp cuối cùng, nó sẽ sử dụng locale mặc định được cấu hình trong ứng dụng
|
|
1509
|
+
>
|
|
1510
|
+
> Điều này đảm bảo locale phù hợp nhất được chọn dựa trên ngữ cảnh có sẵn.
|
|
1511
|
+
|
|
1512
|
+
### (Tùy chọn) Bước 13: Tối ưu kích thước bundle của bạn
|
|
1513
|
+
|
|
1514
|
+
Khi sử dụng `next-intlayer`, các từ điển được bao gồm trong bundle cho mỗi trang theo mặc định. Để tối ưu kích thước bundle, Intlayer cung cấp một plugin SWC tùy chọn thay thế thông minh các lệnh gọi `useIntlayer` bằng cách sử dụng macro. Điều này đảm bảo các từ điển chỉ được bao gồm trong các bundle của những trang thực sự sử dụng chúng.
|
|
1515
|
+
|
|
1516
|
+
Để kích hoạt tối ưu này, hãy cài đặt gói `@intlayer/swc`. Khi đã cài đặt, `next-intlayer` sẽ tự động phát hiện và sử dụng plugin:
|
|
1517
|
+
|
|
1518
|
+
```bash packageManager="npm"
|
|
1519
|
+
npm install @intlayer/swc --save-dev
|
|
1520
|
+
```
|
|
1521
|
+
|
|
1522
|
+
```bash packageManager="pnpm"
|
|
1523
|
+
pnpm add @intlayer/swc --save-dev
|
|
1524
|
+
```
|
|
1525
|
+
|
|
1526
|
+
```bash packageManager="yarn"
|
|
1527
|
+
yarn add @intlayer/swc --save-dev
|
|
1528
|
+
```
|
|
1529
|
+
|
|
1530
|
+
> Lưu ý: Tối ưu hóa này chỉ khả dụng cho Next.js 13 trở lên.
|
|
1531
|
+
|
|
1532
|
+
> Lưu ý: Gói này không được cài đặt mặc định vì các plugin SWC vẫn đang trong giai đoạn thử nghiệm trên Next.js. Điều này có thể thay đổi trong tương lai.
|
|
1533
|
+
|
|
1534
|
+
> Lưu ý: Nếu bạn đặt tùy chọn là `importMode: 'dynamic'` hoặc `importMode: 'live'`, nó sẽ dựa vào Suspense, vì vậy bạn sẽ phải bao bọc các lệnh gọi `useIntlayer` của mình trong một vùng `Suspense`. Điều đó có nghĩa là bạn sẽ không thể sử dụng `useIntlayer` trực tiếp ở cấp trên cùng của thành phần Page / Layout của bạn.
|
|
1535
|
+
|
|
1536
|
+
### Cấu hình TypeScript
|
|
1537
|
+
|
|
1538
|
+
Intlayer sử dụng module augmentation để tận dụng lợi ích của TypeScript và làm cho codebase của bạn mạnh mẽ hơn.
|
|
1539
|
+
|
|
1540
|
+

|
|
1541
|
+
|
|
1542
|
+

|
|
1543
|
+
|
|
1544
|
+
Đảm bảo cấu hình TypeScript của bạn bao gồm các kiểu được tạo tự động.
|
|
1545
|
+
|
|
1546
|
+
```json5 fileName="tsconfig.json"
|
|
1547
|
+
{
|
|
1548
|
+
// ... Các cấu hình TypeScript hiện có của bạn
|
|
1549
|
+
"include": [
|
|
1550
|
+
// ... Các cấu hình TypeScript hiện có của bạn
|
|
1551
|
+
".intlayer/**/*.ts", // Bao gồm các kiểu được tạo tự động
|
|
1552
|
+
],
|
|
1553
|
+
}
|
|
1554
|
+
```
|
|
1555
|
+
|
|
1556
|
+
### Cấu hình Git
|
|
1557
|
+
|
|
1558
|
+
Khuyến nghị bỏ qua các tệp được tạo bởi Intlayer. Điều này giúp bạn tránh việc commit chúng vào kho Git của mình.
|
|
1559
|
+
|
|
1560
|
+
Để làm điều này, bạn có thể thêm các chỉ dẫn sau vào tệp `.gitignore` của bạn:
|
|
1561
|
+
|
|
1562
|
+
```plaintext fileName=".gitignore"
|
|
1563
|
+
# Bỏ qua các tệp được tạo bởi Intlayer
|
|
1564
|
+
.intlayer
|
|
1565
|
+
```
|
|
1566
|
+
|
|
1567
|
+
### Tiện ích mở rộng VS Code
|
|
1568
|
+
|
|
1569
|
+
Để cải thiện trải nghiệm phát triển với Intlayer, bạn có thể cài đặt **Tiện ích mở rộng Intlayer cho VS Code** chính thức.
|
|
1570
|
+
|
|
1571
|
+
[Cài đặt từ VS Code Marketplace](https://marketplace.visualstudio.com/items?itemName=intlayer.intlayer-vs-code-extension)
|
|
1572
|
+
|
|
1573
|
+
Tiện ích mở rộng này cung cấp:
|
|
1574
|
+
|
|
1575
|
+
- **Tự động hoàn thành** cho các khóa dịch.
|
|
1576
|
+
- **Phát hiện lỗi thời gian thực** cho các bản dịch bị thiếu.
|
|
1577
|
+
- **Xem trước nội dung dịch ngay trong dòng**.
|
|
1578
|
+
- **Các hành động nhanh** để dễ dàng tạo và cập nhật bản dịch.
|
|
1579
|
+
|
|
1580
|
+
Để biết thêm chi tiết về cách sử dụng tiện ích mở rộng, tham khảo [tài liệu Tiện ích mở rộng Intlayer cho VS Code](https://intlayer.org/doc/vs-code-extension).
|
|
1581
|
+
|
|
1582
|
+
### Tiến xa hơn
|
|
1583
|
+
|
|
1584
|
+
Để tiến xa hơn, bạn có thể triển khai [trình soạn thảo trực quan](https://github.com/aymericzip/intlayer/blob/main/docs/docs/vi/intlayer_visual_editor.md) hoặc tách nội dung của bạn ra bên ngoài bằng cách sử dụng [CMS](https://github.com/aymericzip/intlayer/blob/main/docs/docs/vi/intlayer_CMS.md).
|