@ultimat3/i18n 31.6.1 → 31.8.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.
- package/package.json +2 -2
- package/src/extract.ts +21 -11
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ultimat3/i18n",
|
|
3
|
-
"version": "31.
|
|
3
|
+
"version": "31.8.0",
|
|
4
4
|
"description": "Dependency-free translator, catalog flattening, locale negotiation and loud missing-key rendering",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ultimate",
|
|
@@ -48,6 +48,6 @@
|
|
|
48
48
|
"test": "bun test"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@ultimat3/core": "31.
|
|
51
|
+
"@ultimat3/core": "31.8.0"
|
|
52
52
|
}
|
|
53
53
|
}
|
package/src/extract.ts
CHANGED
|
@@ -83,7 +83,7 @@ export function extractKeys(
|
|
|
83
83
|
const callees = options.callees ?? DEFAULT_CALLEES;
|
|
84
84
|
const pattern = new RegExp(
|
|
85
85
|
// not preceded by an identifier char or `.`, so `ctx.t(` and `format(` don't match
|
|
86
|
-
String.raw`(?<![\w$.])(?:${callees.map(escapeRegExp).join('|')})(?:\.has)?\s*\(
|
|
86
|
+
String.raw`(?<![\w$.])(?:${callees.map(escapeRegExp).join('|')})(?:\.has)?\s*\(`,
|
|
87
87
|
'g',
|
|
88
88
|
);
|
|
89
89
|
|
|
@@ -102,17 +102,24 @@ export function extractKeys(
|
|
|
102
102
|
usages.push({ key, file, ...position });
|
|
103
103
|
};
|
|
104
104
|
|
|
105
|
-
//
|
|
106
|
-
//
|
|
107
|
-
//
|
|
108
|
-
//
|
|
105
|
+
// Calls are found in `stripped` and KEPT only where `code` — string bodies blanked too — left the
|
|
106
|
+
// call's own index as code; the argument is read off `stripped`.
|
|
107
|
+
// A `// … t('…')` comment produced a phantom key `x i18n sync` would have written into every
|
|
108
|
+
// catalog as `"…": "⟦…⟧"` (measured 2026-09-05), and `"use t('x.y') here"` in a fix line or a
|
|
109
|
+
// docs string did the same. Both masks keep length and every newline, so an index into either is
|
|
110
|
+
// an index into `source`; a template's `${…}` stays code, so a key written there is still found.
|
|
109
111
|
const stripped = stripComments(source);
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
+
const code = blankStrings(stripped);
|
|
113
|
+
const argument = /\s*([^,)]*)/y;
|
|
114
|
+
for (const match of stripped.matchAll(pattern)) {
|
|
115
|
+
const index = match.index ?? 0;
|
|
116
|
+
if (code[index] !== stripped[index]) continue;
|
|
117
|
+
argument.lastIndex = index + match[0].length;
|
|
118
|
+
record(argument.exec(stripped)?.[1], index);
|
|
119
|
+
}
|
|
112
120
|
|
|
113
|
-
// Properties are read in CODE only:
|
|
114
|
-
|
|
115
|
-
const code = properties.length === 0 ? stripped : blankStrings(stripped);
|
|
121
|
+
// Properties are read in CODE only too: a docs example quoting `{ titleKey: 'x' }` is text.
|
|
122
|
+
const properties = options.properties ?? [];
|
|
116
123
|
for (const property of properties) {
|
|
117
124
|
const marker = property.whenFileContains;
|
|
118
125
|
if (marker !== undefined && !code.includes(marker)) continue;
|
|
@@ -263,6 +270,7 @@ function isIgnored(key: string, patterns: readonly string[]): boolean {
|
|
|
263
270
|
}
|
|
264
271
|
|
|
265
272
|
const BLANK = '\u0000';
|
|
273
|
+
const WORD_CHAR = /[\w$]/;
|
|
266
274
|
|
|
267
275
|
/**
|
|
268
276
|
* `text` with every string literal's contents replaced by `BLANK`, same length, so an index into it is
|
|
@@ -296,7 +304,9 @@ function blankStrings(text: string): string {
|
|
|
296
304
|
}
|
|
297
305
|
continue;
|
|
298
306
|
}
|
|
299
|
-
|
|
307
|
+
// A quote right after an identifier char opens nothing — `foo'x'` is no JS — so it is JSX
|
|
308
|
+
// text's apostrophe: `<p>Don't {t('a')}</p>` read as an opener blanked the call after it.
|
|
309
|
+
if ((char === "'" || char === '"') && !WORD_CHAR.test(text[i - 1] ?? '')) quote = char;
|
|
300
310
|
else if (char === '`') templates.push(-1);
|
|
301
311
|
else if (top >= 0 && char === '{') templates[top] = (templates[top] ?? 0) + 1;
|
|
302
312
|
else if (top >= 0 && char === '}') {
|