@intlayer/docs 5.5.8 → 5.5.10
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/ar/autoFill.md +1 -2
- package/ar/intlayer_with_create_react_app.md +1 -14
- package/ar/intlayer_with_nextjs_14.md +1 -14
- package/ar/intlayer_with_nextjs_15.md +1 -14
- package/ar/intlayer_with_nextjs_page_router.md +1 -13
- package/ar/intlayer_with_nuxt.md +792 -0
- package/ar/intlayer_with_react_native+expo.md +6 -3
- package/ar/intlayer_with_vite+preact.md +7 -18
- package/ar/intlayer_with_vite+react.md +7 -17
- package/ar/intlayer_with_vite+vue.md +25 -5
- package/ar/packages/nuxt-intlayer/index.md +29 -0
- package/ar/roadmap.md +11 -11
- package/de/autoFill.md +1 -2
- package/de/how_works_intlayer.md +1 -1
- package/de/intlayer_with_create_react_app.md +1 -14
- package/de/intlayer_with_nextjs_14.md +1 -14
- package/de/intlayer_with_nextjs_15.md +1 -14
- package/de/intlayer_with_nextjs_page_router.md +1 -13
- package/de/intlayer_with_nuxt.md +791 -0
- package/de/intlayer_with_react_native+expo.md +6 -3
- package/de/intlayer_with_vite+preact.md +7 -18
- package/de/intlayer_with_vite+react.md +7 -17
- package/de/intlayer_with_vite+vue.md +84 -62
- package/de/packages/nuxt-intlayer/index.md +29 -0
- package/de/roadmap.md +11 -11
- package/en/autoFill.md +1 -2
- package/en/how_works_intlayer.md +17 -3
- package/en/intlayer_with_angular.md +535 -6
- package/en/intlayer_with_create_react_app.md +1 -14
- package/en/intlayer_with_nextjs_14.md +193 -59
- package/en/intlayer_with_nextjs_15.md +192 -61
- package/en/intlayer_with_nextjs_page_router.md +396 -61
- package/en/intlayer_with_nuxt.md +737 -0
- package/en/intlayer_with_react_native+expo.md +6 -3
- package/en/intlayer_with_vite+preact.md +8 -27
- package/en/intlayer_with_vite+react.md +7 -17
- package/en/intlayer_with_vite+solid.md +6 -3
- package/en/intlayer_with_vite+svelte.md +6 -3
- package/en/intlayer_with_vite+vue.md +17 -6
- package/en/packages/nuxt-intlayer/index.md +31 -0
- package/en/roadmap.md +13 -13
- package/en/t.md +5 -5
- package/en-GB/how_works_intlayer.md +16 -4
- package/en-GB/intlayer_with_create_react_app.md +1 -14
- package/en-GB/intlayer_with_nextjs_14.md +1 -14
- package/en-GB/intlayer_with_nextjs_15.md +1 -14
- package/en-GB/intlayer_with_nextjs_page_router.md +1 -13
- package/en-GB/intlayer_with_nuxt.md +795 -0
- package/en-GB/intlayer_with_react_native+expo.md +6 -3
- package/en-GB/intlayer_with_vite+preact.md +7 -18
- package/en-GB/intlayer_with_vite+react.md +6 -9
- package/en-GB/intlayer_with_vite+vue.md +65 -59
- package/en-GB/packages/nuxt-intlayer/index.md +31 -0
- package/en-GB/roadmap.md +11 -11
- package/es/autoFill.md +1 -2
- package/es/how_works_intlayer.md +1 -1
- package/es/intlayer_with_create_react_app.md +1 -14
- package/es/intlayer_with_nextjs_14.md +1 -14
- package/es/intlayer_with_nextjs_15.md +1 -14
- package/es/intlayer_with_nextjs_page_router.md +1 -13
- package/es/intlayer_with_nuxt.md +731 -0
- package/es/intlayer_with_react_native+expo.md +6 -3
- package/es/intlayer_with_vite+preact.md +7 -18
- package/es/intlayer_with_vite+react.md +7 -17
- package/es/intlayer_with_vite+vue.md +64 -51
- package/es/packages/nuxt-intlayer/index.md +29 -0
- package/fr/autoFill.md +1 -2
- package/fr/how_works_intlayer.md +1 -1
- package/fr/intlayer_with_create_react_app.md +1 -14
- package/fr/intlayer_with_nextjs_14.md +1 -14
- package/fr/intlayer_with_nextjs_15.md +1 -14
- package/fr/intlayer_with_nextjs_page_router.md +1 -13
- package/fr/intlayer_with_nuxt.md +731 -0
- package/fr/intlayer_with_react_native+expo.md +6 -3
- package/fr/intlayer_with_vite+preact.md +7 -18
- package/fr/intlayer_with_vite+react.md +7 -17
- package/fr/intlayer_with_vite+vue.md +30 -15
- package/fr/packages/nuxt-intlayer/index.md +29 -0
- package/fr/roadmap.md +11 -11
- package/hi/autoFill.md +1 -2
- package/hi/how_works_intlayer.md +1 -1
- package/hi/intlayer_with_create_react_app.md +1 -14
- package/hi/intlayer_with_nextjs_14.md +1 -14
- package/hi/intlayer_with_nextjs_15.md +1 -14
- package/hi/intlayer_with_nextjs_page_router.md +1 -13
- package/hi/intlayer_with_nuxt.md +784 -0
- package/hi/intlayer_with_react_native+expo.md +6 -3
- package/hi/intlayer_with_vite+preact.md +7 -18
- package/hi/intlayer_with_vite+react.md +7 -17
- package/hi/intlayer_with_vite+vue.md +59 -47
- package/hi/packages/nuxt-intlayer/index.md +29 -0
- package/hi/roadmap.md +11 -11
- package/index.cjs +30 -0
- package/index.d.ts +2 -0
- package/it/autoFill.md +1 -2
- package/it/how_works_intlayer.md +1 -1
- package/it/intlayer_with_create_react_app.md +0 -6
- package/it/intlayer_with_nextjs_14.md +1 -14
- package/it/intlayer_with_nextjs_15.md +1 -14
- package/it/intlayer_with_nextjs_page_router.md +1 -13
- package/it/intlayer_with_nuxt.md +793 -0
- package/it/intlayer_with_react_native+expo.md +6 -3
- package/it/intlayer_with_vite+preact.md +7 -18
- package/it/intlayer_with_vite+react.md +7 -17
- package/it/intlayer_with_vite+vue.md +26 -17
- package/it/packages/nuxt-intlayer/index.md +29 -0
- package/it/roadmap.md +11 -11
- package/ja/autoFill.md +1 -2
- package/ja/how_works_intlayer.md +1 -1
- package/ja/intlayer_with_create_react_app.md +1 -14
- package/ja/intlayer_with_nextjs_14.md +1 -14
- package/ja/intlayer_with_nextjs_15.md +1 -14
- package/ja/intlayer_with_nextjs_page_router.md +1 -13
- package/ja/intlayer_with_nuxt.md +792 -0
- package/ja/intlayer_with_react_native+expo.md +6 -3
- package/ja/intlayer_with_vite+preact.md +7 -18
- package/ja/intlayer_with_vite+react.md +7 -17
- package/ja/intlayer_with_vite+vue.md +68 -63
- package/ja/packages/nuxt-intlayer/index.md +29 -0
- package/ja/roadmap.md +11 -11
- package/ko/autoFill.md +1 -2
- package/ko/how_works_intlayer.md +1 -1
- package/ko/intlayer_with_create_react_app.md +1 -14
- package/ko/intlayer_with_nextjs_14.md +1 -14
- package/ko/intlayer_with_nextjs_15.md +1 -14
- package/ko/intlayer_with_nextjs_page_router.md +1 -13
- package/ko/intlayer_with_nuxt.md +784 -0
- package/ko/intlayer_with_react_native+expo.md +6 -3
- package/ko/intlayer_with_vite+preact.md +7 -18
- package/ko/intlayer_with_vite+react.md +7 -17
- package/ko/intlayer_with_vite+vue.md +69 -59
- package/ko/packages/nuxt-intlayer/index.md +31 -0
- package/ko/roadmap.md +11 -11
- package/package.json +4 -4
- package/pt/autoFill.md +1 -2
- package/pt/how_works_intlayer.md +1 -1
- package/pt/intlayer_with_create_react_app.md +1 -14
- package/pt/intlayer_with_nextjs_14.md +1 -14
- package/pt/intlayer_with_nextjs_15.md +1 -14
- package/pt/intlayer_with_nextjs_page_router.md +1 -13
- package/pt/intlayer_with_nuxt.md +792 -0
- package/pt/intlayer_with_react_native+expo.md +6 -3
- package/pt/intlayer_with_vite+preact.md +7 -18
- package/pt/intlayer_with_vite+react.md +7 -17
- package/pt/intlayer_with_vite+vue.md +23 -19
- package/pt/packages/nuxt-intlayer/index.md +29 -0
- package/pt/roadmap.md +11 -11
- package/ru/autoFill.md +1 -2
- package/ru/how_works_intlayer.md +1 -1
- package/ru/intlayer_with_create_react_app.md +1 -14
- package/ru/intlayer_with_nextjs_14.md +1 -14
- package/ru/intlayer_with_nextjs_15.md +1 -14
- package/ru/intlayer_with_nextjs_page_router.md +1 -13
- package/ru/intlayer_with_nuxt.md +792 -0
- package/ru/intlayer_with_react_native+expo.md +6 -3
- package/ru/intlayer_with_vite+preact.md +7 -18
- package/ru/intlayer_with_vite+react.md +7 -17
- package/ru/intlayer_with_vite+vue.md +25 -17
- package/ru/packages/nuxt-intlayer/index.md +31 -0
- package/ru/roadmap.md +11 -11
- package/zh/autoFill.md +1 -2
- package/zh/intlayer_with_create_react_app.md +1 -14
- package/zh/intlayer_with_nextjs_14.md +1 -14
- package/zh/intlayer_with_nextjs_15.md +1 -14
- package/zh/intlayer_with_nextjs_page_router.md +1 -13
- package/zh/intlayer_with_nuxt.md +784 -0
- package/zh/intlayer_with_react_native+expo.md +6 -3
- package/zh/intlayer_with_vite+preact.md +7 -18
- package/zh/intlayer_with_vite+react.md +7 -17
- package/zh/intlayer_with_vite+vue.md +68 -57
- package/zh/packages/nuxt-intlayer/index.md +31 -0
- package/zh/roadmap.md +11 -11
|
@@ -0,0 +1,784 @@
|
|
|
1
|
+
# 开始使用 Intlayer 和 Nuxt 进行国际化 (i18n)
|
|
2
|
+
|
|
3
|
+
请参阅 GitHub 上的 [应用模板](https://github.com/aymericzip/intlayer-nuxt-template)。
|
|
4
|
+
|
|
5
|
+
## 什么是 Intlayer?
|
|
6
|
+
|
|
7
|
+
**Intlayer** 是一个创新的开源国际化 (i18n) 库,旨在简化现代 Web 应用程序中的多语言支持。
|
|
8
|
+
|
|
9
|
+
使用 Intlayer,您可以:
|
|
10
|
+
|
|
11
|
+
- **轻松管理翻译**,通过组件级别的声明式字典。
|
|
12
|
+
- **动态本地化元数据**、路由和内容。
|
|
13
|
+
- **确保 TypeScript 支持**,通过自动生成类型,提高自动补全和错误检测能力。
|
|
14
|
+
- **享受高级功能**,如动态语言检测和切换。
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## 在 Nuxt 应用中设置 Intlayer 的分步指南
|
|
19
|
+
|
|
20
|
+
### 第一步:安装依赖
|
|
21
|
+
|
|
22
|
+
使用 npm 安装必要的包:
|
|
23
|
+
|
|
24
|
+
```bash packageManager="npm"
|
|
25
|
+
npm install intlayer vue-intlayer
|
|
26
|
+
npm install --save-dev nuxt-intlayer
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
```bash packageManager="pnpm"
|
|
30
|
+
pnpm add intlayer vue-intlayer
|
|
31
|
+
pnpm add --save-dev nuxt-intlayer
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
```bash packageManager="yarn"
|
|
35
|
+
yarn add intlayer vue-intlayer
|
|
36
|
+
yarn add --save-dev nuxt-intlayer
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
- **intlayer**
|
|
40
|
+
|
|
41
|
+
提供用于配置管理、翻译、[内容声明](https://github.com/aymericzip/intlayer/blob/main/docs/zh/dictionary/get_started.md)、转译和 [CLI 命令](https://github.com/aymericzip/intlayer/blob/main/docs/zh/intlayer_cli.md) 的核心包。
|
|
42
|
+
|
|
43
|
+
- **vue-intlayer**
|
|
44
|
+
将 Intlayer 集成到 Vue 应用中的包。它为 Vue 组件提供可组合的功能。
|
|
45
|
+
|
|
46
|
+
- **nuxt-intlayer**
|
|
47
|
+
将 Intlayer 集成到 Nuxt 应用中的模块。它提供自动设置、用于语言检测的中间件、Cookie 管理和 URL 重定向。
|
|
48
|
+
|
|
49
|
+
### 第二步:配置您的项目
|
|
50
|
+
|
|
51
|
+
创建一个配置文件来配置您的应用语言:
|
|
52
|
+
|
|
53
|
+
```typescript fileName="intlayer.config.ts" codeFormat="typescript"
|
|
54
|
+
import { Locales, type IntlayerConfig } from "intlayer";
|
|
55
|
+
|
|
56
|
+
const config: IntlayerConfig = {
|
|
57
|
+
internationalization: {
|
|
58
|
+
locales: [
|
|
59
|
+
Locales.ENGLISH,
|
|
60
|
+
Locales.FRENCH,
|
|
61
|
+
Locales.SPANISH,
|
|
62
|
+
// 您的其他语言
|
|
63
|
+
],
|
|
64
|
+
defaultLocale: Locales.ENGLISH,
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export default config;
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
```javascript fileName="intlayer.config.mjs" codeFormat="esm"
|
|
72
|
+
import { Locales } from "intlayer";
|
|
73
|
+
|
|
74
|
+
/** @type {import('intlayer').IntlayerConfig} */
|
|
75
|
+
const config = {
|
|
76
|
+
internationalization: {
|
|
77
|
+
locales: [
|
|
78
|
+
Locales.ENGLISH,
|
|
79
|
+
Locales.FRENCH,
|
|
80
|
+
Locales.SPANISH,
|
|
81
|
+
// 您的其他语言
|
|
82
|
+
],
|
|
83
|
+
defaultLocale: Locales.ENGLISH,
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
export default config;
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
```javascript fileName="intlayer.config.cjs" codeFormat="commonjs"
|
|
91
|
+
const { Locales } = require("intlayer");
|
|
92
|
+
|
|
93
|
+
/** @type {import('intlayer').IntlayerConfig} */
|
|
94
|
+
const config = {
|
|
95
|
+
internationalization: {
|
|
96
|
+
locales: [
|
|
97
|
+
Locales.ENGLISH,
|
|
98
|
+
Locales.FRENCH,
|
|
99
|
+
Locales.SPANISH,
|
|
100
|
+
// 您的其他语言
|
|
101
|
+
],
|
|
102
|
+
defaultLocale: Locales.ENGLISH,
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
module.exports = config;
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
> 通过此配置文件,您可以设置本地化 URL、中间件重定向、Cookie 名称、内容声明的位置和扩展名、禁用控制台中的 Intlayer 日志等。有关可用参数的完整列表,请参阅 [配置文档](https://github.com/aymericzip/intlayer/blob/main/docs/zh/configuration.md)。
|
|
110
|
+
|
|
111
|
+
### 第三步:在 Nuxt 配置中集成 Intlayer
|
|
112
|
+
|
|
113
|
+
将 intlayer 模块添加到您的 Nuxt 配置中:
|
|
114
|
+
|
|
115
|
+
```typescript fileName="nuxt.config.ts"
|
|
116
|
+
import { defineNuxtConfig } from "nuxt/config";
|
|
117
|
+
|
|
118
|
+
export default defineNuxtConfig({
|
|
119
|
+
// ... 您现有的 Nuxt 配置
|
|
120
|
+
modules: ["nuxt-intlayer"],
|
|
121
|
+
});
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
> `nuxt-intlayer` 模块自动处理 Intlayer 与 Nuxt 的集成。它设置内容声明构建,监控开发模式下的文件,提供用于语言检测的中间件,并管理本地化路由。
|
|
125
|
+
|
|
126
|
+
### 第四步:声明您的内容
|
|
127
|
+
|
|
128
|
+
创建并管理您的内容声明以存储翻译:
|
|
129
|
+
|
|
130
|
+
```tsx fileName="components/helloWorld.content.ts" contentDeclarationFormat="typescript"
|
|
131
|
+
import { t, type Dictionary } from "intlayer";
|
|
132
|
+
|
|
133
|
+
const helloWorldContent = {
|
|
134
|
+
key: "helloworld",
|
|
135
|
+
content: {
|
|
136
|
+
count: t({
|
|
137
|
+
zh: "计数是 ",
|
|
138
|
+
en: "count is ",
|
|
139
|
+
fr: "le compte est ",
|
|
140
|
+
es: "el recuento es ",
|
|
141
|
+
}),
|
|
142
|
+
edit: t({
|
|
143
|
+
zh: "编辑 <code>components/HelloWorld.vue</code> 并保存以测试 HMR",
|
|
144
|
+
en: "Edit <code>components/HelloWorld.vue</code> and save to test HMR",
|
|
145
|
+
fr: "Éditez <code>components/HelloWorld.vue</code> et enregistrez pour tester HMR",
|
|
146
|
+
es: "Edita <code>components/HelloWorld.vue</code> y guarda para probar HMR",
|
|
147
|
+
}),
|
|
148
|
+
checkOut: t({
|
|
149
|
+
zh: "查看 ",
|
|
150
|
+
en: "Check out ",
|
|
151
|
+
fr: "Vérifiez ",
|
|
152
|
+
es: "Compruebe ",
|
|
153
|
+
}),
|
|
154
|
+
nuxtIntlayer: t({
|
|
155
|
+
zh: "Nuxt Intlayer 文档",
|
|
156
|
+
en: "Nuxt Intlayer documentation",
|
|
157
|
+
fr: "Documentation de Nuxt Intlayer",
|
|
158
|
+
es: "Documentación de Nuxt Intlayer",
|
|
159
|
+
}),
|
|
160
|
+
learnMore: t({
|
|
161
|
+
zh: "在此了解更多关于 Nuxt 的信息 ",
|
|
162
|
+
en: "Learn more about Nuxt in the ",
|
|
163
|
+
fr: "En savoir plus sur Nuxt dans la ",
|
|
164
|
+
es: "Aprenda más sobre Nuxt en la ",
|
|
165
|
+
}),
|
|
166
|
+
nuxtDocs: t({
|
|
167
|
+
zh: "Nuxt 文档",
|
|
168
|
+
en: "Nuxt Documentation",
|
|
169
|
+
fr: "Documentation Nuxt",
|
|
170
|
+
es: "Documentación de Nuxt",
|
|
171
|
+
}),
|
|
172
|
+
readTheDocs: t({
|
|
173
|
+
zh: "点击 Nuxt 标志以了解更多信息",
|
|
174
|
+
en: "Click on the Nuxt logo to learn more",
|
|
175
|
+
fr: "Cliquez sur le logo Nuxt pour en savoir plus",
|
|
176
|
+
es: "Haga clic en el logotipo de Nuxt para obtener más información",
|
|
177
|
+
}),
|
|
178
|
+
},
|
|
179
|
+
} satisfies Dictionary;
|
|
180
|
+
|
|
181
|
+
export default helloWorldContent;
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
```javascript fileName="components/helloWorld.content.mjs" contentDeclarationFormat="esm"
|
|
185
|
+
import { t } from "intlayer";
|
|
186
|
+
|
|
187
|
+
/** @type {import('intlayer').Dictionary} */
|
|
188
|
+
const helloWorldContent = {
|
|
189
|
+
key: "helloworld",
|
|
190
|
+
content: {
|
|
191
|
+
count: t({
|
|
192
|
+
zh: "计数是 ",
|
|
193
|
+
en: "count is ",
|
|
194
|
+
fr: "le compte est ",
|
|
195
|
+
es: "el recuento es ",
|
|
196
|
+
}),
|
|
197
|
+
edit: t({
|
|
198
|
+
zh: "编辑 <code>components/HelloWorld.vue</code> 并保存以测试 HMR",
|
|
199
|
+
en: "Edit <code>components/HelloWorld.vue</code> and save to test HMR",
|
|
200
|
+
fr: "Éditez <code>components/HelloWorld.vue</code> et enregistrez pour tester HMR",
|
|
201
|
+
es: "Edita <code>components/HelloWorld.vue</code> y guarda para probar HMR",
|
|
202
|
+
}),
|
|
203
|
+
checkOut: t({
|
|
204
|
+
zh: "查看 ",
|
|
205
|
+
en: "Check out ",
|
|
206
|
+
fr: "Vérifiez ",
|
|
207
|
+
es: "Compruebe ",
|
|
208
|
+
}),
|
|
209
|
+
nuxtIntlayer: t({
|
|
210
|
+
zh: "Nuxt Intlayer 文档",
|
|
211
|
+
en: "Nuxt Intlayer documentation",
|
|
212
|
+
fr: "Documentation de Nuxt Intlayer",
|
|
213
|
+
es: "Documentación de Nuxt Intlayer",
|
|
214
|
+
}),
|
|
215
|
+
learnMore: t({
|
|
216
|
+
zh: "在此了解更多关于 Nuxt 的信息 ",
|
|
217
|
+
en: "Learn more about Nuxt in the ",
|
|
218
|
+
fr: "En savoir plus sur Nuxt dans la ",
|
|
219
|
+
es: "Aprenda más sobre Nuxt en la ",
|
|
220
|
+
}),
|
|
221
|
+
nuxtDocs: t({
|
|
222
|
+
zh: "Nuxt 文档",
|
|
223
|
+
en: "Nuxt Documentation",
|
|
224
|
+
fr: "Documentation Nuxt",
|
|
225
|
+
es: "Documentación de Nuxt",
|
|
226
|
+
}),
|
|
227
|
+
readTheDocs: t({
|
|
228
|
+
zh: "点击 Nuxt 标志以了解更多信息",
|
|
229
|
+
en: "Click on the Nuxt logo to learn more",
|
|
230
|
+
fr: "Cliquez sur le logo Nuxt pour en savoir plus",
|
|
231
|
+
es: "Haga clic en el logotipo de Nuxt para obtener más información",
|
|
232
|
+
}),
|
|
233
|
+
},
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
export default helloWorldContent;
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
```javascript fileName="components/helloWorld.content.cjs" contentDeclarationFormat="commonjs"
|
|
240
|
+
const { t } = require("intlayer");
|
|
241
|
+
|
|
242
|
+
/** @type {import('intlayer').Dictionary} */
|
|
243
|
+
const helloWorldContent = {
|
|
244
|
+
key: "helloworld",
|
|
245
|
+
content: {
|
|
246
|
+
count: t({
|
|
247
|
+
zh: "计数是 ",
|
|
248
|
+
en: "count is ",
|
|
249
|
+
fr: "le compte est ",
|
|
250
|
+
es: "el recuento es ",
|
|
251
|
+
}),
|
|
252
|
+
edit: t({
|
|
253
|
+
zh: "编辑 <code>components/HelloWorld.vue</code> 并保存以测试 HMR",
|
|
254
|
+
en: "Edit <code>components/HelloWorld.vue</code> and save to test HMR",
|
|
255
|
+
fr: "Éditez <code>components/HelloWorld.vue</code> et enregistrez pour tester HMR",
|
|
256
|
+
es: "Edita <code>components/HelloWorld.vue</code> y guarda para probar HMR",
|
|
257
|
+
}),
|
|
258
|
+
checkOut: t({
|
|
259
|
+
zh: "查看 ",
|
|
260
|
+
en: "Check out ",
|
|
261
|
+
fr: "Vérifiez ",
|
|
262
|
+
es: "Compruebe ",
|
|
263
|
+
}),
|
|
264
|
+
nuxtIntlayer: t({
|
|
265
|
+
zh: "Nuxt Intlayer 文档",
|
|
266
|
+
en: "Nuxt Intlayer documentation",
|
|
267
|
+
fr: "Documentation de Nuxt Intlayer",
|
|
268
|
+
es: "Documentación de Nuxt Intlayer",
|
|
269
|
+
}),
|
|
270
|
+
learnMore: t({
|
|
271
|
+
zh: "在此了解更多关于 Nuxt 的信息 ",
|
|
272
|
+
en: "Learn more about Nuxt in the ",
|
|
273
|
+
fr: "En savoir plus sur Nuxt dans la ",
|
|
274
|
+
es: "Aprenda más sobre Nuxt en la ",
|
|
275
|
+
}),
|
|
276
|
+
nuxtDocs: t({
|
|
277
|
+
zh: "Nuxt 文档",
|
|
278
|
+
en: "Nuxt Documentation",
|
|
279
|
+
fr: "Documentation Nuxt",
|
|
280
|
+
es: "Documentación de Nuxt",
|
|
281
|
+
}),
|
|
282
|
+
readTheDocs: t({
|
|
283
|
+
zh: "点击 Nuxt 标志以了解更多信息",
|
|
284
|
+
en: "Click on the Nuxt logo to learn more",
|
|
285
|
+
fr: "Cliquez sur le logo Nuxt pour en savoir plus",
|
|
286
|
+
es: "Haga clic en el logotipo de Nuxt para obtener más información",
|
|
287
|
+
}),
|
|
288
|
+
},
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
module.exports = helloWorldContent;
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
```json fileName="components/helloWorld.content.json" contentDeclarationFormat="json"
|
|
295
|
+
{
|
|
296
|
+
"$schema": "https://intlayer.org/schema.json",
|
|
297
|
+
"key": "helloworld",
|
|
298
|
+
"content": {
|
|
299
|
+
"count": {
|
|
300
|
+
"nodeType": "translation",
|
|
301
|
+
"translation": {
|
|
302
|
+
"zh": "计数是 ",
|
|
303
|
+
"en": "count is ",
|
|
304
|
+
"fr": "le compte est ",
|
|
305
|
+
"es": "el recuento es "
|
|
306
|
+
}
|
|
307
|
+
},
|
|
308
|
+
"edit": {
|
|
309
|
+
"nodeType": "translation",
|
|
310
|
+
"translation": {
|
|
311
|
+
"zh": "编辑 <code>components/HelloWorld.vue</code> 并保存以测试 HMR",
|
|
312
|
+
"en": "Edit <code>components/HelloWorld.vue</code> and save to test HMR",
|
|
313
|
+
"fr": "Éditez <code>components/HelloWorld.vue</code> et enregistrez pour tester HMR",
|
|
314
|
+
"es": "Edita <code>components/HelloWorld.vue</code> y guarda para probar HMR"
|
|
315
|
+
}
|
|
316
|
+
},
|
|
317
|
+
"checkOut": {
|
|
318
|
+
"nodeType": "translation",
|
|
319
|
+
"translation": {
|
|
320
|
+
"zh": "查看 ",
|
|
321
|
+
"en": "Check out ",
|
|
322
|
+
"fr": "Vérifiez ",
|
|
323
|
+
"es": "Compruebe "
|
|
324
|
+
}
|
|
325
|
+
},
|
|
326
|
+
"nuxtIntlayer": {
|
|
327
|
+
"nodeType": "translation",
|
|
328
|
+
"translation": {
|
|
329
|
+
"zh": "Nuxt Intlayer 文档",
|
|
330
|
+
"en": "Nuxt Intlayer documentation",
|
|
331
|
+
"fr": "Documentation de Nuxt Intlayer",
|
|
332
|
+
"es": "Documentación de Nuxt Intlayer"
|
|
333
|
+
}
|
|
334
|
+
},
|
|
335
|
+
"learnMore": {
|
|
336
|
+
"nodeType": "translation",
|
|
337
|
+
"translation": {
|
|
338
|
+
"zh": "在以下位置了解更多关于 Nuxt 的信息 ",
|
|
339
|
+
"en": "Learn more about Nuxt in the ",
|
|
340
|
+
"fr": "En savoir plus sur Nuxt dans la ",
|
|
341
|
+
"es": "Aprenda más sobre Nuxt en la "
|
|
342
|
+
}
|
|
343
|
+
},
|
|
344
|
+
"nuxtDocs": {
|
|
345
|
+
"nodeType": "translation",
|
|
346
|
+
"translation": {
|
|
347
|
+
"zh": "Nuxt 文档",
|
|
348
|
+
"en": "Nuxt Documentation",
|
|
349
|
+
"fr": "Documentation Nuxt",
|
|
350
|
+
"es": "Documentación de Nuxt"
|
|
351
|
+
}
|
|
352
|
+
},
|
|
353
|
+
"readTheDocs": {
|
|
354
|
+
"nodeType": "translation",
|
|
355
|
+
"translation": {
|
|
356
|
+
"zh": "点击 Nuxt 标志以了解更多信息",
|
|
357
|
+
"en": "Click on the Nuxt logo to learn more",
|
|
358
|
+
"fr": "Cliquez sur le logo Nuxt pour en savoir plus",
|
|
359
|
+
"es": "Haga clic en el logotipo de Nuxt para obtener más información"
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
> 您的内容声明可以在应用程序中的任何位置定义,只要它们包含在 `contentDir` 目录中(默认情况下为 `./src`)。并匹配内容声明文件扩展名(默认情况下为 `.content.{json,ts,tsx,js,jsx,mjs,mjx,cjs,cjx}`)。
|
|
367
|
+
|
|
368
|
+
> 有关更多详细信息,请参阅 [内容声明文档](https://github.com/aymericzip/intlayer/blob/main/docs/zh/dictionary/get_started.md)。
|
|
369
|
+
|
|
370
|
+
### 第五步:在代码中使用 Intlayer
|
|
371
|
+
|
|
372
|
+
通过 `useIntlayer` 可组合函数,在整个 Nuxt 应用程序中访问您的内容字典:
|
|
373
|
+
|
|
374
|
+
```vue fileName="components/HelloWorld.vue"
|
|
375
|
+
<script setup lang="ts">
|
|
376
|
+
import { ref } from "vue";
|
|
377
|
+
import { useIntlayer } from "vue-intlayer";
|
|
378
|
+
|
|
379
|
+
defineProps({
|
|
380
|
+
msg: String,
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
const {
|
|
384
|
+
count,
|
|
385
|
+
edit,
|
|
386
|
+
checkOut,
|
|
387
|
+
nuxtIntlayer,
|
|
388
|
+
learnMore,
|
|
389
|
+
nuxtDocs,
|
|
390
|
+
readTheDocs,
|
|
391
|
+
} = useIntlayer("helloworld");
|
|
392
|
+
const countRef = ref(0);
|
|
393
|
+
</script>
|
|
394
|
+
|
|
395
|
+
<template>
|
|
396
|
+
<h1>{{ msg }}</h1>
|
|
397
|
+
|
|
398
|
+
<div class="card">
|
|
399
|
+
<button type="button" @click="countRef++">
|
|
400
|
+
<count />
|
|
401
|
+
{{ countRef }}
|
|
402
|
+
</button>
|
|
403
|
+
<p v-html="edit"></p>
|
|
404
|
+
</div>
|
|
405
|
+
|
|
406
|
+
<p>
|
|
407
|
+
<checkOut />
|
|
408
|
+
<a href="https://nuxt.com/docs/getting-started/introduction" target="_blank"
|
|
409
|
+
>Nuxt</a
|
|
410
|
+
>, <nuxtIntlayer />
|
|
411
|
+
</p>
|
|
412
|
+
<p>
|
|
413
|
+
<learnMore />
|
|
414
|
+
<a href="https://nuxt.com" target="_blank"><nuxtDocs /></a>.
|
|
415
|
+
</p>
|
|
416
|
+
<p class="read-the-docs"><readTheDocs /></p>
|
|
417
|
+
<p class="read-the-docs">{{ readTheDocs }}</p>
|
|
418
|
+
</template>
|
|
419
|
+
```
|
|
420
|
+
|
|
421
|
+
#### 在 Intlayer 中访问内容
|
|
422
|
+
|
|
423
|
+
Intlayer 提供两种 API 来访问您的内容:
|
|
424
|
+
|
|
425
|
+
- **基于组件的语法**(推荐):
|
|
426
|
+
使用 `<myContent />` 语法将内容呈现为 Intlayer 节点。这与 [可视化编辑器](https://github.com/aymericzip/intlayer/blob/main/docs/zh/intlayer_visual_editor.md) 和 [CMS](https://github.com/aymericzip/intlayer/blob/main/docs/zh/intlayer_CMS.md) 无缝集成。
|
|
427
|
+
|
|
428
|
+
- **基于字符串的语法**:
|
|
429
|
+
使用 `{{ myContent }}` 将内容呈现为纯文本,无任何交互性。
|
|
430
|
+
|
|
431
|
+
### (可选)第六步:更改内容的语言
|
|
432
|
+
|
|
433
|
+
要更改内容的语言,您可以使用 `useLocale` 可组合函数提供的 `setLocale` 函数。此函数允许您设置应用程序的语言环境并相应地更新内容。
|
|
434
|
+
|
|
435
|
+
创建一个组件以在语言之间切换:
|
|
436
|
+
|
|
437
|
+
```vue fileName="components/LocaleSwitcher.vue"
|
|
438
|
+
<template>
|
|
439
|
+
<div class="locale-switcher">
|
|
440
|
+
<select v-model="selectedLocale" @change="changeLocale">
|
|
441
|
+
<option v-for="loc in availableLocales" :key="loc" :value="loc">
|
|
442
|
+
{{ getLocaleName(loc) }}
|
|
443
|
+
</option>
|
|
444
|
+
</select>
|
|
445
|
+
</div>
|
|
446
|
+
</template>
|
|
447
|
+
|
|
448
|
+
<script setup lang="ts">
|
|
449
|
+
import { ref, watch } from "vue";
|
|
450
|
+
import { getLocaleName } from "intlayer";
|
|
451
|
+
import { useLocale } from "vue-intlayer";
|
|
452
|
+
|
|
453
|
+
// 获取语言环境信息和 setLocale 函数
|
|
454
|
+
const { locale, availableLocales, setLocale } = useLocale();
|
|
455
|
+
|
|
456
|
+
// 使用 ref 跟踪选定的语言环境
|
|
457
|
+
const selectedLocale = ref(locale.value);
|
|
458
|
+
|
|
459
|
+
// 当选择更改时更新语言环境
|
|
460
|
+
const changeLocale = () => setLocale(selectedLocale.value);
|
|
461
|
+
|
|
462
|
+
// 将 selectedLocale 与全局语言环境保持同步
|
|
463
|
+
watch(
|
|
464
|
+
() => locale.value,
|
|
465
|
+
(newLocale) => {
|
|
466
|
+
selectedLocale.value = newLocale;
|
|
467
|
+
}
|
|
468
|
+
);
|
|
469
|
+
</script>
|
|
470
|
+
</template>
|
|
471
|
+
|
|
472
|
+
<style scoped>
|
|
473
|
+
.locale-switcher {
|
|
474
|
+
margin: 1rem 0;
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
select {
|
|
478
|
+
padding: 0.5rem;
|
|
479
|
+
border-radius: 0.25rem;
|
|
480
|
+
border: 1px solid #ccc;
|
|
481
|
+
}
|
|
482
|
+
</style>
|
|
483
|
+
```
|
|
484
|
+
|
|
485
|
+
然后,在您的页面或布局中使用此组件:
|
|
486
|
+
|
|
487
|
+
```vue fileName="app.vue"
|
|
488
|
+
<script setup lang="ts">
|
|
489
|
+
import { useIntlayer } from "vue-intlayer";
|
|
490
|
+
import LocaleSwitcher from "~/components/LocaleSwitcher.vue";
|
|
491
|
+
|
|
492
|
+
const content = useIntlayer("app"); // 创建相关的 intlayer 声明文件
|
|
493
|
+
</script>
|
|
494
|
+
|
|
495
|
+
<template>
|
|
496
|
+
<div>
|
|
497
|
+
<header>
|
|
498
|
+
<LocaleSwitcher />
|
|
499
|
+
</header>
|
|
500
|
+
<main>
|
|
501
|
+
<NuxtPage />
|
|
502
|
+
</main>
|
|
503
|
+
</div>
|
|
504
|
+
</template>
|
|
505
|
+
```
|
|
506
|
+
|
|
507
|
+
### (可选)第七步:为您的应用程序添加本地化路由
|
|
508
|
+
|
|
509
|
+
使用 `nuxt-intlayer` 模块时,Nuxt 会自动处理本地化路由。这会根据您的页面目录结构为每种语言自动创建路由。
|
|
510
|
+
|
|
511
|
+
示例:
|
|
512
|
+
|
|
513
|
+
```plaintext
|
|
514
|
+
pages/
|
|
515
|
+
├── index.vue → /, /zh, /fr, /es
|
|
516
|
+
├── about.vue → /about, /zh/about, /fr/about, /es/about
|
|
517
|
+
└── contact/
|
|
518
|
+
└── index.vue → /contact, /zh/contact, /fr/contact, /es/contact
|
|
519
|
+
```
|
|
520
|
+
|
|
521
|
+
要创建本地化页面,只需在 `pages/` 目录中创建您的 Vue 文件:
|
|
522
|
+
|
|
523
|
+
```vue fileName="pages/about.vue"
|
|
524
|
+
<script setup lang="ts">
|
|
525
|
+
import { useIntlayer } from "vue-intlayer";
|
|
526
|
+
|
|
527
|
+
const content = useIntlayer("about");
|
|
528
|
+
</script>
|
|
529
|
+
|
|
530
|
+
<template>
|
|
531
|
+
<div>
|
|
532
|
+
<h1>{{ content.title }}</h1>
|
|
533
|
+
<p>{{ content.description }}</p>
|
|
534
|
+
</div>
|
|
535
|
+
</template>
|
|
536
|
+
```
|
|
537
|
+
|
|
538
|
+
`nuxt-intlayer` 模块将自动:
|
|
539
|
+
|
|
540
|
+
- 检测用户的首选语言环境
|
|
541
|
+
- 通过 URL 处理语言环境切换
|
|
542
|
+
- 设置适当的 `<html lang="">` 属性
|
|
543
|
+
- 管理语言环境 Cookie
|
|
544
|
+
- 将用户重定向到适当的本地化 URL
|
|
545
|
+
|
|
546
|
+
### (可选)第八步:创建本地化链接组件
|
|
547
|
+
|
|
548
|
+
为了确保您的应用程序导航符合当前语言环境,您可以创建一个自定义 `LocalizedLink` 组件。此组件会自动为内部 URL 添加当前语言的前缀。
|
|
549
|
+
|
|
550
|
+
```vue fileName="components/LocalizedLink.vue"
|
|
551
|
+
<template>
|
|
552
|
+
<NuxtLink :to="localizedHref" v-bind="$attrs">
|
|
553
|
+
<slot />
|
|
554
|
+
</NuxtLink>
|
|
555
|
+
</template>
|
|
556
|
+
|
|
557
|
+
<script setup lang="ts">
|
|
558
|
+
import { computed } from "vue";
|
|
559
|
+
import { getLocalizedUrl } from "intlayer";
|
|
560
|
+
import { useLocale } from "vue-intlayer";
|
|
561
|
+
|
|
562
|
+
const props = defineProps({
|
|
563
|
+
to: {
|
|
564
|
+
type: String,
|
|
565
|
+
required: true,
|
|
566
|
+
},
|
|
567
|
+
});
|
|
568
|
+
|
|
569
|
+
const { locale } = useLocale();
|
|
570
|
+
|
|
571
|
+
// 检查链接是否为外部链接
|
|
572
|
+
const isExternalLink = computed(() => /^https?:\/\//.test(props.to || ""));
|
|
573
|
+
|
|
574
|
+
// 为内部链接创建本地化 href
|
|
575
|
+
const localizedHref = computed(() =>
|
|
576
|
+
isExternalLink.value ? props.to : getLocalizedUrl(props.to, locale.value)
|
|
577
|
+
);
|
|
578
|
+
</script>
|
|
579
|
+
```
|
|
580
|
+
|
|
581
|
+
然后在整个应用程序中使用此组件:
|
|
582
|
+
|
|
583
|
+
```vue fileName="pages/index.vue"
|
|
584
|
+
<template>
|
|
585
|
+
<div>
|
|
586
|
+
<LocalizedLink to="/about">
|
|
587
|
+
{{ content.aboutLink }}
|
|
588
|
+
</LocalizedLink>
|
|
589
|
+
|
|
590
|
+
<LocalizedLink to="/zh/contact">
|
|
591
|
+
{{ content.contactLink }}
|
|
592
|
+
</LocalizedLink>
|
|
593
|
+
</div>
|
|
594
|
+
</template>
|
|
595
|
+
|
|
596
|
+
<script setup lang="ts">
|
|
597
|
+
import { useIntlayer } from "vue-intlayer";
|
|
598
|
+
import LocalizedLink from "~/components/LocalizedLink.vue";
|
|
599
|
+
|
|
600
|
+
const content = useIntlayer("home");
|
|
601
|
+
</script>
|
|
602
|
+
```
|
|
603
|
+
|
|
604
|
+
### (可选)步骤 9:处理元数据和 SEO
|
|
605
|
+
|
|
606
|
+
Nuxt 提供了出色的 SEO 功能。您可以使用 Intlayer 来处理本地化的元数据:
|
|
607
|
+
|
|
608
|
+
```vue fileName="pages/about.vue"
|
|
609
|
+
<script setup lang="ts">
|
|
610
|
+
import { useSeoMeta } from "nuxt/app";
|
|
611
|
+
import { getIntlayer } from "intlayer";
|
|
612
|
+
import { useLocale } from "vue-intlayer";
|
|
613
|
+
|
|
614
|
+
const { locale } = useLocale();
|
|
615
|
+
const content = getIntlayer("about-meta", locale.value);
|
|
616
|
+
|
|
617
|
+
useSeoMeta({
|
|
618
|
+
title: content.title,
|
|
619
|
+
description: content.description,
|
|
620
|
+
});
|
|
621
|
+
</script>
|
|
622
|
+
|
|
623
|
+
<template>
|
|
624
|
+
<div>
|
|
625
|
+
<h1>{{ content.pageTitle }}</h1>
|
|
626
|
+
<p>{{ content.pageContent }}</p>
|
|
627
|
+
</div>
|
|
628
|
+
</template>
|
|
629
|
+
```
|
|
630
|
+
|
|
631
|
+
创建相应的内容声明:
|
|
632
|
+
|
|
633
|
+
```typescript fileName="pages/about-meta.content.ts" contentDeclarationFormat="typescript"
|
|
634
|
+
import { t, type Dictionary } from "intlayer";
|
|
635
|
+
import type { useSeoMeta } from "nuxt/app";
|
|
636
|
+
|
|
637
|
+
const aboutMetaContent = {
|
|
638
|
+
key: "about-meta",
|
|
639
|
+
content: {
|
|
640
|
+
title: t({
|
|
641
|
+
zh: "关于我们 - 我的公司",
|
|
642
|
+
en: "About Us - My Company",
|
|
643
|
+
fr: "À Propos - Ma Société",
|
|
644
|
+
es: "Acerca de Nosotros - Mi Empresa",
|
|
645
|
+
}),
|
|
646
|
+
description: t({
|
|
647
|
+
zh: "了解更多关于我们公司和我们的使命",
|
|
648
|
+
en: "Learn more about our company and our mission",
|
|
649
|
+
fr: "En savoir plus sur notre société et notre mission",
|
|
650
|
+
es: "Conozca más sobre nuestra empresa y nuestra misión",
|
|
651
|
+
}),
|
|
652
|
+
},
|
|
653
|
+
} satisfies Dictionary<Parameters<typeof useSeoMeta>[0]>;
|
|
654
|
+
|
|
655
|
+
export default aboutMetaContent;
|
|
656
|
+
```
|
|
657
|
+
|
|
658
|
+
```typescript fileName="pages/about-meta.content.mjs" contentDeclarationFormat="esm"
|
|
659
|
+
import { t } from "intlayer";
|
|
660
|
+
|
|
661
|
+
/** @type {import('intlayer').Dictionary} */
|
|
662
|
+
const aboutMetaContent = {
|
|
663
|
+
key: "about-meta",
|
|
664
|
+
content: {
|
|
665
|
+
title: t({
|
|
666
|
+
zh: "关于我们 - 我的公司",
|
|
667
|
+
en: "About Us - My Company",
|
|
668
|
+
fr: "À Propos - Ma Société",
|
|
669
|
+
es: "Acerca de Nosotros - Mi Empresa",
|
|
670
|
+
}),
|
|
671
|
+
description: t({
|
|
672
|
+
zh: "了解更多关于我们公司和我们的使命",
|
|
673
|
+
en: "Learn more about our company and our mission",
|
|
674
|
+
fr: "En savoir plus sur notre société et notre mission",
|
|
675
|
+
es: "Conozca más sobre nuestra empresa y nuestra misión",
|
|
676
|
+
}),
|
|
677
|
+
},
|
|
678
|
+
};
|
|
679
|
+
|
|
680
|
+
export default aboutMetaContent;
|
|
681
|
+
```
|
|
682
|
+
|
|
683
|
+
```typescript fileName="pages/about-meta.content.js" contentDeclarationFormat="cjs"
|
|
684
|
+
const { t } = require("intlayer");
|
|
685
|
+
|
|
686
|
+
/** @type {import('intlayer').Dictionary} */
|
|
687
|
+
const aboutMetaContent = {
|
|
688
|
+
key: "about-meta",
|
|
689
|
+
content: {
|
|
690
|
+
title: t({
|
|
691
|
+
zh: "关于我们 - 我的公司",
|
|
692
|
+
en: "About Us - My Company",
|
|
693
|
+
fr: "À Propos - Ma Société",
|
|
694
|
+
es: "Acerca de Nosotros - Mi Empresa",
|
|
695
|
+
}),
|
|
696
|
+
description: t({
|
|
697
|
+
zh: "了解更多关于我们公司和我们的使命",
|
|
698
|
+
en: "Learn more about our company and our mission",
|
|
699
|
+
fr: "En savoir plus sur notre société et notre mission",
|
|
700
|
+
es: "Conozca más sobre nuestra empresa y nuestra misión",
|
|
701
|
+
}),
|
|
702
|
+
},
|
|
703
|
+
};
|
|
704
|
+
|
|
705
|
+
module.exports = aboutMetaContent;
|
|
706
|
+
```
|
|
707
|
+
|
|
708
|
+
```json fileName="pages/about-meta.content.json" contentDeclarationFormat="json"
|
|
709
|
+
{
|
|
710
|
+
"key": "about-meta",
|
|
711
|
+
"content": {
|
|
712
|
+
"title": {
|
|
713
|
+
"nodeType": "translation",
|
|
714
|
+
"translations": {
|
|
715
|
+
"zh": "关于我们 - 我的公司",
|
|
716
|
+
"en": "About Us - My Company",
|
|
717
|
+
"fr": "À Propos - Ma Société",
|
|
718
|
+
"es": "Acerca de Nosotros - Mi Empresa"
|
|
719
|
+
}
|
|
720
|
+
},
|
|
721
|
+
"description": {
|
|
722
|
+
"nodeType": "translation",
|
|
723
|
+
"translations": {
|
|
724
|
+
"zh": "了解更多关于我们公司和我们的使命",
|
|
725
|
+
"en": "Learn more about our company and our mission",
|
|
726
|
+
"fr": "En savoir plus sur notre société et notre mission",
|
|
727
|
+
"es": "Conozca más sobre nuestra empresa y nuestra misión"
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
```
|
|
733
|
+
|
|
734
|
+
### 配置 TypeScript
|
|
735
|
+
|
|
736
|
+
Intlayer 使用模块增强来利用 TypeScript 的优势,使您的代码库更强大。
|
|
737
|
+
|
|
738
|
+

|
|
739
|
+
|
|
740
|
+

|
|
741
|
+
|
|
742
|
+
确保您的 TypeScript 配置包含自动生成的类型。
|
|
743
|
+
|
|
744
|
+
```json5 fileName="tsconfig.json"
|
|
745
|
+
{
|
|
746
|
+
// ... 您现有的 TypeScript 配置
|
|
747
|
+
"include": [
|
|
748
|
+
// ... 您现有的 TypeScript 配置
|
|
749
|
+
".intlayer/**/*.ts", // 包含自动生成的类型
|
|
750
|
+
],
|
|
751
|
+
}
|
|
752
|
+
```
|
|
753
|
+
|
|
754
|
+
### Git 配置
|
|
755
|
+
|
|
756
|
+
建议忽略由 Intlayer 生成的文件。这可以避免将它们提交到您的 Git 仓库中。
|
|
757
|
+
|
|
758
|
+
为此,您可以将以下指令添加到 `.gitignore` 文件中:
|
|
759
|
+
|
|
760
|
+
```plaintext fileName=".gitignore"
|
|
761
|
+
# 忽略由 Intlayer 生成的文件
|
|
762
|
+
.intlayer
|
|
763
|
+
```
|
|
764
|
+
|
|
765
|
+
### VS Code 扩展
|
|
766
|
+
|
|
767
|
+
为了改善您使用 Intlayer 的开发体验,您可以安装官方的 **Intlayer VS Code 扩展**。
|
|
768
|
+
|
|
769
|
+
[从 VS Code Marketplace 安装](https://marketplace.visualstudio.com/items?itemName=intlayer.intlayer-vs-code-extension)
|
|
770
|
+
|
|
771
|
+
此扩展提供:
|
|
772
|
+
|
|
773
|
+
- **翻译键的自动补全**。
|
|
774
|
+
- **实时错误检测**,用于缺失的翻译。
|
|
775
|
+
- **翻译内容的内联预览**。
|
|
776
|
+
- **快速操作**,轻松创建和更新翻译。
|
|
777
|
+
|
|
778
|
+
有关如何使用扩展的更多详细信息,请参阅 [Intlayer VS Code 扩展文档](https://intlayer.org/doc/vs-code-extension)。
|
|
779
|
+
|
|
780
|
+
---
|
|
781
|
+
|
|
782
|
+
### 更进一步
|
|
783
|
+
|
|
784
|
+
## 要更进一步,您可以实现 [可视化编辑器](https://github.com/aymericzip/intlayer/blob/main/docs/zh/intlayer_visual_editor.md) 或使用 [CMS](https://github.com/aymericzip/intlayer/blob/main/docs/zh/intlayer_CMS.md) 外部化您的内容。
|