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

|
|
1694
|
+
|
|
1695
|
+

|
|
1696
|
+
|
|
1697
|
+
Đảm bảo cấu hình TypeScript của bạn bao gồm các kiểu được tự động tạo.
|
|
1698
|
+
|
|
1699
|
+
```json5 fileName="tsconfig.json"
|
|
1700
|
+
{
|
|
1701
|
+
// ... Các cấu hình TypeScript hiện có của bạn
|
|
1702
|
+
"include": [
|
|
1703
|
+
// ... Các cấu hình TypeScript hiện có của bạn
|
|
1704
|
+
".intlayer/**/*.ts", // Bao gồm các kiểu được tự động tạo
|
|
1705
|
+
],
|
|
1706
|
+
}
|
|
1707
|
+
```
|
|
1708
|
+
|
|
1709
|
+
### Cấu hình Git
|
|
1710
|
+
|
|
1711
|
+
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.
|
|
1712
|
+
|
|
1713
|
+
Để làm điều này, bạn có thể thêm các hướng dẫn sau vào tệp `.gitignore` của bạn:
|
|
1714
|
+
|
|
1715
|
+
```plaintext fileName=".gitignore"
|
|
1716
|
+
# Bỏ qua các tệp được tạo bởi Intlayer
|
|
1717
|
+
.intlayer
|
|
1718
|
+
```
|
|
1719
|
+
|
|
1720
|
+
### Tiện ích mở rộng VS Code
|
|
1721
|
+
|
|
1722
|
+
Để 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.
|
|
1723
|
+
|
|
1724
|
+
[Cài đặt từ VS Code Marketplace](https://marketplace.visualstudio.com/items?itemName=intlayer.intlayer-vs-code-extension)
|
|
1725
|
+
|
|
1726
|
+
Tiện ích mở rộng này cung cấp:
|
|
1727
|
+
|
|
1728
|
+
- **Tự động hoàn thành** cho các khóa dịch.
|
|
1729
|
+
- **Phát hiện lỗi theo thời gian thực** cho các bản dịch bị thiếu.
|
|
1730
|
+
- **Xem trước nội dung dịch ngay trong dòng**.
|
|
1731
|
+
- **Hành động nhanh** để dễ dàng tạo và cập nhật các bản dịch.
|
|
1732
|
+
|
|
1733
|
+
Để biết thêm chi tiết về cách sử dụng tiện ích mở rộng, hãy tham khảo [Tài liệu Tiện ích mở rộng Intlayer cho VS Code](https://intlayer.org/doc/vs-code-extension).
|
|
1734
|
+
|
|
1735
|
+
### Đi xa hơn
|
|
1736
|
+
|
|
1737
|
+
Để đi 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).
|
|
1738
|
+
````
|