@intlayer/docs 5.5.11 → 5.5.12
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 +3 -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_with_vite+react.md +100 -108
- package/docs/de/intlayer_with_vite+react.md +121 -142
- package/docs/en/CI_CD.md +3 -1
- package/docs/en/autoFill.md +3 -1
- package/docs/en/configuration.md +4 -1
- 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 +3 -1
- package/docs/en/intlayer_cli.md +3 -1
- package/docs/en/intlayer_visual_editor.md +3 -1
- package/docs/en/intlayer_with_angular.md +3 -1
- package/docs/en/intlayer_with_create_react_app.md +3 -1
- package/docs/en/intlayer_with_express.md +3 -1
- package/docs/en/intlayer_with_lynx+react.md +3 -1
- package/docs/en/intlayer_with_nextjs_14.md +6 -1
- package/docs/en/intlayer_with_nextjs_15.md +5 -1
- package/docs/en/intlayer_with_nextjs_page_router.md +5 -1
- package/docs/en/intlayer_with_nuxt.md +3 -1
- package/docs/en/intlayer_with_react_native+expo.md +3 -1
- package/docs/en/intlayer_with_vite+preact.md +3 -1
- package/docs/en/intlayer_with_vite+react.md +9 -7
- package/docs/en/intlayer_with_vite+solid.md +3 -1
- package/docs/en/intlayer_with_vite+svelte.md +3 -1
- package/docs/en/intlayer_with_vite+vue.md +3 -1
- package/docs/en/introduction.md +3 -1
- package/docs/en/mcp_server.md +42 -1
- 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_with_vite+react.md +64 -83
- package/docs/es/intlayer_with_vite+react.md +91 -94
- package/docs/fr/intlayer_with_vite+react.md +73 -65
- package/docs/hi/intlayer_with_vite+react.md +107 -107
- package/docs/it/intlayer_with_vite+react.md +156 -112
- package/docs/ja/intlayer_with_vite+react.md +153 -218
- package/docs/ko/intlayer_with_vite+react.md +116 -148
- package/docs/ko/packages/intlayer/getLocalizedUrl.md +1 -23
- package/docs/pt/intlayer_with_vite+react.md +110 -132
- package/docs/ru/intlayer_with_vite+react.md +98 -83
- package/docs/zh/intlayer_with_vite+react.md +147 -184
- 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 +7 -6
- package/src/blog.ts +6 -4
- package/src/common.ts +23 -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,35 @@
|
|
|
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
|
-
-
|
|
17
|
+
- vite-and-react
|
|
18
18
|
---
|
|
19
19
|
|
|
20
|
-
# 使用 Intlayer
|
|
20
|
+
# 使用 Intlayer 结合 Vite 和 React 开始国际化 (i18n)
|
|
21
21
|
|
|
22
22
|
请参阅 GitHub 上的[应用模板](https://github.com/aymericzip/intlayer-vite-react-template)。
|
|
23
23
|
|
|
24
24
|
## 什么是 Intlayer?
|
|
25
25
|
|
|
26
|
-
**Intlayer**
|
|
26
|
+
**Intlayer** 是一个创新的开源国际化 (i18n) 库,旨在简化现代 Web 应用的多语言支持。
|
|
27
27
|
|
|
28
28
|
使用 Intlayer,您可以:
|
|
29
29
|
|
|
30
|
-
-
|
|
31
|
-
-
|
|
32
|
-
-
|
|
30
|
+
- **轻松管理翻译**,使用组件级别的声明式字典。
|
|
31
|
+
- **动态本地化元数据**、路由和内容。
|
|
32
|
+
- **确保 TypeScript 支持**,通过自动生成的类型提升自动补全和错误检测。
|
|
33
33
|
- **享受高级功能**,如动态语言环境检测和切换。
|
|
34
34
|
|
|
35
35
|
---
|
|
@@ -57,17 +57,17 @@ yarn add --save-dev vite-intlayer
|
|
|
57
57
|
|
|
58
58
|
- **intlayer**
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
核心包,提供用于配置管理、翻译、[内容声明](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
61
|
|
|
62
62
|
- **react-intlayer**
|
|
63
|
-
将 Intlayer 集成到 React
|
|
63
|
+
将 Intlayer 集成到 React 应用中的包。它提供了用于 React 国际化的上下文提供者和钩子。
|
|
64
64
|
|
|
65
65
|
- **vite-intlayer**
|
|
66
|
-
|
|
66
|
+
包含用于将 Intlayer 集成到[Vite 打包工具](https://vite.dev/guide/why.html#why-bundle-for-production)的 Vite 插件,以及用于检测用户首选语言环境、管理 Cookie 和处理 URL 重定向的中间件。
|
|
67
67
|
|
|
68
|
-
### 第
|
|
68
|
+
### 第2步:配置您的项目
|
|
69
69
|
|
|
70
|
-
|
|
70
|
+
创建一个配置文件来配置您应用程序的语言:
|
|
71
71
|
|
|
72
72
|
```typescript fileName="intlayer.config.ts" codeFormat="typescript"
|
|
73
73
|
import { Locales, type IntlayerConfig } from "intlayer";
|
|
@@ -78,7 +78,7 @@ const config: IntlayerConfig = {
|
|
|
78
78
|
Locales.ENGLISH,
|
|
79
79
|
Locales.FRENCH,
|
|
80
80
|
Locales.SPANISH,
|
|
81
|
-
//
|
|
81
|
+
// 您的其他语言
|
|
82
82
|
],
|
|
83
83
|
defaultLocale: Locales.ENGLISH,
|
|
84
84
|
},
|
|
@@ -91,16 +91,15 @@ export default config;
|
|
|
91
91
|
import { Locales } from "intlayer";
|
|
92
92
|
|
|
93
93
|
/** @type {import('intlayer').IntlayerConfig} */
|
|
94
|
-
// 配置对象,定义国际化设置
|
|
95
94
|
const config = {
|
|
96
95
|
internationalization: {
|
|
97
96
|
locales: [
|
|
98
|
-
Locales.ENGLISH,
|
|
99
|
-
Locales.FRENCH,
|
|
100
|
-
Locales.SPANISH,
|
|
101
|
-
//
|
|
97
|
+
Locales.ENGLISH,
|
|
98
|
+
Locales.FRENCH,
|
|
99
|
+
Locales.SPANISH,
|
|
100
|
+
// 您的其他语言
|
|
102
101
|
],
|
|
103
|
-
defaultLocale: Locales.ENGLISH,
|
|
102
|
+
defaultLocale: Locales.ENGLISH,
|
|
104
103
|
},
|
|
105
104
|
};
|
|
106
105
|
|
|
@@ -111,40 +110,22 @@ export default config;
|
|
|
111
110
|
const { Locales } = require("intlayer");
|
|
112
111
|
|
|
113
112
|
/** @type {import('intlayer').IntlayerConfig} */
|
|
114
|
-
// 配置对象,定义国际化设置
|
|
115
113
|
const config = {
|
|
116
114
|
internationalization: {
|
|
117
115
|
locales: [
|
|
118
|
-
Locales.ENGLISH,
|
|
119
|
-
Locales.FRENCH,
|
|
120
|
-
Locales.SPANISH,
|
|
116
|
+
Locales.ENGLISH,
|
|
117
|
+
Locales.FRENCH,
|
|
118
|
+
Locales.SPANISH,
|
|
121
119
|
// 你的其他语言
|
|
122
120
|
],
|
|
123
|
-
defaultLocale: Locales.ENGLISH,
|
|
121
|
+
defaultLocale: Locales.ENGLISH,
|
|
124
122
|
},
|
|
125
123
|
};
|
|
126
124
|
|
|
127
125
|
module.exports = config;
|
|
128
126
|
```
|
|
129
127
|
|
|
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)。
|
|
128
|
+
> 通过此配置文件,您可以设置本地化的 URL、中间件重定向、cookie 名称、内容声明的位置和扩展名,禁用控制台中的 Intlayer 日志等。有关可用参数的完整列表,请参阅[配置文档](https://github.com/aymericzip/intlayer/blob/main/docs/docs/zh/configuration.md)。
|
|
148
129
|
|
|
149
130
|
### 第三步:在您的 Vite 配置中集成 Intlayer
|
|
150
131
|
|
|
@@ -183,29 +164,6 @@ module.exports = defineConfig({
|
|
|
183
164
|
});
|
|
184
165
|
```
|
|
185
166
|
|
|
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
167
|
> `intlayerPlugin()` Vite 插件用于将 Intlayer 集成到 Vite 中。它确保内容声明文件的构建,并在开发模式下监视这些文件。在 Vite 应用程序中定义了 Intlayer 环境变量。此外,它还提供别名以优化性能。
|
|
210
168
|
|
|
211
169
|
### 第4步:声明您的内容
|
|
@@ -227,7 +185,7 @@ const appContent = {
|
|
|
227
185
|
reactLogo: t({
|
|
228
186
|
en: "React logo",
|
|
229
187
|
fr: "Logo React",
|
|
230
|
-
es: "React
|
|
188
|
+
es: "Logo React",
|
|
231
189
|
}),
|
|
232
190
|
|
|
233
191
|
title: "Vite + React",
|
|
@@ -262,7 +220,7 @@ const appContent = {
|
|
|
262
220
|
es: "Haga clic en los logotipos de Vite y React para obtener más información",
|
|
263
221
|
}),
|
|
264
222
|
},
|
|
265
|
-
}
|
|
223
|
+
} 满足 Dictionary;
|
|
266
224
|
|
|
267
225
|
export default appContent;
|
|
268
226
|
```
|
|
@@ -277,13 +235,11 @@ const appContent = {
|
|
|
277
235
|
viteLogo: t({
|
|
278
236
|
en: "Vite logo",
|
|
279
237
|
fr: "Logo Vite",
|
|
280
|
-
zh: "Vite 标志",
|
|
281
238
|
es: "Logo Vite",
|
|
282
239
|
}),
|
|
283
240
|
reactLogo: t({
|
|
284
241
|
en: "React logo",
|
|
285
242
|
fr: "Logo React",
|
|
286
|
-
zh: "React 标志",
|
|
287
243
|
es: "Logo React",
|
|
288
244
|
}),
|
|
289
245
|
|
|
@@ -292,7 +248,6 @@ const appContent = {
|
|
|
292
248
|
count: t({
|
|
293
249
|
en: "count is ",
|
|
294
250
|
fr: "le compte est ",
|
|
295
|
-
zh: "计数是 ",
|
|
296
251
|
es: "el recuento es ",
|
|
297
252
|
}),
|
|
298
253
|
|
|
@@ -340,13 +295,11 @@ const appContent = {
|
|
|
340
295
|
en: "Vite logo",
|
|
341
296
|
fr: "Logo Vite",
|
|
342
297
|
es: "Logo Vite",
|
|
343
|
-
zh: "Vite 标志",
|
|
344
298
|
}),
|
|
345
299
|
reactLogo: t({
|
|
346
300
|
en: "React logo",
|
|
347
301
|
fr: "Logo React",
|
|
348
302
|
es: "Logo React",
|
|
349
|
-
zh: "React 标志",
|
|
350
303
|
}),
|
|
351
304
|
|
|
352
305
|
title: "Vite + React",
|
|
@@ -355,7 +308,6 @@ const appContent = {
|
|
|
355
308
|
en: "count is ",
|
|
356
309
|
fr: "le compte est ",
|
|
357
310
|
es: "el recuento es ",
|
|
358
|
-
zh: "计数是 ",
|
|
359
311
|
}),
|
|
360
312
|
|
|
361
313
|
edit:
|
|
@@ -381,8 +333,7 @@ const appContent = {
|
|
|
381
333
|
},
|
|
382
334
|
|
|
383
335
|
readTheDocs: t({
|
|
384
|
-
|
|
385
|
-
en: "Click on the Vite and React logos to learn more",
|
|
336
|
+
en: "点击 Vite 和 React 标志以了解更多信息",
|
|
386
337
|
fr: "Cliquez sur les logos Vite et React pour en savoir plus",
|
|
387
338
|
es: "Haga clic en los logotipos de Vite y React para obtener más información",
|
|
388
339
|
}),
|
|
@@ -400,7 +351,6 @@ module.exports = appContent;
|
|
|
400
351
|
"viteLogo": {
|
|
401
352
|
"nodeType": "translation",
|
|
402
353
|
"translation": {
|
|
403
|
-
"zh": "Vite 标志",
|
|
404
354
|
"en": "Vite logo",
|
|
405
355
|
"fr": "Logo Vite",
|
|
406
356
|
"es": "Logo Vite"
|
|
@@ -427,7 +377,7 @@ module.exports = appContent;
|
|
|
427
377
|
"count": {
|
|
428
378
|
"nodeType": "translation",
|
|
429
379
|
"translation": {
|
|
430
|
-
"zh": "
|
|
380
|
+
"zh": "计数为 ",
|
|
431
381
|
"en": "count is ",
|
|
432
382
|
"fr": "le compte est ",
|
|
433
383
|
"es": "el recuento es "
|
|
@@ -445,14 +395,17 @@ module.exports = appContent;
|
|
|
445
395
|
"readTheDocs": {
|
|
446
396
|
"nodeType": "translation",
|
|
447
397
|
"translation": {
|
|
448
|
-
"zh": "点击 Vite 和 React 标志以了解更多信息"
|
|
398
|
+
"zh": "点击 Vite 和 React 标志以了解更多信息",
|
|
399
|
+
"en": "Click on the Vite and React logos to learn more",
|
|
400
|
+
"fr": "Cliquez sur les logos Vite et React pour en savoir plus",
|
|
401
|
+
"es": "Haga clic en los logotipos de Vite y React para obtener más información"
|
|
449
402
|
}
|
|
450
403
|
}
|
|
451
404
|
}
|
|
452
405
|
}
|
|
453
406
|
```
|
|
454
407
|
|
|
455
|
-
>
|
|
408
|
+
> 您的内容声明可以定义在应用程序中的任何位置,只要它们被包含在 `contentDir` 目录中(默认是 `./src`)。并且匹配内容声明文件的扩展名(默认是 `.content.{json,ts,tsx,js,jsx,mjs,mjx,cjs,cjx}`)。
|
|
456
409
|
|
|
457
410
|
> 更多详情,请参阅[内容声明文档](https://github.com/aymericzip/intlayer/blob/main/docs/docs/zh/dictionary/get_started.md)。
|
|
458
411
|
|
|
@@ -500,7 +453,7 @@ const AppContent: FC = () => {
|
|
|
500
453
|
);
|
|
501
454
|
};
|
|
502
455
|
|
|
503
|
-
const App = () => (
|
|
456
|
+
const App: FC = () => (
|
|
504
457
|
<IntlayerProvider>
|
|
505
458
|
<AppContent />
|
|
506
459
|
</IntlayerProvider>
|
|
@@ -659,7 +612,7 @@ const LocaleSwitcher = () => {
|
|
|
659
612
|
|
|
660
613
|
### (可选)步骤 7:为您的应用程序添加本地化路由
|
|
661
614
|
|
|
662
|
-
此步骤的目的是为每种语言创建唯一的路由。这对于 SEO
|
|
615
|
+
此步骤的目的是为每种语言创建唯一的路由。这对于 SEO 和 SEO 友好的 URL 非常有用。
|
|
663
616
|
示例:
|
|
664
617
|
|
|
665
618
|
```plaintext
|
|
@@ -668,7 +621,7 @@ const LocaleSwitcher = () => {
|
|
|
668
621
|
- https://example.com/fr/about
|
|
669
622
|
```
|
|
670
623
|
|
|
671
|
-
>
|
|
624
|
+
> 默认情况下,默认语言的路由不会添加前缀。如果您想为默认语言添加前缀,可以在配置中将 `middleware.prefixDefault` 选项设置为 `true`。更多信息请参见[配置文档](https://github.com/aymericzip/intlayer/blob/main/docs/docs/zh/configuration.md)。
|
|
672
625
|
|
|
673
626
|
要为您的应用添加本地化路由,您可以创建一个 `LocaleRouter` 组件,包裹应用的路由并处理基于语言的路由。以下是使用 [React Router](https://reactrouter.com/home) 的示例:
|
|
674
627
|
|
|
@@ -690,21 +643,21 @@ const { internationalization, middleware } = configuration;
|
|
|
690
643
|
const { locales, defaultLocale } = internationalization;
|
|
691
644
|
|
|
692
645
|
/**
|
|
693
|
-
*
|
|
694
|
-
* 它管理基于 URL
|
|
646
|
+
* 一个处理本地化的组件,使用适当的语言环境上下文包裹子组件。
|
|
647
|
+
* 它管理基于 URL 的语言环境检测和验证。
|
|
695
648
|
*/
|
|
696
649
|
const AppLocalized: FC<PropsWithChildren<{ locale: Locales }>> = ({
|
|
697
650
|
children,
|
|
698
651
|
locale,
|
|
699
652
|
}) => {
|
|
700
|
-
const { pathname, search } = useLocation(); // 获取当前的
|
|
653
|
+
const { pathname, search } = useLocation(); // 获取当前的URL路径
|
|
701
654
|
|
|
702
|
-
//
|
|
655
|
+
// 确定当前的语言环境,如果未提供则回退到默认语言环境
|
|
703
656
|
const currentLocale = locale ?? defaultLocale;
|
|
704
657
|
|
|
705
658
|
// 移除路径中的语言环境前缀以构建基础路径
|
|
706
659
|
const pathWithoutLocale = getPathWithoutLocale(
|
|
707
|
-
pathname // 当前的
|
|
660
|
+
pathname // 当前的URL路径
|
|
708
661
|
);
|
|
709
662
|
|
|
710
663
|
/**
|
|
@@ -722,7 +675,7 @@ const AppLocalized: FC<PropsWithChildren<{ locale: Locales }>> = ({
|
|
|
722
675
|
);
|
|
723
676
|
}
|
|
724
677
|
|
|
725
|
-
// 使用 IntlayerProvider
|
|
678
|
+
// 使用 IntlayerProvider 包裹子组件并设置当前语言环境
|
|
726
679
|
return (
|
|
727
680
|
<IntlayerProvider locale={currentLocale}>{children}</IntlayerProvider>
|
|
728
681
|
);
|
|
@@ -737,13 +690,13 @@ const AppLocalized: FC<PropsWithChildren<{ locale: Locales }>> = ({
|
|
|
737
690
|
.filter(
|
|
738
691
|
(locale) => locale.toString() !== defaultLocale.toString() // 排除默认语言环境
|
|
739
692
|
)
|
|
740
|
-
.includes(currentLocale) //
|
|
693
|
+
.includes(currentLocale) // 检查当前语言环境是否在有效语言列表中
|
|
741
694
|
) {
|
|
742
|
-
//
|
|
695
|
+
// 重定向到无语言前缀的路径
|
|
743
696
|
return <Navigate to={`${pathWithoutLocale}${search}`} replace />;
|
|
744
697
|
}
|
|
745
698
|
|
|
746
|
-
// 使用 IntlayerProvider
|
|
699
|
+
// 使用 IntlayerProvider 包裹子组件并设置当前语言环境
|
|
747
700
|
return (
|
|
748
701
|
<IntlayerProvider locale={currentLocale}>{children}</IntlayerProvider>
|
|
749
702
|
);
|
|
@@ -766,18 +719,18 @@ export const LocaleRouter: FC<PropsWithChildren> = ({ children }) => (
|
|
|
766
719
|
// 路由模式用于捕获语言环境(例如 /en/,/fr/)并匹配所有后续路径
|
|
767
720
|
path={`/${locale}/*`}
|
|
768
721
|
key={locale}
|
|
769
|
-
element={<AppLocalized locale={locale}>{children}</AppLocalized>} //
|
|
722
|
+
element={<AppLocalized locale={locale}>{children}</AppLocalized>} // 使用语言环境管理包装子组件
|
|
770
723
|
/>
|
|
771
724
|
))}
|
|
772
725
|
|
|
773
726
|
{
|
|
774
|
-
//
|
|
727
|
+
// 如果禁用默认语言环境前缀,则直接在根路径渲染子组件
|
|
775
728
|
!middleware.prefixDefault && (
|
|
776
729
|
<Route
|
|
777
730
|
path="*"
|
|
778
731
|
element={
|
|
779
732
|
<AppLocalized locale={defaultLocale}>{children}</AppLocalized>
|
|
780
|
-
} //
|
|
733
|
+
} // 使用语言环境管理包装子组件
|
|
781
734
|
/>
|
|
782
735
|
)
|
|
783
736
|
}
|
|
@@ -799,12 +752,13 @@ import {
|
|
|
799
752
|
useLocation,
|
|
800
753
|
} from "react-router-dom"; // 用于管理导航的路由组件
|
|
801
754
|
|
|
802
|
-
// 从 Intlayer
|
|
755
|
+
// 从 Intlayer 配置中解构
|
|
803
756
|
const { internationalization, middleware } = configuration;
|
|
804
757
|
const { locales, defaultLocale } = internationalization;
|
|
805
758
|
|
|
806
759
|
/**
|
|
807
|
-
*
|
|
760
|
+
* 一个处理本地化的组件,使用适当的语言环境上下文包裹子组件。
|
|
761
|
+
/**
|
|
808
762
|
* 它管理基于 URL 的语言检测和验证。
|
|
809
763
|
*/
|
|
810
764
|
const AppLocalized = ({ children, locale }) => {
|
|
@@ -813,9 +767,9 @@ const AppLocalized = ({ children, locale }) => {
|
|
|
813
767
|
// 确定当前语言,如果未提供则回退到默认语言
|
|
814
768
|
const currentLocale = locale ?? defaultLocale;
|
|
815
769
|
|
|
816
|
-
//
|
|
770
|
+
// 从路径中移除语言前缀以构造基础路径
|
|
817
771
|
const pathWithoutLocale = getPathWithoutLocale(
|
|
818
|
-
pathname //
|
|
772
|
+
pathname // 当前 URL 路径
|
|
819
773
|
);
|
|
820
774
|
|
|
821
775
|
/**
|
|
@@ -862,7 +816,7 @@ const AppLocalized = ({ children, locale }) => {
|
|
|
862
816
|
};
|
|
863
817
|
|
|
864
818
|
/**
|
|
865
|
-
*
|
|
819
|
+
* 一个设置特定语言路由的路由组件。
|
|
866
820
|
* 它使用 React Router 来管理导航并渲染本地化组件。
|
|
867
821
|
*/
|
|
868
822
|
export const LocaleRouter = ({ children }) => (
|
|
@@ -882,7 +836,7 @@ export const LocaleRouter = ({ children }) => (
|
|
|
882
836
|
))}
|
|
883
837
|
|
|
884
838
|
{
|
|
885
|
-
//
|
|
839
|
+
// 如果禁用默认语言环境的前缀,则直接在根路径渲染子组件
|
|
886
840
|
!middleware.prefixDefault && (
|
|
887
841
|
<Route
|
|
888
842
|
path="*"
|
|
@@ -923,7 +877,7 @@ const AppLocalized = ({ children, locale }) => {
|
|
|
923
877
|
// 确定当前的语言环境,如果未提供则使用默认语言环境
|
|
924
878
|
const currentLocale = locale ?? defaultLocale;
|
|
925
879
|
|
|
926
|
-
//
|
|
880
|
+
// 移除路径中的语言环境前缀以构建基础路径
|
|
927
881
|
const pathWithoutLocale = getPathWithoutLocale(
|
|
928
882
|
pathname // 当前的 URL 路径
|
|
929
883
|
);
|
|
@@ -934,7 +888,7 @@ const AppLocalized = ({ children, locale }) => {
|
|
|
934
888
|
if (middleware.prefixDefault) {
|
|
935
889
|
// 验证语言环境
|
|
936
890
|
if (!locale || !locales.includes(locale)) {
|
|
937
|
-
//
|
|
891
|
+
// 重定向到带有默认语言环境的更新路径
|
|
938
892
|
return (
|
|
939
893
|
<Navigate
|
|
940
894
|
to={`/${defaultLocale}/${pathWithoutLocale}${search}`}
|
|
@@ -960,7 +914,7 @@ const AppLocalized = ({ children, locale }) => {
|
|
|
960
914
|
)
|
|
961
915
|
.includes(currentLocale) // 检查当前语言环境是否在有效语言环境列表中
|
|
962
916
|
) {
|
|
963
|
-
//
|
|
917
|
+
// 重定向到不带语言前缀的路径
|
|
964
918
|
return <Navigate to={`${pathWithoutLocale}${search}`} replace />;
|
|
965
919
|
}
|
|
966
920
|
|
|
@@ -987,7 +941,7 @@ const LocaleRouter = ({ children }) => (
|
|
|
987
941
|
// 路由模式用于捕获语言环境(例如 /en/,/fr/)并匹配所有后续路径
|
|
988
942
|
path={`/${locale}/*`}
|
|
989
943
|
key={locale}
|
|
990
|
-
element={<AppLocalized locale={locale}>{children}</AppLocalized>} //
|
|
944
|
+
element={<AppLocalized locale={locale}>{children}</AppLocalized>} // 使用本地化管理包装子组件
|
|
991
945
|
/>
|
|
992
946
|
))}
|
|
993
947
|
|
|
@@ -998,7 +952,7 @@ const LocaleRouter = ({ children }) => (
|
|
|
998
952
|
path="*"
|
|
999
953
|
element={
|
|
1000
954
|
<AppLocalized locale={defaultLocale}>{children}</AppLocalized>
|
|
1001
|
-
} //
|
|
955
|
+
} // 使用本地化管理包装子组件
|
|
1002
956
|
/>
|
|
1003
957
|
)
|
|
1004
958
|
}
|
|
@@ -1046,7 +1000,7 @@ const App = () => (
|
|
|
1046
1000
|
);
|
|
1047
1001
|
```
|
|
1048
1002
|
|
|
1049
|
-
同时,您还可以使用 `intLayerMiddlewarePlugin` 为您的应用程序添加服务器端路由。该插件将根据 URL 自动检测当前语言环境并设置相应的语言环境 Cookie
|
|
1003
|
+
同时,您还可以使用 `intLayerMiddlewarePlugin` 为您的应用程序添加服务器端路由。该插件将根据 URL 自动检测当前语言环境并设置相应的语言环境 Cookie。如果未指定语言环境,插件将根据用户浏览器的语言偏好确定最合适的语言环境。如果未检测到任何语言环境,它将重定向到默认语言环境。
|
|
1050
1004
|
|
|
1051
1005
|
```typescript {3,7} fileName="vite.config.ts" codeFormat="typescript"
|
|
1052
1006
|
import { defineConfig } from "vite";
|
|
@@ -1081,9 +1035,9 @@ module.exports = defineConfig({
|
|
|
1081
1035
|
});
|
|
1082
1036
|
```
|
|
1083
1037
|
|
|
1084
|
-
### (可选)步骤 8
|
|
1038
|
+
### (可选)步骤 8:在语言切换时更改 URL
|
|
1085
1039
|
|
|
1086
|
-
|
|
1040
|
+
要在语言切换时更改 URL,可以使用 `useLocale` 钩子提供的 `onLocaleChange` 属性。同时,可以使用 `react-router-dom` 中的 `useLocation` 和 `useNavigate` 钩子来更新 URL 路径。
|
|
1087
1041
|
|
|
1088
1042
|
```tsx fileName="src/components/LocaleSwitcher.tsx" codeFormat="typescript"
|
|
1089
1043
|
import { useLocation, useNavigate } from "react-router-dom";
|
|
@@ -1102,7 +1056,7 @@ const LocaleSwitcher: FC = () => {
|
|
|
1102
1056
|
|
|
1103
1057
|
const { locale, availableLocales, setLocale } = useLocale({
|
|
1104
1058
|
onLocaleChange: (locale) => {
|
|
1105
|
-
//
|
|
1059
|
+
// 构建带有更新后语言环境的 URL
|
|
1106
1060
|
// 例如: /es/about?foo=bar
|
|
1107
1061
|
const pathWithLocale = getLocalizedUrl(`${pathname}${search}`, locale);
|
|
1108
1062
|
|
|
@@ -1131,15 +1085,15 @@ const LocaleSwitcher: FC = () => {
|
|
|
1131
1085
|
{localeItem}
|
|
1132
1086
|
</span>
|
|
1133
1087
|
<span>
|
|
1134
|
-
{/*
|
|
1088
|
+
{/* 该语言环境中的语言名称 - 例如 Français */}
|
|
1135
1089
|
{getLocaleName(localeItem, locale)}
|
|
1136
1090
|
</span>
|
|
1137
1091
|
<span dir={getHTMLTextDir(localeItem)} lang={localeItem}>
|
|
1138
|
-
{/*
|
|
1092
|
+
{/* 当前语言环境中的语言名称 - 例如当当前语言环境设置为 Locales.SPANISH 时显示 Francés */}
|
|
1139
1093
|
{getLocaleName(localeItem)}
|
|
1140
1094
|
</span>
|
|
1141
1095
|
<span dir="ltr" lang={Locales.ENGLISH}>
|
|
1142
|
-
{/*
|
|
1096
|
+
{/* 英文中的语言名称 - 例如 French */}
|
|
1143
1097
|
{getLocaleName(localeItem, Locales.ENGLISH)}
|
|
1144
1098
|
</span>
|
|
1145
1099
|
</a>
|
|
@@ -1195,11 +1149,11 @@ const LocaleSwitcher = () => {
|
|
|
1195
1149
|
{localeItem}
|
|
1196
1150
|
</span>
|
|
1197
1151
|
<span>
|
|
1198
|
-
{/*
|
|
1152
|
+
{/* 语言在其自身的语言环境中 - 例如 Français */}
|
|
1199
1153
|
{getLocaleName(localeItem, locale)}
|
|
1200
1154
|
</span>
|
|
1201
1155
|
<span dir={getHTMLTextDir(localeItem)} lang={localeItem}>
|
|
1202
|
-
{/* 当前语言环境中的语言 -
|
|
1156
|
+
{/* 当前语言环境中的语言 - 例如当前语言环境设为 Locales.SPANISH 时显示 Francés */}
|
|
1203
1157
|
{getLocaleName(localeItem)}
|
|
1204
1158
|
</span>
|
|
1205
1159
|
<span dir="ltr" lang={Locales.ENGLISH}>
|
|
@@ -1230,7 +1184,7 @@ const LocaleSwitcher = () => {
|
|
|
1230
1184
|
|
|
1231
1185
|
const { locale, availableLocales, setLocale } = useLocale({
|
|
1232
1186
|
onLocaleChange: (locale) => {
|
|
1233
|
-
//
|
|
1187
|
+
// 构建带有更新后的语言环境的 URL
|
|
1234
1188
|
// 例如:/es/about?foo=bar
|
|
1235
1189
|
const pathWithLocale = getLocalizedUrl(`${pathname}${search}`, locale);
|
|
1236
1190
|
|
|
@@ -1259,15 +1213,15 @@ const LocaleSwitcher = () => {
|
|
|
1259
1213
|
{localeItem}
|
|
1260
1214
|
</span>
|
|
1261
1215
|
<span>
|
|
1262
|
-
{/*
|
|
1216
|
+
{/* 语言以其自身语言环境显示 - 例如 Français */}
|
|
1263
1217
|
{getLocaleName(localeItem, locale)}
|
|
1264
1218
|
</span>
|
|
1265
1219
|
<span dir={getHTMLTextDir(localeItem)} lang={localeItem}>
|
|
1266
|
-
{/*
|
|
1220
|
+
{/* 语言以当前语言环境显示 - 例如当前语言环境为 Locales.SPANISH 时显示 Francés */}
|
|
1267
1221
|
{getLocaleName(localeItem)}
|
|
1268
1222
|
</span>
|
|
1269
1223
|
<span dir="ltr" lang={Locales.ENGLISH}>
|
|
1270
|
-
{/*
|
|
1224
|
+
{/* 语言的英文名称 - 例如 French */}
|
|
1271
1225
|
{getLocaleName(localeItem, Locales.ENGLISH)}
|
|
1272
1226
|
</span>
|
|
1273
1227
|
</a>
|
|
@@ -1289,16 +1243,16 @@ const LocaleSwitcher = () => {
|
|
|
1289
1243
|
> - [`dir` 属性](https://developer.mozilla.org/zh-CN/docs/Web/HTML/Global_attributes/dir)
|
|
1290
1244
|
> - [`aria-current` 属性](https://developer.mozilla.org/zh-CN/docs/Web/Accessibility/ARIA/Attributes/aria-current)
|
|
1291
1245
|
|
|
1292
|
-
|
|
1246
|
+
以下是更新后的**步骤9**,增加了解释并优化了代码示例:
|
|
1293
1247
|
|
|
1294
1248
|
---
|
|
1295
1249
|
|
|
1296
|
-
###
|
|
1250
|
+
### (可选)步骤9:切换HTML的语言和方向属性
|
|
1297
1251
|
|
|
1298
|
-
当您的应用程序支持多语言时,更新 `<html>` 标签的 `lang` 和 `dir`
|
|
1252
|
+
当您的应用程序支持多语言时,更新 `<html>` 标签的 `lang` 和 `dir` 属性以匹配当前语言环境非常重要。这样做可以确保:
|
|
1299
1253
|
|
|
1300
1254
|
- **无障碍访问**:屏幕阅读器和辅助技术依赖正确的 `lang` 属性来准确发音和解释内容。
|
|
1301
|
-
- **文本渲染**:`dir
|
|
1255
|
+
- **文本渲染**:`dir`(方向)属性确保文本以正确的顺序呈现(例如,英语为从左到右,阿拉伯语或希伯来语为从右到左),这对于可读性至关重要。
|
|
1302
1256
|
- **搜索引擎优化(SEO)**:搜索引擎使用 `lang` 属性来确定页面的语言,有助于在搜索结果中提供正确的本地化内容。
|
|
1303
1257
|
|
|
1304
1258
|
通过在语言环境更改时动态更新这些属性,您可以确保所有支持语言的用户都能获得一致且无障碍的体验。
|
|
@@ -1323,7 +1277,7 @@ export const useI18nHTMLAttributes = () => {
|
|
|
1323
1277
|
const { locale } = useLocale();
|
|
1324
1278
|
|
|
1325
1279
|
useEffect(() => {
|
|
1326
|
-
//
|
|
1280
|
+
// 将语言属性更新为当前语言环境。
|
|
1327
1281
|
document.documentElement.lang = locale;
|
|
1328
1282
|
|
|
1329
1283
|
// 根据当前语言环境设置文本方向。
|
|
@@ -1339,16 +1293,16 @@ import { getHTMLTextDir } from "intlayer";
|
|
|
1339
1293
|
|
|
1340
1294
|
/**
|
|
1341
1295
|
* 根据当前语言环境更新 HTML <html> 元素的 `lang` 和 `dir` 属性。
|
|
1342
|
-
* - `lang
|
|
1343
|
-
* - `dir
|
|
1296
|
+
* - `lang`:通知浏览器和搜索引擎页面的语言。
|
|
1297
|
+
* - `dir`:确保正确的阅读顺序(例如,英文为 'ltr',阿拉伯文为 'rtl')。
|
|
1344
1298
|
*
|
|
1345
|
-
* 此动态更新对于正确的文本渲染、无障碍访问和
|
|
1299
|
+
* 此动态更新对于正确的文本渲染、无障碍访问和SEO至关重要。
|
|
1346
1300
|
*/
|
|
1347
1301
|
export const useI18nHTMLAttributes = () => {
|
|
1348
1302
|
const { locale } = useLocale();
|
|
1349
1303
|
|
|
1350
1304
|
useEffect(() => {
|
|
1351
|
-
//
|
|
1305
|
+
// 将语言属性更新为当前的语言环境。
|
|
1352
1306
|
document.documentElement.lang = locale;
|
|
1353
1307
|
|
|
1354
1308
|
// 根据当前语言环境设置文本方向。
|
|
@@ -1365,7 +1319,7 @@ const { getHTMLTextDir } = require("intlayer");
|
|
|
1365
1319
|
/**
|
|
1366
1320
|
* 根据当前语言环境更新 HTML <html> 元素的 `lang` 和 `dir` 属性。
|
|
1367
1321
|
* - `lang`:告知浏览器和搜索引擎页面的语言。
|
|
1368
|
-
* - `dir
|
|
1322
|
+
* - `dir`:确保正确的阅读顺序(例如,英文为 'ltr',阿拉伯文为 'rtl')。
|
|
1369
1323
|
*
|
|
1370
1324
|
* 这种动态更新对于正确的文本渲染、无障碍访问和 SEO 至关重要。
|
|
1371
1325
|
*/
|
|
@@ -1395,10 +1349,36 @@ import { useI18nHTMLAttributes } from "./hooks/useI18nHTMLAttributes";
|
|
|
1395
1349
|
import "./App.css";
|
|
1396
1350
|
|
|
1397
1351
|
const AppContent: FC = () => {
|
|
1398
|
-
//
|
|
1352
|
+
// 应用该 Hook,根据当前语言环境更新 <html> 标签的 lang 和 dir 属性。
|
|
1353
|
+
useI18nHTMLAttributes();
|
|
1354
|
+
|
|
1355
|
+
// ... 组件的其余部分
|
|
1356
|
+
};
|
|
1357
|
+
|
|
1358
|
+
const App: FC = () => (
|
|
1359
|
+
<IntlayerProvider>
|
|
1360
|
+
<AppContent />
|
|
1361
|
+
</IntlayerProvider>
|
|
1362
|
+
);
|
|
1363
|
+
|
|
1364
|
+
export default App;
|
|
1365
|
+
```
|
|
1366
|
+
|
|
1367
|
+
#### 在您的应用程序中使用 Hook
|
|
1368
|
+
|
|
1369
|
+
将该 Hook 集成到您的主组件中,以便在语言环境更改时更新 HTML 属性:
|
|
1370
|
+
|
|
1371
|
+
```tsx fileName="src/App.tsx" codeFormat="typescript"
|
|
1372
|
+
import type { FC } from "react";
|
|
1373
|
+
import { IntlayerProvider, useIntlayer } from "react-intlayer";
|
|
1374
|
+
import { useI18nHTMLAttributes } from "./hooks/useI18nHTMLAttributes";
|
|
1375
|
+
import "./App.css";
|
|
1376
|
+
|
|
1377
|
+
const AppContent: FC = () => {
|
|
1378
|
+
// 应用该 Hook,根据语言环境更新 <html> 标签的 lang 和 dir 属性。
|
|
1399
1379
|
useI18nHTMLAttributes();
|
|
1400
1380
|
|
|
1401
|
-
// ...
|
|
1381
|
+
// ... 组件的其余部分
|
|
1402
1382
|
};
|
|
1403
1383
|
|
|
1404
1384
|
const App: FC = () => (
|
|
@@ -1416,7 +1396,7 @@ import { useI18nHTMLAttributes } from "./hooks/useI18nHTMLAttributes";
|
|
|
1416
1396
|
import "./App.css";
|
|
1417
1397
|
|
|
1418
1398
|
const AppContent = () => {
|
|
1419
|
-
//
|
|
1399
|
+
// 应用该 Hook,根据语言环境更新 <html> 标签的 lang 和 dir 属性。
|
|
1420
1400
|
useI18nHTMLAttributes();
|
|
1421
1401
|
|
|
1422
1402
|
// ... 组件的其余部分
|
|
@@ -1438,7 +1418,7 @@ const { useI18nHTMLAttributes } = require("./hooks/useI18nHTMLAttributes");
|
|
|
1438
1418
|
require("./App.css");
|
|
1439
1419
|
|
|
1440
1420
|
const AppContent = () => {
|
|
1441
|
-
//
|
|
1421
|
+
// 应用该 Hook,根据语言环境更新 <html> 标签的 lang 和 dir 属性。
|
|
1442
1422
|
useI18nHTMLAttributes();
|
|
1443
1423
|
|
|
1444
1424
|
// ... 组件的其余部分
|
|
@@ -1453,14 +1433,15 @@ const App = () => (
|
|
|
1453
1433
|
module.exports = App;
|
|
1454
1434
|
```
|
|
1455
1435
|
|
|
1456
|
-
|
|
1436
|
+
通过应用这些更改,您的应用程序将:
|
|
1457
1437
|
|
|
1458
1438
|
- 确保 **语言** (`lang`) 属性正确反映当前语言环境,这对 SEO 和浏览器行为非常重要。
|
|
1459
|
-
- 根据语言环境调整 **文本方向** (`dir`)
|
|
1439
|
+
- 根据语言环境调整 **文本方向** (`dir`),提升对不同阅读顺序语言的可读性和可用性。
|
|
1460
1440
|
- 提供更 **无障碍** 的体验,因为辅助技术依赖这些属性以实现最佳功能。
|
|
1461
1441
|
|
|
1462
1442
|
### (可选)步骤 10:创建本地化链接组件
|
|
1463
1443
|
|
|
1444
|
+
```tsx fileName="src/App.tsx" codeFormat="typescript"
|
|
1464
1445
|
// 应用该钩子以根据当前语言环境更新 <html> 标签的 lang 和 dir 属性。
|
|
1465
1446
|
useI18nHTMLAttributes();
|
|
1466
1447
|
|
|
@@ -1475,25 +1456,25 @@ const App = () => (
|
|
|
1475
1456
|
|
|
1476
1457
|
module.exports = App;
|
|
1477
1458
|
|
|
1478
|
-
|
|
1459
|
+
```
|
|
1479
1460
|
|
|
1480
|
-
|
|
1461
|
+
通过应用这些更改,您的应用将能够:
|
|
1481
1462
|
|
|
1482
|
-
- 确保 **语言** (`lang`)
|
|
1483
|
-
- 根据语言环境调整 **文本方向** (`dir`)
|
|
1484
|
-
- 提供更好的 **无障碍**
|
|
1463
|
+
- 确保 **语言** (`lang`) 属性正确反映当前的语言环境,这对于 SEO 和浏览器行为非常重要。
|
|
1464
|
+
- 根据语言环境调整 **文本方向** (`dir`),提升不同阅读顺序语言的可读性和可用性。
|
|
1465
|
+
- 提供更好的 **无障碍** 体验,因为辅助技术依赖这些属性来实现最佳功能。
|
|
1485
1466
|
|
|
1486
1467
|
### (可选)步骤 10:创建本地化链接组件
|
|
1487
1468
|
|
|
1488
|
-
|
|
1469
|
+
为了确保您的应用程序的导航尊重当前的语言环境,您可以创建一个自定义的 `Link` 组件。该组件会自动为内部 URL 添加当前语言的前缀。例如,当讲法语的用户点击“关于”页面的链接时,他们会被重定向到 `/fr/about`,而不是 `/about`。
|
|
1489
1470
|
|
|
1490
1471
|
这种行为有几个好处:
|
|
1491
1472
|
|
|
1492
1473
|
- **SEO 和用户体验**:本地化的 URL 有助于搜索引擎正确索引特定语言的页面,并为用户提供其偏好的语言内容。
|
|
1493
|
-
-
|
|
1474
|
+
- **一致性**:通过在整个应用中使用本地化链接,您可以确保导航保持在当前语言环境内,防止意外的语言切换。
|
|
1494
1475
|
- **可维护性**:将本地化逻辑集中在单个组件中简化了 URL 的管理,使您的代码库更易于维护和扩展,随着应用程序的增长。
|
|
1495
1476
|
|
|
1496
|
-
|
|
1477
|
+
下面是一个使用 TypeScript 实现的本地化 `Link` 组件示例:
|
|
1497
1478
|
|
|
1498
1479
|
```tsx fileName="src/components/Link.tsx" codeFormat="typescript"
|
|
1499
1480
|
import { getLocalizedUrl } from "intlayer";
|
|
@@ -1518,16 +1499,16 @@ export const checkIsExternalLink = (href?: string): boolean =>
|
|
|
1518
1499
|
/^https?:\/\//.test(href ?? "");
|
|
1519
1500
|
|
|
1520
1501
|
/**
|
|
1521
|
-
* 一个自定义的 Link
|
|
1522
|
-
*
|
|
1523
|
-
*
|
|
1502
|
+
* 一个自定义的 Link 组件,根据当前语言环境动态调整 href 属性。
|
|
1503
|
+
* 对于内部链接,使用 `getLocalizedUrl` 在 URL 前添加语言前缀(例如 /fr/about)。
|
|
1504
|
+
* 这样可以确保导航保持在相同的语言环境上下文中。
|
|
1524
1505
|
*/
|
|
1525
1506
|
export const Link = forwardRef<HTMLAnchorElement, LinkProps>(
|
|
1526
1507
|
({ href, children, ...props }, ref) => {
|
|
1527
1508
|
const { locale } = useLocale();
|
|
1528
1509
|
const isExternalLink = checkIsExternalLink(href);
|
|
1529
1510
|
|
|
1530
|
-
//
|
|
1511
|
+
// 如果链接是内部链接且 href 有效,则获取本地化的 URL。
|
|
1531
1512
|
const hrefI18n =
|
|
1532
1513
|
href && !isExternalLink ? getLocalizedUrl(href, locale) : href;
|
|
1533
1514
|
|
|
@@ -1540,7 +1521,7 @@ export const Link = forwardRef<HTMLAnchorElement, LinkProps>(
|
|
|
1540
1521
|
);
|
|
1541
1522
|
|
|
1542
1523
|
Link.displayName = "Link";
|
|
1543
|
-
|
|
1524
|
+
```
|
|
1544
1525
|
|
|
1545
1526
|
```jsx fileName="src/components/Link.mjx" codeFormat="esm"
|
|
1546
1527
|
import { getLocalizedUrl } from "intlayer";
|
|
@@ -1548,16 +1529,16 @@ import { useLocale } from "react-intlayer";
|
|
|
1548
1529
|
import { forwardRef } from "react";
|
|
1549
1530
|
|
|
1550
1531
|
/**
|
|
1551
|
-
*
|
|
1552
|
-
* 如果 URL 以 http:// 或 https://
|
|
1532
|
+
* 工具函数,用于检查给定的 URL 是否为外部链接。
|
|
1533
|
+
* 如果 URL 以 http:// 或 https:// 开头,则视为外部链接。
|
|
1553
1534
|
*/
|
|
1554
1535
|
export const checkIsExternalLink = (href?: string): boolean =>
|
|
1555
1536
|
/^https?:\/\//.test(href ?? "");
|
|
1556
1537
|
|
|
1557
1538
|
/**
|
|
1558
|
-
* 一个自定义的 Link
|
|
1559
|
-
*
|
|
1560
|
-
*
|
|
1539
|
+
* 一个自定义的 Link 组件,根据当前语言环境动态调整 href 属性。
|
|
1540
|
+
* 对于内部链接,使用 `getLocalizedUrl` 在 URL 前加上语言环境前缀(例如 /fr/about)。
|
|
1541
|
+
* 这样可以确保导航保持在相同的语言环境上下文中。
|
|
1561
1542
|
*/
|
|
1562
1543
|
export const Link = forwardRef(({ href, children, ...props }, ref) => {
|
|
1563
1544
|
const { locale } = useLocale();
|
|
@@ -1589,7 +1570,7 @@ const { forwardRef } = require("react");
|
|
|
1589
1570
|
const checkIsExternalLink = (href) => /^https?:\/\//.test(href ?? "");
|
|
1590
1571
|
|
|
1591
1572
|
/**
|
|
1592
|
-
* 一个自定义的 Link
|
|
1573
|
+
* 一个自定义的 Link 组件,根据当前语言环境动态调整 href 属性。
|
|
1593
1574
|
* 对于内部链接,使用 `getLocalizedUrl` 在 URL 前添加语言前缀(例如 /fr/about)。
|
|
1594
1575
|
* 这样可以确保导航保持在相同的语言环境上下文中。
|
|
1595
1576
|
*/
|
|
@@ -1597,7 +1578,7 @@ const Link = forwardRef(({ href, children, ...props }, ref) => {
|
|
|
1597
1578
|
const { locale } = useLocale();
|
|
1598
1579
|
const isExternalLink = checkIsExternalLink(href);
|
|
1599
1580
|
|
|
1600
|
-
//
|
|
1581
|
+
// 如果链接是内部链接且 href 有效,则获取本地化的 URL。
|
|
1601
1582
|
const localizedHref = isExternalLink ? href : getLocalizedUrl(href, locale);
|
|
1602
1583
|
|
|
1603
1584
|
return (
|
|
@@ -1624,12 +1605,12 @@ Link.displayName = "Link";
|
|
|
1624
1605
|
`useLocale` 钩子提供当前的语言环境(例如,法语为 `fr`)。
|
|
1625
1606
|
|
|
1626
1607
|
- **本地化 URL**:
|
|
1627
|
-
对于内部链接(即非外部链接),使用 `getLocalizedUrl` 自动为 URL
|
|
1608
|
+
对于内部链接(即非外部链接),使用 `getLocalizedUrl` 自动为 URL 添加当前语言环境前缀。这意味着如果用户使用的是法语,传入的 `/about` 会被转换为 `/fr/about`。
|
|
1628
1609
|
|
|
1629
1610
|
- **返回链接**:
|
|
1630
1611
|
该组件返回一个带有本地化 URL 的 `<a>` 元素,确保导航与当前语言环境保持一致。
|
|
1631
1612
|
|
|
1632
|
-
通过在整个应用中集成此 `Link`
|
|
1613
|
+
通过在整个应用中集成此 `Link` 组件,您可以维护一致且具语言感知的用户体验,同时提升 SEO 和可用性。
|
|
1633
1614
|
|
|
1634
1615
|
### 配置 TypeScript
|
|
1635
1616
|
|
|
@@ -1641,24 +1622,6 @@ Intlayer 使用模块增强(module augmentation)来利用 TypeScript 的优
|
|
|
1641
1622
|
|
|
1642
1623
|
确保您的 TypeScript 配置包含自动生成的类型。
|
|
1643
1624
|
|
|
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
1625
|
```json5 fileName="tsconfig.json"
|
|
1663
1626
|
{
|
|
1664
1627
|
// ... 您现有的 TypeScript 配置
|
|
@@ -1667,13 +1630,13 @@ Intlayer 使用模块扩展来利用 TypeScript 的优势,使您的代码库
|
|
|
1667
1630
|
".intlayer/**/*.ts", // 包含自动生成的类型
|
|
1668
1631
|
],
|
|
1669
1632
|
}
|
|
1670
|
-
|
|
1633
|
+
```
|
|
1671
1634
|
|
|
1672
1635
|
### Git 配置
|
|
1673
1636
|
|
|
1674
|
-
建议忽略 Intlayer 生成的文件,这样可以避免将它们提交到您的 Git
|
|
1637
|
+
建议忽略 Intlayer 生成的文件,这样可以避免将它们提交到您的 Git 仓库中。
|
|
1675
1638
|
|
|
1676
|
-
为此,您可以在 `.gitignore`
|
|
1639
|
+
为此,您可以在 `.gitignore` 文件中添加以下指令:
|
|
1677
1640
|
|
|
1678
1641
|
```plaintext
|
|
1679
1642
|
# 忽略 Intlayer 生成的文件
|
|
@@ -1688,9 +1651,9 @@ Intlayer 使用模块扩展来利用 TypeScript 的优势,使您的代码库
|
|
|
1688
1651
|
|
|
1689
1652
|
该扩展提供:
|
|
1690
1653
|
|
|
1691
|
-
-
|
|
1654
|
+
- **翻译键的自动补全**。
|
|
1692
1655
|
- **实时错误检测**,用于缺失的翻译。
|
|
1693
|
-
-
|
|
1656
|
+
- **内联预览**已翻译的内容。
|
|
1694
1657
|
- **快速操作**,轻松创建和更新翻译。
|
|
1695
1658
|
|
|
1696
1659
|
有关如何使用该扩展的更多详细信息,请参阅[Intlayer VS Code 扩展文档](https://intlayer.org/doc/vs-code-extension)。
|
|
@@ -1699,7 +1662,7 @@ Intlayer 使用模块扩展来利用 TypeScript 的优势,使您的代码库
|
|
|
1699
1662
|
|
|
1700
1663
|
### 深入了解
|
|
1701
1664
|
|
|
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)
|
|
1665
|
+
要进一步使用,您可以实现[可视化编辑器](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
1666
|
|
|
1704
1667
|
---
|
|
1705
1668
|
|