@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 CHANGED
@@ -1,2 +1,2 @@
1
- const e=require("./errors.cjs"),t=require("./_template.cjs");var n=new Set([`__proto__`,`constructor`,`prototype`]);function r(e){return typeof e==`object`&&!!e&&Object.hasOwn(e,`plural`)}function i(i){let a=new Map,o=(i,s)=>{if(typeof i==`string`){a.set(s,{kind:`text`,template:t.compileTemplate(i)});return}if(typeof i!=`object`||!i||Array.isArray(i))throw new e.LinguaInvalidCatalogError(`Catalog node "${s}" must be a string, plural message, or object.`);if(r(i)){if(Reflect.ownKeys(i).some(e=>e!==`plural`))throw new e.LinguaInvalidCatalogError(`Plural message "${s}" must contain only a "plural" property.`);if(typeof i.plural!=`object`||i.plural===null||Array.isArray(i.plural))throw new e.LinguaInvalidCatalogError(`Plural message "${s}" must provide an object of string forms.`);let n=new Map;for(let[r,a]of Object.entries(i.plural)){if(typeof a!=`string`)throw new e.LinguaInvalidCatalogError(`Plural form "${s}.${r}" must be a string.`);n.set(r,t.compileTemplate(a))}a.set(s,{forms:n,kind:`plural`});return}for(let[t,r]of Object.entries(i)){if(n.has(t))throw new e.LinguaInvalidCatalogError(`Catalog key "${t}" is reserved.`);o(r,s?`${s}.${t}`:t)}};for(let[t,r]of Object.entries(i)){if(n.has(t))throw new e.LinguaInvalidCatalogError(`Catalog key "${t}" is reserved.`);o(r,t)}return a}exports.compileCatalog=i;
1
+ const e=require("./_template.cjs"),t=require("./errors.cjs");var n=new Set([`__proto__`,`constructor`,`prototype`]);function r(e){return typeof e==`object`&&!!e&&Object.hasOwn(e,`plural`)}function i(i){let a=new Map,o=(i,s)=>{if(typeof i==`string`){a.set(s,{kind:`text`,template:e.compileTemplate(i)});return}if(typeof i!=`object`||!i||Array.isArray(i))throw new t.LinguaInvalidCatalogError(`Catalog node "${s}" must be a string, plural message, or object.`);if(r(i)){if(Reflect.ownKeys(i).some(e=>e!==`plural`))throw new t.LinguaInvalidCatalogError(`Plural message "${s}" must contain only a "plural" property.`);if(typeof i.plural!=`object`||i.plural===null||Array.isArray(i.plural))throw new t.LinguaInvalidCatalogError(`Plural message "${s}" must provide an object of string forms.`);let n=new Map;for(let[r,a]of Object.entries(i.plural)){if(typeof a!=`string`)throw new t.LinguaInvalidCatalogError(`Plural form "${s}.${r}" must be a string.`);n.set(r,e.compileTemplate(a))}a.set(s,{forms:n,kind:`plural`});return}for(let[e,r]of Object.entries(i)){if(n.has(e))throw new t.LinguaInvalidCatalogError(`Catalog key "${e}" is reserved.`);o(r,s?`${s}.${e}`:e)}};for(let[e,r]of Object.entries(i)){if(n.has(e))throw new t.LinguaInvalidCatalogError(`Catalog key "${e}" is reserved.`);o(r,e)}return a}exports.compileCatalog=i,exports.isPluralMessage=r;
2
2
  //# sourceMappingURL=_catalog.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"_catalog.cjs","names":[],"sources":["../src/_catalog.ts"],"sourcesContent":["import { compileTemplate, type Template } from './_template';\nimport { LinguaInvalidCatalogError } from './errors';\nimport type { Catalog, CatalogNode, PluralMessage } from './types';\n\nconst unsafeKeys = new Set(['__proto__', 'constructor', 'prototype']);\n\nexport type CompiledText = { readonly kind: 'text'; readonly template: Template };\nexport type CompiledPlural = { readonly forms: ReadonlyMap<string, Template>; readonly kind: 'plural' };\nexport type CompiledMessage = CompiledPlural | CompiledText;\nexport type CompiledCatalog = ReadonlyMap<string, CompiledMessage>;\n\nfunction isPluralMessage(node: CatalogNode): node is PluralMessage {\n return typeof node === 'object' && node !== null && Object.hasOwn(node, 'plural');\n}\n\n/** Compile explicit catalog nodes once. Nested objects only group keys; plural intent is never inferred. */\nexport function compileCatalog(catalog: Catalog): CompiledCatalog {\n const messages = new Map<string, CompiledMessage>();\n\n const visit = (node: CatalogNode, prefix: string): void => {\n if (typeof node === 'string') {\n messages.set(prefix, { kind: 'text', template: compileTemplate(node) });\n\n return;\n }\n\n if (typeof node !== 'object' || node === null || Array.isArray(node)) {\n throw new LinguaInvalidCatalogError(`Catalog node \"${prefix}\" must be a string, plural message, or object.`);\n }\n\n if (isPluralMessage(node)) {\n if (Reflect.ownKeys(node).some((key) => key !== 'plural')) {\n throw new LinguaInvalidCatalogError(`Plural message \"${prefix}\" must contain only a \"plural\" property.`);\n }\n\n if (typeof node.plural !== 'object' || node.plural === null || Array.isArray(node.plural)) {\n throw new LinguaInvalidCatalogError(`Plural message \"${prefix}\" must provide an object of string forms.`);\n }\n\n const forms = new Map<string, Template>();\n\n for (const [form, template] of Object.entries(node.plural)) {\n if (typeof template !== 'string') {\n throw new LinguaInvalidCatalogError(`Plural form \"${prefix}.${form}\" must be a string.`);\n }\n\n forms.set(form, compileTemplate(template));\n }\n\n messages.set(prefix, { forms, kind: 'plural' });\n\n return;\n }\n\n for (const [key, value] of Object.entries(node)) {\n if (unsafeKeys.has(key)) {\n throw new LinguaInvalidCatalogError(`Catalog key \"${key}\" is reserved.`);\n }\n\n visit(value, prefix ? `${prefix}.${key}` : key);\n }\n };\n\n for (const [key, value] of Object.entries(catalog)) {\n if (unsafeKeys.has(key)) throw new LinguaInvalidCatalogError(`Catalog key \"${key}\" is reserved.`);\n\n visit(value, key);\n }\n\n return messages;\n}\n"],"mappings":"6DAIA,IAAM,EAAa,IAAI,IAAI,CAAC,YAAa,cAAe,WAAW,CAAC,EAOpE,SAAS,EAAgB,EAA0C,CACjE,OAAO,OAAO,GAAS,YAAY,GAAiB,OAAO,OAAO,EAAM,QAAQ,CAClF,CAGA,SAAgB,EAAe,EAAmC,CAChE,IAAM,EAAW,IAAI,IAEf,GAAS,EAAmB,IAAyB,CACzD,GAAI,OAAO,GAAS,SAAU,CAC5B,EAAS,IAAI,EAAQ,CAAE,KAAM,OAAQ,SAAU,EAAA,gBAAgB,CAAI,CAAE,CAAC,EAEtE,MACF,CAEA,GAAI,OAAO,GAAS,WAAY,GAAiB,MAAM,QAAQ,CAAI,EACjE,MAAM,IAAI,EAAA,0BAA0B,iBAAiB,EAAO,+CAA+C,EAG7G,GAAI,EAAgB,CAAI,EAAG,CACzB,GAAI,QAAQ,QAAQ,CAAI,CAAC,CAAC,KAAM,GAAQ,IAAQ,QAAQ,EACtD,MAAM,IAAI,EAAA,0BAA0B,mBAAmB,EAAO,yCAAyC,EAGzG,GAAI,OAAO,EAAK,QAAW,UAAY,EAAK,SAAW,MAAQ,MAAM,QAAQ,EAAK,MAAM,EACtF,MAAM,IAAI,EAAA,0BAA0B,mBAAmB,EAAO,0CAA0C,EAG1G,IAAM,EAAQ,IAAI,IAElB,IAAK,GAAM,CAAC,EAAM,KAAa,OAAO,QAAQ,EAAK,MAAM,EAAG,CAC1D,GAAI,OAAO,GAAa,SACtB,MAAM,IAAI,EAAA,0BAA0B,gBAAgB,EAAO,GAAG,EAAK,oBAAoB,EAGzF,EAAM,IAAI,EAAM,EAAA,gBAAgB,CAAQ,CAAC,CAC3C,CAEA,EAAS,IAAI,EAAQ,CAAE,QAAO,KAAM,QAAS,CAAC,EAE9C,MACF,CAEA,IAAK,GAAM,CAAC,EAAK,KAAU,OAAO,QAAQ,CAAI,EAAG,CAC/C,GAAI,EAAW,IAAI,CAAG,EACpB,MAAM,IAAI,EAAA,0BAA0B,gBAAgB,EAAI,eAAe,EAGzE,EAAM,EAAO,EAAS,GAAG,EAAO,GAAG,IAAQ,CAAG,CAChD,CACF,EAEA,IAAK,GAAM,CAAC,EAAK,KAAU,OAAO,QAAQ,CAAO,EAAG,CAClD,GAAI,EAAW,IAAI,CAAG,EAAG,MAAM,IAAI,EAAA,0BAA0B,gBAAgB,EAAI,eAAe,EAEhG,EAAM,EAAO,CAAG,CAClB,CAEA,OAAO,CACT"}
