@intlayer/docs 7.0.7 → 7.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/blog/ar/i18n_using_next-i18next.md +1068 -0
- package/blog/ar/i18n_using_next-intl.md +768 -0
- package/blog/ar/intlayer_with_react-intl.md +0 -4
- package/blog/ar/next-i18next_vs_next-intl_vs_intlayer.md +5 -4
- package/blog/de/i18n_using_next-i18next.md +1107 -0
- package/blog/de/i18n_using_next-intl.md +760 -0
- package/blog/de/intlayer_with_react-intl.md +0 -4
- package/blog/de/next-i18next_vs_next-intl_vs_intlayer.md +2 -0
- package/blog/en/i18n_using_next-i18next.md +1073 -0
- package/blog/en/i18n_using_next-intl.md +757 -0
- package/blog/en/intlayer_with_i18next.md +71 -8
- package/blog/en/intlayer_with_next-i18next.md +71 -8
- package/blog/en/intlayer_with_next-intl.md +71 -8
- package/blog/en/intlayer_with_react-i18next.md +69 -8
- package/blog/en/intlayer_with_react-intl.md +68 -9
- package/blog/en/intlayer_with_vue-i18n.md +68 -7
- package/blog/en/react-i18next_vs_react-intl_vs_intlayer.md +2 -0
- package/blog/en/vue-i18n_vs_intlayer.md +2 -0
- package/blog/en-GB/i18n_using_next-i18next.md +1074 -0
- package/blog/en-GB/i18n_using_next-intl.md +757 -0
- package/blog/en-GB/intlayer_with_i18next.md +15 -6
- package/blog/en-GB/intlayer_with_next-i18next.md +16 -6
- package/blog/en-GB/intlayer_with_next-intl.md +16 -6
- package/blog/en-GB/intlayer_with_react-i18next.md +16 -7
- package/blog/en-GB/intlayer_with_react-intl.md +14 -9
- package/blog/en-GB/intlayer_with_vue-i18n.md +16 -7
- package/blog/en-GB/next-i18next_vs_next-intl_vs_intlayer.md +2 -0
- package/blog/en-GB/react-i18next_vs_react-intl_vs_intlayer.md +2 -0
- package/blog/en-GB/vue-i18n_vs_intlayer.md +2 -0
- package/blog/es/i18n_using_next-i18next.md +1066 -0
- package/blog/es/i18n_using_next-intl.md +757 -0
- package/blog/es/intlayer_with_react-intl.md +0 -4
- package/blog/es/next-i18next_vs_next-intl_vs_intlayer.md +2 -0
- package/blog/fr/i18n_using_next-i18next.md +1078 -0
- package/blog/fr/i18n_using_next-intl.md +759 -0
- package/blog/fr/intlayer_with_react-intl.md +0 -4
- package/blog/fr/next-i18next_vs_next-intl_vs_intlayer.md +2 -0
- package/blog/hi/i18n_using_next-i18next.md +1068 -0
- package/blog/hi/i18n_using_next-intl.md +758 -0
- package/blog/hi/intlayer_with_react-intl.md +0 -4
- package/blog/hi/next-i18next_vs_next-intl_vs_intlayer.md +2 -0
- package/blog/id/i18n_using_next-i18next.md +1078 -0
- package/blog/id/i18n_using_next-intl.md +757 -0
- package/blog/id/index.md +69 -0
- package/blog/id/internationalization_and_SEO.md +364 -0
- package/blog/id/intlayer_with_react-intl.md +0 -4
- package/blog/id/list_i18n_technologies/CMS/drupal.md +143 -0
- package/blog/id/list_i18n_technologies/CMS/wix.md +167 -0
- package/blog/id/list_i18n_technologies/CMS/wordpress.md +188 -0
- package/blog/id/list_i18n_technologies/frameworks/angular.md +125 -0
- package/blog/id/list_i18n_technologies/frameworks/flutter.md +150 -0
- package/blog/id/list_i18n_technologies/frameworks/react-native.md +217 -0
- package/blog/id/list_i18n_technologies/frameworks/react.md +155 -0
- package/blog/id/list_i18n_technologies/frameworks/svelte.md +131 -0
- package/blog/id/list_i18n_technologies/frameworks/vue.md +130 -0
- package/blog/id/next-i18next_vs_next-intl_vs_intlayer.md +1500 -0
- package/blog/id/nextjs-multilingual-seo-comparison.md +361 -0
- package/blog/id/rag_powered_documentation_assistant.md +288 -0
- package/blog/id/react-i18next_vs_react-intl_vs_intlayer.md +164 -0
- package/blog/id/vue-i18n_vs_intlayer.md +278 -0
- package/blog/id/what_is_internationalization.md +166 -0
- package/blog/it/i18n_using_next-i18next.md +1078 -0
- package/blog/it/i18n_using_next-intl.md +758 -0
- package/blog/it/intlayer_with_react-intl.md +0 -4
- package/blog/it/react-i18next_vs_react-intl_vs_intlayer.md +4 -0
- package/blog/it/vue-i18n_vs_intlayer.md +2 -0
- package/blog/ja/i18n_using_next-i18next.md +1078 -0
- package/blog/ja/i18n_using_next-intl.md +758 -0
- package/blog/ja/intlayer_with_react-intl.md +0 -4
- package/blog/ja/next-i18next_vs_next-intl_vs_intlayer.md +2 -0
- package/blog/ko/i18n_using_next-i18next.md +1075 -0
- package/blog/ko/i18n_using_next-intl.md +759 -0
- package/blog/ko/intlayer_with_react-intl.md +0 -4
- package/blog/ko/next-i18next_vs_next-intl_vs_intlayer.md +2 -0
- package/blog/pl/i18n_using_next-i18next.md +1078 -0
- package/blog/pl/i18n_using_next-intl.md +758 -0
- package/blog/pl/index.md +69 -0
- package/blog/pl/internationalization_and_SEO.md +363 -0
- package/blog/pl/intlayer_with_react-intl.md +0 -4
- package/blog/pl/list_i18n_technologies/CMS/drupal.md +143 -0
- package/blog/pl/list_i18n_technologies/CMS/wix.md +167 -0
- package/blog/pl/list_i18n_technologies/CMS/wordpress.md +196 -0
- package/blog/pl/list_i18n_technologies/frameworks/angular.md +125 -0
- package/blog/pl/list_i18n_technologies/frameworks/flutter.md +151 -0
- package/blog/pl/list_i18n_technologies/frameworks/react-native.md +217 -0
- package/blog/pl/list_i18n_technologies/frameworks/react.md +155 -0
- package/blog/pl/list_i18n_technologies/frameworks/svelte.md +131 -0
- package/blog/pl/list_i18n_technologies/frameworks/vue.md +130 -0
- package/blog/pl/next-i18next_vs_next-intl_vs_intlayer.md +1501 -0
- package/blog/pl/nextjs-multilingual-seo-comparison.md +362 -0
- package/blog/pl/rag_powered_documentation_assistant.md +288 -0
- package/blog/pl/react-i18next_vs_react-intl_vs_intlayer.md +164 -0
- package/blog/pl/vue-i18n_vs_intlayer.md +278 -0
- package/blog/pl/what_is_internationalization.md +167 -0
- package/blog/pt/i18n_using_next-i18next.md +1067 -0
- package/blog/pt/i18n_using_next-intl.md +760 -0
- package/blog/pt/next-i18next_vs_next-intl_vs_intlayer.md +2 -0
- package/blog/ru/i18n_using_next-i18next.md +1106 -0
- package/blog/ru/i18n_using_next-intl.md +759 -0
- package/blog/ru/intlayer_with_react-intl.md +0 -4
- package/blog/ru/next-i18next_vs_next-intl_vs_intlayer.md +2 -0
- package/blog/tr/i18n_using_next-i18next.md +1078 -0
- package/blog/tr/i18n_using_next-intl.md +760 -0
- package/blog/tr/intlayer_with_react-intl.md +0 -4
- package/blog/tr/next-i18next_vs_next-intl_vs_intlayer.md +2 -0
- package/blog/tr/react-i18next_vs_react-intl_vs_intlayer.md +2 -0
- package/blog/tr/vue-i18n_vs_intlayer.md +2 -0
- package/blog/vi/i18n_using_next-i18next.md +1080 -0
- package/blog/vi/i18n_using_next-intl.md +758 -0
- package/blog/vi/index.md +69 -0
- package/blog/vi/internationalization_and_SEO.md +363 -0
- package/blog/vi/intlayer_with_react-intl.md +0 -4
- package/blog/vi/list_i18n_technologies/CMS/drupal.md +143 -0
- package/blog/vi/list_i18n_technologies/CMS/wix.md +167 -0
- package/blog/vi/list_i18n_technologies/CMS/wordpress.md +188 -0
- package/blog/vi/list_i18n_technologies/frameworks/angular.md +125 -0
- package/blog/vi/list_i18n_technologies/frameworks/flutter.md +150 -0
- package/blog/vi/list_i18n_technologies/frameworks/react-native.md +217 -0
- package/blog/vi/list_i18n_technologies/frameworks/react.md +155 -0
- package/blog/vi/list_i18n_technologies/frameworks/svelte.md +131 -0
- package/blog/vi/list_i18n_technologies/frameworks/vue.md +130 -0
- package/blog/vi/next-i18next_vs_next-intl_vs_intlayer.md +1520 -0
- package/blog/vi/nextjs-multilingual-seo-comparison.md +362 -0
- package/blog/vi/rag_powered_documentation_assistant.md +288 -0
- package/blog/vi/react-i18next_vs_react-intl_vs_intlayer.md +164 -0
- package/blog/vi/vue-i18n_vs_intlayer.md +278 -0
- package/blog/vi/what_is_internationalization.md +168 -0
- package/blog/zh/i18n_using_next-i18next.md +1105 -0
- package/blog/zh/i18n_using_next-intl.md +758 -0
- package/blog/zh/intlayer_with_react-intl.md +0 -4
- package/blog/zh/next-i18next_vs_next-intl_vs_intlayer.md +2 -0
- package/blog/zh/react-i18next_vs_react-intl_vs_intlayer.md +2 -0
- package/dist/cjs/common.cjs +0 -4
- package/dist/cjs/common.cjs.map +1 -1
- package/dist/cjs/generated/blog.entry.cjs +38 -6
- package/dist/cjs/generated/blog.entry.cjs.map +1 -1
- package/dist/cjs/generated/docs.entry.cjs +0 -6
- package/dist/cjs/generated/docs.entry.cjs.map +1 -1
- package/dist/cjs/generated/frequentQuestions.entry.cjs +0 -6
- package/dist/cjs/generated/frequentQuestions.entry.cjs.map +1 -1
- package/dist/cjs/generated/legal.entry.cjs +0 -6
- package/dist/cjs/generated/legal.entry.cjs.map +1 -1
- package/dist/esm/generated/blog.entry.mjs +38 -0
- package/dist/esm/generated/blog.entry.mjs.map +1 -1
- package/dist/types/generated/blog.entry.d.ts +2 -0
- package/dist/types/generated/blog.entry.d.ts.map +1 -1
- package/docs/ar/component_i18n.md +1 -1
- package/docs/ar/configuration.md +6 -0
- package/docs/ar/intlayer_cli.md +8 -3
- package/docs/ar/intlayer_with_next-i18next.md +619 -0
- package/docs/ar/intlayer_with_next-intl.md +446 -0
- package/docs/ar/intlayer_with_nextjs_16.md +21 -0
- package/docs/ar/intlayer_with_tanstack.md +4 -0
- package/docs/ar/intlayer_with_vite+react.md +4 -0
- package/docs/de/component_i18n.md +1 -1
- package/docs/de/configuration.md +6 -0
- package/docs/de/intlayer_cli.md +8 -3
- package/docs/de/intlayer_with_next-i18next.md +627 -0
- package/docs/de/intlayer_with_next-intl.md +451 -0
- package/docs/de/intlayer_with_nextjs_16.md +21 -0
- package/docs/de/intlayer_with_tanstack.md +4 -0
- package/docs/de/intlayer_with_vite+react.md +4 -0
- package/docs/en/component_i18n.md +1 -1
- package/docs/en/intlayer_cli.md +8 -1
- package/docs/en/intlayer_with_astro.md +10 -2
- package/docs/en/intlayer_with_create_react_app.md +8 -0
- package/docs/en/intlayer_with_lynx+react.md +8 -0
- package/docs/en/intlayer_with_nestjs.md +10 -0
- package/docs/en/intlayer_with_nextjs_14.md +10 -2
- package/docs/en/intlayer_with_nextjs_15.md +21 -4
- package/docs/en/intlayer_with_nextjs_16.md +17 -0
- package/docs/en/intlayer_with_nuxt.md +8 -0
- package/docs/en/intlayer_with_react_native+expo.md +10 -2
- package/docs/en/intlayer_with_react_router_v7.md +8 -0
- package/docs/en/intlayer_with_tanstack.md +10 -0
- package/docs/en/intlayer_with_vite+preact.md +10 -2
- package/docs/en/intlayer_with_vite+react.md +21 -4
- package/docs/en/intlayer_with_vite+vue.md +10 -2
- package/docs/en-GB/component_i18n.md +1 -1
- package/docs/en-GB/configuration.md +6 -0
- package/docs/en-GB/intlayer_cli.md +8 -3
- package/docs/en-GB/intlayer_with_angular.md +4 -4
- package/docs/en-GB/intlayer_with_express.md +4 -4
- package/docs/en-GB/intlayer_with_lynx+react.md +12 -12
- package/{blog/en/_intlayer_with_next-i18next.md → docs/en-GB/intlayer_with_next-i18next.md} +241 -42
- package/{blog/en/_intlayer_with_next-intl.md → docs/en-GB/intlayer_with_next-intl.md} +144 -29
- package/docs/en-GB/intlayer_with_nextjs_16.md +21 -0
- package/docs/en-GB/intlayer_with_tanstack.md +5 -1
- package/docs/en-GB/intlayer_with_vite+react.md +4 -0
- package/docs/en-GB/packages/next-intlayer/t.md +2 -2
- package/docs/es/component_i18n.md +1 -1
- package/docs/es/configuration.md +6 -0
- package/docs/es/intlayer_cli.md +8 -3
- package/docs/es/intlayer_with_next-i18next.md +628 -0
- package/docs/es/intlayer_with_next-intl.md +446 -0
- package/docs/es/intlayer_with_nextjs_16.md +21 -0
- package/docs/es/intlayer_with_tanstack.md +4 -0
- package/docs/es/intlayer_with_vite+react.md +4 -0
- package/docs/fr/configuration.md +6 -0
- package/docs/fr/intlayer_cli.md +8 -3
- package/docs/fr/intlayer_with_next-i18next.md +628 -0
- package/docs/fr/intlayer_with_next-intl.md +446 -0
- package/docs/fr/intlayer_with_nextjs_16.md +23 -2
- package/docs/fr/intlayer_with_tanstack.md +4 -0
- package/docs/fr/intlayer_with_vite+react.md +4 -0
- package/docs/hi/component_i18n.md +1 -1
- package/docs/hi/configuration.md +6 -0
- package/docs/hi/intlayer_cli.md +8 -0
- package/docs/hi/intlayer_with_next-i18next.md +628 -0
- package/docs/hi/intlayer_with_next-intl.md +446 -0
- package/docs/hi/intlayer_with_nextjs_16.md +21 -0
- package/docs/hi/intlayer_with_tanstack.md +4 -0
- package/docs/hi/intlayer_with_vite+react.md +4 -0
- package/docs/id/CI_CD.md +198 -0
- package/docs/id/autoFill.md +284 -0
- package/docs/id/component_i18n.md +186 -0
- package/docs/id/configuration.md +710 -0
- package/docs/id/dictionary/condition.md +231 -0
- package/docs/id/dictionary/content_file.md +1092 -0
- package/docs/id/dictionary/enumeration.md +245 -0
- package/docs/id/dictionary/file.md +237 -0
- package/docs/id/dictionary/function_fetching.md +214 -0
- package/docs/id/dictionary/gender.md +273 -0
- package/docs/id/dictionary/insertion.md +192 -0
- package/docs/id/dictionary/markdown.md +381 -0
- package/docs/id/dictionary/nesting.md +273 -0
- package/docs/id/dictionary/translation.md +310 -0
- package/docs/id/formatters.md +596 -0
- package/docs/id/how_works_intlayer.md +256 -0
- package/docs/id/index.md +176 -0
- package/docs/id/interest_of_intlayer.md +293 -0
- package/docs/id/intlayer_CMS.md +549 -0
- package/docs/id/intlayer_cli.md +850 -0
- package/docs/id/intlayer_visual_editor.md +288 -0
- package/docs/id/intlayer_with_angular.md +694 -0
- package/docs/id/intlayer_with_astro.md +252 -0
- package/docs/id/intlayer_with_create_react_app.md +1233 -0
- package/docs/id/intlayer_with_express.md +411 -0
- package/docs/id/intlayer_with_lynx+react.md +518 -0
- package/docs/id/intlayer_with_nestjs.md +272 -0
- package/docs/id/intlayer_with_next-i18next.md +628 -0
- package/docs/id/intlayer_with_next-intl.md +446 -0
- package/docs/id/intlayer_with_nextjs_14.md +1617 -0
- package/docs/id/intlayer_with_nextjs_15.md +1698 -0
- package/docs/id/intlayer_with_nextjs_16.md +21 -0
- package/docs/id/intlayer_with_nextjs_page_router.md +1478 -0
- package/docs/id/intlayer_with_nuxt.md +808 -0
- package/docs/id/intlayer_with_react_native+expo.md +699 -0
- package/docs/id/intlayer_with_react_router_v7.md +496 -0
- package/docs/id/intlayer_with_tanstack.md +564 -0
- package/docs/id/intlayer_with_vite+preact.md +1737 -0
- package/docs/id/intlayer_with_vite+react.md +1413 -0
- package/docs/id/intlayer_with_vite+solid.md +289 -0
- package/docs/id/intlayer_with_vite+svelte.md +289 -0
- package/docs/id/intlayer_with_vite+vue.md +1088 -0
- package/docs/id/introduction.md +218 -0
- package/docs/id/locale_mapper.md +242 -0
- package/docs/id/mcp_server.md +211 -0
- package/docs/id/packages/express-intlayer/t.md +458 -0
- package/docs/id/packages/intlayer/getConfiguration.md +145 -0
- package/docs/id/packages/intlayer/getEnumeration.md +159 -0
- package/docs/id/packages/intlayer/getHTMLTextDir.md +122 -0
- package/docs/id/packages/intlayer/getLocaleLang.md +81 -0
- package/docs/id/packages/intlayer/getLocaleName.md +119 -0
- package/docs/id/packages/intlayer/getLocalizedUrl.md +309 -0
- package/docs/id/packages/intlayer/getMultilingualUrls.md +223 -0
- package/docs/id/packages/intlayer/getPathWithoutLocale.md +75 -0
- package/docs/id/packages/intlayer/getTranslation.md +190 -0
- package/docs/id/packages/intlayer/getTranslationContent.md +188 -0
- package/docs/id/packages/next-intlayer/t.md +352 -0
- package/docs/id/packages/next-intlayer/useDictionary.md +271 -0
- package/docs/id/packages/next-intlayer/useIntlayer.md +264 -0
- package/docs/id/packages/next-intlayer/useLocale.md +166 -0
- package/docs/id/packages/react-intlayer/t.md +303 -0
- package/docs/id/packages/react-intlayer/useDictionary.md +287 -0
- package/docs/id/packages/react-intlayer/useI18n.md +267 -0
- package/docs/id/packages/react-intlayer/useIntlayer.md +254 -0
- package/docs/id/packages/react-intlayer/useLocale.md +210 -0
- package/docs/id/per_locale_file.md +323 -0
- package/docs/id/readme.md +261 -0
- package/docs/id/releases/v6.md +305 -0
- package/docs/id/roadmap.md +362 -0
- package/docs/id/testing.md +202 -0
- package/docs/id/vs_code_extension.md +126 -0
- package/docs/it/component_i18n.md +1 -1
- package/docs/it/configuration.md +6 -0
- package/docs/it/intlayer_cli.md +8 -3
- package/docs/it/intlayer_with_next-i18next.md +628 -0
- package/docs/it/intlayer_with_next-intl.md +446 -0
- package/docs/it/intlayer_with_nextjs_16.md +21 -0
- package/docs/it/intlayer_with_tanstack.md +4 -0
- package/docs/it/intlayer_with_vite+react.md +4 -0
- package/docs/ja/component_i18n.md +1 -1
- package/docs/ja/configuration.md +6 -0
- package/docs/ja/intlayer_cli.md +8 -3
- package/docs/ja/intlayer_with_next-i18next.md +627 -0
- package/docs/ja/intlayer_with_next-intl.md +446 -0
- package/docs/ja/intlayer_with_nextjs_16.md +21 -0
- package/docs/ja/intlayer_with_tanstack.md +4 -0
- package/docs/ja/intlayer_with_vite+react.md +4 -0
- package/docs/ko/configuration.md +6 -0
- package/docs/ko/intlayer_cli.md +8 -3
- package/docs/ko/intlayer_with_next-i18next.md +627 -0
- package/docs/ko/intlayer_with_next-intl.md +446 -0
- package/docs/ko/intlayer_with_nextjs_16.md +21 -0
- package/docs/ko/intlayer_with_tanstack.md +4 -0
- package/docs/ko/intlayer_with_vite+react.md +4 -0
- package/docs/pl/CI_CD.md +198 -0
- package/docs/pl/autoFill.md +284 -0
- package/docs/pl/component_i18n.md +186 -0
- package/docs/pl/configuration.md +710 -0
- package/docs/pl/dictionary/condition.md +232 -0
- package/docs/pl/dictionary/content_file.md +1130 -0
- package/docs/pl/dictionary/enumeration.md +245 -0
- package/docs/pl/dictionary/file.md +234 -0
- package/docs/pl/dictionary/function_fetching.md +214 -0
- package/docs/pl/dictionary/gender.md +276 -0
- package/docs/pl/dictionary/insertion.md +188 -0
- package/docs/pl/dictionary/markdown.md +408 -0
- package/docs/pl/dictionary/nesting.md +273 -0
- package/docs/pl/dictionary/translation.md +310 -0
- package/docs/pl/formatters.md +596 -0
- package/docs/pl/how_works_intlayer.md +256 -0
- package/docs/pl/index.md +176 -0
- package/docs/pl/interest_of_intlayer.md +291 -0
- package/docs/pl/intlayer_CMS.md +549 -0
- package/docs/pl/intlayer_cli.md +857 -0
- package/docs/pl/intlayer_visual_editor.md +288 -0
- package/docs/pl/intlayer_with_angular.md +690 -0
- package/docs/pl/intlayer_with_astro.md +280 -0
- package/docs/pl/intlayer_with_create_react_app.md +1235 -0
- package/docs/pl/intlayer_with_express.md +411 -0
- package/docs/pl/intlayer_with_lynx+react.md +518 -0
- package/docs/pl/intlayer_with_nestjs.md +272 -0
- package/docs/pl/intlayer_with_next-i18next.md +628 -0
- package/docs/pl/intlayer_with_next-intl.md +446 -0
- package/docs/pl/intlayer_with_nextjs_14.md +1594 -0
- package/docs/pl/intlayer_with_nextjs_15.md +1701 -0
- package/docs/pl/intlayer_with_nextjs_16.md +21 -0
- package/docs/pl/intlayer_with_nextjs_page_router.md +1513 -0
- package/docs/pl/intlayer_with_nuxt.md +885 -0
- package/docs/pl/intlayer_with_react_native+expo.md +698 -0
- package/docs/pl/intlayer_with_react_router_v7.md +503 -0
- package/docs/pl/intlayer_with_tanstack.md +562 -0
- package/docs/pl/intlayer_with_vite+preact.md +1736 -0
- package/docs/pl/intlayer_with_vite+react.md +1438 -0
- package/docs/pl/intlayer_with_vite+solid.md +290 -0
- package/docs/pl/intlayer_with_vite+svelte.md +289 -0
- package/docs/pl/intlayer_with_vite+vue.md +1116 -0
- package/docs/pl/introduction.md +209 -0
- package/docs/pl/locale_mapper.md +242 -0
- package/docs/pl/mcp_server.md +211 -0
- package/docs/pl/packages/express-intlayer/t.md +458 -0
- package/docs/pl/packages/intlayer/getConfiguration.md +146 -0
- package/docs/pl/packages/intlayer/getEnumeration.md +160 -0
- package/docs/pl/packages/intlayer/getHTMLTextDir.md +121 -0
- package/docs/pl/packages/intlayer/getLocaleLang.md +81 -0
- package/docs/pl/packages/intlayer/getLocaleName.md +118 -0
- package/docs/pl/packages/intlayer/getLocalizedUrl.md +300 -0
- package/docs/pl/packages/intlayer/getMultilingualUrls.md +221 -0
- package/docs/pl/packages/intlayer/getPathWithoutLocale.md +75 -0
- package/docs/pl/packages/intlayer/getTranslation.md +190 -0
- package/docs/pl/packages/intlayer/getTranslationContent.md +189 -0
- package/docs/pl/packages/next-intlayer/t.md +353 -0
- package/docs/pl/packages/next-intlayer/useDictionary.md +270 -0
- package/docs/pl/packages/next-intlayer/useIntlayer.md +263 -0
- package/docs/pl/packages/next-intlayer/useLocale.md +166 -0
- package/docs/pl/packages/react-intlayer/t.md +303 -0
- package/docs/pl/packages/react-intlayer/useDictionary.md +289 -0
- package/docs/pl/packages/react-intlayer/useI18n.md +249 -0
- package/docs/pl/packages/react-intlayer/useIntlayer.md +256 -0
- package/docs/pl/packages/react-intlayer/useLocale.md +210 -0
- package/docs/pl/per_locale_file.md +321 -0
- package/docs/pl/readme.md +261 -0
- package/docs/pl/releases/v6.md +305 -0
- package/docs/pl/roadmap.md +362 -0
- package/docs/pl/testing.md +202 -0
- package/docs/pl/vs_code_extension.md +126 -0
- package/docs/pt/component_i18n.md +1 -1
- package/docs/pt/configuration.md +6 -0
- package/docs/pt/intlayer_cli.md +8 -3
- package/docs/pt/intlayer_with_next-i18next.md +627 -0
- package/docs/pt/intlayer_with_next-intl.md +446 -0
- package/docs/pt/intlayer_with_nextjs_16.md +21 -0
- package/docs/pt/intlayer_with_tanstack.md +4 -0
- package/docs/pt/intlayer_with_vite+react.md +4 -0
- package/docs/ru/component_i18n.md +1 -1
- package/docs/ru/configuration.md +6 -0
- package/docs/ru/intlayer_cli.md +301 -22
- package/docs/ru/intlayer_with_next-i18next.md +629 -0
- package/docs/ru/intlayer_with_next-intl.md +448 -0
- package/docs/ru/intlayer_with_nextjs_16.md +21 -0
- package/docs/ru/intlayer_with_tanstack.md +4 -0
- package/docs/ru/intlayer_with_vite+react.md +4 -0
- package/docs/tr/component_i18n.md +1 -1
- package/docs/tr/configuration.md +6 -0
- package/docs/tr/intlayer_cli.md +8 -0
- package/docs/tr/intlayer_with_next-i18next.md +627 -0
- package/docs/tr/intlayer_with_next-intl.md +446 -0
- package/docs/tr/intlayer_with_nextjs_16.md +21 -0
- package/docs/tr/intlayer_with_tanstack.md +4 -0
- package/docs/tr/intlayer_with_vite+react.md +4 -0
- package/docs/vi/CI_CD.md +198 -0
- package/docs/vi/autoFill.md +284 -0
- package/docs/vi/component_i18n.md +186 -0
- package/docs/vi/configuration.md +710 -0
- package/docs/vi/dictionary/condition.md +237 -0
- package/docs/vi/dictionary/content_file.md +1115 -0
- package/docs/vi/dictionary/enumeration.md +255 -0
- package/docs/vi/dictionary/file.md +234 -0
- package/docs/vi/dictionary/function_fetching.md +212 -0
- package/docs/vi/dictionary/gender.md +275 -0
- package/docs/vi/dictionary/insertion.md +191 -0
- package/docs/vi/dictionary/markdown.md +381 -0
- package/docs/vi/dictionary/nesting.md +273 -0
- package/docs/vi/dictionary/translation.md +309 -0
- package/docs/vi/formatters.md +595 -0
- package/docs/vi/how_works_intlayer.md +256 -0
- package/docs/vi/index.md +174 -0
- package/docs/vi/interest_of_intlayer.md +292 -0
- package/docs/vi/intlayer_CMS.md +549 -0
- package/docs/vi/intlayer_cli.md +850 -0
- package/docs/vi/intlayer_visual_editor.md +288 -0
- package/docs/vi/intlayer_with_angular.md +692 -0
- package/docs/vi/intlayer_with_astro.md +252 -0
- package/docs/vi/intlayer_with_create_react_app.md +1230 -0
- package/docs/vi/intlayer_with_express.md +409 -0
- package/docs/vi/intlayer_with_lynx+react.md +520 -0
- package/docs/vi/intlayer_with_nestjs.md +272 -0
- package/docs/vi/intlayer_with_next-i18next.md +628 -0
- package/docs/vi/intlayer_with_next-intl.md +446 -0
- package/docs/vi/intlayer_with_nextjs_14.md +1584 -0
- package/docs/vi/intlayer_with_nextjs_15.md +1738 -0
- package/docs/vi/intlayer_with_nextjs_16.md +21 -0
- package/docs/vi/intlayer_with_nextjs_page_router.md +1504 -0
- package/docs/vi/intlayer_with_nuxt.md +821 -0
- package/docs/vi/intlayer_with_react_native+expo.md +700 -0
- package/docs/vi/intlayer_with_react_router_v7.md +498 -0
- package/docs/vi/intlayer_with_tanstack.md +562 -0
- package/docs/vi/intlayer_with_vite+preact.md +1722 -0
- package/docs/vi/intlayer_with_vite+react.md +1407 -0
- package/docs/vi/intlayer_with_vite+solid.md +287 -0
- package/docs/vi/intlayer_with_vite+svelte.md +289 -0
- package/docs/vi/intlayer_with_vite+vue.md +1071 -0
- package/docs/vi/introduction.md +215 -0
- package/docs/vi/locale_mapper.md +242 -0
- package/docs/vi/mcp_server.md +211 -0
- package/docs/vi/packages/express-intlayer/t.md +457 -0
- package/docs/vi/packages/intlayer/getConfiguration.md +145 -0
- package/docs/vi/packages/intlayer/getEnumeration.md +162 -0
- package/docs/vi/packages/intlayer/getHTMLTextDir.md +121 -0
- package/docs/vi/packages/intlayer/getLocaleLang.md +81 -0
- package/docs/vi/packages/intlayer/getLocaleName.md +129 -0
- package/docs/vi/packages/intlayer/getLocalizedUrl.md +309 -0
- package/docs/vi/packages/intlayer/getMultilingualUrls.md +221 -0
- package/docs/vi/packages/intlayer/getPathWithoutLocale.md +75 -0
- package/docs/vi/packages/intlayer/getTranslation.md +201 -0
- package/docs/vi/packages/intlayer/getTranslationContent.md +188 -0
- package/docs/vi/packages/next-intlayer/t.md +352 -0
- package/docs/vi/packages/next-intlayer/useDictionary.md +273 -0
- package/docs/vi/packages/next-intlayer/useIntlayer.md +264 -0
- package/docs/vi/packages/next-intlayer/useLocale.md +166 -0
- package/docs/vi/packages/react-intlayer/t.md +304 -0
- package/docs/vi/packages/react-intlayer/useDictionary.md +288 -0
- package/docs/vi/packages/react-intlayer/useI18n.md +295 -0
- package/docs/vi/packages/react-intlayer/useIntlayer.md +256 -0
- package/docs/vi/packages/react-intlayer/useLocale.md +210 -0
- package/docs/vi/per_locale_file.md +326 -0
- package/docs/vi/readme.md +261 -0
- package/docs/vi/releases/v6.md +305 -0
- package/docs/vi/roadmap.md +346 -0
- package/docs/vi/testing.md +202 -0
- package/docs/vi/vs_code_extension.md +126 -0
- package/docs/zh/configuration.md +6 -0
- package/docs/zh/intlayer_cli.md +8 -3
- package/docs/zh/intlayer_with_next-i18next.md +628 -0
- package/docs/zh/intlayer_with_next-intl.md +448 -0
- package/docs/zh/intlayer_with_nextjs_16.md +21 -0
- package/docs/zh/intlayer_with_tanstack.md +4 -0
- package/docs/zh/intlayer_with_vite+react.md +4 -0
- package/frequent_questions/ar/SSR_Next_no_[locale].md +1 -2
- package/frequent_questions/ar/array_as_content_declaration.md +1 -2
- package/frequent_questions/ar/build_dictionaries.md +1 -2
- package/frequent_questions/ar/build_error_CI_CD.md +1 -2
- package/frequent_questions/ar/bun_set_up.md +1 -2
- package/frequent_questions/ar/customized_locale_list.md +1 -2
- package/frequent_questions/ar/domain_routing.md +1 -2
- package/frequent_questions/ar/esbuild_error.md +1 -2
- package/frequent_questions/ar/get_locale_cookie.md +1 -2
- package/frequent_questions/ar/intlayer_command_undefined.md +1 -2
- package/frequent_questions/ar/locale_incorect_in_url.md +1 -2
- package/frequent_questions/ar/static_rendering.md +1 -3
- package/frequent_questions/ar/translated_path_url.md +1 -2
- package/frequent_questions/ar/unknown_command.md +1 -2
- package/frequent_questions/de/SSR_Next_no_[locale].md +1 -2
- package/frequent_questions/de/array_as_content_declaration.md +1 -2
- package/frequent_questions/de/build_dictionaries.md +1 -2
- package/frequent_questions/de/build_error_CI_CD.md +1 -2
- package/frequent_questions/de/bun_set_up.md +1 -2
- package/frequent_questions/de/customized_locale_list.md +1 -2
- package/frequent_questions/de/domain_routing.md +1 -2
- package/frequent_questions/de/esbuild_error.md +1 -2
- package/frequent_questions/de/get_locale_cookie.md +1 -2
- package/frequent_questions/de/intlayer_command_undefined.md +1 -2
- package/frequent_questions/de/locale_incorect_in_url.md +1 -2
- package/frequent_questions/de/static_rendering.md +1 -3
- package/frequent_questions/de/translated_path_url.md +1 -2
- package/frequent_questions/de/unknown_command.md +1 -2
- package/frequent_questions/en/SSR_Next_no_[locale].md +1 -2
- package/frequent_questions/en/array_as_content_declaration.md +1 -2
- package/frequent_questions/en/build_dictionaries.md +1 -2
- package/frequent_questions/en/build_error_CI_CD.md +1 -2
- package/frequent_questions/en/bun_set_up.md +1 -2
- package/frequent_questions/en/customized_locale_list.md +1 -2
- package/frequent_questions/en/domain_routing.md +1 -2
- package/frequent_questions/en/esbuild_error.md +1 -2
- package/frequent_questions/en/get_locale_cookie.md +1 -2
- package/frequent_questions/en/intlayer_command_undefined.md +1 -2
- package/frequent_questions/en/locale_incorect_in_url.md +1 -2
- package/frequent_questions/en/static_rendering.md +1 -3
- package/frequent_questions/en/translated_path_url.md +1 -2
- package/frequent_questions/en/unknown_command.md +1 -2
- package/frequent_questions/en-GB/SSR_Next_no_[locale].md +1 -2
- package/frequent_questions/en-GB/array_as_content_declaration.md +1 -2
- package/frequent_questions/en-GB/build_dictionaries.md +1 -2
- package/frequent_questions/en-GB/build_error_CI_CD.md +1 -2
- package/frequent_questions/en-GB/bun_set_up.md +1 -2
- package/frequent_questions/en-GB/customized_locale_list.md +1 -2
- package/frequent_questions/en-GB/domain_routing.md +1 -2
- package/frequent_questions/en-GB/esbuild_error.md +1 -2
- package/frequent_questions/en-GB/get_locale_cookie.md +1 -2
- package/frequent_questions/en-GB/intlayer_command_undefined.md +1 -2
- package/frequent_questions/en-GB/locale_incorect_in_url.md +1 -2
- package/frequent_questions/en-GB/static_rendering.md +1 -3
- package/frequent_questions/en-GB/translated_path_url.md +1 -2
- package/frequent_questions/en-GB/unknown_command.md +1 -2
- package/frequent_questions/es/SSR_Next_no_[locale].md +1 -2
- package/frequent_questions/es/array_as_content_declaration.md +1 -2
- package/frequent_questions/es/build_dictionaries.md +1 -2
- package/frequent_questions/es/build_error_CI_CD.md +1 -2
- package/frequent_questions/es/bun_set_up.md +1 -2
- package/frequent_questions/es/customized_locale_list.md +1 -2
- package/frequent_questions/es/domain_routing.md +1 -2
- package/frequent_questions/es/esbuild_error.md +1 -2
- package/frequent_questions/es/get_locale_cookie.md +1 -2
- package/frequent_questions/es/intlayer_command_undefined.md +1 -2
- package/frequent_questions/es/locale_incorect_in_url.md +1 -2
- package/frequent_questions/es/static_rendering.md +1 -3
- package/frequent_questions/es/translated_path_url.md +1 -2
- package/frequent_questions/es/unknown_command.md +1 -2
- package/frequent_questions/fr/SSR_Next_no_[locale].md +1 -2
- package/frequent_questions/fr/array_as_content_declaration.md +1 -2
- package/frequent_questions/fr/build_dictionaries.md +1 -2
- package/frequent_questions/fr/build_error_CI_CD.md +1 -2
- package/frequent_questions/fr/bun_set_up.md +1 -2
- package/frequent_questions/fr/customized_locale_list.md +1 -2
- package/frequent_questions/fr/domain_routing.md +1 -2
- package/frequent_questions/fr/esbuild_error.md +1 -2
- package/frequent_questions/fr/get_locale_cookie.md +1 -2
- package/frequent_questions/fr/intlayer_command_undefined.md +1 -2
- package/frequent_questions/fr/locale_incorect_in_url.md +1 -2
- package/frequent_questions/fr/static_rendering.md +1 -3
- package/frequent_questions/fr/translated_path_url.md +1 -2
- package/frequent_questions/fr/unknown_command.md +1 -2
- package/frequent_questions/hi/SSR_Next_no_[locale].md +1 -2
- package/frequent_questions/hi/array_as_content_declaration.md +1 -2
- package/frequent_questions/hi/build_dictionaries.md +1 -2
- package/frequent_questions/hi/build_error_CI_CD.md +1 -2
- package/frequent_questions/hi/bun_set_up.md +1 -2
- package/frequent_questions/hi/customized_locale_list.md +1 -2
- package/frequent_questions/hi/domain_routing.md +1 -2
- package/frequent_questions/hi/esbuild_error.md +1 -2
- package/frequent_questions/hi/get_locale_cookie.md +1 -2
- package/frequent_questions/hi/intlayer_command_undefined.md +1 -2
- package/frequent_questions/hi/locale_incorect_in_url.md +1 -2
- package/frequent_questions/hi/static_rendering.md +1 -3
- package/frequent_questions/hi/translated_path_url.md +1 -2
- package/frequent_questions/hi/unknown_command.md +1 -2
- package/frequent_questions/id/SSR_Next_no_[locale].md +104 -0
- package/frequent_questions/id/array_as_content_declaration.md +71 -0
- package/frequent_questions/id/build_dictionaries.md +58 -0
- package/frequent_questions/id/build_error_CI_CD.md +74 -0
- package/frequent_questions/id/bun_set_up.md +53 -0
- package/frequent_questions/id/customized_locale_list.md +64 -0
- package/frequent_questions/id/domain_routing.md +113 -0
- package/frequent_questions/id/esbuild_error.md +29 -0
- package/frequent_questions/id/get_locale_cookie.md +142 -0
- package/frequent_questions/id/intlayer_command_undefined.md +155 -0
- package/frequent_questions/id/locale_incorect_in_url.md +73 -0
- package/frequent_questions/id/static_rendering.md +44 -0
- package/frequent_questions/id/translated_path_url.md +55 -0
- package/frequent_questions/id/unknown_command.md +97 -0
- package/frequent_questions/it/SSR_Next_no_[locale].md +1 -2
- package/frequent_questions/it/array_as_content_declaration.md +1 -2
- package/frequent_questions/it/build_dictionaries.md +1 -2
- package/frequent_questions/it/build_error_CI_CD.md +1 -2
- package/frequent_questions/it/bun_set_up.md +1 -2
- package/frequent_questions/it/customized_locale_list.md +1 -2
- package/frequent_questions/it/domain_routing.md +1 -2
- package/frequent_questions/it/esbuild_error.md +1 -2
- package/frequent_questions/it/get_locale_cookie.md +1 -2
- package/frequent_questions/it/intlayer_command_undefined.md +1 -2
- package/frequent_questions/it/locale_incorect_in_url.md +1 -2
- package/frequent_questions/it/static_rendering.md +1 -3
- package/frequent_questions/it/translated_path_url.md +1 -2
- package/frequent_questions/it/unknown_command.md +1 -2
- package/frequent_questions/ja/SSR_Next_no_[locale].md +1 -2
- package/frequent_questions/ja/array_as_content_declaration.md +1 -2
- package/frequent_questions/ja/build_dictionaries.md +1 -2
- package/frequent_questions/ja/build_error_CI_CD.md +1 -2
- package/frequent_questions/ja/bun_set_up.md +1 -2
- package/frequent_questions/ja/customized_locale_list.md +1 -2
- package/frequent_questions/ja/domain_routing.md +1 -2
- package/frequent_questions/ja/esbuild_error.md +1 -2
- package/frequent_questions/ja/get_locale_cookie.md +1 -2
- package/frequent_questions/ja/intlayer_command_undefined.md +1 -2
- package/frequent_questions/ja/locale_incorect_in_url.md +1 -2
- package/frequent_questions/ja/static_rendering.md +1 -3
- package/frequent_questions/ja/translated_path_url.md +1 -2
- package/frequent_questions/ja/unknown_command.md +1 -2
- package/frequent_questions/ko/SSR_Next_no_[locale].md +1 -2
- package/frequent_questions/ko/array_as_content_declaration.md +1 -2
- package/frequent_questions/ko/build_dictionaries.md +1 -2
- package/frequent_questions/ko/build_error_CI_CD.md +1 -2
- package/frequent_questions/ko/bun_set_up.md +1 -2
- package/frequent_questions/ko/customized_locale_list.md +1 -2
- package/frequent_questions/ko/domain_routing.md +1 -2
- package/frequent_questions/ko/esbuild_error.md +1 -2
- package/frequent_questions/ko/get_locale_cookie.md +1 -2
- package/frequent_questions/ko/intlayer_command_undefined.md +1 -2
- package/frequent_questions/ko/locale_incorect_in_url.md +1 -2
- package/frequent_questions/ko/static_rendering.md +1 -3
- package/frequent_questions/ko/translated_path_url.md +1 -2
- package/frequent_questions/ko/unknown_command.md +1 -2
- package/frequent_questions/pl/SSR_Next_no_[locale].md +104 -0
- package/frequent_questions/pl/array_as_content_declaration.md +71 -0
- package/frequent_questions/pl/build_dictionaries.md +58 -0
- package/frequent_questions/pl/build_error_CI_CD.md +74 -0
- package/frequent_questions/pl/bun_set_up.md +54 -0
- package/frequent_questions/pl/customized_locale_list.md +64 -0
- package/frequent_questions/pl/domain_routing.md +113 -0
- package/frequent_questions/pl/esbuild_error.md +29 -0
- package/frequent_questions/pl/get_locale_cookie.md +142 -0
- package/frequent_questions/pl/intlayer_command_undefined.md +155 -0
- package/frequent_questions/pl/locale_incorect_in_url.md +73 -0
- package/frequent_questions/pl/static_rendering.md +44 -0
- package/frequent_questions/pl/translated_path_url.md +55 -0
- package/frequent_questions/pl/unknown_command.md +97 -0
- package/frequent_questions/pt/SSR_Next_no_[locale].md +1 -2
- package/frequent_questions/pt/array_as_content_declaration.md +1 -2
- package/frequent_questions/pt/build_dictionaries.md +1 -2
- package/frequent_questions/pt/build_error_CI_CD.md +1 -2
- package/frequent_questions/pt/bun_set_up.md +1 -2
- package/frequent_questions/pt/customized_locale_list.md +1 -2
- package/frequent_questions/pt/domain_routing.md +1 -2
- package/frequent_questions/pt/esbuild_error.md +1 -2
- package/frequent_questions/pt/get_locale_cookie.md +1 -2
- package/frequent_questions/pt/intlayer_command_undefined.md +1 -2
- package/frequent_questions/pt/locale_incorect_in_url.md +1 -2
- package/frequent_questions/pt/static_rendering.md +1 -3
- package/frequent_questions/pt/translated_path_url.md +1 -2
- package/frequent_questions/pt/unknown_command.md +1 -2
- package/frequent_questions/ru/SSR_Next_no_[locale].md +1 -2
- package/frequent_questions/ru/array_as_content_declaration.md +1 -2
- package/frequent_questions/ru/build_dictionaries.md +1 -2
- package/frequent_questions/ru/build_error_CI_CD.md +1 -2
- package/frequent_questions/ru/bun_set_up.md +1 -2
- package/frequent_questions/ru/customized_locale_list.md +1 -2
- package/frequent_questions/ru/domain_routing.md +1 -2
- package/frequent_questions/ru/esbuild_error.md +1 -2
- package/frequent_questions/ru/get_locale_cookie.md +1 -2
- package/frequent_questions/ru/intlayer_command_undefined.md +1 -2
- package/frequent_questions/ru/locale_incorect_in_url.md +1 -2
- package/frequent_questions/ru/static_rendering.md +1 -2
- package/frequent_questions/ru/translated_path_url.md +1 -2
- package/frequent_questions/ru/unknown_command.md +1 -2
- package/frequent_questions/tr/SSR_Next_no_[locale].md +1 -2
- package/frequent_questions/tr/array_as_content_declaration.md +1 -2
- package/frequent_questions/tr/build_dictionaries.md +1 -2
- package/frequent_questions/tr/build_error_CI_CD.md +1 -2
- package/frequent_questions/tr/bun_set_up.md +1 -2
- package/frequent_questions/tr/customized_locale_list.md +1 -2
- package/frequent_questions/tr/domain_routing.md +1 -2
- package/frequent_questions/tr/esbuild_error.md +1 -2
- package/frequent_questions/tr/get_locale_cookie.md +1 -2
- package/frequent_questions/tr/intlayer_command_undefined.md +1 -2
- package/frequent_questions/tr/locale_incorect_in_url.md +1 -2
- package/frequent_questions/tr/static_rendering.md +1 -2
- package/frequent_questions/tr/translated_path_url.md +1 -2
- package/frequent_questions/tr/unknown_command.md +1 -2
- package/frequent_questions/vi/SSR_Next_no_[locale].md +106 -0
- package/frequent_questions/vi/array_as_content_declaration.md +71 -0
- package/frequent_questions/vi/build_dictionaries.md +58 -0
- package/frequent_questions/vi/build_error_CI_CD.md +74 -0
- package/frequent_questions/vi/bun_set_up.md +53 -0
- package/frequent_questions/vi/customized_locale_list.md +64 -0
- package/frequent_questions/vi/domain_routing.md +113 -0
- package/frequent_questions/vi/esbuild_error.md +29 -0
- package/frequent_questions/vi/get_locale_cookie.md +142 -0
- package/frequent_questions/vi/intlayer_command_undefined.md +155 -0
- package/frequent_questions/vi/locale_incorect_in_url.md +73 -0
- package/frequent_questions/vi/static_rendering.md +44 -0
- package/frequent_questions/vi/translated_path_url.md +55 -0
- package/frequent_questions/vi/unknown_command.md +97 -0
- package/frequent_questions/zh/SSR_Next_no_[locale].md +1 -2
- package/frequent_questions/zh/array_as_content_declaration.md +1 -2
- package/frequent_questions/zh/build_dictionaries.md +1 -2
- package/frequent_questions/zh/build_error_CI_CD.md +1 -2
- package/frequent_questions/zh/bun_set_up.md +1 -2
- package/frequent_questions/zh/customized_locale_list.md +1 -2
- package/frequent_questions/zh/domain_routing.md +1 -2
- package/frequent_questions/zh/esbuild_error.md +1 -2
- package/frequent_questions/zh/get_locale_cookie.md +1 -2
- package/frequent_questions/zh/intlayer_command_undefined.md +1 -2
- package/frequent_questions/zh/locale_incorect_in_url.md +1 -2
- package/frequent_questions/zh/static_rendering.md +1 -3
- package/frequent_questions/zh/translated_path_url.md +1 -2
- package/frequent_questions/zh/unknown_command.md +1 -2
- package/legal/id/privacy_notice.md +83 -0
- package/legal/id/terms_of_service.md +55 -0
- package/legal/pl/privacy_notice.md +83 -0
- package/legal/pl/terms_of_service.md +55 -0
- package/legal/vi/privacy_notice.md +83 -0
- package/legal/vi/terms_of_service.md +55 -0
- package/package.json +19 -18
- package/src/generated/blog.entry.ts +38 -0
|
@@ -0,0 +1,1105 @@
|
|
|
1
|
+
---
|
|
2
|
+
createdAt: 2025-11-01
|
|
3
|
+
updatedAt: 2025-11-01
|
|
4
|
+
title: 如何使用 next-i18next 国际化您的 Next.js 应用
|
|
5
|
+
description: 使用 next-i18next 设置国际化:多语言 Next.js 应用的最佳实践和 SEO 技巧,涵盖国际化、内容组织和技术设置。
|
|
6
|
+
slugs:
|
|
7
|
+
- blog
|
|
8
|
+
- nextjs-internationalization-using-next-i18next
|
|
9
|
+
applicationTemplate: https://github.com/aymericzip/next-i18next-template
|
|
10
|
+
history:
|
|
11
|
+
- version: 7.0.6
|
|
12
|
+
date: 2025-11-01
|
|
13
|
+
changes: 初始版本
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
# 2025 年如何使用 next-i18next 国际化您的 Next.js 应用
|
|
17
|
+
|
|
18
|
+
## 目录
|
|
19
|
+
|
|
20
|
+
<TOC/>
|
|
21
|
+
|
|
22
|
+
## 什么是 next-i18next?
|
|
23
|
+
|
|
24
|
+
**next-i18next** 是一个流行的 Next.js 应用国际化(i18n)解决方案。虽然最初的 `next-i18next` 包是为 Pages Router 设计的,但本指南将向您展示如何使用 `i18next` 和 `react-i18next` 直接在现代 **App Router** 中实现 i18next。
|
|
25
|
+
|
|
26
|
+
通过这种方法,您可以:
|
|
27
|
+
|
|
28
|
+
- **使用命名空间组织翻译**(例如,`common.json`、`about.json`),以更好地管理内容。
|
|
29
|
+
- **高效加载翻译**,仅加载每个页面所需的命名空间,减少包大小。
|
|
30
|
+
- **支持服务器和客户端组件**,实现正确的 SSR 和 hydration 处理。
|
|
31
|
+
- **确保 TypeScript 支持**,提供类型安全的语言配置和翻译键。
|
|
32
|
+
- **通过适当的元数据、站点地图和 robots.txt 国际化优化 SEO。**
|
|
33
|
+
|
|
34
|
+
> 作为替代方案,您也可以参考 [next-intl 指南](https://github.com/aymericzip/intlayer/blob/main/docs/blog/en/i18n_using_next-intl.md),或直接使用 [Intlayer](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/intlayer_with_nextjs_16.md)。
|
|
35
|
+
|
|
36
|
+
> 查看 [next-i18next vs next-intl vs Intlayer](https://github.com/aymericzip/intlayer/blob/main/docs/blog/en/next-i18next_vs_next-intl_vs_intlayer.md) 中的比较。
|
|
37
|
+
|
|
38
|
+
## 您应该遵循的实践
|
|
39
|
+
|
|
40
|
+
在我们深入实现之前,以下是您应该遵循的一些实践:
|
|
41
|
+
|
|
42
|
+
- **设置 HTML 的 `lang` 和 `dir` 属性**
|
|
43
|
+
- **在布局中,使用 `getLocaleDirection(locale)` 计算 `dir`,并设置 `<html lang={locale} dir={dir}>`,以确保正确的无障碍访问和 SEO。**
|
|
44
|
+
- **按命名空间拆分消息**
|
|
45
|
+
按照语言和命名空间(例如 `common.json`、`about.json`)组织 JSON 文件,只加载所需内容。
|
|
46
|
+
- **最小化客户端负载**
|
|
47
|
+
在页面中,只向 `NextIntlClientProvider` 发送所需的命名空间(例如,`pick(messages, ['common', 'about'])`)。
|
|
48
|
+
- **优先使用静态页面**
|
|
49
|
+
尽可能使用静态页面,以获得更好的性能和 SEO。
|
|
50
|
+
- **服务器组件中的国际化**
|
|
51
|
+
服务器组件,如页面或所有未标记为 `client` 的组件,都是静态的,可以在构建时预渲染。因此,我们需要将翻译函数作为 props 传递给它们。
|
|
52
|
+
- **设置 TypeScript 类型**
|
|
53
|
+
确保您的 locales 在整个应用程序中实现类型安全。
|
|
54
|
+
- **重定向代理**
|
|
55
|
+
使用代理来处理语言环境检测和路由,并将用户重定向到适当的带有语言前缀的 URL。
|
|
56
|
+
- **元数据、站点地图、robots.txt 的国际化**
|
|
57
|
+
使用 Next.js 提供的 `generateMetadata` 函数对元数据、站点地图和 robots.txt 进行国际化,以确保搜索引擎在所有语言环境中更好地发现您的内容。
|
|
58
|
+
- **本地化链接**
|
|
59
|
+
使用 `Link` 组件本地化链接,将用户重定向到适当的带有语言前缀的 URL。这对于确保您的页面在所有语言环境中的发现非常重要。
|
|
60
|
+
- **自动化测试和翻译**
|
|
61
|
+
自动化测试和翻译有助于节省维护多语言应用程序的时间。
|
|
62
|
+
|
|
63
|
+
> 查看我们的文档,了解有关国际化和SEO的所有内容:[使用 next-intl 进行国际化 (i18n)](https://github.com/aymericzip/intlayer/blob/main/docs/blog/zh/internationalization_and_SEO.md)。
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
## 在 Next.js 应用中设置 i18next 的逐步指南
|
|
68
|
+
|
|
69
|
+
<iframe
|
|
70
|
+
src="https://stackblitz.com/github/aymericzip/next-i18next-template?embed=1&ctl=1&file=src/app/i18n.ts"
|
|
71
|
+
className="m-auto overflow-hidden rounded-lg border-0 max-md:size-full max-md:h-[700px] md:aspect-16/9 md:w-full"
|
|
72
|
+
title="演示 CodeSandbox - 如何使用 Intlayer 国际化您的应用"
|
|
73
|
+
sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"
|
|
74
|
+
loading="lazy"
|
|
75
|
+
|
|
76
|
+
> 查看 GitHub 上的[应用模板](https://github.com/aymericzip/next-i18next-template)。
|
|
77
|
+
|
|
78
|
+
以下是我们将要创建的项目结构:
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
.
|
|
82
|
+
├── i18n.config.ts
|
|
83
|
+
└── src # Src 是可选的
|
|
84
|
+
├── locales
|
|
85
|
+
│ ├── en
|
|
86
|
+
│ │ ├── common.json
|
|
87
|
+
│ │ └── about.json
|
|
88
|
+
│ └── fr
|
|
89
|
+
│ ├── common.json
|
|
90
|
+
│ └── about.json
|
|
91
|
+
├── types
|
|
92
|
+
│ └── i18next.d.ts
|
|
93
|
+
├── app
|
|
94
|
+
│ ├── proxy.ts
|
|
95
|
+
│ ├── i18n
|
|
96
|
+
│ │ └── server.ts
|
|
97
|
+
│ └── [locale]
|
|
98
|
+
│ ├── layout.tsx
|
|
99
|
+
│ ├── (home) # / (路由组,避免所有页面都被 home 消息污染)
|
|
100
|
+
│ │ ├── layout.tsx
|
|
101
|
+
│ │ └── page.tsx
|
|
102
|
+
│ └── about # /about
|
|
103
|
+
│ ├── layout.tsx
|
|
104
|
+
│ └── page.tsx
|
|
105
|
+
└── components
|
|
106
|
+
├── I18nProvider.tsx
|
|
107
|
+
├── ClientComponent.tsx
|
|
108
|
+
└── ServerComponent.tsx
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### 第一步:安装依赖
|
|
112
|
+
|
|
113
|
+
使用 npm 安装必要的包:
|
|
114
|
+
|
|
115
|
+
```bash packageManager="npm"
|
|
116
|
+
npm install i18next react-i18next i18next-resources-to-backend
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
```bash packageManager="pnpm"
|
|
120
|
+
pnpm add i18next react-i18next i18next-resources-to-backend
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
```bash packageManager="yarn"
|
|
124
|
+
yarn add i18next react-i18next i18next-resources-to-backend
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
- **i18next**:核心国际化框架,负责翻译文件的加载和管理。
|
|
128
|
+
- **react-i18next**:i18next 的 React 绑定,提供如 `useTranslation` 的钩子,适用于客户端组件。
|
|
129
|
+
- **i18next-resources-to-backend**:一个插件,支持动态加载翻译文件,只加载你需要的命名空间。
|
|
130
|
+
|
|
131
|
+
### 第2步:配置您的项目
|
|
132
|
+
|
|
133
|
+
创建一个配置文件来定义您支持的语言环境、默认语言环境以及用于 URL 本地化的辅助函数。该文件作为您的 i18n 设置的唯一可信来源,并确保整个应用程序中的类型安全。
|
|
134
|
+
|
|
135
|
+
集中管理语言环境配置可以防止不一致情况,并使未来添加或移除语言环境更加容易。辅助函数确保生成的 URL 在 SEO 和路由方面保持一致。
|
|
136
|
+
|
|
137
|
+
```ts fileName="i18n.config.ts"
|
|
138
|
+
// 将支持的语言环境定义为 const 数组以确保类型安全
|
|
139
|
+
// 'as const' 断言使 TypeScript 推断为字面量类型,而不是 string[]
|
|
140
|
+
export const locales = ["en", "fr"] as const;
|
|
141
|
+
|
|
142
|
+
// 从 locales 数组中提取 Locale 类型
|
|
143
|
+
// 这会创建一个联合类型: "en" | "fr"
|
|
144
|
+
export type Locale = (typeof locales)[number];
|
|
145
|
+
|
|
146
|
+
// 设置默认语言环境,当未指定语言环境时使用
|
|
147
|
+
export const defaultLocale: Locale = "en";
|
|
148
|
+
|
|
149
|
+
// 需要特殊文本方向处理的从右到左语言
|
|
150
|
+
export const rtlLocales = ["ar", "he", "fa", "ur"] as const;
|
|
151
|
+
|
|
152
|
+
// 检查某语言环境是否需要从右到左(RTL)文本方向
|
|
153
|
+
// 用于阿拉伯语、希伯来语、波斯语和乌尔都语等语言
|
|
154
|
+
export const isRtl = (locale: string) =>
|
|
155
|
+
(rtlLocales as readonly string[]).includes(locale);
|
|
156
|
+
|
|
157
|
+
// 为给定语言环境和路径生成本地化路径
|
|
158
|
+
// 默认语言环境路径没有前缀(例如 "/about" 而非 "/en/about")
|
|
159
|
+
// 其他语言环境路径带有前缀(例如 "/fr/about")
|
|
160
|
+
export function localizedPath(locale: string, path: string) {
|
|
161
|
+
return locale === defaultLocale ? path : `/${locale}${path}`;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// 绝对 URL 的基础地址(用于站点地图、元数据等)
|
|
165
|
+
const ORIGIN = "https://example.com";
|
|
166
|
+
|
|
167
|
+
// 生成带有语言前缀的绝对 URL
|
|
168
|
+
// 用于 SEO 元数据、站点地图和规范 URL
|
|
169
|
+
export function absoluteUrl(locale: string, path: string) {
|
|
170
|
+
return `${ORIGIN}${localizedPath(locale, path)}`;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// 用于在浏览器中设置语言环境的 cookie
|
|
174
|
+
export function getCookie(locale: Locale) {
|
|
175
|
+
return [
|
|
176
|
+
`NEXT_LOCALE=${locale}`,
|
|
177
|
+
"Path=/",
|
|
178
|
+
`Max-Age=${60 * 60 * 24 * 365}`, // 1 年
|
|
179
|
+
"SameSite=Lax",
|
|
180
|
+
].join("; ");
|
|
181
|
+
}
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### 第3步:集中管理翻译命名空间
|
|
185
|
+
|
|
186
|
+
为您的应用程序公开的每个命名空间创建一个单一的可信来源。重用此列表可以保持服务器、客户端和工具代码的同步,并为翻译辅助工具解锁强类型支持。
|
|
187
|
+
|
|
188
|
+
```ts fileName="src/i18n.namespaces.ts"
|
|
189
|
+
export const namespaces = ["common", "about"] as const;
|
|
190
|
+
|
|
191
|
+
export type Namespace = (typeof namespaces)[number];
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
### 第4步:使用 TypeScript 强类型化翻译键
|
|
195
|
+
|
|
196
|
+
扩展 `i18next` 指向您的规范语言文件(通常是英文)。TypeScript 会推断每个命名空间的有效键,因此对 `t()` 的调用会进行端到端的检查。
|
|
197
|
+
|
|
198
|
+
```ts fileName="src/types/i18next.d.ts"
|
|
199
|
+
import "i18next";
|
|
200
|
+
|
|
201
|
+
declare module "i18next" {
|
|
202
|
+
interface CustomTypeOptions {
|
|
203
|
+
defaultNS: "common";
|
|
204
|
+
resources: {
|
|
205
|
+
common: typeof import("@/locales/en/common.json");
|
|
206
|
+
about: typeof import("@/locales/en/about.json");
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
> 提示:将此声明存放在 `src/types` 目录下(如果不存在,请创建该文件夹)。Next.js 已经在 `tsconfig.json` 中包含了 `src`,因此该增强会被自动识别。如果没有,请在你的 `tsconfig.json` 文件中添加以下内容:
|
|
213
|
+
|
|
214
|
+
```json5 fileName="tsconfig.json"
|
|
215
|
+
{
|
|
216
|
+
"include": ["src/types/**/*.ts"],
|
|
217
|
+
}
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
有了这些配置,你就可以依赖自动补全和编译时检查:
|
|
221
|
+
|
|
222
|
+
```tsx
|
|
223
|
+
import { useTranslation, type TFunction } from "react-i18next";
|
|
224
|
+
|
|
225
|
+
const { t } = useTranslation("about");
|
|
226
|
+
|
|
227
|
+
// 正确,已类型化:t("counter.increment")
|
|
228
|
+
// 错误,编译时报错:t("doesNotExist")
|
|
229
|
+
export type AboutTranslator = TFunction<"about">;
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
### 第五步:设置服务器端 i18n 初始化
|
|
233
|
+
|
|
234
|
+
创建一个服务器端初始化函数,用于加载服务器组件的翻译。该函数为服务器端渲染创建一个独立的 i18next 实例,确保在渲染之前加载翻译内容。
|
|
235
|
+
|
|
236
|
+
服务器组件需要自己的 i18next 实例,因为它们运行在与客户端组件不同的上下文中。在服务器端预加载翻译可以防止未翻译内容的闪烁,并通过确保搜索引擎看到翻译内容来提升 SEO。
|
|
237
|
+
|
|
238
|
+
```ts fileName="src/app/i18n/server.ts"
|
|
239
|
+
import { createInstance } from "i18next";
|
|
240
|
+
import { initReactI18next } from "react-i18next/initReactI18next";
|
|
241
|
+
import resourcesToBackend from "i18next-resources-to-backend";
|
|
242
|
+
import { defaultLocale } from "@/i18n.config";
|
|
243
|
+
import { namespaces, type Namespace } from "@/i18n.namespaces";
|
|
244
|
+
|
|
245
|
+
// 配置 i18next 的动态资源加载
|
|
246
|
+
// 此函数根据 locale 和 namespace 动态导入翻译的 JSON 文件
|
|
247
|
+
// 例如:locale="fr",namespace="about" -> 导入 "@/locales/fr/about.json"
|
|
248
|
+
const backend = resourcesToBackend(
|
|
249
|
+
(locale: string, namespace: string) =>
|
|
250
|
+
import(`@/locales/${locale}/${namespace}.json`)
|
|
251
|
+
);
|
|
252
|
+
|
|
253
|
+
const DEFAULT_NAMESPACES = [
|
|
254
|
+
namespaces[0],
|
|
255
|
+
] as const satisfies readonly Namespace[];
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* 初始化用于服务器端渲染的 i18next 实例
|
|
259
|
+
*
|
|
260
|
+
* @returns 已初始化的 i18next 实例,准备好用于服务器端
|
|
261
|
+
*/
|
|
262
|
+
export async function initI18next(
|
|
263
|
+
locale: string,
|
|
264
|
+
ns: readonly Namespace[] = DEFAULT_NAMESPACES
|
|
265
|
+
) {
|
|
266
|
+
// 创建一个新的 i18next 实例(与客户端实例分开)
|
|
267
|
+
const i18n = createInstance();
|
|
268
|
+
|
|
269
|
+
// 使用 React 集成和后端加载器进行初始化
|
|
270
|
+
await i18n
|
|
271
|
+
.use(initReactI18next) // 启用 React hooks 支持
|
|
272
|
+
.use(backend) // 启用动态资源加载
|
|
273
|
+
.init({
|
|
274
|
+
lng: locale,
|
|
275
|
+
fallbackLng: defaultLocale,
|
|
276
|
+
ns, // 仅加载指定的命名空间以提高性能
|
|
277
|
+
defaultNS: "common", // 未指定时的默认命名空间
|
|
278
|
+
interpolation: { escapeValue: false }, // 不转义 HTML(React 处理 XSS 保护)
|
|
279
|
+
react: { useSuspense: false }, // 禁用 Suspense 以兼容 SSR
|
|
280
|
+
returnNull: false, // 缺失键时返回空字符串而非 null
|
|
281
|
+
initImmediate: false, // 延迟初始化直到资源加载完成(加快SSR速度)
|
|
282
|
+
});
|
|
283
|
+
return i18n;
|
|
284
|
+
}
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
### 第6步:创建客户端i18n提供者
|
|
288
|
+
|
|
289
|
+
创建一个客户端组件提供者,将你的应用包裹在i18next上下文中。该提供者接收从服务器预加载的翻译,防止未翻译内容闪烁(FOUC)并避免重复请求。
|
|
290
|
+
|
|
291
|
+
客户端组件需要自己的i18next实例,在浏览器中运行。通过接受服务器预加载的资源,我们确保无缝的hydration并防止内容闪烁。该提供者还动态管理语言切换和命名空间加载。
|
|
292
|
+
|
|
293
|
+
```tsx fileName="src/components/I18nProvider.tsx"
|
|
294
|
+
"use client";
|
|
295
|
+
|
|
296
|
+
import { useEffect, useState } from "react";
|
|
297
|
+
import { I18nextProvider } from "react-i18next";
|
|
298
|
+
import { createInstance, type ResourceLanguage } from "i18next";
|
|
299
|
+
import { initReactI18next } from "react-i18next/initReactI18next";
|
|
300
|
+
import resourcesToBackend from "i18next-resources-to-backend";
|
|
301
|
+
import { defaultLocale } from "@/i18n.config";
|
|
302
|
+
import { namespaces as allNamespaces, type Namespace } from "@/i18n.namespaces";
|
|
303
|
+
|
|
304
|
+
// 配置客户端的动态资源加载
|
|
305
|
+
// 与服务器端相同的模式,但此实例在浏览器中运行
|
|
306
|
+
const backend = resourcesToBackend(
|
|
307
|
+
(locale: string, namespace: string) =>
|
|
308
|
+
import(`@/locales/${locale}/${namespace}.json`)
|
|
309
|
+
);
|
|
310
|
+
|
|
311
|
+
type Props = {
|
|
312
|
+
locale: string;
|
|
313
|
+
namespaces?: readonly Namespace[];
|
|
314
|
+
// 从服务器预加载的资源(防止 FOUC - 未翻译内容闪烁)
|
|
315
|
+
// 格式: { namespace: translationBundle }
|
|
316
|
+
resources?: Record<Namespace, ResourceLanguage>;
|
|
317
|
+
children: React.ReactNode;
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* 客户端 i18n 提供者,使用 i18next 上下文包裹应用
|
|
322
|
+
* 接收服务器预加载的资源,避免重新请求翻译
|
|
323
|
+
*/
|
|
324
|
+
export default function I18nProvider({
|
|
325
|
+
locale,
|
|
326
|
+
namespaces = [allNamespaces[0]] as const,
|
|
327
|
+
resources,
|
|
328
|
+
children,
|
|
329
|
+
}: Props) {
|
|
330
|
+
// 使用 useState 懒初始化创建 i18n 实例
|
|
331
|
+
// 确保实例只创建一次,而不是每次渲染都创建
|
|
332
|
+
const [i18n] = useState(() => {
|
|
333
|
+
const i18nInstance = createInstance();
|
|
334
|
+
|
|
335
|
+
i18nInstance
|
|
336
|
+
.use(initReactI18next)
|
|
337
|
+
.use(backend)
|
|
338
|
+
.init({
|
|
339
|
+
lng: locale,
|
|
340
|
+
fallbackLng: defaultLocale,
|
|
341
|
+
ns: namespaces,
|
|
342
|
+
// 如果提供了资源(来自服务器),则使用它们以避免客户端重新获取
|
|
343
|
+
// 这可以防止闪烁(FOUC)并提升初始加载性能
|
|
344
|
+
resources: resources ? { [locale]: resources } : undefined,
|
|
345
|
+
defaultNS: "common",
|
|
346
|
+
interpolation: { escapeValue: false },
|
|
347
|
+
react: { useSuspense: false },
|
|
348
|
+
returnNull: false, // 防止返回未定义的值
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
return i18nInstance;
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
// 当 locale 属性变化时更新语言
|
|
355
|
+
useEffect(() => {
|
|
356
|
+
i18n.changeLanguage(locale);
|
|
357
|
+
}, [locale, i18n]);
|
|
358
|
+
|
|
359
|
+
// 确保客户端加载所有必需的命名空间
|
|
360
|
+
// 使用 join("|") 作为依赖以正确比较数组
|
|
361
|
+
useEffect(() => {
|
|
362
|
+
i18n.loadNamespaces(namespaces);
|
|
363
|
+
}, [namespaces.join("|"), i18n]);
|
|
364
|
+
|
|
365
|
+
// 通过 React 上下文向所有子组件提供 i18n 实例
|
|
366
|
+
return <I18nextProvider i18n={i18n}>{children}</I18nextProvider>;
|
|
367
|
+
}
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
### 第7步:定义动态语言路由
|
|
371
|
+
|
|
372
|
+
通过在你的 app 文件夹中创建一个 `[locale]` 目录来设置语言的动态路由。这允许 Next.js 处理基于语言的路由,其中每个语言成为 URL 的一部分(例如 `/en/about`,`/fr/about`)。
|
|
373
|
+
|
|
374
|
+
使用动态路由使 Next.js 能够在构建时为所有语言生成静态页面,从而提升性能和 SEO。布局组件根据语言设置 HTML 的 `lang` 和 `dir` 属性,这对于无障碍访问和搜索引擎理解至关重要。
|
|
375
|
+
|
|
376
|
+
```tsx fileName="src/app/[locale]/layout.tsx"
|
|
377
|
+
import type { ReactNode } from "react";
|
|
378
|
+
import { locales, defaultLocale, isRtl, type Locale } from "@/i18n.config";
|
|
379
|
+
|
|
380
|
+
// 禁用动态参数 - 所有语言环境必须在构建时已知
|
|
381
|
+
// 这确保了所有语言环境路由的静态生成
|
|
382
|
+
export const dynamicParams = false;
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* 在构建时为所有语言环境生成静态参数
|
|
386
|
+
* Next.js 将为这里返回的每个语言环境预渲染页面
|
|
387
|
+
* 示例: [{ locale: "en" }, { locale: "fr" }]
|
|
388
|
+
*/
|
|
389
|
+
export function generateStaticParams() {
|
|
390
|
+
return locales.map((locale) => ({ locale }));
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* 根布局组件,处理语言环境特定的 HTML 属性
|
|
395
|
+
* 根据语言环境设置 lang 属性和文本方向 (ltr/rtl)
|
|
396
|
+
*/
|
|
397
|
+
export default function LocaleLayout({
|
|
398
|
+
children,
|
|
399
|
+
params,
|
|
400
|
+
}: {
|
|
401
|
+
children: ReactNode;
|
|
402
|
+
params: { locale: string };
|
|
403
|
+
}) {
|
|
404
|
+
// 验证来自 URL 参数的 locale
|
|
405
|
+
// 如果提供了无效的 locale,则回退到默认 locale
|
|
406
|
+
const locale: Locale = (locales as readonly string[]).includes(params.locale)
|
|
407
|
+
? (params.locale as any)
|
|
408
|
+
: defaultLocale;
|
|
409
|
+
|
|
410
|
+
// 根据 locale 确定文本方向
|
|
411
|
+
// 像阿拉伯语这样的 RTL 语言需要 dir="rtl" 以正确渲染文本
|
|
412
|
+
const dir = isRtl(locale) ? "rtl" : "ltr";
|
|
413
|
+
|
|
414
|
+
return (
|
|
415
|
+
<html lang={locale} dir={dir}>
|
|
416
|
+
<body>{children}</body>
|
|
417
|
+
</html>
|
|
418
|
+
);
|
|
419
|
+
}
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
### 第8步:创建您的翻译文件
|
|
423
|
+
|
|
424
|
+
为每个 locale 和命名空间创建 JSON 文件。此结构允许您逻辑地组织翻译,并且只加载每个页面所需的内容。
|
|
425
|
+
|
|
426
|
+
通过按命名空间(例如 `common.json`、`about.json`)组织翻译,可以实现代码拆分并减少包大小。您只需加载每个页面所需的翻译,从而提升性能。
|
|
427
|
+
|
|
428
|
+
```json fileName="src/locales/en/common.json"
|
|
429
|
+
{
|
|
430
|
+
"appTitle": "Next.js i18n App",
|
|
431
|
+
"appDescription": "Example Next.js application with internationalization using i18next"
|
|
432
|
+
}
|
|
433
|
+
```
|
|
434
|
+
|
|
435
|
+
```json fileName="src/locales/fr/common.json"
|
|
436
|
+
{
|
|
437
|
+
"appTitle": "Application Next.js i18n",
|
|
438
|
+
"appDescription": "Exemple d'application Next.js avec internationalisation utilisant i18next"
|
|
439
|
+
}
|
|
440
|
+
```
|
|
441
|
+
|
|
442
|
+
```json fileName="src/locales/en/home.json"
|
|
443
|
+
{
|
|
444
|
+
"title": "Home",
|
|
445
|
+
"description": "Home page description",
|
|
446
|
+
"welcome": "Welcome",
|
|
447
|
+
"greeting": "Hello, world!",
|
|
448
|
+
"aboutPage": "About Page",
|
|
449
|
+
"documentation": "Documentation"
|
|
450
|
+
}
|
|
451
|
+
```
|
|
452
|
+
|
|
453
|
+
通过按命名空间(例如 `common.json`、`about.json`)组织翻译,可以实现代码拆分并减少包大小。您只需加载每个页面所需的翻译,从而提升性能。
|
|
454
|
+
|
|
455
|
+
```json fileName="src/locales/en/common.json"
|
|
456
|
+
{
|
|
457
|
+
"appTitle": "Next.js i18n 应用",
|
|
458
|
+
"appDescription": "使用 i18next 进行国际化的 Next.js 示例应用"
|
|
459
|
+
}
|
|
460
|
+
```
|
|
461
|
+
|
|
462
|
+
```json fileName="src/locales/fr/common.json"
|
|
463
|
+
{
|
|
464
|
+
"appTitle": "Application Next.js i18n",
|
|
465
|
+
"appDescription": "Exemple d'application Next.js avec internationalisation utilisant i18next"
|
|
466
|
+
}
|
|
467
|
+
```
|
|
468
|
+
|
|
469
|
+
```json fileName="src/locales/en/home.json"
|
|
470
|
+
{
|
|
471
|
+
"title": "首页",
|
|
472
|
+
"description": "首页描述",
|
|
473
|
+
"welcome": "欢迎",
|
|
474
|
+
"greeting": "你好,世界!",
|
|
475
|
+
"aboutPage": "关于页面",
|
|
476
|
+
"documentation": "文档"
|
|
477
|
+
}
|
|
478
|
+
```
|
|
479
|
+
|
|
480
|
+
```json fileName="src/locales/fr/home.json"
|
|
481
|
+
{
|
|
482
|
+
"title": "Accueil",
|
|
483
|
+
"description": "Description de la page d'accueil",
|
|
484
|
+
"welcome": "Bienvenue",
|
|
485
|
+
"greeting": "Bonjour le monde!",
|
|
486
|
+
"aboutPage": "Page À propos",
|
|
487
|
+
"documentation": "Documentation"
|
|
488
|
+
}
|
|
489
|
+
```
|
|
490
|
+
|
|
491
|
+
```json fileName="src/locales/en/about.json"
|
|
492
|
+
{
|
|
493
|
+
"title": "关于",
|
|
494
|
+
"description": "关于页面描述",
|
|
495
|
+
"counter": {
|
|
496
|
+
"label": "计数器",
|
|
497
|
+
"increment": "增加",
|
|
498
|
+
"description": "点击按钮以增加计数"
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
```
|
|
502
|
+
|
|
503
|
+
```json fileName="src/locales/fr/about.json"
|
|
504
|
+
{
|
|
505
|
+
"title": "À propos",
|
|
506
|
+
"description": "Description de la page À propos",
|
|
507
|
+
"counter": {
|
|
508
|
+
"label": "Compteur",
|
|
509
|
+
"increment": "Incrémenter",
|
|
510
|
+
"description": "Cliquez sur le bouton pour augmenter le compteur"
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
```
|
|
514
|
+
|
|
515
|
+
### 第9步:在页面中使用翻译
|
|
516
|
+
|
|
517
|
+
创建一个页面组件,在服务器端初始化 i18next,并将翻译传递给服务器和客户端组件。这确保了在渲染前加载翻译,防止内容闪烁。
|
|
518
|
+
|
|
519
|
+
服务器端初始化在页面渲染前加载翻译,提升 SEO 并防止 FOUC(无样式内容闪烁)。通过将预加载的资源传递给客户端提供者,避免重复获取,确保平滑的 hydration。
|
|
520
|
+
|
|
521
|
+
```tsx fileName="src/app/[locale]/about/index.tsx"
|
|
522
|
+
import I18nProvider from "@/components/I18nProvider";
|
|
523
|
+
import { initI18next } from "@/app/i18n/server";
|
|
524
|
+
import type { Locale } from "@/i18n.config";
|
|
525
|
+
import { namespaces as allNamespaces, type Namespace } from "@/i18n.namespaces";
|
|
526
|
+
import type { ResourceLanguage } from "i18next";
|
|
527
|
+
import ClientComponent from "@/components/ClientComponent";
|
|
528
|
+
import ServerComponent from "@/components/ServerComponent";
|
|
529
|
+
|
|
530
|
+
/**
|
|
531
|
+
* 处理 i18n 初始化的服务器组件页面
|
|
532
|
+
* 在服务器端预加载翻译并传递给客户端组件
|
|
533
|
+
*/
|
|
534
|
+
export default async function AboutPage({
|
|
535
|
+
params: { locale },
|
|
536
|
+
}: {
|
|
537
|
+
params: { locale: Locale };
|
|
538
|
+
}) {
|
|
539
|
+
// 定义此页面所需的翻译命名空间
|
|
540
|
+
// 重用集中列表以确保类型安全和自动补全
|
|
541
|
+
const pageNamespaces = allNamespaces;
|
|
542
|
+
|
|
543
|
+
// 在服务器上使用所需命名空间初始化 i18next
|
|
544
|
+
// 这会在服务器端加载翻译 JSON 文件
|
|
545
|
+
const i18n = await initI18next(locale, pageNamespaces);
|
|
546
|
+
|
|
547
|
+
// 获取“about”命名空间的固定翻译函数
|
|
548
|
+
// getFixedT 锁定命名空间,因此使用 t("title") 而不是 t("about:title")
|
|
549
|
+
const tAbout = i18n.getFixedT(locale, "about");
|
|
550
|
+
|
|
551
|
+
// 从 i18n 实例中提取翻译包
|
|
552
|
+
// 这些数据传递给 I18nProvider 以在客户端初始化 i18n
|
|
553
|
+
// 防止 FOUC(未翻译内容闪烁)并避免重复请求
|
|
554
|
+
const resources = Object.fromEntries(
|
|
555
|
+
pageNamespaces.map((ns) => [ns, i18n.getResourceBundle(locale, ns)])
|
|
556
|
+
) satisfies Record<Namespace, ResourceLanguage>;
|
|
557
|
+
|
|
558
|
+
return (
|
|
559
|
+
<I18nProvider
|
|
560
|
+
locale={locale}
|
|
561
|
+
namespaces={pageNamespaces}
|
|
562
|
+
resources={resources}
|
|
563
|
+
>
|
|
564
|
+
<main>
|
|
565
|
+
<h1>{tAbout("title")}</h1>
|
|
566
|
+
|
|
567
|
+
<ClientComponent />
|
|
568
|
+
<ServerComponent t={tAbout} locale={locale} count={0} />
|
|
569
|
+
</main>
|
|
570
|
+
</I18nProvider>
|
|
571
|
+
);
|
|
572
|
+
}
|
|
573
|
+
```
|
|
574
|
+
|
|
575
|
+
### 第10步:在客户端组件中使用翻译
|
|
576
|
+
|
|
577
|
+
客户端组件可以使用 `useTranslation` 钩子来访问翻译。该钩子提供对翻译函数和 i18n 实例的访问,允许你翻译内容并访问语言环境信息。
|
|
578
|
+
|
|
579
|
+
客户端组件需要 React 钩子来访问翻译。`useTranslation` 钩子与 i18next 无缝集成,并在语言环境变化时提供响应式更新。
|
|
580
|
+
|
|
581
|
+
> 确保页面/提供者只包含你需要的命名空间(例如 `about`)。
|
|
582
|
+
> 如果你使用 React 版本低于 19,记得对像 `Intl.NumberFormat` 这样的重型格式化器进行缓存。
|
|
583
|
+
|
|
584
|
+
```tsx fileName="src/components/ClientComponent.tsx"
|
|
585
|
+
"use client";
|
|
586
|
+
|
|
587
|
+
import { useState } from "react";
|
|
588
|
+
import { useTranslation } from "react-i18next";
|
|
589
|
+
|
|
590
|
+
/**
|
|
591
|
+
* 使用 React hooks 进行翻译的客户端组件示例
|
|
592
|
+
* 可以使用 useState、useEffect 和 useTranslation 等 hooks
|
|
593
|
+
*/
|
|
594
|
+
const ClientComponent = () => {
|
|
595
|
+
// useTranslation hook 提供访问翻译函数和 i18n 实例的能力
|
|
596
|
+
// 指定命名空间以仅加载 "about" 命名空间的翻译
|
|
597
|
+
const { t, i18n } = useTranslation("about");
|
|
598
|
+
const [count, setCount] = useState(0);
|
|
599
|
+
|
|
600
|
+
// 创建支持本地化的数字格式化器
|
|
601
|
+
// i18n.language 提供当前语言环境(例如 "en", "fr")
|
|
602
|
+
// Intl.NumberFormat 根据语言环境约定格式化数字
|
|
603
|
+
const numberFormat = new Intl.NumberFormat(i18n.language);
|
|
604
|
+
|
|
605
|
+
return (
|
|
606
|
+
<div className="flex flex-col items-center gap-4">
|
|
607
|
+
{/* 使用特定于语言环境的格式格式化数字 */}
|
|
608
|
+
<p className="text-5xl font-bold text-white m-0">
|
|
609
|
+
{numberFormat.format(count)}
|
|
610
|
+
</p>
|
|
611
|
+
<button
|
|
612
|
+
type="button"
|
|
613
|
+
className="flex h-12 w-full items-center justify-center gap-2 rounded-full bg-foreground px-5 text-background transition-colors hover:bg-[#383838] dark:hover:bg-[#ccc] md:w-[158px]"
|
|
614
|
+
aria-label={t("counter.label")}
|
|
615
|
+
onClick={() => setCount((c) => c + 1)}
|
|
616
|
+
>
|
|
617
|
+
{t("counter.increment")}
|
|
618
|
+
</button>
|
|
619
|
+
</div>
|
|
620
|
+
);
|
|
621
|
+
};
|
|
622
|
+
|
|
623
|
+
export default ClientComponent;
|
|
624
|
+
```
|
|
625
|
+
|
|
626
|
+
### 第11步:在服务器组件中使用翻译
|
|
627
|
+
|
|
628
|
+
服务器组件不能使用 React hooks,因此它们通过 props 从父组件接收翻译内容。这种方式保持了服务器组件的同步性,并允许它们嵌套在客户端组件内部。
|
|
629
|
+
|
|
630
|
+
可能嵌套在客户端边界下的服务器组件需要保持同步。通过将翻译字符串和语言信息作为 props 传递,我们避免了异步操作,确保了正确的渲染。
|
|
631
|
+
|
|
632
|
+
```tsx fileName="src/components/ServerComponent.tsx"
|
|
633
|
+
import type { TFunction } from "i18next";
|
|
634
|
+
|
|
635
|
+
type ServerComponentProps = {
|
|
636
|
+
// 从父服务器组件传递的翻译函数
|
|
637
|
+
// 服务器组件不能使用 hooks,因此翻译通过 props 传递
|
|
638
|
+
t: TFunction<"about">;
|
|
639
|
+
locale: string;
|
|
640
|
+
count: number;
|
|
641
|
+
};
|
|
642
|
+
|
|
643
|
+
/**
|
|
644
|
+
* 服务器组件示例 - 通过 props 接收翻译内容
|
|
645
|
+
* 可以嵌套在客户端组件(异步服务器组件)内
|
|
646
|
+
* 不能使用 React hooks,因此所有数据必须来自 props 或异步操作
|
|
647
|
+
*/
|
|
648
|
+
const ServerComponent = ({ t, locale, count }: ServerComponentProps) => {
|
|
649
|
+
// 使用 locale 在服务器端格式化数字
|
|
650
|
+
// 这在 SSR 期间服务器上运行,提升初始页面加载速度
|
|
651
|
+
const formatted = new Intl.NumberFormat(locale).format(count);
|
|
652
|
+
|
|
653
|
+
return (
|
|
654
|
+
<div className="flex flex-col items-center gap-4">
|
|
655
|
+
<p className="text-5xl font-bold text-white m-0">{formatted}</p>
|
|
656
|
+
{/* 使用作为 prop 传入的翻译函数 */}
|
|
657
|
+
<div className="flex flex-col items-center gap-2">
|
|
658
|
+
<span className="text-xl font-semibold text-white">
|
|
659
|
+
{t("counter.label")}
|
|
660
|
+
</span>
|
|
661
|
+
<span className="text-sm opacity-80 italic">
|
|
662
|
+
{t("counter.description")}
|
|
663
|
+
</span>
|
|
664
|
+
</div>
|
|
665
|
+
</div>
|
|
666
|
+
);
|
|
667
|
+
};
|
|
668
|
+
|
|
669
|
+
export default ServerComponent;
|
|
670
|
+
```
|
|
671
|
+
|
|
672
|
+
---
|
|
673
|
+
|
|
674
|
+
### (可选)步骤12:更改内容语言
|
|
675
|
+
|
|
676
|
+
在 Next.js 中更改内容语言,推荐的方式是使用带有区域设置前缀的 URL 和 Next.js 的链接。下面的示例从路由中读取当前区域设置,从路径名中剥离它,并为每个可用的区域设置渲染一个链接。
|
|
677
|
+
|
|
678
|
+
```tsx fileName="src/components/LocaleSwitcher.tsx"
|
|
679
|
+
"use client";
|
|
680
|
+
|
|
681
|
+
import Link from "next/link";
|
|
682
|
+
import { useParams, usePathname } from "next/navigation";
|
|
683
|
+
import { useMemo } from "react";
|
|
684
|
+
import { defaultLocale, getCookie, type Locale, locales } from "@/i18n.config";
|
|
685
|
+
|
|
686
|
+
export default function LocaleSwitcher() {
|
|
687
|
+
const params = useParams();
|
|
688
|
+
const pathname = usePathname();
|
|
689
|
+
|
|
690
|
+
const activeLocale = (params?.locale as Locale | undefined) ?? defaultLocale;
|
|
691
|
+
|
|
692
|
+
const getLocaleLabel = (locale: Locale): string => {
|
|
693
|
+
try {
|
|
694
|
+
const displayNames = new Intl.DisplayNames([locale], {
|
|
695
|
+
type: "language",
|
|
696
|
+
});
|
|
697
|
+
return displayNames.of(locale) ?? locale.toUpperCase();
|
|
698
|
+
} catch {
|
|
699
|
+
return locale.toUpperCase();
|
|
700
|
+
}
|
|
701
|
+
};
|
|
702
|
+
|
|
703
|
+
const basePath = useMemo(() => {
|
|
704
|
+
if (!pathname) return "/";
|
|
705
|
+
|
|
706
|
+
const segments = pathname.split("/").filter(Boolean);
|
|
707
|
+
|
|
708
|
+
if (segments.length === 0) return "/";
|
|
709
|
+
|
|
710
|
+
const maybeLocale = segments[0] as Locale;
|
|
711
|
+
|
|
712
|
+
if ((locales as readonly string[]).includes(maybeLocale)) {
|
|
713
|
+
const rest = segments.slice(1).join("/");
|
|
714
|
+
return rest ? `/${rest}` : "/";
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
return pathname;
|
|
718
|
+
}, [pathname]);
|
|
719
|
+
|
|
720
|
+
return (
|
|
721
|
+
<nav aria-label="语言选择器">
|
|
722
|
+
{(locales as readonly Locale[]).map((locale) => {
|
|
723
|
+
const isActive = locale === activeLocale;
|
|
724
|
+
|
|
725
|
+
const href =
|
|
726
|
+
locale === defaultLocale ? basePath : `/${locale}${basePath}`;
|
|
727
|
+
|
|
728
|
+
return (
|
|
729
|
+
<Link
|
|
730
|
+
key={locale}
|
|
731
|
+
href={href}
|
|
732
|
+
aria-current={isActive ? "page" : undefined}
|
|
733
|
+
onClick={() => {
|
|
734
|
+
document.cookie = getCookie(locale);
|
|
735
|
+
}}
|
|
736
|
+
>
|
|
737
|
+
{getLocaleLabel(locale)}
|
|
738
|
+
</Link>
|
|
739
|
+
);
|
|
740
|
+
})}
|
|
741
|
+
</nav>
|
|
742
|
+
);
|
|
743
|
+
}
|
|
744
|
+
```
|
|
745
|
+
|
|
746
|
+
### (可选)步骤 13:构建本地化的 Link 组件
|
|
747
|
+
|
|
748
|
+
在整个应用中重用本地化的 URL 可以保持导航的一致性并有利于 SEO。将 `next/link` 包装在一个小的辅助函数中,该函数会为内部路由添加当前激活的 locale 前缀,同时保持外部 URL 不变。
|
|
749
|
+
|
|
750
|
+
```tsx fileName="src/components/LocalizedLink.tsx"
|
|
751
|
+
"use client";
|
|
752
|
+
|
|
753
|
+
import NextLink, { type LinkProps } from "next/link";
|
|
754
|
+
import { useParams } from "next/navigation";
|
|
755
|
+
import type { ComponentProps, PropsWithChildren } from "react";
|
|
756
|
+
import {
|
|
757
|
+
defaultLocale,
|
|
758
|
+
type Locale,
|
|
759
|
+
locales,
|
|
760
|
+
localizedPath,
|
|
761
|
+
} from "@/i18n.config";
|
|
762
|
+
|
|
763
|
+
const isExternal = (href: string) => /^https?:\/\//.test(href);
|
|
764
|
+
|
|
765
|
+
type LocalizedLinkProps = PropsWithChildren<
|
|
766
|
+
Omit<LinkProps, "href"> &
|
|
767
|
+
Omit<ComponentProps<"a">, "href"> & { href: string; locale?: Locale }
|
|
768
|
+
>;
|
|
769
|
+
|
|
770
|
+
export default function LocalizedLink({
|
|
771
|
+
href,
|
|
772
|
+
locale,
|
|
773
|
+
children,
|
|
774
|
+
...props
|
|
775
|
+
}: LocalizedLinkProps) {
|
|
776
|
+
const params = useParams();
|
|
777
|
+
const fallback = (params?.locale as Locale | undefined) ?? defaultLocale;
|
|
778
|
+
const normalizedLocale = (locales as readonly string[]).includes(fallback)
|
|
779
|
+
? ((locale ?? fallback) as Locale)
|
|
780
|
+
: defaultLocale;
|
|
781
|
+
|
|
782
|
+
const normalizedPath = href.startsWith("/") ? href : `/${href}`;
|
|
783
|
+
const localizedHref = isExternal(href)
|
|
784
|
+
? href
|
|
785
|
+
: localizedPath(normalizedLocale, normalizedPath);
|
|
786
|
+
|
|
787
|
+
return (
|
|
788
|
+
<NextLink href={localizedHref} {...props}>
|
|
789
|
+
{children}
|
|
790
|
+
</NextLink>
|
|
791
|
+
);
|
|
792
|
+
}
|
|
793
|
+
```
|
|
794
|
+
|
|
795
|
+
> 提示:由于 `LocalizedLink` 是一个即插即用的替代方案,可以通过交换导入并让组件处理特定语言环境的 URL 来逐步迁移。
|
|
796
|
+
|
|
797
|
+
### (可选)步骤 14:在服务器操作中访问当前语言环境
|
|
798
|
+
|
|
799
|
+
服务器操作通常需要当前语言环境来处理邮件、日志记录或第三方集成。将代理设置的语言环境 cookie 与 `Accept-Language` 头部结合使用,作为回退方案。
|
|
800
|
+
|
|
801
|
+
```ts fileName="src/app/actions/get-current-locale.ts"
|
|
802
|
+
"use server";
|
|
803
|
+
|
|
804
|
+
import { cookies, headers } from "next/headers";
|
|
805
|
+
import { defaultLocale, locales, type Locale } from "@/i18n.config";
|
|
806
|
+
|
|
807
|
+
const KNOWN_LOCALES = new Set(locales as readonly string[]);
|
|
808
|
+
|
|
809
|
+
const normalize = (value: string | undefined): Locale | undefined => {
|
|
810
|
+
if (!value) return undefined;
|
|
811
|
+
const base = value.toLowerCase().split("-")[0];
|
|
812
|
+
return KNOWN_LOCALES.has(base) ? (base as Locale) : undefined;
|
|
813
|
+
};
|
|
814
|
+
|
|
815
|
+
export async function getCurrentLocale(): Promise<Locale> {
|
|
816
|
+
const cookieLocale = normalize(cookies().get("NEXT_LOCALE")?.value);
|
|
817
|
+
|
|
818
|
+
if (cookieLocale) return cookieLocale;
|
|
819
|
+
|
|
820
|
+
const headerLocale = normalize(headers().get("accept-language"));
|
|
821
|
+
return headerLocale ?? defaultLocale;
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
// 使用当前语言环境的服务器操作示例
|
|
825
|
+
export async function stuffFromServer(formData: FormData) {
|
|
826
|
+
const locale = await getCurrentLocale();
|
|
827
|
+
|
|
828
|
+
// 使用语言环境进行本地化的副作用(邮件、CRM 等)
|
|
829
|
+
console.log(`服务器端操作,使用的语言环境为 ${locale}`);
|
|
830
|
+
}
|
|
831
|
+
```
|
|
832
|
+
|
|
833
|
+
> 由于该辅助工具依赖于 Next.js 的 cookies 和 headers,因此它适用于路由处理程序、服务器操作以及其他仅限服务器的上下文。
|
|
834
|
+
|
|
835
|
+
### (可选)步骤 15:国际化您的元数据
|
|
836
|
+
|
|
837
|
+
翻译内容很重要,但国际化的主要目标是让您的网站在全球范围内更具可见性。I18n 是通过适当的 SEO 提升网站可见性的强大杠杆。
|
|
838
|
+
|
|
839
|
+
正确国际化的元数据有助于搜索引擎理解您的页面支持哪些语言。这包括设置 hreflang 元标签、翻译标题和描述,以及确保为每个语言环境正确设置规范 URL。
|
|
840
|
+
|
|
841
|
+
以下是关于多语言 SEO 的一些最佳实践列表:
|
|
842
|
+
|
|
843
|
+
- 在 `<head>` 标签中设置 hreflang 元标签,帮助搜索引擎了解页面支持的语言
|
|
844
|
+
- 在 sitemap.xml 中使用 `http://www.w3.org/1999/xhtml` XML 规范列出所有页面翻译
|
|
845
|
+
- 不要忘记在 robots.txt 中排除带有前缀的页面(例如 `/dashboard`、`/fr/dashboard`、`/es/dashboard`)
|
|
846
|
+
- 使用自定义 Link 组件重定向到最本地化的页面(例如,法语中 `<a href="/fr/about">À propos</a>`)
|
|
847
|
+
|
|
848
|
+
开发者经常忘记正确地跨语言引用他们的页面。让我们来修正这个问题:
|
|
849
|
+
|
|
850
|
+
```tsx fileName="src/app/[locale]/about/layout.tsx"
|
|
851
|
+
import type { Metadata } from "next";
|
|
852
|
+
import {
|
|
853
|
+
locales,
|
|
854
|
+
defaultLocale,
|
|
855
|
+
localizedPath,
|
|
856
|
+
absoluteUrl,
|
|
857
|
+
} from "@/i18n.config";
|
|
858
|
+
|
|
859
|
+
/**
|
|
860
|
+
* 为每个语言版本的页面生成 SEO 元数据
|
|
861
|
+
* 该函数在构建时为每个语言环境运行
|
|
862
|
+
*/
|
|
863
|
+
export async function generateMetadata({
|
|
864
|
+
params,
|
|
865
|
+
}: {
|
|
866
|
+
params: { locale: string };
|
|
867
|
+
}): Promise<Metadata> {
|
|
868
|
+
const { locale } = params;
|
|
869
|
+
|
|
870
|
+
// 动态导入该语言环境的翻译文件
|
|
871
|
+
// 用于获取元数据的翻译标题和描述
|
|
872
|
+
const messages = (await import(`@/locales/${locale}/about.json`)).default;
|
|
873
|
+
|
|
874
|
+
// 为所有语言环境创建 hreflang 映射
|
|
875
|
+
// 帮助搜索引擎理解语言替代版本
|
|
876
|
+
// 格式: { "en": "/about", "fr": "/fr/about" }
|
|
877
|
+
const languages = Object.fromEntries(
|
|
878
|
+
locales.map((locale) => [locale, localizedPath(locale, "/about")])
|
|
879
|
+
);
|
|
880
|
+
|
|
881
|
+
return {
|
|
882
|
+
title: messages.title,
|
|
883
|
+
description: messages.description,
|
|
884
|
+
alternates: {
|
|
885
|
+
// 此本地版本的规范 URL
|
|
886
|
+
canonical: absoluteUrl(locale, "/about"),
|
|
887
|
+
// 用于 SEO 的语言替代(hreflang 标签)
|
|
888
|
+
// "x-default" 指定默认的本地版本
|
|
889
|
+
languages: {
|
|
890
|
+
...languages,
|
|
891
|
+
"x-default": absoluteUrl(defaultLocale, "/about"),
|
|
892
|
+
},
|
|
893
|
+
},
|
|
894
|
+
};
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
export default async function AboutPage() {
|
|
898
|
+
return <h1>关于</h1>;
|
|
899
|
+
}
|
|
900
|
+
```
|
|
901
|
+
|
|
902
|
+
### (可选)步骤16:国际化您的网站地图
|
|
903
|
+
|
|
904
|
+
生成包含所有本地版本页面的网站地图。这有助于搜索引擎发现并索引您内容的所有语言版本。
|
|
905
|
+
|
|
906
|
+
一个正确国际化的网站地图确保搜索引擎能够找到并索引您所有语言版本的页面。这提升了在国际搜索结果中的可见度。
|
|
907
|
+
|
|
908
|
+
```ts fileName="src/app/sitemap.ts"
|
|
909
|
+
import type { MetadataRoute } from "next";
|
|
910
|
+
import { defaultLocale, locales } from "@/i18n";
|
|
911
|
+
|
|
912
|
+
const origin = "https://example.com";
|
|
913
|
+
|
|
914
|
+
const formatterLocalizedPath = (locale: string, path: string) =>
|
|
915
|
+
locale === defaultLocale ? `${origin}${path}` : `${origin}/${locale}${path}`;
|
|
916
|
+
|
|
917
|
+
/**
|
|
918
|
+
* 获取所有语言环境及其本地化路径的映射
|
|
919
|
+
*
|
|
920
|
+
* 示例输出:
|
|
921
|
+
* {
|
|
922
|
+
* "en": "https://example.com",
|
|
923
|
+
* "fr": "https://example.com/fr",
|
|
924
|
+
* "es": "https://example.com/es",
|
|
925
|
+
* "x-default": "https://example.com"
|
|
926
|
+
* }
|
|
927
|
+
*/
|
|
928
|
+
const getLocalizedMap = (path: string) =>
|
|
929
|
+
Object.fromEntries([
|
|
930
|
+
...locales.map((locale) => [locale, formatterLocalizedPath(locale, path)]),
|
|
931
|
+
["x-default", formatterLocalizedPath(defaultLocale, path)],
|
|
932
|
+
]);
|
|
933
|
+
|
|
934
|
+
// 生成包含所有语言版本的站点地图,以提升SEO效果
|
|
935
|
+
// alternates字段告知搜索引擎关于语言版本的信息
|
|
936
|
+
export default function sitemap(): MetadataRoute.Sitemap {
|
|
937
|
+
return [
|
|
938
|
+
{
|
|
939
|
+
url: formatterLocalizedPath(defaultLocale, "/"),
|
|
940
|
+
lastModified: new Date(),
|
|
941
|
+
changeFrequency: "monthly",
|
|
942
|
+
priority: 1.0,
|
|
943
|
+
alternates: { languages: getLocalizedMap("/") },
|
|
944
|
+
},
|
|
945
|
+
{
|
|
946
|
+
url: formatterLocalizedPath(defaultLocale, "/about"),
|
|
947
|
+
lastModified: new Date(),
|
|
948
|
+
changeFrequency: "monthly",
|
|
949
|
+
priority: 0.7,
|
|
950
|
+
alternates: { languages: getLocalizedMap("/about") },
|
|
951
|
+
},
|
|
952
|
+
];
|
|
953
|
+
}
|
|
954
|
+
```
|
|
955
|
+
|
|
956
|
+
### (可选)步骤17:国际化您的robots.txt
|
|
957
|
+
|
|
958
|
+
创建一个 robots.txt 文件,正确处理所有受保护路由的所有语言版本。这确保搜索引擎不会索引任何语言的管理员或仪表盘页面。
|
|
959
|
+
|
|
960
|
+
为所有语言正确配置 robots.txt 可以防止搜索引擎索引任何语言的敏感页面。这对于安全和隐私至关重要。
|
|
961
|
+
|
|
962
|
+
```ts fileName="src/app/robots.ts"
|
|
963
|
+
import type { MetadataRoute } from "next";
|
|
964
|
+
import { defaultLocale, locales } from "@/i18n";
|
|
965
|
+
|
|
966
|
+
const origin = "https://example.com";
|
|
967
|
+
|
|
968
|
+
// 生成所有语言版本的路径(例如 /admin, /fr/admin, /es/admin)
|
|
969
|
+
const withAllLocales = (path: string) => [
|
|
970
|
+
path,
|
|
971
|
+
...locales
|
|
972
|
+
.filter((locale) => locale !== defaultLocale)
|
|
973
|
+
.map((locale) => `/${locale}${path}`),
|
|
974
|
+
];
|
|
975
|
+
|
|
976
|
+
const disallow = [...withAllLocales("/dashboard"), ...withAllLocales("/admin")];
|
|
977
|
+
|
|
978
|
+
export default function robots(): MetadataRoute.Robots {
|
|
979
|
+
return {
|
|
980
|
+
rules: { userAgent: "*", allow: ["/"], disallow },
|
|
981
|
+
host: origin,
|
|
982
|
+
sitemap: `${origin}/sitemap.xml`,
|
|
983
|
+
};
|
|
984
|
+
}
|
|
985
|
+
```
|
|
986
|
+
|
|
987
|
+
### (可选)步骤18:设置用于区域路由的中间件
|
|
988
|
+
|
|
989
|
+
创建一个代理,自动检测用户的首选语言环境,并将其重定向到相应的带有语言前缀的URL。这可以通过显示用户首选语言的内容来提升用户体验。
|
|
990
|
+
|
|
991
|
+
中间件确保用户访问您的网站时会自动重定向到其首选语言。它还会将用户的偏好保存在cookie中,以便未来访问时使用。
|
|
992
|
+
|
|
993
|
+
```ts fileName="src/proxy.ts"
|
|
994
|
+
import { NextResponse, type NextRequest } from "next/server";
|
|
995
|
+
import { defaultLocale, locales } from "@/i18n.config";
|
|
996
|
+
|
|
997
|
+
// 匹配带有扩展名的文件的正则表达式(例如 .js、.css、.png)
|
|
998
|
+
// 用于排除静态资源不进行语言路由处理
|
|
999
|
+
const PUBLIC_FILE = /\.[^/]+$/;
|
|
1000
|
+
|
|
1001
|
+
/**
|
|
1002
|
+
* 从 Accept-Language 头部提取语言环境
|
|
1003
|
+
* 处理类似 "fr-CA"、"en-US" 等格式
|
|
1004
|
+
* 如果浏览器语言不支持,则回退到默认语言环境
|
|
1005
|
+
*/
|
|
1006
|
+
const pickLocale = (accept: string | null) => {
|
|
1007
|
+
// 获取首选语言(例如从 "fr-CA,en-US;q=0.9" 中获取 "fr-CA")
|
|
1008
|
+
const raw = accept?.split(",")[0] ?? defaultLocale;
|
|
1009
|
+
// 提取基础语言代码(例如从 "fr-CA" 中提取 "fr")
|
|
1010
|
+
const base = raw.toLowerCase().split("-")[0];
|
|
1011
|
+
// 检查是否支持该语言环境,否则使用默认语言
|
|
1012
|
+
return (locales as readonly string[]).includes(base) ? base : defaultLocale;
|
|
1013
|
+
};
|
|
1014
|
+
|
|
1015
|
+
/**
|
|
1016
|
+
* Next.js 用于语言环境检测和路由的代理
|
|
1017
|
+
* 在每次请求页面渲染前运行
|
|
1018
|
+
* 需要时自动重定向到带语言环境前缀的 URL
|
|
1019
|
+
*/
|
|
1020
|
+
export function proxy(request: NextRequest) {
|
|
1021
|
+
const { pathname } = request.nextUrl;
|
|
1022
|
+
|
|
1023
|
+
// 跳过 Next.js 内部路径、API 路由和静态文件的代理
|
|
1024
|
+
// 这些路径不应带语言环境前缀
|
|
1025
|
+
if (
|
|
1026
|
+
pathname.startsWith("/_next") ||
|
|
1027
|
+
pathname.startsWith("/api") ||
|
|
1028
|
+
pathname.startsWith("/static") ||
|
|
1029
|
+
PUBLIC_FILE.test(pathname)
|
|
1030
|
+
) {
|
|
1031
|
+
return;
|
|
1032
|
+
}
|
|
1033
|
+
|
|
1034
|
+
// 检查 URL 是否已经带有语言环境前缀
|
|
1035
|
+
// 例如 "/fr/about" 或 "/en" 会返回 true
|
|
1036
|
+
const hasLocale = (locales as readonly string[]).some(
|
|
1037
|
+
(locale) => pathname === `/${locale}` || pathname.startsWith(`/${locale}/`)
|
|
1038
|
+
);
|
|
1039
|
+
|
|
1040
|
+
// 如果没有语言前缀,则检测语言并重定向
|
|
1041
|
+
if (!hasLocale) {
|
|
1042
|
+
// 先尝试从 cookie 获取语言(用户偏好)
|
|
1043
|
+
const cookieLocale = request.cookies.get("NEXT_LOCALE")?.value;
|
|
1044
|
+
|
|
1045
|
+
// 如果 cookie 中的语言有效,则使用它,否则从浏览器头部检测语言
|
|
1046
|
+
const locale =
|
|
1047
|
+
cookieLocale && (locales as readonly string[]).includes(cookieLocale)
|
|
1048
|
+
? cookieLocale
|
|
1049
|
+
: pickLocale(request.headers.get("accept-language"));
|
|
1050
|
+
|
|
1051
|
+
// 克隆 URL 以修改路径名
|
|
1052
|
+
const url = request.nextUrl.clone();
|
|
1053
|
+
// 添加语言前缀到路径名
|
|
1054
|
+
// 特别处理根路径以避免出现双斜杠
|
|
1055
|
+
url.pathname = `/${locale}${pathname === "/" ? "" : pathname}`;
|
|
1056
|
+
|
|
1057
|
+
// 创建重定向响应并设置语言环境 cookie
|
|
1058
|
+
const res = NextResponse.redirect(url);
|
|
1059
|
+
res.cookies.set("NEXT_LOCALE", locale, { path: "/" });
|
|
1060
|
+
return res;
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
export const config = {
|
|
1065
|
+
matcher: [
|
|
1066
|
+
// 匹配所有路径,除了:
|
|
1067
|
+
// - API 路由 (/api/*)
|
|
1068
|
+
// - Next.js 内部路径 (/_next/*)
|
|
1069
|
+
// - 静态文件 (/static/*)
|
|
1070
|
+
// - 带有扩展名的文件 (.*\\..*)
|
|
1071
|
+
"/((?!api|_next|static|.*\\..*).*)",
|
|
1072
|
+
],
|
|
1073
|
+
};
|
|
1074
|
+
```
|
|
1075
|
+
|
|
1076
|
+
### (可选)步骤 19:使用 Intlayer 自动化您的翻译
|
|
1077
|
+
|
|
1078
|
+
Intlayer 是一个**免费**且**开源**的库,旨在协助您应用中的本地化流程。虽然 i18next 负责翻译的加载和管理,Intlayer 则帮助自动化翻译工作流。
|
|
1079
|
+
|
|
1080
|
+
手动管理翻译既耗时又容易出错。Intlayer 自动化了翻译的测试、生成和管理,节省您的时间并确保整个应用程序的一致性。
|
|
1081
|
+
|
|
1082
|
+
Intlayer 允许您:
|
|
1083
|
+
|
|
1084
|
+
- **在代码库中任意位置声明您的内容**
|
|
1085
|
+
Intlayer 允许您使用 `.content.{ts|js|json}` 文件在代码库中任意位置声明内容。这将帮助更好地组织内容,确保代码库的可读性和可维护性。
|
|
1086
|
+
|
|
1087
|
+
- **测试缺失的翻译**
|
|
1088
|
+
Intlayer 提供测试功能,可以集成到您的 CI/CD 流水线或单元测试中。了解更多关于[测试您的翻译](https://github.com/aymericzip/intlayer/blob/main/docs/docs/zh/testing.md)。
|
|
1089
|
+
|
|
1090
|
+
- **自动化您的翻译**
|
|
1091
|
+
Intlayer 提供了一个 CLI 和一个 VSCode 扩展来自动化您的翻译流程。它可以集成到您的 CI/CD 管道中。了解更多关于[自动化您的翻译](https://github.com/aymericzip/intlayer/blob/main/docs/docs/zh/intlayer_cli.md)。
|
|
1092
|
+
您可以使用您**自己的 API 密钥和您选择的 AI 提供商**。它还提供上下文感知的翻译,详见[填充内容](https://github.com/aymericzip/intlayer/blob/main/docs/docs/zh/autoFill.md)。
|
|
1093
|
+
|
|
1094
|
+
- **连接外部内容**
|
|
1095
|
+
- **自动化您的翻译**,
|
|
1096
|
+
Intlayer 提供了一个 CLI 和一个 VSCode 扩展来自动化您的翻译。它可以集成到您的 CI/CD 流水线中。了解更多关于[自动化您的翻译](https://github.com/aymericzip/intlayer/blob/main/docs/docs/zh/intlayer_cli.md)。
|
|
1097
|
+
您可以使用您**自己的 API 密钥和您选择的 AI 提供商**。它还提供上下文感知的翻译,详见[填充内容](https://github.com/aymericzip/intlayer/blob/main/docs/docs/zh/autoFill.md)。
|
|
1098
|
+
|
|
1099
|
+
- **连接外部内容**
|
|
1100
|
+
Intlayer 允许您将内容连接到外部内容管理系统(CMS)。以优化的方式获取内容并将其插入到您的 JSON 资源中。了解更多关于[获取外部内容](https://github.com/aymericzip/intlayer/blob/main/docs/docs/zh/dictionary/function_fetching.md)。
|
|
1101
|
+
|
|
1102
|
+
- **可视化编辑器**
|
|
1103
|
+
Intlayer 提供免费的可视化编辑器,使用可视化编辑器编辑您的内容。了解更多关于[可视化编辑您的翻译](https://github.com/aymericzip/intlayer/blob/main/docs/docs/zh/intlayer_visual_editor.md)。
|
|
1104
|
+
|
|
1105
|
+
以及更多功能。要发现 Intlayer 提供的所有功能,请参阅[Intlayer 的优势文档](https://github.com/aymericzip/intlayer/blob/main/docs/docs/zh/interest_of_intlayer.md)。
|