@gram-lang/i18n 1.2.0 → 1.3.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/dist/index.d.ts +10 -1
- package/dist/index.js +19 -4
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -21,6 +21,13 @@ declare const UNIT_DICTIONARIES: {
|
|
|
21
21
|
};
|
|
22
22
|
declare const UNIT_BY_LANG: Record<string, CompiledDict>;
|
|
23
23
|
declare const UNIT_GLOBAL: CompiledDict;
|
|
24
|
+
/**
|
|
25
|
+
* Spelling-insensitive lookup key for a unit: lowercased, diacritics stripped,
|
|
26
|
+
* and abbreviation punctuation / spaces removed, so "c.à.s", "c. à s.", "c.a.s"
|
|
27
|
+
* and "càs" all collapse to "cas". Only used to *find* a canonical unit --
|
|
28
|
+
* unknown units are still returned as the author wrote them.
|
|
29
|
+
*/
|
|
30
|
+
declare function unitKey(raw: string): string;
|
|
24
31
|
interface UnitMap {
|
|
25
32
|
base: string;
|
|
26
33
|
map: Record<string, number>;
|
|
@@ -226,6 +233,8 @@ declare const en: {
|
|
|
226
233
|
entryFile: string;
|
|
227
234
|
newFileName: string;
|
|
228
235
|
previewingStandalone: string;
|
|
236
|
+
openFiles: string;
|
|
237
|
+
hasErrors: string;
|
|
229
238
|
};
|
|
230
239
|
mobileTabs: {
|
|
231
240
|
editor: string;
|
|
@@ -245,4 +254,4 @@ type GramLocale = typeof en;
|
|
|
245
254
|
|
|
246
255
|
declare function getDictionary(lang?: string): GramLocale;
|
|
247
256
|
|
|
248
|
-
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, isCoarseUnit, normalizeUnit, resolveTimeUnit };
|
|
257
|
+
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, isCoarseUnit, normalizeUnit, resolveTimeUnit, unitKey };
|
package/dist/index.js
CHANGED
|
@@ -137,6 +137,14 @@ var fr2 = {
|
|
|
137
137
|
};
|
|
138
138
|
var UNIT_DICTIONARIES = { en: en2, fr: fr2 };
|
|
139
139
|
var { byLang: UNIT_BY_LANG, global: UNIT_GLOBAL } = compileDictionary(UNIT_DICTIONARIES);
|
|
140
|
+
function unitKey(raw) {
|
|
141
|
+
return raw.normalize("NFD").replace(/\p{M}/gu, "").toLowerCase().replace(/[.'’\s]/g, "");
|
|
142
|
+
}
|
|
143
|
+
var foldTable = (table) => Object.fromEntries(Object.entries(table).map(([k, v]) => [unitKey(k), v]));
|
|
144
|
+
var UNIT_BY_LANG_FOLDED = Object.fromEntries(
|
|
145
|
+
Object.entries(UNIT_BY_LANG).map(([lang, table]) => [lang, foldTable(table)])
|
|
146
|
+
);
|
|
147
|
+
var UNIT_GLOBAL_FOLDED = foldTable(UNIT_GLOBAL);
|
|
140
148
|
var UNIT_CONVERSIONS = {
|
|
141
149
|
mass: {
|
|
142
150
|
base: "g",
|
|
@@ -182,7 +190,9 @@ function normalizeUnit(rawUnit, lang) {
|
|
|
182
190
|
if (lang && UNIT_BY_LANG[lang]?.[clean]) {
|
|
183
191
|
return UNIT_BY_LANG[lang][clean];
|
|
184
192
|
}
|
|
185
|
-
|
|
193
|
+
if (UNIT_GLOBAL[clean]) return UNIT_GLOBAL[clean];
|
|
194
|
+
const key = unitKey(clean);
|
|
195
|
+
return lang && UNIT_BY_LANG_FOLDED[lang]?.[key] || UNIT_GLOBAL_FOLDED[key] || clean;
|
|
186
196
|
}
|
|
187
197
|
function isCoarseUnit(rawUnit) {
|
|
188
198
|
const normalized = normalizeUnit(rawUnit);
|
|
@@ -449,7 +459,9 @@ var en3 = {
|
|
|
449
459
|
renameFile: "Rename file",
|
|
450
460
|
entryFile: "Entry",
|
|
451
461
|
newFileName: "New file name",
|
|
452
|
-
previewingStandalone: "Standalone preview of"
|
|
462
|
+
previewingStandalone: "Standalone preview of",
|
|
463
|
+
openFiles: "Open files",
|
|
464
|
+
hasErrors: "has errors"
|
|
453
465
|
},
|
|
454
466
|
mobileTabs: {
|
|
455
467
|
editor: "Editor",
|
|
@@ -627,7 +639,9 @@ var fr3 = {
|
|
|
627
639
|
renameFile: "Renommer le fichier",
|
|
628
640
|
entryFile: "Entr\xE9e",
|
|
629
641
|
newFileName: "Nom du nouveau fichier",
|
|
630
|
-
previewingStandalone: "Aper\xE7u isol\xE9 de"
|
|
642
|
+
previewingStandalone: "Aper\xE7u isol\xE9 de",
|
|
643
|
+
openFiles: "Fichiers ouverts",
|
|
644
|
+
hasErrors: "contient des erreurs"
|
|
631
645
|
},
|
|
632
646
|
mobileTabs: {
|
|
633
647
|
editor: "\xC9diteur",
|
|
@@ -672,5 +686,6 @@ export {
|
|
|
672
686
|
isCategoryKey,
|
|
673
687
|
isCoarseUnit,
|
|
674
688
|
normalizeUnit,
|
|
675
|
-
resolveTimeUnit
|
|
689
|
+
resolveTimeUnit,
|
|
690
|
+
unitKey
|
|
676
691
|
};
|