@jjlmoya/utils-textiles 1.20.0 → 1.22.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.
Files changed (209) hide show
  1. package/package.json +1 -1
  2. package/src/category/i18n/de.ts +76 -76
  3. package/src/category/i18n/en.ts +76 -76
  4. package/src/category/i18n/es.ts +76 -76
  5. package/src/category/i18n/fr.ts +76 -76
  6. package/src/category/i18n/id.ts +76 -76
  7. package/src/category/i18n/it.ts +76 -76
  8. package/src/category/i18n/ja.ts +76 -76
  9. package/src/category/i18n/ko.ts +76 -76
  10. package/src/category/i18n/nl.ts +76 -76
  11. package/src/category/i18n/pl.ts +76 -76
  12. package/src/category/i18n/pt.ts +76 -76
  13. package/src/category/i18n/ru.ts +76 -76
  14. package/src/category/i18n/sv.ts +76 -76
  15. package/src/category/i18n/zh.ts +76 -76
  16. package/src/category/index.ts +2 -0
  17. package/src/category/seo.astro +1 -1
  18. package/src/components/PreviewNavSidebar.astro +1 -1
  19. package/src/components/PreviewToolbar.astro +1 -1
  20. package/src/data.ts +1 -1
  21. package/src/entries.ts +4 -1
  22. package/src/env.d.ts +1 -1
  23. package/src/index.ts +1 -1
  24. package/src/layouts/PreviewLayout.astro +113 -113
  25. package/src/pages/index.astro +1 -1
  26. package/src/tests/faq_count.test.ts +19 -19
  27. package/src/tests/i18n_coverage.test.ts +4 -2
  28. package/src/tests/locale_spelling.test.ts +44 -0
  29. package/src/tests/mocks/astro_mock.js +1 -1
  30. package/src/tests/no_en_dash.test.ts +70 -70
  31. package/src/tests/no_h1_in_components.test.ts +1 -1
  32. package/src/tests/seo_length.test.ts +22 -22
  33. package/src/tests/seo_translation_completeness.test.ts +69 -0
  34. package/src/tests/spanish_leakage.test.ts +175 -153
  35. package/src/tests/tool_validation.test.ts +17 -17
  36. package/src/tool/burnTest/i18n/es.ts +211 -211
  37. package/src/tool/burnTest/i18n/fr.ts +211 -211
  38. package/src/tool/burnTest/i18n/ja.ts +211 -211
  39. package/src/tool/burnTest/i18n/ko.ts +211 -211
  40. package/src/tool/burnTest/i18n/pl.ts +211 -211
  41. package/src/tool/burnTest/i18n/ru.ts +211 -211
  42. package/src/tool/burnTest/i18n/sv.ts +211 -211
  43. package/src/tool/burnTest/i18n/zh.ts +211 -211
  44. package/src/tool/burnTest/seo.astro +15 -15
  45. package/src/tool/clothingSizeConverter/i18n/de.ts +348 -348
  46. package/src/tool/clothingSizeConverter/i18n/en.ts +348 -348
  47. package/src/tool/clothingSizeConverter/i18n/fr.ts +348 -348
  48. package/src/tool/clothingSizeConverter/i18n/ja.ts +348 -348
  49. package/src/tool/clothingSizeConverter/i18n/ko.ts +348 -348
  50. package/src/tool/clothingSizeConverter/i18n/nl.ts +348 -348
  51. package/src/tool/clothingSizeConverter/i18n/pl.ts +348 -348
  52. package/src/tool/clothingSizeConverter/i18n/ru.ts +348 -348
  53. package/src/tool/clothingSizeConverter/i18n/sv.ts +348 -348
  54. package/src/tool/clothingSizeConverter/i18n/tr.ts +348 -348
  55. package/src/tool/clothingSizeConverter/i18n/zh.ts +348 -348
  56. package/src/tool/clothingSizeConverter/seo.astro +15 -15
  57. package/src/tool/embroideryStitchPricingEstimator/bibliography.astro +6 -0
  58. package/src/tool/embroideryStitchPricingEstimator/bibliography.ts +12 -0
  59. package/src/tool/embroideryStitchPricingEstimator/component.astro +111 -0
  60. package/src/tool/embroideryStitchPricingEstimator/controller.ts +111 -0
  61. package/src/tool/embroideryStitchPricingEstimator/dom-views.ts +94 -0
  62. package/src/tool/embroideryStitchPricingEstimator/embroidery-stitch-count-pricing-estimator.css +438 -0
  63. package/src/tool/embroideryStitchPricingEstimator/entry.ts +29 -0
  64. package/src/tool/embroideryStitchPricingEstimator/evaluator.ts +22 -0
  65. package/src/tool/embroideryStitchPricingEstimator/i18n/de.ts +38 -0
  66. package/src/tool/embroideryStitchPricingEstimator/i18n/en.ts +194 -0
  67. package/src/tool/embroideryStitchPricingEstimator/i18n/es.ts +38 -0
  68. package/src/tool/embroideryStitchPricingEstimator/i18n/fr.ts +38 -0
  69. package/src/tool/embroideryStitchPricingEstimator/i18n/id.ts +38 -0
  70. package/src/tool/embroideryStitchPricingEstimator/i18n/it.ts +38 -0
  71. package/src/tool/embroideryStitchPricingEstimator/i18n/ja.ts +38 -0
  72. package/src/tool/embroideryStitchPricingEstimator/i18n/ko.ts +38 -0
  73. package/src/tool/embroideryStitchPricingEstimator/i18n/nl.ts +38 -0
  74. package/src/tool/embroideryStitchPricingEstimator/i18n/pl.ts +38 -0
  75. package/src/tool/embroideryStitchPricingEstimator/i18n/pt.ts +38 -0
  76. package/src/tool/embroideryStitchPricingEstimator/i18n/ru.ts +38 -0
  77. package/src/tool/embroideryStitchPricingEstimator/i18n/sv.ts +38 -0
  78. package/src/tool/embroideryStitchPricingEstimator/i18n/tr.ts +38 -0
  79. package/src/tool/embroideryStitchPricingEstimator/i18n/zh.ts +38 -0
  80. package/src/tool/embroideryStitchPricingEstimator/index.ts +11 -0
  81. package/src/tool/embroideryStitchPricingEstimator/logic.test.ts +40 -0
  82. package/src/tool/embroideryStitchPricingEstimator/logic.ts +86 -0
  83. package/src/tool/embroideryStitchPricingEstimator/seo.astro +15 -0
  84. package/src/tool/embroideryStitchPricingEstimator/storage.ts +20 -0
  85. package/src/tool/embroideryStitchPricingEstimator/ui.ts +53 -0
  86. package/src/tool/fabricProjectCalculator/i18n/de.ts +236 -236
  87. package/src/tool/fabricProjectCalculator/i18n/ja.ts +236 -236
  88. package/src/tool/fabricProjectCalculator/i18n/ko.ts +236 -236
  89. package/src/tool/fabricProjectCalculator/i18n/nl.ts +236 -236
  90. package/src/tool/fabricProjectCalculator/i18n/pl.ts +236 -236
  91. package/src/tool/fabricProjectCalculator/i18n/ru.ts +236 -236
  92. package/src/tool/fabricProjectCalculator/i18n/sv.ts +236 -236
  93. package/src/tool/fabricProjectCalculator/i18n/tr.ts +236 -236
  94. package/src/tool/fabricProjectCalculator/i18n/zh.ts +236 -236
  95. package/src/tool/fabricProjectCalculator/seo.astro +15 -15
  96. package/src/tool/fabricTruth/i18n/de.ts +268 -268
  97. package/src/tool/fabricTruth/i18n/en.ts +268 -268
  98. package/src/tool/fabricTruth/i18n/es.ts +302 -302
  99. package/src/tool/fabricTruth/i18n/fr.ts +268 -268
  100. package/src/tool/fabricTruth/i18n/id.ts +268 -268
  101. package/src/tool/fabricTruth/i18n/it.ts +268 -268
  102. package/src/tool/fabricTruth/i18n/ja.ts +268 -268
  103. package/src/tool/fabricTruth/i18n/ko.ts +268 -268
  104. package/src/tool/fabricTruth/i18n/nl.ts +268 -268
  105. package/src/tool/fabricTruth/i18n/pl.ts +268 -268
  106. package/src/tool/fabricTruth/i18n/pt.ts +268 -268
  107. package/src/tool/fabricTruth/i18n/ru.ts +268 -268
  108. package/src/tool/fabricTruth/i18n/sv.ts +268 -268
  109. package/src/tool/fabricTruth/i18n/tr.ts +268 -268
  110. package/src/tool/fabricTruth/i18n/zh.ts +272 -272
  111. package/src/tool/fabricTruth/seo.astro +15 -15
  112. package/src/tool/fiberPrep/i18n/de.ts +215 -215
  113. package/src/tool/fiberPrep/i18n/fr.ts +215 -215
  114. package/src/tool/fiberPrep/i18n/ja.ts +215 -215
  115. package/src/tool/fiberPrep/i18n/ko.ts +215 -215
  116. package/src/tool/fiberPrep/i18n/nl.ts +215 -215
  117. package/src/tool/fiberPrep/i18n/pl.ts +215 -215
  118. package/src/tool/fiberPrep/i18n/ru.ts +215 -215
  119. package/src/tool/fiberPrep/i18n/sv.ts +215 -215
  120. package/src/tool/fiberPrep/i18n/tr.ts +215 -215
  121. package/src/tool/fiberPrep/i18n/zh.ts +215 -215
  122. package/src/tool/fiberPrep/seo.astro +15 -15
  123. package/src/tool/knittingGauge/i18n/de.ts +224 -224
  124. package/src/tool/knittingGauge/i18n/ja.ts +224 -224
  125. package/src/tool/knittingGauge/i18n/ko.ts +224 -224
  126. package/src/tool/knittingGauge/i18n/pl.ts +224 -224
  127. package/src/tool/knittingGauge/i18n/ru.ts +224 -224
  128. package/src/tool/knittingGauge/i18n/tr.ts +224 -224
  129. package/src/tool/knittingGauge/i18n/zh.ts +224 -224
  130. package/src/tool/knittingGauge/seo.astro +15 -15
  131. package/src/tool/laundryGuide/i18n/de.ts +271 -271
  132. package/src/tool/laundryGuide/i18n/en.ts +271 -271
  133. package/src/tool/laundryGuide/i18n/es.ts +271 -271
  134. package/src/tool/laundryGuide/i18n/fr.ts +255 -255
  135. package/src/tool/laundryGuide/i18n/id.ts +271 -271
  136. package/src/tool/laundryGuide/i18n/it.ts +271 -271
  137. package/src/tool/laundryGuide/i18n/ja.ts +271 -271
  138. package/src/tool/laundryGuide/i18n/ko.ts +271 -271
  139. package/src/tool/laundryGuide/i18n/nl.ts +271 -271
  140. package/src/tool/laundryGuide/i18n/pl.ts +271 -271
  141. package/src/tool/laundryGuide/i18n/pt.ts +271 -271
  142. package/src/tool/laundryGuide/i18n/ru.ts +271 -271
  143. package/src/tool/laundryGuide/i18n/sv.ts +271 -271
  144. package/src/tool/laundryGuide/i18n/tr.ts +271 -271
  145. package/src/tool/laundryGuide/i18n/zh.ts +271 -271
  146. package/src/tool/laundryGuide/seo.astro +15 -15
  147. package/src/tool/needleConverter/i18n/de.ts +202 -202
  148. package/src/tool/needleConverter/i18n/es.ts +207 -207
  149. package/src/tool/needleConverter/i18n/fr.ts +207 -207
  150. package/src/tool/needleConverter/i18n/ja.ts +202 -202
  151. package/src/tool/needleConverter/i18n/ko.ts +202 -202
  152. package/src/tool/needleConverter/i18n/nl.ts +202 -202
  153. package/src/tool/needleConverter/i18n/pl.ts +202 -202
  154. package/src/tool/needleConverter/i18n/ru.ts +202 -202
  155. package/src/tool/needleConverter/i18n/sv.ts +202 -202
  156. package/src/tool/needleConverter/i18n/tr.ts +202 -202
  157. package/src/tool/needleConverter/i18n/zh.ts +202 -202
  158. package/src/tool/needleConverter/seo.astro +15 -15
  159. package/src/tool/sewingPatternScaler/component.astro +236 -236
  160. package/src/tool/sewingPatternScaler/i18n/fr.ts +170 -170
  161. package/src/tool/sewingPatternScaler/i18n/ja.ts +114 -114
  162. package/src/tool/sewingPatternScaler/i18n/ko.ts +114 -114
  163. package/src/tool/sewingPatternScaler/i18n/nl.ts +114 -114
  164. package/src/tool/sewingPatternScaler/i18n/pl.ts +114 -114
  165. package/src/tool/sewingPatternScaler/i18n/ru.ts +114 -114
  166. package/src/tool/sewingPatternScaler/i18n/sv.ts +114 -114
  167. package/src/tool/sewingPatternScaler/i18n/tr.ts +114 -114
  168. package/src/tool/sewingPatternScaler/i18n/zh.ts +114 -114
  169. package/src/tool/sewingPatternScaler/seo.astro +15 -15
  170. package/src/tool/shoeSizeConverter/i18n/fr.ts +183 -183
  171. package/src/tool/shoeSizeConverter/i18n/ja.ts +179 -179
  172. package/src/tool/shoeSizeConverter/i18n/ko.ts +179 -179
  173. package/src/tool/shoeSizeConverter/i18n/nl.ts +179 -179
  174. package/src/tool/shoeSizeConverter/i18n/pl.ts +179 -179
  175. package/src/tool/shoeSizeConverter/i18n/ru.ts +179 -179
  176. package/src/tool/shoeSizeConverter/i18n/sv.ts +179 -179
  177. package/src/tool/shoeSizeConverter/i18n/tr.ts +179 -179
  178. package/src/tool/shoeSizeConverter/i18n/zh.ts +179 -179
  179. package/src/tool/shoeSizeConverter/seo.astro +15 -15
  180. package/src/tool/stainChemistry/bibliography.ts +16 -16
  181. package/src/tool/stainChemistry/i18n/de.ts +286 -286
  182. package/src/tool/stainChemistry/i18n/en.ts +289 -289
  183. package/src/tool/stainChemistry/i18n/es.ts +286 -286
  184. package/src/tool/stainChemistry/i18n/fr.ts +296 -296
  185. package/src/tool/stainChemistry/i18n/id.ts +286 -286
  186. package/src/tool/stainChemistry/i18n/it.ts +286 -286
  187. package/src/tool/stainChemistry/i18n/ja.ts +286 -286
  188. package/src/tool/stainChemistry/i18n/ko.ts +283 -283
  189. package/src/tool/stainChemistry/i18n/nl.ts +286 -286
  190. package/src/tool/stainChemistry/i18n/pl.ts +286 -286
  191. package/src/tool/stainChemistry/i18n/pt.ts +286 -286
  192. package/src/tool/stainChemistry/i18n/ru.ts +286 -286
  193. package/src/tool/stainChemistry/i18n/sv.ts +286 -286
  194. package/src/tool/stainChemistry/i18n/tr.ts +286 -286
  195. package/src/tool/stainChemistry/i18n/zh.ts +281 -281
  196. package/src/tool/stainChemistry/seo.astro +15 -15
  197. package/src/tool/yarnCalculator/i18n/de.ts +296 -296
  198. package/src/tool/yarnCalculator/i18n/es.ts +296 -296
  199. package/src/tool/yarnCalculator/i18n/fr.ts +296 -296
  200. package/src/tool/yarnCalculator/i18n/ja.ts +296 -296
  201. package/src/tool/yarnCalculator/i18n/ko.ts +296 -296
  202. package/src/tool/yarnCalculator/i18n/nl.ts +296 -296
  203. package/src/tool/yarnCalculator/i18n/pl.ts +296 -296
  204. package/src/tool/yarnCalculator/i18n/ru.ts +296 -296
  205. package/src/tool/yarnCalculator/i18n/sv.ts +296 -296
  206. package/src/tool/yarnCalculator/i18n/tr.ts +296 -296
  207. package/src/tool/yarnCalculator/i18n/zh.ts +295 -295
  208. package/src/tool/yarnCalculator/seo.astro +15 -15
  209. package/src/tools.ts +2 -2
