@rig-c/review 0.24.1 → 0.25.1
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 +1 -1
- package/docs/DESIGN.md +1 -1
- package/docs/PANELS.md +20 -5
- package/docs/REVIEW_PACKAGE.md +3 -3
- package/docs/WORKFLOWS.md +1 -1
- package/package.json +1 -1
- package/skills/rig-review/SKILL.md +1 -1
- package/web/animation-inspection.ts +2 -1
- package/web/catalog-en.ts +2956 -0
- package/web/catalog-ko.ts +2956 -0
- package/web/compare-picked-tools.ts +4 -3
- package/web/compare.css +6 -0
- package/web/compare.html +1 -1
- package/web/compare.ts +2 -2
- package/web/i18n.ts +1154 -0
- package/web/index.html +1 -1
- package/web/main.ts +6 -5
- package/web/stage-comments.ts +95 -41
- package/web/styles.css +7 -6
- package/web/workspace-preferences.ts +15 -13
- package/web/workspace-ui.ts +8 -7
package/web/i18n.ts
ADDED
|
@@ -0,0 +1,1154 @@
|
|
|
1
|
+
import { enCatalog } from './catalog-en.ts';
|
|
2
|
+
import { koCatalog } from './catalog-ko.ts';
|
|
3
|
+
import type { WorkspaceLanguage } from './workspace-preferences.ts';
|
|
4
|
+
|
|
5
|
+
export type ResolvedLanguage = 'en' | 'ko';
|
|
6
|
+
|
|
7
|
+
export interface NavigatorLanguageLike {
|
|
8
|
+
readonly languages?: readonly string[];
|
|
9
|
+
readonly language?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface WebStringExemption {
|
|
13
|
+
readonly file: string;
|
|
14
|
+
readonly match: string;
|
|
15
|
+
readonly reason: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface HardcodedStringViolation {
|
|
19
|
+
readonly file: string;
|
|
20
|
+
readonly line: number;
|
|
21
|
+
readonly kind: 'html-text' | 'html-attr' | 'ts-string';
|
|
22
|
+
readonly text: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const WEB_STRING_EXEMPTIONS: readonly WebStringExemption[] = [
|
|
26
|
+
{
|
|
27
|
+
file: 'web/index.html',
|
|
28
|
+
match: 'boob_r',
|
|
29
|
+
reason: 'Canonical rig bone identifier example on chest region right bone input.'
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
file: 'web/index.html',
|
|
33
|
+
match: 'boob_l',
|
|
34
|
+
reason: 'Canonical rig bone identifier example on chest region left bone input.'
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
file: 'web/index.html',
|
|
38
|
+
match: '● R',
|
|
39
|
+
reason: 'Right chest region compact coordinate symbol badge.'
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
file: 'web/index.html',
|
|
43
|
+
match: '● L',
|
|
44
|
+
reason: 'Left chest region compact coordinate symbol badge.'
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
file: 'web/compare.ts',
|
|
48
|
+
match: 'Frames: {0}–{1} (inclusive; explicit producer frame numbers)',
|
|
49
|
+
reason: 'Exported Markdown issue body stays English and byte-identical across languages (Bar 6).'
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
file: 'web/compare.ts',
|
|
53
|
+
match: 'Inspection context:',
|
|
54
|
+
reason: 'Exported Markdown issue body heading stays English and byte-identical across languages (Bar 6).'
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
file: 'web/compare.ts',
|
|
58
|
+
match: 'Ordered A/B and reference provenance:',
|
|
59
|
+
reason: 'Exported Markdown issue body heading stays English and byte-identical across languages (Bar 6).'
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
file: 'web/compare.ts',
|
|
63
|
+
match: 'Ordered compare provenance:',
|
|
64
|
+
reason: 'Exported Markdown issue body heading stays English and byte-identical across languages (Bar 6).'
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
file: 'web/compare.ts',
|
|
68
|
+
match: 'Side: {0}',
|
|
69
|
+
reason: 'Exported Markdown issue body field stays English and byte-identical across languages (Bar 6).'
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
file: 'web/compare.ts',
|
|
73
|
+
match: 'Target: {0} / {1}',
|
|
74
|
+
reason: 'Exported Markdown issue body field stays English and byte-identical across languages (Bar 6).'
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
file: 'web/compare.ts',
|
|
78
|
+
match: 'Validation warnings (must be corrected before submission):',
|
|
79
|
+
reason: 'Exported Markdown issue body heading stays English and byte-identical across languages (Bar 6).'
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
file: 'web/compare.ts',
|
|
83
|
+
match: 'Validation warnings:',
|
|
84
|
+
reason: 'Exported Markdown issue body heading stays English and byte-identical across languages (Bar 6).'
|
|
85
|
+
}
|
|
86
|
+
];
|
|
87
|
+
|
|
88
|
+
export function resolveLanguage(
|
|
89
|
+
preference: WorkspaceLanguage = 'system',
|
|
90
|
+
nav?: NavigatorLanguageLike | null
|
|
91
|
+
): ResolvedLanguage {
|
|
92
|
+
if (preference === 'en' || preference === 'ko') return preference;
|
|
93
|
+
const source = nav === undefined ? (typeof navigator !== 'undefined' ? navigator : null) : nav;
|
|
94
|
+
if (!source) return 'en';
|
|
95
|
+
let tag = '';
|
|
96
|
+
if (Array.isArray(source.languages)) {
|
|
97
|
+
for (const entry of source.languages) {
|
|
98
|
+
if (typeof entry === 'string' && entry.trim()) {
|
|
99
|
+
tag = entry.trim().toLowerCase();
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (!tag && typeof source.language === 'string') {
|
|
105
|
+
tag = source.language.trim().toLowerCase();
|
|
106
|
+
}
|
|
107
|
+
return tag === 'ko' || tag.startsWith('ko-') || tag.startsWith('ko_') ? 'ko' : 'en';
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
let currentPreference: WorkspaceLanguage = 'system';
|
|
111
|
+
let currentLanguage: ResolvedLanguage = resolveLanguage('system');
|
|
112
|
+
const listeners = new Set<(lang: ResolvedLanguage) => void>();
|
|
113
|
+
|
|
114
|
+
export function getLanguage(): ResolvedLanguage {
|
|
115
|
+
return currentLanguage;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export function getLanguagePreference(): WorkspaceLanguage {
|
|
119
|
+
return currentPreference;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export function syncDocumentLanguage(doc?: Document | null): void {
|
|
123
|
+
const target = doc === undefined ? (typeof document !== 'undefined' ? document : null) : doc;
|
|
124
|
+
if (target?.documentElement) {
|
|
125
|
+
target.documentElement.lang = currentLanguage;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export function setLanguagePreference(
|
|
130
|
+
preference: WorkspaceLanguage,
|
|
131
|
+
nav?: NavigatorLanguageLike | null
|
|
132
|
+
): ResolvedLanguage {
|
|
133
|
+
currentPreference = preference;
|
|
134
|
+
const resolved = resolveLanguage(preference, nav);
|
|
135
|
+
currentLanguage = resolved;
|
|
136
|
+
syncDocumentLanguage();
|
|
137
|
+
if (boundRoot) {
|
|
138
|
+
applyDomI18n(boundRoot);
|
|
139
|
+
}
|
|
140
|
+
for (const listener of listeners) {
|
|
141
|
+
listener(resolved);
|
|
142
|
+
}
|
|
143
|
+
return resolved;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export function onLanguageChange(listener: (lang: ResolvedLanguage) => void): () => void {
|
|
147
|
+
listeners.add(listener);
|
|
148
|
+
return () => {
|
|
149
|
+
listeners.delete(listener);
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
let enToKoMap: Map<string, string> | null = null;
|
|
154
|
+
let koToEnMap: Map<string, string> | null = null;
|
|
155
|
+
|
|
156
|
+
function ensureMaps(): { enToKo: Map<string, string>; koToEn: Map<string, string> } {
|
|
157
|
+
if (enToKoMap && koToEnMap) return { enToKo: enToKoMap, koToEn: koToEnMap };
|
|
158
|
+
enToKoMap = new Map<string, string>();
|
|
159
|
+
koToEnMap = new Map<string, string>();
|
|
160
|
+
for (const [en, ko] of Object.entries(koCatalog)) {
|
|
161
|
+
enToKoMap.set(en, ko);
|
|
162
|
+
if (!koToEnMap.has(ko) || en === ko) {
|
|
163
|
+
koToEnMap.set(ko, en);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
for (const [en, ko] of Object.entries(koCatalog)) {
|
|
167
|
+
if (en.startsWith(' · ') && ko.startsWith(' · ')) {
|
|
168
|
+
const enSub = en.slice(3);
|
|
169
|
+
const koSub = ko.slice(3);
|
|
170
|
+
if (!enToKoMap.has(enSub)) enToKoMap.set(enSub, koSub);
|
|
171
|
+
if (!koToEnMap.has(koSub)) koToEnMap.set(koSub, enSub);
|
|
172
|
+
}
|
|
173
|
+
const enCode = /^([A-Z][A-Z0-9_]{2,}):\s+([\s\S]+)$/.exec(en);
|
|
174
|
+
const koCode = /^([A-Z][A-Z0-9_]{2,}):\s+([\s\S]+)$/.exec(ko);
|
|
175
|
+
if (enCode && koCode && enCode[1] === koCode[1]) {
|
|
176
|
+
const enDetail = enCode[2]!;
|
|
177
|
+
const koDetail = koCode[2]!;
|
|
178
|
+
if (!enToKoMap.has(enDetail)) enToKoMap.set(enDetail, koDetail);
|
|
179
|
+
if (!koToEnMap.has(koDetail)) koToEnMap.set(koDetail, enDetail);
|
|
180
|
+
}
|
|
181
|
+
const enTrim = en.trim();
|
|
182
|
+
const koTrim = ko.trim();
|
|
183
|
+
if (enTrim && koTrim && (enTrim !== en || koTrim !== ko) && !/^[a-z0-9_.-]+$/.test(enTrim)) {
|
|
184
|
+
if (!enToKoMap.has(enTrim)) enToKoMap.set(enTrim, koTrim);
|
|
185
|
+
if (!koToEnMap.has(koTrim)) koToEnMap.set(koTrim, enTrim);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return { enToKo: enToKoMap, koToEn: koToEnMap };
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function getEnToKoMap(): Map<string, string> {
|
|
192
|
+
return ensureMaps().enToKo;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function getKoToEnMap(): Map<string, string> {
|
|
196
|
+
return ensureMaps().koToEn;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
interface CompiledPattern {
|
|
200
|
+
readonly regex: RegExp;
|
|
201
|
+
readonly paramOrder: readonly number[];
|
|
202
|
+
readonly targetTemplate: string;
|
|
203
|
+
readonly literalLength: number;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
let enToKoPatterns: readonly CompiledPattern[] | null = null;
|
|
207
|
+
let koToEnPatterns: readonly CompiledPattern[] | null = null;
|
|
208
|
+
|
|
209
|
+
function buildPatterns(fromCatalog: Readonly<Record<string, string>>, toCatalog: Readonly<Record<string, string>>): readonly CompiledPattern[] {
|
|
210
|
+
const list: CompiledPattern[] = [];
|
|
211
|
+
const tokenRe = /\{(\d+)\}/g;
|
|
212
|
+
for (const key of Object.keys(fromCatalog)) {
|
|
213
|
+
const srcPattern = fromCatalog[key];
|
|
214
|
+
const dstPattern = toCatalog[key];
|
|
215
|
+
if (!srcPattern || !dstPattern || srcPattern === dstPattern) continue;
|
|
216
|
+
if (!srcPattern.includes('{0}')) continue;
|
|
217
|
+
const literalOnly = srcPattern.replace(tokenRe, '').trim();
|
|
218
|
+
// Skip bare structural patterns that have no alphabetic or Korean words of their own
|
|
219
|
+
if (!/[A-Za-z가-힣]{2,}/.test(literalOnly)) continue;
|
|
220
|
+
const paramOrder: number[] = [];
|
|
221
|
+
const isShortOpenEnded =
|
|
222
|
+
/^\{\d+\}/.test(srcPattern) &&
|
|
223
|
+
/\{\d+\}$/.test(srcPattern) &&
|
|
224
|
+
literalOnly.length < 10 &&
|
|
225
|
+
!literalOnly.includes('·') &&
|
|
226
|
+
!literalOnly.includes(':');
|
|
227
|
+
let regexBody = '^';
|
|
228
|
+
let lastIndex = 0;
|
|
229
|
+
let match: RegExpExecArray | null;
|
|
230
|
+
tokenRe.lastIndex = 0;
|
|
231
|
+
while ((match = tokenRe.exec(srcPattern)) !== null) {
|
|
232
|
+
const literalChunk = srcPattern.slice(lastIndex, match.index);
|
|
233
|
+
regexBody += literalChunk.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
234
|
+
paramOrder.push(Number(match[1]));
|
|
235
|
+
lastIndex = match.index + match[0].length;
|
|
236
|
+
const isAtEnd = lastIndex === srcPattern.length;
|
|
237
|
+
const nextIsToken = srcPattern.slice(lastIndex).startsWith('{');
|
|
238
|
+
regexBody += isShortOpenEnded
|
|
239
|
+
? '([^\\s]+)'
|
|
240
|
+
: isAtEnd
|
|
241
|
+
? '([\\s\\S]*)'
|
|
242
|
+
: nextIsToken
|
|
243
|
+
? '([\\s\\S]*?)'
|
|
244
|
+
: '([\\s\\S]+?)';
|
|
245
|
+
}
|
|
246
|
+
regexBody += srcPattern.slice(lastIndex).replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + '$';
|
|
247
|
+
try {
|
|
248
|
+
list.push({
|
|
249
|
+
regex: new RegExp(regexBody),
|
|
250
|
+
paramOrder,
|
|
251
|
+
targetTemplate: dstPattern,
|
|
252
|
+
literalLength: literalOnly.length
|
|
253
|
+
});
|
|
254
|
+
} catch {
|
|
255
|
+
// Ignore malformed pattern
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
list.sort((a, b) => b.literalLength - a.literalLength);
|
|
259
|
+
return list;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function getPatterns(lang: ResolvedLanguage): readonly CompiledPattern[] {
|
|
263
|
+
const { enToKo } = ensureMaps();
|
|
264
|
+
const expandedEn: Record<string, string> = {};
|
|
265
|
+
const expandedKo: Record<string, string> = {};
|
|
266
|
+
for (const [en, ko] of enToKo.entries()) {
|
|
267
|
+
expandedEn[en] = en;
|
|
268
|
+
expandedKo[en] = ko;
|
|
269
|
+
}
|
|
270
|
+
if (lang === 'ko') {
|
|
271
|
+
if (!enToKoPatterns) enToKoPatterns = buildPatterns(expandedEn, expandedKo);
|
|
272
|
+
return enToKoPatterns;
|
|
273
|
+
}
|
|
274
|
+
if (!koToEnPatterns) koToEnPatterns = buildPatterns(expandedKo, expandedEn);
|
|
275
|
+
return koToEnPatterns;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
export function t(
|
|
279
|
+
key: string,
|
|
280
|
+
params?: Readonly<Record<string, string | number>> | readonly (string | number)[],
|
|
281
|
+
lang: ResolvedLanguage = currentLanguage
|
|
282
|
+
): string {
|
|
283
|
+
const catalog = lang === 'ko' ? koCatalog : enCatalog;
|
|
284
|
+
if (!params) {
|
|
285
|
+
const direct = catalog[key];
|
|
286
|
+
if (direct !== undefined) return direct;
|
|
287
|
+
return tr(key, lang);
|
|
288
|
+
}
|
|
289
|
+
const template = catalog[key] ?? enCatalog[key] ?? key;
|
|
290
|
+
return template.replace(/\{(\w+)\}/g, (full, token: string) => {
|
|
291
|
+
if (Array.isArray(params)) {
|
|
292
|
+
const idx = Number(token);
|
|
293
|
+
return Number.isInteger(idx) && idx >= 0 && idx < params.length ? String(params[idx]) : full;
|
|
294
|
+
}
|
|
295
|
+
const rec = params as Readonly<Record<string, string | number>>;
|
|
296
|
+
return Object.prototype.hasOwnProperty.call(rec, token) ? String(rec[token]) : full;
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
const KNOWN_SHORT_PROSE = new Set([
|
|
301
|
+
'applied',
|
|
302
|
+
'pending',
|
|
303
|
+
'reused',
|
|
304
|
+
'keyed',
|
|
305
|
+
'off',
|
|
306
|
+
'active',
|
|
307
|
+
'pass',
|
|
308
|
+
'error',
|
|
309
|
+
'none',
|
|
310
|
+
'not read',
|
|
311
|
+
'not drawn',
|
|
312
|
+
'not loaded',
|
|
313
|
+
'not set',
|
|
314
|
+
'no diff',
|
|
315
|
+
'no bone',
|
|
316
|
+
'no blink',
|
|
317
|
+
'no turn',
|
|
318
|
+
'no ribs',
|
|
319
|
+
'no range',
|
|
320
|
+
'no counts',
|
|
321
|
+
'no chain',
|
|
322
|
+
'no base'
|
|
323
|
+
]);
|
|
324
|
+
|
|
325
|
+
function shouldTranslateCapturedArg(arg: string, lang: ResolvedLanguage): boolean {
|
|
326
|
+
const trimmed = arg.trim();
|
|
327
|
+
if (!trimmed) return false;
|
|
328
|
+
if (/^-?\d+(\.\d+)?(\s*(s|ms|px|°|×))?$/.test(trimmed)) return false;
|
|
329
|
+
if (/^[0-9a-f]{7,64}…?$/i.test(trimmed)) return false;
|
|
330
|
+
if (lang === 'ko') {
|
|
331
|
+
// Bare single-token lowercase identifier (like a bone/slot/animation name) stays untouched unless in KNOWN_SHORT_PROSE
|
|
332
|
+
if (/^[a-z0-9_.-]+$/.test(trimmed) && !KNOWN_SHORT_PROSE.has(trimmed)) return false;
|
|
333
|
+
if (koCatalog[trimmed] !== undefined && koCatalog[trimmed] !== trimmed) return true;
|
|
334
|
+
if (koCatalog[arg] !== undefined && koCatalog[arg] !== arg) return true;
|
|
335
|
+
if (/^[a-z0-9_.-]+$/i.test(trimmed) && !KNOWN_SHORT_PROSE.has(trimmed)) return false;
|
|
336
|
+
return /[A-Za-z]{2,}/.test(trimmed) && (trimmed.includes(' ') || trimmed.includes('·') || trimmed.includes('('));
|
|
337
|
+
}
|
|
338
|
+
const koToEn = getKoToEnMap();
|
|
339
|
+
if (koToEn.has(trimmed) || koToEn.has(arg)) return true;
|
|
340
|
+
return /[가-힣]/.test(trimmed);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
function translateCore(text: string, lang: ResolvedLanguage, depth: number): string {
|
|
344
|
+
if (!text || depth > 4) return text;
|
|
345
|
+
if (lang === 'ko') {
|
|
346
|
+
const exact = getEnToKoMap().get(text);
|
|
347
|
+
if (exact !== undefined) return exact;
|
|
348
|
+
} else {
|
|
349
|
+
if (getEnToKoMap().has(text)) return text;
|
|
350
|
+
const rev = getKoToEnMap().get(text);
|
|
351
|
+
if (rev !== undefined) return rev;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
// Preserve leading/trailing whitespace if the trimmed version matches
|
|
355
|
+
const leadMatch = /^(\s+)([\s\S]*?)(\s*)$/.exec(text) || /^(\s*)([\s\S]*?)(\s+)$/.exec(text);
|
|
356
|
+
if (leadMatch && (leadMatch[1] || leadMatch[3])) {
|
|
357
|
+
const inner = leadMatch[2];
|
|
358
|
+
if (inner) {
|
|
359
|
+
const innerTranslated = translateCore(inner, lang, depth + 1);
|
|
360
|
+
if (innerTranslated !== inner) {
|
|
361
|
+
return `${leadMatch[1]}${innerTranslated}${leadMatch[3]}`;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
// Preserve ERROR_CODE: <detail> prefix before wildcard pattern matching
|
|
367
|
+
const codeMatch = /^([A-Z][A-Z0-9_]{2,}):\s+([\s\S]+)$/.exec(text);
|
|
368
|
+
if (codeMatch) {
|
|
369
|
+
const code = codeMatch[1]!;
|
|
370
|
+
const detail = codeMatch[2]!;
|
|
371
|
+
const translatedDetail = translateCore(detail, lang, depth + 1);
|
|
372
|
+
if (translatedDetail !== detail) {
|
|
373
|
+
return `${code}: ${translatedDetail}`;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
// Try parameterized patterns
|
|
378
|
+
const patterns = getPatterns(lang);
|
|
379
|
+
for (const pat of patterns) {
|
|
380
|
+
const m = pat.regex.exec(text);
|
|
381
|
+
if (!m) continue;
|
|
382
|
+
const values = new Map<number, string>();
|
|
383
|
+
for (let i = 0; i < pat.paramOrder.length; i++) {
|
|
384
|
+
const idx = pat.paramOrder[i]!;
|
|
385
|
+
const rawArg = m[i + 1] ?? '';
|
|
386
|
+
const translatedArg = shouldTranslateCapturedArg(rawArg, lang)
|
|
387
|
+
? translateCore(rawArg, lang, depth + 1)
|
|
388
|
+
: rawArg;
|
|
389
|
+
values.set(idx, translatedArg);
|
|
390
|
+
}
|
|
391
|
+
return pat.targetTemplate.replace(/\{(\d+)\}/g, (full, d: string) => {
|
|
392
|
+
const idx = Number(d);
|
|
393
|
+
return values.has(idx) ? values.get(idx)! : full;
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
// Compound delimiters: '\n', ' · ', '; '
|
|
398
|
+
for (const sep of ['\n', ' · ', '; ']) {
|
|
399
|
+
if (text.includes(sep)) {
|
|
400
|
+
const parts = text.split(sep);
|
|
401
|
+
let changed = false;
|
|
402
|
+
const sidePrefix =
|
|
403
|
+
sep === ' · ' && /^(?:[◈◇]\s+)?[AB]$/.test(parts[0]?.trim() ?? '');
|
|
404
|
+
const slotIdx = sep === ' · ' ? (sidePrefix ? 1 : 0) : -1;
|
|
405
|
+
const mapped = parts.map((part, idx) => {
|
|
406
|
+
if (idx === slotIdx && /^[a-z0-9_.-]+$/.test(part.trim()) && !KNOWN_SHORT_PROSE.has(part.trim())) {
|
|
407
|
+
return part;
|
|
408
|
+
}
|
|
409
|
+
if (sep === ' · ' && idx > slotIdx) {
|
|
410
|
+
if (lang === 'ko' && part === 'drawn') {
|
|
411
|
+
changed = true;
|
|
412
|
+
return '그려짐';
|
|
413
|
+
}
|
|
414
|
+
if (lang === 'en' && part === '그려짐') {
|
|
415
|
+
changed = true;
|
|
416
|
+
return 'drawn';
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
const next = translateCore(part, lang, depth + 1);
|
|
420
|
+
if (next !== part) changed = true;
|
|
421
|
+
return next;
|
|
422
|
+
});
|
|
423
|
+
if (changed) return mapped.join(sep);
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
return text;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
export function tr(raw: string, lang: ResolvedLanguage = currentLanguage): string {
|
|
431
|
+
if (!raw) return raw;
|
|
432
|
+
return translateCore(raw, lang, 0);
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
// DOM binding state
|
|
436
|
+
let boundRoot: Document | Element | null = null;
|
|
437
|
+
let domObserver: MutationObserver | null = null;
|
|
438
|
+
let isApplyingDom = false;
|
|
439
|
+
|
|
440
|
+
const textNodeSource = new WeakMap<Node, { en: string; lastApplied: string }>();
|
|
441
|
+
const elementHintSource = new WeakMap<Element, { enHtml: string; lastAppliedHtml: string }>();
|
|
442
|
+
const elementAttrSource = new WeakMap<Element, Map<string, { en: string; lastApplied: string }>>();
|
|
443
|
+
|
|
444
|
+
const TRANSLATED_ATTRS = ['aria-label', 'title', 'placeholder', 'aria-valuetext'] as const;
|
|
445
|
+
|
|
446
|
+
function normalizeHtmlKey(html: string): string {
|
|
447
|
+
return html.replace(/\s+/g, ' ').trim();
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
const CONTEXT_LOWER_KEYS = new Set(['bone', 'box', 'from', 'root', 'silhouette', 'slot', 'tip', 'to', 'vs']);
|
|
451
|
+
|
|
452
|
+
function isExemptElement(el: Element | null): boolean {
|
|
453
|
+
let cur: Element | null = el;
|
|
454
|
+
while (cur) {
|
|
455
|
+
const id = cur.id;
|
|
456
|
+
if (
|
|
457
|
+
id === 'target-names' ||
|
|
458
|
+
id === 'feedback-target-names' ||
|
|
459
|
+
id === 'lm-bones' ||
|
|
460
|
+
id === 'applied-diff' ||
|
|
461
|
+
id === 'trace'
|
|
462
|
+
) {
|
|
463
|
+
return true;
|
|
464
|
+
}
|
|
465
|
+
const cls = typeof cur.className === 'string' ? cur.className : '';
|
|
466
|
+
if (
|
|
467
|
+
cls.includes('feedback-summary') ||
|
|
468
|
+
cls.includes('feedback-heading') ||
|
|
469
|
+
cls.includes('feedback-json') ||
|
|
470
|
+
cls.includes('stage-comment-summary') ||
|
|
471
|
+
cls.includes('part-slot-name') ||
|
|
472
|
+
cls.includes('animation-lane-label') ||
|
|
473
|
+
cls.includes('animation-tree-bone-name') ||
|
|
474
|
+
cls.includes('stage-comment-pin')
|
|
475
|
+
) {
|
|
476
|
+
return true;
|
|
477
|
+
}
|
|
478
|
+
const tag = cur.tagName?.toUpperCase();
|
|
479
|
+
const parentCls = typeof cur.parentElement?.className === 'string' ? cur.parentElement.className : '';
|
|
480
|
+
if (tag === 'BUTTON' && parentCls.includes('stage-comment-item')) {
|
|
481
|
+
return true;
|
|
482
|
+
}
|
|
483
|
+
if (tag === 'SCRIPT' || tag === 'STYLE' || tag === 'KBD') {
|
|
484
|
+
return true;
|
|
485
|
+
}
|
|
486
|
+
if (tag === 'CODE') {
|
|
487
|
+
const parentHint = cur.closest('p.hint');
|
|
488
|
+
if (!parentHint) return true;
|
|
489
|
+
}
|
|
490
|
+
if (tag === 'OPTION') {
|
|
491
|
+
const parentSelect = cur.parentElement;
|
|
492
|
+
const selectId = parentSelect?.id;
|
|
493
|
+
if (
|
|
494
|
+
(selectId === 'animation' ||
|
|
495
|
+
selectId === 'animation-select' ||
|
|
496
|
+
selectId === 'bones-select' ||
|
|
497
|
+
selectId === 'weights-bone' ||
|
|
498
|
+
selectId === 'mesh-segment-bone' ||
|
|
499
|
+
selectId === 'chest-0-bone' ||
|
|
500
|
+
selectId === 'chest-1-bone' ||
|
|
501
|
+
selectId === 'person-select') &&
|
|
502
|
+
(cur as HTMLOptionElement).value !== ''
|
|
503
|
+
) {
|
|
504
|
+
return true;
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
cur = cur.parentElement;
|
|
508
|
+
}
|
|
509
|
+
return false;
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
function applyElementI18n(el: Element, lang: ResolvedLanguage): void {
|
|
513
|
+
if (!el || typeof el.getAttribute !== 'function' || isExemptElement(el)) return;
|
|
514
|
+
|
|
515
|
+
// Check attributes
|
|
516
|
+
let attrMap = elementAttrSource.get(el);
|
|
517
|
+
for (const attr of TRANSLATED_ATTRS) {
|
|
518
|
+
const val = el.getAttribute(attr);
|
|
519
|
+
if (val === null || !val.trim()) continue;
|
|
520
|
+
if (!attrMap) {
|
|
521
|
+
attrMap = new Map();
|
|
522
|
+
elementAttrSource.set(el, attrMap);
|
|
523
|
+
}
|
|
524
|
+
const existing = attrMap.get(attr);
|
|
525
|
+
let enVal: string;
|
|
526
|
+
if (!existing || (val !== existing.lastApplied && val !== existing.en)) {
|
|
527
|
+
enVal = getKoToEnMap().get(val) ?? tr(val, 'en');
|
|
528
|
+
} else {
|
|
529
|
+
enVal = existing.en;
|
|
530
|
+
}
|
|
531
|
+
const nextVal = lang === 'ko' ? tr(enVal, 'ko') : enVal;
|
|
532
|
+
attrMap.set(attr, { en: enVal, lastApplied: nextVal });
|
|
533
|
+
if (val !== nextVal) {
|
|
534
|
+
el.setAttribute(attr, nextVal);
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
// Check rich <p class="hint"> with inline markup
|
|
539
|
+
if (el.tagName?.toUpperCase() === 'P' && el.classList?.contains('hint') && el.children.length > 0) {
|
|
540
|
+
const currentHtml = normalizeHtmlKey(el.innerHTML);
|
|
541
|
+
const existingHint = elementHintSource.get(el);
|
|
542
|
+
let enHtml: string | undefined;
|
|
543
|
+
if (existingHint && (currentHtml === existingHint.lastAppliedHtml || currentHtml === existingHint.enHtml)) {
|
|
544
|
+
enHtml = existingHint.enHtml;
|
|
545
|
+
} else if (koCatalog[currentHtml] !== undefined) {
|
|
546
|
+
enHtml = currentHtml;
|
|
547
|
+
} else {
|
|
548
|
+
const rev = getKoToEnMap().get(currentHtml);
|
|
549
|
+
if (rev !== undefined) enHtml = rev;
|
|
550
|
+
}
|
|
551
|
+
if (enHtml !== undefined) {
|
|
552
|
+
const nextHtml = lang === 'ko' ? (koCatalog[enHtml] ?? enHtml) : enHtml;
|
|
553
|
+
const normalizedNext = normalizeHtmlKey(nextHtml);
|
|
554
|
+
elementHintSource.set(el, { enHtml, lastAppliedHtml: normalizedNext });
|
|
555
|
+
if (currentHtml !== normalizedNext) {
|
|
556
|
+
el.innerHTML = nextHtml;
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
function applyTextNodeI18n(node: Node, lang: ResolvedLanguage): void {
|
|
563
|
+
const parent = node.parentElement;
|
|
564
|
+
if (!parent || isExemptElement(parent)) return;
|
|
565
|
+
const parentTagUpper = parent.tagName?.toUpperCase();
|
|
566
|
+
if (parentTagUpper === 'PRE' || parentTagUpper === 'TEXTAREA' || parent.closest?.('pre, textarea')) {
|
|
567
|
+
return;
|
|
568
|
+
}
|
|
569
|
+
if (parentTagUpper === 'P' && parent.classList?.contains('hint') && elementHintSource.has(parent)) {
|
|
570
|
+
return;
|
|
571
|
+
}
|
|
572
|
+
const raw = node.nodeValue;
|
|
573
|
+
if (!raw || !raw.trim()) return;
|
|
574
|
+
|
|
575
|
+
const existing = textNodeSource.get(node);
|
|
576
|
+
let enText: string;
|
|
577
|
+
if (!existing || (raw !== existing.lastApplied && raw !== existing.en)) {
|
|
578
|
+
const trimmed = raw.trim();
|
|
579
|
+
const revTrimmed = getKoToEnMap().get(trimmed);
|
|
580
|
+
if (revTrimmed !== undefined) {
|
|
581
|
+
const lead = /^(\s*)/.exec(raw)?.[1] ?? '';
|
|
582
|
+
const trail = /(\s*)$/.exec(raw)?.[1] ?? '';
|
|
583
|
+
enText = `${lead}${revTrimmed}${trail}`;
|
|
584
|
+
} else {
|
|
585
|
+
enText = tr(raw, 'en');
|
|
586
|
+
}
|
|
587
|
+
} else {
|
|
588
|
+
enText = existing.en;
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
const enTrimmed = enText.trim();
|
|
592
|
+
if (CONTEXT_LOWER_KEYS.has(enTrimmed) || (/^[a-z0-9_.-]+$/.test(enTrimmed) && enTrimmed !== 'none')) {
|
|
593
|
+
const parentTag = parent.tagName?.toUpperCase();
|
|
594
|
+
const allow =
|
|
595
|
+
parentTag === 'LABEL' ||
|
|
596
|
+
(parentTag === 'SPAN' && enTrimmed === 'vs') ||
|
|
597
|
+
(parentTag === 'OPTION' && (enTrimmed === 'silhouette' || enTrimmed === 'box'));
|
|
598
|
+
if (!allow) return;
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
const nextText = lang === 'ko' ? tr(enText, 'ko') : enText;
|
|
602
|
+
textNodeSource.set(node, { en: enText, lastApplied: nextText });
|
|
603
|
+
if (raw !== nextText) {
|
|
604
|
+
node.nodeValue = nextText;
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
export function sourceTextContent(node: Node | null | undefined): string {
|
|
609
|
+
if (!node) return '';
|
|
610
|
+
if (node.nodeType === 3) {
|
|
611
|
+
const entry = textNodeSource.get(node);
|
|
612
|
+
const raw = node.nodeValue ?? '';
|
|
613
|
+
if (entry && (raw === entry.lastApplied || raw === entry.en)) return entry.en;
|
|
614
|
+
return tr(raw, 'en');
|
|
615
|
+
}
|
|
616
|
+
const children = node.childNodes;
|
|
617
|
+
if (children && children.length === 1 && children[0]?.nodeType === 3) {
|
|
618
|
+
return sourceTextContent(children[0]);
|
|
619
|
+
}
|
|
620
|
+
const raw = node.textContent ?? '';
|
|
621
|
+
return raw ? tr(raw, 'en') : '';
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
export function applyDomI18n(root: Document | Element = boundRoot ?? document): void {
|
|
625
|
+
if (!root || isApplyingDom) return;
|
|
626
|
+
isApplyingDom = true;
|
|
627
|
+
try {
|
|
628
|
+
const lang = currentLanguage;
|
|
629
|
+
if ('documentElement' in root && root.documentElement) {
|
|
630
|
+
root.documentElement.lang = lang;
|
|
631
|
+
}
|
|
632
|
+
const rootEl: Element | null =
|
|
633
|
+
'documentElement' in root && root.documentElement
|
|
634
|
+
? root.documentElement
|
|
635
|
+
: 'body' in root && (root as Document).body
|
|
636
|
+
? (root as Document).body
|
|
637
|
+
: 'getAttribute' in root
|
|
638
|
+
? (root as Element)
|
|
639
|
+
: null;
|
|
640
|
+
if (!rootEl) return;
|
|
641
|
+
|
|
642
|
+
applyElementI18n(rootEl, lang);
|
|
643
|
+
const elements = typeof rootEl.querySelectorAll === 'function' ? rootEl.querySelectorAll('*') : null;
|
|
644
|
+
if (elements) {
|
|
645
|
+
for (const el of elements) {
|
|
646
|
+
applyElementI18n(el, lang);
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
const doc = 'ownerDocument' in rootEl && rootEl.ownerDocument ? rootEl.ownerDocument : (root as Document);
|
|
651
|
+
if (doc && typeof doc.createTreeWalker === 'function') {
|
|
652
|
+
const walker = doc.createTreeWalker(rootEl, 4 /* NodeFilter.SHOW_TEXT */);
|
|
653
|
+
let current: Node | null;
|
|
654
|
+
while ((current = walker.nextNode())) {
|
|
655
|
+
applyTextNodeI18n(current, lang);
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
} finally {
|
|
659
|
+
isApplyingDom = false;
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
export function bindDomI18n(root?: Document | Element | null): void {
|
|
664
|
+
const target = root === undefined ? (typeof document !== 'undefined' ? document : null) : root;
|
|
665
|
+
if (!target) return;
|
|
666
|
+
boundRoot = target;
|
|
667
|
+
applyDomI18n(target);
|
|
668
|
+
|
|
669
|
+
if (domObserver) {
|
|
670
|
+
domObserver.disconnect();
|
|
671
|
+
domObserver = null;
|
|
672
|
+
}
|
|
673
|
+
if (typeof MutationObserver !== 'undefined') {
|
|
674
|
+
const observeTarget =
|
|
675
|
+
'documentElement' in target && target.documentElement
|
|
676
|
+
? target.documentElement
|
|
677
|
+
: 'body' in target && (target as Document).body
|
|
678
|
+
? (target as Document).body
|
|
679
|
+
: target;
|
|
680
|
+
if (observeTarget) {
|
|
681
|
+
domObserver = new MutationObserver((mutations) => {
|
|
682
|
+
if (isApplyingDom) return;
|
|
683
|
+
isApplyingDom = true;
|
|
684
|
+
try {
|
|
685
|
+
const lang = currentLanguage;
|
|
686
|
+
for (const m of mutations) {
|
|
687
|
+
if (m.type === 'characterData') {
|
|
688
|
+
applyTextNodeI18n(m.target, lang);
|
|
689
|
+
} else if (m.type === 'attributes' && m.target.nodeType === 1) {
|
|
690
|
+
applyElementI18n(m.target as Element, lang);
|
|
691
|
+
} else if (m.type === 'childList') {
|
|
692
|
+
if (m.target.nodeType === 1) {
|
|
693
|
+
applyElementI18n(m.target as Element, lang);
|
|
694
|
+
}
|
|
695
|
+
for (const added of m.addedNodes) {
|
|
696
|
+
if (added.nodeType === 3) {
|
|
697
|
+
applyTextNodeI18n(added, lang);
|
|
698
|
+
} else if (added.nodeType === 1) {
|
|
699
|
+
const el = added as Element;
|
|
700
|
+
applyElementI18n(el, lang);
|
|
701
|
+
const descendants = el.querySelectorAll?.('*');
|
|
702
|
+
if (descendants) {
|
|
703
|
+
for (const d of descendants) applyElementI18n(d, lang);
|
|
704
|
+
}
|
|
705
|
+
const doc = el.ownerDocument;
|
|
706
|
+
if (doc && typeof doc.createTreeWalker === 'function') {
|
|
707
|
+
const w = doc.createTreeWalker(el, 4);
|
|
708
|
+
let n: Node | null;
|
|
709
|
+
while ((n = w.nextNode())) applyTextNodeI18n(n, lang);
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
} finally {
|
|
716
|
+
isApplyingDom = false;
|
|
717
|
+
}
|
|
718
|
+
});
|
|
719
|
+
domObserver.observe(observeTarget, {
|
|
720
|
+
subtree: true,
|
|
721
|
+
childList: true,
|
|
722
|
+
characterData: true,
|
|
723
|
+
attributes: true,
|
|
724
|
+
attributeFilter: [...TRANSLATED_ATTRS]
|
|
725
|
+
});
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
// Bar 1: Catalogue parity check
|
|
731
|
+
export function assertCatalogParity(
|
|
732
|
+
en: Readonly<Record<string, string>> = enCatalog,
|
|
733
|
+
ko: Readonly<Record<string, string>> = koCatalog
|
|
734
|
+
): void {
|
|
735
|
+
const enKeys = Object.keys(en);
|
|
736
|
+
const koKeys = new Set(Object.keys(ko));
|
|
737
|
+
for (const key of enKeys) {
|
|
738
|
+
if (!koKeys.has(key)) {
|
|
739
|
+
throw new Error(`CATALOG_MISSING_KEY: koCatalog is missing key ${JSON.stringify(key)}`);
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
const enKeySet = new Set(enKeys);
|
|
743
|
+
for (const key of koKeys) {
|
|
744
|
+
if (!enKeySet.has(key)) {
|
|
745
|
+
throw new Error(`CATALOG_EXTRA_KEY: koCatalog has key absent from enCatalog: ${JSON.stringify(key)}`);
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
const phRe = /\{\d+\}/g;
|
|
749
|
+
for (const key of enKeys) {
|
|
750
|
+
const enVal = en[key]!;
|
|
751
|
+
const koVal = ko[key]!;
|
|
752
|
+
if (!koVal || typeof koVal !== 'string') {
|
|
753
|
+
throw new Error(`CATALOG_EMPTY_VALUE: koCatalog key ${JSON.stringify(key)} has empty value`);
|
|
754
|
+
}
|
|
755
|
+
const enPh = [...new Set(enVal.match(phRe) ?? [])].sort().join(',');
|
|
756
|
+
const koPh = [...new Set(koVal.match(phRe) ?? [])].sort().join(',');
|
|
757
|
+
if (enPh !== koPh) {
|
|
758
|
+
throw new Error(
|
|
759
|
+
`CATALOG_PLACEHOLDER_MISMATCH: key ${JSON.stringify(key)} has placeholders [${enPh}] in en vs [${koPh}] in ko`
|
|
760
|
+
);
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
// Bar 2: Hardcoded visible string check across web/*.html and web/*.ts
|
|
766
|
+
function decodeHtmlEntities(str: string): string {
|
|
767
|
+
return str
|
|
768
|
+
.replace(/&/g, '&')
|
|
769
|
+
.replace(/</g, '<')
|
|
770
|
+
.replace(/>/g, '>')
|
|
771
|
+
.replace(/"/g, '"');
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
function isSingleSymbolOrKeycap(text: string): boolean {
|
|
775
|
+
const t = text.trim();
|
|
776
|
+
if (!t) return true;
|
|
777
|
+
if (t.length === 1) return true;
|
|
778
|
+
if (/^[-0-9.,:/×°%+–—?·✓○↗◇●\s]+$/.test(t)) return true;
|
|
779
|
+
return false;
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
function isExemptString(
|
|
783
|
+
file: string,
|
|
784
|
+
text: string,
|
|
785
|
+
exemptions: readonly WebStringExemption[]
|
|
786
|
+
): boolean {
|
|
787
|
+
for (const ex of exemptions) {
|
|
788
|
+
if (ex.file === file && (ex.match === '*' || ex.match === text)) {
|
|
789
|
+
return true;
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
return false;
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
function tokenizeTsStrings(source: string): ReadonlyArray<{ line: number; norm: readonly string[]; contextBefore: string }> {
|
|
796
|
+
const results: Array<{ line: number; norm: readonly string[]; contextBefore: string }> = [];
|
|
797
|
+
let i = 0;
|
|
798
|
+
const n = source.length;
|
|
799
|
+
let line = 1;
|
|
800
|
+
|
|
801
|
+
function canStartRegex(pos: number): boolean {
|
|
802
|
+
let j = pos - 1;
|
|
803
|
+
while (j >= 0 && /\s/.test(source[j]!)) j--;
|
|
804
|
+
if (j < 0) return true;
|
|
805
|
+
const ch = source[j]!;
|
|
806
|
+
if ('([{,;:=!&|?+-*~^%<>'.includes(ch)) return true;
|
|
807
|
+
const wordMatch = /[A-Za-z_$][A-Za-z0-9_$]*$/.exec(source.slice(Math.max(0, j - 15), j + 1));
|
|
808
|
+
if (wordMatch && ['return', 'throw', 'case', 'typeof', 'void', 'delete', 'in', 'of', 'new'].includes(wordMatch[0])) {
|
|
809
|
+
return true;
|
|
810
|
+
}
|
|
811
|
+
return false;
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
function skipTemplateExpr(start: number): { end: number; expr: string; lines: number } {
|
|
815
|
+
let j = start;
|
|
816
|
+
let depth = 1;
|
|
817
|
+
let addedLines = 0;
|
|
818
|
+
while (j < n && depth > 0) {
|
|
819
|
+
const ch = source[j]!;
|
|
820
|
+
if (ch === '\n') addedLines++;
|
|
821
|
+
if (ch === "'" || ch === '"' || ch === '`') {
|
|
822
|
+
const q = ch;
|
|
823
|
+
j++;
|
|
824
|
+
while (j < n && source[j] !== q) {
|
|
825
|
+
if (source[j] === '\n') addedLines++;
|
|
826
|
+
if (source[j] === '\\') {
|
|
827
|
+
j += 2;
|
|
828
|
+
continue;
|
|
829
|
+
}
|
|
830
|
+
if (q === '`' && source[j] === '$' && source[j + 1] === '{') {
|
|
831
|
+
const sub = skipTemplateExpr(j + 2);
|
|
832
|
+
addedLines += sub.lines;
|
|
833
|
+
j = sub.end;
|
|
834
|
+
continue;
|
|
835
|
+
}
|
|
836
|
+
j++;
|
|
837
|
+
}
|
|
838
|
+
j++;
|
|
839
|
+
continue;
|
|
840
|
+
}
|
|
841
|
+
if (ch === '{') depth++;
|
|
842
|
+
else if (ch === '}') depth--;
|
|
843
|
+
j++;
|
|
844
|
+
}
|
|
845
|
+
return { end: j, expr: source.slice(start, j - 1), lines: addedLines };
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
while (i < n) {
|
|
849
|
+
const ch = source[i]!;
|
|
850
|
+
if (ch === '\n') {
|
|
851
|
+
line++;
|
|
852
|
+
i++;
|
|
853
|
+
continue;
|
|
854
|
+
}
|
|
855
|
+
if (ch === '/' && source[i + 1] === '/') {
|
|
856
|
+
i += 2;
|
|
857
|
+
while (i < n && source[i] !== '\n') i++;
|
|
858
|
+
continue;
|
|
859
|
+
}
|
|
860
|
+
if (ch === '/' && source[i + 1] === '*') {
|
|
861
|
+
i += 2;
|
|
862
|
+
while (i + 1 < n && !(source[i] === '*' && source[i + 1] === '/')) {
|
|
863
|
+
if (source[i] === '\n') line++;
|
|
864
|
+
i++;
|
|
865
|
+
}
|
|
866
|
+
i += 2;
|
|
867
|
+
continue;
|
|
868
|
+
}
|
|
869
|
+
if (ch === '/' && canStartRegex(i)) {
|
|
870
|
+
i++;
|
|
871
|
+
let inClass = false;
|
|
872
|
+
while (i < n) {
|
|
873
|
+
if (source[i] === '\n' && !inClass) break;
|
|
874
|
+
if (source[i] === '\\') {
|
|
875
|
+
i += 2;
|
|
876
|
+
continue;
|
|
877
|
+
}
|
|
878
|
+
if (source[i] === '[') inClass = true;
|
|
879
|
+
else if (source[i] === ']') inClass = false;
|
|
880
|
+
else if (source[i] === '/' && !inClass) {
|
|
881
|
+
i++;
|
|
882
|
+
while (i < n && /[a-z]/i.test(source[i]!)) i++;
|
|
883
|
+
break;
|
|
884
|
+
}
|
|
885
|
+
i++;
|
|
886
|
+
}
|
|
887
|
+
continue;
|
|
888
|
+
}
|
|
889
|
+
if (ch === "'" || ch === '"') {
|
|
890
|
+
const startLine = line;
|
|
891
|
+
const contextBefore = source.slice(Math.max(0, i - 48), i);
|
|
892
|
+
const q = ch;
|
|
893
|
+
i++;
|
|
894
|
+
let val = '';
|
|
895
|
+
while (i < n && source[i] !== q) {
|
|
896
|
+
if (source[i] === '\n') line++;
|
|
897
|
+
if (source[i] === '\\') {
|
|
898
|
+
const next = source[i + 1];
|
|
899
|
+
if (next === 'n') val += '\n';
|
|
900
|
+
else if (next === 't') val += '\t';
|
|
901
|
+
else if (next !== undefined) val += next;
|
|
902
|
+
i += 2;
|
|
903
|
+
continue;
|
|
904
|
+
}
|
|
905
|
+
val += source[i]!;
|
|
906
|
+
i++;
|
|
907
|
+
}
|
|
908
|
+
i++;
|
|
909
|
+
results.push({ line: startLine, norm: [val], contextBefore });
|
|
910
|
+
continue;
|
|
911
|
+
}
|
|
912
|
+
if (ch === '`') {
|
|
913
|
+
const startLine = line;
|
|
914
|
+
const contextBefore = source.slice(Math.max(0, i - 48), i);
|
|
915
|
+
i++;
|
|
916
|
+
let variants: Array<{ text: string; nextIdx: number }> = [{ text: '', nextIdx: 0 }];
|
|
917
|
+
while (i < n && source[i] !== '`') {
|
|
918
|
+
if (source[i] === '\n') line++;
|
|
919
|
+
if (source[i] === '\\') {
|
|
920
|
+
const next = source[i + 1];
|
|
921
|
+
const app = next === 'n' ? '\n' : next === 't' ? '\t' : (next ?? '');
|
|
922
|
+
variants = variants.map((v) => ({ text: v.text + app, nextIdx: v.nextIdx }));
|
|
923
|
+
i += 2;
|
|
924
|
+
continue;
|
|
925
|
+
}
|
|
926
|
+
if (source[i] === '$' && source[i + 1] === '{') {
|
|
927
|
+
const sub = skipTemplateExpr(i + 2);
|
|
928
|
+
line += sub.lines;
|
|
929
|
+
i = sub.end;
|
|
930
|
+
const pluralMatch = /\?\s*(['"])(|s|es)\1\s*:\s*(['"])(|s|es)\3\s*$/.exec(sub.expr.trim());
|
|
931
|
+
if (pluralMatch) {
|
|
932
|
+
const a = pluralMatch[2]!;
|
|
933
|
+
const b = pluralMatch[4]!;
|
|
934
|
+
const expanded: Array<{ text: string; nextIdx: number }> = [];
|
|
935
|
+
for (const v of variants) {
|
|
936
|
+
expanded.push({ text: v.text + a, nextIdx: v.nextIdx });
|
|
937
|
+
expanded.push({ text: v.text + b, nextIdx: v.nextIdx });
|
|
938
|
+
}
|
|
939
|
+
variants = expanded;
|
|
940
|
+
} else {
|
|
941
|
+
variants = variants.map((v) => ({ text: `${v.text}{${v.nextIdx}}`, nextIdx: v.nextIdx + 1 }));
|
|
942
|
+
}
|
|
943
|
+
continue;
|
|
944
|
+
}
|
|
945
|
+
const c = source[i]!;
|
|
946
|
+
variants = variants.map((v) => ({ text: v.text + c, nextIdx: v.nextIdx }));
|
|
947
|
+
i++;
|
|
948
|
+
}
|
|
949
|
+
i++;
|
|
950
|
+
results.push({ line: startLine, norm: variants.map((v) => v.text), contextBefore });
|
|
951
|
+
continue;
|
|
952
|
+
}
|
|
953
|
+
i++;
|
|
954
|
+
}
|
|
955
|
+
return results;
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
function isNonVisibleTsToken(s: string, contextBefore: string): boolean {
|
|
959
|
+
const t = s.trim();
|
|
960
|
+
if (!t || !/[A-Za-z]{2,}/.test(t)) return true;
|
|
961
|
+
if (/(?:from\s+|import\s*\(\s*)$/.test(contextBefore)) return true;
|
|
962
|
+
if (/(?:querySelector(?:All)?|closest|matches|getElementById|createElement(?:NS)?|getAttribute|setAttribute|removeAttribute|hasAttribute|addEventListener|removeEventListener|classList\.(?:add|remove|toggle|contains))\s*\(\s*$/.test(contextBefore)) {
|
|
963
|
+
return true;
|
|
964
|
+
}
|
|
965
|
+
if (/\.className\s*=\s*$/.test(contextBefore)) return true;
|
|
966
|
+
if (!s.includes(' ')) {
|
|
967
|
+
// Single-token string without spaces: only capitalized UI words (>= 2 letters) are visible labels
|
|
968
|
+
if (!/^[A-Z][a-z]+$/.test(s)) return true;
|
|
969
|
+
if (
|
|
970
|
+
s === 'AbortError' ||
|
|
971
|
+
s === 'Canvas2D' ||
|
|
972
|
+
s === 'WebGL' ||
|
|
973
|
+
s === 'Bearer' ||
|
|
974
|
+
s === 'Space' ||
|
|
975
|
+
s === 'Backspace' ||
|
|
976
|
+
s === 'Enter' ||
|
|
977
|
+
s === 'Escape' ||
|
|
978
|
+
s === 'Home' ||
|
|
979
|
+
s === 'End'
|
|
980
|
+
) {
|
|
981
|
+
return true;
|
|
982
|
+
}
|
|
983
|
+
return false;
|
|
984
|
+
}
|
|
985
|
+
if (
|
|
986
|
+
s.startsWith('[data-') ||
|
|
987
|
+
s.startsWith('.animation-') ||
|
|
988
|
+
s.startsWith('.mode-switch') ||
|
|
989
|
+
s.startsWith('#') ||
|
|
990
|
+
s.startsWith('(prefers-') ||
|
|
991
|
+
s.startsWith('input[') ||
|
|
992
|
+
s.startsWith('option[') ||
|
|
993
|
+
s.startsWith('button,input') ||
|
|
994
|
+
s.startsWith('textarea,select') ||
|
|
995
|
+
s.startsWith('dialog[open]') ||
|
|
996
|
+
s.startsWith('[role=separator]') ||
|
|
997
|
+
s.startsWith('calc(') ||
|
|
998
|
+
s.startsWith('minmax(') ||
|
|
999
|
+
s.startsWith('radial-gradient(') ||
|
|
1000
|
+
s.startsWith('translate(') ||
|
|
1001
|
+
s.startsWith('scale(') ||
|
|
1002
|
+
s.startsWith('var(')
|
|
1003
|
+
) {
|
|
1004
|
+
return true;
|
|
1005
|
+
}
|
|
1006
|
+
if (
|
|
1007
|
+
s === ' workspace-side-' ||
|
|
1008
|
+
s === 'workspace-separator workspace-' ||
|
|
1009
|
+
s === '|inspector-' ||
|
|
1010
|
+
s === 'sticky-header settings-header' ||
|
|
1011
|
+
s === 'sticky-header workspace-drawer-header' ||
|
|
1012
|
+
s === 'animation-key-lane readonly-lane-track' ||
|
|
1013
|
+
s === 'animation-readonly-badge animation-readonly-subrow' ||
|
|
1014
|
+
s === 'error idle-refusal' ||
|
|
1015
|
+
s === 'hint animation-key-empty' ||
|
|
1016
|
+
s === 'hint error physics-reason' ||
|
|
1017
|
+
s === 'hint pending' ||
|
|
1018
|
+
s === 'hint rebuild-drop-notice' ||
|
|
1019
|
+
s === 'mesh-region selected' ||
|
|
1020
|
+
s === 'physics-control idle-period' ||
|
|
1021
|
+
s === 'physics-control idle-period pending' ||
|
|
1022
|
+
s === 'physics-control mesh-param' ||
|
|
1023
|
+
s === 'physics-control mesh-param pending' ||
|
|
1024
|
+
s === 'physics-control pending' ||
|
|
1025
|
+
s === 'physics-table idle-table' ||
|
|
1026
|
+
s === 'physics-table physics-locked-table' ||
|
|
1027
|
+
s === 'physics-toggle mesh-param-toggle' ||
|
|
1028
|
+
s === 'physics-toggle pending' ||
|
|
1029
|
+
s === 'reading-tick {0}' ||
|
|
1030
|
+
s === 'readings-line scratch' ||
|
|
1031
|
+
s === 'readings-line {0}{1}' ||
|
|
1032
|
+
s === 'rig-fields-arc inward' ||
|
|
1033
|
+
s === 'rig-fields-arc outward' ||
|
|
1034
|
+
s === 'rig-fields-handle {0}' ||
|
|
1035
|
+
s === 'row requirements-bar' ||
|
|
1036
|
+
s === 'row retarget-translate' ||
|
|
1037
|
+
s === 'tick-swatch scratch' ||
|
|
1038
|
+
s === 'tick-swatch {0}' ||
|
|
1039
|
+
s === 'bones-anchor pending' ||
|
|
1040
|
+
s === 'cloth-field pending' ||
|
|
1041
|
+
s === '0px 0px' ||
|
|
1042
|
+
s === '600 11px ui-monospace, monospace' ||
|
|
1043
|
+
s === '.json,application/json' ||
|
|
1044
|
+
s === 'Bearer ' ||
|
|
1045
|
+
s === ' C{0} {1} {2} {3} {4} {5}' ||
|
|
1046
|
+
s === ' H{0} V{1}' ||
|
|
1047
|
+
s === ' s⁻¹' ||
|
|
1048
|
+
s === ' ms' ||
|
|
1049
|
+
s === 'a, b, …' ||
|
|
1050
|
+
s === '{0}px {1}px minmax(0,1fr) {2}px {3}px'
|
|
1051
|
+
) {
|
|
1052
|
+
return true;
|
|
1053
|
+
}
|
|
1054
|
+
return false;
|
|
1055
|
+
}
|
|
1056
|
+
|
|
1057
|
+
export function checkWebHardcodedStrings(
|
|
1058
|
+
files: ReadonlyArray<{ path: string; content: string }>,
|
|
1059
|
+
options?: {
|
|
1060
|
+
readonly catalog?: Readonly<Record<string, string>>;
|
|
1061
|
+
readonly exemptions?: readonly WebStringExemption[];
|
|
1062
|
+
}
|
|
1063
|
+
): {
|
|
1064
|
+
readonly ok: boolean;
|
|
1065
|
+
readonly violations: readonly HardcodedStringViolation[];
|
|
1066
|
+
readonly exemptions: readonly WebStringExemption[];
|
|
1067
|
+
} {
|
|
1068
|
+
const catalog = options?.catalog ?? enCatalog;
|
|
1069
|
+
const exemptions = options?.exemptions ?? WEB_STRING_EXEMPTIONS;
|
|
1070
|
+
|
|
1071
|
+
for (const ex of exemptions) {
|
|
1072
|
+
if (!ex.file || !ex.match || !ex.reason || !ex.reason.trim()) {
|
|
1073
|
+
throw new Error(`I18N_EXEMPTION_REASON_REQUIRED: exemption for ${ex.file} (${ex.match}) is missing a reason`);
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
|
|
1077
|
+
const violations: HardcodedStringViolation[] = [];
|
|
1078
|
+
|
|
1079
|
+
for (const file of files) {
|
|
1080
|
+
const relPath = file.path.replace(/\\/g, '/');
|
|
1081
|
+
if (
|
|
1082
|
+
relPath === 'web/catalog-en.ts' ||
|
|
1083
|
+
relPath === 'web/catalog-ko.ts' ||
|
|
1084
|
+
relPath === 'web/i18n.ts' ||
|
|
1085
|
+
isExemptString(relPath, '*', exemptions)
|
|
1086
|
+
) {
|
|
1087
|
+
continue;
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
if (relPath.endsWith('.html')) {
|
|
1091
|
+
const src = file.content;
|
|
1092
|
+
// 1. Check attributes (aria-label, title, placeholder)
|
|
1093
|
+
const attrRe = /\b(aria-label|title|placeholder)="([^"]+)"/g;
|
|
1094
|
+
let m: RegExpExecArray | null;
|
|
1095
|
+
while ((m = attrRe.exec(src)) !== null) {
|
|
1096
|
+
const rawVal = m[2]!.replace(/\s+/g, ' ').trim();
|
|
1097
|
+
const decodedVal = decodeHtmlEntities(rawVal);
|
|
1098
|
+
if (isSingleSymbolOrKeycap(decodedVal)) continue;
|
|
1099
|
+
if (catalog[rawVal] !== undefined || catalog[decodedVal] !== undefined) continue;
|
|
1100
|
+
if (isExemptString(relPath, rawVal, exemptions) || isExemptString(relPath, decodedVal, exemptions)) continue;
|
|
1101
|
+
const line = src.slice(0, m.index).split('\n').length;
|
|
1102
|
+
violations.push({ file: relPath, line, kind: 'html-attr', text: decodedVal });
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
// 2. Check rich <p class="hint"> blocks and strip matched ones before text-node scan
|
|
1106
|
+
const strippedHints = src.replace(/<p class="hint[^"]*">([\s\S]*?)<\/p>/g, (full, inner: string) => {
|
|
1107
|
+
const normInner = inner.replace(/\s+/g, ' ').trim();
|
|
1108
|
+
const decodedInner = decodeHtmlEntities(normInner);
|
|
1109
|
+
if (catalog[normInner] !== undefined || catalog[decodedInner] !== undefined) {
|
|
1110
|
+
return '\n'.repeat(full.split('\n').length - 1);
|
|
1111
|
+
}
|
|
1112
|
+
return full;
|
|
1113
|
+
});
|
|
1114
|
+
|
|
1115
|
+
// 3. Check remaining text nodes
|
|
1116
|
+
const textRe = />([^<]+)</g;
|
|
1117
|
+
while ((m = textRe.exec(strippedHints)) !== null) {
|
|
1118
|
+
const normTxt = decodeHtmlEntities(m[1]!.replace(/\s+/g, ' ').trim());
|
|
1119
|
+
if (isSingleSymbolOrKeycap(normTxt)) continue;
|
|
1120
|
+
if (catalog[normTxt] !== undefined) continue;
|
|
1121
|
+
if (isExemptString(relPath, normTxt, exemptions)) continue;
|
|
1122
|
+
const line = strippedHints.slice(0, m.index).split('\n').length;
|
|
1123
|
+
violations.push({ file: relPath, line, kind: 'html-text', text: normTxt });
|
|
1124
|
+
}
|
|
1125
|
+
} else if (relPath.endsWith('.ts')) {
|
|
1126
|
+
const tokens = tokenizeTsStrings(file.content);
|
|
1127
|
+
for (const tok of tokens) {
|
|
1128
|
+
for (const variant of tok.norm) {
|
|
1129
|
+
if (variant.startsWith('<') && variant.includes('>')) {
|
|
1130
|
+
// Inline HTML snippet in TS: check its attributes and text nodes
|
|
1131
|
+
const subRes = checkWebHardcodedStrings(
|
|
1132
|
+
[{ path: `${relPath}#inline.html`, content: variant }],
|
|
1133
|
+
{ catalog, exemptions }
|
|
1134
|
+
);
|
|
1135
|
+
for (const v of subRes.violations) {
|
|
1136
|
+
violations.push({ file: relPath, line: tok.line, kind: 'ts-string', text: v.text });
|
|
1137
|
+
}
|
|
1138
|
+
continue;
|
|
1139
|
+
}
|
|
1140
|
+
if (isNonVisibleTsToken(variant, tok.contextBefore)) continue;
|
|
1141
|
+
if (catalog[variant] !== undefined) continue;
|
|
1142
|
+
if (isExemptString(relPath, variant, exemptions)) continue;
|
|
1143
|
+
violations.push({ file: relPath, line: tok.line, kind: 'ts-string', text: variant });
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1149
|
+
return {
|
|
1150
|
+
ok: violations.length === 0,
|
|
1151
|
+
violations,
|
|
1152
|
+
exemptions
|
|
1153
|
+
};
|
|
1154
|
+
}
|