@intlayer/docs 8.6.0 → 8.6.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.
Files changed (197) hide show
  1. package/dist/cjs/doc.cjs.map +1 -1
  2. package/dist/cjs/generated/docs.entry.cjs +60 -0
  3. package/dist/cjs/generated/docs.entry.cjs.map +1 -1
  4. package/dist/esm/doc.mjs.map +1 -1
  5. package/dist/esm/generated/docs.entry.mjs +60 -0
  6. package/dist/esm/generated/docs.entry.mjs.map +1 -1
  7. package/dist/types/doc.d.ts.map +1 -1
  8. package/dist/types/generated/docs.entry.d.ts +3 -0
  9. package/dist/types/generated/docs.entry.d.ts.map +1 -1
  10. package/docs/ar/cli/index.md +54 -42
  11. package/docs/ar/cli/init.md +32 -20
  12. package/docs/ar/cli/standalone.md +91 -0
  13. package/docs/ar/configuration.md +39 -7
  14. package/docs/ar/custom_domains.md +250 -0
  15. package/docs/ar/intlayer_with_tanstack+solid.md +14 -33
  16. package/docs/ar/intlayer_with_tanstack.md +25 -16
  17. package/docs/ar/intlayer_with_vanilla.md +506 -0
  18. package/docs/bn/cli/index.md +195 -0
  19. package/docs/bn/cli/init.md +96 -0
  20. package/docs/bn/cli/standalone.md +91 -0
  21. package/docs/bn/configuration.md +46 -14
  22. package/docs/bn/custom_domains.md +250 -0
  23. package/docs/bn/intlayer_with_vanilla.md +506 -0
  24. package/docs/cs/cli/index.md +195 -0
  25. package/docs/cs/cli/init.md +96 -0
  26. package/docs/cs/cli/standalone.md +91 -0
  27. package/docs/cs/configuration.md +46 -7
  28. package/docs/cs/custom_domains.md +250 -0
  29. package/docs/cs/intlayer_with_vanilla.md +506 -0
  30. package/docs/de/cli/index.md +53 -41
  31. package/docs/de/cli/standalone.md +91 -0
  32. package/docs/de/configuration.md +46 -7
  33. package/docs/de/custom_domains.md +250 -0
  34. package/docs/de/intlayer_with_tanstack+solid.md +15 -36
  35. package/docs/de/intlayer_with_tanstack.md +25 -16
  36. package/docs/de/intlayer_with_vanilla.md +506 -0
  37. package/docs/en/bundle_optimization.md +288 -23
  38. package/docs/en/cli/index.md +6 -1
  39. package/docs/en/cli/init.md +13 -1
  40. package/docs/en/cli/standalone.md +91 -0
  41. package/docs/en/configuration.md +46 -7
  42. package/docs/en/custom_domains.md +245 -0
  43. package/docs/en/intlayer_with_tanstack+solid.md +15 -36
  44. package/docs/en/intlayer_with_tanstack.md +25 -16
  45. package/docs/en/intlayer_with_vanilla.md +506 -0
  46. package/docs/en-GB/cli/index.md +56 -44
  47. package/docs/en-GB/cli/init.md +28 -21
  48. package/docs/en-GB/cli/standalone.md +91 -0
  49. package/docs/en-GB/configuration.md +53 -14
  50. package/docs/en-GB/custom_domains.md +250 -0
  51. package/docs/en-GB/intlayer_with_tanstack+solid.md +15 -36
  52. package/docs/en-GB/intlayer_with_tanstack.md +25 -16
  53. package/docs/en-GB/intlayer_with_vanilla.md +506 -0
  54. package/docs/es/cli/index.md +65 -53
  55. package/docs/es/cli/init.md +33 -21
  56. package/docs/es/cli/standalone.md +91 -0
  57. package/docs/es/configuration.md +39 -1
  58. package/docs/es/custom_domains.md +250 -0
  59. package/docs/es/intlayer_with_tanstack+solid.md +15 -36
  60. package/docs/es/intlayer_with_tanstack.md +25 -16
  61. package/docs/es/intlayer_with_vanilla.md +506 -0
  62. package/docs/fr/cli/index.md +43 -31
  63. package/docs/fr/cli/init.md +37 -25
  64. package/docs/fr/cli/standalone.md +91 -0
  65. package/docs/fr/configuration.md +46 -7
  66. package/docs/fr/custom_domains.md +250 -0
  67. package/docs/fr/intlayer_with_tanstack+solid.md +15 -36
  68. package/docs/fr/intlayer_with_tanstack.md +25 -16
  69. package/docs/fr/intlayer_with_vanilla.md +506 -0
  70. package/docs/hi/cli/index.md +71 -59
  71. package/docs/hi/cli/init.md +37 -33
  72. package/docs/hi/cli/standalone.md +91 -0
  73. package/docs/hi/configuration.md +39 -7
  74. package/docs/hi/custom_domains.md +250 -0
  75. package/docs/hi/intlayer_with_tanstack+solid.md +14 -33
  76. package/docs/hi/intlayer_with_tanstack.md +25 -16
  77. package/docs/hi/intlayer_with_vanilla.md +506 -0
  78. package/docs/id/cli/index.md +59 -47
  79. package/docs/id/cli/init.md +32 -25
  80. package/docs/id/cli/standalone.md +91 -0
  81. package/docs/id/configuration.md +46 -7
  82. package/docs/id/custom_domains.md +250 -0
  83. package/docs/id/intlayer_with_tanstack+solid.md +14 -33
  84. package/docs/id/intlayer_with_tanstack.md +25 -16
  85. package/docs/id/intlayer_with_vanilla.md +506 -0
  86. package/docs/it/cli/index.md +58 -41
  87. package/docs/it/cli/init.md +37 -38
  88. package/docs/it/cli/standalone.md +91 -0
  89. package/docs/it/configuration.md +46 -7
  90. package/docs/it/custom_domains.md +250 -0
  91. package/docs/it/intlayer_with_tanstack+solid.md +15 -36
  92. package/docs/it/intlayer_with_tanstack.md +25 -16
  93. package/docs/it/intlayer_with_vanilla.md +506 -0
  94. package/docs/ja/cli/index.md +59 -47
  95. package/docs/ja/cli/init.md +36 -24
  96. package/docs/ja/cli/standalone.md +91 -0
  97. package/docs/ja/configuration.md +46 -7
  98. package/docs/ja/custom_domains.md +250 -0
  99. package/docs/ja/intlayer_with_tanstack+solid.md +15 -36
  100. package/docs/ja/intlayer_with_tanstack.md +25 -16
  101. package/docs/ja/intlayer_with_vanilla.md +506 -0
  102. package/docs/ko/cli/index.md +58 -46
  103. package/docs/ko/cli/init.md +39 -35
  104. package/docs/ko/cli/standalone.md +91 -0
  105. package/docs/ko/configuration.md +47 -8
  106. package/docs/ko/custom_domains.md +250 -0
  107. package/docs/ko/intlayer_with_tanstack+solid.md +15 -36
  108. package/docs/ko/intlayer_with_tanstack.md +25 -16
  109. package/docs/ko/intlayer_with_vanilla.md +506 -0
  110. package/docs/nl/cli/index.md +195 -0
  111. package/docs/nl/cli/init.md +96 -0
  112. package/docs/nl/cli/standalone.md +91 -0
  113. package/docs/nl/configuration.md +46 -7
  114. package/docs/nl/custom_domains.md +250 -0
  115. package/docs/nl/intlayer_with_vanilla.md +506 -0
  116. package/docs/pl/cli/index.md +56 -44
  117. package/docs/pl/cli/init.md +36 -32
  118. package/docs/pl/cli/standalone.md +91 -0
  119. package/docs/pl/configuration.md +46 -7
  120. package/docs/pl/custom_domains.md +250 -0
  121. package/docs/pl/intlayer_with_tanstack+solid.md +14 -33
  122. package/docs/pl/intlayer_with_tanstack.md +25 -16
  123. package/docs/pl/intlayer_with_vanilla.md +506 -0
  124. package/docs/pt/cli/index.md +64 -52
  125. package/docs/pt/cli/init.md +35 -31
  126. package/docs/pt/cli/standalone.md +91 -0
  127. package/docs/pt/configuration.md +46 -7
  128. package/docs/pt/custom_domains.md +250 -0
  129. package/docs/pt/intlayer_with_tanstack+solid.md +15 -36
  130. package/docs/pt/intlayer_with_tanstack.md +25 -16
  131. package/docs/pt/intlayer_with_vanilla.md +506 -0
  132. package/docs/ru/cli/index.md +54 -42
  133. package/docs/ru/cli/init.md +31 -27
  134. package/docs/ru/cli/standalone.md +91 -0
  135. package/docs/ru/configuration.md +46 -7
  136. package/docs/ru/custom_domains.md +250 -0
  137. package/docs/ru/intlayer_with_tanstack+solid.md +15 -36
  138. package/docs/ru/intlayer_with_tanstack.md +25 -16
  139. package/docs/ru/intlayer_with_vanilla.md +506 -0
  140. package/docs/tr/cli/index.md +64 -52
  141. package/docs/tr/cli/init.md +37 -30
  142. package/docs/tr/cli/standalone.md +91 -0
  143. package/docs/tr/configuration.md +46 -7
  144. package/docs/tr/custom_domains.md +250 -0
  145. package/docs/tr/intlayer_with_tanstack+solid.md +14 -33
  146. package/docs/tr/intlayer_with_tanstack.md +25 -16
  147. package/docs/tr/intlayer_with_vanilla.md +506 -0
  148. package/docs/uk/cli/index.md +60 -55
  149. package/docs/uk/cli/init.md +32 -20
  150. package/docs/uk/cli/standalone.md +91 -0
  151. package/docs/uk/configuration.md +46 -7
  152. package/docs/uk/custom_domains.md +250 -0
  153. package/docs/uk/intlayer_with_tanstack+solid.md +14 -33
  154. package/docs/uk/intlayer_with_tanstack.md +25 -16
  155. package/docs/uk/intlayer_with_vanilla.md +506 -0
  156. package/docs/ur/cli/index.md +195 -0
  157. package/docs/ur/cli/init.md +96 -0
  158. package/docs/ur/cli/standalone.md +91 -0
  159. package/docs/ur/configuration.md +46 -7
  160. package/docs/ur/custom_domains.md +250 -0
  161. package/docs/ur/intlayer_with_vanilla.md +506 -0
  162. package/docs/vi/cli/index.md +72 -61
  163. package/docs/vi/cli/init.md +33 -21
  164. package/docs/vi/cli/standalone.md +91 -0
  165. package/docs/vi/configuration.md +46 -7
  166. package/docs/vi/custom_domains.md +250 -0
  167. package/docs/vi/intlayer_with_tanstack+solid.md +14 -33
  168. package/docs/vi/intlayer_with_tanstack.md +25 -16
  169. package/docs/vi/intlayer_with_vanilla.md +506 -0
  170. package/docs/zh/cli/index.md +56 -49
  171. package/docs/zh/cli/init.md +30 -18
  172. package/docs/zh/cli/standalone.md +91 -0
  173. package/docs/zh/configuration.md +46 -7
  174. package/docs/zh/custom_domains.md +250 -0
  175. package/docs/zh/intlayer_with_tanstack+solid.md +15 -36
  176. package/docs/zh/intlayer_with_tanstack.md +25 -16
  177. package/docs/zh/intlayer_with_vanilla.md +506 -0
  178. package/package.json +8 -8
  179. package/src/doc.ts +4 -1
  180. package/src/generated/docs.entry.ts +60 -0
  181. package/docs/ar/bundle_optimization.md +0 -185
  182. package/docs/de/bundle_optimization.md +0 -195
  183. package/docs/en-GB/bundle_optimization.md +0 -184
  184. package/docs/es/bundle_optimization.md +0 -194
  185. package/docs/fr/bundle_optimization.md +0 -184
  186. package/docs/hi/bundle_optimization.md +0 -185
  187. package/docs/id/bundle_optimization.md +0 -185
  188. package/docs/it/bundle_optimization.md +0 -185
  189. package/docs/ja/bundle_optimization.md +0 -185
  190. package/docs/ko/bundle_optimization.md +0 -185
  191. package/docs/pl/bundle_optimization.md +0 -185
  192. package/docs/pt/bundle_optimization.md +0 -184
  193. package/docs/ru/bundle_optimization.md +0 -185
  194. package/docs/tr/bundle_optimization.md +0 -184
  195. package/docs/uk/bundle_optimization.md +0 -186
  196. package/docs/vi/bundle_optimization.md +0 -185
  197. package/docs/zh/bundle_optimization.md +0 -185