@@ -1,153 +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 SPANISH_MARKERS = [
32
- ['sangre', /\bsangre\b/gi],
33
- ['molino', /\bmolino\b/gi],
34
- ['grano', /\bgrano\b/gi],
35
- ['paladar', /\bpaladar\b/gi],
36
- ['cuchillas', /\bcuchillas\b/gi],
37
- ['trozos', /\btrozos\b/gi],
38
- ['frescura', /\bfrescura\b/gi],
39
- ['ingresa', /\bingresa\b/gi],
40
- ['selecciona', /\bselecciona\b/gi],
41
- ['herramienta', /\bherramienta\b/gi],
42
- ['según', /\bsegún\b/gi],
43
- ['después', /\bdespués\b/gi],
44
- ['puedes', /\bpuedes\b/gi],
45
- ['debes', /\bdebes\b/gi],
46
- ['tus', /\btus\b/gi],
47
- ['a la vez', /\ba la vez\b/gi],
48
- ['los datos', /\blos datos\b/gi],
49
- ['las opciones', /\blas opciones\b/gi],
50
- ['el resultado', /\bel resultado\b/gi],
51
- ['método de extracción', /\bmétodo de extracción\b/gi],
52
- ['uniformidad del molino', /\buniformidad del molino\b/gi],
53
- ['café recién tostado', /\bcafé recién tostado\b/gi],
54
- ] as const;
55
-
56
- type UnknownRecord = Record<string, unknown>;
57
-
58
- function normalize(value: string): string {
59
- return value
60
- .replace(/<[^>]*>/g, ' ')
61
- .replace(/&nbsp;/gi, ' ')
62
- .replace(/\s+/g, ' ')
63
- .trim()
64
- .toLocaleLowerCase('es');
65
- }
66
-
67
- function isTechnicalInvariant(text: string): boolean {
68
- return [
69
- 'data:image/svg+xml;base64',
70
- 'background-image: url',
71
- '.layout-playground {',
72
- 'const samplerate =',
73
- ].some((pattern) => text.includes(pattern)) || (text.includes('presets') && text.includes('hz'));
74
- }
75
-
76
- function collectString(value: string, output: string[]): void {
77
- const text = normalize(value);
78
- if (!isTechnicalInvariant(text) && text.length >= 20) output.push(text);
79
- }
80
-
81
- function collectObject(value: UnknownRecord, output: string[]): void {
82
- Object.entries(value).forEach(([childKey, childValue]) => {
83
- collectText(childValue, output, childKey);
84
- });
85
- }
86
-
87
- function collectText(value: unknown, output: string[], key?: string): void {
88
- if (key && STRUCTURAL_KEYS.has(key)) return;
89
- if (typeof value === 'string') return collectString(value, output);
90
- if (Array.isArray(value)) return value.forEach((item) => collectText(item, output));
91
- if (value && typeof value === 'object') collectObject(value as UnknownRecord, output);
92
- }
93
-
94
- async function loadText(loader: unknown): Promise<string[]> {
95
- if (typeof loader !== 'function') return [];
96
- const module = await (loader as () => Promise<unknown>)();
97
- const output: string[] = [];
98
- if (module && typeof module === 'object') {
99
- const record = module as UnknownRecord;
100
- for (const key of TRANSLATABLE_KEYS) {
101
- collectText(record[key], output, key);
102
- }
103
- }
104
- return output;
105
- }
106
-
107
- function findSpanishMarkers(text: string[]): string[] {
108
- const corpus = text.join(' ');
109
- return SPANISH_MARKERS.flatMap(([label, pattern]) =>
110
- pattern.test(corpus) ? [label] : [],
111
- );
112
- }
113
-
114
- function findCopiedFragments(spanish: string[], translated: string[]): string[] {
115
- const corpus = translated.join(' ');
116
- return spanish
117
- .filter((fragment) => fragment.length >= 80 && corpus.includes(fragment))
118
- .sort((a, b) => b.length - a.length)
119
- .slice(0, 3);
120
- }
121
-
122
- describe('Locales must not contain copied Spanish content', () => {
123
- for (const entry of ALL_ENTRIES) {
124
- it(`${entry.id} has no untranslated Spanish blocks`, async () => {
125
- const spanish = await loadText(entry.i18n.es);
126
- const failures: string[] = [];
127
-
128
- for (const [locale, loader] of Object.entries(entry.i18n)) {
129
- if (locale === 'es') continue;
130
-
131
- const translated = await loadText(loader);
132
- const copiedFragments = findCopiedFragments(spanish, translated);
133
- const markerHits = findSpanishMarkers(translated);
134
-
135
- if (copiedFragments.length > 0 || markerHits.length >= 2) {
136
- const details = [
137
- copiedFragments.length > 0
138
- ? `copied fragments: ${copiedFragments
139
- .map((fragment) => JSON.stringify(fragment.slice(0, 120)))
140
- .join(', ')}`
141
- : '',
142
- markerHits.length >= 2 ? `Spanish markers: ${markerHits.join(', ')}` : '',
143
- ]
144
- .filter(Boolean)
145
- .join('; ');
146
- failures.push(`${locale}: ${details}`);
147
- }
148
- }
149
-
150
- expect(failures, failures.join('\n')).toEqual([]);
151
- });
152
- }
153
- });
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(/&nbsp;/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,17 +1,17 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { ALL_TOOLS } from '../tools';
3
- import { textilesCategory } from '../data';
4
-
5
- describe('Tool Validation Suite', () => {
6
- describe('Library Registration', () => {
7
- it('should have 9 tools in ALL_TOOLS', () => {
8
- expect(ALL_TOOLS.length).toBe(12);
9
- });
10
-
11
- it('textilesCategory should be defined', () => {
12
- expect(textilesCategory).toBeDefined();
13
- expect(textilesCategory.i18n).toBeDefined();
14
- });
15
- });
16
- });
17
-
1
+ import { describe, it, expect } from 'vitest';
2
+ import { ALL_TOOLS } from '../tools';
3
+ import { textilesCategory } from '../data';
4
+
5
+ describe('Tool Validation Suite', () => {
6
+ describe('Library Registration', () => {
7
+ it('should have 13 tools in ALL_TOOLS', () => {
8
+ expect(ALL_TOOLS.length).toBe(13);
9
+ });
10
+
11
+ it('textilesCategory should be defined', () => {
12
+ expect(textilesCategory).toBeDefined();
13
+ expect(textilesCategory.i18n).toBeDefined();
14
+ });
15
+ });
16
+ });
17
+