@modern-js/main-doc 3.9.2 → 3.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (203) hide show
  1. package/docs/en/apis/app/hooks/api/lambda.mdx +2 -1
  2. package/docs/en/apis/app/hooks/config/html.mdx +1 -0
  3. package/docs/en/apis/app/hooks/config/mock.mdx +1 -0
  4. package/docs/en/apis/app/hooks/config/public.mdx +1 -0
  5. package/docs/en/apis/app/hooks/config/upload.mdx +2 -3
  6. package/docs/en/apis/app/hooks/modern-config.mdx +1 -0
  7. package/docs/en/apis/app/hooks/shared.mdx +1 -0
  8. package/docs/en/apis/app/hooks/src/modern.runtime.mdx +1 -0
  9. package/docs/en/apis/app/hooks/src/routes.mdx +1 -0
  10. package/docs/en/apis/app/hooks/src/server.mdx +2 -1
  11. package/docs/en/apis/app/runtime/bff/use-hono-context.mdx +1 -0
  12. package/docs/en/apis/app/runtime/core/create-root.mdx +4 -1
  13. package/docs/en/apis/app/runtime/core/render.mdx +6 -2
  14. package/docs/en/apis/app/runtime/core/runtime-context.mdx +17 -17
  15. package/docs/en/apis/app/runtime/router/router.mdx +9 -6
  16. package/docs/en/apis/app/runtime/ssr/no-ssr.mdx +1 -0
  17. package/docs/en/apis/app/runtime/utility/head.mdx +1 -0
  18. package/docs/en/apis/app/runtime/utility/loadable.mdx +1 -0
  19. package/docs/en/community/blog/v3-release-note.mdx +36 -27
  20. package/docs/en/community/contributing-guide.mdx +15 -33
  21. package/docs/en/components/default-browserslist.mdx +0 -1
  22. package/docs/en/components/deploy-command.mdx +1 -1
  23. package/docs/en/components/deploy.mdx +1 -1
  24. package/docs/en/components/entry-scan-logic.mdx +1 -1
  25. package/docs/en/components/init-app.mdx +9 -3
  26. package/docs/en/components/international/custom-instance-code.mdx +0 -1
  27. package/docs/en/components/micro-runtime-config.mdx +12 -9
  28. package/docs/en/components/nodeVersion.mdx +2 -2
  29. package/docs/en/components/rsc-deploy-tip.mdx +0 -1
  30. package/docs/en/components/ssr-monitor.mdx +1 -1
  31. package/docs/en/configure/app/bff/cross-project.mdx +2 -2
  32. package/docs/en/configure/app/bff/prefix.mdx +1 -1
  33. package/docs/en/configure/app/dev/lazy-compilation.mdx +17 -1
  34. package/docs/en/configure/app/dev/start-url.mdx +0 -1
  35. package/docs/en/configure/app/output/css-modules.mdx +1 -5
  36. package/docs/en/configure/app/output/disable-svgr.mdx +4 -0
  37. package/docs/en/configure/app/output/dist-path.mdx +0 -1
  38. package/docs/en/configure/app/output/inline-scripts.mdx +1 -2
  39. package/docs/en/configure/app/output/inline-styles.mdx +1 -2
  40. package/docs/en/configure/app/output/split-route-chunks.mdx +1 -1
  41. package/docs/en/configure/app/output/ssg.mdx +1 -1
  42. package/docs/en/configure/app/output/ssgByEntries.mdx +1 -0
  43. package/docs/en/configure/app/output/svg-default-export.mdx +4 -0
  44. package/docs/en/configure/app/performance/chunk-split.mdx +1 -4
  45. package/docs/en/configure/app/runtime/plugins.mdx +6 -4
  46. package/docs/en/configure/app/server/rsc.mdx +1 -1
  47. package/docs/en/configure/app/server/ssr.mdx +7 -8
  48. package/docs/en/configure/app/server/tsconfig-path.mdx +2 -2
  49. package/docs/en/configure/app/tools/less.mdx +94 -19
  50. package/docs/en/configure/app/tools/sass.mdx +87 -18
  51. package/docs/en/configure/app/tools/svgr.mdx +93 -0
  52. package/docs/en/configure/app/usage.mdx +1 -5
  53. package/docs/en/guides/advanced-features/bff/cross-project.mdx +5 -4
  54. package/docs/en/guides/advanced-features/compatibility.mdx +0 -1
  55. package/docs/en/guides/advanced-features/international/advanced.mdx +1 -1
  56. package/docs/en/guides/advanced-features/international/api.mdx +34 -28
  57. package/docs/en/guides/advanced-features/international/best-practices.mdx +15 -15
  58. package/docs/en/guides/advanced-features/international/configuration.mdx +37 -37
  59. package/docs/en/guides/advanced-features/international/locale-detection.mdx +37 -28
  60. package/docs/en/guides/advanced-features/international/resource-loading.mdx +19 -17
  61. package/docs/en/guides/advanced-features/international/routing.mdx +8 -6
  62. package/docs/en/guides/advanced-features/international.mdx +8 -8
  63. package/docs/en/guides/advanced-features/server-monitor/logger.mdx +5 -5
  64. package/docs/en/guides/advanced-features/server-monitor/metrics.mdx +8 -8
  65. package/docs/en/guides/advanced-features/server-monitor/monitors.mdx +1 -3
  66. package/docs/en/guides/advanced-features/source-build.mdx +1 -1
  67. package/docs/en/guides/advanced-features/web-server.mdx +3 -3
  68. package/docs/en/guides/basic-features/data/data-fetch.mdx +1 -3
  69. package/docs/en/guides/basic-features/data/data-write.mdx +24 -28
  70. package/docs/en/guides/basic-features/debug/mock.mdx +2 -2
  71. package/docs/en/guides/basic-features/debug/using-storybook.mdx +5 -6
  72. package/docs/en/guides/basic-features/html.mdx +2 -3
  73. package/docs/en/guides/basic-features/output-files.mdx +1 -1
  74. package/docs/en/guides/basic-features/render/overview.mdx +12 -12
  75. package/docs/en/guides/basic-features/render/rsc.mdx +16 -9
  76. package/docs/en/guides/basic-features/render/ssr-cache.mdx +5 -5
  77. package/docs/en/guides/basic-features/render/ssr.mdx +8 -12
  78. package/docs/en/guides/basic-features/render/streaming-ssr.mdx +2 -1
  79. package/docs/en/guides/basic-features/routes/config-routes.mdx +60 -59
  80. package/docs/en/guides/basic-features/static-assets/svg-assets.mdx +29 -17
  81. package/docs/en/guides/basic-features/testing/playwright.mdx +14 -8
  82. package/docs/en/guides/basic-features/testing/rstest.mdx +6 -4
  83. package/docs/en/guides/get-started/ai-coding-agents.mdx +6 -6
  84. package/docs/en/guides/get-started/introduction.mdx +0 -1
  85. package/docs/en/guides/topic-detail/module-federation/deploy.mdx +2 -2
  86. package/docs/en/guides/topic-detail/module-federation/introduce.mdx +0 -1
  87. package/docs/en/guides/upgrade/config.mdx +12 -0
  88. package/docs/en/guides/upgrade/other.mdx +4 -4
  89. package/docs/en/guides/upgrade/tailwindcss.mdx +0 -1
  90. package/docs/en/guides/upgrade/web-server.md +34 -17
  91. package/docs/en/index.md +1 -0
  92. package/docs/en/plugin/cli-plugins/api.mdx +23 -23
  93. package/docs/en/plugin/cli-plugins/life-cycle.mdx +2 -0
  94. package/docs/en/plugin/introduction.mdx +6 -6
  95. package/docs/en/plugin/official/cli-plugins/plugin-bff.mdx +1 -1
  96. package/docs/en/plugin/official/cli-plugins/plugin-ssg.mdx +1 -1
  97. package/docs/en/plugin/plugin-system.mdx +19 -26
  98. package/docs/en/plugin/runtime-plugins/life-cycle.mdx +2 -0
  99. package/docs/en/plugin/server-plugins/api.mdx +11 -14
  100. package/docs/en/plugin/server-plugins/life-cycle.mdx +2 -0
  101. package/docs/zh/apis/app/hooks/api/lambda.mdx +1 -1
  102. package/docs/zh/apis/app/hooks/config/html.mdx +1 -0
  103. package/docs/zh/apis/app/hooks/config/mock.mdx +1 -0
  104. package/docs/zh/apis/app/hooks/config/public.mdx +1 -0
  105. package/docs/zh/apis/app/hooks/config/upload.mdx +2 -3
  106. package/docs/zh/apis/app/hooks/modern-config.mdx +1 -0
  107. package/docs/zh/apis/app/hooks/shared.mdx +1 -0
  108. package/docs/zh/apis/app/hooks/src/modern.runtime.mdx +1 -0
  109. package/docs/zh/apis/app/hooks/src/routes.mdx +1 -0
  110. package/docs/zh/apis/app/hooks/src/server.mdx +2 -1
  111. package/docs/zh/apis/app/runtime/bff/use-hono-context.mdx +1 -1
  112. package/docs/zh/apis/app/runtime/core/create-root.mdx +4 -1
  113. package/docs/zh/apis/app/runtime/core/render.mdx +6 -3
  114. package/docs/zh/apis/app/runtime/core/runtime-context.mdx +17 -17
  115. package/docs/zh/apis/app/runtime/router/router.mdx +10 -6
  116. package/docs/zh/apis/app/runtime/ssr/no-ssr.mdx +1 -0
  117. package/docs/zh/apis/app/runtime/utility/head.mdx +1 -0
  118. package/docs/zh/apis/app/runtime/utility/loadable.mdx +1 -0
  119. package/docs/zh/community/blog/v3-release-note.mdx +38 -29
  120. package/docs/zh/community/contributing-guide.mdx +16 -34
  121. package/docs/zh/components/default-browserslist.mdx +0 -1
  122. package/docs/zh/components/deploy-command.mdx +1 -1
  123. package/docs/zh/components/deploy.mdx +1 -1
  124. package/docs/zh/components/entry-scan-logic.mdx +1 -1
  125. package/docs/zh/components/init-app.mdx +9 -3
  126. package/docs/zh/components/international/custom-instance-code.mdx +0 -1
  127. package/docs/zh/components/international/install-command.mdx +0 -1
  128. package/docs/zh/components/micro-runtime-config.mdx +12 -9
  129. package/docs/zh/components/nodeVersion.mdx +2 -2
  130. package/docs/zh/components/rsc-deploy-tip.mdx +0 -1
  131. package/docs/zh/components/ssr-monitor.mdx +1 -1
  132. package/docs/zh/configure/app/bff/cross-project.mdx +2 -2
  133. package/docs/zh/configure/app/bff/prefix.mdx +1 -1
  134. package/docs/zh/configure/app/dev/lazy-compilation.mdx +17 -1
  135. package/docs/zh/configure/app/html/crossorigin.mdx +0 -1
  136. package/docs/zh/configure/app/html/favicon.mdx +0 -1
  137. package/docs/zh/configure/app/output/convert-to-rem.mdx +0 -1
  138. package/docs/zh/configure/app/output/css-modules.mdx +1 -5
  139. package/docs/zh/configure/app/output/disable-svgr.mdx +4 -0
  140. package/docs/zh/configure/app/output/inline-scripts.mdx +1 -2
  141. package/docs/zh/configure/app/output/inline-styles.mdx +1 -2
  142. package/docs/zh/configure/app/output/source-map.mdx +0 -2
  143. package/docs/zh/configure/app/output/split-route-chunks.mdx +1 -1
  144. package/docs/zh/configure/app/output/ssg.mdx +1 -0
  145. package/docs/zh/configure/app/output/ssgByEntries.mdx +1 -1
  146. package/docs/zh/configure/app/output/svg-default-export.mdx +4 -0
  147. package/docs/zh/configure/app/performance/chunk-split.mdx +1 -4
  148. package/docs/zh/configure/app/resolve/dedupe.mdx +0 -1
  149. package/docs/zh/configure/app/runtime/plugins.mdx +6 -4
  150. package/docs/zh/configure/app/server/rsc.mdx +1 -1
  151. package/docs/zh/configure/app/server/ssr.mdx +6 -7
  152. package/docs/zh/configure/app/server/tsconfig-path.mdx +2 -2
  153. package/docs/zh/configure/app/tools/less.mdx +93 -19
  154. package/docs/zh/configure/app/tools/sass.mdx +87 -16
  155. package/docs/zh/configure/app/tools/svgr.mdx +93 -0
  156. package/docs/zh/configure/app/usage.mdx +1 -5
  157. package/docs/zh/guides/advanced-features/bff.mdx +1 -0
  158. package/docs/zh/guides/advanced-features/international/advanced.mdx +1 -1
  159. package/docs/zh/guides/advanced-features/international/api.mdx +28 -27
  160. package/docs/zh/guides/advanced-features/international/best-practices.mdx +15 -15
  161. package/docs/zh/guides/advanced-features/international/configuration.mdx +38 -36
  162. package/docs/zh/guides/advanced-features/international/locale-detection.mdx +37 -28
  163. package/docs/zh/guides/advanced-features/international/resource-loading.mdx +20 -16
  164. package/docs/zh/guides/advanced-features/international/routing.mdx +6 -4
  165. package/docs/zh/guides/advanced-features/international.mdx +9 -9
  166. package/docs/zh/guides/advanced-features/server-monitor/logger.mdx +4 -6
  167. package/docs/zh/guides/advanced-features/server-monitor/metrics.mdx +9 -10
  168. package/docs/zh/guides/advanced-features/source-build.mdx +1 -1
  169. package/docs/zh/guides/advanced-features/web-server.mdx +3 -3
  170. package/docs/zh/guides/basic-features/data/data-fetch.mdx +1 -3
  171. package/docs/zh/guides/basic-features/data/data-write.mdx +25 -31
  172. package/docs/zh/guides/basic-features/debug/mock.mdx +2 -2
  173. package/docs/zh/guides/basic-features/debug/using-storybook.mdx +5 -5
  174. package/docs/zh/guides/basic-features/env-vars.mdx +0 -1
  175. package/docs/zh/guides/basic-features/html.mdx +2 -3
  176. package/docs/zh/guides/basic-features/render/overview.mdx +12 -13
  177. package/docs/zh/guides/basic-features/render/rsc.mdx +16 -9
  178. package/docs/zh/guides/basic-features/render/ssr.mdx +8 -17
  179. package/docs/zh/guides/basic-features/routes/config-routes.mdx +61 -59
  180. package/docs/zh/guides/basic-features/static-assets/svg-assets.mdx +29 -17
  181. package/docs/zh/guides/basic-features/testing/playwright.mdx +15 -10
  182. package/docs/zh/guides/basic-features/testing/rstest.mdx +6 -4
  183. package/docs/zh/guides/get-started/ai-coding-agents.mdx +7 -7
  184. package/docs/zh/guides/topic-detail/module-federation/deploy.mdx +2 -2
  185. package/docs/zh/guides/upgrade/config.mdx +12 -0
  186. package/docs/zh/guides/upgrade/other.md +4 -11
  187. package/docs/zh/guides/upgrade/overview.mdx +1 -4
  188. package/docs/zh/guides/upgrade/tailwindcss.mdx +0 -1
  189. package/docs/zh/guides/upgrade/web-server.md +34 -19
  190. package/docs/zh/index.md +1 -0
  191. package/docs/zh/plugin/cli-plugins/api.mdx +24 -24
  192. package/docs/zh/plugin/cli-plugins/life-cycle.mdx +2 -0
  193. package/docs/zh/plugin/introduction.mdx +6 -6
  194. package/docs/zh/plugin/official/cli-plugins/plugin-bff.mdx +1 -1
  195. package/docs/zh/plugin/official/cli-plugins/plugin-ssg.mdx +1 -1
  196. package/docs/zh/plugin/plugin-system.mdx +19 -26
  197. package/docs/zh/plugin/runtime-plugins/life-cycle.mdx +2 -0
  198. package/docs/zh/plugin/server-plugins/api.mdx +11 -14
  199. package/docs/zh/plugin/server-plugins/life-cycle.mdx +2 -0
  200. package/package.json +11 -13
  201. package/{rspress.config.ts → rstack.config.mts} +7 -10
  202. package/src/components/Footer/styles.module.scss +1 -1
  203. package/src/components/SolutionCards/index.module.scss +3 -1
