@intlayer/docs 9.3.1 → 9.3.2
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/dist/cjs/generated/docs.entry.cjs +20 -0
- package/dist/cjs/generated/docs.entry.cjs.map +1 -1
- package/dist/esm/generated/docs.entry.mjs +20 -0
- package/dist/esm/generated/docs.entry.mjs.map +1 -1
- package/dist/types/generated/docs.entry.d.ts +1 -0
- package/dist/types/generated/docs.entry.d.ts.map +1 -1
- package/docs/ar/eslint.md +336 -0
- package/docs/ar/intlayer_with_react_router_v7_fs_routes.md +1 -1
- package/docs/bn/eslint.md +336 -0
- package/docs/cs/eslint.md +336 -0
- package/docs/de/eslint.md +336 -0
- package/docs/en/eslint.md +336 -0
- package/docs/en-GB/eslint.md +336 -0
- package/docs/en-GB/intlayer_with_create_react_app.md +32 -35
- package/docs/en-GB/intlayer_with_react_router_v7_fs_routes.md +1 -1
- package/docs/es/eslint.md +336 -0
- package/docs/fr/eslint.md +336 -0
- package/docs/hi/eslint.md +336 -0
- package/docs/hi/intlayer_with_react_router_v7_fs_routes.md +1 -1
- package/docs/hi/intlayer_with_vite+svelte.md +2 -2
- package/docs/id/eslint.md +336 -0
- package/docs/it/eslint.md +336 -0
- package/docs/ja/eslint.md +336 -0
- package/docs/ja/intlayer_with_react_router_v7.md +1 -146
- package/docs/ja/intlayer_with_vite+react.md +5 -1
- package/docs/ko/eslint.md +336 -0
- package/docs/ko/intlayer_with_lynx+react.md +4 -0
- package/docs/ko/intlayer_with_react_router_v7_fs_routes.md +1 -1
- package/docs/ko/intlayer_with_storybook.md +5 -5
- package/docs/nl/eslint.md +336 -0
- package/docs/pl/eslint.md +336 -0
- package/docs/pl/intlayer_with_astro.md +1 -114
- package/docs/pl/migration_from_i18next_to_intlayer.md +4 -0
- package/docs/pl/migration_from_next-i18next_to_intlayer.md +8 -4
- package/docs/pl/migration_from_next-intl_to_intlayer.md +11 -5
- package/docs/pl/migration_from_nuxtjs_i18n_to_intlayer.md +8 -4
- package/docs/pl/migration_from_react-i18next_to_intlayer.md +8 -4
- package/docs/pl/migration_from_vue-i18n_to_intlayer.md +4 -0
- package/docs/pt/eslint.md +336 -0
- package/docs/pt/intlayer_with_astro.md +1 -114
- package/docs/ru/eslint.md +336 -0
- package/docs/tr/eslint.md +336 -0
- package/docs/uk/eslint.md +336 -0
- package/docs/uk/packages/angular-intlayer/exports.md +2 -2
- package/docs/ur/eslint.md +336 -0
- package/docs/vi/eslint.md +336 -0
- package/docs/zh/eslint.md +336 -0
- package/docs/zh/intlayer_with_create_react_app.md +4 -0
- package/docs/zh/intlayer_with_lynx+react.md +4 -0
- package/docs/zh/intlayer_with_nextjs_14.md +0 -2
- package/docs/zh/intlayer_with_nextjs_15.md +0 -2
- package/docs/zh/intlayer_with_nextjs_page_router.md +0 -2
- package/docs/zh/intlayer_with_nuxt.md +1 -1
- package/docs/zh/intlayer_with_react_router_v7.md +4 -0
- package/docs/zh/intlayer_with_react_router_v7_fs_routes.md +4 -0
- package/docs/zh/intlayer_with_solid_start.md +1 -1
- package/docs/zh/intlayer_with_vite+vue.md +0 -2
- package/docs/zh-TW/eslint.md +336 -0
- package/package.json +6 -6
- package/src/generated/docs.entry.ts +20 -0
|
@@ -531,8 +531,6 @@ const ServerComponentExample: FC = () => {
|
|
|
531
531
|
|
|
532
532
|
> 若要了解有关 `useIntlayer` 钩子的更多信息,请参阅[文档](https://github.com/aymericzip/intlayer/blob/main/docs/docs/zh/packages/next-intlayer/useIntlayer.md)。
|
|
533
533
|
|
|
534
|
-
<Steps>
|
|
535
|
-
|
|
536
534
|
</Step>
|
|
537
535
|
|
|
538
536
|
<Step number={8} title="元数据的国际化">
|
|
@@ -433,8 +433,6 @@ export const ServerComponentExample: FC = () => {
|
|
|
433
433
|
|
|
434
434
|
> 要了解有关 `useIntlayer` 钩子的更多信息,请参阅[文档](https://github.com/aymericzip/intlayer/blob/main/docs/docs/zh/packages/next-intlayer/useIntlayer.md)。
|
|
435
435
|
|
|
436
|
-
<Steps>
|
|
437
|
-
|
|
438
436
|
</Step>
|
|
439
437
|
|
|
440
438
|
<Step number={7} title="配置中间件以检测语言环境">
|
|
@@ -514,8 +514,6 @@ const ComponentExample = () => {
|
|
|
514
514
|
|
|
515
515
|
> 要了解有关 `useIntlayer` 钩子的更多信息,请参阅[文档](https://github.com/aymericzip/intlayer/blob/main/docs/docs/zh/packages/next-intlayer/useIntlayer.md)。
|
|
516
516
|
|
|
517
|
-
<Steps>
|
|
518
|
-
|
|
519
517
|
</Step>
|
|
520
518
|
|
|
521
519
|
<Step number={8} title="元数据的国际化">
|
|
@@ -314,7 +314,7 @@ Intlayer 提供了多种 API 来访问您的内容:
|
|
|
314
314
|
- 使用 `const content = useIntlayer("myContent");` 以及 `{{ content.myContent }}` / `<content.myContent />`。
|
|
315
315
|
- 或者使用 `const { myContent } = useIntlayer("myContent");` 以及 `{{ myContent}}` / `<myContent/>` 来解构内容。
|
|
316
316
|
|
|
317
|
-
|
|
317
|
+
</Step>
|
|
318
318
|
|
|
319
319
|
<Step number={6} title="更改内容语言">
|
|
320
320
|
|
|
@@ -198,6 +198,10 @@ export default config;
|
|
|
198
198
|
|
|
199
199
|
> 通过此配置文件,您可以设置本地化的 URL、中间件重定向、cookie 名称、内容声明的位置和扩展名,禁用控制台中的 Intlayer 日志等。有关可用参数的完整列表,请参阅[配置文档](https://github.com/aymericzip/intlayer/blob/main/docs/docs/zh/configuration.md)。
|
|
200
200
|
|
|
201
|
+
<Steps>
|
|
202
|
+
|
|
203
|
+
<Step number={5} title="创建根布局">
|
|
204
|
+
|
|
201
205
|
#### 根布局
|
|
202
206
|
|
|
203
207
|
```tsx fileName="app/root.tsx"
|
|
@@ -131,6 +131,10 @@ export default config;
|
|
|
131
131
|
|
|
132
132
|
> 通过此配置文件,您可以设置本地化的 URL、中间件重定向、cookie 名称、内容声明的位置和扩展名,禁用控制台中的 Intlayer 日志等。有关可用参数的完整列表,请参阅[配置文档](https://github.com/aymericzip/intlayer/blob/main/docs/docs/zh/configuration.md)。
|
|
133
133
|
|
|
134
|
+
<Steps>
|
|
135
|
+
|
|
136
|
+
<Step number={5} title="创建根布局">
|
|
137
|
+
|
|
134
138
|
#### 文件结构
|
|
135
139
|
|
|
136
140
|
```bash
|
|
@@ -572,7 +572,7 @@ export const Nav: Component = () => {
|
|
|
572
572
|
|
|
573
573
|
<Step number={10} title="创建语言切换器组件">
|
|
574
574
|
|
|
575
|
-
将切换器渲染为**真实的
|
|
575
|
+
将切换器渲染为**真实的 `<a>` 锚点**而非 `<select>`:当前页面的每种语言都会变为可爬取的链接,并且可以在新标签页中打开,这是仅依靠 JavaScript 的控件无法提供的。
|
|
576
576
|
|
|
577
577
|
`getPathWithoutLocale` 会从当前路径中剥离语言段,而 `getLocalizedUrl` 会为目标语言重新构建它,因此这些链接会遵循你的路由模式,无需硬编码任何内容。导航是改变渲染语言的原因 —— `[[locale]]` 路由从 URL 中推导语言 —— 而 `setLocale` 会将选择保存在 `INTLAYER_LOCALE` cookie 中,以便以后访问无语言前缀的 URL 时能解析为相同的语言。
|
|
578
578
|
|
|
@@ -444,8 +444,6 @@ Intlayer 提供了多种 API 来访问您的内容:
|
|
|
444
444
|
|
|
445
445
|
> 如果您的应用程序已经存在,您可以结合使用 [Intlayer 编译器](https://github.com/aymericzip/intlayer/blob/main/docs/docs/zh/compiler.md) 和 [提取命令](https://github.com/aymericzip/intlayer/blob/main/docs/docs/zh/cli/extract.md) 在一秒钟内转换成干个组件。
|
|
446
446
|
|
|
447
|
-
<Steps>
|
|
448
|
-
|
|
449
447
|
</Step>
|
|
450
448
|
|
|
451
449
|
<Step number={6} title="更改内容语言">
|
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
---
|
|
2
|
+
createdAt: 2026-08-12
|
|
3
|
+
updatedAt: 2026-08-12
|
|
4
|
+
title: ESLint 外掛 | Intlayer 的 Lint 規則
|
|
5
|
+
description: 使用 eslint-plugin-intlayer 捕捉硬編碼字串、Intlayer 編譯器無法最佳化的動態呼叫以及未使用的字典內容。支援 ESLint 與 oxlint,適用於 React、Vue、Svelte、Angular 與 Astro。
|
|
6
|
+
keywords:
|
|
7
|
+
- Intlayer
|
|
8
|
+
- ESLint
|
|
9
|
+
- oxlint
|
|
10
|
+
- 程式碼檢查
|
|
11
|
+
- i18n
|
|
12
|
+
- 國際化
|
|
13
|
+
- no-raw-text
|
|
14
|
+
- 硬編碼字串
|
|
15
|
+
- 未使用的翻譯
|
|
16
|
+
- 死內容
|
|
17
|
+
- React
|
|
18
|
+
- Vue
|
|
19
|
+
- Svelte
|
|
20
|
+
- Angular
|
|
21
|
+
slugs:
|
|
22
|
+
- doc
|
|
23
|
+
- eslint
|
|
24
|
+
history:
|
|
25
|
+
- version: 9.3.1
|
|
26
|
+
date: 2026-08-12
|
|
27
|
+
changes: "初始化歷史"
|
|
28
|
+
author: aymericzip
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
# ESLint x OXLint 外掛
|
|
32
|
+
|
|
33
|
+
`eslint-plugin-intlayer` 能夠捕捉 TypeScript 無法發現的幾類 i18n 錯誤:
|
|
34
|
+
|
|
35
|
+
1. **硬編碼文字**:從未寫入字典中的文字。
|
|
36
|
+
2. **動態呼叫**:能夠通過型別檢查並正常執行,但 Intlayer 編譯器無法進行最佳化的呼叫。
|
|
37
|
+
3. **死內容(Dead content)**:專案中沒有任何地方讀取的字典與欄位(需手動開啟)。
|
|
38
|
+
|
|
39
|
+
未知的字典鍵、未知的欄位路徑與缺失的語系本身已是編譯錯誤,因此外掛不會重複回報它們。
|
|
40
|
+
|
|
41
|
+
## 安裝
|
|
42
|
+
|
|
43
|
+
```bash packageManager="npm"
|
|
44
|
+
npm install --save-dev eslint-plugin-intlayer
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
```bash packageManager="pnpm"
|
|
48
|
+
pnpm add --save-dev eslint-plugin-intlayer
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
```bash packageManager="yarn"
|
|
52
|
+
yarn add --dev eslint-plugin-intlayer
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
需要 ESLint 9 或更高版本(Flat config)。
|
|
56
|
+
|
|
57
|
+
## 使用方法
|
|
58
|
+
|
|
59
|
+
此外掛可在 ESLint 與 [oxlint](https://oxc.rs) 中執行 — 擁有相同的規則與設定選項。
|
|
60
|
+
|
|
61
|
+
<Tabs defaultTab="eslint">
|
|
62
|
+
<Tab label="ESLint" value="eslint">
|
|
63
|
+
|
|
64
|
+
```javascript fileName="eslint.config.mjs" codeFormat="esm"
|
|
65
|
+
import intlayer from "eslint-plugin-intlayer";
|
|
66
|
+
|
|
67
|
+
export default [...intlayer.configs.recommended];
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
或者逐一啟用規則:
|
|
71
|
+
|
|
72
|
+
```javascript fileName="eslint.config.mjs" codeFormat="esm"
|
|
73
|
+
import intlayer from "eslint-plugin-intlayer";
|
|
74
|
+
|
|
75
|
+
export default [
|
|
76
|
+
{
|
|
77
|
+
plugins: { intlayer },
|
|
78
|
+
rules: {
|
|
79
|
+
"intlayer/no-raw-text": "warn",
|
|
80
|
+
"intlayer/static-dictionary-key": "error",
|
|
81
|
+
"intlayer/no-dynamic-field-access": "error",
|
|
82
|
+
"intlayer/enforce-adapter-import": "warn",
|
|
83
|
+
"intlayer/no-unused-content": "warn",
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
];
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
</Tab>
|
|
90
|
+
<Tab label="oxlint" value="oxlint">
|
|
91
|
+
|
|
92
|
+
```json fileName=".oxlintrc.json"
|
|
93
|
+
{
|
|
94
|
+
"jsPlugins": ["eslint-plugin-intlayer"],
|
|
95
|
+
"rules": {
|
|
96
|
+
"intlayer/no-raw-text": "warn",
|
|
97
|
+
"intlayer/static-dictionary-key": "error",
|
|
98
|
+
"intlayer/no-dynamic-field-access": "error",
|
|
99
|
+
"intlayer/enforce-adapter-import": "warn"
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
兩點注意事項:oxlint 對 JS 外掛的支援仍處於 Alpha 階段,且 oxlint 不支援自訂解析器 — 因此 `.vue`、`.svelte`、`.astro` 與 Angular 範本無法在此處進行 lint。請在 JS/TS/JSX 檔案上執行 oxlint,其餘檔案保留使用 ESLint。
|
|
105
|
+
|
|
106
|
+
上面特意排除了 `no-unused-content`:它需要從規則上下文中取得工作目錄與被檢查檔案的路徑,而 Alpha 階段的 JS 外掛橋接層無法保證提供這些資訊。請在 ESLint 下執行該規則。
|
|
107
|
+
|
|
108
|
+
</Tab>
|
|
109
|
+
</Tabs>
|
|
110
|
+
|
|
111
|
+
### 預設設定
|
|
112
|
+
|
|
113
|
+
| 設定 | `no-raw-text` | `static-dictionary-key` | `no-dynamic-field-access` | `enforce-adapter-import` | `no-unused-content` |
|
|
114
|
+
| --------------- | ----------------------- | ----------------------- | ------------------------- | ------------------------ | ------------------- |
|
|
115
|
+
| `recommended` | warn | error | error | off | off |
|
|
116
|
+
| `strict` | error (+ 非 JSX 字面量) | error | error | error | off |
|
|
117
|
+
| `contract-only` | off | error | error | off | off |
|
|
118
|
+
|
|
119
|
+
`recommended` 特意將 `no-raw-text` 設為 `warn`:將其指向現有程式碼庫會一次性暴露所有未翻譯的字串,這不應該在第一天就導致建置中斷。
|
|
120
|
+
|
|
121
|
+
`enforce-adapter-import` 預設關閉 — 如果需要請明確啟用。
|
|
122
|
+
|
|
123
|
+
`no-unused-content` 在所有設定中均預設關閉(包含 `strict`)。這是唯一一個需要讀取 Intlayer 設定並從磁碟遍歷來源檔案的規則,因此啟用它應當是一項經過深思熟慮的選擇,而非預設自動執行的行為。
|
|
124
|
+
|
|
125
|
+
## 規則列表
|
|
126
|
+
|
|
127
|
+
### `no-raw-text`
|
|
128
|
+
|
|
129
|
+
回報未在字典中宣告的面向使用者文字。它使用與 `intlayer extract` 相同的偵測邏輯,因此品牌名稱、CSS 類別名稱與技術識別碼都會被忽略。
|
|
130
|
+
|
|
131
|
+
```jsx
|
|
132
|
+
// ✗ 回報錯誤
|
|
133
|
+
<h1>Welcome to our documentation</h1>
|
|
134
|
+
<input placeholder="Enter your email address" />
|
|
135
|
+
|
|
136
|
+
// ✓ 正常
|
|
137
|
+
const { title } = useIntlayer("home");
|
|
138
|
+
<h1>{title}</h1>
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
內容宣告檔案(`*.content.ts`, …)會被略過。
|
|
142
|
+
|
|
143
|
+
若要一次性修復整個檔案,執行 `npx intlayer extract`,讓編譯器自動將字串移入字典。
|
|
144
|
+
|
|
145
|
+
**設定選項**
|
|
146
|
+
|
|
147
|
+
```javascript fileName="eslint.config.mjs" codeFormat="esm"
|
|
148
|
+
{
|
|
149
|
+
"intlayer/no-raw-text": [
|
|
150
|
+
"warn",
|
|
151
|
+
{
|
|
152
|
+
// 值為面向使用者文字的屬性列表。
|
|
153
|
+
// 預設值: title, placeholder, alt, aria-label, label
|
|
154
|
+
attributes: ["title", "placeholder", "alt", "aria-label", "label"],
|
|
155
|
+
|
|
156
|
+
// 內容絕非面向使用者文字的元素列表。
|
|
157
|
+
// 預設值: code, pre, script, style
|
|
158
|
+
ignoreElements: ["code", "pre", "script", "style"],
|
|
159
|
+
|
|
160
|
+
// 絕不回報的文字正規表示式。
|
|
161
|
+
ignorePatterns: ["^Powered by"],
|
|
162
|
+
|
|
163
|
+
// 是否同時回報標記語言之外的字串字面量。預設值: false
|
|
164
|
+
includeStringLiterals: false,
|
|
165
|
+
},
|
|
166
|
+
],
|
|
167
|
+
}
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### `static-dictionary-key`
|
|
171
|
+
|
|
172
|
+
要求字典鍵必須是字串字面量。
|
|
173
|
+
|
|
174
|
+
編譯器只有在呼叫位置直接讀取到鍵時,才能預先載入字典。使用計算鍵會無訊息略過最佳化,轉而打包所有字典。
|
|
175
|
+
|
|
176
|
+
```typescript
|
|
177
|
+
// ✗ 回報錯誤
|
|
178
|
+
useIntlayer(dictionaryKey);
|
|
179
|
+
useIntlayer(`home-${suffix}`);
|
|
180
|
+
getTranslations({ namespace: page });
|
|
181
|
+
|
|
182
|
+
// ✗ 變數仍然不是字面量
|
|
183
|
+
const key = "home";
|
|
184
|
+
useIntlayer(key);
|
|
185
|
+
|
|
186
|
+
// ✓ 正常
|
|
187
|
+
useIntlayer("home");
|
|
188
|
+
getTranslations({ namespace: "home" });
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
這適用於 `useIntlayer`、`getIntlayer` 以及所有相容介面卡(`useTranslation`、`useTranslations`、`formatMessage`、`<FormattedMessage id>`、`<Trans i18nKey>` 等)。
|
|
192
|
+
|
|
193
|
+
### `no-dynamic-field-access`
|
|
194
|
+
|
|
195
|
+
要求從字典中讀取的欄位必須是靜態已知的。
|
|
196
|
+
|
|
197
|
+
編譯器會移除它未偵測到使用的欄位。動態計算存取對其不可見,因此該讀取在執行階段可能會回傳 `undefined`。
|
|
198
|
+
|
|
199
|
+
```typescript
|
|
200
|
+
// ✗ 回報錯誤
|
|
201
|
+
const content = useIntlayer("home");
|
|
202
|
+
content[fieldName];
|
|
203
|
+
|
|
204
|
+
const t = useTranslations("home");
|
|
205
|
+
t(messageKey);
|
|
206
|
+
|
|
207
|
+
// ✓ 正常
|
|
208
|
+
content.title;
|
|
209
|
+
content["title"];
|
|
210
|
+
content.items[0];
|
|
211
|
+
t("hero.title");
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
### `enforce-adapter-import`
|
|
215
|
+
|
|
216
|
+
優先使用 `@intlayer/*` 相容介面卡而非原始套件。原始套件僅在設定了打包工具別名時才會解析為 Intlayer;而介面卡始終生效。可透過 `--fix` 自動修復。
|
|
217
|
+
|
|
218
|
+
```typescript
|
|
219
|
+
// ✗ 回報錯誤
|
|
220
|
+
import { useTranslation } from "react-i18next";
|
|
221
|
+
import { getTranslations } from "next-intl/server";
|
|
222
|
+
|
|
223
|
+
// ✓ 正常
|
|
224
|
+
import { useTranslation } from "@intlayer/react-i18next";
|
|
225
|
+
import { getTranslations } from "@intlayer/next-intl/server";
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
### `no-unused-content`
|
|
229
|
+
|
|
230
|
+
**預設關閉。** 回報專案中沒有任何地方讀取的內容,以及在多個位置宣告的字典鍵。
|
|
231
|
+
|
|
232
|
+
```typescript fileName="src/home.content.ts"
|
|
233
|
+
export default {
|
|
234
|
+
key: "home", // ✗ 當專案中沒有任何呼叫端請求 "home" 時回報
|
|
235
|
+
content: {
|
|
236
|
+
title: t({ "zh-TW": "標題", en: "Title" }),
|
|
237
|
+
|
|
238
|
+
// ✗ 當沒有任何地方讀取 `hero` 時回報
|
|
239
|
+
hero: {
|
|
240
|
+
subtitle: t({ "zh-TW": "副標題", en: "Subtitle" }),
|
|
241
|
+
},
|
|
242
|
+
},
|
|
243
|
+
};
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
與其他規則不同,此規則無法僅憑眼前的檔案給出判斷 — 欄位是否未使用僅相對於整個專案而言。在一次 lint 執行的首次內容宣告時,它會載入你的 Intlayer 設定,比對該設定宣告的來源檔案(`build.traversePattern`、`compiler.transformPattern`),並執行驅動 `@intlayer/lsp` 與 VS Code 擴充套件中「未使用」刪除線的同一套使用情況分析器。結果會快取 `cacheTtl` 毫秒,因此每次執行只會掃描一次,而不是每個檔案掃描一次。
|
|
247
|
+
|
|
248
|
+
**設定選項**
|
|
249
|
+
|
|
250
|
+
```javascript fileName="eslint.config.mjs" codeFormat="esm"
|
|
251
|
+
{
|
|
252
|
+
"intlayer/no-unused-content": [
|
|
253
|
+
"warn",
|
|
254
|
+
{
|
|
255
|
+
// 回報沒有任何地方引用的字典鍵。預設值: true
|
|
256
|
+
reportUnusedDictionaries: true,
|
|
257
|
+
|
|
258
|
+
// 回報沒有任何地方讀取的內容欄位。預設值: true
|
|
259
|
+
reportUnusedFields: true,
|
|
260
|
+
|
|
261
|
+
// 回報在多處宣告的重複鍵。預設值: true
|
|
262
|
+
reportDuplicateKeys: true,
|
|
263
|
+
|
|
264
|
+
// 絕不回報的欄位路徑正規表示式。
|
|
265
|
+
ignoreFields: ["^meta"],
|
|
266
|
+
|
|
267
|
+
// 掃描起始的專案根目錄。預設值: ESLint 的工作目錄
|
|
268
|
+
baseDir: process.cwd(),
|
|
269
|
+
|
|
270
|
+
// 專案掃描結果重複使用時長(毫秒)。預設值: 30000
|
|
271
|
+
cacheTtl: 30000,
|
|
272
|
+
},
|
|
273
|
+
],
|
|
274
|
+
}
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
如果你在長期執行的編輯器服務中進行 lint 且希望更快看到修改結果,可以降低 `cacheTtl`;當單次 lint 執行跨越 monorepo 中的多個 Intlayer 專案時,請設定 `baseDir`。
|
|
278
|
+
|
|
279
|
+
> **傾向於保持沉默。** 此處的誤報會導致翻譯被誤刪,因此當字典以分析器無法追蹤的方式被使用時,不會回報任何內容:內容物件被整體傳遞、從中繫結的翻譯函式(`const t = useTranslations("home")`)、透過直接匯入存取的宣告(`useDictionary(myDictionary)`)、來自另一個字典的 `nest()`、或者因 spread 展開而不詳盡的欄位列表。單一檔案元件(`.vue`、`.svelte`、`.astro`)計為使用了它們提及的字典中的所有欄位,因為它們的指令碼區塊在此處不會被解析。
|
|
280
|
+
|
|
281
|
+
`reportDuplicateKeys` 讀取建置時寫入 `.intlayer/` 下的未合併字典,因此在專案至少建置過一次之前它會保持安靜。共享一個鍵的兩個宣告會被合併,這是一種合法的模式 — 該回報之所以存在,是因為在兩邊同時定義的欄位會無訊息保留兩個值中的一個。
|
|
282
|
+
|
|
283
|
+
分析器從以 ESM 形式發布的 `@intlayer/lsp` 中載入。因此該規則需要能夠 `require()` ES 模組的 Node 版本 — Node 20.19+ 或 22.12+。在更低版本上,它不會回報錯誤中斷 lint 執行,而是什麼都不回報。
|
|
284
|
+
|
|
285
|
+
## 框架支援
|
|
286
|
+
|
|
287
|
+
每條規則均適用於所有 Intlayer 整合,包含 Vue、Svelte 與 Angular 範本內部。你只需告訴 ESLint 哪個解析器負責讀取對應的檔案類型即可。
|
|
288
|
+
|
|
289
|
+
| 框架 | 檔案 | 解析器 |
|
|
290
|
+
| ------------------------- | ----------------- | --------------------------------- |
|
|
291
|
+
| React, Preact, Solid, Lit | `.jsx` `.tsx` | `typescript-eslint` |
|
|
292
|
+
| Next.js | `.jsx` `.tsx` | `typescript-eslint` |
|
|
293
|
+
| Vue, Nuxt | `.vue` | `vue-eslint-parser` |
|
|
294
|
+
| Svelte, SvelteKit | `.svelte` | `svelte-eslint-parser` |
|
|
295
|
+
| Angular | `.ts` | `typescript-eslint` |
|
|
296
|
+
| Angular 範本 | `.component.html` | `@angular-eslint/template-parser` |
|
|
297
|
+
| Astro | `.astro` | `astro-eslint-parser` |
|
|
298
|
+
|
|
299
|
+
```javascript fileName="eslint.config.mjs" codeFormat="esm"
|
|
300
|
+
import intlayer from "eslint-plugin-intlayer";
|
|
301
|
+
import tseslint from "typescript-eslint";
|
|
302
|
+
import vueParser from "vue-eslint-parser";
|
|
303
|
+
import svelteParser from "svelte-eslint-parser";
|
|
304
|
+
import angularTemplateParser from "@angular-eslint/template-parser";
|
|
305
|
+
|
|
306
|
+
export default [
|
|
307
|
+
...intlayer.configs.recommended,
|
|
308
|
+
|
|
309
|
+
{
|
|
310
|
+
files: ["**/*.{ts,tsx,jsx}"],
|
|
311
|
+
languageOptions: { parser: tseslint.parser },
|
|
312
|
+
},
|
|
313
|
+
{
|
|
314
|
+
files: ["**/*.vue"],
|
|
315
|
+
languageOptions: {
|
|
316
|
+
parser: vueParser,
|
|
317
|
+
parserOptions: { parser: tseslint.parser },
|
|
318
|
+
},
|
|
319
|
+
},
|
|
320
|
+
{
|
|
321
|
+
files: ["**/*.svelte"],
|
|
322
|
+
languageOptions: {
|
|
323
|
+
parser: svelteParser,
|
|
324
|
+
parserOptions: { parser: tseslint.parser },
|
|
325
|
+
},
|
|
326
|
+
},
|
|
327
|
+
{
|
|
328
|
+
files: ["**/*.component.html"],
|
|
329
|
+
languageOptions: { parser: angularTemplateParser },
|
|
330
|
+
},
|
|
331
|
+
];
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
請僅安裝專案所需的解析器。
|
|
335
|
+
|
|
336
|
+
> **已知限制。** 在 Vue 與 Angular 範本中,類似於 `{{ content[key] }}` 的運算式不會被 `no-dynamic-field-access` 檢查。寫在 script 區塊中的動態讀取仍會被正常捕捉。
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intlayer/docs",
|
|
3
|
-
"version": "9.3.
|
|
3
|
+
"version": "9.3.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Intlayer documentation",
|
|
6
6
|
"keywords": [
|
|
@@ -73,13 +73,13 @@
|
|
|
73
73
|
"watch": "webpack --config ./webpack.config.ts --watch"
|
|
74
74
|
},
|
|
75
75
|
"dependencies": {
|
|
76
|
-
"@intlayer/config": "9.3.
|
|
77
|
-
"@intlayer/core": "9.3.
|
|
78
|
-
"@intlayer/types": "9.3.
|
|
76
|
+
"@intlayer/config": "9.3.2",
|
|
77
|
+
"@intlayer/core": "9.3.2",
|
|
78
|
+
"@intlayer/types": "9.3.2"
|
|
79
79
|
},
|
|
80
80
|
"devDependencies": {
|
|
81
|
-
"@intlayer/api": "9.3.
|
|
82
|
-
"@intlayer/cli": "9.3.
|
|
81
|
+
"@intlayer/api": "9.3.2",
|
|
82
|
+
"@intlayer/cli": "9.3.2",
|
|
83
83
|
"@types/node": "26.2.0",
|
|
84
84
|
"@utils/ts-config": "1.0.4",
|
|
85
85
|
"@utils/ts-config-types": "1.0.4",
|
|
@@ -1485,6 +1485,26 @@ export const docsEntry = {
|
|
|
1485
1485
|
vi: readLocale('dynamic_dictionaries/variants.md', 'vi'),
|
|
1486
1486
|
uk: readLocale('dynamic_dictionaries/variants.md', 'uk'),
|
|
1487
1487
|
} as unknown as Record<LocalesValues, Promise<string>>,
|
|
1488
|
+
'./docs/en/eslint.md': {
|
|
1489
|
+
en: readLocale('eslint.md', 'en'),
|
|
1490
|
+
es: readLocale('eslint.md', 'es'),
|
|
1491
|
+
ru: readLocale('eslint.md', 'ru'),
|
|
1492
|
+
ja: readLocale('eslint.md', 'ja'),
|
|
1493
|
+
fr: readLocale('eslint.md', 'fr'),
|
|
1494
|
+
ko: readLocale('eslint.md', 'ko'),
|
|
1495
|
+
zh: readLocale('eslint.md', 'zh'),
|
|
1496
|
+
de: readLocale('eslint.md', 'de'),
|
|
1497
|
+
ar: readLocale('eslint.md', 'ar'),
|
|
1498
|
+
it: readLocale('eslint.md', 'it'),
|
|
1499
|
+
'en-GB': readLocale('eslint.md', 'en-GB'),
|
|
1500
|
+
pt: readLocale('eslint.md', 'pt'),
|
|
1501
|
+
hi: readLocale('eslint.md', 'hi'),
|
|
1502
|
+
tr: readLocale('eslint.md', 'tr'),
|
|
1503
|
+
pl: readLocale('eslint.md', 'pl'),
|
|
1504
|
+
id: readLocale('eslint.md', 'id'),
|
|
1505
|
+
vi: readLocale('eslint.md', 'vi'),
|
|
1506
|
+
uk: readLocale('eslint.md', 'uk'),
|
|
1507
|
+
} as unknown as Record<LocalesValues, Promise<string>>,
|
|
1488
1508
|
'./docs/en/formatters.md': {
|
|
1489
1509
|
en: readLocale('formatters.md', 'en'),
|
|
1490
1510
|
es: readLocale('formatters.md', 'es'),
|