@jjlmoya/utils-nature 1.13.0 → 1.15.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 (84) hide show
  1. package/package.json +1 -1
  2. package/src/category/i18n/fr.ts +6 -6
  3. package/src/category/i18n/ru.ts +5 -5
  4. package/src/layouts/PreviewLayout.astro +1 -1
  5. package/src/pages/[locale]/[slug].astro +32 -14
  6. package/src/tests/diacritics_density.test.ts +118 -0
  7. package/src/tests/inverted_punctuation.test.ts +84 -0
  8. package/src/tests/locale_completeness.test.ts +1 -31
  9. package/src/tests/no_en_dash.test.ts +71 -0
  10. package/src/tests/script_density.test.ts +94 -0
  11. package/src/tests/shared-test-helpers.ts +56 -0
  12. package/src/tests/tool_exports.test.ts +34 -0
  13. package/src/tool/cricketThermometer/bibliography.ts +12 -0
  14. package/src/tool/cricketThermometer/i18n/de.ts +6 -18
  15. package/src/tool/cricketThermometer/i18n/en.ts +3 -15
  16. package/src/tool/cricketThermometer/i18n/es.ts +3 -15
  17. package/src/tool/cricketThermometer/i18n/fr.ts +9 -21
  18. package/src/tool/cricketThermometer/i18n/id.ts +3 -15
  19. package/src/tool/cricketThermometer/i18n/it.ts +3 -15
  20. package/src/tool/cricketThermometer/i18n/ja.ts +3 -15
  21. package/src/tool/cricketThermometer/i18n/ko.ts +3 -15
  22. package/src/tool/cricketThermometer/i18n/nl.ts +3 -15
  23. package/src/tool/cricketThermometer/i18n/pl.ts +6 -18
  24. package/src/tool/cricketThermometer/i18n/pt.ts +3 -15
  25. package/src/tool/cricketThermometer/i18n/ru.ts +8 -20
  26. package/src/tool/cricketThermometer/i18n/sv.ts +3 -15
  27. package/src/tool/cricketThermometer/i18n/tr.ts +3 -15
  28. package/src/tool/cricketThermometer/i18n/zh.ts +8 -20
  29. package/src/tool/cricketThermometer/seo.astro +1 -1
  30. package/src/tool/cricketThermometer/ui.ts +0 -2
  31. package/src/tool/digitalCarbon/bibliography.ts +8 -0
  32. package/src/tool/digitalCarbon/digital-carbon-footprint-calculator.css +57 -1
  33. package/src/tool/digitalCarbon/i18n/de.ts +4 -10
  34. package/src/tool/digitalCarbon/i18n/en.ts +2 -8
  35. package/src/tool/digitalCarbon/i18n/es.ts +2 -8
  36. package/src/tool/digitalCarbon/i18n/fr.ts +6 -12
  37. package/src/tool/digitalCarbon/i18n/id.ts +2 -8
  38. package/src/tool/digitalCarbon/i18n/it.ts +2 -8
  39. package/src/tool/digitalCarbon/i18n/ja.ts +2 -8
  40. package/src/tool/digitalCarbon/i18n/ko.ts +2 -8
  41. package/src/tool/digitalCarbon/i18n/nl.ts +2 -8
  42. package/src/tool/digitalCarbon/i18n/pl.ts +2 -8
  43. package/src/tool/digitalCarbon/i18n/pt.ts +2 -8
  44. package/src/tool/digitalCarbon/i18n/ru.ts +3 -9
  45. package/src/tool/digitalCarbon/i18n/sv.ts +2 -8
  46. package/src/tool/digitalCarbon/i18n/tr.ts +2 -8
  47. package/src/tool/digitalCarbon/i18n/zh.ts +2 -8
  48. package/src/tool/digitalCarbon/seo.astro +1 -1
  49. package/src/tool/rainHarvester/bibliography.ts +20 -0
  50. package/src/tool/rainHarvester/i18n/de.ts +5 -23
  51. package/src/tool/rainHarvester/i18n/en.ts +2 -20
  52. package/src/tool/rainHarvester/i18n/es.ts +2 -20
  53. package/src/tool/rainHarvester/i18n/fr.ts +3 -21
  54. package/src/tool/rainHarvester/i18n/id.ts +2 -20
  55. package/src/tool/rainHarvester/i18n/it.ts +2 -20
  56. package/src/tool/rainHarvester/i18n/ja.ts +2 -20
  57. package/src/tool/rainHarvester/i18n/ko.ts +2 -20
  58. package/src/tool/rainHarvester/i18n/nl.ts +2 -20
  59. package/src/tool/rainHarvester/i18n/pl.ts +5 -23
  60. package/src/tool/rainHarvester/i18n/pt.ts +2 -20
  61. package/src/tool/rainHarvester/i18n/ru.ts +8 -26
  62. package/src/tool/rainHarvester/i18n/sv.ts +2 -20
  63. package/src/tool/rainHarvester/i18n/tr.ts +2 -20
  64. package/src/tool/rainHarvester/i18n/zh.ts +5 -23
  65. package/src/tool/rainHarvester/seo.astro +1 -1
  66. package/src/tool/seedCalculator/bibliography.ts +16 -0
  67. package/src/tool/seedCalculator/i18n/de.ts +2 -18
  68. package/src/tool/seedCalculator/i18n/en.ts +2 -18
  69. package/src/tool/seedCalculator/i18n/es.ts +2 -18
  70. package/src/tool/seedCalculator/i18n/fr.ts +3 -19
  71. package/src/tool/seedCalculator/i18n/id.ts +2 -18
  72. package/src/tool/seedCalculator/i18n/it.ts +2 -18
  73. package/src/tool/seedCalculator/i18n/ja.ts +2 -18
  74. package/src/tool/seedCalculator/i18n/ko.ts +2 -18
  75. package/src/tool/seedCalculator/i18n/nl.ts +2 -18
  76. package/src/tool/seedCalculator/i18n/pl.ts +3 -19
  77. package/src/tool/seedCalculator/i18n/pt.ts +2 -18
  78. package/src/tool/seedCalculator/i18n/ru.ts +6 -22
  79. package/src/tool/seedCalculator/i18n/sv.ts +2 -18
  80. package/src/tool/seedCalculator/i18n/tr.ts +2 -18
  81. package/src/tool/seedCalculator/i18n/zh.ts +2 -18
  82. package/src/tool/seedCalculator/seo.astro +8 -2
  83. package/src/tool/seedCalculator/ui.ts +0 -2
  84. package/src/types.ts +0 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jjlmoya/utils-nature",
