@jjlmoya/utils-pets 1.22.0 → 1.24.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/category/i18n/de.ts +1 -1
- package/src/category/i18n/en.ts +2 -2
- package/src/category/i18n/es.ts +1 -1
- package/src/category/i18n/fr.ts +1 -1
- package/src/category/i18n/pt.ts +1 -1
- package/src/category/i18n/tr.ts +1 -1
- package/src/category/index.ts +26 -26
- package/src/entries.ts +12 -12
- package/src/tests/bibliography_wellformed_export.test.ts +46 -0
- package/src/tests/category_seo_quality.test.ts +74 -0
- package/src/tests/faq_count.test.ts +22 -22
- package/src/tests/locale_completeness.test.ts +30 -30
- package/src/tests/no_h1_in_components.test.ts +1 -1
- package/src/tests/pet_logic.test.ts +49 -0
- package/src/tests/seo_length.test.ts +54 -54
- package/src/tests/seo_parity.test.ts +2 -2
- package/src/tests/seo_translation_completeness.test.ts +18 -12
- package/src/tests/seo_wellformed_export.test.ts +65 -0
- package/src/tests/spanish_leakage.test.ts +175 -175
- package/src/tests/tool_validation.test.ts +137 -137
- package/src/tool/petAge/component.astro +3 -3
- package/src/tool/petAge/i18n/de.ts +184 -184
- package/src/tool/petAge/i18n/en.ts +184 -184
- package/src/tool/petAge/i18n/es.ts +184 -184
- package/src/tool/petAge/i18n/fr.ts +184 -184
- package/src/tool/petAge/i18n/id.ts +184 -184
- package/src/tool/petAge/i18n/it.ts +184 -184
- package/src/tool/petAge/i18n/ja.ts +184 -184
- package/src/tool/petAge/i18n/ko.ts +184 -184
- package/src/tool/petAge/i18n/nl.ts +184 -184
- package/src/tool/petAge/i18n/pl.ts +184 -184
- package/src/tool/petAge/i18n/pt.ts +184 -184
- package/src/tool/petAge/i18n/ru.ts +184 -184
- package/src/tool/petAge/i18n/sv.ts +184 -184
- package/src/tool/petAge/i18n/tr.ts +185 -185
- package/src/tool/petAge/i18n/zh.ts +184 -184
- package/src/tool/petAge/seo.astro +15 -15
- package/src/tool/petGestation/i18n/de.ts +0 -2
- package/src/tool/petGestation/i18n/en.ts +0 -2
- package/src/tool/petGestation/i18n/es.ts +0 -2
- package/src/tool/petGestation/i18n/fr.ts +0 -2
- package/src/tool/petGestation/i18n/id.ts +0 -2
- package/src/tool/petGestation/i18n/it.ts +0 -2
- package/src/tool/petGestation/i18n/ja.ts +0 -2
- package/src/tool/petGestation/i18n/ko.ts +0 -2
- package/src/tool/petGestation/i18n/nl.ts +0 -2
- package/src/tool/petGestation/i18n/pl.ts +0 -2
- package/src/tool/petGestation/i18n/pt.ts +0 -2
- package/src/tool/petGestation/i18n/ru.ts +0 -2
- package/src/tool/petGestation/i18n/sv.ts +0 -2
- package/src/tool/petGestation/i18n/tr.ts +0 -2
- package/src/tool/petGestation/i18n/zh.ts +0 -2
- package/src/tool/petGestation/ui.ts +0 -2
- package/src/tool/petRation/i18n/de.ts +181 -181
- package/src/tool/petRation/i18n/en.ts +181 -181
- package/src/tool/petRation/i18n/es.ts +181 -181
- package/src/tool/petRation/i18n/fr.ts +181 -181
- package/src/tool/petRation/i18n/id.ts +181 -181
- package/src/tool/petRation/i18n/it.ts +181 -181
- package/src/tool/petRation/i18n/ja.ts +181 -181
- package/src/tool/petRation/i18n/ko.ts +181 -181
- package/src/tool/petRation/i18n/nl.ts +181 -181
- package/src/tool/petRation/i18n/pl.ts +181 -181
- package/src/tool/petRation/i18n/pt.ts +181 -181
- package/src/tool/petRation/i18n/ru.ts +181 -181
- package/src/tool/petRation/i18n/sv.ts +181 -181
- package/src/tool/petRation/i18n/tr.ts +181 -181
- package/src/tool/petRation/i18n/zh.ts +181 -181
- package/src/tool/petRation/seo.astro +15 -15
- package/src/tool/petToxicity/i18n/de.ts +0 -2
- package/src/tool/petToxicity/i18n/en.ts +0 -2
- package/src/tool/petToxicity/i18n/es.ts +2 -4
- package/src/tool/petToxicity/i18n/fr.ts +0 -2
- package/src/tool/petToxicity/i18n/id.ts +0 -2
- package/src/tool/petToxicity/i18n/it.ts +0 -2
- package/src/tool/petToxicity/i18n/ja.ts +0 -2
- package/src/tool/petToxicity/i18n/ko.ts +0 -2
- package/src/tool/petToxicity/i18n/nl.ts +0 -2
- package/src/tool/petToxicity/i18n/pl.ts +0 -2
- package/src/tool/petToxicity/i18n/pt.ts +0 -2
- package/src/tool/petToxicity/i18n/ru.ts +0 -2
- package/src/tool/petToxicity/i18n/sv.ts +0 -2
- package/src/tool/petToxicity/i18n/tr.ts +0 -2
- package/src/tool/petToxicity/i18n/zh.ts +0 -2
- package/src/tool/petToxicity/ui.ts +0 -2
- package/src/tool/petWaterIntake/i18n/de.ts +0 -15
- package/src/tool/petWaterIntake/i18n/en.ts +0 -15
- package/src/tool/petWaterIntake/i18n/es.ts +2 -17
- package/src/tool/petWaterIntake/i18n/fr.ts +0 -15
- package/src/tool/petWaterIntake/i18n/id.ts +0 -15
- package/src/tool/petWaterIntake/i18n/it.ts +0 -15
- package/src/tool/petWaterIntake/i18n/ja.ts +0 -15
- package/src/tool/petWaterIntake/i18n/ko.ts +0 -15
- package/src/tool/petWaterIntake/i18n/nl.ts +0 -15
- package/src/tool/petWaterIntake/i18n/pl.ts +0 -15
- package/src/tool/petWaterIntake/i18n/pt.ts +0 -15
- package/src/tool/petWaterIntake/i18n/ru.ts +0 -15
- package/src/tool/petWaterIntake/i18n/sv.ts +0 -15
- package/src/tool/petWaterIntake/i18n/tr.ts +0 -15
- package/src/tool/petWaterIntake/i18n/zh.ts +0 -15
- package/src/tool/petWaterIntake/ui.ts +0 -15
- package/src/tools.ts +19 -19
|
@@ -28,23 +28,21 @@ function calculateSeoTextLength(seoSections: any[]): number {
|
|
|
28
28
|
return seoSections.reduce((acc, section) => acc + getSectionLength(section), 0);
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
function checkLocaleSeoLength(toolId: string, locale: string, localeLen: number, enLen: number):
|
|
31
|
+
function checkLocaleSeoLength(toolId: string, locale: string, localeLen: number, enLen: number): string | null {
|
|
32
32
|
const isAsian = ASIAN_LOCALES.includes(locale);
|
|
33
|
-
const minLength = Math.floor(enLen *
|
|
33
|
+
const minLength = isAsian ? 120 : Math.max(240, Math.floor(enLen * 0.35));
|
|
34
34
|
const msgType = isAsian ? 'suspiciously short' : 'truncated/lazy';
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
`[LAZY SEO TRANSLATION] Tool "${toolId}" locale "${locale}" SEO text is ${msgType} (${localeLen} chars vs EN ${enLen} chars, expected min ${minLength})`,
|
|
39
|
-
).toBeGreaterThanOrEqual(minLength);
|
|
36
|
+
if (localeLen >= minLength) return null;
|
|
37
|
+
return `[LAZY SEO TRANSLATION] Tool "${toolId}" locale "${locale}" SEO text is ${msgType} (${localeLen} chars vs EN ${enLen} chars, expected min ${minLength})`;
|
|
40
38
|
}
|
|
41
39
|
|
|
42
|
-
async function auditSingleLocale(toolId: string, locale: string, loader: any, enSeoLength: number): Promise<
|
|
43
|
-
if (locale === 'en' || !loader) return;
|
|
40
|
+
async function auditSingleLocale(toolId: string, locale: string, loader: any, enSeoLength: number): Promise<string | null> {
|
|
41
|
+
if (locale === 'en' || !loader) return null;
|
|
44
42
|
const content = await loader();
|
|
45
|
-
if (!content.seo || !Array.isArray(content.seo)) return;
|
|
43
|
+
if (!content.seo || !Array.isArray(content.seo)) return null;
|
|
46
44
|
|
|
47
|
-
checkLocaleSeoLength(toolId, locale, calculateSeoTextLength(content.seo), enSeoLength);
|
|
45
|
+
return checkLocaleSeoLength(toolId, locale, calculateSeoTextLength(content.seo), enSeoLength);
|
|
48
46
|
}
|
|
49
47
|
|
|
50
48
|
describe('SEO Translation Completeness & Laziness Audit', () => {
|
|
@@ -58,12 +56,20 @@ describe('SEO Translation Completeness & Laziness Audit', () => {
|
|
|
58
56
|
if (!enContent.seo || !Array.isArray(enContent.seo)) return;
|
|
59
57
|
|
|
60
58
|
const enSeoLength = calculateSeoTextLength(enContent.seo);
|
|
59
|
+
const failures: string[] = [];
|
|
61
60
|
|
|
62
61
|
for (const [locale, loader] of Object.entries(entry.i18n)) {
|
|
63
|
-
await auditSingleLocale(entry.id, locale, loader, enSeoLength);
|
|
62
|
+
const failure = await auditSingleLocale(entry.id, locale, loader, enSeoLength);
|
|
63
|
+
if (failure) failures.push(failure);
|
|
64
64
|
}
|
|
65
|
+
|
|
66
|
+
expect(
|
|
67
|
+
failures,
|
|
68
|
+
failures.length > 0
|
|
69
|
+
? `SEO translation completeness failures for "${entry.id}":\n${failures.map((failure, index) => `${index + 1}. ${failure}`).join('\n')}`
|
|
70
|
+
: undefined,
|
|
71
|
+
).toEqual([]);
|
|
65
72
|
});
|
|
66
73
|
});
|
|
67
74
|
});
|
|
68
75
|
});
|
|
69
|
-
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { readdirSync, readFileSync, existsSync } from 'fs';
|
|
3
|
+
import { join, relative } from 'path';
|
|
4
|
+
|
|
5
|
+
function findSeoAstroFiles(dir: string): string[] {
|
|
6
|
+
const files: string[] = [];
|
|
7
|
+
if (!existsSync(dir)) return files;
|
|
8
|
+
const entries = readdirSync(dir, { withFileTypes: true });
|
|
9
|
+
|
|
10
|
+
for (const entry of entries) {
|
|
11
|
+
const fullPath = join(dir, entry.name);
|
|
12
|
+
if (entry.isDirectory()) {
|
|
13
|
+
files.push(...findSeoAstroFiles(fullPath));
|
|
14
|
+
} else if (entry.isFile() && entry.name === 'seo.astro') {
|
|
15
|
+
files.push(fullPath);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return files;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const toolDir = join(process.cwd(), 'src', 'tool');
|
|
23
|
+
const seoFiles = findSeoAstroFiles(toolDir);
|
|
24
|
+
|
|
25
|
+
describe('SEO Component Wellformed Export', () => {
|
|
26
|
+
it('found tool seo.astro components', () => {
|
|
27
|
+
expect(seoFiles.length).toBeGreaterThan(0);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
seoFiles.forEach((file) => {
|
|
31
|
+
const relativePath = relative(process.cwd(), file);
|
|
32
|
+
|
|
33
|
+
it(`${relativePath} should dynamically load SEO sections and use SEORenderer`, () => {
|
|
34
|
+
const content = readFileSync(file, 'utf-8');
|
|
35
|
+
|
|
36
|
+
const usesSeoRenderer =
|
|
37
|
+
content.includes('@jjlmoya/utils-shared') &&
|
|
38
|
+
(content.includes('SEORenderer') || content.includes('SEOArticle'));
|
|
39
|
+
|
|
40
|
+
const acquiresDynamicContent =
|
|
41
|
+
content.includes('.i18n') ||
|
|
42
|
+
content.includes('loader') ||
|
|
43
|
+
content.includes('await loader') ||
|
|
44
|
+
content.includes('.seo');
|
|
45
|
+
|
|
46
|
+
const isBrokenPattern =
|
|
47
|
+
/sections\s*=\s*\[\s*\]/.test(content) && !acquiresDynamicContent;
|
|
48
|
+
|
|
49
|
+
expect(
|
|
50
|
+
usesSeoRenderer,
|
|
51
|
+
`File "${relativePath}" does not import or use SEORenderer from @jjlmoya/utils-shared.`,
|
|
52
|
+
).toBe(true);
|
|
53
|
+
|
|
54
|
+
expect(
|
|
55
|
+
isBrokenPattern,
|
|
56
|
+
`File "${relativePath}" relies on a static sections=[] prop default without fetching content from entry.i18n, resulting in empty SEO text on consumers.`,
|
|
57
|
+
).toBe(false);
|
|
58
|
+
|
|
59
|
+
expect(
|
|
60
|
+
acquiresDynamicContent,
|
|
61
|
+
`File "${relativePath}" does not fetch dynamic i18n content for SEO rendering.`,
|
|
62
|
+
).toBe(true);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
});
|
|
@@ -1,175 +1,175 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { ALL_ENTRIES } from '../entries';
|
|
3
|
-
|
|
4
|
-
const STRUCTURAL_KEYS = new Set([
|
|
5
|
-
'id',
|
|
6
|
-
'slug',
|
|
7
|
-
'url',
|
|
8
|
-
'icon',
|
|
9
|
-
'image',
|
|
10
|
-
'imageUrl',
|
|
11
|
-
'keywords',
|
|
12
|
-
'category',
|
|
13
|
-
'tags',
|
|
14
|
-
'toolId',
|
|
15
|
-
'type',
|
|
16
|
-
'locale',
|
|
17
|
-
'language',
|
|
18
|
-
'direction',
|
|
19
|
-
]);
|
|
20
|
-
|
|
21
|
-
const TRANSLATABLE_KEYS = [
|
|
22
|
-
'title',
|
|
23
|
-
'description',
|
|
24
|
-
'faqTitle',
|
|
25
|
-
'faq',
|
|
26
|
-
'howTo',
|
|
27
|
-
'seo',
|
|
28
|
-
'schemas',
|
|
29
|
-
] as const;
|
|
30
|
-
|
|
31
|
-
const COPY_THRESHOLD = 0.9;
|
|
32
|
-
|
|
33
|
-
const SPANISH_MARKERS = [
|
|
34
|
-
['sangre', /\bsangre\b/gi],
|
|
35
|
-
['molino', /\bmolino\b/gi],
|
|
36
|
-
['grano', /\bgrano\b/gi],
|
|
37
|
-
['paladar', /\bpaladar\b/gi],
|
|
38
|
-
['cuchillas', /\bcuchillas\b/gi],
|
|
39
|
-
['trozos', /\btrozos\b/gi],
|
|
40
|
-
['frescura', /\bfrescura\b/gi],
|
|
41
|
-
['ingresa', /\bingresa\b/gi],
|
|
42
|
-
['selecciona', /\bselecciona\b/gi],
|
|
43
|
-
['herramienta', /\bherramienta\b/gi],
|
|
44
|
-
['según', /\bsegún\b/gi],
|
|
45
|
-
['después', /\bdespués\b/gi],
|
|
46
|
-
['puedes', /\bpuedes\b/gi],
|
|
47
|
-
['debes', /\bdebes\b/gi],
|
|
48
|
-
['tus', /\btus\b/gi],
|
|
49
|
-
['a la vez', /\ba la vez\b/gi],
|
|
50
|
-
['los datos', /\blos datos\b/gi],
|
|
51
|
-
['las opciones', /\blas opciones\b/gi],
|
|
52
|
-
['el resultado', /\bel resultado\b/gi],
|
|
53
|
-
['método de extracción', /\bmétodo de extracción\b/gi],
|
|
54
|
-
['uniformidad del molino', /\buniformidad del molino\b/gi],
|
|
55
|
-
['café recién tostado', /\bcafé recién tostado\b/gi],
|
|
56
|
-
] as const;
|
|
57
|
-
|
|
58
|
-
type UnknownRecord = Record<string, unknown>;
|
|
59
|
-
|
|
60
|
-
function normalize(value: string): string {
|
|
61
|
-
return value
|
|
62
|
-
.replace(/<[^>]*>/g, ' ')
|
|
63
|
-
.replace(/ /gi, ' ')
|
|
64
|
-
.replace(/\s+/g, ' ')
|
|
65
|
-
.trim()
|
|
66
|
-
.toLocaleLowerCase('es');
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function isTechnicalInvariant(text: string): boolean {
|
|
70
|
-
const ledUnitMatches = text.match(/\b\d+(?:-\d+)?\s*(?:w|lm)\b/g) ?? [];
|
|
71
|
-
return [
|
|
72
|
-
'data:image/svg+xml;base64',
|
|
73
|
-
'background-image: url',
|
|
74
|
-
'.layout-playground {',
|
|
75
|
-
'const samplerate =',
|
|
76
|
-
].some((pattern) => text.includes(pattern)) ||
|
|
77
|
-
(text.includes('presets') && text.includes('hz')) ||
|
|
78
|
-
(text.includes('t_rectal') && text.includes('exp(-k * t)')) ||
|
|
79
|
-
(text.includes('led') && ledUnitMatches.length >= 3);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
function collectString(value: string, output: string[]): void {
|
|
83
|
-
const text = normalize(value);
|
|
84
|
-
if (!isTechnicalInvariant(text) && text.length >= 20) output.push(text);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function collectObject(value: UnknownRecord, output: string[]): void {
|
|
88
|
-
Object.entries(value).forEach(([childKey, childValue]) => {
|
|
89
|
-
collectText(childValue, output, childKey);
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
function collectText(value: unknown, output: string[], key?: string): void {
|
|
94
|
-
if (key && STRUCTURAL_KEYS.has(key)) return;
|
|
95
|
-
if (typeof value === 'string') return collectString(value, output);
|
|
96
|
-
if (Array.isArray(value)) return value.forEach((item) => collectText(item, output));
|
|
97
|
-
if (value && typeof value === 'object') collectObject(value as UnknownRecord, output);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
async function loadText(loader: unknown): Promise<string[]> {
|
|
101
|
-
if (typeof loader !== 'function') return [];
|
|
102
|
-
const module = await (loader as () => Promise<unknown>)();
|
|
103
|
-
const output: string[] = [];
|
|
104
|
-
if (module && typeof module === 'object') {
|
|
105
|
-
const record = module as UnknownRecord;
|
|
106
|
-
for (const key of TRANSLATABLE_KEYS) {
|
|
107
|
-
collectText(record[key], output, key);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
return output;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
function findSpanishMarkers(text: string[]): string[] {
|
|
114
|
-
const corpus = text.join(' ');
|
|
115
|
-
return SPANISH_MARKERS.flatMap(([label, pattern]) =>
|
|
116
|
-
pattern.test(corpus) ? [label] : [],
|
|
117
|
-
);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
function similarity(left: string, right: string): number {
|
|
121
|
-
const leftTokens = left.split(/\s+/);
|
|
122
|
-
const rightCounts = new Map<string, number>();
|
|
123
|
-
right.split(/\s+/).forEach((token) => rightCounts.set(token, (rightCounts.get(token) ?? 0) + 1));
|
|
124
|
-
const matches = leftTokens.reduce((total, token) => {
|
|
125
|
-
const count = rightCounts.get(token) ?? 0;
|
|
126
|
-
if (count > 0) rightCounts.set(token, count - 1);
|
|
127
|
-
return total + (count > 0 ? 1 : 0);
|
|
128
|
-
}, 0);
|
|
129
|
-
return (2 * matches) / (leftTokens.length + right.split(/\s+/).length);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
function findCopiedFragments(spanish: string[], translated: string[]): string[] {
|
|
133
|
-
return spanish
|
|
134
|
-
.filter((fragment) => fragment.length >= 80)
|
|
135
|
-
.filter((fragment) => translated.some((candidate) =>
|
|
136
|
-
candidate.length >= 80 &&
|
|
137
|
-
Math.min(fragment.length, candidate.length) / Math.max(fragment.length, candidate.length) >= COPY_THRESHOLD &&
|
|
138
|
-
similarity(fragment, candidate) >= COPY_THRESHOLD,
|
|
139
|
-
))
|
|
140
|
-
.sort((a, b) => b.length - a.length)
|
|
141
|
-
.slice(0, 3);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
describe('Locales must not contain copied Spanish content', () => {
|
|
145
|
-
for (const entry of ALL_ENTRIES) {
|
|
146
|
-
it(`${entry.id} has no untranslated Spanish blocks`, async () => {
|
|
147
|
-
const spanish = await loadText(entry.i18n.es);
|
|
148
|
-
const failures: string[] = [];
|
|
149
|
-
|
|
150
|
-
for (const [locale, loader] of Object.entries(entry.i18n)) {
|
|
151
|
-
if (locale === 'es') continue;
|
|
152
|
-
|
|
153
|
-
const translated = await loadText(loader);
|
|
154
|
-
const copiedFragments = findCopiedFragments(spanish, translated);
|
|
155
|
-
const markerHits = findSpanishMarkers(translated);
|
|
156
|
-
|
|
157
|
-
if (copiedFragments.length > 0 || markerHits.length >= 2) {
|
|
158
|
-
const details = [
|
|
159
|
-
copiedFragments.length > 0
|
|
160
|
-
? `copied fragments: ${copiedFragments
|
|
161
|
-
.map((fragment) => JSON.stringify(fragment.slice(0, 120)))
|
|
162
|
-
.join(', ')}`
|
|
163
|
-
: '',
|
|
164
|
-
markerHits.length >= 2 ? `Spanish markers: ${markerHits.join(', ')}` : '',
|
|
165
|
-
]
|
|
166
|
-
.filter(Boolean)
|
|
167
|
-
.join('; ');
|
|
168
|
-
failures.push(`${locale}: ${details}`);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
expect(failures, failures.join('\n')).toEqual([]);
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
});
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { ALL_ENTRIES } from '../entries';
|
|
3
|
+
|
|
4
|
+
const STRUCTURAL_KEYS = new Set([
|
|
5
|
+
'id',
|
|
6
|
+
'slug',
|
|
7
|
+
'url',
|
|
8
|
+
'icon',
|
|
9
|
+
'image',
|
|
10
|
+
'imageUrl',
|
|
11
|
+
'keywords',
|
|
12
|
+
'category',
|
|
13
|
+
'tags',
|
|
14
|
+
'toolId',
|
|
15
|
+
'type',
|
|
16
|
+
'locale',
|
|
17
|
+
'language',
|
|
18
|
+
'direction',
|
|
19
|
+
]);
|
|
20
|
+
|
|
21
|
+
const TRANSLATABLE_KEYS = [
|
|
22
|
+
'title',
|
|
23
|
+
'description',
|
|
24
|
+
'faqTitle',
|
|
25
|
+
'faq',
|
|
26
|
+
'howTo',
|
|
27
|
+
'seo',
|
|
28
|
+
'schemas',
|
|
29
|
+
] as const;
|
|
30
|
+
|
|
31
|
+
const COPY_THRESHOLD = 0.9;
|
|
32
|
+
|
|
33
|
+
const SPANISH_MARKERS = [
|
|
34
|
+
['sangre', /\bsangre\b/gi],
|
|
35
|
+
['molino', /\bmolino\b/gi],
|
|
36
|
+
['grano', /\bgrano\b/gi],
|
|
37
|
+
['paladar', /\bpaladar\b/gi],
|
|
38
|
+
['cuchillas', /\bcuchillas\b/gi],
|
|
39
|
+
['trozos', /\btrozos\b/gi],
|
|
40
|
+
['frescura', /\bfrescura\b/gi],
|
|
41
|
+
['ingresa', /\bingresa\b/gi],
|
|
42
|
+
['selecciona', /\bselecciona\b/gi],
|
|
43
|
+
['herramienta', /\bherramienta\b/gi],
|
|
44
|
+
['según', /\bsegún\b/gi],
|
|
45
|
+
['después', /\bdespués\b/gi],
|
|
46
|
+
['puedes', /\bpuedes\b/gi],
|
|
47
|
+
['debes', /\bdebes\b/gi],
|
|
48
|
+
['tus', /\btus\b/gi],
|
|
49
|
+
['a la vez', /\ba la vez\b/gi],
|
|
50
|
+
['los datos', /\blos datos\b/gi],
|
|
51
|
+
['las opciones', /\blas opciones\b/gi],
|
|
52
|
+
['el resultado', /\bel resultado\b/gi],
|
|
53
|
+
['método de extracción', /\bmétodo de extracción\b/gi],
|
|
54
|
+
['uniformidad del molino', /\buniformidad del molino\b/gi],
|
|
55
|
+
['café recién tostado', /\bcafé recién tostado\b/gi],
|
|
56
|
+
] as const;
|
|
57
|
+
|
|
58
|
+
type UnknownRecord = Record<string, unknown>;
|
|
59
|
+
|
|
60
|
+
function normalize(value: string): string {
|
|
61
|
+
return value
|
|
62
|
+
.replace(/<[^>]*>/g, ' ')
|
|
63
|
+
.replace(/ /gi, ' ')
|
|
64
|
+
.replace(/\s+/g, ' ')
|
|
65
|
+
.trim()
|
|
66
|
+
.toLocaleLowerCase('es');
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function isTechnicalInvariant(text: string): boolean {
|
|
70
|
+
const ledUnitMatches = text.match(/\b\d+(?:-\d+)?\s*(?:w|lm)\b/g) ?? [];
|
|
71
|
+
return [
|
|
72
|
+
'data:image/svg+xml;base64',
|
|
73
|
+
'background-image: url',
|
|
74
|
+
'.layout-playground {',
|
|
75
|
+
'const samplerate =',
|
|
76
|
+
].some((pattern) => text.includes(pattern)) ||
|
|
77
|
+
(text.includes('presets') && text.includes('hz')) ||
|
|
78
|
+
(text.includes('t_rectal') && text.includes('exp(-k * t)')) ||
|
|
79
|
+
(text.includes('led') && ledUnitMatches.length >= 3);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function collectString(value: string, output: string[]): void {
|
|
83
|
+
const text = normalize(value);
|
|
84
|
+
if (!isTechnicalInvariant(text) && text.length >= 20) output.push(text);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function collectObject(value: UnknownRecord, output: string[]): void {
|
|
88
|
+
Object.entries(value).forEach(([childKey, childValue]) => {
|
|
89
|
+
collectText(childValue, output, childKey);
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function collectText(value: unknown, output: string[], key?: string): void {
|
|
94
|
+
if (key && STRUCTURAL_KEYS.has(key)) return;
|
|
95
|
+
if (typeof value === 'string') return collectString(value, output);
|
|
96
|
+
if (Array.isArray(value)) return value.forEach((item) => collectText(item, output));
|
|
97
|
+
if (value && typeof value === 'object') collectObject(value as UnknownRecord, output);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
async function loadText(loader: unknown): Promise<string[]> {
|
|
101
|
+
if (typeof loader !== 'function') return [];
|
|
102
|
+
const module = await (loader as () => Promise<unknown>)();
|
|
103
|
+
const output: string[] = [];
|
|
104
|
+
if (module && typeof module === 'object') {
|
|
105
|
+
const record = module as UnknownRecord;
|
|
106
|
+
for (const key of TRANSLATABLE_KEYS) {
|
|
107
|
+
collectText(record[key], output, key);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return output;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function findSpanishMarkers(text: string[]): string[] {
|
|
114
|
+
const corpus = text.join(' ');
|
|
115
|
+
return SPANISH_MARKERS.flatMap(([label, pattern]) =>
|
|
116
|
+
pattern.test(corpus) ? [label] : [],
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function similarity(left: string, right: string): number {
|
|
121
|
+
const leftTokens = left.split(/\s+/);
|
|
122
|
+
const rightCounts = new Map<string, number>();
|
|
123
|
+
right.split(/\s+/).forEach((token) => rightCounts.set(token, (rightCounts.get(token) ?? 0) + 1));
|
|
124
|
+
const matches = leftTokens.reduce((total, token) => {
|
|
125
|
+
const count = rightCounts.get(token) ?? 0;
|
|
126
|
+
if (count > 0) rightCounts.set(token, count - 1);
|
|
127
|
+
return total + (count > 0 ? 1 : 0);
|
|
128
|
+
}, 0);
|
|
129
|
+
return (2 * matches) / (leftTokens.length + right.split(/\s+/).length);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function findCopiedFragments(spanish: string[], translated: string[]): string[] {
|
|
133
|
+
return spanish
|
|
134
|
+
.filter((fragment) => fragment.length >= 80)
|
|
135
|
+
.filter((fragment) => translated.some((candidate) =>
|
|
136
|
+
candidate.length >= 80 &&
|
|
137
|
+
Math.min(fragment.length, candidate.length) / Math.max(fragment.length, candidate.length) >= COPY_THRESHOLD &&
|
|
138
|
+
similarity(fragment, candidate) >= COPY_THRESHOLD,
|
|
139
|
+
))
|
|
140
|
+
.sort((a, b) => b.length - a.length)
|
|
141
|
+
.slice(0, 3);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
describe('Locales must not contain copied Spanish content', () => {
|
|
145
|
+
for (const entry of ALL_ENTRIES) {
|
|
146
|
+
it(`${entry.id} has no untranslated Spanish blocks`, async () => {
|
|
147
|
+
const spanish = await loadText(entry.i18n.es);
|
|
148
|
+
const failures: string[] = [];
|
|
149
|
+
|
|
150
|
+
for (const [locale, loader] of Object.entries(entry.i18n)) {
|
|
151
|
+
if (locale === 'es') continue;
|
|
152
|
+
|
|
153
|
+
const translated = await loadText(loader);
|
|
154
|
+
const copiedFragments = findCopiedFragments(spanish, translated);
|
|
155
|
+
const markerHits = findSpanishMarkers(translated);
|
|
156
|
+
|
|
157
|
+
if (copiedFragments.length > 0 || markerHits.length >= 2) {
|
|
158
|
+
const details = [
|
|
159
|
+
copiedFragments.length > 0
|
|
160
|
+
? `copied fragments: ${copiedFragments
|
|
161
|
+
.map((fragment) => JSON.stringify(fragment.slice(0, 120)))
|
|
162
|
+
.join(', ')}`
|
|
163
|
+
: '',
|
|
164
|
+
markerHits.length >= 2 ? `Spanish markers: ${markerHits.join(', ')}` : '',
|
|
165
|
+
]
|
|
166
|
+
.filter(Boolean)
|
|
167
|
+
.join('; ');
|
|
168
|
+
failures.push(`${locale}: ${details}`);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
expect(failures, failures.join('\n')).toEqual([]);
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
});
|