@@ -265,11 +265,7 @@ import { defineConfig } from '@modern-js/app-tools';
265
265
  import { xxPlugin } from '@modern-js/plugin-xx';
266
266
 
267
267
  export default defineConfig({
268
- plugins: [
269
- xxPlugin({
270
- /** Add parameters here */
271
- }),
272
- ],
268
+ plugins: [xxPlugin({/** Add parameters here */})],
273
269
  });
274
270
  ```
275
271
 
@@ -9,6 +9,7 @@ Cross-project invocation consists of **producer** and **consumer** sides. The pr
9
9
 
10
10
  Enable cross-project invocation via configuration. Projects with BFF capabilities enabled can act as BFF producers, or you can create standalone BFF applications.
11
11
  When executing `dev` or `build`, the following artifacts for consumers will be automatically generated:
12
+
12
13
  - API functions under the `dist/client` directory
13
14
  - Runtime configuration functions under the `dist/runtime` directory
14
15
  - Interface exports defined in `exports` field of `package.json`
@@ -24,7 +25,7 @@ Ensure the current project has BFF enabled with API files defined under `api/lam
24
25
  export default defineConfig({
25
26
  bff: {
26
27
  crossProject: true,
27
- }
28
+ },
28
29
  });
29
30
  ```
30
31
 
@@ -88,9 +89,9 @@ import { configure as innerConfigure } from '@modern-js/plugin-bff/client';
88
89
  import axios from 'axios';
89
90
 
90
91
  configure({
91
- setDomain() {
92
- return 'https://your-bff-api.com';
93
- },
92
+ setDomain() {
93
+ return 'https://your-bff-api.com';
94
+ },
94
95
  });
95
96
 
96
97
  innerConfigure({
@@ -18,7 +18,6 @@ import DefaultBrowserslist from '@site-docs/components/default-browserslist';
18
18
 
19
19
  <DefaultBrowserslist />
20
20
 
21
-
22
21
  When the `overrideBrowserslist` configuration is not specified in the project, this `.browserslistrc` file will take effect.
23
22
 
24
23
  ### Method 2: Configure via package.json
@@ -68,7 +68,7 @@ i18nPlugin({
68
68
  localeDetectionByEntry: {
69
69
  admin: {
70
70
  localePathRedirect: false, // admin does not use path prefixes
71
- languages: ['en'], // admin only supports English
71
+ languages: ['en'], // admin only supports English
72
72
  },
73
73
  mobile: {
74
74
  languages: ['zh', 'en', 'ja'], // mobile supports more languages
@@ -10,14 +10,14 @@ title: API Reference
10
10
 
11
11
  ### Return Value
12
12
 
13
- | Field | Type | Description |
14
- | --- | --- | --- |
15
- | `language` | `string` | Current language code |
16
- | `changeLanguage` | `(lang: string) => Promise<void>` | Switches language |
17
- | `supportedLanguages` | `string[]` | Supported language list, from `localeDetection.languages` |
18
- | `isLanguageSupported` | `(lang: string) => boolean` | Checks whether a language is in the supported list |
19
- | `isResourcesReady` | `boolean` | Whether translation resources for the current language have finished loading |
20
- | `i18nInstance` | `I18nInstance` | i18next instance for advanced scenarios |
13
+ | Field | Type | Description |
14
+ | --------------------- | --------------------------------- | ---------------------------------------------------------------------------- |
15
+ | `language` | `string` | Current language code |
16
+ | `changeLanguage` | `(lang: string) => Promise<void>` | Switches language |
17
+ | `supportedLanguages` | `string[]` | Supported language list, from `localeDetection.languages` |
18
+ | `isLanguageSupported` | `(lang: string) => boolean` | Checks whether a language is in the supported list |
19
+ | `isResourcesReady` | `boolean` | Whether translation resources for the current language have finished loading |
20
+ | `i18nInstance` | `I18nInstance` | i18next instance for advanced scenarios |
21
21
 
22
22
  ### Basic Usage
23
23
 
@@ -85,13 +85,13 @@ A route link component with a locale prefix.
85
85
 
86
86
  ### Props
87
87
 
88
- | Prop | Type | Required | Description |
89
- | --- | --- | --- | --- |
90
- | `to` | `string` | Yes | Target path. Do not include the locale prefix |
91
- | `children` | `React.ReactNode` | Yes | Link content |
92
- | `replace` | `boolean` | No | Uses `history.replace` instead of `push` |
93
- | `state` | `any` | No | State passed to the target route |
94
- | Other Link props | - | No | Inherited from the `Link` component in `@modern-js/runtime/router` |
88
+ | Prop | Type | Required | Description |
89
+ | ---------------- | ----------------- | -------- | ------------------------------------------------------------------ |
90
+ | `to` | `string` | Yes | Target path. Do not include the locale prefix |
91
+ | `children` | `React.ReactNode` | Yes | Link content |
92
+ | `replace` | `boolean` | No | Uses `history.replace` instead of `push` |
93
+ | `state` | `any` | No | State passed to the target route |
94
+ | Other Link props | - | No | Inherited from the `Link` component in `@modern-js/runtime/router` |
95
95
 
96
96
  ### Usage
97
97
 
@@ -166,11 +166,11 @@ Type of the custom backend loader function:
166
166
  type I18nSdkLoader = (options: I18nSdkLoadOptions) => Promise<Resources>;
167
167
 
168
168
  interface I18nSdkLoadOptions {
169
- lng?: string; // Single language code
170
- ns?: string; // Single namespace
171
- lngs?: string[]; // Multiple language codes
172
- nss?: string[]; // Multiple namespaces
173
- all?: boolean; // Load all resources
169
+ lng?: string; // Single language code
170
+ ns?: string; // Single namespace
171
+ lngs?: string[]; // Multiple language codes
172
+ nss?: string[]; // Multiple namespaces
173
+ all?: boolean; // Load all resources
174
174
  }
175
175
 
176
176
  type Resources = {
@@ -185,14 +185,14 @@ type Resources = {
185
185
  ```ts