3
- "version": "1.13.0",
3
+ "version": "1.15.0",
4
4
  "type": "module",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
@@ -8,7 +8,7 @@ export const content: CategoryLocaleContent = {
8
8
  seo: [
9
9
  {
10
10
  type: 'title',
11
- text: 'Ingénierie Biologique et Durabilité : Données pour la Planète',
11
+ text: 'Ingénierie Biologique et Durabilité: Données pour la Planète',
12
12
  level: 2,
13
13
  },
14
14
  {
@@ -21,7 +21,7 @@ export const content: CategoryLocaleContent = {
21
21
  },
22
22
  {
23
23
  type: 'title',
24
- text: 'Agriculture de Précision : Étalonnage des Semis et Culture',
24
+ text: 'Agriculture de Précision: Étalonnage des Semis et Culture',
25
25
  level: 2,
26
26
  },
27
27
  {
@@ -30,7 +30,7 @@ export const content: CategoryLocaleContent = {
30
30
  },
31
31
  {
32
32
  type: 'title',
33
- text: 'Gestion des Ressources en Eau : Récupération d\'Eau de Pluie',
33
+ text: 'Gestion des Ressources en Eau: Récupération d\'Eau de Pluie',
34
34
  level: 2,
35
35
  },
36
36
  {
@@ -48,7 +48,7 @@ export const content: CategoryLocaleContent = {
48
48
  },
49
49
  {
50
50
  type: 'title',
51
- text: 'Durabilité Numérique : Empreinte Carbone Web',
51
+ text: 'Durabilité Numérique: Empreinte Carbone Web',
52
52
  level: 2,
53
53
  },
54
54
  {
@@ -71,7 +71,7 @@ export const content: CategoryLocaleContent = {
71
71
  },
72
72
  {
73
73
  type: 'title',
74
- text: 'Rotation des Cultures et Biodiversité : La Science Agricole Millénaire',
74
+ text: 'Rotation des Cultures et Biodiversité: La Science Agricole Millénaire',
75
75
  level: 2,
76
76
  },
77
77
  {
@@ -80,7 +80,7 @@ export const content: CategoryLocaleContent = {
80
80
  },
81
81
  {
82
82
  type: 'title',
83
- text: 'Conservation du Sol et des Nutriments : Analyse Pédologique',
83
+ text: 'Conservation du Sol et des Nutriments: Analyse Pédologique',
84
84
  level: 2,
85
85
  },
86
86
  {
@@ -13,7 +13,7 @@ export const content: CategoryLocaleContent = {
13
13
  },
14
14
  {
15
15
  type: 'paragraph',
16
- html: 'Связь с природой в 2026 году опосредована более глубоким техническим пониманием наших ресурсов. В этом разделе мы предлагаем <strong>бесплатные онлайн-инструменты</strong>, разработанные для оптимизации сельскохозяйственного производства в малом и крупном масштабе, управления жизненно важными водными ресурсами и измерения нашего невидимого воздействия на глобальную экосистему. <strong>Точное земледелие</strong> и устойчивое развитие это не просто концепции, а действия, основанные на точных расчётах.',
16
+ html: 'Связь с природой в 2026 году опосредована более глубоким техническим пониманием наших ресурсов. В этом разделе мы предлагаем <strong>бесплатные онлайн-инструменты</strong>, разработанные для оптимизации сельскохозяйственного производства в малом и крупном масштабе, управления жизненно важными водными ресурсами и измерения нашего невидимого воздействия на глобальную экосистему. <strong>Точное земледелие</strong> и устойчивое развитие - это не просто концепции, а действия, основанные на точных расчётах.',
17
17
  },
18
18
  {
19
19
  type: 'paragraph',
@@ -35,7 +35,7 @@ export const content: CategoryLocaleContent = {
35
35
  },
36
36
  {
37
37
  type: 'paragraph',
38
- html: 'Вода конечный ресурс. <strong>Коллектор дождевой воды</strong> рассчитывает, сколько литров воды вы можете собрать ежегодно, исходя из площади вашей кровли и истории осадков в вашем регионе. Этот инструмент жизненно важен для расчёта объёма накопительных баков и внедрения дополнительных систем полива для городских садов и сельских ферм.',
38
+ html: 'Вода - конечный ресурс. <strong>Коллектор дождевой воды</strong> рассчитывает, сколько литров воды вы можете собрать ежегодно, исходя из площади вашей кровли и истории осадков в вашем регионе. Этот инструмент жизненно важен для расчёта объёма накопительных баков и внедрения дополнительных систем полива для городских садов и сельских ферм.',
39
39
  },
40
40
  {
41
41
  type: 'title',
@@ -76,7 +76,7 @@ export const content: CategoryLocaleContent = {
76
76
  },
77
77
  {
78
78
  type: 'paragraph',
79
- html: 'Севооборот не средневековая традиция; это физиология растений. Разные культуры потребляют разные почвенные питательные вещества и создают разный бактериальный состав в ризосфере. Пшеница истощает азот; люцерна его фиксирует. Кукуруза требует много калия; овёс оставляет его доступным. Разумный севооборот (пшеница-люцерна-кукуруза-бобовые) восстанавливает природное плодородие без дорогих синтетических удобрений.',
79
+ html: 'Севооборот - не средневековая традиция; это физиология растений. Разные культуры потребляют разные почвенные питательные вещества и создают разный бактериальный состав в ризосфере. Пшеница истощает азот; люцерна его фиксирует. Кукуруза требует много калия; овёс оставляет его доступным. Разумный севооборот (пшеница-люцерна-кукуруза-бобовые) восстанавливает природное плодородие без дорогих синтетических удобрений.',
80
80
  },
81
81
  {
82
82
  type: 'title',
@@ -85,7 +85,7 @@ export const content: CategoryLocaleContent = {
85
85
  },
86
86
  {
87
87
  type: 'paragraph',
88
- html: 'Почва живая. Она содержит триллионы микробов, грибков и организмов, создающих структуру и плодородие. Эрозия от чрезмерной вспашки разрушает эту структуру; уплотнённая почва не впитывает воду; низкое содержание органического вещества снижает водоудерживающую способность. Анализ почвы (pH, питательные вещества, органическое вещество, текстура) это диагностика перед любым вмешательством.',
88
+ html: 'Почва живая. Она содержит триллионы микробов, грибков и организмов, создающих структуру и плодородие. Эрозия от чрезмерной вспашки разрушает эту структуру; уплотнённая почва не впитывает воду; низкое содержание органического вещества снижает водоудерживающую способность. Анализ почвы (pH, питательные вещества, органическое вещество, текстура) - это диагностика перед любым вмешательством.',
89
89
  },
90
90
  {
91
91
  type: 'title',
@@ -94,7 +94,7 @@ export const content: CategoryLocaleContent = {
94
94
  },
95
95
  {
96
96
  type: 'paragraph',
97
- html: 'Тренд 2026 года это <strong>Интернет естественных вещей (IoNT)</strong>. Датчики влажности, дроны мониторинга и программное обеспечение для управления средой демократизируют регенеративное земледелие. Эти инструменты дают вам возможность управлять своей средой не как ресурсом для эксплуатации, а как экосистемой, которую необходимо питать и защищать с помощью технического интеллекта.',
97
+ html: 'Тренд 2026 года - это <strong>Интернет естественных вещей (IoNT)</strong>. Датчики влажности, дроны мониторинга и программное обеспечение для управления средой демократизируют регенеративное земледелие. Эти инструменты дают вам возможность управлять своей средой не как ресурсом для эксплуатации, а как экосистемой, которую необходимо питать и защищать с помощью технического интеллекта.',
98
98
  },
99
99
  {
100
100
  type: 'stats',
@@ -78,7 +78,7 @@ const { title, currentLocale = "es", localeUrls = {}, hasSidebar = false } = Ast
78
78
  transition:
79
79
  background-color 0.3s ease,
80
80
  color 0.3s ease;
81
- }
81
+ font-family: Inter, sans-serif;}
82
82
 
83
83
  main {
84
84
  padding: 0 2rem;
@@ -34,18 +34,28 @@ export async function getStaticPaths() {
34
34
  ]),
35
35
  ) as Partial<Record<KnownLocale, string>>;
36
36
 
37
+ const firstLoader = entry.i18n.en ?? Object.values(entry.i18n)[0];
38
+ const englishSlug = firstLoader ? (await firstLoader()).slug : entry.id;
39
+
37
40
  for (const { locale, content } of localeContents) {
38
- const allToolsNav = await Promise.all(
39
- ALL_TOOLS.map(async ({ entry: navEntry }) => ({
40
- id: navEntry.id,
41
- title: (await navEntry.i18n[locale]!()).title,
42
- href: `/${locale}/${(await navEntry.i18n[locale]!()).slug}`,
43
- isActive: navEntry.id === entry.id,
44
- })),
45
- );
41
+ const allToolsNav = (
42
+ await Promise.all(
43
+ ALL_TOOLS.map(async ({ entry: navEntry }) => {
44
+ const loader = navEntry.i18n[locale] ?? navEntry.i18n.en;
45
+ if (!loader) return null;
46
+ const navContent = await loader();
47
+ return {
48
+ id: navEntry.id,
49
+ title: navContent.title,
50
+ href: `/${locale}/${navContent.slug}`,
51
+ isActive: navEntry.id === entry.id,
52
+ };
53
+ }),
54
+ )
55
+ ).filter(Boolean) as NavItem[];
46
56
  paths.push({
47
57
  params: { locale, slug: content.slug },
48
- props: { Component, locale, content, localeUrls, allToolsNav },
58
+ props: { Component, locale, content, localeUrls, allToolsNav, englishSlug },
49
59
  });
50
60
  }
51
61
  }
@@ -66,11 +76,16 @@ interface Props {
66
76
  content: ToolLocaleContent;
67
77
  localeUrls: Partial<Record<KnownLocale, string>>;
68
78
  allToolsNav: NavItem[];
79
+ englishSlug: string;
69
80
  }
70
81
 
71
- const { Component, locale, content, localeUrls, allToolsNav } = Astro.props;
82
+ const { Component, locale, content, localeUrls, allToolsNav, englishSlug } = Astro.props;
83
+
84
+ const cssFiles = import.meta.glob("../../tool/**/*.css", { query: "?raw", import: "default" });
85
+ const cssKey = Object.keys(cssFiles).find((k) => k.endsWith(`/${englishSlug}.css`));
86
+ const toolCss = cssKey ? await cssFiles[cssKey]() as string : "";
72
87
 
73
- const seoContent: UtilitySEOContent = { locale, sections: content.seo };
88
+ const seoContent: UtilitySEOContent = { locale, sections: content.seo ?? [] };
74
89
 
75
90
  const words = content.title.split(" ");
76
91
  const titleHighlight = words[0] || "";
@@ -89,8 +104,9 @@ const titleBase = words.slice(1).join(" ") || "";
89
104
  tools={allToolsNav}
90
105
  />
91
106
  <Fragment slot="head">
107
+ {toolCss && <style set:html={toolCss} />}
92
108
  {
93
- content.schemas.map((schema: unknown) => (
109
+ ( content.schemas ?? []).map((schema) => (
94
110
  <script
95
111
  is:inline
96
112
  type="application/ld+json"
@@ -116,11 +132,11 @@ const titleBase = words.slice(1).join(" ") || "";
116
132
  </section>
117
133
 
118
134
  <section class="section-faq">
119
- <FAQSection items={content.faq} title={content.ui.faqTitle} inLanguage={locale} />
135
+ <FAQSection items={content.faq} inLanguage={locale} />
120
136
  </section>
121
137
 
122
138
  <section class="section-bibliography">
123
- <Bibliography links={content.bibliography} title={content.ui.bibliographyTitle} />
139
+ <Bibliography links={content.bibliography} />
124
140
  </section>
125
141
  </div>
126
142
  </PreviewLayout>
@@ -131,11 +147,13 @@ const titleBase = words.slice(1).join(" ") || "";
131
147
  flex-direction: column;
132
148
  gap: 2rem;
133
149
  }
150
+
134
151
  .section-tool {
135
152
  max-width: 1200px;
136
153
  margin: 0 auto;
137
154
  width: 100%;
138
155
  }
156
+
139
157
  .section-seo,
140
158
  .section-faq,
141
159
  .section-bibliography {
@@ -0,0 +1,118 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { ALL_TOOLS } from '../tools';
3
+
4
+ type LocaleWithDiacritics = keyof typeof DIACRITIC_RULES;
5
+
6
+ const DIACRITIC_RULES = {
7
+ de: {
8
+ language: 'German',
9
+ expectedCharacters: 'ä ö ü ß',
10
+ characters: /[äöüÄÖÜß]/g,
11
+ minPerThousandLetters: 0.1,
12
+ },
13
+ es: {
14
+ language: 'Spanish',
15
+ expectedCharacters: 'á é í ó ú ü ñ',
16
+ characters: /[áéíóúüñÁÉÍÓÚÜÑ]/g,
17
+ minPerThousandLetters: 0.1,
18
+ },
19
+ fr: {
20
+ language: 'French',
21
+ expectedCharacters: 'à â æ ç é è ê ë î ï ô œ ù û ü ÿ',
22
+ characters: /[àâæçéèêëîïôœùûüÿÀÂÆÇÉÈÊËÎÏÔŒÙÛÜŸ]/g,
23
+ minPerThousandLetters: 0.1,
24
+ },
25
+ it: {
26
+ language: 'Italian',
27
+ expectedCharacters: 'à è é ì í î ò ó ù ú',
28
+ characters: /[àèéìíîòóùúÀÈÉÌÍÎÒÓÙÚ]/g,
29
+ minPerThousandLetters: 0.1,
30
+ },
31
+ pl: {
32
+ language: 'Polish',
33
+ expectedCharacters: 'ą ć ę ł ń ó ś ź ż',
34
+ characters: /[ąćęłńóśźżĄĆĘŁŃÓŚŹŻ]/g,
35
+ minPerThousandLetters: 0.1,
36
+ },
37
+ pt: {
38
+ language: 'Portuguese',
39
+ expectedCharacters: 'á â ã à ç é ê í ó ô õ ú ü',
40
+ characters: /[áâãàçéêíóôõúüÁÂÃÀÇÉÊÍÓÔÕÚÜ]/g,
41
+ minPerThousandLetters: 0.1,
42
+ },
43
+ sv: {
44
+ language: 'Swedish',
45
+ expectedCharacters: 'å ä ö',
46
+ characters: /[åäöÅÄÖ]/g,
47
+ minPerThousandLetters: 0.1,
48
+ },
49
+ tr: {
50
+ language: 'Turkish',
51
+ expectedCharacters: 'ç ğ ı İ ö ş ü',
52
+ characters: /[çğıöşüÇĞİÖŞÜ]/g,
53
+ minPerThousandLetters: 0.1,
54
+ },
55
+ } as const;
56
+
57
+ const LETTERS = /\p{L}/gu;
58
+ const TRANSLATABLE_KEYS = ['title', 'description', 'ui', 'seo', 'faq', 'howTo'] as const;
59
+
60
+ function collectStrings(value: unknown): string[] {
61
+ if (typeof value === 'string') return [value];
62
+ if (!value || typeof value !== 'object') return [];
63
+ if (Array.isArray(value)) return value.flatMap(collectStrings);
64
+ return Object.values(value).flatMap(collectStrings);
65
+ }
66
+
67
+ function normalizeText(value: unknown): string {
68
+ return collectStrings(value).join(' ').normalize('NFC');
69
+ }
70
+
71
+ function translatableContent(content: Record<string, unknown>) {
72
+ return TRANSLATABLE_KEYS.map((key) => content[key]);
73
+ }
74
+
75
+ function letterCount(text: string): number {
76
+ return text.match(LETTERS)?.length ?? 0;
77
+ }
78
+
79
+ function diacriticCount(text: string, locale: LocaleWithDiacritics): number {
80
+ return text.match(DIACRITIC_RULES[locale].characters)?.length ?? 0;
81
+ }
82
+
83
+ function diacriticsPerThousandLetters(text: string, locale: LocaleWithDiacritics): number {
84
+ const letters = letterCount(text);
85
+ if (letters === 0) return 0;
86
+ return diacriticCount(text, locale) / letters * 1000;
87
+ }
88
+
89
+ describe('Diacritics density validation', () => {
90
+ ALL_TOOLS.forEach((tool) => {
91
+ describe(`Tool: ${tool.entry.id}`, () => {
92
+ Object.keys(DIACRITIC_RULES).forEach((locale) => {
93
+ it(`${locale} keeps the expected accent and special-letter set`, async () => {
94
+ const typedLocale = locale as LocaleWithDiacritics;
95
+ const loader = tool.entry.i18n[typedLocale];
96
+ if (!loader) return;
97
+
98
+ const content = await loader();
99
+ const text = normalizeText(translatableContent(content as Record<string, unknown>));
100
+ const rule = DIACRITIC_RULES[typedLocale];
101
+ const letters = letterCount(text);
102
+ const matches = diacriticCount(text, typedLocale);
103
+ const density = diacriticsPerThousandLetters(text, typedLocale);
104
+
105
+ expect(
106
+ density,
107
+ [
108
+ `Possible spelling or encoding issue detected in ${tool.entry.id}/${typedLocale} (${rule.language}).`,
109
+ `The text has ${matches} special characters (${density.toFixed(2)} per 1000 letters, ${letters} letters analyzed).`,
110
+ `This locale should include some of these characters: ${rule.expectedCharacters}.`,
111
+ 'If the count is 0 or near 0, accents, tildes, or special letters were probably stripped by encoding or normalization.',
112
+ ].join(' '),
113
+ ).toBeGreaterThanOrEqual(rule.minPerThousandLetters);
114
+ });
115
+ });
116
+ });
117
+ });
118
+ });
@@ -0,0 +1,84 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { ALL_TOOLS } from '../tools';
3
+
4
+ const INVERTED_PUNCTUATION_LOCALES = {
5
+ es: {
6
+ language: 'Spanish',
7
+ questionStart: '¿',
8
+ questionEnd: '?',
9
+ exclamationStart: '¡',
10
+ exclamationEnd: '!',
11
+ },
12
+ } as const;
13
+
14
+ type InvertedPunctuationLocale = keyof typeof INVERTED_PUNCTUATION_LOCALES;
15
+
16
+ const TRANSLATABLE_KEYS = ['title', 'description', 'ui', 'seo', 'faq', 'howTo'] as const;
17
+
18
+ function collectStrings(value: unknown): string[] {
19
+ if (typeof value === 'string') return [value];
20
+ if (!value || typeof value !== 'object') return [];
21
+ if (Array.isArray(value)) return value.flatMap(collectStrings);
22
+ return Object.values(value).flatMap(collectStrings);
23
+ }
24
+
25
+ function translatableStrings(content: Record<string, unknown>): string[] {
26
+ return TRANSLATABLE_KEYS.flatMap((key) => collectStrings(content[key]));
27
+ }
28
+
29
+ function sentenceStart(text: string, endIndex: number): string {
30
+ const beforeMark = text.slice(0, endIndex).trimEnd();
31
+ const boundary = Math.max(
32
+ beforeMark.lastIndexOf('.'),
33
+ beforeMark.lastIndexOf(':'),
34
+ beforeMark.lastIndexOf(';'),
35
+ beforeMark.lastIndexOf('\n'),
36
+ );
37
+
38
+ return beforeMark.slice(boundary + 1).trimStart();
39
+ }
40
+
41
+ function findMissingInvertedMarks(
42
+ text: string,
43
+ startMark: string,
44
+ endMark: string,
45
+ ): string[] {
46
+ return [...text.matchAll(new RegExp(`\\${endMark}`, 'g'))]
47
+ .map((match) => sentenceStart(text, match.index ?? 0))
48
+ .filter((segment) => segment.length > 0 && !segment.includes(startMark))
49
+ .map((segment) => `${segment}${endMark}`);
50
+ }
51
+
52
+ describe('Inverted punctuation validation', () => {
53
+ ALL_TOOLS.forEach((tool) => {
54
+ describe(`Tool: ${tool.entry.id}`, () => {
55
+ Object.keys(INVERTED_PUNCTUATION_LOCALES).forEach((locale) => {
56
+ it(`${locale} uses opening punctuation marks for questions and exclamations`, async () => {
57
+ const typedLocale = locale as InvertedPunctuationLocale;
58
+ const loader = tool.entry.i18n[typedLocale];
59
+ if (!loader) return;
60
+
61
+ const rule = INVERTED_PUNCTUATION_LOCALES[typedLocale];
62
+ const content = await loader();
63
+ const strings = translatableStrings(content as Record<string, unknown>);
64
+ const missingQuestions = strings.flatMap((text) =>
65
+ findMissingInvertedMarks(text, rule.questionStart, rule.questionEnd)
66
+ );
67
+ const missingExclamations = strings.flatMap((text) =>
68
+ findMissingInvertedMarks(text, rule.exclamationStart, rule.exclamationEnd)
69
+ );
70
+ const failures = [...missingQuestions, ...missingExclamations];
71
+
72
+ expect(
73
+ failures,
74
+ [
75
+ `Missing opening punctuation marks in ${tool.entry.id}/${typedLocale} (${rule.language}).`,
76
+ `Questions must use ${rule.questionStart}...${rule.questionEnd} and exclamations must use ${rule.exclamationStart}...${rule.exclamationEnd}.`,
77
+ `Examples: ${failures.slice(0, 5).join(' | ')}`,
78
+ ].join(' '),
79
+ ).toHaveLength(0);
80
+ });
81
+ });
82
+ });
83
+ });
84
+ });
@@ -1,39 +1,9 @@
1
1
  import { describe, it, expect } from 'vitest';
2
2
  import { ALL_TOOLS } from '../tools';
3
- import type { ToolLocaleContent } from '../types';
4
3
 
5
- describe('Locale Completeness Validation', () => {
6
- ALL_TOOLS.forEach((tool) => {
7
- describe(`Tool: ${tool.entry.id}`, () => {
8
- Object.keys(tool.entry.i18n).forEach((locale) => {
9
- describe(`Locale: ${locale}`, () => {
10
- it('faqTitle should be defined when faq items exist', async () => {
11
- const loader = tool.entry.i18n[locale as keyof typeof tool.entry.i18n];
12
- const content = (await loader?.()) as ToolLocaleContent;
13
-
14
- if (content.faq.length > 0) {
15
- expect(
16
- content.faqTitle,
17
- `Tool "${tool.entry.id}" locale "${locale}" has ${content.faq.length} FAQ items but is missing faqTitle`,
18
- ).toBeTruthy();
19
- }
20
- });
21
4
 
22
- it('bibliographyTitle should be defined when bibliography items exist', async () => {
23
- const loader = tool.entry.i18n[locale as keyof typeof tool.entry.i18n];
24
- const content = (await loader?.()) as ToolLocaleContent;
5
+ describe('Locale Completeness Validation', () => {
25
6
 
26
- if (content.bibliography.length > 0) {
27
- expect(
28
- content.bibliographyTitle,
29
- `Tool "${tool.entry.id}" locale "${locale}" has ${content.bibliography.length} bibliography items but is missing bibliographyTitle`,
30
- ).toBeTruthy();
31
- }
32
- });
33
- });
34
- });
35
- });
36
- });
37
7
 
38
8
  it('should have at least 1 tool registered', () => {
39
9
  expect(ALL_TOOLS.length).toBeGreaterThan(0);
@@ -0,0 +1,71 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+
5
+ function getFiles(dir: string): string[] {
6
+ const results: string[] = [];
7
+ if (!fs.existsSync(dir)) {
8
+ return results;
9
+ }
10
+ const list = fs.readdirSync(dir);
11
+ for (const file of list) {
12
+ const fullPath = path.join(dir, file);
13
+ const stat = fs.statSync(fullPath);
14
+ if (stat && stat.isDirectory()) {
15
+ if (file !== 'tests' && file !== 'node_modules' && file !== '.astro') {
16
+ results.push(...getFiles(fullPath));
17
+ }
18
+ } else {
19
+ results.push(fullPath);
20
+ }
21
+ }
22
+ return results;
23
+ }
24
+
25
+ function isContentFile(filePath: string): boolean {
26
+ return /\\i18n\\/.test(filePath) || filePath.endsWith('bibliography.ts');
27
+ }
28
+
29
+ const srcDir = path.join(process.cwd(), 'src');
30
+ const scriptsDir = path.join(process.cwd(), 'scripts');
31
+ const filesToTest = [
32
+ ...getFiles(srcDir).filter(isContentFile),
33
+ ...getFiles(scriptsDir).filter(isContentFile),
34
+ ];
35
+
36
+ const aiTypographyGarbage = [
37
+ '\u2013',
38
+ '\u2014',
39
+ '\u2026',
40
+ '\u201C',
41
+ '\u201D',
42
+ '\u2018',
43
+ '\u2019',
44
+ '\u00AB',
45
+ '\u00BB',
46
+ '\u200B',
47
+ '\u201E',
48
+ ];
49
+
50
+ describe('Typography Garbage Character Validation', () => {
51
+ filesToTest.forEach((filePath) => {
52
+ const relativePath = path.relative(process.cwd(), filePath);
53
+ it(`should not contain typography garbage characters in ${relativePath}`, () => {
54
+ const content = fs.readFileSync(filePath, 'utf-8');
55
+ const hasAiPatterns = aiTypographyGarbage.some(char => content.includes(char));
56
+ expect(hasAiPatterns).toBe(false);
57
+ });
58
+
59
+ it(`should not contain space before colon in ${relativePath}`, () => {
60
+ const content = fs.readFileSync(filePath, 'utf-8');
61
+ const spaceBeforeColon = / : /.test(content);
62
+ expect(spaceBeforeColon).toBe(false);
63
+ });
64
+
65
+ it(`should not contain double hyphen in ${relativePath}`, () => {
66
+ const content = fs.readFileSync(filePath, 'utf-8');
67
+ const cleaned = content.replace(/var\(--[\w-]+\)/g, '');
68
+ expect(cleaned).not.toContain('--');
69
+ });
70
+ });
71
+ });
@@ -0,0 +1,94 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { ALL_TOOLS } from '../tools';
3
+
4
+ type ScriptLocale = keyof typeof SCRIPT_RULES;
5
+
6
+ const SCRIPT_RULES = {
7
+ ja: {
8
+ language: 'Japanese',
9
+ scriptName: 'kana/kanji',
10
+ scriptCharacters: /[\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Han}]/gu,
11
+ minScriptRatio: 0.45,
12
+ },
13
+ ko: {
14
+ language: 'Korean',
15
+ scriptName: 'hangul',
16
+ scriptCharacters: /\p{Script=Hangul}/gu,
17
+ minScriptRatio: 0.55,
18
+ },
19
+ ru: {
20
+ language: 'Russian',
21
+ scriptName: 'cyrillic',
22
+ scriptCharacters: /\p{Script=Cyrillic}/gu,
23
+ minScriptRatio: 0.65,
24
+ },
25
+ zh: {
26
+ language: 'Chinese',
27
+ scriptName: 'han',
28
+ scriptCharacters: /\p{Script=Han}/gu,
29
+ minScriptRatio: 0.45,
30
+ },
31
+ } as const;
32
+
33
+ const LETTERS = /\p{L}/gu;
34
+ const TRANSLATABLE_KEYS = ['title', 'description', 'ui', 'seo', 'faq', 'howTo'] as const;
35
+
36
+ function collectStrings(value: unknown): string[] {
37
+ if (typeof value === 'string') return [value];
38
+ if (!value || typeof value !== 'object') return [];
39
+ if (Array.isArray(value)) return value.flatMap(collectStrings);
40
+ return Object.values(value).flatMap(collectStrings);
41
+ }
42
+
43
+ function normalizeText(value: unknown): string {
44
+ return collectStrings(value).join(' ').normalize('NFC');
45
+ }
46
+
47
+ function translatableContent(content: Record<string, unknown>) {
48
+ return TRANSLATABLE_KEYS.map((key) => content[key]);
49
+ }
50
+
51
+ function letterCount(text: string): number {
52
+ return text.match(LETTERS)?.length ?? 0;
53
+ }
54
+
55
+ function scriptCount(text: string, locale: ScriptLocale): number {
56
+ return text.match(SCRIPT_RULES[locale].scriptCharacters)?.length ?? 0;
57
+ }
58
+
59
+ function scriptRatio(text: string, locale: ScriptLocale): number {
60
+ const letters = letterCount(text);
61
+ if (letters === 0) return 0;
62
+ return scriptCount(text, locale) / letters;
63
+ }
64
+
65
+ describe('Native script density validation', () => {
66
+ ALL_TOOLS.forEach((tool) => {
67
+ describe(`Tool: ${tool.entry.id}`, () => {
68
+ Object.keys(SCRIPT_RULES).forEach((locale) => {
69
+ it(`${locale} keeps most translated text in its native script`, async () => {
70
+ const typedLocale = locale as ScriptLocale;
71
+ const loader = tool.entry.i18n[typedLocale];
72
+ if (!loader) return;
73
+
74
+ const content = await loader();
75
+ const rule = SCRIPT_RULES[typedLocale];
76
+ const text = normalizeText(translatableContent(content as Record<string, unknown>));
77
+ const letters = letterCount(text);
78
+ const matches = scriptCount(text, typedLocale);
79
+ const ratio = scriptRatio(text, typedLocale);
80
+
81
+ expect(
82
+ ratio,
83
+ [
84
+ `Possible broken translation detected in ${tool.entry.id}/${typedLocale} (${rule.language}).`,
85
+ `The text has ${matches} ${rule.scriptName} characters out of ${letters} analyzed letters (${(ratio * 100).toFixed(1)}%).`,
86
+ `Most translatable content should be written in ${rule.scriptName} script.`,
87
+ 'Non-translatable fields such as slug, bibliography, and schemas are ignored to avoid false positives.',
88
+ ].join(' '),
89
+ ).toBeGreaterThanOrEqual(rule.minScriptRatio);
90
+ });
91
+ });
92
+ });
93
+ });
94
+ });