1
+ {"version":3,"file":"_catalog.cjs","names":[],"sources":["../src/_catalog.ts"],"sourcesContent":["import { compileTemplate, type Template } from './_template';\nimport { LinguaInvalidCatalogError } from './errors';\nimport type { Catalog, CatalogNode, PluralMessage } from './types';\n\nconst unsafeKeys = new Set(['__proto__', 'constructor', 'prototype']);\n\nexport type CompiledText = { readonly kind: 'text'; readonly template: Template };\nexport type CompiledPlural = { readonly forms: ReadonlyMap<string, Template>; readonly kind: 'plural' };\nexport type CompiledMessage = CompiledPlural | CompiledText;\nexport type CompiledCatalog = ReadonlyMap<string, CompiledMessage>;\n\nexport function isPluralMessage(node: CatalogNode): node is PluralMessage {\n return typeof node === 'object' && node !== null && Object.hasOwn(node, 'plural');\n}\n\n/** Compile explicit catalog nodes once. Nested objects only group keys; plural intent is never inferred. */\nexport function compileCatalog(catalog: Catalog): CompiledCatalog {\n const messages = new Map<string, CompiledMessage>();\n\n const visit = (node: CatalogNode, prefix: string): void => {\n if (typeof node === 'string') {\n messages.set(prefix, { kind: 'text', template: compileTemplate(node) });\n\n return;\n }\n\n if (typeof node !== 'object' || node === null || Array.isArray(node)) {\n throw new LinguaInvalidCatalogError(`Catalog node \"${prefix}\" must be a string, plural message, or object.`);\n }\n\n if (isPluralMessage(node)) {\n if (Reflect.ownKeys(node).some((key) => key !== 'plural')) {\n throw new LinguaInvalidCatalogError(`Plural message \"${prefix}\" must contain only a \"plural\" property.`);\n }\n\n if (typeof node.plural !== 'object' || node.plural === null || Array.isArray(node.plural)) {\n throw new LinguaInvalidCatalogError(`Plural message \"${prefix}\" must provide an object of string forms.`);\n }\n\n const forms = new Map<string, Template>();\n\n for (const [form, template] of Object.entries(node.plural)) {\n if (typeof template !== 'string') {\n throw new LinguaInvalidCatalogError(`Plural form \"${prefix}.${form}\" must be a string.`);\n }\n\n forms.set(form, compileTemplate(template));\n }\n\n messages.set(prefix, { forms, kind: 'plural' });\n\n return;\n }\n\n for (const [key, value] of Object.entries(node)) {\n if (unsafeKeys.has(key)) {\n throw new LinguaInvalidCatalogError(`Catalog key \"${key}\" is reserved.`);\n }\n\n visit(value, prefix ? `${prefix}.${key}` : key);\n }\n };\n\n for (const [key, value] of Object.entries(catalog)) {\n if (unsafeKeys.has(key)) throw new LinguaInvalidCat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AAW,IAAI,CAAG,EACpB,MAAM,IAAI,EAAA,0BAA0B,gBAAgB,EAAI,eAAe,EAGzE,EAAM,EAAO,EAAS,GAAG,EAAO,GAAG,IAAQ,CAAG,CAChD,CACF,EAEA,IAAK,GAAM,CAAC,EAAK,KAAU,OAAO,QAAQ,CAAO,EAAG,CAClD,GAAI,EAAW,IAAI,CAAG,EAAG,MAAM,IAAI,EAAA,0BAA0B,gBAAgB,EAAI,eAAe,EAEhG,EAAM,EAAO,CAAG,CAClB,CAEA,OAAO,CACT"}
@@ -1,5 +1,5 @@
1
1
  import { type Template } from './_template';
2
- import type { Catalog } from './types';
2
+ import type { Catalog, CatalogNode, PluralMessage } from './types';
3
3
  export type CompiledText = {
4
4
  readonly kind: 'text';
5
5
  readonly template: Template;
@@ -10,6 +10,7 @@ export type CompiledPlural = {
10
10
  };
11
11
  export type CompiledMessage = CompiledPlural | CompiledText;
12
12
  export type CompiledCatalog = ReadonlyMap<string, CompiledMessage>;
13
+ export declare function isPluralMessage(node: CatalogNode): node is PluralMessage;
13
14
  /** Compile explicit catalog nodes once. Nested objects only group keys; plural intent is never inferred. */
14
15
  export declare function compileCatalog(catalog: Catalog): CompiledCatalog;
15
16
  //# sourceMappingURL=_catalog.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"_catalog.d.ts","sourceRoot":"","sources":["../src/_catalog.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,KAAK,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE7D,OAAO,KAAK,EAAE,OAAO,EAA8B,MAAM,SAAS,CAAC;AAInE,MAAM,MAAM,YAAY,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAA;CAAE,CAAC;AAClF,MAAM,MAAM,cAAc,GAAG;IAAE,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAA;CAAE,CAAC;AACxG,MAAM,MAAM,eAAe,GAAG,cAAc,GAAG,YAAY,CAAC;AAC5D,MAAM,MAAM,eAAe,GAAG,WAAW,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;AAMnE,4GAA4G;AAC5G,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,GAAG,eAAe,CAsDhE"}
1
+ {"version":3,"file":"_catalog.d.ts","sourceRoot":"","sources":["../src/_catalog.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,KAAK,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE7D,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAInE,MAAM,MAAM,YAAY,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAA;CAAE,CAAC;AAClF,MAAM,MAAM,cAAc,GAAG;IAAE,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAA;CAAE,CAAC;AACxG,MAAM,MAAM,eAAe,GAAG,cAAc,GAAG,YAAY,CAAC;AAC5D,MAAM,MAAM,eAAe,GAAG,WAAW,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;AAEnE,wBAAgB,eAAe,CAAC,IAAI,EAAE,WAAW,GAAG,IAAI,IAAI,aAAa,CAExE;AAED,4GAA4G;AAC5G,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,GAAG,eAAe,CAsDhE"}
package/dist/_catalog.js CHANGED
@@ -1,5 +1,5 @@
1
- import { LinguaInvalidCatalogError as e } from "./errors.js";
2
- import { compileTemplate as t } from "./_template.js";
1
+ import { compileTemplate as e } from "./_template.js";
2
+ import { LinguaInvalidCatalogError as t } from "./errors.js";
3
3
  //#region src/_catalog.ts
4
4
  var n = /* @__PURE__ */ new Set([
5
5
  "__proto__",
@@ -14,18 +14,18 @@ function i(i) {
14
14
  if (typeof i == "string") {
15
15
  a.set(s, {
16
16
  kind: "text",
17
- template: t(i)
17
+ template: e(i)
18
18
  });
19
19
  return;
20
20
  }
21
- if (typeof i != "object" || !i || Array.isArray(i)) throw new e(`Catalog node "${s}" must be a string, plural message, or object.`);
21
+ if (typeof i != "object" || !i || Array.isArray(i)) throw new t(`Catalog node "${s}" must be a string, plural message, or object.`);
22
22
  if (r(i)) {
23
- if (Reflect.ownKeys(i).some((e) => e !== "plural")) throw new e(`Plural message "${s}" must contain only a "plural" property.`);
24
- if (typeof i.plural != "object" || i.plural === null || Array.isArray(i.plural)) throw new e(`Plural message "${s}" must provide an object of string forms.`);
23
+ if (Reflect.ownKeys(i).some((e) => e !== "plural")) throw new t(`Plural message "${s}" must contain only a "plural" property.`);
24
+ if (typeof i.plural != "object" || i.plural === null || Array.isArray(i.plural)) throw new t(`Plural message "${s}" must provide an object of string forms.`);
25
25
  let n = /* @__PURE__ */ new Map();
26
26
  for (let [r, a] of Object.entries(i.plural)) {
27
- if (typeof a != "string") throw new e(`Plural form "${s}.${r}" must be a string.`);
28
- n.set(r, t(a));
27
+ if (typeof a != "string") throw new t(`Plural form "${s}.${r}" must be a string.`);
28
+ n.set(r, e(a));
29
29
  }
30
30
  a.set(s, {
31
31
  forms: n,
@@ -33,18 +33,18 @@ function i(i) {
33
33
  });
34
34
  return;
35
35
  }
36
- for (let [t, r] of Object.entries(i)) {
37
- if (n.has(t)) throw new e(`Catalog key "${t}" is reserved.`);
38
- o(r, s ? `${s}.${t}` : t);
36
+ for (let [e, r] of Object.entries(i)) {
37
+ if (n.has(e)) throw new t(`Catalog key "${e}" is reserved.`);
38
+ o(r, s ? `${s}.${e}` : e);
39
39
  }
40
40
  };
41
- for (let [t, r] of Object.entries(i)) {
42
- if (n.has(t)) throw new e(`Catalog key "${t}" is reserved.`);
43
- o(r, t);
41
+ for (let [e, r] of Object.entries(i)) {
42
+ if (n.has(e)) throw new t(`Catalog key "${e}" is reserved.`);
43
+ o(r, e);
44
44
  }
45
45
  return a;
46
46
  }
47
47
  //#endregion
48
- export { i as compileCatalog };
48
+ export { i as compileCatalog, r as isPluralMessage };
49
49
 
50
50
  //# sourceMappingURL=_catalog.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"_catalog.js","names":[],"sources":["../src/_catalog.ts"],"sourcesContent":["import { compileTemplate, type Template } from './_template';\nimport { LinguaInvalidCatalogError } from './errors';\nimport type { Catalog, CatalogNode, PluralMessage } from './types';\n\nconst unsafeKeys = new Set(['__proto__', 'constructor', 'prototype']);\n\nexport type CompiledText = { readonly kind: 'text'; readonly template: Template };\nexport type CompiledPlural = { readonly forms: ReadonlyMap<string, Template>; readonly kind: 'plural' };\nexport type CompiledMessage = CompiledPlural | CompiledText;\nexport type CompiledCatalog = ReadonlyMap<string, CompiledMessage>;\n\nfunction isPluralMessage(node: CatalogNode): node is PluralMessage {\n return typeof node === 'object' && node !== null && Object.hasOwn(node, 'plural');\n}\n\n/** Compile explicit catalog nodes once. Nested objects only group keys; plural intent is never inferred. */\nexport function compileCatalog(catalog: Catalog): CompiledCatalog {\n const messages = new Map<string, CompiledMessage>();\n\n const visit = (node: CatalogNode, prefix: string): void => {\n if (typeof node === 'string') {\n messages.set(prefix, { kind: 'text', template: compileTemplate(node) });\n\n return;\n }\n\n if (typeof node !== 'object' || node === null || Array.isArray(node)) {\n throw new LinguaInvalidCatalogError(`Catalog node \"${prefix}\" must be a string, plural message, or object.`);\n }\n\n if (isPluralMessage(node)) {\n if (Reflect.ownKeys(node).some((key) => key !== 'plural')) {\n throw new LinguaInvalidCatalogError(`Plural message \"${prefix}\" must contain only a \"plural\" property.`);\n }\n\n if (typeof node.plural !== 'object' || node.plural === null || Array.isArray(node.plural)) {\n throw new LinguaInvalidCatalogError(`Plural message \"${prefix}\" must provide an object of string forms.`);\n }\n\n const forms = new Map<string, Template>();\n\n for (const [form, template] of Object.entries(node.plural)) {\n if (typeof template !== 'string') {\n throw new LinguaInvalidCatalogError(`Plural form \"${prefix}.${form}\" must be a string.`);\n }\n\n forms.set(form, compileTemplate(template));\n }\n\n messages.set(prefix, { forms, kind: 'plural' });\n\n return;\n }\n\n for (const [key, value] of Object.entries(node)) {\n if (unsafeKeys.has(key)) {\n throw new LinguaInvalidCatalogError(`Catalog key \"${key}\" is reserved.`);\n }\n\n visit(value, prefix ? `${prefix}.${key}` : key);\n }\n };\n\n for (const [key, value] of Object.entries(catalog)) {\n if (unsafeKeys.has(key)) throw new LinguaInvalidCatalogError(`Catalog key \"${key}\" is reserved.`);\n\n visit(value, key);\n }\n\n return messages;\n}\n"],"mappings":";;;AAIA,IAAM,oBAAa,IAAI,IAAI;CAAC;CAAa;CAAe;AAAW,CAAC;AAOpE,SAAS,EAAgB,GAA0C;CACjE,OAAO,OAAO,KAAS,cAAY,KAAiB,OAAO,OAAO,GAAM,QAAQ;AAClF;AAGA,SAAgB,EAAe,GAAmC;CAChE,IAAM,oBAAW,IAAI,IAA6B,GAE5C,KAAS,GAAmB,MAAyB;EACzD,IAAI,OAAO,KAAS,UAAU;GAC5B,EAAS,IAAI,GAAQ;IAAE,MAAM;IAAQ,UAAU,EAAgB,CAAI;GAAE,CAAC;GAEtE;EACF;EAEA,IAAI,OAAO,KAAS,aAAY,KAAiB,MAAM,QAAQ,CAAI,GACjE,MAAM,IAAI,EAA0B,iBAAiB,EAAO,+CAA+C;EAG7G,IAAI,EAAgB,CAAI,GAAG;GACzB,IAAI,QAAQ,QAAQ,CAAI,CAAC,CAAC,MAAM,MAAQ,MAAQ,QAAQ,GACtD,MAAM,IAAI,EAA0B,mBAAmB,EAAO,yCAAyC;GAGzG,IAAI,OAAO,EAAK,UAAW,YAAY,EAAK,WAAW,QAAQ,MAAM,QAAQ,EAAK,MAAM,GACtF,MAAM,IAAI,EAA0B,mBAAmB,EAAO,0CAA0C;GAG1G,IAAM,oBAAQ,IAAI,IAAsB;GAExC,KAAK,IAAM,CAAC,GAAM,MAAa,OAAO,QAAQ,EAAK,MAAM,GAAG;IAC1D,IAAI,OAAO,KAAa,UACtB,MAAM,IAAI,EAA0B,gBAAgB,EAAO,GAAG,EAAK,oBAAoB;IAGzF,EAAM,IAAI,GAAM,EAAgB,CAAQ,CAAC;GAC3C;GAEA,EAAS,IAAI,GAAQ;IAAE;IAAO,MAAM;GAAS,CAAC;GAE9C;EACF;EAEA,KAAK,IAAM,CAAC,GAAK,MAAU,OAAO,QAAQ,CAAI,GAAG;GAC/C,IAAI,EAAW,IAAI,CAAG,GACpB,MAAM,IAAI,EAA0B,gBAAgB,EAAI,eAAe;GAGzE,EAAM,GAAO,IAAS,GAAG,EAAO,GAAG,MAAQ,CAAG;EAChD;CACF;CAEA,KAAK,IAAM,CAAC,GAAK,MAAU,OAAO,QAAQ,CAAO,GAAG;EAClD,IAAI,EAAW,IAAI,CAAG,GAAG,MAAM,IAAI,EAA0B,gBAAgB,EAAI,eAAe;EAEhG,EAAM,GAAO,CAAG;CAClB;CAEA,OAAO;AACT"}
1
+ {"version":3,"file":"_catalog.js","names":[],"sources":["../src/_catalog.ts"],"sourcesContent":["import { compileTemplate, type Template } from './_template';\nimport { LinguaInvalidCatalogError } from './errors';\nimport type { Catalog, CatalogNode, PluralMessage } from './types';\n\nconst unsafeKeys = new Set(['__proto__', 'constructor', 'prototype']);\n\nexport type CompiledText = { readonly kind: 'text'; readonly template: Template };\nexport type CompiledPlural = { readonly forms: ReadonlyMap<string, Template>; readonly kind: 'plural' };\nexport type CompiledMessage = CompiledPlural | CompiledText;\nexport type CompiledCatalog = ReadonlyMap<string, CompiledMessage>;\n\nexport function isPluralMessage(node: CatalogNode): node is PluralMessage {\n return typeof node === 'object' && node !== null && Object.hasOwn(node, 'plural');\n}\n\n/** Compile explicit catalog nodes once. Nested objects only group keys; plural intent is never inferred. */\nexport function compileCatalog(catalog: Catalog): CompiledCatalog {\n const messages = new Map<string, CompiledMessage>();\n\n const visit = (node: CatalogNode, prefix: string): void => {\n if (typeof node === 'string') {\n messages.set(prefix, { kind: 'text', template: compileTemplate(node) });\n\n return;\n }\n\n if (typeof node !== 'object' || node === null || Array.isArray(node)) {\n throw new LinguaInvalidCatalogError(`Catalog node \"${prefix}\" must be a string, plural message, or object.`);\n }\n\n if (isPluralMessage(node)) {\n if (Reflect.ownKeys(node).some((key) => key !== 'plural')) {\n throw new LinguaInvalidCatalogError(`Plural message \"${prefix}\" must contain only a \"plural\" property.`);\n }\n\n if (typeof node.plural !== 'object' || node.plural === null || Array.isArray(node.plural)) {\n throw new LinguaInvalidCatalogError(`Plural message \"${prefix}\" must provide an object of string forms.`);\n }\n\n const forms = new Map<string, Template>();\n\n for (const [form, template] of Object.entries(node.plural)) {\n if (typeof template !== 'string') {\n throw new LinguaInvalidCatalogError(`Plural form \"${prefix}.${form}\" must be a string.`);\n }\n\n forms.set(form, compileTemplate(template));\n }\n\n messages.set(prefix, { forms, kind: 'plural' });\n\n return;\n }\n\n for (const [key, value] of Object.entries(node)) {\n if (unsafeKeys.has(key)) {\n throw new LinguaInvalidCatalogError(`Catalog key \"${key}\" is reserved.`);\n }\n\n visit(value, prefix ? `${prefix}.${key}` : key);\n }\n };\n\n for (const [key, value] of Object.entries(catalog)) {\n if (unsafeKeys.has(key)) throw new LinguaInvalidCatalogError(`Catalog key \"${key}\" is reserved.`);\n\n visit(value, key);\n }\n\n return messages;\n}\n"],"mappings":";;;AAIA,IAAM,oBAAa,IAAI,IAAI;CAAC;CAAa;CAAe;AAAW,CAAC;AAOpE,SAAgB,EAAgB,GAA0C;CACxE,OAAO,OAAO,KAAS,cAAY,KAAiB,OAAO,OAAO,GAAM,QAAQ;AAClF;AAGA,SAAgB,EAAe,GAAmC;CAChE,IAAM,oBAAW,IAAI,IAA6B,GAE5C,KAAS,GAAmB,MAAyB;EACzD,IAAI,OAAO,KAAS,UAAU;GAC5B,EAAS,IAAI,GAAQ;IAAE,MAAM;IAAQ,UAAU,EAAgB,CAAI;GAAE,CAA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.canonicalLocale(e),n);let s=(e,t)=>{a.set(e,{catalog:t,compiled:n.compileCatalog(t)})};for(let[e,t]of i)typeof t!=`function`&&s(e,t);return{catalogMap(){return new Map([...a].map(([e,{compiled:t}])=>[e,t]))},isLoaded(e){return a.has(t.canonicalLocale(e))},load:async n=>{let r=t.canonicalLocale(n);if(a.has(r))return!1;let c=i.get(r);if(!c)throw new e.LinguaMissingCatalogError(`Catalog has no source for locale "${r}".`);if(typeof c!=`function`)return s(r,c),!0;let l=o.get(r);if(l)return await l,!1;let u=c().then(e=>{s(r,e),o.delete(r)},e=>{throw o.delete(r),e});return o.set(r,u),await u,!0},state(e){let t={};for(let[e,{catalog:n}]of a)t[e]=n;return{catalogs:t,locale:e,version:3}}}}exports.createCatalogStore=r;
1
+ const e=require("./errors.cjs"),t=require("./_catalog.cjs"),n=require("./_locale.cjs");function r(r){let i=new Map,a=new Map,o=new Map;for(let[e,t]of Object.entries(r))i.set(n.canonicalLocale(e),t);let s=(e,n)=>{a.set(e,{catalog:n,compiled:t.compileCatalog(n)})};for(let[e,t]of i)typeof t!=`function`&&s(e,t);return{catalogMap(){return new Map([...a].map(([e,{compiled:t}])=>[e,t]))},isLoaded(e){return a.has(n.canonicalLocale(e))},load:async t=>{let r=n.canonicalLocale(t);if(a.has(r))return!1;let c=i.get(r);if(!c)throw new e.LinguaMissingCatalogError(`Catalog has no source for locale "${r}".`);if(typeof c!=`function`)return s(r,c),!0;let l=o.get(r);if(l)return await l,!1;let u=c().then(e=>{s(r,e),o.delete(r)},e=>{throw o.delete(r),e});return o.set(r,u),await u,!0},state(e){let t={};for(let[e,{catalog:n}]of a)t[e]=n;return{catalogs:t,locale:e,version:3}}}}exports.createCatalogStore=r;
2
2
  //# sourceMappingURL=_resources.cjs.map
@@ -1,14 +1,14 @@
1
1
  import { LinguaMissingCatalogError as e } from "./errors.js";
2
- import { canonicalLocale as t } from "./_locale.js";
3
- import { compileCatalog as n } from "./_catalog.js";
2
+ import { compileCatalog as t } from "./_catalog.js";
3
+ import { canonicalLocale as n } from "./_locale.js";
4
4
  //#region src/_resources.ts
5
5
  function r(r) {
6
6
  let i = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map();
7
- for (let [e, n] of Object.entries(r)) i.set(t(e), n);
8
- let s = (e, t) => {
7
+ for (let [e, t] of Object.entries(r)) i.set(n(e), t);
8
+ let s = (e, n) => {
9
9
  a.set(e, {
10
- catalog: t,
11
- compiled: n(t)
10
+ catalog: n,
11
+ compiled: t(n)
12
12
  });
13
13
  };
14
14
  for (let [e, t] of i) typeof t != "function" && s(e, t);
@@ -17,10 +17,10 @@ function r(r) {
17
17
  return new Map([...a].map(([e, { compiled: t }]) => [e, t]));
18
18
  },
19
19
  isLoaded(e) {
20
- return a.has(t(e));
20
+ return a.has(n(e));
21
21
  },
22
- load: async (n) => {
23
- let r = t(n);
22
+ load: async (t) => {
23
+ let r = n(t);
24
24
  if (a.has(r)) return !1;
25
25
  let c = i.get(r);
26
26
  if (!c) throw new e(`Catalog has no source for locale "${r}".`);
@@ -0,0 +1,2 @@
1
+ const e=require("./_catalog.cjs");function t(t){let n=typeof t==`object`&&t&&`serialize`in t&&`getSnapshot`in t?t.serialize().catalogs[t.locale]:t;return[...e.compileCatalog(n).keys()]}exports.catalogKeys=t;
2
+ //# sourceMappingURL=catalog.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"catalog.cjs","names":[],"sources":["../src/catalog.ts"],"sourcesContent":["import { compileCatalog } from './_catalog';\nimport type { TranslationStore } from './i18n';\nimport type { Catalog, TextKey } from './types';\n\n/** Enumerate every message key in a catalog as a dotted path.\n *\n * Traverses nested grouping objects and explicit `{ plural: ... }` messages,\n * producing the same dotted paths that `TextKey<C>` represents at the type\n * level. Use this to derive key arrays from the catalog itself instead of\n * maintaining a parallel list that can go stale.\n *\n * Pass a `TranslationStore` to enumerate keys from its current locale catalog\n * without specifying a locale explicitly.\n *\n * @example\n * ```ts\n * const messages = {\n * nav: { home: '...', settings: '...' },\n * };\n * const keys = catalogKeys(messages); // ['nav.home', 'nav.settings']\n *\n * // From a translation store — uses current locale's catalog\n * const i18n = createTranslationStore({ catalogs: { en: messages }, locale: 'en' });\n * const allKeys = catalogKeys(i18n);\n * ```\n */\nexport function catalogKeys<C extends Catalog>(store: TranslationStore<C>): ReadonlyArray<TextKey<C>>;\nexport function catalogKeys<C extends Catalog>(catalog: C): ReadonlyArray<TextKey<C>>;\nexport function catalogKeys(source: unknown): ReadonlyArray<TextKey<Catalog>> {\n const catalog =\n typeof source === 'object' && source !== null && 'serialize' in source && 'getSnapshot' in source\n ? (source as TranslationStore).serialize().catalogs[(source as TranslationStore).locale]\n : (source as Catalog);\n\n return [...compileCatalog(catalog).keys()] as unknown as ReadonlyArray<TextKey<Catalog>>;\n}\n"],"mappings":"kCA4BA,SAAgB,EAAY,EAAkD,CAC5E,IAAM,EACJ,OAAO,GAAW,UAAY,GAAmB,cAAe,GAAU,gBAAiB,EACtF,EAA4B,UAAU,CAAC,CAAC,SAAU,EAA4B,QAC9E,EAEP,MAAO,CAAC,GAAG,EAAA,eAAe,CAAO,CAAC,CAAC,KAAK,CAAC,CAC3C"}
@@ -0,0 +1,27 @@
1
+ import type { TranslationStore } from './i18n';
2
+ import type { Catalog, TextKey } from './types';
3
+ /** Enumerate every message key in a catalog as a dotted path.
4
+ *
5
+ * Traverses nested grouping objects and explicit `{ plural: ... }` messages,
6
+ * producing the same dotted paths that `TextKey<C>` represents at the type
7
+ * level. Use this to derive key arrays from the catalog itself instead of
8
+ * maintaining a parallel list that can go stale.
9
+ *
10
+ * Pass a `TranslationStore` to enumerate keys from its current locale catalog
11
+ * without specifying a locale explicitly.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * const messages = {
16
+ * nav: { home: '...', settings: '...' },
17
+ * };
18
+ * const keys = catalogKeys(messages); // ['nav.home', 'nav.settings']
19
+ *
20
+ * // From a translation store — uses current locale's catalog
21
+ * const i18n = createTranslationStore({ catalogs: { en: messages }, locale: 'en' });
22
+ * const allKeys = catalogKeys(i18n);
23
+ * ```
24
+ */
25
+ export declare function catalogKeys<C extends Catalog>(store: TranslationStore<C>): ReadonlyArray<TextKey<C>>;
26
+ export declare function catalogKeys<C extends Catalog>(catalog: C): ReadonlyArray<TextKey<C>>;
27
+ //# sourceMappingURL=catalog.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"catalog.d.ts","sourceRoot":"","sources":["../src/catalog.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAC;AAC/C,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAEhD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,OAAO,EAAE,KAAK,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;AACtG,wBAAgB,WAAW,CAAC,CAAC,SAAS,OAAO,EAAE,OAAO,EAAE,CAAC,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { compileCatalog as e } from "./_catalog.js";
2
+ //#region src/catalog.ts
3
+ function t(t) {
4
+ let n = typeof t == "object" && t && "serialize" in t && "getSnapshot" in t ? t.serialize().catalogs[t.locale] : t;
5
+ return [...e(n).keys()];
6
+ }
7
+ //#endregion
8
+ export { t as catalogKeys };
9
+
10
+ //# sourceMappingURL=catalog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"catalog.js","names":[],"sources":["../src/catalog.ts"],"sourcesContent":["import { compileCatalog } from './_catalog';\nimport type { TranslationStore } from './i18n';\nimport type { Catalog, TextKey } from './types';\n\n/** Enumerate every message key in a catalog as a dotted path.\n *\n * Traverses nested grouping objects and explicit `{ plural: ... }` messages,\n * producing the same dotted paths that `TextKey<C>` represents at the type\n * level. Use this to derive key arrays from the catalog itself instead of\n * maintaining a parallel list that can go stale.\n *\n * Pass a `TranslationStore` to enumerate keys from its current locale catalog\n * without specifying a locale explicitly.\n *\n * @example\n * ```ts\n * const messages = {\n * nav: { home: '...', settings: '...' },\n * };\n * const keys = catalogKeys(messages); // ['nav.home', 'nav.settings']\n *\n * // From a translation store — uses current locale's catalog\n * const i18n = createTranslationStore({ catalogs: { en: messages }, locale: 'en' });\n * const allKeys = catalogKeys(i18n);\n * ```\n */\nexport function catalogKeys<C extends Catalog>(store: TranslationStore<C>): ReadonlyArray<TextKey<C>>;\nexport function catalogKeys<C extends Catalog>(catalog: C): ReadonlyArray<TextKey<C>>;\nexport function catalogKeys(source: unknown): ReadonlyArray<TextKey<Catalog>> {\n const catalog =\n typeof source === 'object' && source !== null && 'serialize' in source && 'getSnapshot' in source\n ? (source as TranslationStore).serialize().catalogs[(source as TranslationStore).locale]\n : (source as Catalog);\n\n return [...compileCatalog(catalog).keys()] as unknown as ReadonlyArray<TextKey<Catalog>>;\n}\n"],"mappings":";;AA4BA,SAAgB,EAAY,GAAkD;CAC5E,IAAM,IACJ,OAAO,KAAW,YAAY,KAAmB,eAAe,KAAU,iBAAiB,IACtF,EAA4B,UAAU,CAAC,CAAC,SAAU,EAA4B,UAC9E;CAEP,OAAO,CAAC,GAAG,EAAe,CAAO,CAAC,CAAC,KAAK,CAAC;AAC3C"}
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./errors.cjs"),t=require("./translator.cjs"),n=require("./i18n.cjs");exports.LinguaDisposedError=e.LinguaDisposedError,exports.LinguaError=e.LinguaError,exports.LinguaInvalidCatalogError=e.LinguaInvalidCatalogError,exports.LinguaInvalidLocaleError=e.LinguaInvalidLocaleError,exports.LinguaInvalidPluralCountError=e.LinguaInvalidPluralCountError,exports.LinguaInvalidStateError=e.LinguaInvalidStateError,exports.LinguaMissingCatalogError=e.LinguaMissingCatalogError,exports.createCatalogTranslator=t.createCatalogTranslator,exports.createTranslationStore=n.createTranslationStore,exports.createTranslator=t.createTranslator,exports.hydrateTranslationStore=n.hydrateTranslationStore;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./errors.cjs"),t=require("./catalog.cjs"),n=require("./translator.cjs"),r=require("./i18n.cjs");exports.LinguaDisposedError=e.LinguaDisposedError,exports.LinguaError=e.LinguaError,exports.LinguaInvalidCatalogError=e.LinguaInvalidCatalogError,exports.LinguaInvalidLocaleError=e.LinguaInvalidLocaleError,exports.LinguaInvalidPluralCountError=e.LinguaInvalidPluralCountError,exports.LinguaInvalidStateError=e.LinguaInvalidStateError,exports.LinguaMissingCatalogError=e.LinguaMissingCatalogError,exports.catalogKeys=t.catalogKeys,exports.createCatalogTranslator=n.createCatalogTranslator,exports.createTranslationStore=r.createTranslationStore,exports.createTranslator=n.createTranslator,exports.hydrateTranslationStore=r.hydrateTranslationStore;
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export { catalogKeys } from './catalog';
1
2
  export { LinguaDisposedError, LinguaError, LinguaInvalidCatalogError, LinguaInvalidLocaleError, LinguaInvalidPluralCountError, LinguaInvalidStateError, LinguaMissingCatalogError, } from './errors';
2
3
  export { createTranslationStore, hydrateTranslationStore, type TranslationSnapshot, type TranslationStore, } from './i18n';
3
4
  export { createCatalogTranslator, createTranslator, type Translator } from './translator';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,WAAW,EACX,yBAAyB,EACzB,wBAAwB,EACxB,6BAA6B,EAC7B,uBAAuB,EACvB,yBAAyB,GAC1B,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,sBAAsB,EACtB,uBAAuB,EACvB,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,GACtB,MAAM,QAAQ,CAAC;AAChB,OAAO,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1F,YAAY,EACV,OAAO,EACP,aAAa,EACb,WAAW,EACX,aAAa,EACb,cAAc,EACd,QAAQ,EACR,wBAAwB,EACxB,MAAM,EACN,UAAU,EACV,cAAc,EACd,SAAS,EACT,aAAa,EACb,aAAa,EACb,gBAAgB,EAChB,OAAO,EACP,gBAAgB,EAChB,gBAAgB,EAChB,uBAAuB,EACvB,iBAAiB,EACjB,MAAM,GACP,MAAM,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EACL,mBAAmB,EACnB,WAAW,EACX,yBAAyB,EACzB,wBAAwB,EACxB,6BAA6B,EAC7B,uBAAuB,EACvB,yBAAyB,GAC1B,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,sBAAsB,EACtB,uBAAuB,EACvB,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,GACtB,MAAM,QAAQ,CAAC;AAChB,OAAO,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1F,YAAY,EACV,OAAO,EACP,aAAa,EACb,WAAW,EACX,aAAa,EACb,cAAc,EACd,QAAQ,EACR,wBAAwB,EACxB,MAAM,EACN,UAAU,EACV,cAAc,EACd,SAAS,EACT,aAAa,EACb,aAAa,EACb,gBAAgB,EAChB,OAAO,EACP,gBAAgB,EAChB,gBAAgB,EAChB,uBAAuB,EACvB,iBAAiB,EACjB,MAAM,GACP,MAAM,SAAS,CAAC"}
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { LinguaDisposedError as e, LinguaError as t, LinguaInvalidCatalogError as n, LinguaInvalidLocaleError as r, LinguaInvalidPluralCountError as i, LinguaInvalidStateError as a, LinguaMissingCatalogError as o } from "./errors.js";
2
- import { createCatalogTranslator as s, createTranslator as c } from "./translator.js";
3
- import { createTranslationStore as l, hydrateTranslationStore as u } from "./i18n.js";
4
- export { e as LinguaDisposedError, t as LinguaError, n as LinguaInvalidCatalogError, r as LinguaInvalidLocaleError, i as LinguaInvalidPluralCountError, a as LinguaInvalidStateError, o as LinguaMissingCatalogError, s as createCatalogTranslator, l as createTranslationStore, c as createTranslator, u as hydrateTranslationStore };
2
+ import { catalogKeys as s } from "./catalog.js";
3
+ import { createCatalogTranslator as c, createTranslator as l } from "./translator.js";
4
+ import { createTranslationStore as u, hydrateTranslationStore as d } from "./i18n.js";
5
+ export { e as LinguaDisposedError, t as LinguaError, n as LinguaInvalidCatalogError, r as LinguaInvalidLocaleError, i as LinguaInvalidPluralCountError, a as LinguaInvalidStateError, o as LinguaMissingCatalogError, s as catalogKeys, c as createCatalogTranslator, u as createTranslationStore, l as createTranslator, d as hydrateTranslationStore };
package/dist/lingua.cjs CHANGED
@@ -1,2 +1,2 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=class e extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}static is(t){return t instanceof e}},t=class extends e{constructor(){super(`Operation called on a disposed translation store.`)}},n=class extends e{},r=class extends e{},i=class extends e{},a=class extends e{},o=class extends e{},s=new Map;function c(e){try{let[t]=Intl.getCanonicalLocales(e);if(t)return t}catch{}throw new r(`Invalid BCP 47 locale tag: "${e}".`)}function l(e,t){let n=new Set;for(let r of[e,...t]){let e=r.split(`-`);for(let t=e.length;t>0;t--)n.add(e.slice(0,t).join(`-`))}return[...n]}function u(e,t,n){let r=`${e}:${n?`ordinal`:`cardinal`}`,i=s.get(r);return i||(i=new Intl.PluralRules(e,{type:n?`ordinal`:`cardinal`}),s.set(r,i)),i.select(t)}var d=/\{([\p{ID_Continue}-]+)\}/gu;function f(e){let t=[],n=0;for(let r of e.matchAll(d)){let i=r.index??0;i>n&&t.push(e.slice(n,i)),t.push({value:r[1]}),n=i+r[0].length}return n<e.length&&t.push(e.slice(n)),t}function p(e,t,n){return e.map(e=>{if(typeof e==`string`)return e;let r=Object.hasOwn(t,e.value)?t[e.value]:void 0;return r==null?n(e.value):String(r)}).join(``)}function m(e,t,n){let r=[];for(let i of e){if(typeof i==`string`){i!==``&&r.push(i);continue}r.push(Object.hasOwn(t,i.value)?t[i.value]:n(i.value))}return r}var h=new Set([`__proto__`,`constructor`,`prototype`]);function g(e){return typeof e==`object`&&!!e&&Object.hasOwn(e,`plural`)}function _(e){let t=new Map,r=(e,i)=>{if(typeof e==`string`){t.set(i,{kind:`text`,template:f(e)});return}if(typeof e!=`object`||!e||Array.isArray(e))throw new n(`Catalog node "${i}" must be a string, plural message, or object.`);if(g(e)){if(Reflect.ownKeys(e).some(e=>e!==`plural`))throw new n(`Plural message "${i}" must contain only a "plural" property.`);if(typeof e.plural!=`object`||e.plural===null||Array.isArray(e.plural))throw new n(`Plural message "${i}" must provide an object of string forms.`);let r=new Map;for(let[t,a]of Object.entries(e.plural)){if(typeof a!=`string`)throw new n(`Plural form "${i}.${t}" must be a string.`);r.set(t,f(a))}t.set(i,{forms:r,kind:`plural`});return}for(let[t,a]of Object.entries(e)){if(h.has(t))throw new n(`Catalog key "${t}" is reserved.`);r(a,i?`${i}.${t}`:t)}};for(let[t,i]of Object.entries(e)){if(h.has(t))throw new n(`Catalog key "${t}" is reserved.`);r(i,t)}return t}function v(e){let t=new Map,n=new Map,r=new Map;for(let[n,r]of Object.entries(e))t.set(c(n),r);let i=(e,t)=>{n.set(e,{catalog:t,compiled:_(t)})};for(let[e,n]of t)typeof n!=`function`&&i(e,n);return{catalogMap(){return new Map([...n].map(([e,{compiled:t}])=>[e,t]))},isLoaded(e){return n.has(c(e))},load:async e=>{let a=c(e);if(n.has(a))return!1;let s=t.get(a);if(!s)throw new o(`Catalog has no source for locale "${a}".`);if(typeof s!=`function`)return i(a,s),!0;let l=r.get(a);if(l)return await l,!1;let u=s().then(e=>{i(a,e),r.delete(a)},e=>{throw r.delete(a),e});return r.set(a,u),await u,!0},state(e){let t={};for(let[e,{catalog:r}]of n)t[e]=r;return{catalogs:t,locale:e,version:3}}}}function y(e,t={}){let n=c(t.locale??`en`),r=l(n,(Array.isArray(t.fallback)?t.fallback:t.fallback?[t.fallback]:[]).map(c)),a=t.onMissingKey??(e=>e),o=t.onMissingValue??(e=>`{${e}}`),s=t=>{for(let n of r){let r=e.get(n)?.get(t);if(r)return{locale:n,message:r}}},d=(e,t)=>{let n=s(e);if(!n)return;if(n.message.kind===`text`)return`count`in t?void 0:{key:e,template:n.message.template};if(!(`count`in t)||!Number.isFinite(t.count)){if(`count`in t)throw new i("`count` must be a finite number.");return}let r=t.count===0&&!t.ordinal?`zero`:u(n.locale,t.count,t.ordinal??!1),a=n.message.forms.get(r)??n.message.forms.get(`other`);return a?{key:e,template:a}:void 0},f=e=>`count`in e?{count:e.count,...e.values}:e.values??{},h=(e,t)=>{let r=d(e,t);return r?m(r.template,f(t),e=>o(e,r.key,n)):[a(e,n)]},g=(e,t={})=>{let r=d(e,t);return r?p(r.template,f(t),e=>o(e,r.key,n)):a(e,n)};return{locale:n,segments(e,t){return h(e,t)},segmentsDynamic:h,translate(e,t={}){return g(e,t)},translateDynamic:g}}function b(e,t={}){let n=c(t.locale??`en`);return y(new Map([[n,_(e)]]),{...t,locale:n})}function x(e,t){let n=new Map;for(let[t,r]of Object.entries(e))n.set(c(t),_(r));return y(n,t)}function S(e){let n=v(e.catalogs),r=e.fallback,i=(Array.isArray(r)?r:r?[r]:[]).map(c),a=new AbortController,o=new Set,s=!1,u=c(e.locale??`en`),d=0,f=()=>({locale:u,revision:d,translator:y(n.catalogMap(),{...e,fallback:r,locale:u})}),p=f(),m=()=>{if(s)throw new t},h=()=>{s||(s=!0,o.clear(),a.abort())},g=e=>{try{e(p)}catch{}},_=()=>{d++,p=f();for(let e of[...o])g(e)},b=e=>l(u,i).includes(e);return{get disposalSignal(){return a.signal},dispose:h,get disposed(){return s},getSnapshot(){return p},isLoaded(e){return!s&&n.isLoaded(e?.locale??u)},async load(e){m();let t=c(e?.locale??u),r=await n.load(t);!s&&r&&b(t)&&_()},get locale(){return u},segments(e,t){return p.translator.segmentsDynamic(e,t)},segmentsDynamic(e,t){return p.translator.segmentsDynamic(e,t)},serialize(){return m(),n.state(u)},async setLocale(e){m();let t=c(e);t!==u&&(u=t,_())},subscribe(e,t){if(m(),t?.signal?.aborted)return()=>{};let n=()=>{o.delete(e),t?.signal?.removeEventListener(`abort`,n)};return t?.signal?.addEventListener(`abort`,n,{once:!0}),o.add(e),t?.immediate&&g(e),n},[Symbol.dispose]:h,translate(e,t={}){return p.translator.translateDynamic(e,t)},translateDynamic(e,t){return p.translator.translateDynamic(e,t)}}}function C(e,t){if(e.version!==3)throw new a(`Unsupported lingua state version: ${String(e.version)}.`);return S({...t,catalogs:e.catalogs,locale:e.locale})}exports.LinguaDisposedError=t,exports.LinguaError=e,exports.LinguaInvalidCatalogError=n,exports.LinguaInvalidLocaleError=r,exports.LinguaInvalidPluralCountError=i,exports.LinguaInvalidStateError=a,exports.LinguaMissingCatalogError=o,exports.createCatalogTranslator=b,exports.createTranslationStore=S,exports.createTranslator=x,exports.hydrateTranslationStore=C;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=/\{([\p{ID_Continue}-]+)\}/gu;function t(t){let n=[],r=0;for(let i of t.matchAll(e)){let e=i.index??0;e>r&&n.push(t.slice(r,e)),n.push({value:i[1]}),r=e+i[0].length}return r<t.length&&n.push(t.slice(r)),n}function n(e,t,n){return e.map(e=>{if(typeof e==`string`)return e;let r=Object.hasOwn(t,e.value)?t[e.value]:void 0;return r==null?n(e.value):String(r)}).join(``)}function r(e,t,n){let r=[];for(let i of e){if(typeof i==`string`){i!==``&&r.push(i);continue}r.push(Object.hasOwn(t,i.value)?t[i.value]:n(i.value))}return r}var i=class e extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}static is(t){return t instanceof e}},a=class extends i{constructor(){super(`Operation called on a disposed translation store.`)}},o=class extends i{},s=class extends i{},c=class extends i{},l=class extends i{},u=class extends i{},d=new Set([`__proto__`,`constructor`,`prototype`]);function f(e){return typeof e==`object`&&!!e&&Object.hasOwn(e,`plural`)}function p(e){let n=new Map,r=(e,i)=>{if(typeof e==`string`){n.set(i,{kind:`text`,template:t(e)});return}if(typeof e!=`object`||!e||Array.isArray(e))throw new o(`Catalog node "${i}" must be a string, plural message, or object.`);if(f(e)){if(Reflect.ownKeys(e).some(e=>e!==`plural`))throw new o(`Plural message "${i}" must contain only a "plural" property.`);if(typeof e.plural!=`object`||e.plural===null||Array.isArray(e.plural))throw new o(`Plural message "${i}" must provide an object of string forms.`);let r=new Map;for(let[n,a]of Object.entries(e.plural)){if(typeof a!=`string`)throw new o(`Plural form "${i}.${n}" must be a string.`);r.set(n,t(a))}n.set(i,{forms:r,kind:`plural`});return}for(let[t,n]of Object.entries(e)){if(d.has(t))throw new o(`Catalog key "${t}" is reserved.`);r(n,i?`${i}.${t}`:t)}};for(let[t,n]of Object.entries(e)){if(d.has(t))throw new o(`Catalog key "${t}" is reserved.`);r(n,t)}return n}function m(e){return[...p(typeof e==`object`&&e&&`serialize`in e&&`getSnapshot`in e?e.serialize().catalogs[e.locale]:e).keys()]}var h=new Map;function g(e){try{let[t]=Intl.getCanonicalLocales(e);if(t)return t}catch{}throw new s(`Invalid BCP 47 locale tag: "${e}".`)}function _(e,t){let n=new Set;for(let r of[e,...t]){let e=r.split(`-`);for(let t=e.length;t>0;t--)n.add(e.slice(0,t).join(`-`))}return[...n]}function v(e,t,n){let r=`${e}:${n?`ordinal`:`cardinal`}`,i=h.get(r);return i||(i=new Intl.PluralRules(e,{type:n?`ordinal`:`cardinal`}),h.set(r,i)),i.select(t)}function y(e){let t=new Map,n=new Map,r=new Map;for(let[n,r]of Object.entries(e))t.set(g(n),r);let i=(e,t)=>{n.set(e,{catalog:t,compiled:p(t)})};for(let[e,n]of t)typeof n!=`function`&&i(e,n);return{catalogMap(){return new Map([...n].map(([e,{compiled:t}])=>[e,t]))},isLoaded(e){return n.has(g(e))},load:async e=>{let a=g(e);if(n.has(a))return!1;let o=t.get(a);if(!o)throw new u(`Catalog has no source for locale "${a}".`);if(typeof o!=`function`)return i(a,o),!0;let s=r.get(a);if(s)return await s,!1;let c=o().then(e=>{i(a,e),r.delete(a)},e=>{throw r.delete(a),e});return r.set(a,c),await c,!0},state(e){let t={};for(let[e,{catalog:r}]of n)t[e]=r;return{catalogs:t,locale:e,version:3}}}}function b(e,t={}){let i=g(t.locale??`en`),a=_(i,(Array.isArray(t.fallback)?t.fallback:t.fallback?[t.fallback]:[]).map(g)),o=t.onMissingKey??(e=>e),s=t.onMissingValue??(e=>`{${e}}`),l=t=>{for(let n of a){let r=e.get(n)?.get(t);if(r)return{locale:n,message:r}}},u=(e,t)=>{let n=l(e);if(!n)return;if(n.message.kind===`text`)return`count`in t?void 0:{key:e,template:n.message.template};if(!(`count`in t)||!Number.isFinite(t.count)){if(`count`in t)throw new c("`count` must be a finite number.");return}let r=t.count===0&&!t.ordinal?`zero`:v(n.locale,t.count,t.ordinal??!1),i=n.message.forms.get(r)??n.message.forms.get(`other`);return i?{key:e,template:i}:void 0},d=e=>`count`in e?{count:e.count,...e.values}:e.values??{},f=(e,t)=>{let n=u(e,t);return n?r(n.template,d(t),e=>s(e,n.key,i)):[o(e,i)]},p=(e,t={})=>{let r=u(e,t);return r?n(r.template,d(t),e=>s(e,r.key,i)):o(e,i)};return{locale:i,segments(e,t){return f(e,t)},segmentsDynamic:f,translate(e,t={}){return p(e,t)},translateDynamic:p}}function x(e,t={}){let n=g(t.locale??`en`);return b(new Map([[n,p(e)]]),{...t,locale:n})}function S(e,t){let n=new Map;for(let[t,r]of Object.entries(e))n.set(g(t),p(r));return b(n,t)}function C(e){let t=y(e.catalogs),n=e.fallback,r=(Array.isArray(n)?n:n?[n]:[]).map(g),i=new AbortController,o=new Set,s=!1,c=g(e.locale??`en`),l=0,u=()=>({locale:c,revision:l,translator:b(t.catalogMap(),{...e,fallback:n,locale:c})}),d=u(),f=()=>{if(s)throw new a},p=()=>{s||(s=!0,o.clear(),i.abort())},m=e=>{try{e(d)}catch{}},h=()=>{l++,d=u();for(let e of[...o])m(e)},v=e=>_(c,r).includes(e);return{get disposalSignal(){return i.signal},dispose:p,get disposed(){return s},getSnapshot(){return d},isLoaded(e){return!s&&t.isLoaded(e?.locale??c)},async load(e){f();let n=g(e?.locale??c),r=await t.load(n);!s&&r&&v(n)&&h()},get locale(){return c},segments(e,t){return d.translator.segmentsDynamic(e,t)},segmentsDynamic(e,t){return d.translator.segmentsDynamic(e,t)},serialize(){return f(),t.state(c)},async setLocale(e){f();let t=g(e);t!==c&&(c=t,h())},subscribe(e,t){if(f(),t?.signal?.aborted)return()=>{};let n=()=>{o.delete(e),t?.signal?.removeEventListener(`abort`,n)};return t?.signal?.addEventListener(`abort`,n,{once:!0}),o.add(e),t?.immediate&&m(e),n},[Symbol.dispose]:p,translate(e,t={}){return d.translator.translateDynamic(e,t)},translateDynamic(e,t){return d.translator.translateDynamic(e,t)}}}function w(e,t){if(e.version!==3)throw new l(`Unsupported lingua state version: ${String(e.version)}.`);return C({...t,catalogs:e.catalogs,locale:e.locale})}exports.LinguaDisposedError=a,exports.LinguaError=i,exports.LinguaInvalidCatalogError=o,exports.LinguaInvalidLocaleError=s,exports.LinguaInvalidPluralCountError=c,exports.LinguaInvalidStateError=l,exports.LinguaMissingCatalogError=u,exports.catalogKeys=m,exports.createCatalogTranslator=x,exports.createTranslationStore=C,exports.createTranslator=S,exports.hydrateTranslationStore=w;
2
2
  //# sourceMappingURL=lingua.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"lingua.cjs","names":[],"sources":["../src/errors.ts","../src/_dev.ts","../src/_locale.ts","../src/_template.ts","../src/_catalog.ts","../src/_resources.ts","../src/translator.ts","../src/i18n.ts"],"sourcesContent":["export class LinguaError extends Error {\n constructor(message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n\n static is(error: unknown): error is LinguaError {\n return error instanceof LinguaError;\n }\n}\n\nexport class LinguaDisposedError extends LinguaError {\n constructor() {\n super('Operation called on a disposed translation store.');\n }\n}\n\nexport class LinguaInvalidCatalogError extends LinguaError {}\nexport class LinguaInvalidLocaleError extends LinguaError {}\nexport class LinguaInvalidPluralCountError extends LinguaError {}\nexport class LinguaInvalidStateError extends LinguaError {}\nexport class LinguaMissingCatalogError extends LinguaError {}\n","const isDev = !(globalThis as { __LINGUA_PROD__?: boolean }).__LINGUA_PROD__;\n\n/** @internal @security Messages may include user-supplied data. */\nexport function warn(msg: string): void {\n if (isDev) console.warn(`[@vielzeug/lingua] ${msg}`);\n}\n\n/** @internal */\nexport function error(msg: string, ...args: unknown[]): void {\n if (isDev) console.error(`[@vielzeug/lingua] ${msg}`, ...args);\n}\n\n/** @internal — Run fn only in dev builds. Use when dev-only logic goes beyond a single warn() / error() call. */\nexport function devOnly(fn: () => void): void {\n if (isDev) fn();\n}\n","import { LinguaInvalidLocaleError } from './errors';\nimport type { Locale } from './types';\n\nconst pluralRules = new Map<string, Intl.PluralRules>();\n\nexport function canonicalLocale(locale: string): Locale {\n try {\n const [canonical] = Intl.getCanonicalLocales(locale);\n\n if (canonical) return canonical;\n } catch {\n // Error below names the failed public input.\n }\n\n throw new LinguaInvalidLocaleError(`Invalid BCP 47 locale tag: \"${locale}\".`);\n}\n\nexport function localeChain(locale: Locale, fallback: readonly Locale[]): readonly Locale[] {\n const chain = new Set<Locale>();\n\n for (const candidate of [locale, ...fallback]) {\n const parts = candidate.split('-');\n\n for (let length = parts.length; length > 0; length--) {\n chain.add(parts.slice(0, length).join('-'));\n }\n }\n\n return [...chain];\n}\n\nexport function pluralCategory(locale: Locale, count: number, ordinal: boolean): Intl.LDMLPluralRule {\n const key = `${locale}:${ordinal ? 'ordinal' : 'cardinal'}`;\n let rules = pluralRules.get(key);\n\n if (!rules) {\n rules = new Intl.PluralRules(locale, { type: ordinal ? 'ordinal' : 'cardinal' });\n pluralRules.set(key, rules);\n }\n\n return rules.select(count);\n}\n","export type TemplatePart = string | { readonly value: string };\nexport type Template = readonly TemplatePart[];\n\nconst interpolation = /\\{([\\p{ID_Continue}-]+)\\}/gu;\n\nexport function compileTemplate(value: string): Template {\n const parts: TemplatePart[] = [];\n let offset = 0;\n\n for (const match of value.matchAll(interpolation)) {\n const index = match.index ?? 0;\n\n if (index > offset) parts.push(value.slice(offset, index));\n\n parts.push({ value: match[1] });\n offset = index + match[0].length;\n }\n\n if (offset < value.length) parts.push(value.slice(offset));\n\n return parts;\n}\n\nexport function renderText(\n parts: Template,\n values: Record<string, unknown>,\n missing: (name: string) => string,\n): string {\n return parts\n .map((part) => {\n if (typeof part === 'string') return part;\n\n const value = Object.hasOwn(values, part.value) ? values[part.value] : undefined;\n\n return value == null ? missing(part.value) : String(value);\n })\n .join('');\n}\n\nexport function renderSegments<V>(\n parts: Template,\n values: Record<string, V | number>,\n missing: (name: string) => string,\n): Array<string | number | V> {\n const result: Array<string | number | V> = [];\n\n for (const part of parts) {\n if (typeof part === 'string') {\n if (part !== '') result.push(part);\n\n continue;\n }\n\n result.push(Object.hasOwn(values, part.value) ? values[part.value]! : missing(part.value));\n }\n\n return result;\n}\n","import { compileTemplate, type Template } from './_template';\nimport { LinguaInvalidCatalogError } from './errors';\nimport type { Catalog, CatalogNode, PluralMessage } from './types';\n\nconst unsafeKeys = new Set(['__proto__', 'constructor', 'prototype']);\n\nexport type CompiledText = { readonly kind: 'text'; readonly template: Template };\nexport type CompiledPlural = { readonly forms: ReadonlyMap<string, Template>; readonly kind: 'plural' };\nexport type CompiledMessage = CompiledPlural | CompiledText;\nexport type CompiledCatalog = ReadonlyMap<string, CompiledMessage>;\n\nfunction isPluralMessage(node: CatalogNode): node is PluralMessage {\n return typeof node === 'object' && node !== null && Object.hasOwn(node, 'plural');\n}\n\n/** Compile explicit catalog nodes once. Nested objects only group keys; plural intent is never inferred. */\nexport function compileCatalog(catalog: Catalog): CompiledCatalog {\n const messages = new Map<string, CompiledMessage>();\n\n const visit = (node: CatalogNode, prefix: string): void => {\n if (typeof node === 'string') {\n messages.set(prefix, { kind: 'text', template: compileTemplate(node) });\n\n return;\n }\n\n if (typeof node !== 'object' || node === null || Array.isArray(node)) {\n throw new LinguaInvalidCatalogError(`Catalog node \"${prefix}\" must be a string, plural message, or object.`);\n }\n\n if (isPluralMessage(node)) {\n if (Reflect.ownKeys(node).some((key) => key !== 'plural')) {\n throw new LinguaInvalidCatalogError(`Plural message \"${prefix}\" must contain only a \"plural\" property.`);\n }\n\n if (typeof node.plural !== 'object' || node.plural === null || Array.isArray(node.plural)) {\n throw new LinguaInvalidCatalogError(`Plural message \"${prefix}\" must provide an object of string forms.`);\n }\n\n const forms = new Map<string, Template>();\n\n for (const [form, template] of Object.entries(node.plural)) {\n if (typeof template !== 'string') {\n throw new LinguaInvalidCatalogError(`Plural form \"${prefix}.${form}\" must be a string.`);\n }\n\n forms.set(form, compileTemplate(template));\n }\n\n messages.set(prefix, { forms, kind: 'plural' });\n\n return;\n }\n\n for (const [key, value] of Object.entries(node)) {\n if (unsafeKeys.has(key)) {\n throw new LinguaInvalidCatalogError(`Catalog key \"${key}\" is reserved.`);\n }\n\n visit(value, prefix ? `${prefix}.${key}` : key);\n }\n };\n\n for (const [key, value] of Object.entries(catalog)) {\n if (unsafeKeys.has(key)) throw new LinguaInvalidCatalogError(`Catalog key \"${key}\" is reserved.`);\n\n visit(value, key);\n }\n\n return messages;\n}\n","import { type CompiledCatalog, compileCatalog } from './_catalog';\nimport { canonicalLocale } from './_locale';\nimport { LinguaMissingCatalogError } from './errors';\nimport type { Catalog, CatalogSources, Catalogs, Locale, TranslationState } from './types';\n\n/** One catalog state machine owns static sources, lazy sources, and in-flight work. */\nexport function createCatalogStore<C extends Catalog>(sources: CatalogSources<C>) {\n const definitions = new Map<Locale, C | (() => Promise<C>)>();\n const loaded = new Map<Locale, { readonly catalog: C; readonly compiled: CompiledCatalog }>();\n const tasks = new Map<Locale, Promise<void>>();\n\n for (const [locale, source] of Object.entries(sources)) definitions.set(canonicalLocale(locale), source);\n\n const add = (locale: Locale, catalog: C): void => {\n loaded.set(locale, { catalog, compiled: compileCatalog(catalog) });\n };\n\n for (const [locale, source] of definitions) {\n if (typeof source !== 'function') add(locale, source);\n }\n\n const load = async (requestedLocale: Locale): Promise<boolean> => {\n const locale = canonicalLocale(requestedLocale);\n\n if (loaded.has(locale)) return false;\n\n const source = definitions.get(locale);\n\n if (!source) throw new LinguaMissingCatalogError(`Catalog has no source for locale \"${locale}\".`);\n\n if (typeof source !== 'function') {\n add(locale, source);\n\n return true;\n }\n\n const existing = tasks.get(locale);\n\n if (existing) {\n await existing;\n\n return false;\n }\n\n const task = source().then(\n (catalog) => {\n add(locale, catalog);\n tasks.delete(locale);\n },\n (error: unknown) => {\n tasks.delete(locale);\n throw error;\n },\n );\n\n tasks.set(locale, task);\n await task;\n\n return true;\n };\n\n return {\n catalogMap(): ReadonlyMap<Locale, CompiledCatalog> {\n return new Map([...loaded].map(([locale, { compiled }]) => [locale, compiled]));\n },\n isLoaded(locale: Locale): boolean {\n return loaded.has(canonicalLocale(locale));\n },\n load,\n state(locale: Locale): TranslationState<C> {\n const catalogs: Catalogs<C> = {};\n\n for (const [loadedLocale, { catalog }] of loaded) catalogs[loadedLocale] = catalog;\n\n return { catalogs, locale, version: 3 };\n },\n };\n}\n","import { type CompiledCatalog, type CompiledMessage, compileCatalog } from './_catalog';\nimport { canonicalLocale, localeChain, pluralCategory } from './_locale';\nimport { renderSegments, renderText, type Template } from './_template';\nimport { LinguaInvalidPluralCountError } from './errors';\nimport type {\n Catalog,\n Catalogs,\n CatalogTranslatorOptions,\n Locale,\n PluralKey,\n PluralOptions,\n TextKey,\n TranslateOptions,\n TranslatorOptions,\n} from './types';\n\nexport type Translator<C extends Catalog = Catalog> = {\n readonly locale: Locale;\n segments<V>(key: TextKey<C>, options: TranslateOptions & { values: Record<string, V> }): Array<string | V>;\n segments<V>(key: PluralKey<C>, options: PluralOptions & { values?: Record<string, V> }): Array<string | number | V>;\n segmentsDynamic<V>(\n key: string,\n options: (TranslateOptions | PluralOptions) & { values?: Record<string, V> },\n ): Array<string | number | V>;\n translate(key: TextKey<C>, options?: TranslateOptions): string;\n translate(key: PluralKey<C>, options: PluralOptions): string;\n translateDynamic(key: string, options?: TranslateOptions | PluralOptions): string;\n};\n\ntype ResolvedMessage = { readonly locale: Locale; readonly message: CompiledMessage };\n\nexport function createTranslatorFromCompiled<C extends Catalog>(\n catalogs: ReadonlyMap<Locale, CompiledCatalog>,\n options: TranslatorOptions = {},\n): Translator<C> {\n const locale = canonicalLocale(options.locale ?? 'en');\n const fallback = (\n Array.isArray(options.fallback) ? options.fallback : options.fallback ? [options.fallback] : []\n ).map(canonicalLocale);\n const chain = localeChain(locale, fallback);\n const missingKey = options.onMissingKey ?? ((key: string) => key);\n const missingValue = options.onMissingValue ?? ((name: string) => `{${name}}`);\n\n const resolve = (key: string): ResolvedMessage | undefined => {\n for (const candidate of chain) {\n const message = catalogs.get(candidate)?.get(key);\n\n if (message) return { locale: candidate, message };\n }\n\n return undefined;\n };\n\n const templateFor = (\n key: string,\n options: TranslateOptions | PluralOptions,\n ): { key: string; template: Template } | undefined => {\n const found = resolve(key);\n\n if (!found) return undefined;\n\n if (found.message.kind === 'text') {\n if ('count' in options) return undefined;\n\n return { key, template: found.message.template };\n }\n\n if (!('count' in options) || !Number.isFinite(options.count)) {\n if ('count' in options) throw new LinguaInvalidPluralCountError('`count` must be a finite number.');\n\n return undefined;\n }\n\n const category =\n options.count === 0 && !options.ordinal\n ? 'zero'\n : pluralCategory(found.locale, options.count, options.ordinal ?? false);\n const template = found.message.forms.get(category) ?? found.message.forms.get('other');\n\n return template ? { key, template } : undefined;\n };\n\n const valuesFor = (options: TranslateOptions | PluralOptions): Record<string, unknown> =>\n 'count' in options ? { count: options.count, ...options.values } : (options.values ?? {});\n\n const segmentsDynamic = <V>(\n key: string,\n options: (TranslateOptions | PluralOptions) & { values?: Record<string, V> },\n ): Array<string | number | V> => {\n const found = templateFor(key, options);\n\n if (!found) return [missingKey(key, locale)];\n\n return renderSegments(found.template, valuesFor(options) as Record<string, V | number>, (name) =>\n missingValue(name, found.key, locale),\n );\n };\n\n const translateDynamic = (key: string, options: TranslateOptions | PluralOptions = {}): string => {\n const found = templateFor(key, options);\n\n if (!found) return missingKey(key, locale);\n\n return renderText(found.template, valuesFor(options), (name) => missingValue(name, found.key, locale));\n };\n\n return {\n locale,\n segments(key: string, options: (TranslateOptions | PluralOptions) & { values?: Record<string, unknown> }) {\n return segmentsDynamic(key, options);\n },\n segmentsDynamic,\n translate(key: string, options: TranslateOptions | PluralOptions = {}) {\n return translateDynamic(key, options);\n },\n translateDynamic,\n } as Translator<C>;\n}\n\n/** Creates a fixed-locale translator from one catalog. Lingua snapshots catalog messages during construction. */\nexport function createCatalogTranslator<C extends Catalog>(\n catalog: C,\n options: CatalogTranslatorOptions = {},\n): Translator<C> {\n const locale = canonicalLocale(options.locale ?? 'en');\n const compiled = new Map<Locale, CompiledCatalog>([[locale, compileCatalog(catalog)]]);\n\n return createTranslatorFromCompiled<C>(compiled, { ...options, locale });\n}\n\nexport function createTranslator<C extends Catalog>(catalogs: Catalogs<C>, options?: TranslatorOptions): Translator<C> {\n const compiled = new Map<Locale, CompiledCatalog>();\n\n for (const [locale, catalog] of Object.entries(catalogs)) {\n compiled.set(canonicalLocale(locale), compileCatalog(catalog));\n }\n\n return createTranslatorFromCompiled<C>(compiled, options);\n}\n","import { error as logError } from './_dev';\nimport { canonicalLocale, localeChain } from './_locale';\nimport { createCatalogStore } from './_resources';\nimport { LinguaDisposedError, LinguaInvalidStateError } from './errors';\nimport { createTranslatorFromCompiled, type Translator } from './translator';\nimport type { Catalog, Locale, SubscribeOptions, TranslationState, TranslationStoreOptions } from './types';\n\nexport type TranslationSnapshot<C extends Catalog = Catalog> = {\n readonly locale: Locale;\n readonly revision: number;\n readonly translator: Translator<C>;\n};\n\nexport type TranslationStore<C extends Catalog = Catalog> = Translator<C> & {\n [Symbol.dispose](): void;\n readonly disposalSignal: AbortSignal;\n dispose(): void;\n readonly disposed: boolean;\n getSnapshot(): TranslationSnapshot<C>;\n isLoaded(options?: { locale?: Locale }): boolean;\n load(options?: { locale?: Locale }): Promise<void>;\n serialize(): TranslationState<C>;\n setLocale(locale: Locale): Promise<void>;\n subscribe(listener: (snapshot: TranslationSnapshot<C>) => void, options?: SubscribeOptions): () => void;\n};\n\nexport function createTranslationStore<C extends Catalog>(options: TranslationStoreOptions<C>): TranslationStore<C> {\n const catalogs = createCatalogStore(options.catalogs);\n const fallback = options.fallback;\n const fallbackLocales = (Array.isArray(fallback) ? fallback : fallback ? [fallback] : []).map(canonicalLocale);\n const controller = new AbortController();\n const subscribers = new Set<(snapshot: TranslationSnapshot<C>) => void>();\n let disposed = false;\n let locale = canonicalLocale(options.locale ?? 'en');\n let revision = 0;\n\n const buildSnapshot = (): TranslationSnapshot<C> => ({\n locale,\n revision,\n translator: createTranslatorFromCompiled<C>(catalogs.catalogMap(), { ...options, fallback, locale }),\n });\n let snapshot = buildSnapshot();\n\n const assertLive = (): void => {\n if (disposed) throw new LinguaDisposedError();\n };\n\n const dispose = (): void => {\n if (disposed) return;\n\n disposed = true;\n subscribers.clear();\n controller.abort();\n };\n\n const dispatch = (listener: (next: TranslationSnapshot<C>) => void): void => {\n try {\n listener(snapshot);\n } catch (error) {\n logError('subscriber error', error);\n }\n };\n\n const notify = (): void => {\n revision++;\n snapshot = buildSnapshot();\n\n for (const listener of [...subscribers]) dispatch(listener);\n };\n\n const relevant = (candidate: Locale): boolean => localeChain(locale, fallbackLocales).includes(candidate);\n\n return {\n get disposalSignal() {\n return controller.signal;\n },\n dispose,\n get disposed() {\n return disposed;\n },\n getSnapshot() {\n return snapshot;\n },\n isLoaded(loadOptions) {\n return !disposed && catalogs.isLoaded(loadOptions?.locale ?? locale);\n },\n async load(loadOptions) {\n assertLive();\n\n const targetLocale = canonicalLocale(loadOptions?.locale ?? locale);\n const changed = await catalogs.load(targetLocale);\n\n if (!disposed && changed && relevant(targetLocale)) notify();\n },\n get locale() {\n return locale;\n },\n segments(key: string, translateOptions) {\n return snapshot.translator.segmentsDynamic(key, translateOptions);\n },\n segmentsDynamic(key, translateOptions) {\n return snapshot.translator.segmentsDynamic(key, translateOptions);\n },\n serialize() {\n assertLive();\n\n return catalogs.state(locale);\n },\n async setLocale(nextLocale) {\n assertLive();\n\n const next = canonicalLocale(nextLocale);\n\n if (next === locale) return;\n\n locale = next;\n notify();\n },\n subscribe(listener, subscribeOptions) {\n assertLive();\n\n if (subscribeOptions?.signal?.aborted) return () => {};\n\n const unsubscribe = (): void => {\n subscribers.delete(listener);\n subscribeOptions?.signal?.removeEventListener('abort', unsubscribe);\n };\n\n subscribeOptions?.signal?.addEventListener('abort', unsubscribe, { once: true });\n subscribers.add(listener);\n\n if (subscribeOptions?.immediate) dispatch(listener);\n\n return unsubscribe;\n },\n [Symbol.dispose]: dispose,\n translate(key: string, translateOptions = {}) {\n return snapshot.translator.translateDynamic(key, translateOptions);\n },\n translateDynamic(key, translateOptions) {\n return snapshot.translator.translateDynamic(key, translateOptions);\n },\n } as TranslationStore<C>;\n}\n\nexport function hydrateTranslationStore<C extends Catalog>(\n state: TranslationState<C>,\n options?: Omit<TranslationStoreOptions<C>, 'locale' | 'catalogs'>,\n): TranslationStore<C> {\n if (state.version !== 3) {\n throw new LinguaInvalidStateError(`Unsupported lingua state version: ${String(state.version)}.`);\n }\n\n return createTranslationStore({ ...options, catalogs: state.catalogs, locale: state.locale });\n}\n"],"mappings":"mEAAA,IAAa,EAAb,MAAa,UAAoB,KAAM,CACrC,YAAY,EAAiB,EAAqB,CAChD,MAAM,EAAS,CAAI,EACnB,KAAK,KAAO,WAAW,KACvB,OAAO,eAAe,KAAM,WAAW,SAAS,CAClD,CAEA,OAAO,GAAG,EAAsC,CAC9C,OAAO,aAA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ALA,GAAkB,QAAQ,iBAAiB,QAAS,EAAa,CAAE,KAAM,EAAK,CAAC,EAC/E,EAAY,IAAI,CAAQ,EAEpB,GAAkB,WAAW,EAAS,CAAQ,EAE3C,CACT,GACC,OAAO,SAAU,EAClB,UAAU,EAAa,EAAmB,CAAC,EAAG,CAC5C,OAAO,EAAS,WAAW,iBAAiB,EAAK,CAAgB,CACnE,EACA,iBAAiB,EAAK,EAAkB,CACtC,OAAO,EAAS,WAAW,iBAAiB,EAAK,CAAgB,CACnE,CACF,CACF,CAEA,SAAgB,EACd,EACA,EACqB,CACrB,GAAI,EAAM,UAAY,EACpB,MAAM,IAAI,EAAwB,qCAAqC,OAAO,EAAM,OAAO,EAAE,EAAE,EAGjG,OAAO,EAAuB,CAAE,GAAG,EAAS,SAAU,EAAM,SAAU,OAAQ,EAAM,MAAO,CAAC,CAC9F"}
1
+ {"version":3,"file":"lingua.cjs","names":[],"sources":["../src/_template.ts","../src/errors.ts","../src/_catalog.ts","../src/catalog.ts","../src/_dev.ts","../src/_locale.ts","../src/_resources.ts","../src/translator.ts","../src/i18n.ts"],"sourcesContent":["export type TemplatePart = string | { readonly value: string };\nexport type Template = readonly TemplatePart[];\n\nconst interpolation = /\\{([\\p{ID_Continue}-]+)\\}/gu;\n\nexport function compileTemplate(value: string): Template {\n const parts: TemplatePart[] = [];\n let offset = 0;\n\n for (const match of value.matchAll(interpolation)) {\n const index = match.index ?? 0;\n\n if (index > offset) parts.push(value.slice(offset, index));\n\n parts.push({ value: match[1] });\n offset = index + match[0].length;\n }\n\n if (offset < value.length) parts.push(value.slice(offset));\n\n return parts;\n}\n\nexport function renderText(\n parts: Template,\n values: Record<string, unknown>,\n missing: (name: string) => string,\n): string {\n return parts\n .map((part) => {\n if (typeof part === 'string') return part;\n\n const value = Object.hasOwn(values, part.value) ? values[part.value] : undefined;\n\n return value == null ? missing(part.value) : String(value);\n })\n .join('');\n}\n\nexport function renderSegments<V>(\n parts: Template,\n values: Record<string, V | number>,\n missing: (name: string) => string,\n): Array<string | number | V> {\n const result: Array<string | number | V> = [];\n\n for (const part of parts) {\n if (typeof part === 'string') {\n if (part !== '') result.push(part);\n\n continue;\n }\n\n result.push(Object.hasOwn(values, part.value) ? values[part.value]! : missing(part.value));\n }\n\n return result;\n}\n","export class LinguaError extends Error {\n constructor(message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n\n static is(error: unknown): error is LinguaError {\n return error instanceof LinguaError;\n }\n}\n\nexport class LinguaDisposedError extends LinguaError {\n constructor() {\n super('Operation called on a disposed translation store.');\n }\n}\n\nexport class LinguaInvalidCatalogError extends LinguaError {}\nexport class LinguaInvalidLocaleError extends LinguaError {}\nexport class LinguaInvalidPluralCountError extends LinguaError {}\nexport class LinguaInvalidStateError extends LinguaError {}\nexport class LinguaMissingCatalogError extends LinguaError {}\n","import { compileTemplate, type Template } from './_template';\nimport { LinguaInvalidCatalogError } from './errors';\nimport type { Catalog, CatalogNode, PluralMessage } from './types';\n\nconst unsafeKeys = new Set(['__proto__', 'constructor', 'prototype']);\n\nexport type CompiledText = { readonly kind: 'text'; readonly template: Template };\nexport type CompiledPlural = { readonly forms: ReadonlyMap<string, Template>; readonly kind: 'plural' };\nexport type CompiledMessage = CompiledPlural | CompiledText;\nexport type CompiledCatalog = ReadonlyMap<string, CompiledMessage>;\n\nexport function isPluralMessage(node: CatalogNode): node is PluralMessage {\n return typeof node === 'object' && node !== null && Object.hasOwn(node, 'plural');\n}\n\n/** Compile explicit catalog nodes once. Nested objects only group keys; plural intent is never inferred. */\nexport function compileCatalog(catalog: Catalog): CompiledCatalog {\n const messages = new Map<string, CompiledMessage>();\n\n const visit = (node: CatalogNode, prefix: string): void => {\n if (typeof node === 'string') {\n messages.set(prefix, { kind: 'text', template: compileTemplate(node) });\n\n return;\n }\n\n if (typeof node !== 'object' || node === null || Array.isArray(node)) {\n throw new LinguaInvalidCatalogError(`Catalog node \"${prefix}\" must be a string, plural message, or object.`);\n }\n\n if (isPluralMessage(node)) {\n if (Reflect.ownKeys(node).some((key) => key !== 'plural')) {\n throw new LinguaInvalidCatalogError(`Plural message \"${prefix}\" must contain only a \"plural\" property.`);\n }\n\n if (typeof node.plural !== 'object' || node.plural === null || Array.isArray(node.plural)) {\n throw new LinguaInvalidCatalogError(`Plural message \"${prefix}\" must provide an object of string forms.`);\n }\n\n const forms = new Map<string, Template>();\n\n for (const [form, template] of Object.entries(node.plural)) {\n if (typeof template !== 'string') {\n throw new LinguaInvalidCatalogError(`Plural form \"${prefix}.${form}\" must be a string.`);\n }\n\n forms.set(form, compileTemplate(template));\n }\n\n messages.set(prefix, { forms, kind: 'plural' });\n\n return;\n }\n\n for (const [key, value] of Object.entries(node)) {\n if (unsafeKeys.has(key)) {\n throw new LinguaInvalidCatalogError(`Catalog key \"${key}\" is reserved.`);\n }\n\n visit(value, prefix ? `${prefix}.${key}` : key);\n }\n };\n\n for (const [key, value] of Object.entries(catalog)) {\n if (unsafeKeys.has(key)) throw new LinguaInvalidCatalogError(`Catalog key \"${key}\" is reserved.`);\n\n visit(value, key);\n }\n\n return messages;\n}\n","import { compileCatalog } from './_catalog';\nimport type { TranslationStore } from './i18n';\nimport type { Catalog, TextKey } from './types';\n\n/** Enumerate every message key in a catalog as a dotted path.\n *\n * Traverses nested grouping objects and explicit `{ plural: ... }` messages,\n * producing the same dotted paths that `TextKey<C>` represents at the type\n * level. Use this to derive key arrays from the catalog itself instead of\n * maintaining a parallel list that can go stale.\n *\n * Pass a `TranslationStore` to enumerate keys from its current locale catalog\n * without specifying a locale explicitly.\n *\n * @example\n * ```ts\n * const messages = {\n * nav: { home: '...', settings: '...' },\n * };\n * const keys = catalogKeys(messages); // ['nav.home', 'nav.settings']\n *\n * // From a translation store — uses current locale's catalog\n * const i18n = createTranslationStore({ catalogs: { en: messages }, locale: 'en' });\n * const allKeys = catalogKeys(i18n);\n * ```\n */\nexport function catalogKeys<C extends Catalog>(store: TranslationStore<C>): ReadonlyArray<TextKey<C>>;\nexport function catalogKeys<C extends Catalog>(catalog: C): ReadonlyArray<TextKey<C>>;\nexport function catalogKeys(source: unknown): ReadonlyArray<TextKey<Catalog>> {\n const catalog =\n typeof source === 'object' && source !== null && 'serialize' in source && 'getSnapshot' in source\n ? (source as TranslationStore).serialize().catalogs[(source as TranslationStore).locale]\n : (source as Catalog);\n\n return [...compileCatalog(catalog).keys()] as unknown as ReadonlyArray<TextKey<Catalog>>;\n}\n","const isDev = !(globalThis as { __LINGUA_PROD__?: boolean }).__LINGUA_PROD__;\n\n/** @internal @security Messages may include user-supplied data. */\nexport function warn(msg: string): void {\n if (isDev) console.warn(`[@vielzeug/lingua] ${msg}`);\n}\n\n/** @internal */\nexport function error(msg: string, ...args: unknown[]): void {\n if (isDev) console.error(`[@vielzeug/lingua] ${msg}`, ...args);\n}\n\n/** @internal — Run fn only in dev builds. Use when dev-only logic goes beyond a single warn() / error() call. */\nexport function devOnly(fn: () => void): void {\n if (isDev) fn();\n}\n","import { LinguaInvalidLocaleError } from './errors';\nimport type { Locale } from './types';\n\nconst pluralRules = new Map<string, Intl.PluralRules>();\n\nexport function canonicalLocale(locale: string): Locale {\n try {\n const [canonical] = Intl.getCanonicalLocales(locale);\n\n if (canonical) return canonical;\n } catch {\n // Error below names the failed public input.\n }\n\n throw new LinguaInvalidLocaleError(`Invalid BCP 47 locale tag: \"${locale}\".`);\n}\n\nexport function localeChain(locale: Locale, fallback: readonly Locale[]): readonly Locale[] {\n const chain = new Set<Locale>();\n\n for (const candidate of [locale, ...fallback]) {\n const parts = candidate.split('-');\n\n for (let length = parts.length; length > 0; length--) {\n chain.add(parts.slice(0, length).join('-'));\n }\n }\n\n return [...chain];\n}\n\nexport function pluralCategory(locale: Locale, count: number, ordinal: boolean): Intl.LDMLPluralRule {\n const key = `${locale}:${ordinal ? 'ordinal' : 'cardinal'}`;\n let rules = pluralRules.get(key);\n\n if (!rules) {\n rules = new Intl.PluralRules(locale, { type: ordinal ? 'ordinal' : 'cardinal' });\n pluralRules.set(key, rules);\n }\n\n return rules.select(count);\n}\n","import { type CompiledCatalog, compileCatalog } from './_catalog';\nimport { canonicalLocale } from './_locale';\nimport { LinguaMissingCatalogError } from './errors';\nimport type { Catalog, CatalogSources, Catalogs, Locale, TranslationState } from './types';\n\n/** One catalog state machine owns static sources, lazy sources, and in-flight work. */\nexport function createCatalogStore<C extends Catalog>(sources: CatalogSources<C>) {\n const definitions = new Map<Locale, C | (() => Promise<C>)>();\n const loaded = new Map<Locale, { readonly catalog: C; readonly compiled: CompiledCatalog }>();\n const tasks = new Map<Locale, Promise<void>>();\n\n for (const [locale, source] of Object.entries(sources)) definitions.set(canonicalLocale(locale), source);\n\n const add = (locale: Locale, catalog: C): void => {\n loaded.set(locale, { catalog, compiled: compileCatalog(catalog) });\n };\n\n for (const [locale, source] of definitions) {\n if (typeof source !== 'function') add(locale, source);\n }\n\n const load = async (requestedLocale: Locale): Promise<boolean> => {\n const locale = canonicalLocale(requestedLocale);\n\n if (loaded.has(locale)) return false;\n\n const source = definitions.get(locale);\n\n if (!source) throw new LinguaMissingCatalogError(`Catalog has no source for locale \"${locale}\".`);\n\n if (typeof source !== 'function') {\n add(locale, source);\n\n return true;\n }\n\n const existing = tasks.get(locale);\n\n if (existing) {\n await existing;\n\n return false;\n }\n\n const task = source().then(\n (catalog) => {\n add(locale, catalog);\n tasks.delete(locale);\n },\n (error: unknown) => {\n tasks.delete(locale);\n throw error;\n },\n );\n\n tasks.set(locale, task);\n await task;\n\n return true;\n };\n\n return {\n catalogMap(): ReadonlyMap<Locale, CompiledCatalog> {\n return new Map([...loaded].map(([locale, { compiled }]) => [locale, compiled]));\n },\n isLoaded(locale: Locale): boolean {\n return loaded.has(canonicalLocale(locale));\n },\n load,\n state(locale: Locale): TranslationState<C> {\n const catalogs: Catalogs<C> = {};\n\n for (const [loadedLocale, { catalog }] of loaded) catalogs[loadedLocale] = catalog;\n\n return { catalogs, locale, version: 3 };\n },\n };\n}\n","import { type CompiledCatalog, type CompiledMessage, compileCatalog } from './_catalog';\nimport { canonicalLocale, localeChain, pluralCategory } from './_locale';\nimport { renderSegments, renderText, type Template } from './_template';\nimport { LinguaInvalidPluralCountError } from './errors';\nimport type {\n Catalog,\n Catalogs,\n CatalogTranslatorOptions,\n Locale,\n PluralKey,\n PluralOptions,\n TextKey,\n TranslateOptions,\n TranslatorOptions,\n} from './types';\n\nexport type Translator<C extends Catalog = Catalog> = {\n readonly locale: Locale;\n segments<V>(key: TextKey<C>, options: TranslateOptions & { values: Record<string, V> }): Array<string | V>;\n segments<V>(key: PluralKey<C>, options: PluralOptions & { values?: Record<string, V> }): Array<string | number | V>;\n segmentsDynamic<V>(\n key: string,\n options: (TranslateOptions | PluralOptions) & { values?: Record<string, V> },\n ): Array<string | number | V>;\n translate(key: TextKey<C>, options?: TranslateOptions): string;\n translate(key: PluralKey<C>, options: PluralOptions): string;\n translateDynamic(key: string, options?: TranslateOptions | PluralOptions): string;\n};\n\ntype ResolvedMessage = { readonly locale: Locale; readonly message: CompiledMessage };\n\nexport function createTranslatorFromCompiled<C extends Catalog>(\n catalogs: ReadonlyMap<Locale, CompiledCatalog>,\n options: TranslatorOptions = {},\n): Translator<C> {\n const locale = canonicalLocale(options.locale ?? 'en');\n const fallback = (\n Array.isArray(options.fallback) ? options.fallback : options.fallback ? [options.fallback] : []\n ).map(canonicalLocale);\n const chain = localeChain(locale, fallback);\n const missingKey = options.onMissingKey ?? ((key: string) => key);\n const missingValue = options.onMissingValue ?? ((name: string) => `{${name}}`);\n\n const resolve = (key: string): ResolvedMessage | undefined => {\n for (const candidate of chain) {\n const message = catalogs.get(candidate)?.get(key);\n\n if (message) return { locale: candidate, message };\n }\n\n return undefined;\n };\n\n const templateFor = (\n key: string,\n options: TranslateOptions | PluralOptions,\n ): { key: string; template: Template } | undefined => {\n const found = resolve(key);\n\n if (!found) return undefined;\n\n if (found.message.kind === 'text') {\n if ('count' in options) return undefined;\n\n return { key, template: found.message.template };\n }\n\n if (!('count' in options) || !Number.isFinite(options.count)) {\n if ('count' in options) throw new LinguaInvalidPluralCountError('`count` must be a finite number.');\n\n return undefined;\n }\n\n const category =\n options.count === 0 && !options.ordinal\n ? 'zero'\n : pluralCategory(found.locale, options.count, options.ordinal ?? false);\n const template = found.message.forms.get(category) ?? found.message.forms.get('other');\n\n return template ? { key, template } : undefined;\n };\n\n const valuesFor = (options: TranslateOptions | PluralOptions): Record<string, unknown> =>\n 'count' in options ? { count: options.count, ...options.values } : (options.values ?? {});\n\n const segmentsDynamic = <V>(\n key: string,\n options: (TranslateOptions | PluralOptions) & { values?: Record<string, V> },\n ): Array<string | number | V> => {\n const found = templateFor(key, options);\n\n if (!found) return [missingKey(key, locale)];\n\n return renderSegments(found.template, valuesFor(options) as Record<string, V | number>, (name) =>\n missingValue(name, found.key, locale),\n );\n };\n\n const translateDynamic = (key: string, options: TranslateOptions | PluralOptions = {}): string => {\n const found = templateFor(key, options);\n\n if (!found) return missingKey(key, locale);\n\n return renderText(found.template, valuesFor(options), (name) => missingValue(name, found.key, locale));\n };\n\n return {\n locale,\n segments(key: string, options: (TranslateOptions | PluralOptions) & { values?: Record<string, unknown> }) {\n return segmentsDynamic(key, options);\n },\n segmentsDynamic,\n translate(key: string, options: TranslateOptions | PluralOptions = {}) {\n return translateDynamic(key, options);\n },\n translateDynamic,\n } as Translator<C>;\n}\n\n/** Creates a fixed-locale translator from one catalog. Lingua snapshots catalog messages during construction. */\nexport function createCatalogTranslator<C extends Catalog>(\n catalog: C,\n options: CatalogTranslatorOptions = {},\n): Translator<C> {\n const locale = canonicalLocale(options.locale ?? 'en');\n const compiled = new Map<Locale, CompiledCatalog>([[locale, compileCatalog(catalog)]]);\n\n return createTranslatorFromCompiled<C>(compiled, { ...options, locale });\n}\n\nexport function createTranslator<C extends Catalog>(catalogs: Catalogs<C>, options?: TranslatorOptions): Translator<C> {\n const compiled = new Map<Locale, CompiledCatalog>();\n\n for (const [locale, catalog] of Object.entries(catalogs)) {\n compiled.set(canonicalLocale(locale), compileCatalog(catalog));\n }\n\n return createTranslatorFromCompiled<C>(compiled, options);\n}\n","import { error as logError } from './_dev';\nimport { canonicalLocale, localeChain } from './_locale';\nimport { createCatalogStore } from './_resources';\nimport { LinguaDisposedError, LinguaInvalidStateError } from './errors';\nimport { createTranslatorFromCompiled, type Translator } from './translator';\nimport type { Catalog, Locale, SubscribeOptions, TranslationState, TranslationStoreOptions } from './types';\n\nexport type TranslationSnapshot<C extends Catalog = Catalog> = {\n readonly locale: Locale;\n readonly revision: number;\n readonly translator: Translator<C>;\n};\n\nexport type TranslationStore<C extends Catalog = Catalog> = Translator<C> & {\n [Symbol.dispose](): void;\n readonly disposalSignal: AbortSignal;\n dispose(): void;\n readonly disposed: boolean;\n getSnapshot(): TranslationSnapshot<C>;\n isLoaded(options?: { locale?: Locale }): boolean;\n load(options?: { locale?: Locale }): Promise<void>;\n serialize(): TranslationState<C>;\n setLocale(locale: Locale): Promise<void>;\n subscribe(listener: (snapshot: TranslationSnapshot<C>) => void, options?: SubscribeOptions): () => void;\n};\n\nexport function createTranslationStore<C extends Catalog>(options: TranslationStoreOptions<C>): TranslationStore<C> {\n const catalogs = createCatalogStore(options.catalogs);\n const fallback = options.fallback;\n const fallbackLocales = (Array.isArray(fallback) ? fallback : fallback ? [fallback] : []).map(canonicalLocale);\n const controller = new AbortController();\n const subscribers = new Set<(snapshot: TranslationSnapshot<C>) => void>();\n let disposed = false;\n let locale = canonicalLocale(options.locale ?? 'en');\n let revision = 0;\n\n const buildSnapshot = (): TranslationSnapshot<C> => ({\n locale,\n revision,\n translator: createTranslatorFromCompiled<C>(catalogs.catalogMap(), { ...options, fallback, locale }),\n });\n let snapshot = buildSnapshot();\n\n const assertLive = (): void => {\n if (disposed) throw new LinguaDisposedError();\n };\n\n const dispose = (): void => {\n if (disposed) return;\n\n disposed = true;\n subscribers.clear();\n controller.abort();\n };\n\n const dispatch = (listener: (next: TranslationSnapshot<C>) => void): void => {\n try {\n listener(snapshot);\n } catch (error) {\n logError('subscriber error', error);\n }\n };\n\n const notify = (): void => {\n revision++;\n snapshot = buildSnapshot();\n\n for (const listener of [...subscribers]) dispatch(listener);\n };\n\n const relevant = (candidate: Locale): boolean => localeChain(locale, fallbackLocales).includes(candidate);\n\n return {\n get disposalSignal() {\n return controller.signal;\n },\n dispose,\n get disposed() {\n return disposed;\n },\n getSnapshot() {\n return snapshot;\n },\n isLoaded(loadOptions) {\n return !disposed && catalogs.isLoaded(loadOptions?.locale ?? locale);\n },\n async load(loadOptions) {\n assertLive();\n\n const targetLocale = canonicalLocale(loadOptions?.locale ?? locale);\n const changed = await catalogs.load(targetLocale);\n\n if (!disposed && changed && relevant(targetLocale)) notify();\n },\n get locale() {\n return locale;\n },\n segments(key: string, translateOptions) {\n return snapshot.translator.segmentsDynamic(key, translateOptions);\n },\n segmentsDynamic(key, translateOptions) {\n return snapshot.translator.segmentsDynamic(key, translateOptions);\n },\n serialize() {\n assertLive();\n\n return catalogs.state(locale);\n },\n async setLocale(nextLocale) {\n assertLive();\n\n const next = canonicalLocale(nextLocale);\n\n if (next === locale) return;\n\n locale = next;\n notify();\n },\n subscribe(listener, subscribeOptions) {\n assertLive();\n\n if (subscribeOptions?.signal?.aborted) return () => {};\n\n const unsubscribe = (): void => {\n subscribers.delete(listener);\n subscribeOptions?.signal?.removeEventListener('abort', unsubscribe);\n };\n\n subscribeOptions?.signal?.addEventListener('abort', unsubscribe, { once: true });\n subscribers.add(listener);\n\n if (subscribeOptions?.immediate) dispatch(listener);\n\n return unsubscribe;\n },\n [Symbol.dispose]: dispose,\n translate(key: string, translateOptions = {}) {\n return snapshot.translator.translateDynamic(key, translateOptions);\n },\n translateDynamic(key, translateOptions) {\n return snapshot.translator.translateDynamic(key, translateOptions);\n },\n } as TranslationStore<C>;\n}\n\nexport function hydrateTranslationStore<C extends Catalog>(\n state: TranslationState<C>,\n options?: Omit<TranslationStoreOptions<C>, 'locale' | 'catalogs'>,\n): TranslationStore<C> {\n if (state.version !== 3) {\n throw new LinguaInvalidStateError(`Unsupported lingua state version: ${String(state.version)}.`);\n }\n\n return createTranslationStore({ ...options, catalogs: state.catalogs, locale: state.locale });\n}\n"],"mappings":"mEAGA,IAAM,EAAgB,8BAEtB,SAAgB,EAAgB,EAAyB,CACvD,IAAM,EAAwB,CAAC,EAC3B,EAAS,EAEb,IAAK,IAAM,KAAS,EAAM,SAAS,CAAa,EAAG,CACjD,IAAM,EAAQ,EAAM,OAAS,EAEzB,EAAQ,GAAQ,EAAM,KAAK,EAAM,MAAM,EAAQ,CAAK,CAAC,EAEzD,EAAM,KAAK,CAAE,MAAO,EAAM,EAAG,CAAC,EAC9B,EAAS,EAAQ,EAAM,EAAE,CAAC,MAC5B,CAIA,OAFI,EAAS,EAAM,QAAQ,EAAM,KAAK,EAAM,MAAM,CAAM,CAAC,EAElD,CACT,CAEA,SAAgB,EACd,EACA,EACA,EACQ,CACR,OAAO,EACJ,IAAK,GAAS,CACb,GAAI,OAAO,GAAS,SAAU,OAAO,EAErC,IAAM,EAAQ,OAAO,OAAO,EAAQ,EAAK,KAAK,EAAI,EAAO,EAAK,OAAS,IAAA,GAEvE,OAAO,GAAS,KAAO,EAAQ,EAAK,KAAK,EAAI,OAAO,CAAK,CAC3D,CAAC,CAAC,CACD,KAAK,EAAE,CACZ,CAEA,SAAgB,EACd,EACA,EACA,EAC4B,CAC5B,IAAM,EAAqC,CAAC,EAE5C,IAAK,IAAM,KAAQ,EAAO,CACxB,GAAI,OAAO,GAAS,SAAU,CACxB,IAAS,IAAI,EAAO,KAAK,CAAI,EAEjC,QACF,CAEA,EAAO,KAAK,OAAO,OAAO,EAAQ,EAAK,KAAK,EAAI,EAAO,EAAK,OAAU,EAAQ,EAAK,KAAK,CAAC,CAC3F,CAEA,OAAO,CACT,CCzDA,IAAa,EAAb,MAAa,UAAoB,KAAM,CACrC,YAAY,EAAiB,EAAqB,CAChD,MAAM,EAAS,CAAI,EACnB,KAAK,KAAO,WAAW,KACvB,OAAO,e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AO,CACT,EACA,SAAS,EAAa,EAAkB,CACtC,OAAO,EAAS,WAAW,gBAAgB,EAAK,CAAgB,CAClE,EACA,gBAAgB,EAAK,EAAkB,CACrC,OAAO,EAAS,WAAW,gBAAgB,EAAK,CAAgB,CAClE,EACA,WAAY,CAGV,OAFA,EAAW,EAEJ,EAAS,MAAM,CAAM,CAC9B,EACA,MAAM,UAAU,EAAY,CAC1B,EAAW,EAEX,IAAM,EAAO,EAAgB,CAAU,EAEnC,IAAS,IAEb,EAAS,EACT,EAAO,EACT,EACA,UAAU,EAAU,EAAkB,CAGpC,GAFA,EAAW,EAEP,GAAkB,QAAQ,QAAS,UAAa,CAAC,EAErD,IAAM,MAA0B,CAC9B,EAAY,OAAO,CAAQ,EAC3B,GAAkB,QAAQ,oBAAoB,QAAS,CAAW,CACpE,EAOA,OALA,GAAkB,QAAQ,iBAAiB,QAAS,EAAa,CAAE,KAAM,EAAK,CAAC,EAC/E,EAAY,IAAI,CAAQ,EAEpB,GAAkB,WAAW,EAAS,CAAQ,EAE3C,CACT,GACC,OAAO,SAAU,EAClB,UAAU,EAAa,EAAmB,CAAC,EAAG,CAC5C,OAAO,EAAS,WAAW,iBAAiB,EAAK,CAAgB,CACnE,EACA,iBAAiB,EAAK,EAAkB,CACtC,OAAO,EAAS,WAAW,iBAAiB,EAAK,CAAgB,CACnE,CACF,CACF,CAEA,SAAgB,EACd,EACA,EACqB,CACrB,GAAI,EAAM,UAAY,EACpB,MAAM,IAAI,EAAwB,qCAAqC,OAAO,EAAM,OAAO,EAAE,EAAE,EAGjG,OAAO,EAAuB,CAAE,GAAG,EAAS,SAAU,EAAM,SAAU,OAAQ,EAAM,MAAO,CAAC,CAC9F"}
@@ -1,2 +1,2 @@
1
- var Lingua=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=class e extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}static is(t){return t instanceof e}},n=class extends t{constructor(){super(`Operation called on a disposed translation store.`)}},r=class extends t{},i=class extends t{},a=class extends t{},o=class extends t{},s=class extends t{},c=new Map;function l(e){try{let[t]=Intl.getCanonicalLocales(e);if(t)return t}catch{}throw new i(`Invalid BCP 47 locale tag: "${e}".`)}function u(e,t){let n=new Set;for(let r of[e,...t]){let e=r.split(`-`);for(let t=e.length;t>0;t--)n.add(e.slice(0,t).join(`-`))}return[...n]}function d(e,t,n){let r=`${e}:${n?`ordinal`:`cardinal`}`,i=c.get(r);return i||(i=new Intl.PluralRules(e,{type:n?`ordinal`:`cardinal`}),c.set(r,i)),i.select(t)}var f=/\{([\p{ID_Continue}-]+)\}/gu;function p(e){let t=[],n=0;for(let r of e.matchAll(f)){let i=r.index??0;i>n&&t.push(e.slice(n,i)),t.push({value:r[1]}),n=i+r[0].length}return n<e.length&&t.push(e.slice(n)),t}function m(e,t,n){return e.map(e=>{if(typeof e==`string`)return e;let r=Object.hasOwn(t,e.value)?t[e.value]:void 0;return r==null?n(e.value):String(r)}).join(``)}function h(e,t,n){let r=[];for(let i of e){if(typeof i==`string`){i!==``&&r.push(i);continue}r.push(Object.hasOwn(t,i.value)?t[i.value]:n(i.value))}return r}var g=new Set([`__proto__`,`constructor`,`prototype`]);function _(e){return typeof e==`object`&&!!e&&Object.hasOwn(e,`plural`)}function v(e){let t=new Map,n=(e,i)=>{if(typeof e==`string`){t.set(i,{kind:`text`,template:p(e)});return}if(typeof e!=`object`||!e||Array.isArray(e))throw new r(`Catalog node "${i}" must be a string, plural message, or object.`);if(_(e)){if(Reflect.ownKeys(e).some(e=>e!==`plural`))throw new r(`Plural message "${i}" must contain only a "plural" property.`);if(typeof e.plural!=`object`||e.plural===null||Array.isArray(e.plural))throw new r(`Plural message "${i}" must provide an object of string forms.`);let n=new Map;for(let[t,a]of Object.entries(e.plural)){if(typeof a!=`string`)throw new r(`Plural form "${i}.${t}" must be a string.`);n.set(t,p(a))}t.set(i,{forms:n,kind:`plural`});return}for(let[t,a]of Object.entries(e)){if(g.has(t))throw new r(`Catalog key "${t}" is reserved.`);n(a,i?`${i}.${t}`:t)}};for(let[t,i]of Object.entries(e)){if(g.has(t))throw new r(`Catalog key "${t}" is reserved.`);n(i,t)}return t}function y(e){let t=new Map,n=new Map,r=new Map;for(let[n,r]of Object.entries(e))t.set(l(n),r);let i=(e,t)=>{n.set(e,{catalog:t,compiled:v(t)})};for(let[e,n]of t)typeof n!=`function`&&i(e,n);return{catalogMap(){return new Map([...n].map(([e,{compiled:t}])=>[e,t]))},isLoaded(e){return n.has(l(e))},load:async e=>{let a=l(e);if(n.has(a))return!1;let o=t.get(a);if(!o)throw new s(`Catalog has no source for locale "${a}".`);if(typeof o!=`function`)return i(a,o),!0;let c=r.get(a);if(c)return await c,!1;let u=o().then(e=>{i(a,e),r.delete(a)},e=>{throw r.delete(a),e});return r.set(a,u),await u,!0},state(e){let t={};for(let[e,{catalog:r}]of n)t[e]=r;return{catalogs:t,locale:e,version:3}}}}function b(e,t={}){let n=l(t.locale??`en`),r=u(n,(Array.isArray(t.fallback)?t.fallback:t.fallback?[t.fallback]:[]).map(l)),i=t.onMissingKey??(e=>e),o=t.onMissingValue??(e=>`{${e}}`),s=t=>{for(let n of r){let r=e.get(n)?.get(t);if(r)return{locale:n,message:r}}},c=(e,t)=>{let n=s(e);if(!n)return;if(n.message.kind===`text`)return`count`in t?void 0:{key:e,template:n.message.template};if(!(`count`in t)||!Number.isFinite(t.count)){if(`count`in t)throw new a("`count` must be a finite number.");return}let r=t.count===0&&!t.ordinal?`zero`:d(n.locale,t.count,t.ordinal??!1),i=n.message.forms.get(r)??n.message.forms.get(`other`);return i?{key:e,template:i}:void 0},f=e=>`count`in e?{count:e.count,...e.values}:e.values??{},p=(e,t)=>{let r=c(e,t);return r?h(r.template,f(t),e=>o(e,r.key,n)):[i(e,n)]},g=(e,t={})=>{let r=c(e,t);return r?m(r.template,f(t),e=>o(e,r.key,n)):i(e,n)};return{locale:n,segments(e,t){return p(e,t)},segmentsDynamic:p,translate(e,t={}){return g(e,t)},translateDynamic:g}}function x(e,t={}){let n=l(t.locale??`en`);return b(new Map([[n,v(e)]]),{...t,locale:n})}function S(e,t){let n=new Map;for(let[t,r]of Object.entries(e))n.set(l(t),v(r));return b(n,t)}function C(e){let t=y(e.catalogs),r=e.fallback,i=(Array.isArray(r)?r:r?[r]:[]).map(l),a=new AbortController,o=new Set,s=!1,c=l(e.locale??`en`),d=0,f=()=>({locale:c,revision:d,translator:b(t.catalogMap(),{...e,fallback:r,locale:c})}),p=f(),m=()=>{if(s)throw new n},h=()=>{s||(s=!0,o.clear(),a.abort())},g=e=>{try{e(p)}catch{}},_=()=>{d++,p=f();for(let e of[...o])g(e)},v=e=>u(c,i).includes(e);return{get disposalSignal(){return a.signal},dispose:h,get disposed(){return s},getSnapshot(){return p},isLoaded(e){return!s&&t.isLoaded(e?.locale??c)},async load(e){m();let n=l(e?.locale??c),r=await t.load(n);!s&&r&&v(n)&&_()},get locale(){return c},segments(e,t){return p.translator.segmentsDynamic(e,t)},segmentsDynamic(e,t){return p.translator.segmentsDynamic(e,t)},serialize(){return m(),t.state(c)},async setLocale(e){m();let t=l(e);t!==c&&(c=t,_())},subscribe(e,t){if(m(),t?.signal?.aborted)return()=>{};let n=()=>{o.delete(e),t?.signal?.removeEventListener(`abort`,n)};return t?.signal?.addEventListener(`abort`,n,{once:!0}),o.add(e),t?.immediate&&g(e),n},[Symbol.dispose]:h,translate(e,t={}){return p.translator.translateDynamic(e,t)},translateDynamic(e,t){return p.translator.translateDynamic(e,t)}}}function w(e,t){if(e.version!==3)throw new o(`Unsupported lingua state version: ${String(e.version)}.`);return C({...t,catalogs:e.catalogs,locale:e.locale})}return e.LinguaDisposedError=n,e.LinguaError=t,e.LinguaInvalidCatalogError=r,e.LinguaInvalidLocaleError=i,e.LinguaInvalidPluralCountError=a,e.LinguaInvalidStateError=o,e.LinguaMissingCatalogError=s,e.createCatalogTranslator=x,e.createTranslationStore=C,e.createTranslator=S,e.hydrateTranslationStore=w,e})({});
1
+ var Lingua=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=/\{([\p{ID_Continue}-]+)\}/gu;function n(e){let n=[],r=0;for(let i of e.matchAll(t)){let t=i.index??0;t>r&&n.push(e.slice(r,t)),n.push({value:i[1]}),r=t+i[0].length}return r<e.length&&n.push(e.slice(r)),n}function r(e,t,n){return e.map(e=>{if(typeof e==`string`)return e;let r=Object.hasOwn(t,e.value)?t[e.value]:void 0;return r==null?n(e.value):String(r)}).join(``)}function i(e,t,n){let r=[];for(let i of e){if(typeof i==`string`){i!==``&&r.push(i);continue}r.push(Object.hasOwn(t,i.value)?t[i.value]:n(i.value))}return r}var a=class e extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}static is(t){return t instanceof e}},o=class extends a{constructor(){super(`Operation called on a disposed translation store.`)}},s=class extends a{},c=class extends a{},l=class extends a{},u=class extends a{},d=class extends a{},f=new Set([`__proto__`,`constructor`,`prototype`]);function p(e){return typeof e==`object`&&!!e&&Object.hasOwn(e,`plural`)}function m(e){let t=new Map,r=(e,i)=>{if(typeof e==`string`){t.set(i,{kind:`text`,template:n(e)});return}if(typeof e!=`object`||!e||Array.isArray(e))throw new s(`Catalog node "${i}" must be a string, plural message, or object.`);if(p(e)){if(Reflect.ownKeys(e).some(e=>e!==`plural`))throw new s(`Plural message "${i}" must contain only a "plural" property.`);if(typeof e.plural!=`object`||e.plural===null||Array.isArray(e.plural))throw new s(`Plural message "${i}" must provide an object of string forms.`);let r=new Map;for(let[t,a]of Object.entries(e.plural)){if(typeof a!=`string`)throw new s(`Plural form "${i}.${t}" must be a string.`);r.set(t,n(a))}t.set(i,{forms:r,kind:`plural`});return}for(let[t,n]of Object.entries(e)){if(f.has(t))throw new s(`Catalog key "${t}" is reserved.`);r(n,i?`${i}.${t}`:t)}};for(let[t,n]of Object.entries(e)){if(f.has(t))throw new s(`Catalog key "${t}" is reserved.`);r(n,t)}return t}function h(e){return[...m(typeof e==`object`&&e&&`serialize`in e&&`getSnapshot`in e?e.serialize().catalogs[e.locale]:e).keys()]}var g=new Map;function _(e){try{let[t]=Intl.getCanonicalLocales(e);if(t)return t}catch{}throw new c(`Invalid BCP 47 locale tag: "${e}".`)}function v(e,t){let n=new Set;for(let r of[e,...t]){let e=r.split(`-`);for(let t=e.length;t>0;t--)n.add(e.slice(0,t).join(`-`))}return[...n]}function y(e,t,n){let r=`${e}:${n?`ordinal`:`cardinal`}`,i=g.get(r);return i||(i=new Intl.PluralRules(e,{type:n?`ordinal`:`cardinal`}),g.set(r,i)),i.select(t)}function b(e){let t=new Map,n=new Map,r=new Map;for(let[n,r]of Object.entries(e))t.set(_(n),r);let i=(e,t)=>{n.set(e,{catalog:t,compiled:m(t)})};for(let[e,n]of t)typeof n!=`function`&&i(e,n);return{catalogMap(){return new Map([...n].map(([e,{compiled:t}])=>[e,t]))},isLoaded(e){return n.has(_(e))},load:async e=>{let a=_(e);if(n.has(a))return!1;let o=t.get(a);if(!o)throw new d(`Catalog has no source for locale "${a}".`);if(typeof o!=`function`)return i(a,o),!0;let s=r.get(a);if(s)return await s,!1;let c=o().then(e=>{i(a,e),r.delete(a)},e=>{throw r.delete(a),e});return r.set(a,c),await c,!0},state(e){let t={};for(let[e,{catalog:r}]of n)t[e]=r;return{catalogs:t,locale:e,version:3}}}}function x(e,t={}){let n=_(t.locale??`en`),a=v(n,(Array.isArray(t.fallback)?t.fallback:t.fallback?[t.fallback]:[]).map(_)),o=t.onMissingKey??(e=>e),s=t.onMissingValue??(e=>`{${e}}`),c=t=>{for(let n of a){let r=e.get(n)?.get(t);if(r)return{locale:n,message:r}}},u=(e,t)=>{let n=c(e);if(!n)return;if(n.message.kind===`text`)return`count`in t?void 0:{key:e,template:n.message.template};if(!(`count`in t)||!Number.isFinite(t.count)){if(`count`in t)throw new l("`count` must be a finite number.");return}let r=t.count===0&&!t.ordinal?`zero`:y(n.locale,t.count,t.ordinal??!1),i=n.message.forms.get(r)??n.message.forms.get(`other`);return i?{key:e,template:i}:void 0},d=e=>`count`in e?{count:e.count,...e.values}:e.values??{},f=(e,t)=>{let r=u(e,t);return r?i(r.template,d(t),e=>s(e,r.key,n)):[o(e,n)]},p=(e,t={})=>{let i=u(e,t);return i?r(i.template,d(t),e=>s(e,i.key,n)):o(e,n)};return{locale:n,segments(e,t){return f(e,t)},segmentsDynamic:f,translate(e,t={}){return p(e,t)},translateDynamic:p}}function S(e,t={}){let n=_(t.locale??`en`);return x(new Map([[n,m(e)]]),{...t,locale:n})}function C(e,t){let n=new Map;for(let[t,r]of Object.entries(e))n.set(_(t),m(r));return x(n,t)}function w(e){let t=b(e.catalogs),n=e.fallback,r=(Array.isArray(n)?n:n?[n]:[]).map(_),i=new AbortController,a=new Set,s=!1,c=_(e.locale??`en`),l=0,u=()=>({locale:c,revision:l,translator:x(t.catalogMap(),{...e,fallback:n,locale:c})}),d=u(),f=()=>{if(s)throw new o},p=()=>{s||(s=!0,a.clear(),i.abort())},m=e=>{try{e(d)}catch{}},h=()=>{l++,d=u();for(let e of[...a])m(e)},g=e=>v(c,r).includes(e);return{get disposalSignal(){return i.signal},dispose:p,get disposed(){return s},getSnapshot(){return d},isLoaded(e){return!s&&t.isLoaded(e?.locale??c)},async load(e){f();let n=_(e?.locale??c),r=await t.load(n);!s&&r&&g(n)&&h()},get locale(){return c},segments(e,t){return d.translator.segmentsDynamic(e,t)},segmentsDynamic(e,t){return d.translator.segmentsDynamic(e,t)},serialize(){return f(),t.state(c)},async setLocale(e){f();let t=_(e);t!==c&&(c=t,h())},subscribe(e,t){if(f(),t?.signal?.aborted)return()=>{};let n=()=>{a.delete(e),t?.signal?.removeEventListener(`abort`,n)};return t?.signal?.addEventListener(`abort`,n,{once:!0}),a.add(e),t?.immediate&&m(e),n},[Symbol.dispose]:p,translate(e,t={}){return d.translator.translateDynamic(e,t)},translateDynamic(e,t){return d.translator.translateDynamic(e,t)}}}function T(e,t){if(e.version!==3)throw new u(`Unsupported lingua state version: ${String(e.version)}.`);return w({...t,catalogs:e.catalogs,locale:e.locale})}return e.LinguaDisposedError=o,e.LinguaError=a,e.LinguaInvalidCatalogError=s,e.LinguaInvalidLocaleError=c,e.LinguaInvalidPluralCountError=l,e.LinguaInvalidStateError=u,e.LinguaMissingCatalogError=d,e.catalogKeys=h,e.createCatalogTranslator=S,e.createTranslationStore=w,e.createTranslator=C,e.hydrateTranslationStore=T,e})({});
2
2
  //# sourceMappingURL=lingua.iife.js.map