@gram-lang/i18n 1.0.0-beta.4 → 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: {
@@ -125,6 +145,8 @@ declare const en: {
125
145
  };
126
146
  options: {
127
147
  scaleTitle: string;
148
+ scaleGlobal: string;
149
+ scaleByIngredient: string;
128
150
  selectIngredient: string;
129
151
  qty: string;
130
152
  unit: string;
@@ -165,4 +187,4 @@ type GramLocale = typeof en;
165
187
 
166
188
  declare function getDictionary(lang?: string): GramLocale;
167
189
 
168
- 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
@@ -33,6 +33,12 @@ var fr = {
33
33
  };
34
34
  var TIME_DICTIONARIES = { en, fr };
35
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
+ };
36
42
  var resolveTimeUnit = (unit, lang) => {
37
43
  if (!unit) return "";
38
44
  const clean = unit.trim().toLowerCase();
@@ -56,7 +62,13 @@ var en2 = {
56
62
  // Volume — cups & imperial
57
63
  cup: ["cups"],
58
64
  pt: ["pint", "pints"],
59
- 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"],
60
72
  "fl oz": ["floz", "fl. oz.", "fluid ounce", "fluid ounces"],
61
73
  // Volume — metric
62
74
  ml: ["milliliter", "milliliters"],
@@ -97,26 +109,73 @@ var fr2 = {
97
109
  pinch: ["pinc\xE9e", "pincee", "pinc\xE9es", "pincees"],
98
110
  smidgen: ["poussi\xE8re", "poussiere", "poussi\xE8res", "poussieres"],
99
111
  drop: ["goutte", "gouttes"],
100
- // Volume — tasse & mesures anglo-saxonnes
101
- cup: ["tasse", "tasses"],
102
- pt: ["pinte", "pintes"],
103
- 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.
104
117
  "fl oz": ["once liquide", "onces liquides"],
105
118
  // Volume — métrique
106
119
  ml: ["millilitre", "millilitres"],
107
120
  cl: ["centilitre", "centilitres"],
108
121
  dl: ["d\xE9cilitre", "d\xE9cilitres", "decilitre", "decilitres"],
109
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"],
110
127
  // Poids — métrique
111
128
  mg: ["milligramme", "milligrammes"],
112
129
  g: ["gramme", "grammes"],
113
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"],
114
135
  // Poids — impérial
115
- oz: ["once", "onces"],
116
- lb: ["livre", "livres"]
136
+ oz: ["once", "onces"]
117
137
  };
118
138
  var UNIT_DICTIONARIES = { en: en2, fr: fr2 };
119
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
+ };
120
179
  function normalizeUnit(rawUnit, lang) {
121
180
  if (!rawUnit) return "";
122
181
  const clean = rawUnit.toLowerCase().trim();
@@ -144,44 +203,68 @@ function getAiLanguageInstruction(lang = "en") {
144
203
  }
145
204
 
146
205
  // src/categories.ts
147
- var CATEGORIES = {
148
- fr: [
149
- "L\xE9gumes",
150
- "Fruits",
151
- "Viandes",
152
- "Poissons & Fruits de mer",
153
- "Cr\xE9merie",
154
- "C\xE9r\xE9ales",
155
- "L\xE9gumineuses",
156
- "Noix & Graines",
157
- "Huiles",
158
- "Herbes",
159
- "\xC9pices",
160
- "Condiments",
161
- "Sucres",
162
- "Boissons",
163
- "Autres"
164
- ],
165
- en: [
166
- "Vegetables",
167
- "Fruits",
168
- "Meat",
169
- "Seafood",
170
- "Dairy",
171
- "Grains",
172
- "Legumes",
173
- "Nuts",
174
- "Oils",
175
- "Herbs",
176
- "Spices",
177
- "Condiments",
178
- "Sugars",
179
- "Beverages",
180
- "Other"
181
- ]
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
+ }
182
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
+ }
183
265
  function getDefaultCategories(lang = "en") {
184
- return CATEGORIES[lang] ?? CATEGORIES.en;
266
+ const labels = getCategoryLabels(lang);
267
+ return CATEGORY_KEYS.map((key) => labels[key]);
185
268
  }
186
269
 
187
270
  // src/locales/en.ts
@@ -273,7 +356,9 @@ var en3 = {
273
356
  gantt_target_time_label: "Serve at:"
274
357
  },
275
358
  options: {
276
- scaleTitle: "Scale by Ingredient",
359
+ scaleTitle: "Modify Quantities",
360
+ scaleGlobal: "Overall Scale",
361
+ scaleByIngredient: "By Ingredient",
277
362
  selectIngredient: "Select ingredient...",
278
363
  qty: "Qty",
279
364
  unit: "Unit",
@@ -370,7 +455,7 @@ var fr3 = {
370
455
  viewLabel: "Vue :",
371
456
  loadExample: "Charger un exemple...",
372
457
  recipe: "Recette",
373
- scaleFactor: "Facteur d'\xE9chelle %",
458
+ scaleFactor: "Quantit\xE9s",
374
459
  examples: {
375
460
  canneles: "Cannel\xE9s Bordelais",
376
461
  empanadas: "Empanadas de Boeuf"
@@ -400,7 +485,9 @@ var fr3 = {
400
485
  gantt_target_time_label: "Servir \xE0 :"
401
486
  },
402
487
  options: {
403
- scaleTitle: "Mettre \xE0 l'\xE9chelle par ingr\xE9dient",
488
+ scaleTitle: "Modifier les quantit\xE9s",
489
+ scaleGlobal: "Au global",
490
+ scaleByIngredient: "Par ingr\xE9dient",
404
491
  selectIngredient: "S\xE9lectionner un ingr\xE9dient...",
405
492
  qty: "Qt\xE9",
406
493
  unit: "Unit\xE9",
@@ -449,16 +536,21 @@ function getDictionary(lang) {
449
536
  return dictionaries[code] || en3;
450
537
  }
451
538
  export {
539
+ CATEGORY_KEYS,
452
540
  TIME_BY_LANG,
453
541
  TIME_DICTIONARIES,
454
542
  TIME_GLOBAL,
543
+ TIME_TO_MINUTES,
455
544
  UNIT_BY_LANG,
545
+ UNIT_CONVERSIONS,
456
546
  UNIT_DICTIONARIES,
457
547
  UNIT_GLOBAL,
458
548
  compileDictionary,
459
549
  getAiLanguageInstruction,
550
+ getCategoryLabels,
460
551
  getDefaultCategories,
461
552
  getDictionary,
553
+ isCategoryKey,
462
554
  normalizeUnit,
463
555
  resolveTimeUnit
464
556
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gram-lang/i18n",
3
- "version": "1.0.0-beta.4",
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",