@gram-lang/i18n 1.0.0-beta.3 → 1.0.0-beta.5

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/dist/index.d.ts CHANGED
@@ -1,9 +1,6 @@
1
1
  type LanguageDict = Record<string, string[]>;
2
2
  type CompiledDict = Record<string, string>;
3
- /**
4
- * Compiles human-readable language dictionaries into optimized O(1) lookup tables.
5
- * Generates both language-specific lookups and a unified global fallback lookup.
6
- */
3
+ /** Compiles alias lists into O(1) lookup tables, per language plus a unified global fallback. */
7
4
  declare function compileDictionary(dictionaries: Record<string, LanguageDict>): {
8
5
  byLang: Record<string, CompiledDict>;
9
6
  global: CompiledDict;
@@ -15,9 +12,7 @@ declare const TIME_DICTIONARIES: {
15
12
  };
16
13
  declare const TIME_BY_LANG: Record<string, CompiledDict>;
17
14
  declare const TIME_GLOBAL: CompiledDict;
18
- /**
19
- * Helper to normalize a time unit string into its canonical alias ('h', 'm', 's').
20
- */
15
+ declare const TIME_TO_MINUTES: Record<string, number>;
21
16
  declare const resolveTimeUnit: (unit?: string | null, lang?: string) => string;
22
17
 
23
18
  declare const UNIT_DICTIONARIES: {
@@ -26,6 +21,14 @@ declare const UNIT_DICTIONARIES: {
26
21
  };
27
22
  declare const UNIT_BY_LANG: Record<string, CompiledDict>;
28
23
  declare const UNIT_GLOBAL: CompiledDict;
24
+ interface UnitMap {
25
+ base: string;
26
+ map: Record<string, number>;
27
+ }
28
+ declare const UNIT_CONVERSIONS: {
29
+ mass: UnitMap;
30
+ volume: UnitMap;
31
+ };
29
32
  /**
30
33
  * Normalizes a raw string unit into a standard canon unit.
31
34
  * Examples: 'càs' -> 'tbsp', 'kilo' -> 'kg'.
@@ -34,6 +37,23 @@ declare function normalizeUnit(rawUnit: string | undefined | null, lang?: string
34
37
 
35
38
  declare function getAiLanguageInstruction(lang?: string): string;
36
39
 
40
+ declare const CATEGORY_KEYS: readonly ["vegetables", "fruits", "meat", "seafood", "dairy", "grains", "legumes", "nuts", "oils", "herbs", "spices", "condiments", "sugars", "beverages", "other"];
41
+ type CategoryKey = (typeof CATEGORY_KEYS)[number];
42
+ /**
43
+ * Display label for every category key, in canonical order — for showing to
44
+ * a human (a prompt, a UI list). Never persist these as data; persist the
45
+ * key (`CategoryKey`) instead, and translate to a label only at display time.
46
+ */
47
+ declare function getCategoryLabels(lang?: string): Record<CategoryKey, string>;
48
+ declare function isCategoryKey(value: string): value is CategoryKey;
49
+ /**
50
+ * Returns display labels only, in canonical key order. Kept for the one
51
+ * legitimate label-only use left (`shopper.ts`'s sort-order comparison,
52
+ * which also has to keep matching pre-F-03 databases that already have a
53
+ * translated label — not a key — written into `category`). Prefer
54
+ * `getCategoryLabels`/`CATEGORY_KEYS` for anything that persists a category
55
+ * as data.
56
+ */
37
57
  declare function getDefaultCategories(lang?: string): string[];
38
58
 
39
59
  declare const en: {
@@ -43,9 +63,13 @@ declare const en: {
43
63
  equipment: string;
44
64
  nutrition: string;
45
65
  totalTime: string;
46
- cookTime: string;
66
+ idleTime: string;
47
67
  activeTime: string;
48
68
  prepTime: string;
69
+ totalTimeTooltip: string;
70
+ idleTimeTooltip: string;
71
+ activeTimeCardTooltip: string;
72
+ prepTimeTooltip: string;
49
73
  est: string;
50
74
  passiveTimeTooltip: string;
51
75
  activeTimeTooltip: string;
@@ -59,6 +83,12 @@ declare const en: {
59
83
  standardized: string;
60
84
  optional: string;
61
85
  calculationPartialOrFailed: string;
86
+ ingredientsOverhead: string;
87
+ cookwareOverhead: string;
88
+ breakdownActive: string;
89
+ breakdownPassive: string;
90
+ breakdownTimer: string;
91
+ breakdownPrep: string;
62
92
  standardizedMass: string;
63
93
  quantity: string;
64
94
  intermediateIngredient: string;
@@ -95,9 +125,28 @@ declare const en: {
95
125
  jsonTree: string;
96
126
  markdown: string;
97
127
  preview: string;
128
+ gantt: string;
129
+ gantt_active: string;
130
+ gantt_passive: string;
131
+ gantt_compact: string;
132
+ gantt_time: string;
133
+ gantt_cook: string;
134
+ gantt_timer: string;
135
+ gantt_prep: string;
136
+ gantt_empty: string;
137
+ gantt_compressed: string;
138
+ gantt_assembly: string;
139
+ gantt_more_sections: string;
140
+ gantt_section: string;
141
+ gantt_mode_forward: string;
142
+ gantt_mode_reverse: string;
143
+ gantt_mode_target: string;
144
+ gantt_target_time_label: string;
98
145
  };
99
146
  options: {
100
147
  scaleTitle: string;
148
+ scaleGlobal: string;
149
+ scaleByIngredient: string;
101
150
  selectIngredient: string;
102
151
  qty: string;
103
152
  unit: string;
@@ -138,4 +187,4 @@ type GramLocale = typeof en;
138
187
 
139
188
  declare function getDictionary(lang?: string): GramLocale;
140
189
 
141
- export { type CompiledDict, type GramLocale, type LanguageDict, TIME_BY_LANG, TIME_DICTIONARIES, TIME_GLOBAL, UNIT_BY_LANG, UNIT_DICTIONARIES, UNIT_GLOBAL, compileDictionary, getAiLanguageInstruction, getDefaultCategories, getDictionary, normalizeUnit, resolveTimeUnit };
190
+ export { CATEGORY_KEYS, type CategoryKey, type CompiledDict, type GramLocale, type LanguageDict, TIME_BY_LANG, TIME_DICTIONARIES, TIME_GLOBAL, TIME_TO_MINUTES, UNIT_BY_LANG, UNIT_CONVERSIONS, UNIT_DICTIONARIES, UNIT_GLOBAL, type UnitMap, compileDictionary, getAiLanguageInstruction, getCategoryLabels, getDefaultCategories, getDictionary, isCategoryKey, normalizeUnit, resolveTimeUnit };
package/dist/index.js CHANGED
@@ -20,17 +20,25 @@ function compileDictionary(dictionaries2) {
20
20
 
21
21
  // src/time.ts
22
22
  var en = {
23
+ d: ["day", "days"],
23
24
  h: ["hour", "hours"],
24
25
  m: ["min", "mins", "minute", "minutes"],
25
26
  s: ["sec", "secs", "second", "seconds"]
26
27
  };
27
28
  var fr = {
29
+ d: ["j", "jour", "jours"],
28
30
  h: ["heure", "heures"],
29
31
  m: ["min", "mins", "minute", "minutes"],
30
32
  s: ["sec", "secs", "seconde", "secondes"]
31
33
  };
32
34
  var TIME_DICTIONARIES = { en, fr };
33
35
  var { byLang: TIME_BY_LANG, global: TIME_GLOBAL } = compileDictionary(TIME_DICTIONARIES);
36
+ var TIME_TO_MINUTES = {
37
+ d: 60 * 24,
38
+ h: 60,
39
+ m: 1,
40
+ s: 1 / 60
41
+ };
34
42
  var resolveTimeUnit = (unit, lang) => {
35
43
  if (!unit) return "";
36
44
  const clean = unit.trim().toLowerCase();
@@ -54,7 +62,13 @@ var en2 = {
54
62
  // Volume — cups & imperial
55
63
  cup: ["cups"],
56
64
  pt: ["pint", "pints"],
57
- qt: ["quart", "quarts"],
65
+ // "quart"/"quarts" is deliberately NOT an alias for "qt" here (audit
66
+ // 2026-07-22, finding F-01): the French word "quart" means "a quarter"
67
+ // (as in "un quart d'heure"), not the US liquid measure — the identical
68
+ // spelling made it a silent false-friend when both dictionaries mapped it
69
+ // to the same canonical. "qt" is still usable by typing it directly.
70
+ qt: [],
71
+ gal: ["gallon", "gallons"],
58
72
  "fl oz": ["floz", "fl. oz.", "fluid ounce", "fluid ounces"],
59
73
  // Volume — metric
60
74
  ml: ["milliliter", "milliliters"],
@@ -95,26 +109,73 @@ var fr2 = {
95
109
  pinch: ["pinc\xE9e", "pincee", "pinc\xE9es", "pincees"],
96
110
  smidgen: ["poussi\xE8re", "poussiere", "poussi\xE8res", "poussieres"],
97
111
  drop: ["goutte", "gouttes"],
98
- // Volume — tasse & mesures anglo-saxonnes
99
- cup: ["tasse", "tasses"],
100
- pt: ["pinte", "pintes"],
101
- qt: ["quart", "quarts"],
112
+ // Pas d'alias FR pour "quart" (cf. dict EN ci-dessus) ni pour "pinte" : la
113
+ // pinte française historique n'a pas de valeur moderne fiable et unique
114
+ // (elle a varié de ~0,93 L à plus de 3 L selon les régions avant la
115
+ // métrication) — mieux vaut un avertissement « unité inconnue » qu'une
116
+ // conversion silencieusement fausse.
102
117
  "fl oz": ["once liquide", "onces liquides"],
103
118
  // Volume — métrique
104
119
  ml: ["millilitre", "millilitres"],
105
120
  cl: ["centilitre", "centilitres"],
106
121
  dl: ["d\xE9cilitre", "d\xE9cilitres", "decilitre", "decilitres"],
107
122
  l: ["litre", "litres"],
123
+ // Volume — tasse française (250 mL), distincte du "cup" nord-américain
124
+ // (236,588 mL) : les fusionner sous un seul canonique produisait une
125
+ // erreur silencieuse d'environ 6 % (audit 2026-07-22, finding F-01).
126
+ tasse: ["tasse", "tasses"],
108
127
  // Poids — métrique
109
128
  mg: ["milligramme", "milligrammes"],
110
129
  g: ["gramme", "grammes"],
111
130
  kg: ["kilo", "kilos", "kilogramme", "kilogrammes"],
131
+ // Poids — livre française (500 g, la "livre métrique" toujours en usage
132
+ // courant), distincte de la livre impériale "lb" (453,592 g) — les fusionner
133
+ // produisait ~500 g → 453 g, une erreur silencieuse d'environ 10 %.
134
+ livre: ["livre", "livres"],
112
135
  // Poids — impérial
113
- oz: ["once", "onces"],
114
- lb: ["livre", "livres"]
136
+ oz: ["once", "onces"]
115
137
  };
116
138
  var UNIT_DICTIONARIES = { en: en2, fr: fr2 };
117
139
  var { byLang: UNIT_BY_LANG, global: UNIT_GLOBAL } = compileDictionary(UNIT_DICTIONARIES);
140
+ var UNIT_CONVERSIONS = {
141
+ mass: {
142
+ base: "g",
143
+ map: {
144
+ mg: 1e-3,
145
+ g: 1,
146
+ kg: 1e3,
147
+ oz: 28.3495,
148
+ lb: 453.592,
149
+ // French "livre" (métrique) — see above for why this is a distinct
150
+ // canonical from "lb" rather than an alias of it.
151
+ livre: 500
152
+ }
153
+ },
154
+ volume: {
155
+ base: "ml",
156
+ map: {
157
+ ml: 1,
158
+ cl: 10,
159
+ dl: 100,
160
+ l: 1e3,
161
+ drop: 0.078,
162
+ smidgen: 0.156,
163
+ pinch: 0.3125,
164
+ dash: 0.625,
165
+ tad: 1.25,
166
+ tsp: 4.9289,
167
+ tbsp: 14.7868,
168
+ cup: 236.588,
169
+ // French "tasse" — see above for why this is a distinct canonical
170
+ // from "cup" rather than an alias of it.
171
+ tasse: 250,
172
+ pt: 473.176,
173
+ qt: 946.353,
174
+ gal: 3785.41,
175
+ "fl oz": 29.5735
176
+ }
177
+ }
178
+ };
118
179
  function normalizeUnit(rawUnit, lang) {
119
180
  if (!rawUnit) return "";
120
181
  const clean = rawUnit.toLowerCase().trim();
@@ -142,44 +203,68 @@ function getAiLanguageInstruction(lang = "en") {
142
203
  }
143
204
 
144
205
  // src/categories.ts
145
- var CATEGORIES = {
146
- fr: [
147
- "L\xE9gumes",
148
- "Fruits",
149
- "Viandes",
150
- "Poissons & Fruits de mer",
151
- "Cr\xE9merie",
152
- "C\xE9r\xE9ales",
153
- "L\xE9gumineuses",
154
- "Noix & Graines",
155
- "Huiles",
156
- "Herbes",
157
- "\xC9pices",
158
- "Condiments",
159
- "Sucres",
160
- "Boissons",
161
- "Autres"
162
- ],
163
- en: [
164
- "Vegetables",
165
- "Fruits",
166
- "Meat",
167
- "Seafood",
168
- "Dairy",
169
- "Grains",
170
- "Legumes",
171
- "Nuts",
172
- "Oils",
173
- "Herbs",
174
- "Spices",
175
- "Condiments",
176
- "Sugars",
177
- "Beverages",
178
- "Other"
179
- ]
206
+ var CATEGORY_KEYS = [
207
+ "vegetables",
208
+ "fruits",
209
+ "meat",
210
+ "seafood",
211
+ "dairy",
212
+ "grains",
213
+ "legumes",
214
+ "nuts",
215
+ "oils",
216
+ "herbs",
217
+ "spices",
218
+ "condiments",
219
+ "sugars",
220
+ "beverages",
221
+ "other"
222
+ ];
223
+ var CATEGORY_LABELS = {
224
+ fr: {
225
+ vegetables: "L\xE9gumes",
226
+ fruits: "Fruits",
227
+ meat: "Viandes",
228
+ seafood: "Poissons & Fruits de mer",
229
+ dairy: "Cr\xE9merie",
230
+ grains: "C\xE9r\xE9ales",
231
+ legumes: "L\xE9gumineuses",
232
+ nuts: "Noix & Graines",
233
+ oils: "Huiles",
234
+ herbs: "Herbes",
235
+ spices: "\xC9pices",
236
+ condiments: "Condiments",
237
+ sugars: "Sucres",
238
+ beverages: "Boissons",
239
+ other: "Autres"
240
+ },
241
+ en: {
242
+ vegetables: "Vegetables",
243
+ fruits: "Fruits",
244
+ meat: "Meat",
245
+ seafood: "Seafood",
246
+ dairy: "Dairy",
247
+ grains: "Grains",
248
+ legumes: "Legumes",
249
+ nuts: "Nuts",
250
+ oils: "Oils",
251
+ herbs: "Herbs",
252
+ spices: "Spices",
253
+ condiments: "Condiments",
254
+ sugars: "Sugars",
255
+ beverages: "Beverages",
256
+ other: "Other"
257
+ }
180
258
  };
259
+ function getCategoryLabels(lang = "en") {
260
+ return CATEGORY_LABELS[lang] ?? CATEGORY_LABELS.en;
261
+ }
262
+ function isCategoryKey(value) {
263
+ return CATEGORY_KEYS.includes(value);
264
+ }
181
265
  function getDefaultCategories(lang = "en") {
182
- return CATEGORIES[lang] ?? CATEGORIES.en;
266
+ const labels = getCategoryLabels(lang);
267
+ return CATEGORY_KEYS.map((key) => labels[key]);
183
268
  }
184
269
 
185
270
  // src/locales/en.ts
@@ -190,9 +275,13 @@ var en3 = {
190
275
  equipment: "Equipment",
191
276
  nutrition: "Nutrition",
192
277
  totalTime: "Total Time",
193
- cookTime: "Cook Time",
278
+ idleTime: "Idle Time",
194
279
  activeTime: "Active Time",
195
280
  prepTime: "Prep Time",
281
+ totalTimeTooltip: "Total Time = Prep + Active + Idle",
282
+ idleTimeTooltip: "Idle Time = Total Time - Prep - Active",
283
+ activeTimeCardTooltip: "Active Time = Sum of manual work time",
284
+ prepTimeTooltip: "Prep Time = Time needed before starting step 1",
196
285
  est: "(est.)",
197
286
  passiveTimeTooltip: "Passive Time (Waiting, resting...)",
198
287
  activeTimeTooltip: "Active Time",
@@ -206,6 +295,12 @@ var en3 = {
206
295
  standardized: "Standardized",
207
296
  optional: "Optional",
208
297
  calculationPartialOrFailed: "Calculation partial or failed",
298
+ ingredientsOverhead: "Ingredients lookup (base)",
299
+ cookwareOverhead: "Cookware lookup (base)",
300
+ breakdownActive: "Active",
301
+ breakdownPassive: "Passive",
302
+ breakdownTimer: "Timer",
303
+ breakdownPrep: "Preparation",
209
304
  standardizedMass: "Standardized mass",
210
305
  quantity: "Quantity",
211
306
  intermediateIngredient: "Intermediate Ingredient",
@@ -241,10 +336,29 @@ var en3 = {
241
336
  ast: "AST (Raw)",
242
337
  jsonTree: "Interactive Tree",
243
338
  markdown: "Markdown",
244
- preview: "Preview (HTML)"
339
+ preview: "Preview (HTML)",
340
+ gantt: "Gantt Chart",
341
+ gantt_active: "Active Task",
342
+ gantt_passive: "Background Task",
343
+ gantt_compact: "Compact View",
344
+ gantt_time: "Time",
345
+ gantt_cook: "Actions",
346
+ gantt_timer: "Timer",
347
+ gantt_prep: "Prep",
348
+ gantt_empty: "No timing data available. Write a recipe with steps and durations to see the chart.",
349
+ gantt_compressed: "Time compressed (idle period)",
350
+ gantt_assembly: "Assembly / Dependencies",
351
+ gantt_more_sections: "+{count} more...",
352
+ gantt_section: "Section",
353
+ gantt_mode_forward: "Stopwatch (T+)",
354
+ gantt_mode_reverse: "Countdown (T-)",
355
+ gantt_mode_target: "Target Time",
356
+ gantt_target_time_label: "Serve at:"
245
357
  },
246
358
  options: {
247
- scaleTitle: "Scale by Ingredient",
359
+ scaleTitle: "Modify Quantities",
360
+ scaleGlobal: "Overall Scale",
361
+ scaleByIngredient: "By Ingredient",
248
362
  selectIngredient: "Select ingredient...",
249
363
  qty: "Qty",
250
364
  unit: "Unit",
@@ -290,9 +404,13 @@ var fr3 = {
290
404
  equipment: "\xC9quipement",
291
405
  nutrition: "Nutrition",
292
406
  totalTime: "Temps Total",
293
- cookTime: "Cuisson",
407
+ idleTime: "Attente",
294
408
  activeTime: "Actif",
295
409
  prepTime: "Pr\xE9paration",
410
+ totalTimeTooltip: "Temps Total = Pr\xE9paration + Actif + Attente",
411
+ idleTimeTooltip: "Temps d'Attente = Temps Total - Pr\xE9paration - Actif",
412
+ activeTimeCardTooltip: "Temps Actif = Somme des temps de manipulation manuelle",
413
+ prepTimeTooltip: "Pr\xE9paration = Temps n\xE9cessaire avant l'\xE9tape 1",
296
414
  est: "(est.)",
297
415
  passiveTimeTooltip: "Temps passif (Repos, attente...)",
298
416
  activeTimeTooltip: "Temps actif",
@@ -306,6 +424,12 @@ var fr3 = {
306
424
  standardized: "Standardis\xE9",
307
425
  optional: "Optionnel",
308
426
  calculationPartialOrFailed: "Calcul partiel ou \xE9chou\xE9",
427
+ ingredientsOverhead: "Ingr\xE9dients (base)",
428
+ cookwareOverhead: "Mat\xE9riel (base)",
429
+ breakdownActive: "Actif",
430
+ breakdownPassive: "Passif",
431
+ breakdownTimer: "Minuteur",
432
+ breakdownPrep: "Pr\xE9paration",
309
433
  standardizedMass: "Masse standardis\xE9e",
310
434
  quantity: "Quantit\xE9",
311
435
  intermediateIngredient: "Ingr\xE9dient interm\xE9diaire",
@@ -331,7 +455,7 @@ var fr3 = {
331
455
  viewLabel: "Vue :",
332
456
  loadExample: "Charger un exemple...",
333
457
  recipe: "Recette",
334
- scaleFactor: "Facteur d'\xE9chelle %",
458
+ scaleFactor: "Quantit\xE9s",
335
459
  examples: {
336
460
  canneles: "Cannel\xE9s Bordelais",
337
461
  empanadas: "Empanadas de Boeuf"
@@ -341,10 +465,29 @@ var fr3 = {
341
465
  ast: "AST (Brut)",
342
466
  jsonTree: "Arbre Interactif",
343
467
  markdown: "Markdown",
344
- preview: "Aper\xE7u (HTML)"
468
+ preview: "Aper\xE7u (HTML)",
469
+ gantt: "Diagramme de Gantt",
470
+ gantt_active: "T\xE2che active",
471
+ gantt_passive: "T\xE2che de fond",
472
+ gantt_compact: "Vue compacte",
473
+ gantt_time: "Temps",
474
+ gantt_cook: "Actions",
475
+ gantt_timer: "Minuteur",
476
+ gantt_prep: "Pr\xE9paration",
477
+ gantt_empty: "Aucune donn\xE9e temporelle disponible. \xC9crivez une recette avec des \xE9tapes et des dur\xE9es pour voir le diagramme.",
478
+ gantt_compressed: "Temps compress\xE9 (p\xE9riode d'inactivit\xE9)",
479
+ gantt_assembly: "Assemblage / D\xE9pendances",
480
+ gantt_more_sections: "+{count} autres...",
481
+ gantt_section: "Section",
482
+ gantt_mode_forward: "Chronom\xE8tre (T+)",
483
+ gantt_mode_reverse: "Compte \xE0 rebours (T-)",
484
+ gantt_mode_target: "Heure cible",
485
+ gantt_target_time_label: "Servir \xE0 :"
345
486
  },
346
487
  options: {
347
- scaleTitle: "Mettre \xE0 l'\xE9chelle par ingr\xE9dient",
488
+ scaleTitle: "Modifier les quantit\xE9s",
489
+ scaleGlobal: "Au global",
490
+ scaleByIngredient: "Par ingr\xE9dient",
348
491
  selectIngredient: "S\xE9lectionner un ingr\xE9dient...",
349
492
  qty: "Qt\xE9",
350
493
  unit: "Unit\xE9",
@@ -393,16 +536,21 @@ function getDictionary(lang) {
393
536
  return dictionaries[code] || en3;
394
537
  }
395
538
  export {
539
+ CATEGORY_KEYS,
396
540
  TIME_BY_LANG,
397
541
  TIME_DICTIONARIES,
398
542
  TIME_GLOBAL,
543
+ TIME_TO_MINUTES,
399
544
  UNIT_BY_LANG,
545
+ UNIT_CONVERSIONS,
400
546
  UNIT_DICTIONARIES,
401
547
  UNIT_GLOBAL,
402
548
  compileDictionary,
403
549
  getAiLanguageInstruction,
550
+ getCategoryLabels,
404
551
  getDefaultCategories,
405
552
  getDictionary,
553
+ isCategoryKey,
406
554
  normalizeUnit,
407
555
  resolveTimeUnit
408
556
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gram-lang/i18n",
3
- "version": "1.0.0-beta.3",
3
+ "version": "1.0.0-beta.5",
4
4
  "description": "Gram recipe i18n and unit normalization logic",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",