@vielzeug/lingua 2.2.0 → 2.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/_catalog.cjs +1 -1
- package/dist/_catalog.cjs.map +1 -1
- package/dist/_catalog.d.ts +2 -1
- package/dist/_catalog.d.ts.map +1 -1
- package/dist/_catalog.js +15 -15
- package/dist/_catalog.js.map +1 -1
- package/dist/_resources.cjs +1 -1
- package/dist/_resources.js +9 -9
- package/dist/catalog.cjs +2 -0
- package/dist/catalog.cjs.map +1 -0
- package/dist/catalog.d.ts +27 -0
- package/dist/catalog.d.ts.map +1 -0
- package/dist/catalog.js +10 -0
- package/dist/catalog.js.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -3
- package/dist/lingua.cjs +1 -1
- package/dist/lingua.cjs.map +1 -1
- package/dist/lingua.iife.js +1 -1
- package/dist/lingua.iife.js.map +1 -1
- package/dist/lingua.js +1 -1
- package/dist/lingua.js.map +1 -1
- package/dist/translator.cjs +1 -1
- package/dist/translator.js +34 -34
- package/dist/types.d.ts +7 -8
- package/dist/types.d.ts.map +1 -1
- package/dist/validate.cjs +1 -1
- package/dist/validate.cjs.map +1 -1
- package/dist/validate.d.ts +13 -1
- package/dist/validate.d.ts.map +1 -1
- package/dist/validate.js +31 -13
- package/dist/validate.js.map +1 -1
- package/package.json +6 -1
package/dist/validate.js
CHANGED
|
@@ -1,28 +1,46 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { compileCatalog as e, isPluralMessage as t } from "./_catalog.js";
|
|
2
|
+
import { canonicalLocale as n } from "./_locale.js";
|
|
3
3
|
//#region src/validate.ts
|
|
4
|
-
function n(e) {
|
|
5
|
-
return typeof e == "object" && !!e && Object.hasOwn(e, "plural");
|
|
6
|
-
}
|
|
7
4
|
function r(r, i) {
|
|
8
|
-
|
|
9
|
-
let a =
|
|
5
|
+
e(r);
|
|
6
|
+
let a = n(i), o = new Intl.PluralRules(a).resolvedOptions().pluralCategories, s = [], c = (e, n) => {
|
|
10
7
|
if (typeof e != "string") {
|
|
11
|
-
if (
|
|
12
|
-
for (let
|
|
13
|
-
key:
|
|
8
|
+
if (t(e)) {
|
|
9
|
+
for (let t of o) Object.hasOwn(e.plural, t) || s.push({
|
|
10
|
+
key: n,
|
|
14
11
|
locale: a,
|
|
15
|
-
missing:
|
|
12
|
+
missing: t
|
|
16
13
|
});
|
|
17
14
|
return;
|
|
18
15
|
}
|
|
19
|
-
for (let [
|
|
16
|
+
for (let [t, r] of Object.entries(e)) c(r, n ? `${n}.${t}` : t);
|
|
20
17
|
}
|
|
21
18
|
};
|
|
22
19
|
for (let [e, t] of Object.entries(r)) c(t, e);
|
|
23
20
|
return s;
|
|
24
21
|
}
|
|
22
|
+
function i(t) {
|
|
23
|
+
let n = Object.keys(t), r = /* @__PURE__ */ new Map(), i = [], a = [];
|
|
24
|
+
for (let i of n) r.set(i, new Set(e(t[i]).keys()));
|
|
25
|
+
let o = n[0], s = r.get(o);
|
|
26
|
+
for (let e of n) {
|
|
27
|
+
if (e === o) continue;
|
|
28
|
+
let t = r.get(e);
|
|
29
|
+
for (let n of s) t.has(n) || i.push({
|
|
30
|
+
key: n,
|
|
31
|
+
locale: e
|
|
32
|
+
});
|
|
33
|
+
for (let n of t) s.has(n) || a.push({
|
|
34
|
+
key: n,
|
|
35
|
+
locale: e
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
extra: a,
|
|
40
|
+
missing: i
|
|
41
|
+
};
|
|
42
|
+
}
|
|
25
43
|
//#endregion
|
|
26
|
-
export { r as validateCatalog };
|
|
44
|
+
export { i as compareCatalogs, r as validateCatalog };
|
|
27
45
|
|
|
28
46
|
//# sourceMappingURL=validate.js.map
|
package/dist/validate.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate.js","names":[],"sources":["../src/validate.ts"],"sourcesContent":["import { compileCatalog } from './_catalog';\nimport { canonicalLocale } from './_locale';\nimport type { Catalog, CatalogNode,
|
|
1
|
+
{"version":3,"file":"validate.js","names":[],"sources":["../src/validate.ts"],"sourcesContent":["import { compileCatalog, isPluralMessage } from './_catalog';\nimport { canonicalLocale } from './_locale';\nimport type { Catalog, CatalogNode, Catalogs, Locale } from './types';\n\nexport type ValidationIssue = {\n key: string;\n locale: Locale;\n missing: Intl.LDMLPluralRule;\n};\n\nexport type CatalogComparison = {\n readonly missing: ReadonlyArray<{ key: string; locale: Locale }>;\n readonly extra: ReadonlyArray<{ key: string; locale: Locale }>;\n};\n\n/** Explicit tooling API. Runtime never loads validation code or emits asynchronous catalog warnings. */\nexport function validateCatalog(catalog: Catalog, locale: Locale): ValidationIssue[] {\n compileCatalog(catalog);\n\n const canonical = canonicalLocale(locale);\n const categories = new Intl.PluralRules(canonical).resolvedOptions().pluralCategories;\n const issues: ValidationIssue[] = [];\n\n const visit = (node: CatalogNode, key: string): void => {\n if (typeof node === 'string') return;\n\n if (isPluralMessage(node)) {\n for (const missing of categories) {\n if (!Object.hasOwn(node.plural, missing)) issues.push({ key, locale: canonical, missing });\n }\n\n return;\n }\n\n for (const [childKey, child] of Object.entries(node)) visit(child, key ? `${key}.${childKey}` : childKey);\n };\n\n for (const [key, node] of Object.entries(catalog)) visit(node, key);\n\n return issues;\n}\n\n/** Compares catalog key sets across locales. Reports keys missing in each target locale and keys present in targets but absent from the base. */\nexport function compareCatalogs<C extends Catalog>(catalogs: Catalogs<C>): CatalogComparison {\n const locales = Object.keys(catalogs);\n const keySets = new Map<Locale, Set<string>>();\n const missing: Array<{ key: string; locale: Locale }> = [];\n const extra: Array<{ key: string; locale: Locale }> = [];\n\n for (const locale of locales) {\n keySets.set(locale, new Set(compileCatalog(catalogs[locale]).keys()));\n }\n\n const base = locales[0];\n const baseKeys = keySets.get(base)!;\n\n for (const locale of locales) {\n if (locale === base) continue;\n const targetKeys = keySets.get(locale)!;\n\n for (const key of baseKeys) {\n if (!targetKeys.has(key)) missing.push({ key, locale });\n }\n\n for (const key of targetKeys) {\n if (!baseKeys.has(key)) extra.push({ key, locale });\n }\n }\n\n return { extra, missing };\n}\n"],"mappings":";;;AAgBA,SAAgB,EAAgB,GAAkB,GAAmC;CACnF,EAAe,CAAO;CAEtB,IAAM,IAAY,EAAgB,CAAM,GAClC,IAAa,IAAI,KAAK,YAAY,CAAS,CAAC,CAAC,gBAAgB,CAAC,CAAC,kBAC/D,IAA4B,CAAC,GAE7B,KAAS,GAAmB,MAAsB;EAClD,WAAO,KAAS,UAEpB;OAAI,EAAgB,CAAI,GAAG;IACzB,KAAK,IAAM,KAAW,GACpB,AAAK,OAAO,OAAO,EAAK,QAAQ,CAAO,KAAG,EAAO,KAAK;KAAE;KAAK,QAAQ;KAAW;IAAQ,CAAC;IAG3F;GACF;GAEA,KAAK,IAAM,CAAC,GAAU,MAAU,OAAO,QAAQ,CAAI,GAAG,EAAM,GAAO,IAAM,GAAG,EAAI,GAAG,MAAa,CAAQ;EAFxG;CAGF;CAEA,KAAK,IAAM,CAAC,GAAK,MAAS,OAAO,QAAQ,CAAO,GAAG,EAAM,GAAM,CAAG;CAElE,OAAO;AACT;AAGA,SAAgB,EAAmC,GAA0C;CAC3F,IAAM,IAAU,OAAO,KAAK,CAAQ,GAC9B,oBAAU,IAAI,IAAyB,GACvC,IAAkD,CAAC,GACnD,IAAgD,CAAC;CAEvD,KAAK,IAAM,KAAU,GACnB,EAAQ,IAAI,GAAQ,IAAI,IAAI,EAAe,EAAS,EAAO,CAAC,CAAC,KAAK,CAAC,CAAC;CAGtE,IAAM,IAAO,EAAQ,IACf,IAAW,EAAQ,IAAI,CAAI;CAEjC,KAAK,IAAM,KAAU,GAAS;EAC5B,IAAI,MAAW,GAAM;EACrB,IAAM,IAAa,EAAQ,IAAI,CAAM;EAErC,KAAK,IAAM,KAAO,GAChB,AAAK,EAAW,IAAI,CAAG,KAAG,EAAQ,KAAK;GAAE;GAAK;EAAO,CAAC;EAGxD,KAAK,IAAM,KAAO,GAChB,AAAK,EAAS,IAAI,CAAG,KAAG,EAAM,KAAK;GAAE;GAAK;EAAO,CAAC;CAEtD;CAEA,OAAO;EAAE;EAAO;CAAQ;AAC1B"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vielzeug/lingua",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"description": "Explicit typed localization with pluralization, lazy locale catalogs, and SSR hydration",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/helmuthdu/vielzeug",
|
|
8
|
+
"directory": "packages/lingua"
|
|
9
|
+
},
|
|
5
10
|
"type": "module",
|
|
6
11
|
"engines": {
|
|
7
12
|
"node": ">=22"
|