@jjlmoya/utils-creative 1.27.0 → 1.28.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
CHANGED
|
@@ -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 ? 240 : Math.max(600, 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
|
-
|