186
186
  interface LanguageDetectorOptions {
187
187
  order?: string[];
188
- lookupQuerystring?: string; // Default: 'lng'
189
- lookupCookie?: string; // Default: 'i18next'
190
- lookupLocalStorage?: string; // Default: 'i18nextLng'
188
+ lookupQuerystring?: string; // Default: 'lng'
189
+ lookupCookie?: string; // Default: 'i18next'
190
+ lookupLocalStorage?: string; // Default: 'i18nextLng'
191
191
  lookupSession?: string;
192
- lookupHeader?: string; // Default: 'accept-language'
192
+ lookupHeader?: string; // Default: 'accept-language'
193
193
  lookupFromPathIndex?: number; // Default: 0
194
194
  caches?: false | string[];
195
- cookieMinutes?: number; // Default: 525600 (1 year)
195
+ cookieMinutes?: number; // Default: 525600 (1 year)
196
196
  cookieExpirationDate?: Date;
197
197
  cookieDomain?: string;
198
198
  }
@@ -212,8 +212,8 @@ import { useTranslation } from 'react-i18next';
212
212
  import { useModernI18n } from '@modern-js/plugin-i18n/runtime';
213
213
 
214
214
  function App() {
215
- const { t } = useTranslation(); // Translate text
216
- const { language, changeLanguage } = useModernI18n(); // Switch language
215
+ const { t } = useTranslation(); // Translate text
216
+ const { language, changeLanguage } = useModernI18n(); // Switch language
217
217
 
218
218
  return (
219
219
  <div>
@@ -231,5 +231,11 @@ You can also get the i18next instance from `useModernI18n` and call capabilities
231
231
  const { i18nInstance } = useModernI18n();
232
232
 
233
233
  // Dynamically add translation resources.
234
- i18nInstance.addResourceBundle('zh', 'translation', { key: 'Value' }, true, true);
234
+ i18nInstance.addResourceBundle(
235
+ 'zh',
236
+ 'translation',
237
+ { key: 'Value' },
238
+ true,
239
+ true,
240
+ );
235
241
  ```
@@ -63,8 +63,8 @@ function ButtonGroup() {
63
63
  const { t } = useTranslation('common', { keyPrefix: 'button' });
64
64
  return (
65
65
  <>
66
- <button>{t('submit')}</button> {/* common:button.submit */}
67
- <button>{t('cancel')}</button> {/* common:button.cancel */}
66
+ <button>{t('submit')}</button> {/* common:button.submit */}
67
+ <button>{t('cancel')}</button> {/* common:button.cancel */}
68
68
  </>
69
69
  );
70
70
  }
@@ -94,9 +94,9 @@ The quality of translation key names directly affects maintenance cost. Recommen
94
94
  ```
95
95
 
96
96
  ```tsx
97
- t('page.title')
98
- t('form.username.label')
99
- t('form.submit', { defaultValue: 'Save' }) // defaultValue prevents showing the key string when the key is missing.
97
+ t('page.title');
98
+ t('form.username.label');
99
+ t('form.submit', { defaultValue: 'Save' }); // defaultValue prevents showing the key string when the key is missing.
100
100
  ```
101
101
 
102
102
  ## Plurals
@@ -121,9 +121,9 @@ i18next automatically selects the correct plural form based on the `count` param
121
121
  ```
122
122
 
123
123
  ```tsx
124
- t('item', { count: 0 }) // "没有条目" / "No items"
125
- t('item', { count: 1 }) // "没有条目" / "1 item" (Chinese usually has only one form)
126
- t('item', { count: 5 }) // "5 个条目" / "5 items"
124
+ t('item', { count: 0 }); // "没有条目" / "No items"
125
+ t('item', { count: 1 }); // "没有条目" / "1 item" (Chinese usually has only one form)
126
+ t('item', { count: 5 }); // "5 个条目" / "5 items"
127
127
  ```
128
128
 
129
129
  Different languages have different plural rules. English has singular and plural, while Russian has one/few/many forms. i18next automatically matches CLDR rules based on the language code.
@@ -152,8 +152,8 @@ Nested structures can clearly reflect UI hierarchy and are accessed with dots:
152
152
  ```
153
153
 
154
154
  ```tsx
155
- t('modal.confirm.title')
156
- t('modal.confirm.actions.ok')
155
+ t('modal.confirm.title');
156
+ t('modal.confirm.actions.ok');
157
157
  ```
158
158
 
159
159
  Avoid nesting deeper than 4 levels. Excessive depth makes key names long and hard to maintain.
@@ -199,8 +199,8 @@ Use `, format` in translation files to specify the formatting type:
199
199
  ```
200
200
 
201
201
  ```tsx
202
- t('price', { value: 99.5 }) // "当前价格:¥99.50" (zh) / "$99.50" (en)
203
- t('expiry', { date: new Date() }) // "到期日:2025年5月12日" (zh)
202
+ t('price', { value: 99.5 }); // "当前价格:¥99.50" (zh) / "$99.50" (en)
203
+ t('expiry', { date: new Date() }); // "到期日:2025年5月12日" (zh)
204
204
  ```
205
205
 
206
206
  ## Error Handling
@@ -237,7 +237,7 @@ if (!i18n.isInitialized) return null;
237
237
  Provide fallback text with `defaultValue` to prevent key strings from appearing in the UI:
238
238
 
239
239
  ```tsx
240
- t('missing.key', { defaultValue: 'Default text' })
240
+ t('missing.key', { defaultValue: 'Default text' });
241
241
  ```
242
242
 
243
243
  In development, you can enable `saveMissing` to output missing keys to the console for debugging:
@@ -281,8 +281,8 @@ Referencing JSON file types directly is less likely to drift from actual transla
281
281
 
282
282
  ```tsx
283
283
  const { t } = useTranslation();
284
- t('welcome'); // TypeScript autocomplete
285
- t('nonExistent'); // TypeScript error
284
+ t('welcome'); // TypeScript autocomplete
285
+ t('nonExistent'); // TypeScript error
286
286
  ```
287
287
 
288
288
  :::tip Large projects
@@ -6,10 +6,10 @@ title: Configuration
6
6
 
7
7
  Plugin configuration is split between two files, each with a different responsibility:
8
8
 
9
- | File | Purpose |
10
- | --- | --- |
11
- | `modern.config.ts` | Basic plugin settings, read during build/startup |
12
- | `src/modern.runtime.ts` | i18next initialization options, read at runtime |
9
+ | File | Purpose |
10
+ | ----------------------- | ------------------------------------------------ |
11
+ | `modern.config.ts` | Basic plugin settings, read during build/startup |
12
+ | `src/modern.runtime.ts` | i18next initialization options, read at runtime |
13
13
 
14
14
  :::warning Function values can only be configured at runtime
15
15
  `modern.config.ts` runs at build time and cannot serialize functions. SDK loaders, custom detection functions, and similar function values must be placed in `modern.runtime.ts`.
@@ -17,13 +17,13 @@ Plugin configuration is split between two files, each with a different responsib
17
17
 
18
18
  ## Configuration Ownership
19
19
 
20
- | Configuration | Where to configure |
21
- | --- | --- |
22
- | `localeDetection` (language detection, path redirects, etc.) | `modern.config.ts` |
23
- | `backend` (resource paths, SDK declaration, etc.) | `modern.config.ts` |
24
- | `i18nInstance` | `modern.runtime.ts` |
20
+ | Configuration | Where to configure |
21
+ | -------------------------------------------------------------- | ------------------- |
22
+ | `localeDetection` (language detection, path redirects, etc.) | `modern.config.ts` |
23
+ | `backend` (resource paths, SDK declaration, etc.) | `modern.config.ts` |
24
+ | `i18nInstance` | `modern.runtime.ts` |
25
25
  | `initOptions` (`fallbackLng`, `ns`, and other i18next options) | `modern.runtime.ts` |
26
- | The actual `backend.sdk` loader function | `modern.runtime.ts` |
26
+ | The actual `backend.sdk` loader function | `modern.runtime.ts` |
27
27
 
28
28
  ## CLI Configuration
29
29
 
@@ -44,15 +44,15 @@ export default defineConfig({
44
44
 
45
45
  ### localeDetection Options
46
46
 
47
- | Field | Type | Default | Description |
48
- | --- | --- | --- | --- |
49
- | `languages` | `string[]` | `[]` | Supported language list |
50
- | `fallbackLanguage` | `string` | `''` | Fallback language when detection fails |
51
- | `localePathRedirect` | `boolean` | `false` | Handles URL locale prefix recognition, redirects, and switching. See [Routing Integration](./routing.md#enable-locale-path-prefixes) |
52
- | `i18nextDetector` | `boolean` | `false` | Enables the i18next detector (Cookie / Header, etc.) |
53
- | `detection` | `LanguageDetectorOptions` | - | Detailed i18next detector configuration. See [Locale Detection](./locale-detection.md) |
54
- | `ignoreRedirectRoutes` | `string[] \| Function` | - | Routes that skip redirects. See [Locale Detection](./locale-detection.md#ignoreredirectroutes) |
55
- | `localeDetectionByEntry` | `Record<string, ...>` | - | Per-entry overrides for multiple entries |
47
+ | Field | Type | Default | Description |
48
+ | ------------------------ | ------------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------ |
49
+ | `languages` | `string[]` | `[]` | Supported language list |
50
+ | `fallbackLanguage` | `string` | `''` | Fallback language when detection fails |
51
+ | `localePathRedirect` | `boolean` | `false` | Handles URL locale prefix recognition, redirects, and switching. See [Routing Integration](./routing.md#enable-locale-path-prefixes) |
52
+ | `i18nextDetector` | `boolean` | `false` | Enables the i18next detector (Cookie / Header, etc.) |
53
+ | `detection` | `LanguageDetectorOptions` | - | Detailed i18next detector configuration. See [Locale Detection](./locale-detection.md) |
54
+ | `ignoreRedirectRoutes` | `string[] \| Function` | - | Routes that skip redirects. See [Locale Detection](./locale-detection.md#ignoreredirectroutes) |
55
+ | `localeDetectionByEntry` | `Record<string, ...>` | - | Per-entry overrides for multiple entries |
56
56
 
57
57
  **Example:**
58
58
 
@@ -105,11 +105,11 @@ interface BackendOptions {
105
105
 
106
106
  **backend auto-enable rules:**
107
107
 
108
- | Situation | Result |
109
- | --- | --- |
110
- | `loadPath` or `addPath` is configured | Automatically enabled. No need to write `enabled: true` |
111
- | No backend is configured, but a `locales` directory exists and contains JSON files | Automatically enabled with the default `loadPath` |
112
- | `enabled: false` is set explicitly | Disabled, and auto-detection is skipped |
108
+ | Situation | Result |
109
+ | ---------------------------------------------------------------------------------- | ------------------------------------------------------- |
110
+ | `loadPath` or `addPath` is configured | Automatically enabled. No need to write `enabled: true` |
111
+ | No backend is configured, but a `locales` directory exists and contains JSON files | Automatically enabled with the default `loadPath` |
112
+ | `enabled: false` is set explicitly | Disabled, and auto-detection is skipped |
113
113
 
114
114
  Auto-detected directory locations, in priority order:
115
115
 
@@ -118,11 +118,11 @@ Auto-detected directory locations, in priority order:
118
118
 
119
119
  **Which backend should you choose?**
120
120
 
121
- | Scenario | Recommended approach |
122
- | --- | --- |
123
- | Translation files are local to the project | Static file backend (configure `loadPath`; CSR/SSR switch automatically) |
124
- | Translations come from a remote API or translation platform | Custom backend (configure `sdk: true`) |
125
- | Local fallback + remote real-time updates | Chained backend (configure both `loadPath` and `sdk`) |
121
+ | Scenario | Recommended approach |
122
+ | ----------------------------------------------------------- | ------------------------------------------------------------------------ |
123
+ | Translation files are local to the project | Static file backend (configure `loadPath`; CSR/SSR switch automatically) |
124
+ | Translations come from a remote API or translation platform | Custom backend (configure `sdk: true`) |
125
+ | Local fallback + remote real-time updates | Chained backend (configure both `loadPath` and `sdk`) |
126
126
 
127
127
  See [Resource Loading](./resource-loading.md) for detailed usage.
128
128
 
@@ -136,7 +136,7 @@ const i18nInstance = i18next.createInstance();
136
136
 
137
137
  export default defineRuntimeConfig({
138
138
  i18n: {
139
- i18nInstance, // Optional. An isolated instance is recommended.
139
+ i18nInstance, // Optional. An isolated instance is recommended.
140
140
  initOptions: {
141
141
  fallbackLng: 'en',
142
142
  supportedLngs: ['zh', 'en'],
@@ -164,13 +164,13 @@ import Desc from '@site-docs/components/international/init-options-desc';
164
164
 
165
165
  <Desc />
166
166
 
167
- | Field | Description |
168
- | --- | --- |
169
- | `fallbackLng` | Which language resources i18next falls back to when a translation key is missing. Supports strings, arrays, and maps (fallback chains) |
170
- | `supportedLngs` | Language list supported by i18next |
171
- | `ns` | Namespace list. Default is `['translation']` |
172
- | `defaultNS` | Default namespace. Default is `'translation'` |
173
- | `lng` | Forces the initial language. Usually not needed because the detector decides it |
167
+ | Field | Description |
168
+ | --------------- | -------------------------------------------------------------------------------------------------------------------------------------- |
169
+ | `fallbackLng` | Which language resources i18next falls back to when a translation key is missing. Supports strings, arrays, and maps (fallback chains) |
170
+ | `supportedLngs` | Language list supported by i18next |
171
+ | `ns` | Namespace list. Default is `['translation']` |
172
+ | `defaultNS` | Default namespace. Default is `'translation'` |
173
+ | `lng` | Forces the initial language. Usually not needed because the detector decides it |
174
174
 
175
175
  `fallbackLng` supports fallback chains, which are useful for regional language degradation:
176
176
 
@@ -64,8 +64,8 @@ Both methods can be enabled at the same time:
64
64
  ```ts
65
65
  i18nPlugin({
66
66
  localeDetection: {
67
- localePathRedirect: true, // Path prefix
68
- i18nextDetector: true, // Cookie / Header, etc.
67
+ localePathRedirect: true, // Path prefix
68
+ i18nextDetector: true, // Cookie / Header, etc.
69
69
  languages: ['zh', 'en'],
70
70
  fallbackLanguage: 'en',
71
71
  detection: {
@@ -77,39 +77,48 @@ i18nPlugin({
77
77
 
78
78
  ## Detection Options (`detection`)
79
79
 
80
- | Option | Type | Default | Description |
81
- | --- | --- | --- | --- |
82
- | `order` | `string[]` | See below | Detection order inside the i18next detector |
83
- | `lookupQuerystring` | `string` | `'lng'` | Query parameter key, such as `?lng=en` |
84
- | `lookupCookie` | `string` | `'i18next'` | Cookie key |
85
- | `lookupLocalStorage` | `string` | `'i18nextLng'` | LocalStorage key (browser only) |
86
- | `lookupSession` | `string` | - | SessionStorage key (browser only) |
87
- | `lookupHeader` | `string` | `'accept-language'` | HTTP request header key |
88
- | `lookupFromPathIndex` | `number` | `0` | Which URL path segment to start recognizing language from |
89
- | `caches` | `false \| string[]` | - | Where to cache the detected language, such as `['cookie']` |
90
- | `cookieMinutes` | `number` | `525600` (1 year) | Cookie expiration time in minutes |
91
- | `cookieExpirationDate` | `Date` | - | Cookie expiration date. Takes precedence over `cookieMinutes` |
92
- | `cookieDomain` | `string` | - | Cookie domain |
80
+ | Option | Type | Default | Description |
81
+ | ---------------------- | ------------------- | ------------------- | ------------------------------------------------------------- |
82
+ | `order` | `string[]` | See below | Detection order inside the i18next detector |
83
+ | `lookupQuerystring` | `string` | `'lng'` | Query parameter key, such as `?lng=en` |
84
+ | `lookupCookie` | `string` | `'i18next'` | Cookie key |
85
+ | `lookupLocalStorage` | `string` | `'i18nextLng'` | LocalStorage key (browser only) |
86
+ | `lookupSession` | `string` | - | SessionStorage key (browser only) |
87
+ | `lookupHeader` | `string` | `'accept-language'` | HTTP request header key |
88
+ | `lookupFromPathIndex` | `number` | `0` | Which URL path segment to start recognizing language from |
89
+ | `caches` | `false \| string[]` | - | Where to cache the detected language, such as `['cookie']` |
90
+ | `cookieMinutes` | `number` | `525600` (1 year) | Cookie expiration time in minutes |
91
+ | `cookieExpirationDate` | `Date` | - | Cookie expiration date. Takes precedence over `cookieMinutes` |
92
+ | `cookieDomain` | `string` | - | Cookie domain |
93
93
 
94
94
  **Default detection order when `order` is not configured:**
95
95
 
96
96
  ```ts
97
- ['querystring', 'cookie', 'localStorage', 'header', 'navigator', 'htmlTag', 'path', 'subdomain']
97
+ [
98
+ 'querystring',
99
+ 'cookie',
100
+ 'localStorage',
101
+ 'header',
102
+ 'navigator',
103
+ 'htmlTag',
104
+ 'path',
105
+ 'subdomain',
106
+ ];
98
107
  ```
99
108
 
100
109
  **Available `order` values:**
101
110
 
102
- | Value | Source | Limitation |
103
- | --- | --- | --- |
104
- | `querystring` | URL query parameter (`?lng=en`) | - |
105
- | `cookie` | Cookie | - |
106
- | `localStorage` | LocalStorage | Browser only |
107
- | `sessionStorage` | SessionStorage | Browser only |
108
- | `navigator` | Browser language settings | Browser only |
109
- | `htmlTag` | `<html lang="...">` | Browser only |
110
- | `header` | `Accept-Language` request header | - |
111
- | `path` | URL path (requires `localePathRedirect`) | - |
112
- | `subdomain` | Subdomain (`en.example.com`) | - |
111
+ | Value | Source | Limitation |
112
+ | ---------------- | ---------------------------------------- | ------------ |
113
+ | `querystring` | URL query parameter (`?lng=en`) | - |
114
+ | `cookie` | Cookie | - |
115
+ | `localStorage` | LocalStorage | Browser only |
116
+ | `sessionStorage` | SessionStorage | Browser only |
117
+ | `navigator` | Browser language settings | Browser only |
118
+ | `htmlTag` | `<html lang="...">` | Browser only |
119
+ | `header` | `Accept-Language` request header | - |
120
+ | `path` | URL path (requires `localePathRedirect`) | - |
121
+ | `subdomain` | Subdomain (`en.example.com`) | - |
113
122
 
114
123
  ## ignoreRedirectRoutes
115
124
 
@@ -118,7 +127,7 @@ Specify which paths should skip locale path redirects. This is useful for API ro
118
127
  **Syntax 1: string array** (supports exact match and prefix match)
119
128
 
120
129
  ```ts
121
- ignoreRedirectRoutes: ['/api', '/admin', '/static']
130
+ ignoreRedirectRoutes: ['/api', '/admin', '/static'];
122
131
  // '/api' matches both /api and /api/users.
123
132
  ```
124
133
 
@@ -6,11 +6,11 @@ title: Resource Loading
6
6
 
7
7
  How translation files are loaded depends on where your translation resources are stored:
8
8
 
9
- | Scenario | Loading method |
10
- | --- | --- |
11
- | Translation files are local to the project | Static file backend (the default method in this guide) |
12
- | Translations come from a remote API or translation platform | Custom backend |
13
- | Both: local fallback + remote real-time updates | Chained backend |
9
+ | Scenario | Loading method |
10
+ | ----------------------------------------------------------- | ------------------------------------------------------ |
11
+ | Translation files are local to the project | Static file backend (the default method in this guide) |
12
+ | Translations come from a remote API or translation platform | Custom backend |
13
+ | Both: local fallback + remote real-time updates | Chained backend |
14
14
 
15
15
  ## Static File Backend
16
16
 
@@ -103,11 +103,11 @@ export default defineRuntimeConfig({
103
103
 
104
104
  ```ts
105
105
  interface I18nSdkLoadOptions {
106
- lng?: string; // Single language code
107
- ns?: string; // Single namespace
108
- lngs?: string[]; // Multiple language codes
109
- nss?: string[]; // Multiple namespaces
110
- all?: boolean; // Load all resources
106
+ lng?: string; // Single language code
107
+ ns?: string; // Single namespace
108
+ lngs?: string[]; // Multiple language codes
109
+ nss?: string[]; // Multiple namespaces
110
+ all?: boolean; // Load all resources
111
111
  }
112
112
  ```
113
113
 
@@ -125,7 +125,7 @@ Use local files and a custom backend together to implement "show local translati
125
125
  i18nPlugin({
126
126
  backend: {
127
127
  loadPath: '/locales/{{lng}}/{{ns}}.json', // Local files, fast display
128
- sdk: true, // Remote loading, async update
128
+ sdk: true, // Remote loading, async update
129
129
  },
130
130
  });
131
131
  ```
@@ -138,7 +138,9 @@ export default defineRuntimeConfig({
138
138
  backend: {
139
139
  sdk: async options => {
140
140
  if (options.lng && options.ns) {
141
- const res = await fetch(`https://api.example.com/i18n/${options.lng}/${options.ns}`);
141
+ const res = await fetch(
142
+ `https://api.example.com/i18n/${options.lng}/${options.ns}`,
143
+ );
142
144
  return { [options.lng]: { [options.ns]: await res.json() } };
143
145
  }
144
146
  return {};
@@ -151,8 +153,8 @@ export default defineRuntimeConfig({
151
153
 
152
154
  **`cacheHitMode` option** (controls how the two backends cooperate):
153
155
 
154
- | Value | Behavior |
155
- | --- | --- |
156
- | `'none'` | Use local files after a successful local hit and do not request the custom backend |
157
- | `'refresh'` | Continue requesting the custom backend and update cache, but do not update the current page |
158
- | `'refreshAndUpdateStore'` | Continue requesting the custom backend, update cache, and refresh page text (default) |
156
+ | Value | Behavior |
157
+ | ------------------------- | ------------------------------------------------------------------------------------------- |
158
+ | `'none'` | Use local files after a successful local hit and do not request the custom backend |
159
+ | `'refresh'` | Continue requesting the custom backend and update cache, but do not update the current page |
160
+ | `'refreshAndUpdateStore'` | Continue requesting the custom backend, update cache, and refresh page text (default) |
@@ -26,11 +26,11 @@ i18nPlugin({
26
26
 
27
27
  **Result:**
28
28
 
29
- | Visited path | Result |
30
- | --- | --- |
31
- | `/about` | Redirects to `/en/about` |
32
- | `/en/about` | Visits normally, language is `en` |
33
- | `/zh/about` | Visits normally, language is `zh` |
29
+ | Visited path | Result |
30
+ | ------------ | --------------------------------- |
31
+ | `/about` | Redirects to `/en/about` |
32
+ | `/en/about` | Visits normally, language is `en` |
33
+ | `/zh/about` | Visits normally, language is `zh` |
34
34
 
35
35
  Some paths, such as API routes and static assets, do not need locale prefixes. Use `ignoreRedirectRoutes` to skip redirects. See [Locale Detection -> ignoreRedirectRoutes](./locale-detection.md#ignoreredirectroutes).
36
36
 
@@ -108,7 +108,9 @@ function Navigation() {
108
108
  <nav>
109
109
  <I18nLink to="/">Home</I18nLink>
110
110
  <I18nLink to="/about">About</I18nLink>
111
- <I18nLink to="/contact" replace>Contact</I18nLink>
111
+ <I18nLink to="/contact" replace>
112
+ Contact
113
+ </I18nLink>
112
114
  </nav>
113
115
  );
114
116
  }
@@ -10,15 +10,15 @@ import I18nPluginIntroduce from '@site-docs/components/international/introduce';
10
10
 
11
11
  ## Where to start?
12
12
 
13
- | What you want to do | Documentation |
14
- | --- | --- |
15
- | Integrate for the first time and run an example | [Quick Start](./international/quick-start.md) |
16
- | Learn all configuration options | [Configuration](./international/configuration.md) |
17
- | Detect language from URL / Cookie / Header | [Locale Detection](./international/locale-detection.md) |
18
- | Implement paths with locale prefixes, such as `/en/about` | [Routing Integration](./international/routing.md) |
13
+ | What you want to do | Documentation |
14
+ | ------------------------------------------------------------ | ---------------------------------------------------------------------------------------- |
15
+ | Integrate for the first time and run an example | [Quick Start](./international/quick-start.md) |
16
+ | Learn all configuration options | [Configuration](./international/configuration.md) |
17
+ | Detect language from URL / Cookie / Header | [Locale Detection](./international/locale-detection.md) |
18
+ | Implement paths with locale prefixes, such as `/en/about` | [Routing Integration](./international/routing.md) |
19
19
  | Load translation resources from a remote service or platform | [Resource Loading -> Custom Backend](./international/resource-loading.md#custom-backend) |
20
- | SSR, multiple entries, or custom instances | [Advanced Usage](./international/advanced.md) |
21
- | Look up Hooks / components / type definitions | [API Reference](./international/api.md) |
20
+ | SSR, multiple entries, or custom instances | [Advanced Usage](./international/advanced.md) |
21
+ | Look up Hooks / components / type definitions | [API Reference](./international/api.md) |
22
22
 
23
23
  ## Core Capabilities
24
24
 
@@ -6,11 +6,11 @@ Log events are distributed by Modern.js as events of type `log`.
6
6
 
7
7
  Based on server-side runtime logic, Modern.js provides the following log events:
8
8
 
9
- | Stage | Message | Level |
10
- | --------------- | -------------------------------------------- | ----- |
11
- | RENDER_HTML | App Render To HTML | error |
12
- | RENDER_STREAM | An error occurs during streaming SSR | error |
13
- | RENDER_SHELL | An error occurs during streaming render shell | error |
9
+ | Stage | Message | Level |
10
+ | ------------- | --------------------------------------------- | ----- |
11
+ | RENDER_HTML | App Render To HTML | error |
12
+ | RENDER_STREAM | An error occurs during streaming SSR | error |
13
+ | RENDER_SHELL | An error occurs during streaming render shell | error |
14
14
 
15
15
  ## Built-in Monitor
16
16