@@ -0,0 +1,506 @@
1
+ ---
2
+ createdAt: 2026-03-31
3
+ updatedAt: 2026-03-31
4
+ title: Vanilla JS i18n - 2026 年如何翻译 Vanilla JS 应用
5
+ description: 了解如何让您的 Vanilla JS 网站支持多语言。按照文档进行国际化 (i18n) 和翻译。
6
+ keywords:
7
+ - 国际化
8
+ - 文档
9
+ - Intlayer
10
+ - Vanilla JS
11
+ - JavaScript
12
+ - TypeScript
13
+ - HTML
14
+ slugs:
15
+ - doc
16
+ - environment
17
+ - vanilla
18
+ applicationTemplate: https://github.com/aymericzip/intlayer-vanilla-template
19
+ history:
20
+ - version: 8.4.10
21
+ date: 2026-03-31
22
+ changes: "初始化历史记录"
23
+ ---
24
+
25
+ # 使用 Intlayer 翻译您的 Vanilla JS 网站 | 国际化 (i18n)
26
+
27
+ ## 目录
28
+
29
+ <TOC/>
30
+
31
+ ## 什么是 Intlayer?
32
+
33
+ **Intlayer** 是一个创新的开源国际化 (i18n) 库,旨在简化现代 Web 应用中的多语言支持。
34
+
35
+ 借助 Intlayer,您可以:
36
+
37
+ - **轻松管理翻译**:在组件级使用声明式字典。
38
+ - **动态本地化元数据、路由和内容**。
39
+ - **确保 TypeScript 支持**:通过自动生成的类型,提升自动补全和错误检测能力。
40
+ - **受益于高级功能**:例如动态语言检测和切换。
41
+
42
+ 本指南演示了如何在**不使用包管理器或构建工具**(如 Vite、Webpack 等)的情况下,在 Vanilla JavaScript 应用中使用 Intlayer。
43
+
44
+ 如果您的应用使用了构建工具(如 Vite),我们建议参考 [Vite + Vanilla JS 指南](https://github.com/aymericzip/intlayer/blob/main/docs/docs/zh/intlayer_with_vite+vanilla.md)。
45
+
46
+ 使用独立版本 (standalone bundle),您可以通过单个 JavaScript 文件直接在 HTML 文件中导入 Intlayer,非常适合旧项目或简单的静态网站。
47
+
48
+ ---
49
+
50
+ ## 在 Vanilla JS 应用中设置 Intlayer 的步骤指南
51
+
52
+ ### 第一步:安装依赖
53
+
54
+ 使用 npm 安装必要的包:
55
+
56
+ ```bash packageManager="npm"
57
+ # 生成 intlayer 和 vanilla-intlayer 的独立 bundle
58
+ # 此文件将导入到您的 HTML 文件中
59
+ npx intlayer standalone --packages intlayer vanilla-intlayer --outfile intlayer.js
60
+
61
+ # 使用配置文件初始化 intlayer
62
+ npx intlayer init --no-gitignore
63
+
64
+ # 构建字典
65
+ npx intlayer build
66
+ ```
67
+
68
+ ```bash packageManager="pnpm"
69
+ # 生成 intlayer 和 vanilla-intlayer 的独立 bundle
70
+ # 此文件将导入到您的 HTML 文件中
71
+ pnpm intlayer standalone --packages intlayer vanilla-intlayer --outfile intlayer.js
72
+
73
+ # 使用配置文件初始化 intlayer
74
+ pnpm intlayer init --no-gitignore
75
+
76
+ # 构建字典
77
+ pnpm intlayer build
78
+ ```
79
+
80
+ ```bash packageManager="yarn"
81
+ # 生成 intlayer 和 vanilla-intlayer 的独立 bundle
82
+ # 此文件将导入到您的 HTML 文件中
83
+ yarn intlayer standalone --packages intlayer vanilla-intlayer --outfile intlayer.js
84
+
85
+ # 初始化 intlayer 配置文件、TypeScript(如果已设置)、环境变量
86
+ yarn intlayer init --no-gitignore
87
+
88
+ # 构建字典
89
+ yarn intlayer build
90
+ ```
91
+
92
+ ```bash packageManager="bun"
93
+ # 生成 intlayer 和 vanilla-intlayer 的独立 bundle
94
+ # 此文件将导入到您的 HTML 文件中
95
+ bun x intlayer standalone --packages intlayer vanilla-intlayer --outfile intlayer.js
96
+
97
+ # 使用配置文件初始化 intlayer
98
+ bun x intlayer init --no-gitignore
99
+
100
+ # 构建字典
101
+ bun x intlayer build
102
+ ```
103
+
104
+ - **intlayer**
105
+ 核心包,用于配置管理、翻译、[内容声明](https://github.com/aymericzip/intlayer/blob/main/docs/docs/zh/dictionary/content_file.md)、转译和 [CLI 命令](https://github.com/aymericzip/intlayer/blob/main/docs/docs/zh/cli/index.md)的国际化工具。
106
+
107
+ - **vanilla-intlayer**
108
+ 将 Intlayer 与纯 JavaScript / TypeScript 应用集成的包。它提供了一个发布/订阅单例 (`IntlayerClient`) 和基于回调的辅助函数 (`useIntlayer`、`useLocale` 等),使您应用的任何部分都能在不依赖 UI 框架的情况下响应语言更改。
109
+
110
+ > `intlayer standalone` CLI 的打包导出通过对您的配置中未使用的包、语言区域和非必要逻辑(如重定向或前缀)进行摇树优化(tree-shaking)来生成优化的构建版本。
111
+
112
+ ### 第二步:项目配置
113
+
114
+ 创建一个配置文件以配置您应用的语言:
115
+
116
+ ```typescript fileName="intlayer.config.ts" codeFormat="typescript"
117
+ import { Locales, type IntlayerConfig } from "intlayer";
118
+
119
+ const config: IntlayerConfig = {
120
+ internationalization: {
121
+ locales: [
122
+ Locales.ENGLISH,
123
+ Locales.FRENCH,
124
+ Locales.SPANISH,
125
+ // 您的其他语言
126
+ ],
127
+ defaultLocale: Locales.ENGLISH,
128
+ },
129
+ };
130
+
131
+ export default config;
132
+ ```
133
+
134
+ ```javascript fileName="intlayer.config.mjs" codeFormat="esm"
135
+ import { Locales } from "intlayer";
136
+
137
+ /** @type {import('intlayer').IntlayerConfig} */
138
+ const config = {
139
+ internationalization: {
140
+ locales: [
141
+ Locales.ENGLISH,
142
+ Locales.FRENCH,
143
+ Locales.SPANISH,
144
+ // 您的其他语言
145
+ ],
146
+ defaultLocale: Locales.ENGLISH,
147
+ },
148
+ };
149
+
150
+ export default config;
151
+ ```
152
+
153
+ ```javascript fileName="intlayer.config.cjs" codeFormat="commonjs"
154
+ const { Locales } = require("intlayer");
155
+
156
+ /** @type {import('intlayer').IntlayerConfig} */
157
+ const config = {
158
+ internationalization: {
159
+ locales: [
160
+ Locales.ENGLISH,
161
+ Locales.FRENCH,
162
+ Locales.SPANISH,
163
+ // 您的其他语言
164
+ ],
165
+ defaultLocale: Locales.ENGLISH,
166
+ },
167
+ };
168
+
169
+ module.exports = config;
170
+ ```
171
+
172
+ > 通过此配置文件,您可以设置本地化 URL、中间件重定向、Cookie 名称、内容声明的位置和扩展名、禁用控制台中的 Intlayer 日志等。有关可用参数的完整列表,请参阅[配置文档](https://github.com/aymericzip/intlayer/blob/main/docs/docs/zh/configuration.md)。
173
+
174
+ ### 第三步:在 HTML 中导入 bundle
175
+
176
+ 生成 `intlayer.js` bundle 后,您可以将其导入到 HTML 文件中:
177
+
178
+ ```html fileName="index.html"
179
+ <!DOCTYPE html>
180
+ <html lang="zh">
181
+ <head>
182
+ <meta charset="UTF-8" />
183
+
184
+ <!-- 导入 bundle -->
185
+ <script src="./intlayer.js" defer></script>
186
+ <!-- 导入您的主脚本 -->
187
+ <script src="./src/main.js" defer></script>
188
+ </head>
189
+ <body>
190
+ <h1 id="title"></h1>
191
+ <p class="read-the-docs"></p>
192
+ </body>
193
+ </html>
194
+ ```
195
+
196
+ 该 bundle 会将 `Intlayer` 和 `VanillaIntlayer` 暴露为 `window` 上的全局对象。
197
+
198
+ ### 第四步:在入口点引导 Intlayer
199
+
200
+ 在 `src/main.js` 中,**在**渲染任何内容之前调用 `installIntlayer()`,以便全局语言单例准备就绪。
201
+
202
+ ```javascript fileName="src/main.js"
203
+ const { installIntlayer } = window.VanillaIntlayer;
204
+
205
+ // 必须在渲染任何 i18n 内容之前调用。
206
+ installIntlayer();
207
+ ```
208
+
209
+ 如果您还想使用 Markdown 渲染器,请调用 `installIntlayerMarkdown()`:
210
+
211
+ ```javascript fileName="src/main.js"
212
+ const { installIntlayer, installIntlayerMarkdown } = window.VanillaIntlayer;
213
+
214
+ installIntlayer();
215
+ installIntlayerMarkdown();
216
+ ```
217
+
218
+ ### 第五步:声明您的内容
219
+
220
+ 创建并管理您的内容声明以存储翻译:
221
+
222
+ ```typescript fileName="src/app.content.ts" contentDeclarationFormat="typescript"
223
+ import { insert, t, type Dictionary } from "intlayer";
224
+
225
+ const appContent = {
226
+ key: "app",
227
+ content: {
228
+ title: "Vite + Vanilla",
229
+
230
+ viteLogoLabel: t({
231
+ en: "Vite Logo",
232
+ fr: "Logo Vite",
233
+ es: "Logo Vite",
234
+ }),
235
+
236
+ count: insert(
237
+ t({
238
+ en: "count is {{count}}",
239
+ fr: "le compte est {{count}}",
240
+ es: "el recuento es {{count}}",
241
+ })
242
+ ),
243
+
244
+ readTheDocs: t({
245
+ en: "Click on the Vite logo to learn more",
246
+ fr: "Cliquez sur le logo Vite pour en savoir plus",
247
+ es: "Haga clic en el logotipo de Vite para obtener más información",
248
+ }),
249
+ },
250
+ } satisfies Dictionary;
251
+
252
+ export default appContent;
253
+ ```
254
+
255
+ ```javascript fileName="src/app.content.mjs" contentDeclarationFormat="esm"
256
+ import { insert, t } from "intlayer";
257
+
258
+ /** @type {import('intlayer').Dictionary} */
259
+ const appContent = {
260
+ key: "app",
261
+ content: {
262
+ title: "Vite + Vanilla",
263
+
264
+ viteLogoLabel: t({
265
+ en: "Vite Logo",
266
+ fr: "Logo Vite",
267
+ es: "Logo Vite",
268
+ }),
269
+
270
+ count: insert(
271
+ t({
272
+ en: "count is {{count}}",
273
+ fr: "le compte est {{count}}",
274
+ es: "el recuento es {{count}}",
275
+ })
276
+ ),
277
+
278
+ readTheDocs: t({
279
+ en: "Click on the Vite logo to learn more",
280
+ fr: "Cliquez sur le logo Vite pour en savoir plus",
281
+ es: "Haga clic en el logotipo de Vite para obtener más información",
282
+ }),
283
+ },
284
+ };
285
+
286
+ export default appContent;
287
+ ```
288
+
289
+ ```javascript fileName="src/app.content.cjs" contentDeclarationFormat="commonjs"
290
+ const { insert, t } = require("intlayer");
291
+
292
+ /** @type {import('intlayer').Dictionary} */
293
+ const appContent = {
294
+ key: "app",
295
+ content: {
296
+ title: "Vite + Vanilla",
297
+
298
+ viteLogoLabel: t({
299
+ en: "Vite Logo",
300
+ fr: "Logo Vite",
301
+ es: "Logo Vite",
302
+ }),
303
+
304
+ count: insert(
305
+ t({
306
+ en: "count is {{count}}",
307
+ fr: "le compte est {{count}}",
308
+ es: "el recuento es {{count}}",
309
+ })
310
+ ),
311
+
312
+ readTheDocs: t({
313
+ en: "Click on the Vite logo to learn more",
314
+ fr: "Cliquez sur le logo Vite pour en savoir plus",
315
+ es: "点击 Vite 徽标了解更多信息",
316
+ }),
317
+ },
318
+ };
319
+
320
+ module.exports = appContent;
321
+ ```
322
+
323
+ ```json fileName="src/app.content.json" contentDeclarationFormat="json"
324
+ {
325
+ "$schema": "https://intlayer.org/schema.json",
326
+ "key": "app",
327
+ "content": {
328
+ "title": "Vite + Vanilla",
329
+ "viteLogoLabel": {
330
+ "nodeType": "translation",
331
+ "translation": {
332
+ "en": "Vite Logo",
333
+ "fr": "Logo Vite",
334
+ "es": "Logo Vite"
335
+ }
336
+ },
337
+ "count": {
338
+ "nodeType": "insertion",
339
+ "insertion": {
340
+ "nodeType": "translation",
341
+ "translation": {
342
+ "en": "count is {{count}}",
343
+ "fr": "le compte est {{count}}",
344
+ "es": "el recuento es {{count}}"
345
+ }
346
+ }
347
+ },
348
+ "readTheDocs": {
349
+ "nodeType": "translation",
350
+ "translation": {
351
+ "en": "Click on the Vite logo to learn more",
352
+ "fr": "Cliquez sur le logo Vite pour en savoir plus",
353
+ "es": "Haga clic en el logotipo de Vite para obtener más información"
354
+ }
355
+ }
356
+ }
357
+ }
358
+ ```
359
+
360
+ > 只要您的内容声明包含在 `contentDir` 目录(默认为 `./src`)中,并且符合内容声明文件扩展名(默认为 `.content.{json,ts,tsx,js,jsx,mjs,cjs}`),您可以在应用的任何位置定义它们。
361
+ >
362
+ > 有关更多详细信息,请参阅[内容声明文档](https://github.com/aymericzip/intlayer/blob/main/docs/docs/zh/dictionary/content_file.md)。
363
+
364
+ ### 第六步:在 JavaScript 中使用 Intlayer
365
+
366
+ `window.VanillaIntlayer` 对象提供了 API 辅助函数:`useIntlayer(key, locale?)` 返回给定键的翻译内容。
367
+
368
+ ```javascript fileName="src/main.js"
369
+ const { installIntlayer, useIntlayer } = window.VanillaIntlayer;
370
+
371
+ installIntlayer();
372
+
373
+ // 获取当前语言的初始内容。
374
+ // 链式调用 .onChange() 以在语言更改时获得通知。
375
+ const content = useIntlayer("app").onChange((newContent) => {
376
+ // 仅重新渲染或修补受影响的 DOM 节点
377
+ document.querySelector("h1").textContent = String(newContent.title);
378
+ document.querySelector(".read-the-docs").textContent = String(
379
+ newContent.readTheDocs
380
+ );
381
+ });
382
+
383
+ // 初始渲染
384
+ document.querySelector("h1").textContent = String(content.title);
385
+ document.querySelector(".read-the-docs").textContent = String(
386
+ content.readTheDocs
387
+ );
388
+ ```
389
+
390
+ > 通过将叶子节点值包裹在 `String()` 中,将其作为字符串访问,这将调用节点的 `toString()` 方法并返回翻译后的文本。
391
+ >
392
+ > 当您需要原生 HTML 属性(如 `alt`、`aria-label`)的值时,请直接使用 `.value`:
393
+ >
394
+ > ```javascript
395
+ > img.alt = content.viteLogoLabel.value;
396
+ > ```
397
+
398
+ ### (可选)第七步:更改内容语言
399
+
400
+ 要更改内容的语言,请使用 `useLocale` 暴露的 `setLocale` 函数。
401
+
402
+ ```javascript fileName="src/locale-switcher.js"
403
+ const { getLocaleName } = window.Intlayer;
404
+ const { useLocale } = window.VanillaIntlayer;
405
+
406
+ export function setupLocaleSwitcher(container) {
407
+ const { locale, availableLocales, setLocale, subscribe } = useLocale();
408
+
409
+ const select = document.createElement("select");
410
+ select.setAttribute("aria-label", "语言");
411
+
412
+ const render = (currentLocale) => {
413
+ select.innerHTML = availableLocales
414
+ .map(
415
+ (loc) =>
416
+ `<option value="${loc}"${loc === currentLocale ? " selected" : ""}>
417
+ ${getLocaleName(loc)}
418
+ </option>`
419
+ )
420
+ .join("");
421
+ };
422
+
423
+ render(locale);
424
+ container.appendChild(select);
425
+
426
+ select.addEventListener("change", () => setLocale(select.value));
427
+
428
+ // 当从其他地方更改语言时,保持下拉菜单同步
429
+ return subscribe((newLocale) => render(newLocale));
430
+ }
431
+ ```
432
+
433
+ ### (可选)第八步:切换 HTML 语言和方向属性
434
+
435
+ 根据当前语言更新 `<html>` 标签的 `lang` 和 `dir` 属性,以满足辅助功能和 SEO 的要求。
436
+
437
+ ```javascript fileName="src/main.js"
438
+ const { getHTMLTextDir } = window.Intlayer;
439
+ const { installIntlayer, useLocale } = window.VanillaIntlayer;
440
+
441
+ installIntlayer();
442
+
443
+ useLocale({
444
+ onLocaleChange: (locale) => {
445
+ document.documentElement.lang = locale;
446
+ document.documentElement.dir = getHTMLTextDir(locale);
447
+ },
448
+ });
449
+ ```
450
+
451
+ ### (可选)第九步:按需加载(Lazy-load)语言字典
452
+
453
+ 如果您想按需加载字典,可以使用 `useDictionaryDynamic`。如果您不想在初始的 `intlayer.js` 文件中打包所有翻译,这非常有用。
454
+
455
+ ```javascript fileName="src/app.js"
456
+ const { installIntlayer, useDictionaryDynamic } = window.VanillaIntlayer;
457
+
458
+ installIntlayer();
459
+
460
+ const unsubscribe = useDictionaryDynamic(
461
+ {
462
+ en: () => import("../.intlayer/dictionaries/en/app.mjs"),
463
+ fr: () => import("../.intlayer/dictionaries/fr/app.mjs"),
464
+ es: () => import("../.intlayer/dictionaries/es/app.mjs"),
465
+ },
466
+ "app"
467
+ ).onChange((content) => {
468
+ document.querySelector("h1").textContent = String(content.title);
469
+ });
470
+ ```
471
+
472
+ > 注意:`useDictionaryDynamic` 要求字典作为单独的 ESM 文件可用。如果您的 Web 服务器负责提供这些字典,通常会使用这种方法。
473
+
474
+ ### 配置 TypeScript
475
+
476
+ 确保您的 TypeScript 配置包含自动生成的类型。
477
+
478
+ ```json5 fileName="tsconfig.json"
479
+ {
480
+ "compilerOptions": {
481
+ // ...
482
+ },
483
+ "include": ["src", ".intlayer/**/*.ts"],
484
+ }
485
+ ```
486
+
487
+ ### VS Code 扩展
488
+
489
+ 为了提升使用 Intlayer 的开发体验,您可以安装官方的 **Intlayer VS Code 扩展**。
490
+
491
+ [从 VS Code Marketplace 安装](https://marketplace.visualstudio.com/items?itemName=intlayer.intlayer-vs-code-extension)
492
+
493
+ 该扩展提供:
494
+
495
+ - 翻译键的**自动补全**。
496
+ - 缺失翻译的**实时错误检测**。
497
+ - 翻译内容的**内联预览**。
498
+ - 轻松创建和更新翻译的**快速操作**。
499
+
500
+ 有关如何使用该扩展的更多详细信息,请参阅 [Intlayer VS Code 扩展文档](https://intlayer.org/doc/vs-code-extension)。
501
+
502
+ ---
503
+
504
+ ### 深入了解
505
+
506
+ 若要深入了解,您可以实现[可视化编辑器](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) 外置您的内容。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intlayer/docs",
3
- "version": "8.6.0",
3
+ "version": "8.6.10",
4
4
  "private": false,
5
5
  "description": "Intlayer documentation",
6
6
  "keywords": [
@@ -72,14 +72,14 @@
72
72
  "watch": "webpack --config ./webpack.config.ts --watch"
73
73
  },
74
74
  "dependencies": {
75
- "@intlayer/config": "8.6.0",
76
- "@intlayer/core": "8.6.0",
77
- "@intlayer/types": "8.6.0"
75
+ "@intlayer/config": "8.6.10",
76
+ "@intlayer/core": "8.6.10",
77
+ "@intlayer/types": "8.6.10"
78
78
  },
79
79
  "devDependencies": {
80
- "@intlayer/api": "8.6.0",
81
- "@intlayer/cli": "8.6.0",
82
- "@types/node": "25.5.0",
80
+ "@intlayer/api": "8.6.10",
81
+ "@intlayer/cli": "8.6.10",
82
+ "@types/node": "25.5.2",
83
83
  "@utils/ts-config": "1.0.4",
84
84
  "@utils/ts-config-types": "1.0.4",
85
85
  "@utils/tsdown-config": "1.0.4",
@@ -87,7 +87,7 @@
87
87
  "rimraf": "6.1.3",
88
88
  "tsdown": "0.21.7",
89
89
  "typescript": "6.0.2",
90
- "vitest": "4.1.2"
90
+ "vitest": "4.1.3"
91
91
  },
92
92
  "engines": {
93
93
  "node": ">=14.18"
package/src/doc.ts CHANGED
@@ -1,4 +1,7 @@
1
- import type { DeclaredLocales, LocalesValues } from '@intlayer/types/module_augmentation';
1
+ import type {
2
+ DeclaredLocales,
3
+ LocalesValues,
4
+ } from '@intlayer/types/module_augmentation';
2
5
  import {
3
6
  defaultLocale,
4
7
  type FileMetadata,
@@ -493,6 +493,26 @@ export const docsEntry = {
493
493
  vi: readLocale('cli/sdk.md', 'vi'),
494
494
  uk: readLocale('cli/sdk.md', 'uk'),
495
495
  } as unknown as Record<LocalesValues, Promise<string>>,
496
+ './docs/en/cli/standalone.md': {
497
+ en: readLocale('cli/standalone.md', 'en'),
498
+ ru: readLocale('cli/standalone.md', 'ru'),
499
+ ja: readLocale('cli/standalone.md', 'ja'),
500
+ fr: readLocale('cli/standalone.md', 'fr'),
501
+ ko: readLocale('cli/standalone.md', 'ko'),
502
+ zh: readLocale('cli/standalone.md', 'zh'),
503
+ es: readLocale('cli/standalone.md', 'es'),
504
+ de: readLocale('cli/standalone.md', 'de'),
505
+ ar: readLocale('cli/standalone.md', 'ar'),
506
+ it: readLocale('cli/standalone.md', 'it'),
507
+ 'en-GB': readLocale('cli/standalone.md', 'en-GB'),
508
+ pt: readLocale('cli/standalone.md', 'pt'),
509
+ hi: readLocale('cli/standalone.md', 'hi'),
510
+ tr: readLocale('cli/standalone.md', 'tr'),
511
+ pl: readLocale('cli/standalone.md', 'pl'),
512
+ id: readLocale('cli/standalone.md', 'id'),
513
+ vi: readLocale('cli/standalone.md', 'vi'),
514
+ uk: readLocale('cli/standalone.md', 'uk'),
515
+ } as unknown as Record<LocalesValues, Promise<string>>,
496
516
  './docs/en/cli/test.md': {
497
517
  en: readLocale('cli/test.md', 'en'),
498
518
  ru: readLocale('cli/test.md', 'ru'),
@@ -613,6 +633,26 @@ export const docsEntry = {
613
633
  vi: readLocale('configuration.md', 'vi'),
614
634
  uk: readLocale('configuration.md', 'uk'),
615
635
  } as unknown as Record<LocalesValues, Promise<string>>,
636
+ './docs/en/custom_domains.md': {
637
+ en: readLocale('custom_domains.md', 'en'),
638
+ ru: readLocale('custom_domains.md', 'ru'),
639
+ ja: readLocale('custom_domains.md', 'ja'),
640
+ fr: readLocale('custom_domains.md', 'fr'),
641
+ ko: readLocale('custom_domains.md', 'ko'),
642
+ zh: readLocale('custom_domains.md', 'zh'),
643
+ es: readLocale('custom_domains.md', 'es'),
644
+ de: readLocale('custom_domains.md', 'de'),
645
+ ar: readLocale('custom_domains.md', 'ar'),
646
+ it: readLocale('custom_domains.md', 'it'),
647
+ 'en-GB': readLocale('custom_domains.md', 'en-GB'),
648
+ pt: readLocale('custom_domains.md', 'pt'),
649
+ hi: readLocale('custom_domains.md', 'hi'),
650
+ tr: readLocale('custom_domains.md', 'tr'),
651
+ pl: readLocale('custom_domains.md', 'pl'),
652
+ id: readLocale('custom_domains.md', 'id'),
653
+ vi: readLocale('custom_domains.md', 'vi'),
654
+ uk: readLocale('custom_domains.md', 'uk'),
655
+ } as unknown as Record<LocalesValues, Promise<string>>,
616
656
  './docs/en/custom_url_rewrites.md': {
617
657
  en: readLocale('custom_url_rewrites.md', 'en'),
618
658
  ru: readLocale('custom_url_rewrites.md', 'ru'),
@@ -1493,6 +1533,26 @@ export const docsEntry = {
1493
1533
  vi: readLocale('intlayer_with_tanstack.md', 'vi'),
1494
1534
  uk: readLocale('intlayer_with_tanstack.md', 'uk'),
1495
1535
  } as unknown as Record<LocalesValues, Promise<string>>,
1536
+ './docs/en/intlayer_with_vanilla.md': {
1537
+ en: readLocale('intlayer_with_vanilla.md', 'en'),
1538
+ ru: readLocale('intlayer_with_vanilla.md', 'ru'),
1539
+ ja: readLocale('intlayer_with_vanilla.md', 'ja'),
1540
+ fr: readLocale('intlayer_with_vanilla.md', 'fr'),
1541
+ ko: readLocale('intlayer_with_vanilla.md', 'ko'),
1542
+ zh: readLocale('intlayer_with_vanilla.md', 'zh'),
1543
+ es: readLocale('intlayer_with_vanilla.md', 'es'),
1544
+ de: readLocale('intlayer_with_vanilla.md', 'de'),
1545
+ ar: readLocale('intlayer_with_vanilla.md', 'ar'),
1546
+ it: readLocale('intlayer_with_vanilla.md', 'it'),
1547
+ 'en-GB': readLocale('intlayer_with_vanilla.md', 'en-GB'),
1548
+ pt: readLocale('intlayer_with_vanilla.md', 'pt'),
1549
+ hi: readLocale('intlayer_with_vanilla.md', 'hi'),
1550
+ tr: readLocale('intlayer_with_vanilla.md', 'tr'),
1551
+ pl: readLocale('intlayer_with_vanilla.md', 'pl'),
1552
+ id: readLocale('intlayer_with_vanilla.md', 'id'),
1553
+ vi: readLocale('intlayer_with_vanilla.md', 'vi'),
1554
+ uk: readLocale('intlayer_with_vanilla.md', 'uk'),
1555
+ } as unknown as Record<LocalesValues, Promise<string>>,
1496
1556
  './docs/en/intlayer_with_vite+lit.md': {
1497
1557
  en: readLocale('intlayer_with_vite+lit.md', 'en'),
1498
1558
  ru: readLocale('intlayer_with_vite+lit.md', 'ru'),