@intlayer/docs 5.5.11 → 5.6.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/intlayer_with_next-intl.md +0 -1
- package/blog/ar/list_i18n_technologies/CMS/wordpress.md +1 -1
- package/blog/ar/list_i18n_technologies/frameworks/angular.md +1 -1
- package/blog/ar/list_i18n_technologies/frameworks/flutter.md +1 -1
- package/blog/ar/list_i18n_technologies/frameworks/react-native.md +1 -1
- package/blog/ar/list_i18n_technologies/frameworks/react.md +1 -1
- package/blog/ar/list_i18n_technologies/frameworks/svelte.md +1 -1
- package/blog/ar/list_i18n_technologies/frameworks/vue.md +1 -1
- package/blog/ar/what_is_internationalization.md +2 -2
- package/blog/de/intlayer_with_next-intl.md +0 -1
- package/blog/de/list_i18n_technologies/CMS/wordpress.md +1 -1
- package/blog/de/list_i18n_technologies/frameworks/angular.md +1 -1
- package/blog/de/list_i18n_technologies/frameworks/flutter.md +1 -1
- package/blog/de/list_i18n_technologies/frameworks/react-native.md +1 -1
- package/blog/de/list_i18n_technologies/frameworks/react.md +1 -1
- package/blog/de/list_i18n_technologies/frameworks/svelte.md +1 -1
- package/blog/de/list_i18n_technologies/frameworks/vue.md +1 -1
- package/blog/de/what_is_internationalization.md +2 -2
- package/blog/en/intlayer_with_next-intl.md +0 -1
- package/blog/en/list_i18n_technologies/CMS/wordpress.md +1 -1
- package/blog/en/list_i18n_technologies/frameworks/angular.md +1 -1
- package/blog/en/list_i18n_technologies/frameworks/flutter.md +1 -1
- package/blog/en/list_i18n_technologies/frameworks/react-native.md +1 -1
- package/blog/en/list_i18n_technologies/frameworks/react.md +1 -1
- package/blog/en/list_i18n_technologies/frameworks/svelte.md +1 -1
- package/blog/en/list_i18n_technologies/frameworks/vue.md +1 -1
- package/blog/en/what_is_internationalization.md +2 -2
- package/blog/en-GB/intlayer_with_next-intl.md +0 -1
- package/blog/en-GB/list_i18n_technologies/CMS/wordpress.md +1 -1
- package/blog/en-GB/list_i18n_technologies/frameworks/angular.md +1 -1
- package/blog/en-GB/list_i18n_technologies/frameworks/flutter.md +1 -1
- package/blog/en-GB/list_i18n_technologies/frameworks/react-native.md +1 -1
- package/blog/en-GB/list_i18n_technologies/frameworks/svelte.md +1 -1
- package/blog/en-GB/list_i18n_technologies/frameworks/vue.md +1 -1
- package/blog/en-GB/what_is_internationalization.md +2 -2
- package/blog/es/intlayer_with_next-intl.md +0 -1
- package/blog/es/list_i18n_technologies/CMS/wordpress.md +1 -1
- package/blog/es/list_i18n_technologies/frameworks/angular.md +1 -1
- package/blog/es/list_i18n_technologies/frameworks/flutter.md +1 -1
- package/blog/es/list_i18n_technologies/frameworks/react-native.md +1 -1
- package/blog/es/list_i18n_technologies/frameworks/react.md +1 -1
- package/blog/es/list_i18n_technologies/frameworks/svelte.md +1 -1
- package/blog/es/list_i18n_technologies/frameworks/vue.md +1 -1
- package/blog/es/what_is_internationalization.md +2 -2
- package/blog/fr/intlayer_with_next-intl.md +0 -1
- package/blog/fr/list_i18n_technologies/CMS/wordpress.md +1 -1
- package/blog/fr/list_i18n_technologies/frameworks/angular.md +1 -1
- package/blog/fr/list_i18n_technologies/frameworks/flutter.md +1 -1
- package/blog/fr/list_i18n_technologies/frameworks/react-native.md +1 -1
- package/blog/fr/list_i18n_technologies/frameworks/react.md +1 -1
- package/blog/fr/list_i18n_technologies/frameworks/svelte.md +1 -1
- package/blog/fr/list_i18n_technologies/frameworks/vue.md +1 -1
- package/blog/fr/what_is_internationalization.md +2 -2
- package/blog/hi/list_i18n_technologies/CMS/wordpress.md +1 -1
- package/blog/hi/list_i18n_technologies/frameworks/angular.md +1 -1
- package/blog/hi/list_i18n_technologies/frameworks/flutter.md +1 -1
- package/blog/hi/list_i18n_technologies/frameworks/react-native.md +1 -1
- package/blog/hi/list_i18n_technologies/frameworks/react.md +1 -1
- package/blog/hi/list_i18n_technologies/frameworks/svelte.md +1 -1
- package/blog/hi/list_i18n_technologies/frameworks/vue.md +1 -1
- package/blog/hi/what_is_internationalization.md +2 -2
- package/blog/it/intlayer_with_next-intl.md +0 -1
- package/blog/it/list_i18n_technologies/CMS/wordpress.md +1 -1
- package/blog/it/list_i18n_technologies/frameworks/angular.md +1 -1
- package/blog/it/list_i18n_technologies/frameworks/react-native.md +1 -1
- package/blog/it/list_i18n_technologies/frameworks/react.md +1 -1
- package/blog/it/list_i18n_technologies/frameworks/svelte.md +1 -1
- package/blog/it/list_i18n_technologies/frameworks/vue.md +1 -1
- package/blog/it/what_is_internationalization.md +2 -2
- package/blog/ja/intlayer_with_next-intl.md +0 -1
- package/blog/ja/list_i18n_technologies/CMS/wordpress.md +1 -1
- package/blog/ja/list_i18n_technologies/frameworks/angular.md +1 -1
- package/blog/ja/list_i18n_technologies/frameworks/flutter.md +1 -1
- package/blog/ja/list_i18n_technologies/frameworks/react-native.md +1 -1
- package/blog/ja/list_i18n_technologies/frameworks/react.md +1 -1
- package/blog/ja/list_i18n_technologies/frameworks/svelte.md +1 -1
- package/blog/ja/list_i18n_technologies/frameworks/vue.md +1 -1
- package/blog/ja/what_is_internationalization.md +2 -2
- package/blog/ko/intlayer_with_next-intl.md +0 -1
- package/blog/ko/list_i18n_technologies/CMS/wordpress.md +1 -1
- package/blog/ko/list_i18n_technologies/frameworks/angular.md +1 -1
- package/blog/ko/list_i18n_technologies/frameworks/react-native.md +1 -1
- package/blog/ko/list_i18n_technologies/frameworks/react.md +1 -1
- package/blog/ko/list_i18n_technologies/frameworks/vue.md +1 -1
- package/blog/pt/intlayer_with_next-intl.md +0 -1
- package/blog/pt/list_i18n_technologies/CMS/wordpress.md +1 -1
- package/blog/pt/list_i18n_technologies/frameworks/angular.md +1 -1
- package/blog/pt/list_i18n_technologies/frameworks/flutter.md +1 -1
- package/blog/pt/list_i18n_technologies/frameworks/react-native.md +1 -1
- package/blog/pt/list_i18n_technologies/frameworks/react.md +1 -1
- package/blog/pt/list_i18n_technologies/frameworks/svelte.md +1 -1
- package/blog/pt/list_i18n_technologies/frameworks/vue.md +1 -1
- package/blog/pt/what_is_internationalization.md +2 -2
- package/blog/ru/intlayer_with_next-intl.md +0 -1
- package/blog/ru/list_i18n_technologies/CMS/wordpress.md +1 -1
- package/blog/ru/list_i18n_technologies/frameworks/angular.md +1 -1
- package/blog/ru/list_i18n_technologies/frameworks/flutter.md +1 -1
- package/blog/ru/list_i18n_technologies/frameworks/react-native.md +1 -1
- package/blog/ru/list_i18n_technologies/frameworks/react.md +1 -1
- package/blog/ru/list_i18n_technologies/frameworks/svelte.md +1 -1
- package/blog/ru/list_i18n_technologies/frameworks/vue.md +1 -1
- package/blog/ru/what_is_internationalization.md +2 -2
- package/blog/zh/intlayer_with_next-intl.md +0 -1
- package/blog/zh/list_i18n_technologies/CMS/wordpress.md +1 -1
- package/blog/zh/list_i18n_technologies/frameworks/angular.md +1 -1
- package/blog/zh/list_i18n_technologies/frameworks/flutter.md +1 -1
- package/blog/zh/list_i18n_technologies/frameworks/react-native.md +1 -1
- package/blog/zh/list_i18n_technologies/frameworks/react.md +1 -1
- package/blog/zh/list_i18n_technologies/frameworks/svelte.md +1 -1
- package/blog/zh/list_i18n_technologies/frameworks/vue.md +1 -1
- package/blog/zh/what_is_internationalization.md +2 -2
- package/dist/cjs/blog.cjs +2 -2
- package/dist/cjs/blog.cjs.map +1 -1
- package/dist/cjs/common.cjs +17 -6
- package/dist/cjs/common.cjs.map +1 -1
- package/dist/cjs/doc.cjs +2 -2
- package/dist/cjs/doc.cjs.map +1 -1
- package/dist/cjs/frequentQuestions.cjs +2 -2
- package/dist/cjs/frequentQuestions.cjs.map +1 -1
- package/dist/cjs/generated/blog.entry.cjs +1152 -252
- package/dist/cjs/generated/blog.entry.cjs.map +1 -1
- package/dist/cjs/generated/docs.entry.cjs +3778 -1124
- package/dist/cjs/generated/docs.entry.cjs.map +1 -1
- package/dist/cjs/generated/frequentQuestions.entry.cjs +794 -161
- package/dist/cjs/generated/frequentQuestions.entry.cjs.map +1 -1
- package/dist/cjs/generated/legal.entry.cjs +32 -31
- package/dist/cjs/generated/legal.entry.cjs.map +1 -1
- package/dist/cjs/legal.cjs +2 -2
- package/dist/cjs/legal.cjs.map +1 -1
- package/dist/esm/blog.mjs +2 -2
- package/dist/esm/blog.mjs.map +1 -1
- package/dist/esm/common.mjs +17 -6
- package/dist/esm/common.mjs.map +1 -1
- package/dist/esm/doc.mjs +2 -2
- package/dist/esm/doc.mjs.map +1 -1
- package/dist/esm/frequentQuestions.mjs +2 -2
- package/dist/esm/frequentQuestions.mjs.map +1 -1
- package/dist/esm/generated/blog.entry.mjs +1151 -252
- package/dist/esm/generated/blog.entry.mjs.map +1 -1
- package/dist/esm/generated/docs.entry.mjs +3777 -1124
- package/dist/esm/generated/docs.entry.mjs.map +1 -1
- package/dist/esm/generated/frequentQuestions.entry.mjs +793 -161
- package/dist/esm/generated/frequentQuestions.entry.mjs.map +1 -1
- package/dist/esm/generated/legal.entry.mjs +31 -31
- package/dist/esm/generated/legal.entry.mjs.map +1 -1
- package/dist/esm/legal.mjs +2 -2
- package/dist/esm/legal.mjs.map +1 -1
- package/dist/types/blog.d.ts +2 -2
- package/dist/types/blog.d.ts.map +1 -1
- package/dist/types/common.d.ts +5 -2
- package/dist/types/common.d.ts.map +1 -1
- package/dist/types/doc.d.ts +2 -2
- package/dist/types/doc.d.ts.map +1 -1
- package/dist/types/frequentQuestions.d.ts +2 -2
- package/dist/types/frequentQuestions.d.ts.map +1 -1
- package/dist/types/generated/blog.entry.d.ts.map +1 -1
- package/dist/types/generated/docs.entry.d.ts.map +1 -1
- package/dist/types/generated/frequentQuestions.entry.d.ts +1 -0
- package/dist/types/generated/frequentQuestions.entry.d.ts.map +1 -1
- package/dist/types/generated/legal.entry.d.ts.map +1 -1
- package/dist/types/legal.d.ts +2 -2
- package/dist/types/legal.d.ts.map +1 -1
- package/docs/ar/intlayer_CMS.md +1 -0
- package/docs/ar/intlayer_cli.md +292 -177
- package/docs/ar/intlayer_visual_editor.md +1 -0
- package/docs/ar/intlayer_with_angular.md +1 -0
- package/docs/ar/intlayer_with_create_react_app.md +1 -0
- package/docs/ar/intlayer_with_lynx+react.md +1 -0
- package/docs/ar/intlayer_with_nextjs_14.md +1 -0
- package/docs/ar/intlayer_with_nextjs_15.md +3 -1
- package/docs/ar/intlayer_with_nuxt.md +1 -0
- package/docs/ar/intlayer_with_react_native+expo.md +1 -0
- package/docs/ar/intlayer_with_vite+preact.md +4 -3
- package/docs/ar/intlayer_with_vite+react.md +108 -112
- package/docs/ar/intlayer_with_vite+solid.md +4 -3
- package/docs/ar/intlayer_with_vite+svelte.md +4 -3
- package/docs/ar/intlayer_with_vite+vue.md +5 -4
- package/docs/ar/mcp_server.md +126 -92
- package/docs/de/intlayer_CMS.md +1 -0
- package/docs/de/intlayer_cli.md +291 -171
- package/docs/de/intlayer_visual_editor.md +1 -0
- package/docs/de/intlayer_with_angular.md +1 -0
- package/docs/de/intlayer_with_create_react_app.md +1 -0
- package/docs/de/intlayer_with_lynx+react.md +1 -0
- package/docs/de/intlayer_with_nextjs_14.md +1 -0
- package/docs/de/intlayer_with_nextjs_15.md +3 -1
- package/docs/de/intlayer_with_nuxt.md +1 -0
- package/docs/de/intlayer_with_react_native+expo.md +1 -0
- package/docs/de/intlayer_with_vite+preact.md +4 -3
- package/docs/de/intlayer_with_vite+react.md +128 -146
- package/docs/de/intlayer_with_vite+solid.md +4 -3
- package/docs/de/intlayer_with_vite+svelte.md +4 -3
- package/docs/de/intlayer_with_vite+vue.md +5 -4
- package/docs/de/mcp_server.md +116 -112
- package/docs/en/CI_CD.md +3 -1
- package/docs/en/autoFill.md +3 -1
- package/docs/en/configuration.md +7 -3
- package/docs/en/dictionary/condition.md +3 -1
- package/docs/en/dictionary/content_extention_customization.md +3 -1
- package/docs/en/dictionary/enumeration.md +3 -1
- package/docs/en/dictionary/file.md +3 -1
- package/docs/en/dictionary/function_fetching.md +3 -1
- package/docs/en/dictionary/get_started.md +3 -1
- package/docs/en/dictionary/insertion.md +3 -1
- package/docs/en/dictionary/markdown.md +3 -1
- package/docs/en/dictionary/nesting.md +3 -1
- package/docs/en/dictionary/translation.md +3 -1
- package/docs/en/how_works_intlayer.md +3 -1
- package/docs/en/index.md +3 -1
- package/docs/en/interest_of_intlayer.md +3 -1
- package/docs/en/intlayer_CMS.md +4 -1
- package/docs/en/intlayer_cli.md +246 -136
- package/docs/en/intlayer_visual_editor.md +4 -1
- package/docs/en/intlayer_with_angular.md +4 -1
- package/docs/en/intlayer_with_create_react_app.md +4 -1
- package/docs/en/intlayer_with_express.md +3 -1
- package/docs/en/intlayer_with_lynx+react.md +4 -1
- package/docs/en/intlayer_with_nextjs_14.md +7 -1
- package/docs/en/intlayer_with_nextjs_15.md +8 -2
- package/docs/en/intlayer_with_nextjs_page_router.md +5 -1
- package/docs/en/intlayer_with_nuxt.md +4 -1
- package/docs/en/intlayer_with_react_native+expo.md +4 -1
- package/docs/en/intlayer_with_vite+preact.md +9 -4
- package/docs/en/intlayer_with_vite+react.md +18 -10
- package/docs/en/intlayer_with_vite+solid.md +7 -4
- package/docs/en/intlayer_with_vite+svelte.md +7 -4
- package/docs/en/intlayer_with_vite+vue.md +10 -5
- package/docs/en/introduction.md +3 -1
- package/docs/en/mcp_server.md +114 -80
- package/docs/en/packages/@intlayer/api/index.md +3 -1
- package/docs/en/packages/@intlayer/chokidar/index.md +3 -1
- package/docs/en/packages/@intlayer/cli/index.md +3 -1
- package/docs/en/packages/@intlayer/config/index.md +3 -1
- package/docs/en/packages/@intlayer/core/index.md +3 -1
- package/docs/en/packages/@intlayer/design-system/index.md +3 -1
- package/docs/en/packages/@intlayer/dictionary-entry/index.md +3 -1
- package/docs/en/packages/@intlayer/editor/index.md +3 -1
- package/docs/en/packages/@intlayer/editor-react/index.md +3 -1
- package/docs/en/packages/@intlayer/webpack/index.md +3 -1
- package/docs/en/packages/angular-intlayer/index.md +3 -1
- package/docs/en/packages/express-intlayer/index.md +3 -1
- package/docs/en/packages/express-intlayer/t.md +3 -1
- package/docs/en/packages/intlayer/getConfiguration.md +3 -1
- package/docs/en/packages/intlayer/getEnumeration.md +3 -1
- package/docs/en/packages/intlayer/getHTMLTextDir.md +3 -1
- package/docs/en/packages/intlayer/getLocaleLang.md +3 -1
- package/docs/en/packages/intlayer/getLocaleName.md +3 -1
- package/docs/en/packages/intlayer/getLocalizedUrl.md +3 -1
- package/docs/en/packages/intlayer/getMultilingualUrls.md +3 -1
- package/docs/en/packages/intlayer/getPathWithoutLocale.md +3 -1
- package/docs/en/packages/intlayer/getTranslation.md +3 -1
- package/docs/en/packages/intlayer/getTranslationContent.md +3 -1
- package/docs/en/packages/intlayer/index.md +3 -1
- package/docs/en/packages/intlayer-cli/index.md +3 -1
- package/docs/en/packages/intlayer-editor/index.md +3 -1
- package/docs/en/packages/lynx-intlayer/index.md +3 -1
- package/docs/en/packages/next-intlayer/index.md +3 -1
- package/docs/en/packages/next-intlayer/t.md +3 -1
- package/docs/en/packages/next-intlayer/useDictionary.md +3 -1
- package/docs/en/packages/next-intlayer/useIntlayer.md +3 -1
- package/docs/en/packages/next-intlayer/useIntlayerAsync.md +3 -1
- package/docs/en/packages/next-intlayer/useLocale.md +3 -1
- package/docs/en/packages/nuxt-intlayer/index.md +3 -1
- package/docs/en/packages/preact-intlayer/index.md +3 -1
- package/docs/en/packages/react-intlayer/index.md +3 -1
- package/docs/en/packages/react-intlayer/t.md +3 -1
- package/docs/en/packages/react-intlayer/useDictionary.md +3 -1
- package/docs/en/packages/react-intlayer/useIntlayer.md +3 -1
- package/docs/en/packages/react-intlayer/useIntlayerAsync.md +3 -1
- package/docs/en/packages/react-intlayer/useLocale.md +3 -1
- package/docs/en/packages/react-native-intlayer/index.md +3 -1
- package/docs/en/packages/react-scripts-intlayer/index.md +3 -1
- package/docs/en/packages/solid-intlayer/index.md +3 -1
- package/docs/en/packages/svelte-intlayer/index.md +3 -1
- package/docs/en/packages/vite-intlayer/index.md +3 -1
- package/docs/en/packages/vue-intlayer/index.md +3 -1
- package/docs/en/per_locale_file.md +3 -1
- package/docs/en/roadmap.md +5 -2
- package/docs/en/vs_code_extension.md +3 -1
- package/docs/en-GB/intlayer_CMS.md +1 -0
- package/docs/en-GB/intlayer_cli.md +257 -138
- package/docs/en-GB/intlayer_visual_editor.md +1 -0
- package/docs/en-GB/intlayer_with_angular.md +1 -0
- package/docs/en-GB/intlayer_with_create_react_app.md +1 -0
- package/docs/en-GB/intlayer_with_lynx+react.md +1 -0
- package/docs/en-GB/intlayer_with_nextjs_14.md +1 -0
- package/docs/en-GB/intlayer_with_nextjs_15.md +3 -1
- package/docs/en-GB/intlayer_with_nuxt.md +1 -0
- package/docs/en-GB/intlayer_with_react_native+expo.md +1 -0
- package/docs/en-GB/intlayer_with_vite+preact.md +4 -3
- package/docs/en-GB/intlayer_with_vite+react.md +71 -87
- package/docs/en-GB/intlayer_with_vite+solid.md +4 -3
- package/docs/en-GB/intlayer_with_vite+svelte.md +4 -3
- package/docs/en-GB/intlayer_with_vite+vue.md +5 -4
- package/docs/en-GB/mcp_server.md +116 -82
- package/docs/es/intlayer_CMS.md +1 -0
- package/docs/es/intlayer_cli.md +283 -164
- package/docs/es/intlayer_visual_editor.md +1 -0
- package/docs/es/intlayer_with_angular.md +1 -0
- package/docs/es/intlayer_with_create_react_app.md +1 -0
- package/docs/es/intlayer_with_lynx+react.md +1 -0
- package/docs/es/intlayer_with_nextjs_14.md +1 -0
- package/docs/es/intlayer_with_nextjs_15.md +3 -1
- package/docs/es/intlayer_with_nuxt.md +1 -0
- package/docs/es/intlayer_with_react_native+expo.md +1 -0
- package/docs/es/intlayer_with_vite+preact.md +4 -3
- package/docs/es/intlayer_with_vite+react.md +98 -98
- package/docs/es/intlayer_with_vite+solid.md +4 -3
- package/docs/es/intlayer_with_vite+svelte.md +4 -3
- package/docs/es/intlayer_with_vite+vue.md +5 -4
- package/docs/es/mcp_server.md +120 -86
- package/docs/es/vs_code_extension.md +1 -0
- package/docs/fr/intlayer_CMS.md +1 -0
- package/docs/fr/intlayer_cli.md +280 -184
- package/docs/fr/intlayer_visual_editor.md +1 -0
- package/docs/fr/intlayer_with_angular.md +1 -0
- package/docs/fr/intlayer_with_create_react_app.md +1 -0
- package/docs/fr/intlayer_with_lynx+react.md +1 -0
- package/docs/fr/intlayer_with_nextjs_14.md +1 -0
- package/docs/fr/intlayer_with_nextjs_15.md +3 -1
- package/docs/fr/intlayer_with_nuxt.md +1 -0
- package/docs/fr/intlayer_with_react_native+expo.md +1 -0
- package/docs/fr/intlayer_with_vite+preact.md +5 -4
- package/docs/fr/intlayer_with_vite+react.md +80 -69
- package/docs/fr/intlayer_with_vite+solid.md +4 -3
- package/docs/fr/intlayer_with_vite+svelte.md +4 -3
- package/docs/fr/intlayer_with_vite+vue.md +5 -4
- package/docs/fr/mcp_server.md +121 -87
- package/docs/hi/intlayer_CMS.md +1 -0
- package/docs/hi/intlayer_cli.md +295 -174
- package/docs/hi/intlayer_visual_editor.md +1 -0
- package/docs/hi/intlayer_with_angular.md +1 -0
- package/docs/hi/intlayer_with_create_react_app.md +1 -0
- package/docs/hi/intlayer_with_lynx+react.md +1 -0
- package/docs/hi/intlayer_with_nextjs_14.md +1 -0
- package/docs/hi/intlayer_with_nextjs_15.md +3 -1
- package/docs/hi/intlayer_with_nuxt.md +1 -0
- package/docs/hi/intlayer_with_react_native+expo.md +1 -0
- package/docs/hi/intlayer_with_vite+preact.md +4 -3
- package/docs/hi/intlayer_with_vite+react.md +114 -111
- package/docs/hi/intlayer_with_vite+solid.md +4 -3
- package/docs/hi/intlayer_with_vite+svelte.md +4 -3
- package/docs/hi/intlayer_with_vite+vue.md +5 -4
- package/docs/hi/mcp_server.md +118 -84
- package/docs/it/intlayer_CMS.md +1 -0
- package/docs/it/intlayer_cli.md +282 -167
- package/docs/it/intlayer_visual_editor.md +1 -0
- package/docs/it/intlayer_with_angular.md +1 -0
- package/docs/it/intlayer_with_create_react_app.md +1 -0
- package/docs/it/intlayer_with_lynx+react.md +1 -0
- package/docs/it/intlayer_with_nextjs_14.md +1 -0
- package/docs/it/intlayer_with_nextjs_15.md +3 -1
- package/docs/it/intlayer_with_nuxt.md +1 -0
- package/docs/it/intlayer_with_react_native+expo.md +1 -0
- package/docs/it/intlayer_with_vite+preact.md +4 -3
- package/docs/it/intlayer_with_vite+react.md +163 -116
- package/docs/it/intlayer_with_vite+solid.md +4 -3
- package/docs/it/intlayer_with_vite+svelte.md +4 -3
- package/docs/it/intlayer_with_vite+vue.md +4 -4
- package/docs/it/mcp_server.md +120 -86
- package/docs/ja/intlayer_CMS.md +1 -0
- package/docs/ja/intlayer_cli.md +285 -168
- package/docs/ja/intlayer_visual_editor.md +1 -0
- package/docs/ja/intlayer_with_angular.md +1 -0
- package/docs/ja/intlayer_with_create_react_app.md +1 -0
- package/docs/ja/intlayer_with_lynx+react.md +1 -0
- package/docs/ja/intlayer_with_nextjs_14.md +1 -0
- package/docs/ja/intlayer_with_nextjs_15.md +3 -1
- package/docs/ja/intlayer_with_nuxt.md +1 -0
- package/docs/ja/intlayer_with_react_native+expo.md +1 -0
- package/docs/ja/intlayer_with_vite+preact.md +4 -3
- package/docs/ja/intlayer_with_vite+react.md +160 -222
- package/docs/ja/intlayer_with_vite+solid.md +4 -3
- package/docs/ja/intlayer_with_vite+svelte.md +4 -3
- package/docs/ja/intlayer_with_vite+vue.md +5 -4
- package/docs/ja/mcp_server.md +121 -85
- package/docs/ko/intlayer_CMS.md +1 -0
- package/docs/ko/intlayer_cli.md +291 -175
- package/docs/ko/intlayer_visual_editor.md +1 -0
- package/docs/ko/intlayer_with_angular.md +1 -0
- package/docs/ko/intlayer_with_create_react_app.md +1 -0
- package/docs/ko/intlayer_with_lynx+react.md +1 -0
- package/docs/ko/intlayer_with_nextjs_14.md +1 -0
- package/docs/ko/intlayer_with_nextjs_15.md +3 -1
- package/docs/ko/intlayer_with_nuxt.md +1 -0
- package/docs/ko/intlayer_with_react_native+expo.md +1 -0
- package/docs/ko/intlayer_with_vite+preact.md +4 -3
- package/docs/ko/intlayer_with_vite+react.md +123 -152
- package/docs/ko/intlayer_with_vite+solid.md +4 -3
- package/docs/ko/intlayer_with_vite+svelte.md +4 -3
- package/docs/ko/intlayer_with_vite+vue.md +5 -4
- package/docs/ko/mcp_server.md +117 -83
- package/docs/ko/packages/intlayer/getLocalizedUrl.md +1 -23
- package/docs/pt/intlayer_CMS.md +1 -0
- package/docs/pt/intlayer_cli.md +274 -154
- package/docs/pt/intlayer_visual_editor.md +1 -0
- package/docs/pt/intlayer_with_angular.md +1 -0
- package/docs/pt/intlayer_with_create_react_app.md +1 -0
- package/docs/pt/intlayer_with_lynx+react.md +1 -0
- package/docs/pt/intlayer_with_nextjs_14.md +1 -0
- package/docs/pt/intlayer_with_nextjs_15.md +3 -1
- package/docs/pt/intlayer_with_nuxt.md +1 -0
- package/docs/pt/intlayer_with_react_native+expo.md +1 -0
- package/docs/pt/intlayer_with_vite+preact.md +4 -3
- package/docs/pt/intlayer_with_vite+react.md +117 -136
- package/docs/pt/intlayer_with_vite+solid.md +4 -3
- package/docs/pt/intlayer_with_vite+svelte.md +4 -3
- package/docs/pt/intlayer_with_vite+vue.md +4 -4
- package/docs/pt/mcp_server.md +121 -87
- package/docs/ru/intlayer_CMS.md +1 -0
- package/docs/ru/intlayer_cli.md +287 -170
- package/docs/ru/intlayer_visual_editor.md +1 -0
- package/docs/ru/intlayer_with_angular.md +1 -0
- package/docs/ru/intlayer_with_create_react_app.md +1 -0
- package/docs/ru/intlayer_with_lynx+react.md +1 -0
- package/docs/ru/intlayer_with_nextjs_14.md +1 -0
- package/docs/ru/intlayer_with_nextjs_15.md +3 -1
- package/docs/ru/intlayer_with_nuxt.md +1 -0
- package/docs/ru/intlayer_with_react_native+expo.md +1 -0
- package/docs/ru/intlayer_with_vite+preact.md +4 -3
- package/docs/ru/intlayer_with_vite+react.md +105 -87
- package/docs/ru/intlayer_with_vite+solid.md +4 -3
- package/docs/ru/intlayer_with_vite+svelte.md +4 -3
- package/docs/ru/intlayer_with_vite+vue.md +5 -4
- package/docs/ru/mcp_server.md +119 -85
- package/docs/zh/intlayer_CMS.md +1 -0
- package/docs/zh/intlayer_cli.md +275 -155
- package/docs/zh/intlayer_visual_editor.md +1 -0
- package/docs/zh/intlayer_with_angular.md +1 -0
- package/docs/zh/intlayer_with_create_react_app.md +1 -0
- package/docs/zh/intlayer_with_lynx+react.md +1 -0
- package/docs/zh/intlayer_with_nextjs_14.md +1 -0
- package/docs/zh/intlayer_with_nextjs_15.md +3 -1
- package/docs/zh/intlayer_with_nuxt.md +1 -0
- package/docs/zh/intlayer_with_react_native+expo.md +1 -0
- package/docs/zh/intlayer_with_vite+preact.md +4 -3
- package/docs/zh/intlayer_with_vite+react.md +154 -188
- package/docs/zh/intlayer_with_vite+solid.md +4 -3
- package/docs/zh/intlayer_with_vite+svelte.md +4 -3
- package/docs/zh/intlayer_with_vite+vue.md +5 -4
- package/docs/zh/mcp_server.md +119 -86
- package/docs/zh/packages/intlayer/getLocalizedUrl.md +1 -23
- package/frequent_questions/ar/build_error_CI_CD.md +75 -0
- package/frequent_questions/de/build_error_CI_CD.md +75 -0
- package/frequent_questions/en/build_error_CI_CD.md +75 -0
- package/frequent_questions/en-GB/build_error_CI_CD.md +75 -0
- package/frequent_questions/es/build_error_CI_CD.md +75 -0
- package/frequent_questions/fr/build_error_CI_CD.md +75 -0
- package/frequent_questions/hi/build_error_CI_CD.md +75 -0
- package/frequent_questions/it/build_error_CI_CD.md +75 -0
- package/frequent_questions/ja/build_error_CI_CD.md +75 -0
- package/frequent_questions/ja/intlayer_command_undefined.md +3 -3
- package/frequent_questions/ko/build_error_CI_CD.md +75 -0
- package/frequent_questions/ko/intlayer_command_undefined.md +3 -3
- package/frequent_questions/pt/build_error_CI_CD.md +75 -0
- package/frequent_questions/ru/build_error_CI_CD.md +75 -0
- package/frequent_questions/zh/build_error_CI_CD.md +75 -0
- package/frequent_questions/zh/intlayer_command_undefined.md +3 -3
- package/legal/ar/privacy_notice.md +83 -0
- package/legal/ar/terms_of_service.md +55 -0
- package/legal/de/privacy_notice.md +83 -0
- package/legal/de/terms_of_service.md +55 -0
- package/legal/en/privacy_notice.md +83 -0
- package/legal/en/terms_of_service.md +55 -0
- package/legal/en-GB/privacy_notice.md +83 -0
- package/legal/en-GB/terms_of_service.md +55 -0
- package/legal/es/privacy_notice.md +83 -0
- package/legal/es/terms_of_service.md +55 -0
- package/legal/fr/privacy_notice.md +83 -0
- package/legal/fr/terms_of_service.md +55 -0
- package/legal/hi/privacy_notice.md +83 -0
- package/legal/hi/terms_of_service.md +55 -0
- package/legal/it/privacy_notice.md +83 -0
- package/legal/it/terms_of_service.md +55 -0
- package/legal/ja/privacy_notice.md +83 -0
- package/legal/ja/terms_of_service.md +55 -0
- package/legal/ko/privacy_notice.md +83 -0
- package/legal/ko/terms_of_service.md +55 -0
- package/legal/pt/privacy_notice.md +83 -0
- package/legal/pt/terms_of_service.md +55 -0
- package/legal/ru/privacy_notice.md +83 -0
- package/legal/ru/terms_of_service.md +55 -0
- package/legal/zh/privacy_notice.md +83 -0
- package/legal/zh/terms_of_service.md +55 -0
- package/package.json +12 -11
- package/src/blog.ts +6 -4
- package/src/common.ts +25 -7
- package/src/doc.ts +6 -4
- package/src/frequentQuestions.ts +6 -4
- package/src/generated/blog.entry.ts +1177 -280
- package/src/generated/docs.entry.ts +3868 -1217
- package/src/generated/frequentQuestions.entry.ts +808 -178
- package/src/generated/legal.entry.ts +34 -36
- package/src/legal.ts +6 -4
|
@@ -1,35 +1,38 @@
|
|
|
1
1
|
---
|
|
2
|
-
createdAt:
|
|
3
|
-
updatedAt:
|
|
4
|
-
title:
|
|
5
|
-
description:
|
|
2
|
+
createdAt: 2024-03-07
|
|
3
|
+
updatedAt: 2024-03-07
|
|
4
|
+
title: 在 Vite + React 中使用 Intlayer 入门
|
|
5
|
+
description: 学习如何使用 Intlayer 为您的 Vite 和 React 应用添加国际化 (i18n)。按照本指南使您的应用支持多语言。
|
|
6
6
|
keywords:
|
|
7
7
|
- 国际化
|
|
8
8
|
- 文档
|
|
9
9
|
- Intlayer
|
|
10
10
|
- Vite
|
|
11
11
|
- React
|
|
12
|
-
-
|
|
12
|
+
- i18n
|
|
13
13
|
- JavaScript
|
|
14
14
|
slugs:
|
|
15
15
|
- doc
|
|
16
16
|
- environment
|
|
17
|
-
-
|
|
18
|
-
|
|
17
|
+
- vite-and-react
|
|
18
|
+
applicationTemplate: https://github.com/aymericzip/intlayer-vite-react-template
|
|
19
|
+
youtubeVideo: https://www.youtube.com/watch?v=dS9L7uJeak4---
|
|
20
|
+
|
|
21
|
+
# 使用 Intlayer 结合 Vite 和 React 开始国际化 (i18n)
|
|
19
22
|
|
|
20
|
-
|
|
23
|
+
<iframe title="The best i18n solution for Vite and React? Discover 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"/>
|
|
21
24
|
|
|
22
25
|
请参阅 GitHub 上的[应用模板](https://github.com/aymericzip/intlayer-vite-react-template)。
|
|
23
26
|
|
|
24
27
|
## 什么是 Intlayer?
|
|
25
28
|
|
|
26
|
-
**Intlayer**
|
|
29
|
+
**Intlayer** 是一个创新的开源国际化 (i18n) 库,旨在简化现代 Web 应用的多语言支持。
|
|
27
30
|
|
|
28
31
|
使用 Intlayer,您可以:
|
|
29
32
|
|
|
30
|
-
-
|
|
31
|
-
-
|
|
32
|
-
-
|
|
33
|
+
- **轻松管理翻译**,使用组件级别的声明式字典。
|
|
34
|
+
- **动态本地化元数据**、路由和内容。
|
|
35
|
+
- **确保 TypeScript 支持**,通过自动生成的类型提升自动补全和错误检测。
|
|
33
36
|
- **享受高级功能**,如动态语言环境检测和切换。
|
|
34
37
|
|
|
35
38
|
---
|
|
@@ -42,32 +45,32 @@ slugs:
|
|
|
42
45
|
|
|
43
46
|
```bash packageManager="npm"
|
|
44
47
|
npm install intlayer react-intlayer
|
|
45
|
-
npm install --save-dev
|
|
48
|
+
npm install vite-intlayer --save-dev
|
|
46
49
|
```
|
|
47
50
|
|
|
48
51
|
```bash packageManager="pnpm"
|
|
49
52
|
pnpm add intlayer react-intlayer
|
|
50
|
-
pnpm add --save-dev
|
|
53
|
+
pnpm add vite-intlayer --save-dev
|
|
51
54
|
```
|
|
52
55
|
|
|
53
56
|
```bash packageManager="yarn"
|
|
54
57
|
yarn add intlayer react-intlayer
|
|
55
|
-
yarn add --save-dev
|
|
58
|
+
yarn add vite-intlayer --save-dev
|
|
56
59
|
```
|
|
57
60
|
|
|
58
61
|
- **intlayer**
|
|
59
62
|
|
|
60
|
-
|
|
63
|
+
核心包,提供用于配置管理、翻译、[内容声明](https://github.com/aymericzip/intlayer/blob/main/docs/docs/zh/dictionary/get_started.md)、转译和[CLI命令](https://github.com/aymericzip/intlayer/blob/main/docs/docs/zh/intlayer_cli.md)的国际化工具。
|
|
61
64
|
|
|
62
65
|
- **react-intlayer**
|
|
63
|
-
将 Intlayer 集成到 React
|
|
66
|
+
将 Intlayer 集成到 React 应用中的包。它提供了用于 React 国际化的上下文提供者和钩子。
|
|
64
67
|
|
|
65
68
|
- **vite-intlayer**
|
|
66
|
-
|
|
69
|
+
包含用于将 Intlayer 集成到[Vite 打包工具](https://vite.dev/guide/why.html#why-bundle-for-production)的 Vite 插件,以及用于检测用户首选语言环境、管理 Cookie 和处理 URL 重定向的中间件。
|
|
67
70
|
|
|
68
|
-
### 第
|
|
71
|
+
### 第2步:配置您的项目
|
|
69
72
|
|
|
70
|
-
|
|
73
|
+
创建一个配置文件来配置您应用程序的语言:
|
|
71
74
|
|
|
72
75
|
```typescript fileName="intlayer.config.ts" codeFormat="typescript"
|
|
73
76
|
import { Locales, type IntlayerConfig } from "intlayer";
|
|
@@ -78,7 +81,7 @@ const config: IntlayerConfig = {
|
|
|
78
81
|
Locales.ENGLISH,
|
|
79
82
|
Locales.FRENCH,
|
|
80
83
|
Locales.SPANISH,
|
|
81
|
-
//
|
|
84
|
+
// 您的其他语言
|
|
82
85
|
],
|
|
83
86
|
defaultLocale: Locales.ENGLISH,
|
|
84
87
|
},
|
|
@@ -91,16 +94,15 @@ export default config;
|
|
|
91
94
|
import { Locales } from "intlayer";
|
|
92
95
|
|
|
93
96
|
/** @type {import('intlayer').IntlayerConfig} */
|
|
94
|
-
// 配置对象,定义国际化设置
|
|
95
97
|
const config = {
|
|
96
98
|
internationalization: {
|
|
97
99
|
locales: [
|
|
98
|
-
Locales.ENGLISH,
|
|
99
|
-
Locales.FRENCH,
|
|
100
|
-
Locales.SPANISH,
|
|
101
|
-
//
|
|
100
|
+
Locales.ENGLISH,
|
|
101
|
+
Locales.FRENCH,
|
|
102
|
+
Locales.SPANISH,
|
|
103
|
+
// 您的其他语言
|
|
102
104
|
],
|
|
103
|
-
defaultLocale: Locales.ENGLISH,
|
|
105
|
+
defaultLocale: Locales.ENGLISH,
|
|
104
106
|
},
|
|
105
107
|
};
|
|
106
108
|
|
|
@@ -111,40 +113,22 @@ export default config;
|
|
|
111
113
|
const { Locales } = require("intlayer");
|
|
112
114
|
|
|
113
115
|
/** @type {import('intlayer').IntlayerConfig} */
|
|
114
|
-
// 配置对象,定义国际化设置
|
|
115
116
|
const config = {
|
|
116
117
|
internationalization: {
|
|
117
118
|
locales: [
|
|
118
|
-
Locales.ENGLISH,
|
|
119
|
-
Locales.FRENCH,
|
|
120
|
-
Locales.SPANISH,
|
|
119
|
+
Locales.ENGLISH,
|
|
120
|
+
Locales.FRENCH,
|
|
121
|
+
Locales.SPANISH,
|
|
121
122
|
// 你的其他语言
|
|
122
123
|
],
|
|
123
|
-
defaultLocale: Locales.ENGLISH,
|
|
124
|
+
defaultLocale: Locales.ENGLISH,
|
|
124
125
|
},
|
|
125
126
|
};
|
|
126
127
|
|
|
127
128
|
module.exports = config;
|
|
128
129
|
```
|
|
129
130
|
|
|
130
|
-
> 通过此配置文件,您可以设置本地化的 URL、中间件重定向、
|
|
131
|
-
|
|
132
|
-
### 第三步:在您的 Vite 配置中集成 Intlayer
|
|
133
|
-
|
|
134
|
-
将 intlayer 插件添加到您的配置中。
|
|
135
|
-
|
|
136
|
-
```typescript fileName="vite.config.ts" codeFormat="typescript"
|
|
137
|
-
import { defineConfig } from "vite";
|
|
138
|
-
import react from "@vitejs/plugin-react-swc";
|
|
139
|
-
import { intlayerPlugin } from "vite-intlayer";
|
|
140
|
-
|
|
141
|
-
// https://vitejs.dev/config/
|
|
142
|
-
export default defineConfig({
|
|
143
|
-
plugins: [react(), intlayerPlugin()],
|
|
144
|
-
});
|
|
145
|
-
```
|
|
146
|
-
|
|
147
|
-
> 通过此配置文件,您可以设置本地化 URL、中间件重定向、Cookie 名称、内容声明的位置和扩展名、禁用 Intlayer 控制台日志等。有关可用参数的完整列表,请参阅[配置文档](https://github.com/aymericzip/intlayer/blob/main/docs/docs/zh/configuration.md)。
|
|
131
|
+
> 通过此配置文件,您可以设置本地化的 URL、中间件重定向、cookie 名称、内容声明的位置和扩展名,禁用控制台中的 Intlayer 日志等。有关可用参数的完整列表,请参阅[配置文档](https://github.com/aymericzip/intlayer/blob/main/docs/docs/zh/configuration.md)。
|
|
148
132
|
|
|
149
133
|
### 第三步:在您的 Vite 配置中集成 Intlayer
|
|
150
134
|
|
|
@@ -183,29 +167,6 @@ module.exports = defineConfig({
|
|
|
183
167
|
});
|
|
184
168
|
```
|
|
185
169
|
|
|
186
|
-
> `intlayerPlugin()` 是用于将 Intlayer 集成到 Vite 的插件。它确保构建内容声明文件并在开发模式下监视它们。在 Vite 应用中定义了 Intlayer 环境变量。此外,它还提供别名以优化性能。
|
|
187
|
-
|
|
188
|
-
### 第四步:声明您的内容
|
|
189
|
-
|
|
190
|
-
创建并管理您的内容声明以存储翻译:
|
|
191
|
-
|
|
192
|
-
```tsx fileName="src/app.content.tsx" contentDeclarationFormat="typescript"
|
|
193
|
-
import { t, type Dictionary } from "intlayer";
|
|
194
|
-
import type { ReactNode } from "react";
|
|
195
|
-
|
|
196
|
-
const appContent = {
|
|
197
|
-
key: "app",
|
|
198
|
-
content: {
|
|
199
|
-
viteLogo: t({
|
|
200
|
-
en: "Vite logo",
|
|
201
|
-
fr: "Logo Vite",
|
|
202
|
-
es: "Logo Vite",
|
|
203
|
-
}),
|
|
204
|
-
reactLogo: t({
|
|
205
|
-
en: "React logo",
|
|
206
|
-
fr: "Logo React",
|
|
207
|
-
```
|
|
208
|
-
|
|
209
170
|
> `intlayerPlugin()` Vite 插件用于将 Intlayer 集成到 Vite 中。它确保内容声明文件的构建,并在开发模式下监视这些文件。在 Vite 应用程序中定义了 Intlayer 环境变量。此外,它还提供别名以优化性能。
|
|
210
171
|
|
|
211
172
|
### 第4步:声明您的内容
|
|
@@ -227,7 +188,7 @@ const appContent = {
|
|
|
227
188
|
reactLogo: t({
|
|
228
189
|
en: "React logo",
|
|
229
190
|
fr: "Logo React",
|
|
230
|
-
es: "React
|
|
191
|
+
es: "Logo React",
|
|
231
192
|
}),
|
|
232
193
|
|
|
233
194
|
title: "Vite + React",
|
|
@@ -262,7 +223,7 @@ const appContent = {
|
|
|
262
223
|
es: "Haga clic en los logotipos de Vite y React para obtener más información",
|
|
263
224
|
}),
|
|
264
225
|
},
|
|
265
|
-
}
|
|
226
|
+
} 满足 Dictionary;
|
|
266
227
|
|
|
267
228
|
export default appContent;
|
|
268
229
|
```
|
|
@@ -277,13 +238,11 @@ const appContent = {
|
|
|
277
238
|
viteLogo: t({
|
|
278
239
|
en: "Vite logo",
|
|
279
240
|
fr: "Logo Vite",
|
|
280
|
-
zh: "Vite 标志",
|
|
281
241
|
es: "Logo Vite",
|
|
282
242
|
}),
|
|
283
243
|
reactLogo: t({
|
|
284
244
|
en: "React logo",
|
|
285
245
|
fr: "Logo React",
|
|
286
|
-
zh: "React 标志",
|
|
287
246
|
es: "Logo React",
|
|
288
247
|
}),
|
|
289
248
|
|
|
@@ -292,7 +251,6 @@ const appContent = {
|
|
|
292
251
|
count: t({
|
|
293
252
|
en: "count is ",
|
|
294
253
|
fr: "le compte est ",
|
|
295
|
-
zh: "计数是 ",
|
|
296
254
|
es: "el recuento es ",
|
|
297
255
|
}),
|
|
298
256
|
|
|
@@ -340,13 +298,11 @@ const appContent = {
|
|
|
340
298
|
en: "Vite logo",
|
|
341
299
|
fr: "Logo Vite",
|
|
342
300
|
es: "Logo Vite",
|
|
343
|
-
zh: "Vite 标志",
|
|
344
301
|
}),
|
|
345
302
|
reactLogo: t({
|
|
346
303
|
en: "React logo",
|
|
347
304
|
fr: "Logo React",
|
|
348
305
|
es: "Logo React",
|
|
349
|
-
zh: "React 标志",
|
|
350
306
|
}),
|
|
351
307
|
|
|
352
308
|
title: "Vite + React",
|
|
@@ -355,7 +311,6 @@ const appContent = {
|
|
|
355
311
|
en: "count is ",
|
|
356
312
|
fr: "le compte est ",
|
|
357
313
|
es: "el recuento es ",
|
|
358
|
-
zh: "计数是 ",
|
|
359
314
|
}),
|
|
360
315
|
|
|
361
316
|
edit:
|
|
@@ -381,8 +336,7 @@ const appContent = {
|
|
|
381
336
|
},
|
|
382
337
|
|
|
383
338
|
readTheDocs: t({
|
|
384
|
-
|
|
385
|
-
en: "Click on the Vite and React logos to learn more",
|
|
339
|
+
en: "点击 Vite 和 React 标志以了解更多信息",
|
|
386
340
|
fr: "Cliquez sur les logos Vite et React pour en savoir plus",
|
|
387
341
|
es: "Haga clic en los logotipos de Vite y React para obtener más información",
|
|
388
342
|
}),
|
|
@@ -400,7 +354,6 @@ module.exports = appContent;
|
|
|
400
354
|
"viteLogo": {
|
|
401
355
|
"nodeType": "translation",
|
|
402
356
|
"translation": {
|
|
403
|
-
"zh": "Vite 标志",
|
|
404
357
|
"en": "Vite logo",
|
|
405
358
|
"fr": "Logo Vite",
|
|
406
359
|
"es": "Logo Vite"
|
|
@@ -427,7 +380,7 @@ module.exports = appContent;
|
|
|
427
380
|
"count": {
|
|
428
381
|
"nodeType": "translation",
|
|
429
382
|
"translation": {
|
|
430
|
-
"zh": "
|
|
383
|
+
"zh": "计数为 ",
|
|
431
384
|
"en": "count is ",
|
|
432
385
|
"fr": "le compte est ",
|
|
433
386
|
"es": "el recuento es "
|
|
@@ -445,14 +398,17 @@ module.exports = appContent;
|
|
|
445
398
|
"readTheDocs": {
|
|
446
399
|
"nodeType": "translation",
|
|
447
400
|
"translation": {
|
|
448
|
-
"zh": "点击 Vite 和 React 标志以了解更多信息"
|
|
401
|
+
"zh": "点击 Vite 和 React 标志以了解更多信息",
|
|
402
|
+
"en": "Click on the Vite and React logos to learn more",
|
|
403
|
+
"fr": "Cliquez sur les logos Vite et React pour en savoir plus",
|
|
404
|
+
"es": "Haga clic en los logotipos de Vite y React para obtener más información"
|
|
449
405
|
}
|
|
450
406
|
}
|
|
451
407
|
}
|
|
452
408
|
}
|
|
453
409
|
```
|
|
454
410
|
|
|
455
|
-
>
|
|
411
|
+
> 您的内容声明可以定义在应用程序中的任何位置,只要它们被包含在 `contentDir` 目录中(默认是 `./src`)。并且匹配内容声明文件的扩展名(默认是 `.content.{json,ts,tsx,js,jsx,mjs,mjx,cjs,cjx}`)。
|
|
456
412
|
|
|
457
413
|
> 更多详情,请参阅[内容声明文档](https://github.com/aymericzip/intlayer/blob/main/docs/docs/zh/dictionary/get_started.md)。
|
|
458
414
|
|
|
@@ -500,7 +456,7 @@ const AppContent: FC = () => {
|
|
|
500
456
|
);
|
|
501
457
|
};
|
|
502
458
|
|
|
503
|
-
const App = () => (
|
|
459
|
+
const App: FC = () => (
|
|
504
460
|
<IntlayerProvider>
|
|
505
461
|
<AppContent />
|
|
506
462
|
</IntlayerProvider>
|
|
@@ -659,7 +615,7 @@ const LocaleSwitcher = () => {
|
|
|
659
615
|
|
|
660
616
|
### (可选)步骤 7:为您的应用程序添加本地化路由
|
|
661
617
|
|
|
662
|
-
此步骤的目的是为每种语言创建唯一的路由。这对于 SEO
|
|
618
|
+
此步骤的目的是为每种语言创建唯一的路由。这对于 SEO 和 SEO 友好的 URL 非常有用。
|
|
663
619
|
示例:
|
|
664
620
|
|
|
665
621
|
```plaintext
|
|
@@ -668,7 +624,7 @@ const LocaleSwitcher = () => {
|
|
|
668
624
|
- https://example.com/fr/about
|
|
669
625
|
```
|
|
670
626
|
|
|
671
|
-
>
|
|
627
|
+
> 默认情况下,默认语言的路由不会添加前缀。如果您想为默认语言添加前缀,可以在配置中将 `middleware.prefixDefault` 选项设置为 `true`。更多信息请参见[配置文档](https://github.com/aymericzip/intlayer/blob/main/docs/docs/zh/configuration.md)。
|
|
672
628
|
|
|
673
629
|
要为您的应用添加本地化路由,您可以创建一个 `LocaleRouter` 组件,包裹应用的路由并处理基于语言的路由。以下是使用 [React Router](https://reactrouter.com/home) 的示例:
|
|
674
630
|
|
|
@@ -690,21 +646,21 @@ const { internationalization, middleware } = configuration;
|
|
|
690
646
|
const { locales, defaultLocale } = internationalization;
|
|
691
647
|
|
|
692
648
|
/**
|
|
693
|
-
*
|
|
694
|
-
* 它管理基于 URL
|
|
649
|
+
* 一个处理本地化的组件,使用适当的语言环境上下文包裹子组件。
|
|
650
|
+
* 它管理基于 URL 的语言环境检测和验证。
|
|
695
651
|
*/
|
|
696
652
|
const AppLocalized: FC<PropsWithChildren<{ locale: Locales }>> = ({
|
|
697
653
|
children,
|
|
698
654
|
locale,
|
|
699
655
|
}) => {
|
|
700
|
-
const { pathname, search } = useLocation(); // 获取当前的
|
|
656
|
+
const { pathname, search } = useLocation(); // 获取当前的URL路径
|
|
701
657
|
|
|
702
|
-
//
|
|
658
|
+
// 确定当前的语言环境,如果未提供则回退到默认语言环境
|
|
703
659
|
const currentLocale = locale ?? defaultLocale;
|
|
704
660
|
|
|
705
661
|
// 移除路径中的语言环境前缀以构建基础路径
|
|
706
662
|
const pathWithoutLocale = getPathWithoutLocale(
|
|
707
|
-
pathname // 当前的
|
|
663
|
+
pathname // 当前的URL路径
|
|
708
664
|
);
|
|
709
665
|
|
|
710
666
|
/**
|
|
@@ -722,7 +678,7 @@ const AppLocalized: FC<PropsWithChildren<{ locale: Locales }>> = ({
|
|
|
722
678
|
);
|
|
723
679
|
}
|
|
724
680
|
|
|
725
|
-
// 使用 IntlayerProvider
|
|
681
|
+
// 使用 IntlayerProvider 包裹子组件并设置当前语言环境
|
|
726
682
|
return (
|
|
727
683
|
<IntlayerProvider locale={currentLocale}>{children}</IntlayerProvider>
|
|
728
684
|
);
|
|
@@ -737,13 +693,13 @@ const AppLocalized: FC<PropsWithChildren<{ locale: Locales }>> = ({
|
|
|
737
693
|
.filter(
|
|
738
694
|
(locale) => locale.toString() !== defaultLocale.toString() // 排除默认语言环境
|
|
739
695
|
)
|
|
740
|
-
.includes(currentLocale) //
|
|
696
|
+
.includes(currentLocale) // 检查当前语言环境是否在有效语言列表中
|
|
741
697
|
) {
|
|
742
|
-
//
|
|
698
|
+
// 重定向到无语言前缀的路径
|
|
743
699
|
return <Navigate to={`${pathWithoutLocale}${search}`} replace />;
|
|
744
700
|
}
|
|
745
701
|
|
|
746
|
-
// 使用 IntlayerProvider
|
|
702
|
+
// 使用 IntlayerProvider 包裹子组件并设置当前语言环境
|
|
747
703
|
return (
|
|
748
704
|
<IntlayerProvider locale={currentLocale}>{children}</IntlayerProvider>
|
|
749
705
|
);
|
|
@@ -766,18 +722,18 @@ export const LocaleRouter: FC<PropsWithChildren> = ({ children }) => (
|
|
|
766
722
|
// 路由模式用于捕获语言环境(例如 /en/,/fr/)并匹配所有后续路径
|
|
767
723
|
path={`/${locale}/*`}
|
|
768
724
|
key={locale}
|
|
769
|
-
element={<AppLocalized locale={locale}>{children}</AppLocalized>} //
|
|
725
|
+
element={<AppLocalized locale={locale}>{children}</AppLocalized>} // 使用语言环境管理包装子组件
|
|
770
726
|
/>
|
|
771
727
|
))}
|
|
772
728
|
|
|
773
729
|
{
|
|
774
|
-
//
|
|
730
|
+
// 如果禁用默认语言环境前缀,则直接在根路径渲染子组件
|
|
775
731
|
!middleware.prefixDefault && (
|
|
776
732
|
<Route
|
|
777
733
|
path="*"
|
|
778
734
|
element={
|
|
779
735
|
<AppLocalized locale={defaultLocale}>{children}</AppLocalized>
|
|
780
|
-
} //
|
|
736
|
+
} // 使用语言环境管理包装子组件
|
|
781
737
|
/>
|
|
782
738
|
)
|
|
783
739
|
}
|
|
@@ -799,12 +755,13 @@ import {
|
|
|
799
755
|
useLocation,
|
|
800
756
|
} from "react-router-dom"; // 用于管理导航的路由组件
|
|
801
757
|
|
|
802
|
-
// 从 Intlayer
|
|
758
|
+
// 从 Intlayer 配置中解构
|
|
803
759
|
const { internationalization, middleware } = configuration;
|
|
804
760
|
const { locales, defaultLocale } = internationalization;
|
|
805
761
|
|
|
806
762
|
/**
|
|
807
|
-
*
|
|
763
|
+
* 一个处理本地化的组件,使用适当的语言环境上下文包裹子组件。
|
|
764
|
+
/**
|
|
808
765
|
* 它管理基于 URL 的语言检测和验证。
|
|
809
766
|
*/
|
|
810
767
|
const AppLocalized = ({ children, locale }) => {
|
|
@@ -813,9 +770,9 @@ const AppLocalized = ({ children, locale }) => {
|
|
|
813
770
|
// 确定当前语言,如果未提供则回退到默认语言
|
|
814
771
|
const currentLocale = locale ?? defaultLocale;
|
|
815
772
|
|
|
816
|
-
//
|
|
773
|
+
// 从路径中移除语言前缀以构造基础路径
|
|
817
774
|
const pathWithoutLocale = getPathWithoutLocale(
|
|
818
|
-
pathname //
|
|
775
|
+
pathname // 当前 URL 路径
|
|
819
776
|
);
|
|
820
777
|
|
|
821
778
|
/**
|
|
@@ -862,7 +819,7 @@ const AppLocalized = ({ children, locale }) => {
|
|
|
862
819
|
};
|
|
863
820
|
|
|
864
821
|
/**
|
|
865
|
-
*
|
|
822
|
+
* 一个设置特定语言路由的路由组件。
|
|
866
823
|
* 它使用 React Router 来管理导航并渲染本地化组件。
|
|
867
824
|
*/
|
|
868
825
|
export const LocaleRouter = ({ children }) => (
|
|
@@ -882,7 +839,7 @@ export const LocaleRouter = ({ children }) => (
|
|
|
882
839
|
))}
|
|
883
840
|
|
|
884
841
|
{
|
|
885
|
-
//
|
|
842
|
+
// 如果禁用默认语言环境的前缀,则直接在根路径渲染子组件
|
|
886
843
|
!middleware.prefixDefault && (
|
|
887
844
|
<Route
|
|
888
845
|
path="*"
|
|
@@ -923,7 +880,7 @@ const AppLocalized = ({ children, locale }) => {
|
|
|
923
880
|
// 确定当前的语言环境,如果未提供则使用默认语言环境
|
|
924
881
|
const currentLocale = locale ?? defaultLocale;
|
|
925
882
|
|
|
926
|
-
//
|
|
883
|
+
// 移除路径中的语言环境前缀以构建基础路径
|
|
927
884
|
const pathWithoutLocale = getPathWithoutLocale(
|
|
928
885
|
pathname // 当前的 URL 路径
|
|
929
886
|
);
|
|
@@ -934,7 +891,7 @@ const AppLocalized = ({ children, locale }) => {
|
|
|
934
891
|
if (middleware.prefixDefault) {
|
|
935
892
|
// 验证语言环境
|
|
936
893
|
if (!locale || !locales.includes(locale)) {
|
|
937
|
-
//
|
|
894
|
+
// 重定向到带有默认语言环境的更新路径
|
|
938
895
|
return (
|
|
939
896
|
<Navigate
|
|
940
897
|
to={`/${defaultLocale}/${pathWithoutLocale}${search}`}
|
|
@@ -960,7 +917,7 @@ const AppLocalized = ({ children, locale }) => {
|
|
|
960
917
|
)
|
|
961
918
|
.includes(currentLocale) // 检查当前语言环境是否在有效语言环境列表中
|
|
962
919
|
) {
|
|
963
|
-
//
|
|
920
|
+
// 重定向到不带语言前缀的路径
|
|
964
921
|
return <Navigate to={`${pathWithoutLocale}${search}`} replace />;
|
|
965
922
|
}
|
|
966
923
|
|
|
@@ -987,7 +944,7 @@ const LocaleRouter = ({ children }) => (
|
|
|
987
944
|
// 路由模式用于捕获语言环境(例如 /en/,/fr/)并匹配所有后续路径
|
|
988
945
|
path={`/${locale}/*`}
|
|
989
946
|
key={locale}
|
|
990
|
-
element={<AppLocalized locale={locale}>{children}</AppLocalized>} //
|
|
947
|
+
element={<AppLocalized locale={locale}>{children}</AppLocalized>} // 使用本地化管理包装子组件
|
|
991
948
|
/>
|
|
992
949
|
))}
|
|
993
950
|
|
|
@@ -998,7 +955,7 @@ const LocaleRouter = ({ children }) => (
|
|
|
998
955
|
path="*"
|
|
999
956
|
element={
|
|
1000
957
|
<AppLocalized locale={defaultLocale}>{children}</AppLocalized>
|
|
1001
|
-
} //
|
|
958
|
+
} // 使用本地化管理包装子组件
|
|
1002
959
|
/>
|
|
1003
960
|
)
|
|
1004
961
|
}
|
|
@@ -1046,7 +1003,7 @@ const App = () => (
|
|
|
1046
1003
|
);
|
|
1047
1004
|
```
|
|
1048
1005
|
|
|
1049
|
-
同时,您还可以使用 `intLayerMiddlewarePlugin` 为您的应用程序添加服务器端路由。该插件将根据 URL 自动检测当前语言环境并设置相应的语言环境 Cookie
|
|
1006
|
+
同时,您还可以使用 `intLayerMiddlewarePlugin` 为您的应用程序添加服务器端路由。该插件将根据 URL 自动检测当前语言环境并设置相应的语言环境 Cookie。如果未指定语言环境,插件将根据用户浏览器的语言偏好确定最合适的语言环境。如果未检测到任何语言环境,它将重定向到默认语言环境。
|
|
1050
1007
|
|
|
1051
1008
|
```typescript {3,7} fileName="vite.config.ts" codeFormat="typescript"
|
|
1052
1009
|
import { defineConfig } from "vite";
|
|
@@ -1081,9 +1038,9 @@ module.exports = defineConfig({
|
|
|
1081
1038
|
});
|
|
1082
1039
|
```
|
|
1083
1040
|
|
|
1084
|
-
### (可选)步骤 8
|
|
1041
|
+
### (可选)步骤 8:在语言切换时更改 URL
|
|
1085
1042
|
|
|
1086
|
-
|
|
1043
|
+
要在语言切换时更改 URL,可以使用 `useLocale` 钩子提供的 `onLocaleChange` 属性。同时,可以使用 `react-router-dom` 中的 `useLocation` 和 `useNavigate` 钩子来更新 URL 路径。
|
|
1087
1044
|
|
|
1088
1045
|
```tsx fileName="src/components/LocaleSwitcher.tsx" codeFormat="typescript"
|
|
1089
1046
|
import { useLocation, useNavigate } from "react-router-dom";
|
|
@@ -1102,7 +1059,7 @@ const LocaleSwitcher: FC = () => {
|
|
|
1102
1059
|
|
|
1103
1060
|
const { locale, availableLocales, setLocale } = useLocale({
|
|
1104
1061
|
onLocaleChange: (locale) => {
|
|
1105
|
-
//
|
|
1062
|
+
// 构建带有更新后语言环境的 URL
|
|
1106
1063
|
// 例如: /es/about?foo=bar
|
|
1107
1064
|
const pathWithLocale = getLocalizedUrl(`${pathname}${search}`, locale);
|
|
1108
1065
|
|
|
@@ -1131,15 +1088,15 @@ const LocaleSwitcher: FC = () => {
|
|
|
1131
1088
|
{localeItem}
|
|
1132
1089
|
</span>
|
|
1133
1090
|
<span>
|
|
1134
|
-
{/*
|
|
1091
|
+
{/* 该语言环境中的语言名称 - 例如 Français */}
|
|
1135
1092
|
{getLocaleName(localeItem, locale)}
|
|
1136
1093
|
</span>
|
|
1137
1094
|
<span dir={getHTMLTextDir(localeItem)} lang={localeItem}>
|
|
1138
|
-
{/*
|
|
1095
|
+
{/* 当前语言环境中的语言名称 - 例如当当前语言环境设置为 Locales.SPANISH 时显示 Francés */}
|
|
1139
1096
|
{getLocaleName(localeItem)}
|
|
1140
1097
|
</span>
|
|
1141
1098
|
<span dir="ltr" lang={Locales.ENGLISH}>
|
|
1142
|
-
{/*
|
|
1099
|
+
{/* 英文中的语言名称 - 例如 French */}
|
|
1143
1100
|
{getLocaleName(localeItem, Locales.ENGLISH)}
|
|
1144
1101
|
</span>
|
|
1145
1102
|
</a>
|
|
@@ -1195,11 +1152,11 @@ const LocaleSwitcher = () => {
|
|
|
1195
1152
|
{localeItem}
|
|
1196
1153
|
</span>
|
|
1197
1154
|
<span>
|
|
1198
|
-
{/*
|
|
1155
|
+
{/* 语言在其自身的语言环境中 - 例如 Français */}
|
|
1199
1156
|
{getLocaleName(localeItem, locale)}
|
|
1200
1157
|
</span>
|
|
1201
1158
|
<span dir={getHTMLTextDir(localeItem)} lang={localeItem}>
|
|
1202
|
-
{/* 当前语言环境中的语言 -
|
|
1159
|
+
{/* 当前语言环境中的语言 - 例如当前语言环境设为 Locales.SPANISH 时显示 Francés */}
|
|
1203
1160
|
{getLocaleName(localeItem)}
|
|
1204
1161
|
</span>
|
|
1205
1162
|
<span dir="ltr" lang={Locales.ENGLISH}>
|
|
@@ -1230,7 +1187,7 @@ const LocaleSwitcher = () => {
|
|
|
1230
1187
|
|
|
1231
1188
|
const { locale, availableLocales, setLocale } = useLocale({
|
|
1232
1189
|
onLocaleChange: (locale) => {
|
|
1233
|
-
//
|
|
1190
|
+
// 构建带有更新后的语言环境的 URL
|
|
1234
1191
|
// 例如:/es/about?foo=bar
|
|
1235
1192
|
const pathWithLocale = getLocalizedUrl(`${pathname}${search}`, locale);
|
|
1236
1193
|
|
|
@@ -1259,15 +1216,15 @@ const LocaleSwitcher = () => {
|
|
|
1259
1216
|
{localeItem}
|
|
1260
1217
|
</span>
|
|
1261
1218
|
<span>
|
|
1262
|
-
{/*
|
|
1219
|
+
{/* 语言以其自身语言环境显示 - 例如 Français */}
|
|
1263
1220
|
{getLocaleName(localeItem, locale)}
|
|
1264
1221
|
</span>
|
|
1265
1222
|
<span dir={getHTMLTextDir(localeItem)} lang={localeItem}>
|
|
1266
|
-
{/*
|
|
1223
|
+
{/* 语言以当前语言环境显示 - 例如当前语言环境为 Locales.SPANISH 时显示 Francés */}
|
|
1267
1224
|
{getLocaleName(localeItem)}
|
|
1268
1225
|
</span>
|
|
1269
1226
|
<span dir="ltr" lang={Locales.ENGLISH}>
|
|
1270
|
-
{/*
|
|
1227
|
+
{/* 语言的英文名称 - 例如 French */}
|
|
1271
1228
|
{getLocaleName(localeItem, Locales.ENGLISH)}
|
|
1272
1229
|
</span>
|
|
1273
1230
|
</a>
|
|
@@ -1289,16 +1246,16 @@ const LocaleSwitcher = () => {
|
|
|
1289
1246
|
> - [`dir` 属性](https://developer.mozilla.org/zh-CN/docs/Web/HTML/Global_attributes/dir)
|
|
1290
1247
|
> - [`aria-current` 属性](https://developer.mozilla.org/zh-CN/docs/Web/Accessibility/ARIA/Attributes/aria-current)
|
|
1291
1248
|
|
|
1292
|
-
|
|
1249
|
+
以下是更新后的**步骤9**,增加了解释并优化了代码示例:
|
|
1293
1250
|
|
|
1294
1251
|
---
|
|
1295
1252
|
|
|
1296
|
-
###
|
|
1253
|
+
### (可选)步骤9:切换HTML的语言和方向属性
|
|
1297
1254
|
|
|
1298
|
-
当您的应用程序支持多语言时,更新 `<html>` 标签的 `lang` 和 `dir`
|
|
1255
|
+
当您的应用程序支持多语言时,更新 `<html>` 标签的 `lang` 和 `dir` 属性以匹配当前语言环境非常重要。这样做可以确保:
|
|
1299
1256
|
|
|
1300
1257
|
- **无障碍访问**:屏幕阅读器和辅助技术依赖正确的 `lang` 属性来准确发音和解释内容。
|
|
1301
|
-
- **文本渲染**:`dir
|
|
1258
|
+
- **文本渲染**:`dir`(方向)属性确保文本以正确的顺序呈现(例如,英语为从左到右,阿拉伯语或希伯来语为从右到左),这对于可读性至关重要。
|
|
1302
1259
|
- **搜索引擎优化(SEO)**:搜索引擎使用 `lang` 属性来确定页面的语言,有助于在搜索结果中提供正确的本地化内容。
|
|
1303
1260
|
|
|
1304
1261
|
通过在语言环境更改时动态更新这些属性,您可以确保所有支持语言的用户都能获得一致且无障碍的体验。
|
|
@@ -1323,7 +1280,7 @@ export const useI18nHTMLAttributes = () => {
|
|
|
1323
1280
|
const { locale } = useLocale();
|
|
1324
1281
|
|
|
1325
1282
|
useEffect(() => {
|
|
1326
|
-
//
|
|
1283
|
+
// 将语言属性更新为当前语言环境。
|
|
1327
1284
|
document.documentElement.lang = locale;
|
|
1328
1285
|
|
|
1329
1286
|
// 根据当前语言环境设置文本方向。
|
|
@@ -1339,16 +1296,16 @@ import { getHTMLTextDir } from "intlayer";
|
|
|
1339
1296
|
|
|
1340
1297
|
/**
|
|
1341
1298
|
* 根据当前语言环境更新 HTML <html> 元素的 `lang` 和 `dir` 属性。
|
|
1342
|
-
* - `lang
|
|
1343
|
-
* - `dir
|
|
1299
|
+
* - `lang`:通知浏览器和搜索引擎页面的语言。
|
|
1300
|
+
* - `dir`:确保正确的阅读顺序(例如,英文为 'ltr',阿拉伯文为 'rtl')。
|
|
1344
1301
|
*
|
|
1345
|
-
* 此动态更新对于正确的文本渲染、无障碍访问和
|
|
1302
|
+
* 此动态更新对于正确的文本渲染、无障碍访问和SEO至关重要。
|
|
1346
1303
|
*/
|
|
1347
1304
|
export const useI18nHTMLAttributes = () => {
|
|
1348
1305
|
const { locale } = useLocale();
|
|
1349
1306
|
|
|
1350
1307
|
useEffect(() => {
|
|
1351
|
-
//
|
|
1308
|
+
// 将语言属性更新为当前的语言环境。
|
|
1352
1309
|
document.documentElement.lang = locale;
|
|
1353
1310
|
|
|
1354
1311
|
// 根据当前语言环境设置文本方向。
|
|
@@ -1365,7 +1322,7 @@ const { getHTMLTextDir } = require("intlayer");
|
|
|
1365
1322
|
/**
|
|
1366
1323
|
* 根据当前语言环境更新 HTML <html> 元素的 `lang` 和 `dir` 属性。
|
|
1367
1324
|
* - `lang`:告知浏览器和搜索引擎页面的语言。
|
|
1368
|
-
* - `dir
|
|
1325
|
+
* - `dir`:确保正确的阅读顺序(例如,英文为 'ltr',阿拉伯文为 'rtl')。
|
|
1369
1326
|
*
|
|
1370
1327
|
* 这种动态更新对于正确的文本渲染、无障碍访问和 SEO 至关重要。
|
|
1371
1328
|
*/
|
|
@@ -1395,10 +1352,36 @@ import { useI18nHTMLAttributes } from "./hooks/useI18nHTMLAttributes";
|
|
|
1395
1352
|
import "./App.css";
|
|
1396
1353
|
|
|
1397
1354
|
const AppContent: FC = () => {
|
|
1398
|
-
//
|
|
1355
|
+
// 应用该 Hook,根据当前语言环境更新 <html> 标签的 lang 和 dir 属性。
|
|
1399
1356
|
useI18nHTMLAttributes();
|
|
1400
1357
|
|
|
1401
|
-
// ...
|
|
1358
|
+
// ... 组件的其余部分
|
|
1359
|
+
};
|
|
1360
|
+
|
|
1361
|
+
const App: FC = () => (
|
|
1362
|
+
<IntlayerProvider>
|
|
1363
|
+
<AppContent />
|
|
1364
|
+
</IntlayerProvider>
|
|
1365
|
+
);
|
|
1366
|
+
|
|
1367
|
+
export default App;
|
|
1368
|
+
```
|
|
1369
|
+
|
|
1370
|
+
#### 在您的应用程序中使用 Hook
|
|
1371
|
+
|
|
1372
|
+
将该 Hook 集成到您的主组件中,以便在语言环境更改时更新 HTML 属性:
|
|
1373
|
+
|
|
1374
|
+
```tsx fileName="src/App.tsx" codeFormat="typescript"
|
|
1375
|
+
import type { FC } from "react";
|
|
1376
|
+
import { IntlayerProvider, useIntlayer } from "react-intlayer";
|
|
1377
|
+
import { useI18nHTMLAttributes } from "./hooks/useI18nHTMLAttributes";
|
|
1378
|
+
import "./App.css";
|
|
1379
|
+
|
|
1380
|
+
const AppContent: FC = () => {
|
|
1381
|
+
// 应用该 Hook,根据语言环境更新 <html> 标签的 lang 和 dir 属性。
|
|
1382
|
+
useI18nHTMLAttributes();
|
|
1383
|
+
|
|
1384
|
+
// ... 组件的其余部分
|
|
1402
1385
|
};
|
|
1403
1386
|
|
|
1404
1387
|
const App: FC = () => (
|
|
@@ -1416,7 +1399,7 @@ import { useI18nHTMLAttributes } from "./hooks/useI18nHTMLAttributes";
|
|
|
1416
1399
|
import "./App.css";
|
|
1417
1400
|
|
|
1418
1401
|
const AppContent = () => {
|
|
1419
|
-
//
|
|
1402
|
+
// 应用该 Hook,根据语言环境更新 <html> 标签的 lang 和 dir 属性。
|
|
1420
1403
|
useI18nHTMLAttributes();
|
|
1421
1404
|
|
|
1422
1405
|
// ... 组件的其余部分
|
|
@@ -1438,7 +1421,7 @@ const { useI18nHTMLAttributes } = require("./hooks/useI18nHTMLAttributes");
|
|
|
1438
1421
|
require("./App.css");
|
|
1439
1422
|
|
|
1440
1423
|
const AppContent = () => {
|
|
1441
|
-
//
|
|
1424
|
+
// 应用该 Hook,根据语言环境更新 <html> 标签的 lang 和 dir 属性。
|
|
1442
1425
|
useI18nHTMLAttributes();
|
|
1443
1426
|
|
|
1444
1427
|
// ... 组件的其余部分
|
|
@@ -1453,14 +1436,15 @@ const App = () => (
|
|
|
1453
1436
|
module.exports = App;
|
|
1454
1437
|
```
|
|
1455
1438
|
|
|
1456
|
-
|
|
1439
|
+
通过应用这些更改,您的应用程序将:
|
|
1457
1440
|
|
|
1458
1441
|
- 确保 **语言** (`lang`) 属性正确反映当前语言环境,这对 SEO 和浏览器行为非常重要。
|
|
1459
|
-
- 根据语言环境调整 **文本方向** (`dir`)
|
|
1442
|
+
- 根据语言环境调整 **文本方向** (`dir`),提升对不同阅读顺序语言的可读性和可用性。
|
|
1460
1443
|
- 提供更 **无障碍** 的体验,因为辅助技术依赖这些属性以实现最佳功能。
|
|
1461
1444
|
|
|
1462
1445
|
### (可选)步骤 10:创建本地化链接组件
|
|
1463
1446
|
|
|
1447
|
+
```tsx fileName="src/App.tsx" codeFormat="typescript"
|
|
1464
1448
|
// 应用该钩子以根据当前语言环境更新 <html> 标签的 lang 和 dir 属性。
|
|
1465
1449
|
useI18nHTMLAttributes();
|
|
1466
1450
|
|
|
@@ -1475,25 +1459,25 @@ const App = () => (
|
|
|
1475
1459
|
|
|
1476
1460
|
module.exports = App;
|
|
1477
1461
|
|
|
1478
|
-
|
|
1462
|
+
```
|
|
1479
1463
|
|
|
1480
|
-
|
|
1464
|
+
通过应用这些更改,您的应用将能够:
|
|
1481
1465
|
|
|
1482
|
-
- 确保 **语言** (`lang`)
|
|
1483
|
-
- 根据语言环境调整 **文本方向** (`dir`)
|
|
1484
|
-
- 提供更好的 **无障碍**
|
|
1466
|
+
- 确保 **语言** (`lang`) 属性正确反映当前的语言环境,这对于 SEO 和浏览器行为非常重要。
|
|
1467
|
+
- 根据语言环境调整 **文本方向** (`dir`),提升不同阅读顺序语言的可读性和可用性。
|
|
1468
|
+
- 提供更好的 **无障碍** 体验,因为辅助技术依赖这些属性来实现最佳功能。
|
|
1485
1469
|
|
|
1486
1470
|
### (可选)步骤 10:创建本地化链接组件
|
|
1487
1471
|
|
|
1488
|
-
|
|
1472
|
+
为了确保您的应用程序的导航尊重当前的语言环境,您可以创建一个自定义的 `Link` 组件。该组件会自动为内部 URL 添加当前语言的前缀。例如,当讲法语的用户点击“关于”页面的链接时,他们会被重定向到 `/fr/about`,而不是 `/about`。
|
|
1489
1473
|
|
|
1490
1474
|
这种行为有几个好处:
|
|
1491
1475
|
|
|
1492
1476
|
- **SEO 和用户体验**:本地化的 URL 有助于搜索引擎正确索引特定语言的页面,并为用户提供其偏好的语言内容。
|
|
1493
|
-
-
|
|
1477
|
+
- **一致性**:通过在整个应用中使用本地化链接,您可以确保导航保持在当前语言环境内,防止意外的语言切换。
|
|
1494
1478
|
- **可维护性**:将本地化逻辑集中在单个组件中简化了 URL 的管理,使您的代码库更易于维护和扩展,随着应用程序的增长。
|
|
1495
1479
|
|
|
1496
|
-
|
|
1480
|
+
下面是一个使用 TypeScript 实现的本地化 `Link` 组件示例:
|
|
1497
1481
|
|
|
1498
1482
|
```tsx fileName="src/components/Link.tsx" codeFormat="typescript"
|
|
1499
1483
|
import { getLocalizedUrl } from "intlayer";
|
|
@@ -1518,16 +1502,16 @@ export const checkIsExternalLink = (href?: string): boolean =>
|
|
|
1518
1502
|
/^https?:\/\//.test(href ?? "");
|
|
1519
1503
|
|
|
1520
1504
|
/**
|
|
1521
|
-
* 一个自定义的 Link
|
|
1522
|
-
*
|
|
1523
|
-
*
|
|
1505
|
+
* 一个自定义的 Link 组件,根据当前语言环境动态调整 href 属性。
|
|
1506
|
+
* 对于内部链接,使用 `getLocalizedUrl` 在 URL 前添加语言前缀(例如 /fr/about)。
|
|
1507
|
+
* 这样可以确保导航保持在相同的语言环境上下文中。
|
|
1524
1508
|
*/
|
|
1525
1509
|
export const Link = forwardRef<HTMLAnchorElement, LinkProps>(
|
|
1526
1510
|
({ href, children, ...props }, ref) => {
|
|
1527
1511
|
const { locale } = useLocale();
|
|
1528
1512
|
const isExternalLink = checkIsExternalLink(href);
|
|
1529
1513
|
|
|
1530
|
-
//
|
|
1514
|
+
// 如果链接是内部链接且 href 有效,则获取本地化的 URL。
|
|
1531
1515
|
const hrefI18n =
|
|
1532
1516
|
href && !isExternalLink ? getLocalizedUrl(href, locale) : href;
|
|
1533
1517
|
|
|
@@ -1540,7 +1524,7 @@ export const Link = forwardRef<HTMLAnchorElement, LinkProps>(
|
|
|
1540
1524
|
);
|
|
1541
1525
|
|
|
1542
1526
|
Link.displayName = "Link";
|
|
1543
|
-
|
|
1527
|
+
```
|
|
1544
1528
|
|
|
1545
1529
|
```jsx fileName="src/components/Link.mjx" codeFormat="esm"
|
|
1546
1530
|
import { getLocalizedUrl } from "intlayer";
|
|
@@ -1548,16 +1532,16 @@ import { useLocale } from "react-intlayer";
|
|
|
1548
1532
|
import { forwardRef } from "react";
|
|
1549
1533
|
|
|
1550
1534
|
/**
|
|
1551
|
-
*
|
|
1552
|
-
* 如果 URL 以 http:// 或 https://
|
|
1535
|
+
* 工具函数,用于检查给定的 URL 是否为外部链接。
|
|
1536
|
+
* 如果 URL 以 http:// 或 https:// 开头,则视为外部链接。
|
|
1553
1537
|
*/
|
|
1554
1538
|
export const checkIsExternalLink = (href?: string): boolean =>
|
|
1555
1539
|
/^https?:\/\//.test(href ?? "");
|
|
1556
1540
|
|
|
1557
1541
|
/**
|
|
1558
|
-
* 一个自定义的 Link
|
|
1559
|
-
*
|
|
1560
|
-
*
|
|
1542
|
+
* 一个自定义的 Link 组件,根据当前语言环境动态调整 href 属性。
|
|
1543
|
+
* 对于内部链接,使用 `getLocalizedUrl` 在 URL 前加上语言环境前缀(例如 /fr/about)。
|
|
1544
|
+
* 这样可以确保导航保持在相同的语言环境上下文中。
|
|
1561
1545
|
*/
|
|
1562
1546
|
export const Link = forwardRef(({ href, children, ...props }, ref) => {
|
|
1563
1547
|
const { locale } = useLocale();
|
|
@@ -1589,7 +1573,7 @@ const { forwardRef } = require("react");
|
|
|
1589
1573
|
const checkIsExternalLink = (href) => /^https?:\/\//.test(href ?? "");
|
|
1590
1574
|
|
|
1591
1575
|
/**
|
|
1592
|
-
* 一个自定义的 Link
|
|
1576
|
+
* 一个自定义的 Link 组件,根据当前语言环境动态调整 href 属性。
|
|
1593
1577
|
* 对于内部链接,使用 `getLocalizedUrl` 在 URL 前添加语言前缀(例如 /fr/about)。
|
|
1594
1578
|
* 这样可以确保导航保持在相同的语言环境上下文中。
|
|
1595
1579
|
*/
|
|
@@ -1597,7 +1581,7 @@ const Link = forwardRef(({ href, children, ...props }, ref) => {
|
|
|
1597
1581
|
const { locale } = useLocale();
|
|
1598
1582
|
const isExternalLink = checkIsExternalLink(href);
|
|
1599
1583
|
|
|
1600
|
-
//
|
|
1584
|
+
// 如果链接是内部链接且 href 有效,则获取本地化的 URL。
|
|
1601
1585
|
const localizedHref = isExternalLink ? href : getLocalizedUrl(href, locale);
|
|
1602
1586
|
|
|
1603
1587
|
return (
|
|
@@ -1624,12 +1608,12 @@ Link.displayName = "Link";
|
|
|
1624
1608
|
`useLocale` 钩子提供当前的语言环境(例如,法语为 `fr`)。
|
|
1625
1609
|
|
|
1626
1610
|
- **本地化 URL**:
|
|
1627
|
-
对于内部链接(即非外部链接),使用 `getLocalizedUrl` 自动为 URL
|
|
1611
|
+
对于内部链接(即非外部链接),使用 `getLocalizedUrl` 自动为 URL 添加当前语言环境前缀。这意味着如果用户使用的是法语,传入的 `/about` 会被转换为 `/fr/about`。
|
|
1628
1612
|
|
|
1629
1613
|
- **返回链接**:
|
|
1630
1614
|
该组件返回一个带有本地化 URL 的 `<a>` 元素,确保导航与当前语言环境保持一致。
|
|
1631
1615
|
|
|
1632
|
-
通过在整个应用中集成此 `Link`
|
|
1616
|
+
通过在整个应用中集成此 `Link` 组件,您可以维护一致且具语言感知的用户体验,同时提升 SEO 和可用性。
|
|
1633
1617
|
|
|
1634
1618
|
### 配置 TypeScript
|
|
1635
1619
|
|
|
@@ -1641,24 +1625,6 @@ Intlayer 使用模块增强(module augmentation)来利用 TypeScript 的优
|
|
|
1641
1625
|
|
|
1642
1626
|
确保您的 TypeScript 配置包含自动生成的类型。
|
|
1643
1627
|
|
|
1644
|
-
````json5 fileName="tsconfig.json"
|
|
1645
|
-
{
|
|
1646
|
-
// ... 您现有的 TypeScript 配置
|
|
1647
|
-
"include": [
|
|
1648
|
-
该组件返回一个带有本地化 URL 的 `<a>` 元素,确保导航与当前语言环境保持一致。
|
|
1649
|
-
|
|
1650
|
-
通过在整个应用中集成此 `Link` 组件,您可以保持一致且具语言感知的用户体验,同时还能提升 SEO 和可用性。
|
|
1651
|
-
|
|
1652
|
-
### 配置 TypeScript
|
|
1653
|
-
|
|
1654
|
-
Intlayer 使用模块扩展来利用 TypeScript 的优势,使您的代码库更健壮。
|
|
1655
|
-
|
|
1656
|
-

|
|
1657
|
-
|
|
1658
|
-

|
|
1659
|
-
|
|
1660
|
-
确保您的 TypeScript 配置包含自动生成的类型。
|
|
1661
|
-
|
|
1662
1628
|
```json5 fileName="tsconfig.json"
|
|
1663
1629
|
{
|
|
1664
1630
|
// ... 您现有的 TypeScript 配置
|
|
@@ -1667,13 +1633,13 @@ Intlayer 使用模块扩展来利用 TypeScript 的优势,使您的代码库
|
|
|
1667
1633
|
".intlayer/**/*.ts", // 包含自动生成的类型
|
|
1668
1634
|
],
|
|
1669
1635
|
}
|
|
1670
|
-
|
|
1636
|
+
```
|
|
1671
1637
|
|
|
1672
1638
|
### Git 配置
|
|
1673
1639
|
|
|
1674
|
-
建议忽略 Intlayer 生成的文件,这样可以避免将它们提交到您的 Git
|
|
1640
|
+
建议忽略 Intlayer 生成的文件,这样可以避免将它们提交到您的 Git 仓库中。
|
|
1675
1641
|
|
|
1676
|
-
为此,您可以在 `.gitignore`
|
|
1642
|
+
为此,您可以在 `.gitignore` 文件中添加以下指令:
|
|
1677
1643
|
|
|
1678
1644
|
```plaintext
|
|
1679
1645
|
# 忽略 Intlayer 生成的文件
|
|
@@ -1688,9 +1654,9 @@ Intlayer 使用模块扩展来利用 TypeScript 的优势,使您的代码库
|
|
|
1688
1654
|
|
|
1689
1655
|
该扩展提供:
|
|
1690
1656
|
|
|
1691
|
-
-
|
|
1657
|
+
- **翻译键的自动补全**。
|
|
1692
1658
|
- **实时错误检测**,用于缺失的翻译。
|
|
1693
|
-
-
|
|
1659
|
+
- **内联预览**已翻译的内容。
|
|
1694
1660
|
- **快速操作**,轻松创建和更新翻译。
|
|
1695
1661
|
|
|
1696
1662
|
有关如何使用该扩展的更多详细信息,请参阅[Intlayer VS Code 扩展文档](https://intlayer.org/doc/vs-code-extension)。
|
|
@@ -1699,7 +1665,7 @@ Intlayer 使用模块扩展来利用 TypeScript 的优势,使您的代码库
|
|
|
1699
1665
|
|
|
1700
1666
|
### 深入了解
|
|
1701
1667
|
|
|
1702
|
-
要进一步使用,您可以实现[可视化编辑器](https://github.com/aymericzip/intlayer/blob/main/docs/docs/zh/intlayer_visual_editor.md)或使用[内容管理系统(CMS)](https://github.com/aymericzip/intlayer/blob/main/docs/docs/zh/intlayer_CMS.md)
|
|
1668
|
+
要进一步使用,您可以实现[可视化编辑器](https://github.com/aymericzip/intlayer/blob/main/docs/docs/zh/intlayer_visual_editor.md)或使用[内容管理系统(CMS)](https://github.com/aymericzip/intlayer/blob/main/docs/docs/zh/intlayer_CMS.md)将内容外部化。
|
|
1703
1669
|
|
|
1704
1670
|
---
|
|
1705
1671
|
|