@intlayer/docs 7.0.7 → 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,1407 @@
|
|
|
1
|
+
---
|
|
2
|
+
createdAt: 2024-03-07
|
|
3
|
+
updatedAt: 2024-03-07
|
|
4
|
+
title: Cách dịch ứng dụng Vite và React của bạn – Hướng dẫn i18n 2025
|
|
5
|
+
description: Tìm hiểu cách thêm quốc tế hóa (i18n) vào ứng dụng Vite và React của bạn bằng cách sử dụng Intlayer. Theo dõi hướng dẫn này để làm cho ứng dụng của bạn đa ngôn ngữ.
|
|
6
|
+
keywords:
|
|
7
|
+
- Quốc tế hóa
|
|
8
|
+
- Tài liệu
|
|
9
|
+
- Intlayer
|
|
10
|
+
- Vite
|
|
11
|
+
- React
|
|
12
|
+
- i18n
|
|
13
|
+
- JavaScript
|
|
14
|
+
slugs:
|
|
15
|
+
- doc
|
|
16
|
+
- environment
|
|
17
|
+
- vite-and-react
|
|
18
|
+
applicationTemplate: https://github.com/aymericzip/intlayer-vite-react-template
|
|
19
|
+
youtubeVideo: https://www.youtube.com/watch?v=dS9L7uJeak4
|
|
20
|
+
history:
|
|
21
|
+
- version: 5.5.10
|
|
22
|
+
date: 2025-06-29
|
|
23
|
+
changes: Lịch sử khởi tạo
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
# Dịch trang web Vite và React của bạn bằng Intlayer | Quốc tế hóa (i18n)
|
|
27
|
+
|
|
28
|
+
## Mục lục
|
|
29
|
+
|
|
30
|
+
<TOC/>
|
|
31
|
+
|
|
32
|
+
## Intlayer là gì?
|
|
33
|
+
|
|
34
|
+
**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.
|
|
35
|
+
|
|
36
|
+
Với Intlayer, bạn có thể:
|
|
37
|
+
|
|
38
|
+
- **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.
|
|
39
|
+
- **Địa phương hóa động metadata**, các route và nội dung.
|
|
40
|
+
- **Đảm bảo hỗ trợ TypeScript** với các kiểu tự động tạo, cải thiện tính năng tự động hoàn thành và phát hiện lỗi.
|
|
41
|
+
- **Tận hưởng các tính năng nâng cao**, như phát hiện và chuyển đổi locale động.
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
## Hướng dẫn từng bước để thiết lập Intlayer trong ứng dụng Vite và React
|
|
46
|
+
|
|
47
|
+
<Tab defaultTab="video">
|
|
48
|
+
<TabItem label="Video" value="video">
|
|
49
|
+
|
|
50
|
+
<iframe title="Giải pháp i18n tốt nhất cho Vite và React? 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/dS9L7uJeak4?si=VaKmrYMmXjo3xpk2"/>
|
|
51
|
+
|
|
52
|
+
</TabItem>
|
|
53
|
+
<TabItem label="Code" value="code">
|
|
54
|
+
|
|
55
|
+
<iframe
|
|
56
|
+
src="https://stackblitz.com/github/aymericzip/intlayer-vite-react-template?embed=1&ctl=1&file=intlayer.config.ts"
|
|
57
|
+
className="m-auto overflow-hidden rounded-lg border-0 max-md:size-full max-md:h-[700px] md:aspect-16/9 md:w-full"
|
|
58
|
+
title="Demo CodeSandbox - Cách quốc tế hóa ứng dụng của bạn bằng Intlayer"
|
|
59
|
+
sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"
|
|
60
|
+
loading="lazy"
|
|
61
|
+
/>
|
|
62
|
+
|
|
63
|
+
</TabItem>
|
|
64
|
+
</Tab>
|
|
65
|
+
|
|
66
|
+
Xem [Mẫu Ứng Dụng](https://github.com/aymericzip/intlayer-vite-react-template) trên GitHub.
|
|
67
|
+
|
|
68
|
+
### Bước 1: Cài đặt các phụ thuộc
|
|
69
|
+
|
|
70
|
+
Cài đặt các gói cần thiết bằng npm:
|
|
71
|
+
|
|
72
|
+
```bash packageManager="npm"
|
|
73
|
+
npm install intlayer react-intlayer
|
|
74
|
+
npm install vite-intlayer --save-dev
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
```bash packageManager="pnpm"
|
|
78
|
+
pnpm add intlayer react-intlayer
|
|
79
|
+
pnpm add vite-intlayer --save-dev
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
```bash packageManager="yarn"
|
|
83
|
+
yarn add intlayer react-intlayer
|
|
84
|
+
yarn add vite-intlayer --save-dev
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
- **intlayer**
|
|
88
|
+
|
|
89
|
+
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).
|
|
90
|
+
|
|
91
|
+
- **react-intlayer**
|
|
92
|
+
Gói tích hợp Intlayer với ứng dụng React. Nó cung cấp các context provider và hook cho việc quốc tế hóa trong React.
|
|
93
|
+
|
|
94
|
+
- **vite-intlayer**
|
|
95
|
+
Bao gồm plugin Vite để tích hợp Intlayer với [trình đóng gói Vite](https://vite.dev/guide/why.html#why-bundle-for-production), cũng như middleware để phát hiện ngôn ngữ ưu tiên của người dùng, quản lý cookie, và xử lý chuyển hướng URL.
|
|
96
|
+
|
|
97
|
+
### Bước 2: Cấu hình dự án của bạn
|
|
98
|
+
|
|
99
|
+
Tạo một file cấu hình để cấu hình các ngôn ngữ cho ứng dụng của bạn:
|
|
100
|
+
|
|
101
|
+
```typescript fileName="intlayer.config.ts" codeFormat="typescript"
|
|
102
|
+
import { Locales, type IntlayerConfig } from "intlayer";
|
|
103
|
+
|
|
104
|
+
const config: IntlayerConfig = {
|
|
105
|
+
internationalization: {
|
|
106
|
+
locales: [
|
|
107
|
+
Locales.ENGLISH,
|
|
108
|
+
Locales.FRENCH,
|
|
109
|
+
Locales.SPANISH,
|
|
110
|
+
// Các ngôn ngữ khác của bạn
|
|
111
|
+
],
|
|
112
|
+
defaultLocale: Locales.ENGLISH,
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
export default config;
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
```javascript fileName="intlayer.config.mjs" codeFormat="esm"
|
|
120
|
+
import { Locales } from "intlayer";
|
|
121
|
+
|
|
122
|
+
/** @type {import('intlayer').IntlayerConfig} */
|
|
123
|
+
const config = {
|
|
124
|
+
internationalization: {
|
|
125
|
+
locales: [
|
|
126
|
+
Locales.ENGLISH,
|
|
127
|
+
Locales.FRENCH,
|
|
128
|
+
Locales.SPANISH,
|
|
129
|
+
// Các ngôn ngữ khác của bạn
|
|
130
|
+
],
|
|
131
|
+
defaultLocale: Locales.ENGLISH,
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
export default config;
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
```javascript fileName="intlayer.config.cjs" codeFormat="commonjs"
|
|
139
|
+
const { Locales } = require("intlayer");
|
|
140
|
+
|
|
141
|
+
/** @type {import('intlayer').IntlayerConfig} */
|
|
142
|
+
const config = {
|
|
143
|
+
internationalization: {
|
|
144
|
+
locales: [
|
|
145
|
+
Locales.ENGLISH,
|
|
146
|
+
Locales.FRENCH,
|
|
147
|
+
Locales.SPANISH,
|
|
148
|
+
// Các ngôn ngữ khác của bạn
|
|
149
|
+
],
|
|
150
|
+
defaultLocale: Locales.ENGLISH,
|
|
151
|
+
},
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
module.exports = config;
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
> Thông qua tệp cấu hình này, bạn có thể thiết lập URL theo ngôn ngữ, 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).
|
|
158
|
+
|
|
159
|
+
### Bước 3: Tích hợp Intlayer vào cấu hình Vite của bạn
|
|
160
|
+
|
|
161
|
+
Thêm plugin intlayer vào cấu hình của bạn.
|
|
162
|
+
|
|
163
|
+
```typescript fileName="vite.config.ts" codeFormat="typescript"
|
|
164
|
+
import { defineConfig } from "vite";
|
|
165
|
+
import react from "@vitejs/plugin-react-swc";
|
|
166
|
+
import { intlayer } from "vite-intlayer";
|
|
167
|
+
|
|
168
|
+
// https://vitejs.dev/config/
|
|
169
|
+
export default defineConfig({
|
|
170
|
+
plugins: [react(), intlayer()],
|
|
171
|
+
});
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
```javascript fileName="vite.config.mjs" codeFormat="esm"
|
|
175
|
+
import { defineConfig } from "vite";
|
|
176
|
+
import react from "@vitejs/plugin-react-swc";
|
|
177
|
+
import { intlayer } from "vite-intlayer";
|
|
178
|
+
|
|
179
|
+
// https://vitejs.dev/config/
|
|
180
|
+
export default defineConfig({
|
|
181
|
+
plugins: [react(), intlayer()],
|
|
182
|
+
});
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
```javascript fileName="vite.config.cjs" codeFormat="commonjs"
|
|
186
|
+
const { defineConfig } = require("vite");
|
|
187
|
+
const react = require("@vitejs/plugin-react-swc");
|
|
188
|
+
const { intlayer } = require("vite-intlayer");
|
|
189
|
+
|
|
190
|
+
// https://vitejs.dev/config/
|
|
191
|
+
module.exports = defineConfig({
|
|
192
|
+
plugins: [react(), intlayer()],
|
|
193
|
+
});
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
> Plugin Vite `intlayer()` được sử dụng để tích hợp Intlayer với Vite. Nó đảm bảo việc xây dựng các file 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 ứng dụng Vite. Ngoài ra, nó còn cung cấp các bí danh để tối ưu hiệu suất.
|
|
197
|
+
|
|
198
|
+
### Bước 4: Khai báo Nội dung của Bạn
|
|
199
|
+
|
|
200
|
+
Tạo và quản lý các khai báo nội dung để lưu trữ bản dịch:
|
|
201
|
+
|
|
202
|
+
```tsx fileName="src/app.content.tsx" contentDeclarationFormat="typescript"
|
|
203
|
+
import { t, type Dictionary } from "intlayer";
|
|
204
|
+
import type { ReactNode } from "react";
|
|
205
|
+
|
|
206
|
+
const appContent = {
|
|
207
|
+
key: "app",
|
|
208
|
+
content: {
|
|
209
|
+
viteLogo: t({
|
|
210
|
+
en: "Vite logo",
|
|
211
|
+
fr: "Logo Vite",
|
|
212
|
+
es: "Logo Vite",
|
|
213
|
+
}),
|
|
214
|
+
reactLogo: t({
|
|
215
|
+
en: "React logo",
|
|
216
|
+
fr: "Logo React",
|
|
217
|
+
es: "Logo React",
|
|
218
|
+
}),
|
|
219
|
+
|
|
220
|
+
title: "Vite + React",
|
|
221
|
+
|
|
222
|
+
count: t({
|
|
223
|
+
en: "count is ",
|
|
224
|
+
fr: "le compte est ",
|
|
225
|
+
es: "el recuento es ",
|
|
226
|
+
}),
|
|
227
|
+
|
|
228
|
+
edit: t<ReactNode>({
|
|
229
|
+
en: (
|
|
230
|
+
<>
|
|
231
|
+
Chỉnh sửa <code>src/App.tsx</code> và lưu để thử HMR
|
|
232
|
+
</>
|
|
233
|
+
),
|
|
234
|
+
fr: (
|
|
235
|
+
<>
|
|
236
|
+
Éditez <code>src/App.tsx</code> et enregistrez pour tester HMR
|
|
237
|
+
</>
|
|
238
|
+
),
|
|
239
|
+
es: (
|
|
240
|
+
<>
|
|
241
|
+
Edita <code>src/App.tsx</code> y guarda para probar HMR
|
|
242
|
+
</>
|
|
243
|
+
),
|
|
244
|
+
}),
|
|
245
|
+
|
|
246
|
+
readTheDocs: t({
|
|
247
|
+
en: "Nhấn vào logo Vite và React để tìm hiểu thêm",
|
|
248
|
+
fr: "Cliquez sur les logos Vite et React pour en savoir plus",
|
|
249
|
+
es: "Haga clic en los logotipos de Vite y React para obtener más información",
|
|
250
|
+
}),
|
|
251
|
+
},
|
|
252
|
+
} satisfies Dictionary;
|
|
253
|
+
|
|
254
|
+
export default appContent;
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
```javascript fileName="src/app.content.mjs" contentDeclarationFormat="esm"
|
|
258
|
+
import { t } from "intlayer";
|
|
259
|
+
|
|
260
|
+
/** @type {import('intlayer').Dictionary} */
|
|
261
|
+
const appContent = {
|
|
262
|
+
key: "app",
|
|
263
|
+
content: {
|
|
264
|
+
viteLogo: t({
|
|
265
|
+
en: "Logo Vite",
|
|
266
|
+
fr: "Logo Vite",
|
|
267
|
+
es: "Logo Vite",
|
|
268
|
+
}),
|
|
269
|
+
reactLogo: t({
|
|
270
|
+
en: "Logo React",
|
|
271
|
+
fr: "Logo React",
|
|
272
|
+
es: "Logo React",
|
|
273
|
+
}),
|
|
274
|
+
|
|
275
|
+
title: "Vite + React",
|
|
276
|
+
|
|
277
|
+
count: t({
|
|
278
|
+
en: "số đếm là ",
|
|
279
|
+
fr: "le compte est ",
|
|
280
|
+
es: "el recuento es ",
|
|
281
|
+
}),
|
|
282
|
+
|
|
283
|
+
edit:
|
|
284
|
+
t <
|
|
285
|
+
ReactNode >
|
|
286
|
+
{
|
|
287
|
+
// Đừng quên import React nếu bạn sử dụng một React node trong nội dung của bạn
|
|
288
|
+
en: (
|
|
289
|
+
<>
|
|
290
|
+
Chỉnh sửa <code>src/App.tsx</code> và lưu để thử HMR
|
|
291
|
+
</>
|
|
292
|
+
),
|
|
293
|
+
fr: (
|
|
294
|
+
<>
|
|
295
|
+
Chỉnh sửa <code>src/App.tsx</code> và lưu để thử HMR
|
|
296
|
+
</>
|
|
297
|
+
),
|
|
298
|
+
es: (
|
|
299
|
+
<>
|
|
300
|
+
Chỉnh sửa <code>src/App.tsx</code> và lưu để thử HMR
|
|
301
|
+
</>
|
|
302
|
+
),
|
|
303
|
+
},
|
|
304
|
+
|
|
305
|
+
readTheDocs: t({
|
|
306
|
+
en: "Nhấn vào logo Vite và React để tìm hiểu thêm",
|
|
307
|
+
fr: "Cliquez sur les logos Vite et React pour en savoir plus",
|
|
308
|
+
es: "Haga clic en los logotipos de Vite y React para obtener más información",
|
|
309
|
+
}),
|
|
310
|
+
},
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
export default appContent;
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
```javascript fileName="src/app.content.cjs" contentDeclarationFormat="commonjs"
|
|
317
|
+
const { t } = require("intlayer");
|
|
318
|
+
|
|
319
|
+
/** @type {import('intlayer').Dictionary} */
|
|
320
|
+
const appContent = {
|
|
321
|
+
key: "app",
|
|
322
|
+
content: {
|
|
323
|
+
viteLogo: t({
|
|
324
|
+
en: "Vite logo",
|
|
325
|
+
fr: "Logo Vite",
|
|
326
|
+
es: "Logo Vite",
|
|
327
|
+
}),
|
|
328
|
+
reactLogo: t({
|
|
329
|
+
en: "React logo",
|
|
330
|
+
fr: "Logo React",
|
|
331
|
+
es: "Logo React",
|
|
332
|
+
}),
|
|
333
|
+
|
|
334
|
+
title: "Vite + React",
|
|
335
|
+
|
|
336
|
+
count: t({
|
|
337
|
+
en: "count is ",
|
|
338
|
+
fr: "le compte est ",
|
|
339
|
+
es: "el recuento es ",
|
|
340
|
+
}),
|
|
341
|
+
|
|
342
|
+
edit:
|
|
343
|
+
t <
|
|
344
|
+
ReactNode >
|
|
345
|
+
{
|
|
346
|
+
// Đừng quên import React nếu bạn sử dụng một React node trong nội dung của bạn
|
|
347
|
+
en: (
|
|
348
|
+
<>
|
|
349
|
+
Edit <code>src/App.tsx</code> and save to test HMR
|
|
350
|
+
</>
|
|
351
|
+
),
|
|
352
|
+
fr: (
|
|
353
|
+
<>
|
|
354
|
+
Éditez <code>src/App.tsx</code> et enregistrez pour tester HMR
|
|
355
|
+
</>
|
|
356
|
+
),
|
|
357
|
+
es: (
|
|
358
|
+
<>
|
|
359
|
+
Edita <code>src/App.tsx</code> y guarda para probar HMR
|
|
360
|
+
</>
|
|
361
|
+
),
|
|
362
|
+
},
|
|
363
|
+
|
|
364
|
+
readTheDocs: t({
|
|
365
|
+
en: "Click on the Vite and React logos to learn more",
|
|
366
|
+
fr: "Cliquez sur les logos Vite et React pour en savoir plus",
|
|
367
|
+
es: "Haga clic en los logotipos de Vite y React para obtener más información",
|
|
368
|
+
vi: "Nhấn vào logo Vite và React để tìm hiểu thêm",
|
|
369
|
+
}),
|
|
370
|
+
},
|
|
371
|
+
};
|
|
372
|
+
|
|
373
|
+
module.exports = appContent;
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
```json fileName="src/app.content.json" contentDeclarationFormat="json"
|
|
377
|
+
{
|
|
378
|
+
"$schema": "https://intlayer.org/schema.json",
|
|
379
|
+
"key": "app",
|
|
380
|
+
"content": {
|
|
381
|
+
"viteLogo": {
|
|
382
|
+
"nodeType": "translation",
|
|
383
|
+
"translation": {
|
|
384
|
+
"en": "Vite logo",
|
|
385
|
+
"fr": "Logo Vite",
|
|
386
|
+
"es": "Logo Vite",
|
|
387
|
+
"vi": "Logo Vite"
|
|
388
|
+
}
|
|
389
|
+
},
|
|
390
|
+
"reactLogo": {
|
|
391
|
+
"nodeType": "translation",
|
|
392
|
+
"translation": {
|
|
393
|
+
"en": "React logo",
|
|
394
|
+
"fr": "Logo React",
|
|
395
|
+
"es": "Logo React",
|
|
396
|
+
"vi": "Logo React"
|
|
397
|
+
}
|
|
398
|
+
},
|
|
399
|
+
"title": {
|
|
400
|
+
"nodeType": "translation",
|
|
401
|
+
"translation": {
|
|
402
|
+
"en": "Vite + React",
|
|
403
|
+
"fr": "Vite + React",
|
|
404
|
+
"es": "Vite + React",
|
|
405
|
+
"vi": "Vite + React"
|
|
406
|
+
}
|
|
407
|
+
},
|
|
408
|
+
"count": {
|
|
409
|
+
"nodeType": "translation",
|
|
410
|
+
"translation": {
|
|
411
|
+
"en": "count is ",
|
|
412
|
+
"fr": "le compte est ",
|
|
413
|
+
"es": "el recuento es ",
|
|
414
|
+
"vi": "số đếm là "
|
|
415
|
+
}
|
|
416
|
+
},
|
|
417
|
+
"edit": {
|
|
418
|
+
"nodeType": "translation",
|
|
419
|
+
"translation": {
|
|
420
|
+
"en": "Edit src/App.tsx and save to test HMR",
|
|
421
|
+
"fr": "Éditez src/App.tsx et enregistrez pour tester HMR",
|
|
422
|
+
"es": "Edita src/App.tsx y guarda para probar HMR",
|
|
423
|
+
"vi": "Chỉnh sửa src/App.tsx và lưu để kiểm tra HMR"
|
|
424
|
+
}
|
|
425
|
+
},
|
|
426
|
+
"readTheDocs": {
|
|
427
|
+
"nodeType": "translation",
|
|
428
|
+
"translation": {
|
|
429
|
+
"en": "Click on the Vite and React logos to learn more",
|
|
430
|
+
"fr": "Cliquez sur les logos Vite et React pour en savoir plus",
|
|
431
|
+
"es": "Haga clic en los logotipos de Vite y React para obtener más información",
|
|
432
|
+
"vi": "Nhấn vào logo Vite và React để tìm hiểu thêm"
|
|
433
|
+
}
|
|
434
|
+
},
|
|
435
|
+
"vi": "Nhấp vào các logo Vite và React để tìm hiểu thêm"
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
```
|
|
441
|
+
|
|
442
|
+
> 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 bao gồm trong thư mục `contentDir` (mặc định là `./src`). Và phù hợp với phần mở rộng tệp khai báo nội dung (mặc định là `.content.{json,ts,tsx,js,jsx,mjs,mjx,cjs,cjx}`).
|
|
443
|
+
|
|
444
|
+
> Để 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).
|
|
445
|
+
|
|
446
|
+
> Nếu tệp nội dung của bạn bao gồm mã TSX, bạn nên xem xét việc import `import React from "react";` trong tệp nội dung của bạn.
|
|
447
|
+
|
|
448
|
+
### Bước 5: Sử dụng Intlayer trong Mã của Bạn
|
|
449
|
+
|
|
450
|
+
Truy cập các từ điển nội dung của bạn trong toàn bộ ứng dụng:
|
|
451
|
+
|
|
452
|
+
```tsx {5,9} fileName="src/App.tsx" codeFormat="typescript"
|
|
453
|
+
import { useState, type FC } from "react";
|
|
454
|
+
import reactLogo from "./assets/react.svg";
|
|
455
|
+
import viteLogo from "/vite.svg";
|
|
456
|
+
import "./App.css";
|
|
457
|
+
import { IntlayerProvider, useIntlayer } from "react-intlayer";
|
|
458
|
+
|
|
459
|
+
const AppContent: FC = () => {
|
|
460
|
+
const [count, setCount] = useState(0);
|
|
461
|
+
const content = useIntlayer("app");
|
|
462
|
+
|
|
463
|
+
return (
|
|
464
|
+
<>
|
|
465
|
+
<div>
|
|
466
|
+
<a href="https://vitejs.dev" target="_blank">
|
|
467
|
+
<img src={viteLogo} className="logo" alt={content.viteLogo.value} />
|
|
468
|
+
</a>
|
|
469
|
+
<a href="https://react.dev" target="_blank">
|
|
470
|
+
<img
|
|
471
|
+
src={reactLogo}
|
|
472
|
+
className="logo react"
|
|
473
|
+
alt={content.reactLogo.value}
|
|
474
|
+
/>
|
|
475
|
+
</a>
|
|
476
|
+
</div>
|
|
477
|
+
<h1>{content.title}</h1>
|
|
478
|
+
<div className="card">
|
|
479
|
+
<button onClick={() => setCount((count) => count + 1)}>
|
|
480
|
+
{content.count}
|
|
481
|
+
{count}
|
|
482
|
+
</button>
|
|
483
|
+
<p>{content.edit}</p>
|
|
484
|
+
</div>
|
|
485
|
+
<p className="read-the-docs">{content.readTheDocs}</p>
|
|
486
|
+
</>
|
|
487
|
+
);
|
|
488
|
+
};
|
|
489
|
+
|
|
490
|
+
const App: FC = () => (
|
|
491
|
+
<IntlayerProvider>
|
|
492
|
+
<AppContent />
|
|
493
|
+
</IntlayerProvider>
|
|
494
|
+
);
|
|
495
|
+
|
|
496
|
+
export default App;
|
|
497
|
+
```
|
|
498
|
+
|
|
499
|
+
```tsx {5,9} fileName="src/App.msx" codeFormat="esm"
|
|
500
|
+
import { useState } from "react";
|
|
501
|
+
import reactLogo from "./assets/react.svg";
|
|
502
|
+
import viteLogo from "/vite.svg";
|
|
503
|
+
import "./App.css";
|
|
504
|
+
import { IntlayerProvider, useIntlayer } from "react-intlayer";
|
|
505
|
+
|
|
506
|
+
const AppContent = () => {
|
|
507
|
+
const [count, setCount] = useState(0);
|
|
508
|
+
const content = useIntlayer("app");
|
|
509
|
+
|
|
510
|
+
return (
|
|
511
|
+
<>
|
|
512
|
+
<div>
|
|
513
|
+
<a href="https://vitejs.dev" target="_blank">
|
|
514
|
+
<img src={viteLogo} className="logo" alt={content.viteLogo.value} />
|
|
515
|
+
</a>
|
|
516
|
+
<a href="https://react.dev" target="_blank">
|
|
517
|
+
<img
|
|
518
|
+
src={reactLogo}
|
|
519
|
+
className="logo react"
|
|
520
|
+
alt={content.reactLogo.value}
|
|
521
|
+
/>
|
|
522
|
+
</a>
|
|
523
|
+
</div>
|
|
524
|
+
<h1>{content.title}</h1>
|
|
525
|
+
<div className="card">
|
|
526
|
+
<button onClick={() => setCount((count) => count + 1)}>
|
|
527
|
+
{content.count}
|
|
528
|
+
{count}
|
|
529
|
+
</button>
|
|
530
|
+
<p>{content.edit}</p>
|
|
531
|
+
</div>
|
|
532
|
+
<p className="read-the-docs">{content.readTheDocs}</p>
|
|
533
|
+
</>
|
|
534
|
+
);
|
|
535
|
+
};
|
|
536
|
+
|
|
537
|
+
const App = () => (
|
|
538
|
+
<IntlayerProvider>
|
|
539
|
+
<AppContent />
|
|
540
|
+
</IntlayerProvider>
|
|
541
|
+
);
|
|
542
|
+
|
|
543
|
+
export default App;
|
|
544
|
+
```
|
|
545
|
+
|
|
546
|
+
```tsx {5,9} fileName="src/App.csx" codeFormat="commonjs"
|
|
547
|
+
const { useState } = require("react");
|
|
548
|
+
const reactLogo = require("./assets/react.svg");
|
|
549
|
+
const viteLogo = require("/vite.svg");
|
|
550
|
+
require("./App.css");
|
|
551
|
+
const { IntlayerProvider, useIntlayer } = require("react-intlayer");
|
|
552
|
+
|
|
553
|
+
const AppContent = () => {
|
|
554
|
+
const [count, setCount] = useState(0);
|
|
555
|
+
const content = useIntlayer("app");
|
|
556
|
+
|
|
557
|
+
return (
|
|
558
|
+
<>
|
|
559
|
+
<div>
|
|
560
|
+
<a href="https://vitejs.dev" target="_blank">
|
|
561
|
+
<img src={viteLogo} className="logo" alt={content.viteLogo.value} />
|
|
562
|
+
</a>
|
|
563
|
+
<a href="https://react.dev" target="_blank">
|
|
564
|
+
<img
|
|
565
|
+
src={reactLogo}
|
|
566
|
+
className="logo react"
|
|
567
|
+
alt={content.reactLogo.value}
|
|
568
|
+
/>
|
|
569
|
+
</a>
|
|
570
|
+
</div>
|
|
571
|
+
<h1>{content.title}</h1>
|
|
572
|
+
<div className="card">
|
|
573
|
+
<button onClick={() => setCount((count) => count + 1)}>
|
|
574
|
+
{content.count}
|
|
575
|
+
{count}
|
|
576
|
+
</button>
|
|
577
|
+
<p>{content.edit}</p>
|
|
578
|
+
</div>
|
|
579
|
+
<p className="read-the-docs">{content.readTheDocs}</p>
|
|
580
|
+
</>
|
|
581
|
+
);
|
|
582
|
+
};
|
|
583
|
+
|
|
584
|
+
const App = () => (
|
|
585
|
+
<IntlayerProvider>
|
|
586
|
+
<AppContent />
|
|
587
|
+
</IntlayerProvider>
|
|
588
|
+
);
|
|
589
|
+
|
|
590
|
+
module.exports = App;
|
|
591
|
+
```
|
|
592
|
+
|
|
593
|
+
> Nếu bạn muốn sử dụng nội dung của mình trong một thuộc tính `string`, chẳng hạn như `alt`, `title`, `href`, `aria-label`, v.v., bạn phải gọi giá trị của hàm, như sau:
|
|
594
|
+
|
|
595
|
+
> ```jsx
|
|
596
|
+
> <img src={content.image.src.value} alt={content.image.value} />
|
|
597
|
+
> ```
|
|
598
|
+
|
|
599
|
+
> Để 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/react-intlayer/useIntlayer.md).
|
|
600
|
+
|
|
601
|
+
### (Tùy chọn) Bước 6: Thay đổi ngôn ngữ cho nội dung của bạn
|
|
602
|
+
|
|
603
|
+
Để thay đổi ngôn ngữ cho nội dung của bạn, bạn có thể sử dụng hàm `setLocale` được cung cấp bởi hook `useLocale`. Hàm này cho phép bạn thiết lập locale của ứng dụng và cập nhật nội dung tương ứng.
|
|
604
|
+
|
|
605
|
+
```tsx fileName="src/components/LocaleSwitcher.tsx" codeFormat="typescript"
|
|
606
|
+
import type { FC } from "react";
|
|
607
|
+
import { Locales } from "intlayer";
|
|
608
|
+
import { useLocale } from "react-intlayer";
|
|
609
|
+
|
|
610
|
+
const LocaleSwitcher: FC = () => {
|
|
611
|
+
const { setLocale } = useLocale();
|
|
612
|
+
|
|
613
|
+
return (
|
|
614
|
+
<button onClick={() => setLocale(Locales.English)}>
|
|
615
|
+
Thay đổi ngôn ngữ sang tiếng Anh
|
|
616
|
+
</button>
|
|
617
|
+
);
|
|
618
|
+
};
|
|
619
|
+
```
|
|
620
|
+
|
|
621
|
+
```jsx fileName="src/components/LocaleSwitcher.msx" codeFormat="esm"
|
|
622
|
+
import { Locales } from "intlayer";
|
|
623
|
+
import { useLocale } from "react-intlayer";
|
|
624
|
+
|
|
625
|
+
const LocaleSwitcher = () => {
|
|
626
|
+
const { setLocale } = useLocale();
|
|
627
|
+
|
|
628
|
+
return (
|
|
629
|
+
<button onClick={() => setLocale(Locales.English)}>
|
|
630
|
+
Thay đổi ngôn ngữ sang tiếng Anh
|
|
631
|
+
</button>
|
|
632
|
+
);
|
|
633
|
+
};
|
|
634
|
+
```
|
|
635
|
+
|
|
636
|
+
```jsx fileName="src/components/LocaleSwitcher.csx" codeFormat="commonjs"
|
|
637
|
+
const { Locales } = require("intlayer");
|
|
638
|
+
const { useLocale } = require("react-intlayer");
|
|
639
|
+
|
|
640
|
+
const LocaleSwitcher = () => {
|
|
641
|
+
const { setLocale } = useLocale();
|
|
642
|
+
|
|
643
|
+
return (
|
|
644
|
+
<button onClick={() => setLocale(Locales.English)}>
|
|
645
|
+
Thay đổi ngôn ngữ sang tiếng Anh
|
|
646
|
+
</button>
|
|
647
|
+
);
|
|
648
|
+
};
|
|
649
|
+
```
|
|
650
|
+
|
|
651
|
+
> Để tìm hiểu thêm về hook `useLocale`, hãy tham khảo [tài liệu](https://github.com/aymericzip/intlayer/blob/main/docs/docs/vi/packages/react-intlayer/useLocale.md).
|
|
652
|
+
|
|
653
|
+
### (Tùy chọn) Bước 7: Thêm định tuyến theo ngôn ngữ vào ứng dụng của bạn
|
|
654
|
+
|
|
655
|
+
Mục đích của bước này là tạo các đường dẫn duy nhất cho mỗi ngôn ngữ. Điều này hữu ích cho SEO và các URL thân thiện với SEO.
|
|
656
|
+
Ví dụ:
|
|
657
|
+
|
|
658
|
+
```plaintext
|
|
659
|
+
- https://example.com/about
|
|
660
|
+
- https://example.com/es/about
|
|
661
|
+
- https://example.com/fr/about
|
|
662
|
+
```
|
|
663
|
+
|
|
664
|
+
> Theo mặc định, các tuyến đường không được thêm tiền tố cho ngôn ngữ mặc định. Nếu bạn muốn thêm tiền tố cho ngôn ngữ mặc định, bạn có thể đặt tùy chọn `middleware.prefixDefault` thành `true` trong cấu hình của bạn. Xem thêm tại [tài liệu cấu hình](https://github.com/aymericzip/intlayer/blob/main/docs/docs/vi/configuration.md) để biết thêm thông tin.
|
|
665
|
+
|
|
666
|
+
Để thêm định tuyến theo ngôn ngữ vào ứng dụng của bạn, bạn có thể tạo một thành phần `LocaleRouter` bao bọc các tuyến đường của ứng dụng và xử lý định tuyến dựa trên ngôn ngữ. Dưới đây là ví dụ sử dụng [React Router](https://reactrouter.com/home):
|
|
667
|
+
|
|
668
|
+
```tsx fileName="src/components/LocaleRouter.tsx" codeFormat="typescript"
|
|
669
|
+
import { localeMap } from "intlayer"; // Các hàm tiện ích và kiểu từ 'intlayer'
|
|
670
|
+
import type { FC, PropsWithChildren } from "react"; // Kiểu React cho các functional component và props
|
|
671
|
+
import { IntlayerProvider } from "react-intlayer"; // Provider cho ngữ cảnh quốc tế hóa
|
|
672
|
+
import { BrowserRouter, Route, Routes } from "react-router-dom"; // Các thành phần Router để quản lý điều hướng
|
|
673
|
+
|
|
674
|
+
/**
|
|
675
|
+
* Một thành phần router thiết lập các tuyến đường theo ngôn ngữ cụ thể.
|
|
676
|
+
* Nó sử dụng React Router để quản lý điều hướng và hiển thị các thành phần được địa phương hóa.
|
|
677
|
+
*/
|
|
678
|
+
export const LocaleRouter: FC<PropsWithChildren> = ({ children }) => (
|
|
679
|
+
<BrowserRouter>
|
|
680
|
+
<Routes>
|
|
681
|
+
{localeMap(({ locale, urlPrefix }) => (
|
|
682
|
+
<Route
|
|
683
|
+
// Mẫu tuyến đường để bắt ngôn ngữ (ví dụ: /en/, /fr/) và khớp với tất cả các đường dẫn tiếp theo
|
|
684
|
+
path={`${urlPrefix}/*`}
|
|
685
|
+
key={locale}
|
|
686
|
+
element={
|
|
687
|
+
<IntlayerProvider locale={locale}>{children}</IntlayerProvider>
|
|
688
|
+
} // Bao bọc các phần tử con với quản lý ngôn ngữ
|
|
689
|
+
/>
|
|
690
|
+
))}
|
|
691
|
+
</Routes>
|
|
692
|
+
</BrowserRouter>
|
|
693
|
+
);
|
|
694
|
+
```
|
|
695
|
+
|
|
696
|
+
```jsx fileName="src/components/LocaleRouter.mjx" codeFormat="esm"
|
|
697
|
+
import { localeMap } from 'intlayer'; // Các hàm tiện ích và kiểu từ 'intlayer'
|
|
698
|
+
import type { FC, PropsWithChildren } from 'react'; // Kiểu React cho các functional component và props
|
|
699
|
+
import { IntlayerProvider } from 'react-intlayer'; // Provider cho ngữ cảnh quốc tế hóa
|
|
700
|
+
import { BrowserRouter, Route, Routes } from 'react-router-dom'; // Các thành phần Router để quản lý điều hướng
|
|
701
|
+
|
|
702
|
+
/**
|
|
703
|
+
* Một thành phần router thiết lập các tuyến đường theo ngôn ngữ cụ thể.
|
|
704
|
+
* Nó sử dụng React Router để quản lý điều hướng và hiển thị các thành phần được bản địa hóa.
|
|
705
|
+
*/
|
|
706
|
+
export const LocaleRouter: FC<PropsWithChildren> = ({ children }) => (
|
|
707
|
+
<BrowserRouter>
|
|
708
|
+
<Routes>
|
|
709
|
+
{localeMap(({ locale, urlPrefix }) => (
|
|
710
|
+
<Route
|
|
711
|
+
// Mẫu tuyến đường để bắt ngôn ngữ (ví dụ: /en/, /fr/) và khớp với tất cả các đường dẫn tiếp theo
|
|
712
|
+
path={`${urlPrefix}/*`}
|
|
713
|
+
key={locale}
|
|
714
|
+
element={
|
|
715
|
+
<IntlayerProvider locale={locale}>{children}</IntlayerProvider>
|
|
716
|
+
} // Bao bọc các phần tử con với quản lý ngôn ngữ
|
|
717
|
+
/>
|
|
718
|
+
))}
|
|
719
|
+
</Routes>
|
|
720
|
+
</BrowserRouter>
|
|
721
|
+
);
|
|
722
|
+
```
|
|
723
|
+
|
|
724
|
+
```jsx fileName="src/components/LocaleRouter.cjx" codeFormat="commonjs"
|
|
725
|
+
const { localeMap } = require("intlayer"); // Các hàm tiện ích và kiểu từ 'intlayer'
|
|
726
|
+
const React = require("react"); // Nhập React
|
|
727
|
+
const { IntlayerProvider } = require("react-intlayer"); // Provider cho ngữ cảnh quốc tế hóa
|
|
728
|
+
const { BrowserRouter, Route, Routes } = require("react-router-dom"); // Các thành phần Router để quản lý điều hướng
|
|
729
|
+
|
|
730
|
+
/**
|
|
731
|
+
* Một thành phần router thiết lập các tuyến đường theo ngôn ngữ cụ thể.
|
|
732
|
+
* Nó sử dụng React Router để quản lý điều hướng và hiển thị các thành phần được bản địa hóa.
|
|
733
|
+
*/
|
|
734
|
+
const LocaleRouter = ({ children }) =>
|
|
735
|
+
React.createElement(
|
|
736
|
+
BrowserRouter,
|
|
737
|
+
{},
|
|
738
|
+
React.createElement(
|
|
739
|
+
Routes,
|
|
740
|
+
{},
|
|
741
|
+
localeMap(({ locale, urlPrefix }) =>
|
|
742
|
+
React.createElement(Route, {
|
|
743
|
+
path: `${urlPrefix}/*`,
|
|
744
|
+
key: locale,
|
|
745
|
+
element: React.createElement(IntlayerProvider, { locale }, children),
|
|
746
|
+
})
|
|
747
|
+
)
|
|
748
|
+
)
|
|
749
|
+
);
|
|
750
|
+
|
|
751
|
+
exports.LocaleRouter = LocaleRouter;
|
|
752
|
+
```
|
|
753
|
+
|
|
754
|
+
> Lưu ý: Nếu bạn sử dụng `routing.mode: 'no-prefix' | 'search-params'`, có thể bạn không cần sử dụng hàm `localeMap`.
|
|
755
|
+
|
|
756
|
+
Sau đó, bạn có thể sử dụng thành phần `LocaleRouter` trong ứng dụng của mình:
|
|
757
|
+
|
|
758
|
+
```tsx fileName="src/App.tsx" codeFormat="typescript"
|
|
759
|
+
import { LocaleRouter } from "./components/LocaleRouter";
|
|
760
|
+
import type { FC } from "react";
|
|
761
|
+
|
|
762
|
+
// ... Thành phần AppContent của bạn
|
|
763
|
+
|
|
764
|
+
const App: FC = () => (
|
|
765
|
+
<LocaleRouter>
|
|
766
|
+
<AppContent />
|
|
767
|
+
</LocaleRouter>
|
|
768
|
+
);
|
|
769
|
+
```
|
|
770
|
+
|
|
771
|
+
```jsx fileName="src/App.mjx" codeFormat="esm"
|
|
772
|
+
import { LocaleRouter } from "./components/LocaleRouter";
|
|
773
|
+
|
|
774
|
+
// ... Thành phần AppContent của bạn
|
|
775
|
+
|
|
776
|
+
const App = () => (
|
|
777
|
+
<LocaleRouter>
|
|
778
|
+
<AppContent />
|
|
779
|
+
</LocaleRouter>
|
|
780
|
+
);
|
|
781
|
+
```
|
|
782
|
+
|
|
783
|
+
```jsx fileName="src/App.cjx" codeFormat="commonjs"
|
|
784
|
+
const { LocaleRouter } = require("./components/LocaleRouter");
|
|
785
|
+
|
|
786
|
+
// ... Thành phần AppContent của bạn
|
|
787
|
+
|
|
788
|
+
const App = () => (
|
|
789
|
+
<LocaleRouter>
|
|
790
|
+
<AppContent />
|
|
791
|
+
</LocaleRouter>
|
|
792
|
+
);
|
|
793
|
+
```
|
|
794
|
+
|
|
795
|
+
Song song đó, bạn cũng có thể sử dụng `intlayerMiddleware` để thêm routing phía server cho ứng dụng của bạn. Plugin này sẽ tự động phát hiện locale hiện tại dựa trên URL và thiết lập cookie locale phù hợp. Nếu không có locale nào được chỉ định, plugin sẽ xác định locale phù hợp nhất dựa trên ngôn ngữ trình duyệt của người dùng. Nếu không phát hiện được locale nào, nó sẽ chuyển hướng đến locale mặc định.
|
|
796
|
+
|
|
797
|
+
> Lưu ý rằng để sử dụng `intlayerMiddleware` trong môi trường production, bạn cần chuyển gói `vite-intlayer` từ `devDependencies` sang `dependencies`.
|
|
798
|
+
|
|
799
|
+
```typescript {3,7} fileName="vite.config.ts" codeFormat="typescript"
|
|
800
|
+
import { defineConfig } from "vite";
|
|
801
|
+
import react from "@vitejs/plugin-react-swc";
|
|
802
|
+
import { intlayer, intlayerMiddleware } from "vite-intlayer";
|
|
803
|
+
|
|
804
|
+
// https://vitejs.dev/config/
|
|
805
|
+
export default defineConfig({
|
|
806
|
+
plugins: [react(), intlayer(), intlayerMiddleware()],
|
|
807
|
+
});
|
|
808
|
+
```
|
|
809
|
+
|
|
810
|
+
```javascript {3,7} fileName="vite.config.mjs" codeFormat="esm"
|
|
811
|
+
import { defineConfig } from "vite";
|
|
812
|
+
import react from "@vitejs/plugin-react-swc";
|
|
813
|
+
import { intlayer, intlayerMiddleware } from "vite-intlayer";
|
|
814
|
+
|
|
815
|
+
// https://vitejs.dev/config/
|
|
816
|
+
export default defineConfig({
|
|
817
|
+
plugins: [react(), intlayer(), intlayerMiddleware()],
|
|
818
|
+
});
|
|
819
|
+
```
|
|
820
|
+
|
|
821
|
+
```javascript {3,7} fileName="vite.config.cjs" codeFormat="commonjs"
|
|
822
|
+
const { defineConfig } = require("vite");
|
|
823
|
+
const react = require("@vitejs/plugin-react-swc");
|
|
824
|
+
const { intlayer, intlayerMiddleware } = require("vite-intlayer");
|
|
825
|
+
|
|
826
|
+
// https://vitejs.dev/config/
|
|
827
|
+
module.exports = defineConfig({
|
|
828
|
+
plugins: [react(), intlayer(), intlayerMiddleware()],
|
|
829
|
+
});
|
|
830
|
+
```
|
|
831
|
+
|
|
832
|
+
### (Tùy chọn) Bước 8: Thay đổi URL khi thay đổi locale
|
|
833
|
+
|
|
834
|
+
Để thay đổi URL khi locale thay đổi, bạn có thể sử dụng prop `onLocaleChange` được cung cấp bởi hook `useLocale`. Đồng thời, bạn có thể sử dụng các hook `useLocation` và `useNavigate` từ `react-router-dom` để cập nhật đường dẫn URL.
|
|
835
|
+
|
|
836
|
+
```tsx fileName="src/components/LocaleSwitcher.tsx" codeFormat="typescript"
|
|
837
|
+
import { useLocation, useNavigate } from "react-router-dom";
|
|
838
|
+
import {
|
|
839
|
+
Locales,
|
|
840
|
+
getHTMLTextDir,
|
|
841
|
+
getLocaleName,
|
|
842
|
+
getLocalizedUrl,
|
|
843
|
+
} from "intlayer";
|
|
844
|
+
import { useLocale } from "react-intlayer";
|
|
845
|
+
import { type FC } from "react";
|
|
846
|
+
|
|
847
|
+
const LocaleSwitcher: FC = () => {
|
|
848
|
+
const { pathname, search } = useLocation(); // Lấy đường dẫn URL hiện tại. Ví dụ: /fr/about?foo=bar
|
|
849
|
+
const navigate = useNavigate();
|
|
850
|
+
|
|
851
|
+
const { locale, availableLocales, setLocale } = useLocale({
|
|
852
|
+
onLocaleChange: (locale) => {
|
|
853
|
+
// Tạo URL với locale được cập nhật
|
|
854
|
+
// Ví dụ: /es/about?foo=bar
|
|
855
|
+
const pathWithLocale = getLocalizedUrl(`${pathname}${search}`, locale);
|
|
856
|
+
|
|
857
|
+
// Cập nhật đường dẫn URL
|
|
858
|
+
navigate(pathWithLocale);
|
|
859
|
+
},
|
|
860
|
+
});
|
|
861
|
+
|
|
862
|
+
return (
|
|
863
|
+
<div>
|
|
864
|
+
<button popoverTarget="localePopover">{getLocaleName(locale)}</button>
|
|
865
|
+
<div id="localePopover" popover="auto">
|
|
866
|
+
{availableLocales.map((localeItem) => (
|
|
867
|
+
<a
|
|
868
|
+
href={getLocalizedUrl(location.pathname, localeItem)}
|
|
869
|
+
hrefLang={localeItem}
|
|
870
|
+
aria-current={locale === localeItem ? "page" : undefined}
|
|
871
|
+
onClick={(e) => {
|
|
872
|
+
e.preventDefault();
|
|
873
|
+
setLocale(localeItem);
|
|
874
|
+
}}
|
|
875
|
+
key={localeItem}
|
|
876
|
+
>
|
|
877
|
+
<span>
|
|
878
|
+
{/* Ngôn ngữ - ví dụ: FR */}
|
|
879
|
+
{localeItem}
|
|
880
|
+
</span>
|
|
881
|
+
<span>
|
|
882
|
+
{/* Tên ngôn ngữ trong chính ngôn ngữ đó - ví dụ: Français */}
|
|
883
|
+
{getLocaleName(localeItem, locale)}
|
|
884
|
+
</span>
|
|
885
|
+
<span dir={getHTMLTextDir(localeItem)} lang={localeItem}>
|
|
886
|
+
{/* Tên ngôn ngữ trong ngôn ngữ hiện tại - ví dụ: Francés khi locale hiện tại là Locales.SPANISH */}
|
|
887
|
+
{getLocaleName(localeItem)}
|
|
888
|
+
</span>
|
|
889
|
+
<span dir="ltr" lang={Locales.ENGLISH}>
|
|
890
|
+
{/* Ngôn ngữ bằng tiếng Anh - ví dụ: French */}
|
|
891
|
+
{getLocaleName(localeItem, Locales.ENGLISH)}
|
|
892
|
+
</span>
|
|
893
|
+
</a>
|
|
894
|
+
))}
|
|
895
|
+
</div>
|
|
896
|
+
</div>
|
|
897
|
+
);
|
|
898
|
+
};
|
|
899
|
+
```
|
|
900
|
+
|
|
901
|
+
```jsx fileName="src/components/LocaleSwitcher.msx" codeFormat="esm"
|
|
902
|
+
import { useLocation, useNavigate } from "react-router-dom";
|
|
903
|
+
import {
|
|
904
|
+
Locales,
|
|
905
|
+
getHTMLTextDir,
|
|
906
|
+
getLocaleName,
|
|
907
|
+
getLocalizedUrl,
|
|
908
|
+
} from "intlayer";
|
|
909
|
+
import { useLocale } from "react-intlayer";
|
|
910
|
+
|
|
911
|
+
const LocaleSwitcher = () => {
|
|
912
|
+
const { pathname, search } = useLocation(); // Lấy đường dẫn URL hiện tại. Ví dụ: /fr/about?foo=bar
|
|
913
|
+
const navigate = useNavigate();
|
|
914
|
+
|
|
915
|
+
const { locale, availableLocales, setLocale } = useLocale({
|
|
916
|
+
onLocaleChange: (locale) => {
|
|
917
|
+
// Tạo URL với locale được cập nhật
|
|
918
|
+
// Ví dụ: /es/about?foo=bar
|
|
919
|
+
const pathWithLocale = getLocalizedUrl(`${pathname}${search}`, locale);
|
|
920
|
+
|
|
921
|
+
// Cập nhật đường dẫn URL
|
|
922
|
+
navigate(pathWithLocale);
|
|
923
|
+
},
|
|
924
|
+
});
|
|
925
|
+
|
|
926
|
+
return (
|
|
927
|
+
<div>
|
|
928
|
+
<button popoverTarget="localePopover">{getLocaleName(locale)}</button>
|
|
929
|
+
<div id="localePopover" popover="auto">
|
|
930
|
+
{availableLocales.map((localeItem) => (
|
|
931
|
+
<a
|
|
932
|
+
href={getLocalizedUrl(location.pathname, localeItem)}
|
|
933
|
+
hrefLang={localeItem}
|
|
934
|
+
aria-current={locale === localeItem ? "page" : undefined}
|
|
935
|
+
onClick={(e) => {
|
|
936
|
+
e.preventDefault();
|
|
937
|
+
setLocale(localeItem);
|
|
938
|
+
}}
|
|
939
|
+
key={localeItem}
|
|
940
|
+
>
|
|
941
|
+
<span>
|
|
942
|
+
{/* Mã ngôn ngữ - ví dụ: FR */}
|
|
943
|
+
{localeItem}
|
|
944
|
+
</span>
|
|
945
|
+
<span>
|
|
946
|
+
{/* Ngôn ngữ trong chính Locale của nó - ví dụ: Français */}
|
|
947
|
+
{getLocaleName(localeItem, locale)}
|
|
948
|
+
</span>
|
|
949
|
+
<span dir={getHTMLTextDir(localeItem)} lang={localeItem}>
|
|
950
|
+
{/* Ngôn ngữ trong Locale hiện tại - ví dụ: Francés với locale hiện tại đặt là Locales.SPANISH */}
|
|
951
|
+
{getLocaleName(localeItem)}
|
|
952
|
+
</span>
|
|
953
|
+
<span dir="ltr" lang={Locales.ENGLISH}>
|
|
954
|
+
{/* Ngôn ngữ bằng tiếng Anh - ví dụ: French */}
|
|
955
|
+
{getLocaleName(localeItem, Locales.ENGLISH)}
|
|
956
|
+
</span>
|
|
957
|
+
</a>
|
|
958
|
+
))}
|
|
959
|
+
</div>
|
|
960
|
+
</div>
|
|
961
|
+
);
|
|
962
|
+
};
|
|
963
|
+
const { useLocation, useNavigate } = require("react-router-dom");
|
|
964
|
+
const {
|
|
965
|
+
Locales,
|
|
966
|
+
getHTMLTextDir,
|
|
967
|
+
getLocaleName,
|
|
968
|
+
getLocalizedUrl,
|
|
969
|
+
} = require("intlayer");
|
|
970
|
+
const { useLocale } = require("react-intlayer");
|
|
971
|
+
|
|
972
|
+
const LocaleSwitcher = () => {
|
|
973
|
+
const { pathname, search } = useLocation(); // Lấy đường dẫn URL hiện tại. Ví dụ: /fr/about?foo=bar
|
|
974
|
+
const navigate = useNavigate();
|
|
975
|
+
|
|
976
|
+
const { locale, availableLocales, setLocale } = useLocale({
|
|
977
|
+
onLocaleChange: (locale) => {
|
|
978
|
+
// Xây dựng URL với locale được cập nhật
|
|
979
|
+
// Ví dụ: /es/about?foo=bar
|
|
980
|
+
const pathWithLocale = getLocalizedUrl(`${pathname}${search}`, locale);
|
|
981
|
+
|
|
982
|
+
// Cập nhật đường dẫn URL
|
|
983
|
+
navigate(pathWithLocale);
|
|
984
|
+
},
|
|
985
|
+
});
|
|
986
|
+
|
|
987
|
+
return (
|
|
988
|
+
<div>
|
|
989
|
+
<button popoverTarget="localePopover">{getLocaleName(locale)}</button>
|
|
990
|
+
<div id="localePopover" popover="auto">
|
|
991
|
+
{availableLocales.map((localeItem) => (
|
|
992
|
+
<a
|
|
993
|
+
href={getLocalizedUrl(location.pathname, localeItem)}
|
|
994
|
+
hrefLang={localeItem}
|
|
995
|
+
aria-current={locale === localeItem ? "page" : undefined}
|
|
996
|
+
onClick={(e) => {
|
|
997
|
+
e.preventDefault();
|
|
998
|
+
setLocale(localeItem);
|
|
999
|
+
}}
|
|
1000
|
+
key={localeItem}
|
|
1001
|
+
>
|
|
1002
|
+
<span>
|
|
1003
|
+
{/* Ngôn ngữ - ví dụ: FR */}
|
|
1004
|
+
{localeItem}
|
|
1005
|
+
</span>
|
|
1006
|
+
<span>
|
|
1007
|
+
{/* Ngôn ngữ trong chính ngôn ngữ đó - ví dụ: Français */}
|
|
1008
|
+
{getLocaleName(localeItem, locale)}
|
|
1009
|
+
</span>
|
|
1010
|
+
<span dir={getHTMLTextDir(localeItem)} lang={localeItem}>
|
|
1011
|
+
{/* 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 */}
|
|
1012
|
+
{getLocaleName(localeItem)}
|
|
1013
|
+
</span>
|
|
1014
|
+
<span dir="ltr" lang={Locales.ENGLISH}>
|
|
1015
|
+
{/* Ngôn ngữ bằng tiếng Anh - ví dụ French */}
|
|
1016
|
+
{getLocaleName(localeItem, Locales.ENGLISH)}
|
|
1017
|
+
</span>
|
|
1018
|
+
</a>
|
|
1019
|
+
))}
|
|
1020
|
+
</div>
|
|
1021
|
+
</div>
|
|
1022
|
+
);
|
|
1023
|
+
};
|
|
1024
|
+
```
|
|
1025
|
+
|
|
1026
|
+
> Tham khảo tài liệu:
|
|
1027
|
+
>
|
|
1028
|
+
> - [`useLocale` hook](https://github.com/aymericzip/intlayer/blob/main/docs/docs/vi/packages/react-intlayer/useLocale.md)
|
|
1029
|
+
> - [`getLocaleName` hook](https://github.com/aymericzip/intlayer/blob/main/docs/docs/vi/packages/intlayer/getLocaleName.md)
|
|
1030
|
+
> - [`getLocalizedUrl` hook](https://github.com/aymericzip/intlayer/blob/main/docs/docs/vi/packages/intlayer/getLocalizedUrl.md)
|
|
1031
|
+
> - [`getHTMLTextDir` hook](https://github.com/aymericzip/intlayer/blob/main/docs/docs/vi/packages/intlayer/getHTMLTextDir.md)
|
|
1032
|
+
> - [`hrefLang` attribute](https://developers.google.com/search/docs/specialty/international/localized-versions?hl=fr)
|
|
1033
|
+
> - [`lang` attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/lang)
|
|
1034
|
+
> - [`dir` attribute`](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/dir)
|
|
1035
|
+
> - [`aria-current` attribute`](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-current)
|
|
1036
|
+
|
|
1037
|
+
Dưới đây là **Bước 9** đã được cập nhật với các giải thích bổ sung và ví dụ mã được tinh chỉnh:
|
|
1038
|
+
|
|
1039
|
+
---
|
|
1040
|
+
|
|
1041
|
+
### (Tùy chọn) Bước 9: Chuyển đổi Thuộc tính Ngôn ngữ và Hướng của HTML
|
|
1042
|
+
|
|
1043
|
+
Khi ứng dụng của bạn hỗ trợ nhiều ngôn ngữ, việc cập nhật các thuộc tính `lang` và `dir` của thẻ `<html>` để phù hợp với locale hiện tại là rất quan trọng. Việc này đảm bảo:
|
|
1044
|
+
|
|
1045
|
+
- **Khả năng truy cập**: Các trình đọc màn hình và công nghệ hỗ trợ dựa vào thuộc tính `lang` chính xác để phát âm và hiểu nội dung một cách chính xác.
|
|
1046
|
+
- **Hiển thị văn bản**: Thuộc tính `dir` (hướng) đảm bảo văn bản được hiển thị theo đúng thứ tự (ví dụ: từ trái sang phải cho tiếng Anh, từ phải sang trái cho tiếng Ả Rập hoặc Do Thái), điều này rất cần thiết cho khả năng đọc.
|
|
1047
|
+
- **SEO**: Các công cụ tìm kiếm sử dụng thuộc tính `lang` để xác định ngôn ngữ của trang, giúp phục vụ nội dung địa phương hóa phù hợp trong kết quả tìm kiếm.
|
|
1048
|
+
|
|
1049
|
+
Bằng cách cập nhật các thuộc tính này một cách động khi locale thay đổi, bạn đảm bảo trải nghiệm nhất quán và dễ tiếp cận cho người dùng trên tất cả các ngôn ngữ được hỗ trợ.
|
|
1050
|
+
|
|
1051
|
+
#### Triển khai Hook
|
|
1052
|
+
|
|
1053
|
+
Tạo một hook tùy chỉnh để quản lý các thuộc tính HTML. Hook này lắng nghe sự thay đổi của locale và cập nhật các thuộc tính tương ứng:
|
|
1054
|
+
|
|
1055
|
+
```tsx fileName="src/hooks/useI18nHTMLAttributes.tsx" codeFormat="typescript"
|
|
1056
|
+
import { useEffect } from "react";
|
|
1057
|
+
import { useLocale } from "react-intlayer";
|
|
1058
|
+
import { getHTMLTextDir } from "intlayer";
|
|
1059
|
+
|
|
1060
|
+
/**
|
|
1061
|
+
* Cập nhật các thuộc tính `lang` và `dir` của phần tử HTML <html> dựa trên locale hiện tại.
|
|
1062
|
+
* - `lang`: Thông báo cho trình duyệt và công cụ tìm kiếm về ngôn ngữ của trang.
|
|
1063
|
+
* - `dir`: Đảm bảo thứ tự đọc đúng (ví dụ: 'ltr' cho tiếng Anh, 'rtl' cho tiếng Ả Rập).
|
|
1064
|
+
*
|
|
1065
|
+
* Việc cập nhật động này rất cần thiết cho việc hiển thị văn bản đúng cách, khả năng tiếp cận và SEO.
|
|
1066
|
+
*/
|
|
1067
|
+
export const useI18nHTMLAttributes = () => {
|
|
1068
|
+
const { locale } = useLocale();
|
|
1069
|
+
|
|
1070
|
+
useEffect(() => {
|
|
1071
|
+
// Cập nhật thuộc tính ngôn ngữ theo locale hiện tại.
|
|
1072
|
+
document.documentElement.lang = locale;
|
|
1073
|
+
|
|
1074
|
+
// Đặt hướng văn bản dựa trên locale hiện tại.
|
|
1075
|
+
document.documentElement.dir = getHTMLTextDir(locale);
|
|
1076
|
+
}, [locale]);
|
|
1077
|
+
};
|
|
1078
|
+
```
|
|
1079
|
+
|
|
1080
|
+
```jsx fileName="src/hooks/useI18nHTMLAttributes.msx" codeFormat="esm"
|
|
1081
|
+
import { useEffect } from "react";
|
|
1082
|
+
import { useLocale } from "react-intlayer";
|
|
1083
|
+
import { getHTMLTextDir } from "intlayer";
|
|
1084
|
+
|
|
1085
|
+
/**
|
|
1086
|
+
* Cập nhật các thuộc tính `lang` và `dir` của phần tử HTML <html> dựa trên locale hiện tại.
|
|
1087
|
+
* - `lang`: Thông báo cho trình duyệt và công cụ tìm kiếm về ngôn ngữ của trang.
|
|
1088
|
+
* - `dir`: Đảm bảo thứ tự đọc đúng (ví dụ: 'ltr' cho tiếng Anh, 'rtl' cho tiếng Ả Rập).
|
|
1089
|
+
*
|
|
1090
|
+
* Việc cập nhật động này rất cần thiết cho việc hiển thị văn bản đúng cách, khả năng tiếp cận và SEO.
|
|
1091
|
+
*/
|
|
1092
|
+
export const useI18nHTMLAttributes = () => {
|
|
1093
|
+
const { locale } = useLocale();
|
|
1094
|
+
|
|
1095
|
+
useEffect(() => {
|
|
1096
|
+
// Cập nhật thuộc tính ngôn ngữ thành locale hiện tại.
|
|
1097
|
+
document.documentElement.lang = locale;
|
|
1098
|
+
|
|
1099
|
+
// Đặt hướng văn bản dựa trên locale hiện tại.
|
|
1100
|
+
document.documentElement.dir = getHTMLTextDir(locale);
|
|
1101
|
+
}, [locale]);
|
|
1102
|
+
};
|
|
1103
|
+
```
|
|
1104
|
+
|
|
1105
|
+
```jsx fileName="src/hooks/useI18nHTMLAttributes.csx" codeFormat="commonjs"
|
|
1106
|
+
const { useEffect } = require("react");
|
|
1107
|
+
const { useLocale } = require("react-intlayer");
|
|
1108
|
+
const { getHTMLTextDir } = require("intlayer");
|
|
1109
|
+
|
|
1110
|
+
/**
|
|
1111
|
+
* Cập nhật các thuộc tính `lang` và `dir` của phần tử HTML <html> dựa trên locale hiện tại.
|
|
1112
|
+
* - `lang`: Thông báo cho trình duyệt và công cụ tìm kiếm về ngôn ngữ của trang.
|
|
1113
|
+
* - `dir`: Đảm bảo thứ tự đọc đúng (ví dụ: 'ltr' cho tiếng Anh, 'rtl' cho tiếng Ả Rập).
|
|
1114
|
+
*
|
|
1115
|
+
* Việc cập nhật động này rất cần thiết cho việc hiển thị văn bản đúng, khả năng truy cập và SEO.
|
|
1116
|
+
*/
|
|
1117
|
+
const useI18nHTMLAttributes = () => {
|
|
1118
|
+
const { locale } = useLocale();
|
|
1119
|
+
|
|
1120
|
+
useEffect(() => {
|
|
1121
|
+
// Cập nhật thuộc tính ngôn ngữ theo locale hiện tại.
|
|
1122
|
+
document.documentElement.lang = locale;
|
|
1123
|
+
|
|
1124
|
+
// Đặt hướng văn bản dựa trên locale hiện tại.
|
|
1125
|
+
document.documentElement.dir = getHTMLTextDir(locale);
|
|
1126
|
+
}, [locale]);
|
|
1127
|
+
};
|
|
1128
|
+
|
|
1129
|
+
module.exports = { useI18nHTMLAttributes };
|
|
1130
|
+
```
|
|
1131
|
+
|
|
1132
|
+
#### Sử dụng Hook trong Ứng dụng của Bạn
|
|
1133
|
+
|
|
1134
|
+
Tích hợp hook vào thành phần chính của bạn để các thuộc tính HTML được cập nhật mỗi khi locale thay đổi:
|
|
1135
|
+
|
|
1136
|
+
```tsx fileName="src/App.tsx" codeFormat="typescript"
|
|
1137
|
+
import type { FC } from "react";
|
|
1138
|
+
import { IntlayerProvider, useIntlayer } from "react-intlayer";
|
|
1139
|
+
import { useI18nHTMLAttributes } from "./hooks/useI18nHTMLAttributes";
|
|
1140
|
+
import "./App.css";
|
|
1141
|
+
|
|
1142
|
+
const AppContent: FC = () => {
|
|
1143
|
+
// Áp dụng hook để cập nhật các thuộc tính lang và dir của thẻ <html> dựa trên locale.
|
|
1144
|
+
useI18nHTMLAttributes();
|
|
1145
|
+
|
|
1146
|
+
// ... Phần còn lại của component
|
|
1147
|
+
};
|
|
1148
|
+
|
|
1149
|
+
const App: FC = () => (
|
|
1150
|
+
<IntlayerProvider>
|
|
1151
|
+
<AppContent />
|
|
1152
|
+
</IntlayerProvider>
|
|
1153
|
+
);
|
|
1154
|
+
|
|
1155
|
+
export default App;
|
|
1156
|
+
```
|
|
1157
|
+
|
|
1158
|
+
```jsx fileName="src/App.msx" codeFormat="esm"
|
|
1159
|
+
import { IntlayerProvider, useIntlayer } from "react-intlayer";
|
|
1160
|
+
import { useI18nHTMLAttributes } from "./hooks/useI18nHTMLAttributes";
|
|
1161
|
+
import "./App.css";
|
|
1162
|
+
|
|
1163
|
+
const AppContent = () => {
|
|
1164
|
+
// Áp dụng hook để cập nhật các thuộc tính lang và dir của thẻ <html> dựa trên locale.
|
|
1165
|
+
useI18nHTMLAttributes();
|
|
1166
|
+
|
|
1167
|
+
// ... Phần còn lại của component
|
|
1168
|
+
};
|
|
1169
|
+
|
|
1170
|
+
const App = () => (
|
|
1171
|
+
<IntlayerProvider>
|
|
1172
|
+
<AppContent />
|
|
1173
|
+
</IntlayerProvider>
|
|
1174
|
+
);
|
|
1175
|
+
|
|
1176
|
+
export default App;
|
|
1177
|
+
```
|
|
1178
|
+
|
|
1179
|
+
```jsx fileName="src/App.csx" codeFormat="commonjs"
|
|
1180
|
+
const { FC } = require("react");
|
|
1181
|
+
const { IntlayerProvider, useIntlayer } = require("react-intlayer");
|
|
1182
|
+
const { useI18nHTMLAttributes } = require("./hooks/useI18nHTMLAttributes");
|
|
1183
|
+
require("./App.css");
|
|
1184
|
+
|
|
1185
|
+
const AppContent = () => {
|
|
1186
|
+
// Áp dụng hook để cập nhật các thuộc tính lang và dir của thẻ <html> dựa trên locale.
|
|
1187
|
+
useI18nHTMLAttributes();
|
|
1188
|
+
|
|
1189
|
+
// ... Phần còn lại của component của bạn
|
|
1190
|
+
};
|
|
1191
|
+
|
|
1192
|
+
const App = () => (
|
|
1193
|
+
<IntlayerProvider>
|
|
1194
|
+
<AppContent />
|
|
1195
|
+
</IntlayerProvider>
|
|
1196
|
+
);
|
|
1197
|
+
|
|
1198
|
+
module.exports = App;
|
|
1199
|
+
```
|
|
1200
|
+
|
|
1201
|
+
Bằng cách áp dụng những thay đổi này, ứng dụng của bạn sẽ:
|
|
1202
|
+
|
|
1203
|
+
- Đảm bảo thuộc tính **ngôn ngữ** (`lang`) phản ánh chính xác locale hiện tại, điều này quan trọng cho SEO và hành vi của trình duyệt.
|
|
1204
|
+
- Điều chỉnh **hướng văn bản** (`dir`) theo locale, nâng cao khả năng đọc và trải nghiệm người dùng cho các ngôn ngữ có thứ tự đọc khác nhau.
|
|
1205
|
+
- Cung cấp trải nghiệm **truy cập tốt hơn**, vì các công nghệ hỗ trợ phụ thuộc vào các thuộc tính này để hoạt động tối ưu.
|
|
1206
|
+
|
|
1207
|
+
### (Tùy chọn) Bước 10: Tạo Component Link Đa Ngôn Ngữ
|
|
1208
|
+
|
|
1209
|
+
Để đảm bảo rằng điều hướng của ứng dụng của bạn tuân thủ locale 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 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`.
|
|
1210
|
+
|
|
1211
|
+
Hành vi này hữu ích vì một số lý do sau:
|
|
1212
|
+
|
|
1213
|
+
- **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 phù hợp với ngôn ngữ ưu tiên của người dùng.
|
|
1214
|
+
- **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 điều hướng luôn ở trong locale hiện tại, tránh việc chuyển đổi ngôn ngữ không mong muốn.
|
|
1215
|
+
- **Dễ bảo trì**: Tập trung logic đa ngôn ngữ vào 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.
|
|
1216
|
+
|
|
1217
|
+
Dưới đây là triển khai của component `Link` đa ngôn ngữ bằng TypeScript:
|
|
1218
|
+
|
|
1219
|
+
```tsx fileName="src/components/Link.tsx" codeFormat="typescript"
|
|
1220
|
+
import { getLocalizedUrl } from "intlayer";
|
|
1221
|
+
import {
|
|
1222
|
+
forwardRef,
|
|
1223
|
+
type DetailedHTMLProps,
|
|
1224
|
+
type AnchorHTMLAttributes,
|
|
1225
|
+
} from "react";
|
|
1226
|
+
import { useLocale } from "react-intlayer";
|
|
1227
|
+
|
|
1228
|
+
export interface LinkProps
|
|
1229
|
+
extends DetailedHTMLProps<
|
|
1230
|
+
AnchorHTMLAttributes<HTMLAnchorElement>,
|
|
1231
|
+
HTMLAnchorElement
|
|
1232
|
+
> {}
|
|
1233
|
+
|
|
1234
|
+
/**
|
|
1235
|
+
* Hàm tiện ích để kiểm tra xem một URL có phải là liên kết ngoài không.
|
|
1236
|
+
* Nếu URL bắt đầu bằng http:// hoặc https://, nó được coi là liên kết ngoài.
|
|
1237
|
+
*/
|
|
1238
|
+
export const checkIsExternalLink = (href?: string): boolean =>
|
|
1239
|
+
/^https?:\/\//.test(href ?? "");
|
|
1240
|
+
|
|
1241
|
+
/**
|
|
1242
|
+
* 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.
|
|
1243
|
+
* Đố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).
|
|
1244
|
+
* Điều này đảm bảo việc điều hướng luôn giữ trong cùng một ngữ cảnh locale.
|
|
1245
|
+
*/
|
|
1246
|
+
export const Link = forwardRef<HTMLAnchorElement, LinkProps>(
|
|
1247
|
+
({ href, children, ...props }, ref) => {
|
|
1248
|
+
const { locale } = useLocale();
|
|
1249
|
+
const isExternalLink = checkIsExternalLink(href);
|
|
1250
|
+
|
|
1251
|
+
// 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.
|
|
1252
|
+
const hrefI18n =
|
|
1253
|
+
href && !isExternalLink ? getLocalizedUrl(href, locale) : href;
|
|
1254
|
+
|
|
1255
|
+
return (
|
|
1256
|
+
<a href={hrefI18n} ref={ref} {...props}>
|
|
1257
|
+
{children}
|
|
1258
|
+
</a>
|
|
1259
|
+
);
|
|
1260
|
+
}
|
|
1261
|
+
);
|
|
1262
|
+
|
|
1263
|
+
Link.displayName = "Link";
|
|
1264
|
+
```
|
|
1265
|
+
|
|
1266
|
+
```jsx fileName="src/components/Link.mjx" codeFormat="esm"
|
|
1267
|
+
import { getLocalizedUrl } from "intlayer";
|
|
1268
|
+
import { useLocale } from "react-intlayer";
|
|
1269
|
+
import { forwardRef } from "react";
|
|
1270
|
+
|
|
1271
|
+
/**
|
|
1272
|
+
* Hàm tiện ích để kiểm tra xem một URL có phải là liên kết ngoài không.
|
|
1273
|
+
* Nếu URL bắt đầu bằng http:// hoặc https://, nó được coi là liên kết ngoài.
|
|
1274
|
+
*/
|
|
1275
|
+
export const checkIsExternalLink = (href?: string): boolean =>
|
|
1276
|
+
/^https?:\/\//.test(href ?? "");
|
|
1277
|
+
|
|
1278
|
+
/**
|
|
1279
|
+
* 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.
|
|
1280
|
+
* Đố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).
|
|
1281
|
+
* Điều này đảm bảo rằng việc điều hướng vẫn giữ trong cùng một ngữ cảnh locale.
|
|
1282
|
+
*/
|
|
1283
|
+
export const Link = forwardRef(({ href, children, ...props }, ref) => {
|
|
1284
|
+
const { locale } = useLocale();
|
|
1285
|
+
const isExternalLink = checkIsExternalLink(href);
|
|
1286
|
+
|
|
1287
|
+
// 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.
|
|
1288
|
+
const hrefI18n =
|
|
1289
|
+
href && !isExternalLink ? getLocalizedUrl(href, locale) : href;
|
|
1290
|
+
|
|
1291
|
+
return (
|
|
1292
|
+
<a href={hrefI18n} ref={ref} {...props}>
|
|
1293
|
+
{children}
|
|
1294
|
+
</a>
|
|
1295
|
+
);
|
|
1296
|
+
});
|
|
1297
|
+
|
|
1298
|
+
Link.displayName = "Link";
|
|
1299
|
+
```
|
|
1300
|
+
|
|
1301
|
+
```jsx fileName="src/components/Link.csx" codeFormat="commonjs"
|
|
1302
|
+
const { getLocalizedUrl } = require("intlayer");
|
|
1303
|
+
const { useLocale } = require("react-intlayer");
|
|
1304
|
+
const { forwardRef } = require("react");
|
|
1305
|
+
|
|
1306
|
+
/**
|
|
1307
|
+
* 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.
|
|
1308
|
+
* Nếu URL bắt đầu bằng http:// hoặc https://, nó được coi là liên kết ngoài.
|
|
1309
|
+
*/
|
|
1310
|
+
const checkIsExternalLink = (href) => /^https?:\/\//.test(href ?? "");
|
|
1311
|
+
|
|
1312
|
+
/**
|
|
1313
|
+
* 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.
|
|
1314
|
+
* Đố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).
|
|
1315
|
+
* Điều này đảm bảo rằng việc điều hướng vẫn giữ trong cùng một ngữ cảnh locale.
|
|
1316
|
+
*/
|
|
1317
|
+
const Link = forwardRef(({ href, children, ...props }, ref) => {
|
|
1318
|
+
const { locale } = useLocale();
|
|
1319
|
+
const isExternalLink = checkIsExternalLink(href);
|
|
1320
|
+
|
|
1321
|
+
// Nếu liên kết là nội bộ và có href hợp lệ, lấy URL đã được địa phương hóa.
|
|
1322
|
+
const localizedHref = isExternalLink ? href : getLocalizedUrl(href, locale);
|
|
1323
|
+
|
|
1324
|
+
return (
|
|
1325
|
+
<a
|
|
1326
|
+
href={localizedHref}
|
|
1327
|
+
ref={ref}
|
|
1328
|
+
{...props}
|
|
1329
|
+
aria-current={isExternalLink ? "external" : undefined}
|
|
1330
|
+
>
|
|
1331
|
+
{children}
|
|
1332
|
+
</a>
|
|
1333
|
+
);
|
|
1334
|
+
});
|
|
1335
|
+
|
|
1336
|
+
Link.displayName = "Link";
|
|
1337
|
+
```
|
|
1338
|
+
|
|
1339
|
+
#### Cách Hoạt Động
|
|
1340
|
+
|
|
1341
|
+
- **Phát hiện Liên kết Ngoài**:
|
|
1342
|
+
Hàm trợ giúp `checkIsExternalLink` xác định xem một URL có phải là liên kết ngoài hay không. Các liên kết ngoài được giữ nguyên vì không cần phải địa phương hóa.
|
|
1343
|
+
|
|
1344
|
+
- **Lấy Ngôn ngữ Hiện tại**:
|
|
1345
|
+
Hook `useLocale` cung cấp ngôn ngữ hiện tại (ví dụ: `fr` cho tiếng Pháp).
|
|
1346
|
+
|
|
1347
|
+
- **Địa phương hóa URL**:
|
|
1348
|
+
Đối với các liên kết nội bộ (tức là không phải liên kết ngoài), `getLocalizedUrl` được sử dụng để tự động thêm tiền tố 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ữ Pháp, việc truyền `/about` làm `href` sẽ chuyển thành `/fr/about`.
|
|
1349
|
+
|
|
1350
|
+
- **Trả về Liên kết**:
|
|
1351
|
+
Thành phần 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 nhất quán với ngôn ngữ hiện tại.
|
|
1352
|
+
|
|
1353
|
+
Bằng cách tích hợp thành phần `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 từ SEO và khả năng sử dụng được cải thiện.
|
|
1354
|
+
|
|
1355
|
+
### Cấu hình TypeScript
|
|
1356
|
+
|
|
1357
|
+
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.
|
|
1358
|
+
|
|
1359
|
+

|
|
1360
|
+
|
|
1361
|
+

|
|
1362
|
+
|
|
1363
|
+
Đảm bảo cấu hình TypeScript của bạn bao gồm các kiểu được tạo tự động.
|
|
1364
|
+
|
|
1365
|
+
```json5 fileName="tsconfig.json"
|
|
1366
|
+
{
|
|
1367
|
+
// ... Cấu hình TypeScript hiện tại của bạn
|
|
1368
|
+
"include": [
|
|
1369
|
+
// ... Cấu hình TypeScript hiện tại của bạn
|
|
1370
|
+
".intlayer/**/*.ts", // Bao gồm các kiểu tự động tạo
|
|
1371
|
+
],
|
|
1372
|
+
}
|
|
1373
|
+
```
|
|
1374
|
+
|
|
1375
|
+
### Cấu hình Git
|
|
1376
|
+
|
|
1377
|
+
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.
|
|
1378
|
+
|
|
1379
|
+
Để làm điều này, bạn có thể thêm các chỉ dẫn sau vào tệp `.gitignore` của bạn:
|
|
1380
|
+
|
|
1381
|
+
```plaintext
|
|
1382
|
+
# Bỏ qua các tệp được tạo bởi Intlayer
|
|
1383
|
+
.intlayer
|
|
1384
|
+
```
|
|
1385
|
+
|
|
1386
|
+
### Tiện ích mở rộng VS Code
|
|
1387
|
+
|
|
1388
|
+
Để 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.
|
|
1389
|
+
|
|
1390
|
+
[Cài đặt từ VS Code Marketplace](https://marketplace.visualstudio.com/items?itemName=intlayer.intlayer-vs-code-extension)
|
|
1391
|
+
|
|
1392
|
+
Tiện ích mở rộng này cung cấp:
|
|
1393
|
+
|
|
1394
|
+
- **Tự động hoàn thành** cho các khóa dịch.
|
|
1395
|
+
- **Phát hiện lỗi thời gian thực** cho các bản dịch còn thiếu.
|
|
1396
|
+
- **Xem trước nội dung dịch ngay trong dòng**.
|
|
1397
|
+
- **Hành động nhanh** để dễ dàng tạo và cập nhật bản dịch.
|
|
1398
|
+
|
|
1399
|
+
Để 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).
|
|
1400
|
+
|
|
1401
|
+
---
|
|
1402
|
+
|
|
1403
|
+
### Tiến xa hơn
|
|
1404
|
+
|
|
1405
|
+
Để tiến xa hơn, bạn có thể triển khai [trình soạn thảo trực quan](https://github.com/aymericzip/intlayer/blob/main/docs/docs/vi/intlayer_visual_editor.md) hoặc tách nội dung của bạn ra ngoài bằng cách sử dụng [CMS](https://github.com/aymericzip/intlayer/blob/main/docs/docs/vi/intlayer_CMS.md).
|
|
1406
|
+
|
|
1407
|
+
---
|