@npm-questionpro/wick-ui-i18n 2.0.0-next.31 → 2.0.0-next.32
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/README.md +9 -11
- package/index.d.ts +12 -13
- package/index.js +24 -7
- package/package.json +1 -1
- package/src/processor.js +1 -1
package/README.md
CHANGED
|
@@ -33,17 +33,15 @@ export default defineConfig({plugins: [react(), wickI18n()]})
|
|
|
33
33
|
|
|
34
34
|
## Options
|
|
35
35
|
|
|
36
|
-
| Option | Default | Description
|
|
37
|
-
| ------------------- | ----------------------------------------------------------------- |
|
|
38
|
-
| `components` | `[]` | Extra components treated like Wu\*
|
|
39
|
-
| `ignoreComponents` | `[]` | Extra components never translated
|
|
40
|
-
| `translatableProps` | `['Label','placeholder','title','aria-label','aria-placeholder']` | Props rewritten to `useWt()()`
|
|
41
|
-
| `dataLabelKeys` | `[]` | Property names whose values are labels in mixed data files
|
|
42
|
-
| `dictionaryFiles` | — |
|
|
43
|
-
| `excludeFiles` | — | Files skipped entirely
|
|
44
|
-
| `debug` | `false` | Print extraction table at build
|
|
45
|
-
|
|
46
|
-
> **Deprecated:** `extractFromKeys` → `dataLabelKeys` · `resolveFiles` → `dictionaryFiles`
|
|
36
|
+
| Option | Default | Description |
|
|
37
|
+
| ------------------- | ----------------------------------------------------------------- | --------------------------------------------------------------------------------------- |
|
|
38
|
+
| `components` | `[]` | Extra components treated like Wu\* |
|
|
39
|
+
| `ignoreComponents` | `[]` | Extra components never translated |
|
|
40
|
+
| `translatableProps` | `['Label','placeholder','title','aria-label','aria-placeholder']` | Props rewritten to `useWt()()` |
|
|
41
|
+
| `dataLabelKeys` | `[]` | Property names whose values are labels in mixed data files |
|
|
42
|
+
| `dictionaryFiles` | — | Globs (project files via Vite) or exact paths (anywhere, incl. `node_modules` via `fs`) |
|
|
43
|
+
| `excludeFiles` | — | Files skipped entirely |
|
|
44
|
+
| `debug` | `false` | Print extraction table at build |
|
|
47
45
|
|
|
48
46
|
---
|
|
49
47
|
|
package/index.d.ts
CHANGED
|
@@ -39,11 +39,20 @@ export interface WickI18nOptions {
|
|
|
39
39
|
* Use **only** for dedicated enum/constant files. Do NOT point at mixed data
|
|
40
40
|
* files — use `dataLabelKeys` for those.
|
|
41
41
|
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
42
|
+
* Two modes depending on the value:
|
|
43
|
+
* - **Glob patterns** (`'src/enums/*.ts'`) — matched via Vite's transform pipeline.
|
|
44
|
+
* Works for files in your project; does **not** reach `node_modules`.
|
|
45
|
+
* - **Exact paths** (`'node_modules/@company/shared/enums.ts'`) — read directly
|
|
46
|
+
* with `fs` at build time, bypassing Vite's transform pipeline. Use this for
|
|
47
|
+
* `node_modules` files. Missing files produce a `console.warn`.
|
|
48
|
+
*
|
|
49
|
+
* Both modes can be mixed in the same array.
|
|
44
50
|
*
|
|
45
51
|
* @example
|
|
46
|
-
* dictionaryFiles: [
|
|
52
|
+
* dictionaryFiles: [
|
|
53
|
+
* 'src/enums/*.ts', // glob — project files
|
|
54
|
+
* 'node_modules/@company/shared/enums.ts', // exact — node_modules
|
|
55
|
+
* ]
|
|
47
56
|
*/
|
|
48
57
|
dictionaryFiles?: string | RegExp | Array<string | RegExp>
|
|
49
58
|
|
|
@@ -52,16 +61,6 @@ export interface WickI18nOptions {
|
|
|
52
61
|
|
|
53
62
|
/** Print a build-time extraction report table to stdout. */
|
|
54
63
|
debug?: boolean
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* @deprecated Use `dataLabelKeys` instead.
|
|
58
|
-
*/
|
|
59
|
-
extractFromKeys?: string[]
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* @deprecated Use `dictionaryFiles` instead.
|
|
63
|
-
*/
|
|
64
|
-
resolveFiles?: string | RegExp | Array<string | RegExp>
|
|
65
64
|
}
|
|
66
65
|
|
|
67
66
|
/**
|
package/index.js
CHANGED
|
@@ -18,6 +18,8 @@
|
|
|
18
18
|
* };
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
|
+
import fs from 'node:fs'
|
|
22
|
+
import path from 'node:path'
|
|
21
23
|
import {createFilter} from 'vite'
|
|
22
24
|
import {TranslationProcessor} from './src/processor.js'
|
|
23
25
|
import {transformFile} from './src/transform.js'
|
|
@@ -33,11 +35,9 @@ import {extractStringsFromFile} from './src/extractStrings.js'
|
|
|
33
35
|
* @property {string[]} [dataLabelKeys] - Object property names whose string values are labels in mixed data
|
|
34
36
|
* files (e.g. `['label', 'title']` in nav config arrays). No code rewrite;
|
|
35
37
|
* keys are recorded into `wick-ui-i18n.json` for the translation API.
|
|
36
|
-
* @property {string[]} [extractFromKeys] - @deprecated Use `dataLabelKeys` instead.
|
|
37
38
|
* @property {string|string[]|RegExp} [dictionaryFiles] - Files where every string is a display label (enum files,
|
|
38
39
|
* message constants). Pattern: `'**\/enums\/*.ts'`.
|
|
39
40
|
* Do NOT point at mixed data files — use `dataLabelKeys` for those.
|
|
40
|
-
* @property {string|string[]|RegExp} [resolveFiles] - @deprecated Use `dictionaryFiles` instead.
|
|
41
41
|
* @property {string|string[]|RegExp} [excludeFiles] - Files to skip (passed as `exclude` to Vite's createFilter).
|
|
42
42
|
* @property {boolean} [debug] - Log transform activity to the console.
|
|
43
43
|
*/
|
|
@@ -56,17 +56,23 @@ export default function wickuiI18nPlugin(options = {}) {
|
|
|
56
56
|
ignoreComponents: options.ignoreComponents,
|
|
57
57
|
translatableProps: options.translatableProps,
|
|
58
58
|
dataLabelKeys: options.dataLabelKeys,
|
|
59
|
-
extractFromKeys: options.extractFromKeys, // deprecated alias — processor handles both
|
|
60
59
|
debug: options.debug,
|
|
61
60
|
})
|
|
62
61
|
|
|
63
62
|
const filter = createFilter([/\.(jsx|tsx|ts)$/], options.excludeFiles)
|
|
64
|
-
const enumFilter =
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
63
|
+
const enumFilter = options.dictionaryFiles ? createFilter(options.dictionaryFiles) : null
|
|
64
|
+
|
|
65
|
+
// Exact-path entries from dictionaryFiles (no glob chars) are read via fs in buildStart
|
|
66
|
+
// so they work for node_modules files that Vite never processes through transforms.
|
|
67
|
+
const dictionaryPatterns = (() => {
|
|
68
|
+
const raw = options.dictionaryFiles
|
|
69
|
+
if (!raw) return []
|
|
70
|
+
const arr = Array.isArray(raw) ? raw : [raw]
|
|
71
|
+
return arr.filter(p => typeof p === 'string' && !/[*?{}[\]]/.test(p))
|
|
72
|
+
})()
|
|
68
73
|
|
|
69
74
|
let base = '/'
|
|
75
|
+
let root = '/'
|
|
70
76
|
|
|
71
77
|
return {
|
|
72
78
|
name: 'wick-ui-i18n',
|
|
@@ -80,6 +86,7 @@ export default function wickuiI18nPlugin(options = {}) {
|
|
|
80
86
|
*/
|
|
81
87
|
configResolved(resolvedConfig) {
|
|
82
88
|
base = resolvedConfig.base
|
|
89
|
+
root = resolvedConfig.root
|
|
83
90
|
telemetry.scanVersions(resolvedConfig.root)
|
|
84
91
|
},
|
|
85
92
|
|
|
@@ -91,6 +98,16 @@ export default function wickuiI18nPlugin(options = {}) {
|
|
|
91
98
|
processor.dictionary.clear()
|
|
92
99
|
processor.entries = []
|
|
93
100
|
telemetry.reset()
|
|
101
|
+
|
|
102
|
+
for (const rel of dictionaryPatterns) {
|
|
103
|
+
const abs = path.isAbsolute(rel) ? rel : path.resolve(root, rel)
|
|
104
|
+
try {
|
|
105
|
+
const code = fs.readFileSync(abs, 'utf8')
|
|
106
|
+
extractStringsFromFile(code, abs, processor)
|
|
107
|
+
} catch {
|
|
108
|
+
console.warn(`[wick-i18n] dictionaryFiles: could not read "${rel}" — file not found or unreadable`)
|
|
109
|
+
}
|
|
110
|
+
}
|
|
94
111
|
},
|
|
95
112
|
|
|
96
113
|
/**
|
package/package.json
CHANGED
package/src/processor.js
CHANGED
|
@@ -38,7 +38,7 @@ export class TranslationProcessor {
|
|
|
38
38
|
/** @type {Set<string>} JSX prop names that should be translated. */
|
|
39
39
|
this.translatableProps = new Set([...DEFAULT_TRANSLATABLE_PROPS, ...(options.translatableProps || [])])
|
|
40
40
|
/** @type {Set<string>} Object property key names whose string values are extracted (e.g. 'label'). */
|
|
41
|
-
this.extractFromKeys = new Set(options.dataLabelKeys ||
|
|
41
|
+
this.extractFromKeys = new Set(options.dataLabelKeys || [])
|
|
42
42
|
/** @type {Map<string, string>} key → original text */
|
|
43
43
|
this.dictionary = new Map()
|
|
44
44
|
/** @type {import('./debug.js').DebugEntry[]} */
|