@vielzeug/lingua 3.0.0 → 26.10.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.
Files changed (71) hide show
  1. package/dist/_bounded-cache.cjs +1 -1
  2. package/dist/_bounded-cache.cjs.map +1 -1
  3. package/dist/_bounded-cache.js +1 -9
  4. package/dist/_bounded-cache.js.map +1 -1
  5. package/dist/_catalog.cjs +1 -1
  6. package/dist/_catalog.cjs.map +1 -1
  7. package/dist/_catalog.js +1 -49
  8. package/dist/_catalog.js.map +1 -1
  9. package/dist/_dev.cjs +1 -1
  10. package/dist/_dev.cjs.map +1 -1
  11. package/dist/_dev.d.ts +1 -1
  12. package/dist/_dev.d.ts.map +1 -1
  13. package/dist/_dev.js +1 -6
  14. package/dist/_dev.js.map +1 -1
  15. package/dist/_locale.cjs +1 -1
  16. package/dist/_locale.cjs.map +1 -1
  17. package/dist/_locale.js +1 -25
  18. package/dist/_locale.js.map +1 -1
  19. package/dist/_resources.cjs +1 -1
  20. package/dist/_resources.cjs.map +1 -1
  21. package/dist/_resources.js +1 -47
  22. package/dist/_resources.js.map +1 -1
  23. package/dist/_template.cjs +1 -1
  24. package/dist/_template.cjs.map +1 -1
  25. package/dist/_template.js +1 -40
  26. package/dist/_template.js.map +1 -1
  27. package/dist/catalog.cjs +1 -1
  28. package/dist/catalog.cjs.map +1 -1
  29. package/dist/catalog.d.ts +6 -6
  30. package/dist/catalog.d.ts.map +1 -1
  31. package/dist/catalog.js +1 -14
  32. package/dist/catalog.js.map +1 -1
  33. package/dist/errors.cjs +1 -1
  34. package/dist/errors.cjs.map +1 -1
  35. package/dist/errors.js +1 -13
  36. package/dist/errors.js.map +1 -1
  37. package/dist/format.cjs +1 -1
  38. package/dist/format.cjs.map +1 -1
  39. package/dist/format.d.ts.map +1 -1
  40. package/dist/format.js +1 -84
  41. package/dist/format.js.map +1 -1
  42. package/dist/i18n.cjs +1 -1
  43. package/dist/i18n.cjs.map +1 -1
  44. package/dist/i18n.d.ts +5 -0
  45. package/dist/i18n.d.ts.map +1 -1
  46. package/dist/i18n.js +1 -103
  47. package/dist/i18n.js.map +1 -1
  48. package/dist/index.js +1 -5
  49. package/dist/lingua.cjs +1 -1
  50. package/dist/lingua.cjs.map +1 -1
  51. package/dist/lingua.iife.js +1 -1
  52. package/dist/lingua.iife.js.map +1 -1
  53. package/dist/lingua.js +1 -1
  54. package/dist/lingua.js.map +1 -1
  55. package/dist/ripple.cjs +2 -0
  56. package/dist/ripple.cjs.map +1 -0
  57. package/dist/ripple.d.ts +24 -0
  58. package/dist/ripple.d.ts.map +1 -0
  59. package/dist/ripple.js +2 -0
  60. package/dist/ripple.js.map +1 -0
  61. package/dist/translator.cjs +1 -1
  62. package/dist/translator.cjs.map +1 -1
  63. package/dist/translator.d.ts.map +1 -1
  64. package/dist/translator.js +1 -76
  65. package/dist/translator.js.map +1 -1
  66. package/dist/types.d.ts +1 -1
  67. package/dist/validate.cjs +1 -1
  68. package/dist/validate.cjs.map +1 -1
  69. package/dist/validate.js +1 -45
  70. package/dist/validate.js.map +1 -1
  71. package/package.json +22 -5
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ripple.cjs","names":[],"sources":["../src/ripple.ts"],"sourcesContent":["import { fromSubscribable, type Readable } from '@vielzeug/ripple';\n\nimport type { I18n } from './i18n';\nimport type { Catalog, Locale, MessageKey, PluralOptions, TranslateOptions } from './types';\n\n/** A lingua instance mirrored into ripple readables so templates react to locale changes. */\nexport interface ReactiveI18n<C extends Catalog> {\n /** The underlying instance for imperative work (`setLocale`, `load`, disposal). */\n readonly i18n: I18n<C>;\n /** Reactive locale — reading it inside a computed/template registers the dependency. */\n readonly locale: Readable<Locale>;\n /** Translate a text or plural key; re-evaluates whenever the locale changes. */\n translate(key: MessageKey<C>, options?: TranslateOptions | PluralOptions): string;\n /** Translate a runtime-assembled key; re-evaluates whenever the locale changes. */\n translateDynamic(key: string, options?: TranslateOptions | PluralOptions): string;\n}\n\n/**\n * Bridges a lingua instance into ripple so translated strings are reactive.\n *\n * `i18n.translate()` is not ripple-reactive on its own: reading it inside a `computed()`\n * computes once and never re-runs, since it registers no tracked dependency. Both translate\n * methods here first read the reactive {@link ReactiveI18n.locale}, so any binding built on them\n * re-evaluates the instant `setLocale()` resolves.\n */\nexport function createReactiveI18n<C extends Catalog>(i18n: I18n<C>): ReactiveI18n<C> {\n const locale = fromSubscribable<Locale>({\n getSnapshot: () => i18n.locale,\n subscribe: (listener) => i18n.subscribe(() => listener()),\n });\n\n return {\n i18n,\n locale,\n translate: (key, options) => {\n void locale.value;\n return i18n.translateDynamic(key, options);\n },\n translateDynamic: (key, options) => {\n void locale.value;\n return i18n.translateDynamic(key, options);\n },\n };\n}\n"],"mappings":"qGAyBA,SAAgB,mBAAsC,EAAgC,CACpF,IAAM,GAAA,EAAS,EAAA,iBAAA,CAAyB,CACtC,gBAAmB,EAAK,OACxB,UAAY,GAAa,EAAK,cAAgB,EAAS,CAAC,CAC1D,CAAC,EAED,MAAO,CACL,OACA,SACA,WAAY,EAAK,KACf,EAAY,MACL,EAAK,iBAAiB,EAAK,CAAO,GAE3C,kBAAmB,EAAK,KACtB,EAAY,MACL,EAAK,iBAAiB,EAAK,CAAO,EAE7C,CACF"}
@@ -0,0 +1,24 @@
1
+ import { type Readable } from '@vielzeug/ripple';
2
+ import type { I18n } from './i18n';
3
+ import type { Catalog, Locale, MessageKey, PluralOptions, TranslateOptions } from './types';
4
+ /** A lingua instance mirrored into ripple readables so templates react to locale changes. */
5
+ export interface ReactiveI18n<C extends Catalog> {
6
+ /** The underlying instance for imperative work (`setLocale`, `load`, disposal). */
7
+ readonly i18n: I18n<C>;
8
+ /** Reactive locale — reading it inside a computed/template registers the dependency. */
9
+ readonly locale: Readable<Locale>;
10
+ /** Translate a text or plural key; re-evaluates whenever the locale changes. */
11
+ translate(key: MessageKey<C>, options?: TranslateOptions | PluralOptions): string;
12
+ /** Translate a runtime-assembled key; re-evaluates whenever the locale changes. */
13
+ translateDynamic(key: string, options?: TranslateOptions | PluralOptions): string;
14
+ }
15
+ /**
16
+ * Bridges a lingua instance into ripple so translated strings are reactive.
17
+ *
18
+ * `i18n.translate()` is not ripple-reactive on its own: reading it inside a `computed()`
19
+ * computes once and never re-runs, since it registers no tracked dependency. Both translate
20
+ * methods here first read the reactive {@link ReactiveI18n.locale}, so any binding built on them
21
+ * re-evaluates the instant `setLocale()` resolves.
22
+ */
23
+ export declare function createReactiveI18n<C extends Catalog>(i18n: I18n<C>): ReactiveI18n<C>;
24
+ //# sourceMappingURL=ripple.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ripple.d.ts","sourceRoot":"","sources":["../src/ripple.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,KAAK,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAEnE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAE5F,6FAA6F;AAC7F,MAAM,WAAW,YAAY,CAAC,CAAC,SAAS,OAAO;IAC7C,mFAAmF;IACnF,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;IACvB,wFAAwF;IACxF,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IAClC,gFAAgF;IAChF,SAAS,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,aAAa,GAAG,MAAM,CAAC;IAClF,mFAAmF;IACnF,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,aAAa,GAAG,MAAM,CAAC;CACnF;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAkBpF"}
package/dist/ripple.js ADDED
@@ -0,0 +1,2 @@
1
+ import{fromSubscribable as e}from"@vielzeug/ripple";function createReactiveI18n(t){let n=e({getSnapshot:()=>t.locale,subscribe:e=>t.subscribe(()=>e())});return{i18n:t,locale:n,translate:(e,r)=>(n.value,t.translateDynamic(e,r)),translateDynamic:(e,r)=>(n.value,t.translateDynamic(e,r))}}export{createReactiveI18n};
2
+ //# sourceMappingURL=ripple.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ripple.js","names":[],"sources":["../src/ripple.ts"],"sourcesContent":["import { fromSubscribable, type Readable } from '@vielzeug/ripple';\n\nimport type { I18n } from './i18n';\nimport type { Catalog, Locale, MessageKey, PluralOptions, TranslateOptions } from './types';\n\n/** A lingua instance mirrored into ripple readables so templates react to locale changes. */\nexport interface ReactiveI18n<C extends Catalog> {\n /** The underlying instance for imperative work (`setLocale`, `load`, disposal). */\n readonly i18n: I18n<C>;\n /** Reactive locale — reading it inside a computed/template registers the dependency. */\n readonly locale: Readable<Locale>;\n /** Translate a text or plural key; re-evaluates whenever the locale changes. */\n translate(key: MessageKey<C>, options?: TranslateOptions | PluralOptions): string;\n /** Translate a runtime-assembled key; re-evaluates whenever the locale changes. */\n translateDynamic(key: string, options?: TranslateOptions | PluralOptions): string;\n}\n\n/**\n * Bridges a lingua instance into ripple so translated strings are reactive.\n *\n * `i18n.translate()` is not ripple-reactive on its own: reading it inside a `computed()`\n * computes once and never re-runs, since it registers no tracked dependency. Both translate\n * methods here first read the reactive {@link ReactiveI18n.locale}, so any binding built on them\n * re-evaluates the instant `setLocale()` resolves.\n */\nexport function createReactiveI18n<C extends Catalog>(i18n: I18n<C>): ReactiveI18n<C> {\n const locale = fromSubscribable<Locale>({\n getSnapshot: () => i18n.locale,\n subscribe: (listener) => i18n.subscribe(() => listener()),\n });\n\n return {\n i18n,\n locale,\n translate: (key, options) => {\n void locale.value;\n return i18n.translateDynamic(key, options);\n },\n translateDynamic: (key, options) => {\n void locale.value;\n return i18n.translateDynamic(key, options);\n },\n };\n}\n"],"mappings":"oDAyBA,SAAgB,mBAAsC,EAAgC,CACpF,IAAM,EAAS,EAAyB,CACtC,gBAAmB,EAAK,OACxB,UAAY,GAAa,EAAK,cAAgB,EAAS,CAAC,CAC1D,CAAC,EAED,MAAO,CACL,OACA,SACA,WAAY,EAAK,KACf,EAAY,MACL,EAAK,iBAAiB,EAAK,CAAO,GAE3C,kBAAmB,EAAK,KACtB,EAAY,MACL,EAAK,iBAAiB,EAAK,CAAO,EAE7C,CACF"}
@@ -1,2 +1,2 @@
1
- const e=require("./_template.cjs"),t=require("./errors.cjs"),n=require("./_catalog.cjs"),r=require("./_locale.cjs");function i(e,n){if(e===`throw`)throw n.name?new t.LinguaMissingValueError(`Missing interpolation value "${n.name}" for key "${n.key}" in locale "${n.locale}".`):new t.LinguaMissingKeyError(`Missing translation key "${n.key}" in locale "${n.locale}".`);return typeof e==`function`?e(n):n.name?`{${n.name}}`:n.key}function a(n,a={}){let o=r.canonicalLocale(a.locale??`en`),s=(Array.isArray(a.fallback)?a.fallback:a.fallback?[a.fallback]:[]).map(r.canonicalLocale),c=r.localeChain(o,s),l=a.missing,u=e=>i(l,{key:e,locale:o}),d=(e,t)=>i(l,{key:t,locale:o,name:e}),f=e=>{for(let t of c){let r=n.get(t)?.get(e);if(r)return{locale:t,message:r}}},p=(e,n)=>{let i=f(e);if(!i)return;if(i.message.kind===`text`)return`count`in n?void 0:{key:e,template:i.message.template};if(!(`count`in n)||!Number.isFinite(n.count)){if(`count`in n)throw new t.LinguaInvalidPluralCountError("`count` must be a finite number.");return}let a=n.count===0&&!n.ordinal?`zero`:r.pluralCategory(i.locale,n.count,n.ordinal??!1),o=i.message.forms.get(a)??i.message.forms.get(`other`);return o?{key:e,template:o}:void 0},m=e=>`count`in e?{count:e.count,...e.values}:e.values??{},h=(t,n)=>{let r=p(t,n);return r?e.renderParts(r.template,m(n),e=>d(e,r.key)):[{type:`text`,value:u(t)}]},g=(t,n={})=>{let r=p(t,n);return r?e.renderText(r.template,m(n),e=>d(e,r.key)):u(t)};return{locale:o,parts(e,t){return h(e,t)},partsDynamic:h,translate(e,t={}){return g(e,t)},translateDynamic:g}}function o(e,t){let i=r.canonicalLocale(t?.locale??`en`);return a(new Map([[i,n.compileCatalog(e)]]),{...t,locale:i})}exports.createTranslator=o,exports.createTranslatorFromCompiled=a;
1
+ const e=require("./_template.cjs"),t=require("./errors.cjs"),n=require("./_catalog.cjs");require("./_dev.cjs");const r=require("./_locale.cjs");function resolveMissing(e,n){if(e===`throw`)throw n.name?new t.LinguaMissingValueError(`Missing interpolation value "${n.name}" for key "${n.key}" in locale "${n.locale}".`):new t.LinguaMissingKeyError(`Missing translation key "${n.key}" in locale "${n.locale}".`);return typeof e==`function`?e(n):n.name?`{${n.name}}`:n.key}function createTranslatorFromCompiled(n,i={}){let a=r.canonicalLocale(i.locale??`en`),o=(Array.isArray(i.fallback)?i.fallback:i.fallback?[i.fallback]:[]).map(r.canonicalLocale),s=r.localeChain(a,o),c=i.missing,missingKey=e=>resolveMissing(c,{key:e,locale:a}),missingValue=(e,t)=>resolveMissing(c,{key:t,locale:a,name:e}),resolve=e=>{for(let t of s){let r=n.get(t)?.get(e);if(r)return{locale:t,message:r}}},templateFor=(e,n)=>{let i=resolve(e);if(!i)return;if(i.message.kind===`text`)return`count`in n?void 0:{key:e,template:i.message.template};if(!(`count`in n)||!Number.isFinite(n.count)){if(`count`in n)throw new t.LinguaInvalidPluralCountError("`count` must be a finite number.");return}let a=n.count===0&&!n.ordinal?`zero`:r.pluralCategory(i.locale,n.count,n.ordinal??!1),o=i.message.forms.get(a)??i.message.forms.get(`other`);return o?{key:e,template:o}:void 0},valuesFor=e=>`count`in e?{count:e.count,...e.values}:e.values??{},partsDynamic=(t,n)=>{let r=templateFor(t,n);return r?e.renderParts(r.template,valuesFor(n),e=>missingValue(e,r.key)):[{type:`text`,value:missingKey(t)}]},translateDynamic=(t,n={})=>{let r=templateFor(t,n);return r?e.renderText(r.template,valuesFor(n),e=>missingValue(e,r.key)):missingKey(t)};return{locale:a,parts(e,t){return partsDynamic(e,t)},partsDynamic,translate(e,t={}){return translateDynamic(e,t)},translateDynamic}}function createTranslator(e,t){let i=r.canonicalLocale(t?.locale??`en`);return createTranslatorFromCompiled(new Map([[i,n.compileCatalog(e)]]),{...t,locale:i})}exports.createTranslator=createTranslator,exports.createTranslatorFromCompiled=createTranslatorFromCompiled;
2
2
  //# sourceMappingURL=translator.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"translator.cjs","names":[],"sources":["../src/translator.ts"],"sourcesContent":["import { type CompiledCatalog, type CompiledMessage, compileCatalog } from './_catalog';\nimport { warn } from './_dev';\nimport { canonicalLocale, localeChain, pluralCategory } from './_locale';\nimport { renderParts, renderText, type Template } from './_template';\nimport { LinguaInvalidPluralCountError, LinguaMissingKeyError, LinguaMissingValueError } from './errors';\nimport type {\n Catalog,\n Locale,\n MissingInfo,\n MissingStrategy,\n Part,\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 parts<V>(key: TextKey<C>, options: TranslateOptions & { values: Record<string, V> }): Array<Part<V>>;\n parts<V>(key: PluralKey<C>, options: PluralOptions & { values?: Record<string, V> }): Array<Part<number | V>>;\n partsDynamic<V>(\n key: string,\n options: (TranslateOptions | PluralOptions) & { values?: Record<string, V> },\n ): Array<Part<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 InternalOptions = {\n readonly fallback?: Locale | readonly Locale[];\n readonly locale?: Locale;\n readonly missing?: MissingStrategy;\n};\n\nconst isDev = !(globalThis as { __LINGUA_PROD__?: boolean }).__LINGUA_PROD__;\n\nfunction resolveMissing(strategy: MissingStrategy | undefined, info: MissingInfo): string {\n if (strategy === 'throw') {\n throw info.name\n ? new LinguaMissingValueError(\n `Missing interpolation value \"${info.name}\" for key \"${info.key}\" in locale \"${info.locale}\".`,\n )\n : new LinguaMissingKeyError(`Missing translation key \"${info.key}\" in locale \"${info.locale}\".`);\n }\n\n if (typeof strategy === 'function') return strategy(info);\n\n // 'key' or undefined (default)\n if (strategy === undefined && isDev) {\n warn(\n info.name\n ? `Missing interpolation value \"${info.name}\" for key \"${info.key}\" in locale \"${info.locale}\".`\n : `Missing translation key \"${info.key}\" in locale \"${info.locale}\".`,\n );\n }\n\n return info.name ? `{${info.name}}` : info.key;\n}\n\ntype ResolvedMessage = { readonly locale: Locale; readonly message: CompiledMessage };\n\nexport function createTranslatorFromCompiled<C extends Catalog>(\n catalogs: ReadonlyMap<Locale, CompiledCatalog>,\n options: InternalOptions = {},\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 missing = options.missing;\n\n const missingKey = (key: string): string => resolveMissing(missing, { key, locale });\n const missingValue = (name: string, key: string): string => resolveMissing(missing, { key, locale, 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 partsDynamic = <V>(\n key: string,\n options: (TranslateOptions | PluralOptions) & { values?: Record<string, V> },\n ): Array<Part<number | V>> => {\n const found = templateFor(key, options);\n\n if (!found) return [{ type: 'text', value: missingKey(key) }];\n\n return renderParts(found.template, valuesFor(options) as Record<string, V | number>, (name) =>\n missingValue(name, found.key),\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);\n\n return renderText(found.template, valuesFor(options), (name) => missingValue(name, found.key));\n };\n\n return {\n locale,\n parts(key: string, options: (TranslateOptions | PluralOptions) & { values?: Record<string, unknown> }) {\n return partsDynamic(key, options);\n },\n partsDynamic,\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 createTranslator<C extends Catalog>(catalog: C, options?: TranslatorOptions): 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"],"mappings":"oHAuCA,SAAS,EAAe,EAAuC,EAA2B,CACxF,GAAI,IAAa,QACf,MAAM,EAAK,KACP,IAAI,EAAA,wBACF,gCAAgC,EAAK,KAAK,aAAa,EAAK,IAAI,eAAe,EAAK,OAAO,GAC7F,EACA,IAAI,EAAA,sBAAsB,4BAA4B,EAAK,IAAI,eAAe,EAAK,OAAO,GAAG,EAcnG,OAXI,OAAO,GAAa,WAAmB,EAAS,CAAI,EAWjD,EAAK,KAAO,IAAI,EAAK,KAAK,GAAK,EAAK,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AAG,EAAQ,MAAO,EAAK,EAAQ,QAAU,CAAC,EAEnF,GACJ,EACA,IAC4B,CAC5B,IAAM,EAAQ,EAAY,EAAK,CAAO,EAItC,OAFK,EAEE,EAAA,YAAY,EAAM,SAAU,EAAU,CAAO,EAAkC,GACpF,EAAa,EAAM,EAAM,GAAG,CAC9B,EAJmB,CAAC,CAAE,KAAM,OAAQ,MAAO,EAAW,CAAG,CAAE,CAAC,CAK9D,EAEM,GAAoB,EAAa,EAA4C,CAAC,IAAc,CAChG,IAAM,EAAQ,EAAY,EAAK,CAAO,EAItC,OAFK,EAEE,EAAA,WAAW,EAAM,SAAU,EAAU,CAAO,EAAI,GAAS,EAAa,EAAM,EAAM,GAAG,CAAC,EAF1E,EAAW,CAAG,CAGnC,EAEA,MAAO,CACL,SACA,MAAM,EAAa,EAAoF,CACrG,OAAO,EAAa,EAAK,CAAO,CAClC,EACA,eACA,UAAU,EAAa,EAA4C,CAAC,EAAG,CACrE,OAAO,EAAiB,EAAK,CAAO,CACtC,EACA,kBACF,CACF,CAGA,SAAgB,EAAoC,EAAY,EAA4C,CAC1G,IAAM,EAAS,EAAA,gBAAgB,GAAS,QAAU,IAAI,EAGtD,OAAO,EAAgC,IAFlB,IAA6B,CAAC,CAAC,EAAQ,EAAA,eAAe,CAAO,CAAC,CAAC,CAE7C,EAAU,CAAE,GAAG,EAAS,QAAO,CAAC,CACzE"}
1
+ {"version":3,"file":"translator.cjs","names":[],"sources":["../src/translator.ts"],"sourcesContent":["import { type CompiledCatalog, type CompiledMessage, compileCatalog } from './_catalog';\nimport { isDev, warn } from './_dev';\nimport { canonicalLocale, localeChain, pluralCategory } from './_locale';\nimport { renderParts, renderText, type Template } from './_template';\nimport { LinguaInvalidPluralCountError, LinguaMissingKeyError, LinguaMissingValueError } from './errors';\nimport type {\n Catalog,\n Locale,\n MissingInfo,\n MissingStrategy,\n Part,\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 parts<V>(key: TextKey<C>, options: TranslateOptions & { values: Record<string, V> }): Array<Part<V>>;\n parts<V>(key: PluralKey<C>, options: PluralOptions & { values?: Record<string, V> }): Array<Part<number | V>>;\n partsDynamic<V>(\n key: string,\n options: (TranslateOptions | PluralOptions) & { values?: Record<string, V> },\n ): Array<Part<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 InternalOptions = {\n readonly fallback?: Locale | readonly Locale[];\n readonly locale?: Locale;\n readonly missing?: MissingStrategy;\n};\n\nfunction resolveMissing(strategy: MissingStrategy | undefined, info: MissingInfo): string {\n if (strategy === 'throw') {\n throw info.name\n ? new LinguaMissingValueError(\n `Missing interpolation value \"${info.name}\" for key \"${info.key}\" in locale \"${info.locale}\".`,\n )\n : new LinguaMissingKeyError(`Missing translation key \"${info.key}\" in locale \"${info.locale}\".`);\n }\n\n if (typeof strategy === 'function') return strategy(info);\n\n // 'key' or undefined (default)\n if (strategy === undefined && isDev) {\n warn(\n info.name\n ? `Missing interpolation value \"${info.name}\" for key \"${info.key}\" in locale \"${info.locale}\".`\n : `Missing translation key \"${info.key}\" in locale \"${info.locale}\".`,\n );\n }\n\n return info.name ? `{${info.name}}` : info.key;\n}\n\ntype ResolvedMessage = { readonly locale: Locale; readonly message: CompiledMessage };\n\nexport function createTranslatorFromCompiled<C extends Catalog>(\n catalogs: ReadonlyMap<Locale, CompiledCatalog>,\n options: InternalOptions = {},\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 missing = options.missing;\n\n const missingKey = (key: string): string => resolveMissing(missing, { key, locale });\n const missingValue = (name: string, key: string): string => resolveMissing(missing, { key, locale, 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 partsDynamic = <V>(\n key: string,\n options: (TranslateOptions | PluralOptions) & { values?: Record<string, V> },\n ): Array<Part<number | V>> => {\n const found = templateFor(key, options);\n\n if (!found) return [{ type: 'text', value: missingKey(key) }];\n\n return renderParts(found.template, valuesFor(options) as Record<string, V | number>, (name) =>\n missingValue(name, found.key),\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);\n\n return renderText(found.template, valuesFor(options), (name) => missingValue(name, found.key));\n };\n\n return {\n locale,\n parts(key: string, options: (TranslateOptions | PluralOptions) & { values?: Record<string, unknown> }) {\n return partsDynamic(key, options);\n },\n partsDynamic,\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 createTranslator<C extends Catalog>(catalog: C, options?: TranslatorOptions): 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"],"mappings":"gJAqCA,SAAS,eAAe,EAAuC,EAA2B,CACxF,GAAI,IAAa,QACf,MAAM,EAAK,KACP,IAAI,EAAA,wBACF,gCAAgC,EAAK,KAAK,aAAa,EAAK,IAAI,eAAe,EAAK,OAAO,GAC7F,EACA,IAAI,EAAA,sBAAsB,4BAA4B,EAAK,IAAI,eAAe,EAAK,OAAO,GAAG,EAcnG,OAXI,OAAO,GAAa,WAAmB,EAAS,CAAI,EAWjD,EAAK,KAAO,IAAI,EAAK,KAAK,GAAK,EAAK,GAC7C,CAIA,SAAgB,6BACd,EACA,EAA2B,CAAC,EACb,CACf,IAAM,EAAS,EAAA,gBAAgB,EAAQ,QAAU,IAAI,EAC/C,GACJ,MAAM,QAAQ,EAAQ,QAAQ,EAAI,EAAQ,SAAW,EAAQ,SAAW,CAAC,EAAQ,QAAQ,EAAI,CAAC,EAAA,CAC9F,IAAI,EAAA,eAAe,EACf,EAAQ,EAAA,YAAY,EAAQ,CAAQ,EACpC,EAAU,EAAQ,QAElB,WAAc,GAAwB,eAAe,EAAS,CAAE,MAAK,QAAO,CAAC,EAC7E,cAAgB,EAAc,IAAwB,eAAe,EAAS,CAAE,MAAK,SAAQ,MAAK,CAAC,EAEnG,QAAW,GAA6C,CAC5D,IAAK,IAAM,KAAa,EAAO,CAC7B,IAAM,EAAU,EAAS,IAAI,CAAS,CAAC,EAAE,IAAI,CAAG,EAEhD,GAAI,EAAS,MAAO,CAAE,OAAQ,EAAW,SAAQ,CACnD,CAGF,EAEM,aACJ,EACA,IACoD,CACpD,IAAM,EAAQ,QAAQ,CAAG,EAEzB,GAAI,CAAC,EAAO,OAEZ,GAAI,EAAM,QAAQ,OAAS,OAGzB,MAFI,UAAW,EAAS,OAEjB,CAAE,MAAK,SAAU,EAAM,QAAQ,QA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AO,EAC5D,QAAQ,EAAE,WAAW,CAAC,MAAM,EAAE,eAAe,CAAC,EAC9C,OAAO,GAAE,eAAoB,GAC5B,UAAU,CAAC,CAAC,CAAC,CAqFf;AAED,iHAAiH;AACjH,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,UAAU,CAAC,CAAC,CAAC,CAK1G"}
@@ -1,77 +1,2 @@
1
- import { renderParts as e, renderText as t } from "./_template.js";
2
- import { LinguaInvalidPluralCountError as n, LinguaMissingKeyError as r, LinguaMissingValueError as i } from "./errors.js";
3
- import { compileCatalog as a } from "./_catalog.js";
4
- import { canonicalLocale as o, localeChain as s, pluralCategory as c } from "./_locale.js";
5
- //#region src/translator.ts
6
- function l(e, t) {
7
- if (e === "throw") throw t.name ? new i(`Missing interpolation value "${t.name}" for key "${t.key}" in locale "${t.locale}".`) : new r(`Missing translation key "${t.key}" in locale "${t.locale}".`);
8
- return typeof e == "function" ? e(t) : t.name ? `{${t.name}}` : t.key;
9
- }
10
- function u(r, i = {}) {
11
- let a = o(i.locale ?? "en"), u = (Array.isArray(i.fallback) ? i.fallback : i.fallback ? [i.fallback] : []).map(o), d = s(a, u), f = i.missing, p = (e) => l(f, {
12
- key: e,
13
- locale: a
14
- }), m = (e, t) => l(f, {
15
- key: t,
16
- locale: a,
17
- name: e
18
- }), h = (e) => {
19
- for (let t of d) {
20
- let n = r.get(t)?.get(e);
21
- if (n) return {
22
- locale: t,
23
- message: n
24
- };
25
- }
26
- }, g = (e, t) => {
27
- let r = h(e);
28
- if (!r) return;
29
- if (r.message.kind === "text") return "count" in t ? void 0 : {
30
- key: e,
31
- template: r.message.template
32
- };
33
- if (!("count" in t) || !Number.isFinite(t.count)) {
34
- if ("count" in t) throw new n("`count` must be a finite number.");
35
- return;
36
- }
37
- let i = t.count === 0 && !t.ordinal ? "zero" : c(r.locale, t.count, t.ordinal ?? !1), a = r.message.forms.get(i) ?? r.message.forms.get("other");
38
- return a ? {
39
- key: e,
40
- template: a
41
- } : void 0;
42
- }, _ = (e) => "count" in e ? {
43
- count: e.count,
44
- ...e.values
45
- } : e.values ?? {}, v = (t, n) => {
46
- let r = g(t, n);
47
- return r ? e(r.template, _(n), (e) => m(e, r.key)) : [{
48
- type: "text",
49
- value: p(t)
50
- }];
51
- }, y = (e, n = {}) => {
52
- let r = g(e, n);
53
- return r ? t(r.template, _(n), (e) => m(e, r.key)) : p(e);
54
- };
55
- return {
56
- locale: a,
57
- parts(e, t) {
58
- return v(e, t);
59
- },
60
- partsDynamic: v,
61
- translate(e, t = {}) {
62
- return y(e, t);
63
- },
64
- translateDynamic: y
65
- };
66
- }
67
- function d(e, t) {
68
- let n = o(t?.locale ?? "en");
69
- return u(/* @__PURE__ */ new Map([[n, a(e)]]), {
70
- ...t,
71
- locale: n
72
- });
73
- }
74
- //#endregion
75
- export { d as createTranslator, u as createTranslatorFromCompiled };
76
-
1
+ import{renderParts as e,renderText as t}from"./_template.js";import{LinguaInvalidPluralCountError as n,LinguaMissingKeyError as r,LinguaMissingValueError as i}from"./errors.js";import{compileCatalog as a}from"./_catalog.js";import"./_dev.js";import{canonicalLocale as o,localeChain as s,pluralCategory as c}from"./_locale.js";function resolveMissing(e,t){if(e===`throw`)throw t.name?new i(`Missing interpolation value "${t.name}" for key "${t.key}" in locale "${t.locale}".`):new r(`Missing translation key "${t.key}" in locale "${t.locale}".`);return typeof e==`function`?e(t):t.name?`{${t.name}}`:t.key}function createTranslatorFromCompiled(r,i={}){let a=o(i.locale??`en`),l=(Array.isArray(i.fallback)?i.fallback:i.fallback?[i.fallback]:[]).map(o),u=s(a,l),d=i.missing,missingKey=e=>resolveMissing(d,{key:e,locale:a}),missingValue=(e,t)=>resolveMissing(d,{key:t,locale:a,name:e}),resolve=e=>{for(let t of u){let n=r.get(t)?.get(e);if(n)return{locale:t,message:n}}},templateFor=(e,t)=>{let r=resolve(e);if(!r)return;if(r.message.kind===`text`)return`count`in t?void 0:{key:e,template:r.message.template};if(!(`count`in t)||!Number.isFinite(t.count)){if(`count`in t)throw new n("`count` must be a finite number.");return}let i=t.count===0&&!t.ordinal?`zero`:c(r.locale,t.count,t.ordinal??!1),a=r.message.forms.get(i)??r.message.forms.get(`other`);return a?{key:e,template:a}:void 0},valuesFor=e=>`count`in e?{count:e.count,...e.values}:e.values??{},partsDynamic=(t,n)=>{let r=templateFor(t,n);return r?e(r.template,valuesFor(n),e=>missingValue(e,r.key)):[{type:`text`,value:missingKey(t)}]},translateDynamic=(e,n={})=>{let r=templateFor(e,n);return r?t(r.template,valuesFor(n),e=>missingValue(e,r.key)):missingKey(e)};return{locale:a,parts(e,t){return partsDynamic(e,t)},partsDynamic,translate(e,t={}){return translateDynamic(e,t)},translateDynamic}}function createTranslator(e,t){let n=o(t?.locale??`en`);return createTranslatorFromCompiled(new Map([[n,a(e)]]),{...t,locale:n})}export{createTranslator,createTranslatorFromCompiled};
77
2
  //# sourceMappingURL=translator.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"translator.js","names":[],"sources":["../src/translator.ts"],"sourcesContent":["import { type CompiledCatalog, type CompiledMessage, compileCatalog } from './_catalog';\nimport { warn } from './_dev';\nimport { canonicalLocale, localeChain, pluralCategory } from './_locale';\nimport { renderParts, renderText, type Template } from './_template';\nimport { LinguaInvalidPluralCountError, LinguaMissingKeyError, LinguaMissingValueError } from './errors';\nimport type {\n Catalog,\n Locale,\n MissingInfo,\n MissingStrategy,\n Part,\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 parts<V>(key: TextKey<C>, options: TranslateOptions & { values: Record<string, V> }): Array<Part<V>>;\n parts<V>(key: PluralKey<C>, options: PluralOptions & { values?: Record<string, V> }): Array<Part<number | V>>;\n partsDynamic<V>(\n key: string,\n options: (TranslateOptions | PluralOptions) & { values?: Record<string, V> },\n ): Array<Part<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 InternalOptions = {\n readonly fallback?: Locale | readonly Locale[];\n readonly locale?: Locale;\n readonly missing?: MissingStrategy;\n};\n\nconst isDev = !(globalThis as { __LINGUA_PROD__?: boolean }).__LINGUA_PROD__;\n\nfunction resolveMissing(strategy: MissingStrategy | undefined, info: MissingInfo): string {\n if (strategy === 'throw') {\n throw info.name\n ? new LinguaMissingValueError(\n `Missing interpolation value \"${info.name}\" for key \"${info.key}\" in locale \"${info.locale}\".`,\n )\n : new LinguaMissingKeyError(`Missing translation key \"${info.key}\" in locale \"${info.locale}\".`);\n }\n\n if (typeof strategy === 'function') return strategy(info);\n\n // 'key' or undefined (default)\n if (strategy === undefined && isDev) {\n warn(\n info.name\n ? `Missing interpolation value \"${info.name}\" for key \"${info.key}\" in locale \"${info.locale}\".`\n : `Missing translation key \"${info.key}\" in locale \"${info.locale}\".`,\n );\n }\n\n return info.name ? `{${info.name}}` : info.key;\n}\n\ntype ResolvedMessage = { readonly locale: Locale; readonly message: CompiledMessage };\n\nexport function createTranslatorFromCompiled<C extends Catalog>(\n catalogs: ReadonlyMap<Locale, CompiledCatalog>,\n options: InternalOptions = {},\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 missing = options.missing;\n\n const missingKey = (key: string): string => resolveMissing(missing, { key, locale });\n const missingValue = (name: string, key: string): string => resolveMissing(missing, { key, locale, 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 partsDynamic = <V>(\n key: string,\n options: (TranslateOptions | PluralOptions) & { values?: Record<string, V> },\n ): Array<Part<number | V>> => {\n const found = templateFor(key, options);\n\n if (!found) return [{ type: 'text', value: missingKey(key) }];\n\n return renderParts(found.template, valuesFor(options) as Record<string, V | number>, (name) =>\n missingValue(name, found.key),\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);\n\n return renderText(found.template, valuesFor(options), (name) => missingValue(name, found.key));\n };\n\n return {\n locale,\n parts(key: string, options: (TranslateOptions | PluralOptions) & { values?: Record<string, unknown> }) {\n return partsDynamic(key, options);\n },\n partsDynamic,\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 createTranslator<C extends Catalog>(catalog: C, options?: TranslatorOptions): 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"],"mappings":";;;;;AAuCA,SAAS,EAAe,GAAuC,GAA2B;C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AAM,QAAQ,EAAQ,OAAO,EAAQ,WAAW,EAAK,GACpE,IAAW,EAAM,QAAQ,MAAM,IAAI,CAAQ,KAAK,EAAM,QAAQ,MAAM,IAAI,OAAO;EAErF,OAAO,IAAW;GAAE;GAAK;EAAS,IAAI,KAAA;CACxC,GAEM,KAAa,MACjB,WAAW,IAAU;EAAE,OAAO,EAAQ;EAAO,GAAG,EAAQ;CAAO,IAAK,EAAQ,UAAU,CAAC,GAEnF,KACJ,GACA,MAC4B;EAC5B,IAAM,IAAQ,EAAY,GAAK,CAAO;EAItC,OAFK,IAEE,EAAY,EAAM,UAAU,EAAU,CAAO,IAAkC,MACpF,EAAa,GAAM,EAAM,GAAG,CAC9B,IAJmB,CAAC;GAAE,MAAM;GAAQ,OAAO,EAAW,CAAG;EAAE,CAAC;CAK9D,GAEM,KAAoB,GAAa,IAA4C,CAAC,MAAc;EAChG,IAAM,IAAQ,EAAY,GAAK,CAAO;EAItC,OAFK,IAEE,EAAW,EAAM,UAAU,EAAU,CAAO,IAAI,MAAS,EAAa,GAAM,EAAM,GAAG,CAAC,IAF1E,EAAW,CAAG;CAGnC;CAEA,OAAO;EACL;EACA,MAAM,GAAa,GAAoF;GACrG,OAAO,EAAa,GAAK,CAAO;EAClC;EACA;EACA,UAAU,GAAa,IAA4C,CAAC,GAAG;GACrE,OAAO,EAAiB,GAAK,CAAO;EACtC;EACA;CACF;AACF;AAGA,SAAgB,EAAoC,GAAY,GAA4C;CAC1G,IAAM,IAAS,EAAgB,GAAS,UAAU,IAAI;CAGtD,OAAO,kBAAgC,IAFlB,IAA6B,CAAC,CAAC,GAAQ,EAAe,CAAO,CAAC,CAAC,CAE7C,GAAU;EAAE,GAAG;EAAS;CAAO,CAAC;AACzE"}
1
+ {"version":3,"file":"translator.js","names":[],"sources":["../src/translator.ts"],"sourcesContent":["import { type CompiledCatalog, type CompiledMessage, compileCatalog } from './_catalog';\nimport { isDev, warn } from './_dev';\nimport { canonicalLocale, localeChain, pluralCategory } from './_locale';\nimport { renderParts, renderText, type Template } from './_template';\nimport { LinguaInvalidPluralCountError, LinguaMissingKeyError, LinguaMissingValueError } from './errors';\nimport type {\n Catalog,\n Locale,\n MissingInfo,\n MissingStrategy,\n Part,\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 parts<V>(key: TextKey<C>, options: TranslateOptions & { values: Record<string, V> }): Array<Part<V>>;\n parts<V>(key: PluralKey<C>, options: PluralOptions & { values?: Record<string, V> }): Array<Part<number | V>>;\n partsDynamic<V>(\n key: string,\n options: (TranslateOptions | PluralOptions) & { values?: Record<string, V> },\n ): Array<Part<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 InternalOptions = {\n readonly fallback?: Locale | readonly Locale[];\n readonly locale?: Locale;\n readonly missing?: MissingStrategy;\n};\n\nfunction resolveMissing(strategy: MissingStrategy | undefined, info: MissingInfo): string {\n if (strategy === 'throw') {\n throw info.name\n ? new LinguaMissingValueError(\n `Missing interpolation value \"${info.name}\" for key \"${info.key}\" in locale \"${info.locale}\".`,\n )\n : new LinguaMissingKeyError(`Missing translation key \"${info.key}\" in locale \"${info.locale}\".`);\n }\n\n if (typeof strategy === 'function') return strategy(info);\n\n // 'key' or undefined (default)\n if (strategy === undefined && isDev) {\n warn(\n info.name\n ? `Missing interpolation value \"${info.name}\" for key \"${info.key}\" in locale \"${info.locale}\".`\n : `Missing translation key \"${info.key}\" in locale \"${info.locale}\".`,\n );\n }\n\n return info.name ? `{${info.name}}` : info.key;\n}\n\ntype ResolvedMessage = { readonly locale: Locale; readonly message: CompiledMessage };\n\nexport function createTranslatorFromCompiled<C extends Catalog>(\n catalogs: ReadonlyMap<Locale, CompiledCatalog>,\n options: InternalOptions = {},\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 missing = options.missing;\n\n const missingKey = (key: string): string => resolveMissing(missing, { key, locale });\n const missingValue = (name: string, key: string): string => resolveMissing(missing, { key, locale, 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 partsDynamic = <V>(\n key: string,\n options: (TranslateOptions | PluralOptions) & { values?: Record<string, V> },\n ): Array<Part<number | V>> => {\n const found = templateFor(key, options);\n\n if (!found) return [{ type: 'text', value: missingKey(key) }];\n\n return renderParts(found.template, valuesFor(options) as Record<string, V | number>, (name) =>\n missingValue(name, found.key),\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);\n\n return renderText(found.template, valuesFor(options), (name) => missingValue(name, found.key));\n };\n\n return {\n locale,\n parts(key: string, options: (TranslateOptions | PluralOptions) & { values?: Record<string, unknown> }) {\n return partsDynamic(key, options);\n },\n partsDynamic,\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 createTranslator<C extends Catalog>(catalog: C, options?: TranslatorOptions): 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"],"mappings":"sUAqCA,SAAS,eAAe,EAAuC,EAA2B,CACxF,GAAI,IAAa,QACf,MAAM,EAAK,KACP,IAAI,EACF,gCAAgC,EAAK,KAAK,aAAa,EAAK,IAAI,eAAe,EAAK,OAAO,GAC7F,EACA,IAAI,EAAsB,4BAA4B,EAAK,IAAI,eAAe,EAAK,OAAO,GAAG,EAcnG,OAXI,OAAO,GAAa,WAAmB,EAAS,CAAI,EAWjD,EAAK,KAAO,IAAI,EAAK,KAAK,GAAK,EAAK,GAC7C,CAIA,SAAgB,6BACd,EACA,EAA2B,CAAC,EACb,CACf,IAAM,EAAS,EAAgB,EAAQ,QAAU,IAAI,EAC/C,GACJ,MAAM,QAAQ,EAAQ,QAAQ,EAAI,EAAQ,SAAW,EAAQ,SAAW,CAAC,EAAQ,QAAQ,EAAI,CAAC,EAAA,CAC9F,IAAI,CAAe,EACf,EAAQ,EAAY,EAAQ,CAAQ,EACpC,EAAU,EAAQ,QAElB,WAAc,GAAwB,eAAe,EAAS,CAAE,MAAK,QAAO,CAAC,EAC7E,cAAgB,EAAc,IAAwB,eAAe,EAAS,CAAE,MAAK,SAAQ,MAAK,CAAC,EAEnG,QAAW,GAA6C,CAC5D,IAAK,IAAM,KAAa,EAAO,CAC7B,IAAM,EAAU,EAAS,IAAI,CAAS,CAAC,EAAE,IAAI,CAAG,EAEhD,GAAI,EAAS,MAAO,CAAE,OAAQ,EAAW,SAAQ,CACnD,CAGF,EAE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CACtC,EACA,gBACF,CACF,CAGA,SAAgB,iBAAoC,EAAY,EAA4C,CAC1G,IAAM,EAAS,EAAgB,GAAS,QAAU,IAAI,EAGtD,OAAO,6BAAgC,IAFlB,IAA6B,CAAC,CAAC,EAAQ,EAAe,CAAO,CAAC,CAAC,CAE7C,EAAU,CAAE,GAAG,EAAS,QAAO,CAAC,CACzE"}
package/dist/types.d.ts CHANGED
@@ -70,7 +70,7 @@ export type SubscribeOptions = {
70
70
  export type TranslationState<C extends Catalog = Catalog> = {
71
71
  readonly catalogs: Catalogs<C>;
72
72
  readonly locale: Locale;
73
- readonly version: 4;
73
+ readonly version: 1;
74
74
  };
75
75
  export {};
76
76
  //# sourceMappingURL=types.d.ts.map
package/dist/validate.cjs CHANGED
@@ -1,2 +1,2 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./_catalog.cjs"),t=require("./_locale.cjs");function n(n,r){e.compileCatalog(n);let i=t.canonicalLocale(r),a=new Intl.PluralRules(i).resolvedOptions().pluralCategories,o=[],s=(t,n)=>{if(typeof t!=`string`){if(e.isPluralMessage(t)){for(let e of a)Object.hasOwn(t.plural,e)||o.push({key:n,locale:i,missing:e});return}for(let[e,r]of Object.entries(t))s(r,n?`${n}.${e}`:e)}};for(let[e,t]of Object.entries(n))s(t,e);return o}function r(t){let n=Object.keys(t),r=new Map,i=[],a=[];for(let i of n)r.set(i,new Set(e.compileCatalog(t[i]).keys()));let o=n[0],s=r.get(o);for(let e of n){if(e===o)continue;let t=r.get(e);for(let n of s)t.has(n)||i.push({key:n,locale:e});for(let n of t)s.has(n)||a.push({key:n,locale:e})}return{extra:a,missing:i}}exports.compareCatalogs=r,exports.validateCatalog=n;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./_catalog.cjs"),t=require("./_locale.cjs");function validateCatalog(n,r){e.compileCatalog(n);let i=t.canonicalLocale(r),a=new Intl.PluralRules(i).resolvedOptions().pluralCategories,o=[],visit=(t,n)=>{if(typeof t!=`string`){if(e.isPluralMessage(t)){for(let e of a)Object.hasOwn(t.plural,e)||o.push({key:n,locale:i,missing:e});return}for(let[e,r]of Object.entries(t))visit(r,n?`${n}.${e}`:e)}};for(let[e,t]of Object.entries(n))visit(t,e);return o}function compareCatalogs(t){let n=Object.keys(t),r=new Map,i=[],a=[];for(let i of n)r.set(i,new Set(e.compileCatalog(t[i]).keys()));let o=n[0],s=r.get(o);for(let e of n){if(e===o)continue;let t=r.get(e);for(let n of s)t.has(n)||i.push({key:n,locale:e});for(let n of t)s.has(n)||a.push({key:n,locale:e})}return{extra:a,missing:i}}exports.compareCatalogs=compareCatalogs,exports.validateCatalog=validateCatalog;
2
2
  //# sourceMappingURL=validate.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"validate.cjs","names":[],"sources":["../src/validate.ts"],"sourcesContent":["import { compileCatalog, isPluralMessage } from './_catalog';\nimport { canonicalLocale } from './_locale';\nimport type { Catalog, CatalogNode, Catalogs, Locale } from './types';\n\nexport type ValidationIssue = {\n key: string;\n locale: Locale;\n missing: Intl.LDMLPluralRule;\n};\n\nexport type CatalogComparison = {\n readonly missing: ReadonlyArray<{ key: string; locale: Locale }>;\n readonly extra: ReadonlyArray<{ key: string; locale: Locale }>;\n};\n\n/** Explicit tooling API. Runtime never loads validation code or emits asynchronous catalog warnings. */\nexport function validateCatalog(catalog: Catalog, locale: Locale): ValidationIssue[] {\n compileCatalog(catalog);\n\n const canonical = canonicalLocale(locale);\n const categories = new Intl.PluralRules(canonical).resolvedOptions().pluralCategories;\n const issues: ValidationIssue[] = [];\n\n const visit = (node: CatalogNode, key: string): void => {\n if (typeof node === 'string') return;\n\n if (isPluralMessage(node)) {\n for (const missing of categories) {\n if (!Object.hasOwn(node.plural, missing)) issues.push({ key, locale: canonical, missing });\n }\n\n return;\n }\n\n for (const [childKey, child] of Object.entries(node)) visit(child, key ? `${key}.${childKey}` : childKey);\n };\n\n for (const [key, node] of Object.entries(catalog)) visit(node, key);\n\n return issues;\n}\n\n/** Compares catalog key sets across locales. Reports keys missing in each target locale and keys present in targets but absent from the base. */\nexport function compareCatalogs<C extends Catalog>(catalogs: Catalogs<C>): CatalogComparison {\n const locales = Object.keys(catalogs);\n const keySets = new Map<Locale, Set<string>>();\n const missing: Array<{ key: string; locale: Locale }> = [];\n const extra: Array<{ key: string; locale: Locale }> = [];\n\n for (const locale of locales) {\n keySets.set(locale, new Set(compileCatalog(catalogs[locale]).keys()));\n }\n\n const base = locales[0];\n const baseKeys = keySets.get(base)!;\n\n for (const locale of locales) {\n if (locale === base) continue;\n const targetKeys = keySets.get(locale)!;\n\n for (const key of baseKeys) {\n if (!targetKeys.has(key)) missing.push({ key, locale });\n }\n\n for (const key of targetKeys) {\n if (!baseKeys.has(key)) extra.push({ key, locale });\n }\n }\n\n return { extra, missing };\n}\n"],"mappings":"gIAgBA,SAAgB,EAAgB,EAAkB,EAAmC,CACnF,EAAA,eAAe,CAAO,EAEtB,IAAM,EAAY,EAAA,gBAAgB,CAAM,EAClC,EAAa,IAAI,KAAK,YAAY,CAAS,CAAC,CAAC,gBAAgB,CAAC,CAAC,iBAC/D,EAA4B,CAAC,EAE7B,GAAS,EAAmB,IAAsB,CAClD,UAAO,GAAS,SAEpB,IAAI,EAAA,gBAAgB,CAAI,EAAG,CACzB,IAAK,IAAM,KAAW,EACf,OAAO,OAAO,EAAK,OAAQ,CAAO,GAAG,EAAO,KAAK,CAAE,MAAK,OAAQ,EAAW,SAAQ,CAAC,EAG3F,MACF,CAEA,IAAK,GAAM,CAAC,EAAU,KAAU,OAAO,QAAQ,CAAI,EAAG,EAAM,EAAO,EAAM,GAAG,EAAI,GAAG,IAAa,CAAQ,CAFxG,CAGF,EAEA,IAAK,GAAM,CAAC,EAAK,KAAS,OAAO,QAAQ,CAAO,EAAG,EAAM,EAAM,CAAG,EAElE,OAAO,CACT,CAGA,SAAgB,EAAmC,EAA0C,CAC3F,IAAM,EAAU,OAAO,KAAK,CAAQ,EAC9B,EAAU,IAAI,IACd,EAAkD,CAAC,EACnD,EAAgD,CAAC,EAEvD,IAAK,IAAM,KAAU,EACnB,EAAQ,IAAI,EAAQ,IAAI,IAAI,EAAA,eAAe,EAAS,EAAO,CAAC,CAAC,KAAK,CAAC,CAAC,EAGtE,IAAM,EAAO,EAAQ,GACf,EAAW,EAAQ,IAAI,CAAI,EAEjC,IAAK,IAAM,KAAU,EAAS,CAC5B,GAAI,IAAW,EAAM,SACrB,IAAM,EAAa,EAAQ,IAAI,CAAM,EAErC,IAAK,IAAM,KAAO,EACX,EAAW,IAAI,CAAG,GAAG,EAAQ,KAAK,CAAE,MAAK,QAAO,CAAC,EAGxD,IAAK,IAAM,KAAO,EACX,EAAS,IAAI,CAAG,GAAG,EAAM,KAAK,CAAE,MAAK,QAAO,CAAC,CAEtD,CAEA,MAAO,CAAE,QAAO,SAAQ,CAC1B"}
1
+ {"version":3,"file":"validate.cjs","names":[],"sources":["../src/validate.ts"],"sourcesContent":["import { compileCatalog, isPluralMessage } from './_catalog';\nimport { canonicalLocale } from './_locale';\nimport type { Catalog, CatalogNode, Catalogs, Locale } from './types';\n\nexport type ValidationIssue = {\n key: string;\n locale: Locale;\n missing: Intl.LDMLPluralRule;\n};\n\nexport type CatalogComparison = {\n readonly missing: ReadonlyArray<{ key: string; locale: Locale }>;\n readonly extra: ReadonlyArray<{ key: string; locale: Locale }>;\n};\n\n/** Explicit tooling API. Runtime never loads validation code or emits asynchronous catalog warnings. */\nexport function validateCatalog(catalog: Catalog, locale: Locale): ValidationIssue[] {\n compileCatalog(catalog);\n\n const canonical = canonicalLocale(locale);\n const categories = new Intl.PluralRules(canonical).resolvedOptions().pluralCategories;\n const issues: ValidationIssue[] = [];\n\n const visit = (node: CatalogNode, key: string): void => {\n if (typeof node === 'string') return;\n\n if (isPluralMessage(node)) {\n for (const missing of categories) {\n if (!Object.hasOwn(node.plural, missing)) issues.push({ key, locale: canonical, missing });\n }\n\n return;\n }\n\n for (const [childKey, child] of Object.entries(node)) visit(child, key ? `${key}.${childKey}` : childKey);\n };\n\n for (const [key, node] of Object.entries(catalog)) visit(node, key);\n\n return issues;\n}\n\n/** Compares catalog key sets across locales. Reports keys missing in each target locale and keys present in targets but absent from the base. */\nexport function compareCatalogs<C extends Catalog>(catalogs: Catalogs<C>): CatalogComparison {\n const locales = Object.keys(catalogs);\n const keySets = new Map<Locale, Set<string>>();\n const missing: Array<{ key: string; locale: Locale }> = [];\n const extra: Array<{ key: string; locale: Locale }> = [];\n\n for (const locale of locales) {\n keySets.set(locale, new Set(compileCatalog(catalogs[locale]).keys()));\n }\n\n const base = locales[0];\n const baseKeys = keySets.get(base)!;\n\n for (const locale of locales) {\n if (locale === base) continue;\n const targetKeys = keySets.get(locale)!;\n\n for (const key of baseKeys) {\n if (!targetKeys.has(key)) missing.push({ key, locale });\n }\n\n for (const key of targetKeys) {\n if (!baseKeys.has(key)) extra.push({ key, locale });\n }\n }\n\n return { extra, missing };\n}\n"],"mappings":"gIAgBA,SAAgB,gBAAgB,EAAkB,EAAmC,CACnF,EAAA,eAAe,CAAO,EAEtB,IAAM,EAAY,EAAA,gBAAgB,CAAM,EAClC,EAAa,IAAI,KAAK,YAAY,CAAS,CAAC,CAAC,gBAAgB,CAAC,CAAC,iBAC/D,EAA4B,CAAC,EAE7B,OAAS,EAAmB,IAAsB,CAClD,UAAO,GAAS,SAEpB,IAAI,EAAA,gBAAgB,CAAI,EAAG,CACzB,IAAK,IAAM,KAAW,EACf,OAAO,OAAO,EAAK,OAAQ,CAAO,GAAG,EAAO,KAAK,CAAE,MAAK,OAAQ,EAAW,SAAQ,CAAC,EAG3F,MACF,CAEA,IAAK,GAAM,CAAC,EAAU,KAAU,OAAO,QAAQ,CAAI,EAAG,MAAM,EAAO,EAAM,GAAG,EAAI,GAAG,IAAa,CAAQ,CAFxG,CAGF,EAEA,IAAK,GAAM,CAAC,EAAK,KAAS,OAAO,QAAQ,CAAO,EAAG,MAAM,EAAM,CAAG,EAElE,OAAO,CACT,CAGA,SAAgB,gBAAmC,EAA0C,CAC3F,IAAM,EAAU,OAAO,KAAK,CAAQ,EAC9B,EAAU,IAAI,IACd,EAAkD,CAAC,EACnD,EAAgD,CAAC,EAEvD,IAAK,IAAM,KAAU,EACnB,EAAQ,IAAI,EAAQ,IAAI,IAAI,EAAA,eAAe,EAAS,EAAO,CAAC,CAAC,KAAK,CAAC,CAAC,EAGtE,IAAM,EAAO,EAAQ,GACf,EAAW,EAAQ,IAAI,CAAI,EAEjC,IAAK,IAAM,KAAU,EAAS,CAC5B,GAAI,IAAW,EAAM,SACrB,IAAM,EAAa,EAAQ,IAAI,CAAM,EAErC,IAAK,IAAM,KAAO,EACX,EAAW,IAAI,CAAG,GAAG,EAAQ,KAAK,CAAE,MAAK,QAAO,CAAC,EAGxD,IAAK,IAAM,KAAO,EACX,EAAS,IAAI,CAAG,GAAG,EAAM,KAAK,CAAE,MAAK,QAAO,CAAC,CAEtD,CAEA,MAAO,CAAE,QAAO,SAAQ,CAC1B"}
package/dist/validate.js CHANGED
@@ -1,46 +1,2 @@
1
- import { compileCatalog as e, isPluralMessage as t } from "./_catalog.js";
2
- import { canonicalLocale as n } from "./_locale.js";
3
- //#region src/validate.ts
4
- function r(r, i) {
5
- e(r);
6
- let a = n(i), o = new Intl.PluralRules(a).resolvedOptions().pluralCategories, s = [], c = (e, n) => {
7
- if (typeof e != "string") {
8
- if (t(e)) {
9
- for (let t of o) Object.hasOwn(e.plural, t) || s.push({
10
- key: n,
11
- locale: a,
12
- missing: t
13
- });
14
- return;
15
- }
16
- for (let [t, r] of Object.entries(e)) c(r, n ? `${n}.${t}` : t);
17
- }
18
- };
19
- for (let [e, t] of Object.entries(r)) c(t, e);
20
- return s;
21
- }
22
- function i(t) {
23
- let n = Object.keys(t), r = /* @__PURE__ */ new Map(), i = [], a = [];
24
- for (let i of n) r.set(i, new Set(e(t[i]).keys()));
25
- let o = n[0], s = r.get(o);
26
- for (let e of n) {
27
- if (e === o) continue;
28
- let t = r.get(e);
29
- for (let n of s) t.has(n) || i.push({
30
- key: n,
31
- locale: e
32
- });
33
- for (let n of t) s.has(n) || a.push({
34
- key: n,
35
- locale: e
36
- });
37
- }
38
- return {
39
- extra: a,
40
- missing: i
41
- };
42
- }
43
- //#endregion
44
- export { i as compareCatalogs, r as validateCatalog };
45
-
1
+ import{compileCatalog as e,isPluralMessage as t}from"./_catalog.js";import{canonicalLocale as n}from"./_locale.js";function validateCatalog(r,i){e(r);let a=n(i),o=new Intl.PluralRules(a).resolvedOptions().pluralCategories,s=[],visit=(e,n)=>{if(typeof e!=`string`){if(t(e)){for(let t of o)Object.hasOwn(e.plural,t)||s.push({key:n,locale:a,missing:t});return}for(let[t,r]of Object.entries(e))visit(r,n?`${n}.${t}`:t)}};for(let[e,t]of Object.entries(r))visit(t,e);return s}function compareCatalogs(t){let n=Object.keys(t),r=new Map,i=[],a=[];for(let i of n)r.set(i,new Set(e(t[i]).keys()));let o=n[0],s=r.get(o);for(let e of n){if(e===o)continue;let t=r.get(e);for(let n of s)t.has(n)||i.push({key:n,locale:e});for(let n of t)s.has(n)||a.push({key:n,locale:e})}return{extra:a,missing:i}}export{compareCatalogs,validateCatalog};
46
2
  //# sourceMappingURL=validate.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"validate.js","names":[],"sources":["../src/validate.ts"],"sourcesContent":["import { compileCatalog, isPluralMessage } from './_catalog';\nimport { canonicalLocale } from './_locale';\nimport type { Catalog, CatalogNode, Catalogs, Locale } from './types';\n\nexport type ValidationIssue = {\n key: string;\n locale: Locale;\n missing: Intl.LDMLPluralRule;\n};\n\nexport type CatalogComparison = {\n readonly missing: ReadonlyArray<{ key: string; locale: Locale }>;\n readonly extra: ReadonlyArray<{ key: string; locale: Locale }>;\n};\n\n/** Explicit tooling API. Runtime never loads validation code or emits asynchronous catalog warnings. */\nexport function validateCatalog(catalog: Catalog, locale: Locale): ValidationIssue[] {\n compileCatalog(catalog);\n\n const canonical = canonicalLocale(locale);\n const categories = new Intl.PluralRules(canonical).resolvedOptions().pluralCategories;\n const issues: ValidationIssue[] = [];\n\n const visit = (node: CatalogNode, key: string): void => {\n if (typeof node === 'string') return;\n\n if (isPluralMessage(node)) {\n for (const missing of categories) {\n if (!Object.hasOwn(node.plural, missing)) issues.push({ key, locale: canonical, missing });\n }\n\n return;\n }\n\n for (const [childKey, child] of Object.entries(node)) visit(child, key ? `${key}.${childKey}` : childKey);\n };\n\n for (const [key, node] of Object.entries(catalog)) visit(node, key);\n\n return issues;\n}\n\n/** Compares catalog key sets across locales. Reports keys missing in each target locale and keys present in targets but absent from the base. */\nexport function compareCatalogs<C extends Catalog>(catalogs: Catalogs<C>): CatalogComparison {\n const locales = Object.keys(catalogs);\n const keySets = new Map<Locale, Set<string>>();\n const missing: Array<{ key: string; locale: Locale }> = [];\n const extra: Array<{ key: string; locale: Locale }> = [];\n\n for (const locale of locales) {\n keySets.set(locale, new Set(compileCatalog(catalogs[locale]).keys()));\n }\n\n const base = locales[0];\n const baseKeys = keySets.get(base)!;\n\n for (const locale of locales) {\n if (locale === base) continue;\n const targetKeys = keySets.get(locale)!;\n\n for (const key of baseKeys) {\n if (!targetKeys.has(key)) missing.push({ key, locale });\n }\n\n for (const key of targetKeys) {\n if (!baseKeys.has(key)) extra.push({ key, locale });\n }\n }\n\n return { extra, missing };\n}\n"],"mappings":";;;AAgBA,SAAgB,EAAgB,GAAkB,GAAmC;CACnF,EAAe,CAAO;CAEtB,IAAM,IAAY,EAAgB,CAAM,GAClC,IAAa,IAAI,KAAK,YAAY,CAAS,CAAC,CAAC,gBAAgB,CAAC,CAAC,kBAC/D,IAA4B,CAAC,GAE7B,KAAS,GAAmB,MAAsB;EAClD,WAAO,KAAS,UAEpB;OAAI,EAAgB,CAAI,GAAG;IACzB,KAAK,IAAM,KAAW,GACpB,AAAK,OAAO,OAAO,EAAK,QAAQ,CAAO,KAAG,EAAO,KAAK;KAAE;KAAK,QAAQ;KAAW;IAAQ,CAAC;IAG3F;GACF;GAEA,KAAK,IAAM,CAAC,GAAU,MAAU,OAAO,QAAQ,CAAI,GAAG,EAAM,GAAO,IAAM,GAAG,EAAI,GAAG,MAAa,CAAQ;EAFxG;CAGF;CAEA,KAAK,IAAM,CAAC,GAAK,MAAS,OAAO,QAAQ,CAAO,GAAG,EAAM,GAAM,CAAG;CAElE,OAAO;AACT;AAGA,SAAgB,EAAmC,GAA0C;CAC3F,IAAM,IAAU,OAAO,KAAK,CAAQ,GAC9B,oBAAU,IAAI,IAAyB,GACvC,IAAkD,CAAC,GACnD,IAAgD,CAAC;CAEvD,KAAK,IAAM,KAAU,GACnB,EAAQ,IAAI,GAAQ,IAAI,IAAI,EAAe,EAAS,EAAO,CAAC,CAAC,KAAK,CAAC,CAAC;CAGtE,IAAM,IAAO,EAAQ,IACf,IAAW,EAAQ,IAAI,CAAI;CAEjC,KAAK,IAAM,KAAU,GAAS;EAC5B,IAAI,MAAW,GAAM;EACrB,IAAM,IAAa,EAAQ,IAAI,CAAM;EAErC,KAAK,IAAM,KAAO,GAChB,AAAK,EAAW,IAAI,CAAG,KAAG,EAAQ,KAAK;GAAE;GAAK;EAAO,CAAC;EAGxD,KAAK,IAAM,KAAO,GAChB,AAAK,EAAS,IAAI,CAAG,KAAG,EAAM,KAAK;GAAE;GAAK;EAAO,CAAC;CAEtD;CAEA,OAAO;EAAE;EAAO;CAAQ;AAC1B"}
1
+ {"version":3,"file":"validate.js","names":[],"sources":["../src/validate.ts"],"sourcesContent":["import { compileCatalog, isPluralMessage } from './_catalog';\nimport { canonicalLocale } from './_locale';\nimport type { Catalog, CatalogNode, Catalogs, Locale } from './types';\n\nexport type ValidationIssue = {\n key: string;\n locale: Locale;\n missing: Intl.LDMLPluralRule;\n};\n\nexport type CatalogComparison = {\n readonly missing: ReadonlyArray<{ key: string; locale: Locale }>;\n readonly extra: ReadonlyArray<{ key: string; locale: Locale }>;\n};\n\n/** Explicit tooling API. Runtime never loads validation code or emits asynchronous catalog warnings. */\nexport function validateCatalog(catalog: Catalog, locale: Locale): ValidationIssue[] {\n compileCatalog(catalog);\n\n const canonical = canonicalLocale(locale);\n const categories = new Intl.PluralRules(canonical).resolvedOptions().pluralCategories;\n const issues: ValidationIssue[] = [];\n\n const visit = (node: CatalogNode, key: string): void => {\n if (typeof node === 'string') return;\n\n if (isPluralMessage(node)) {\n for (const missing of categories) {\n if (!Object.hasOwn(node.plural, missing)) issues.push({ key, locale: canonical, missing });\n }\n\n return;\n }\n\n for (const [childKey, child] of Object.entries(node)) visit(child, key ? `${key}.${childKey}` : childKey);\n };\n\n for (const [key, node] of Object.entries(catalog)) visit(node, key);\n\n return issues;\n}\n\n/** Compares catalog key sets across locales. Reports keys missing in each target locale and keys present in targets but absent from the base. */\nexport function compareCatalogs<C extends Catalog>(catalogs: Catalogs<C>): CatalogComparison {\n const locales = Object.keys(catalogs);\n const keySets = new Map<Locale, Set<string>>();\n const missing: Array<{ key: string; locale: Locale }> = [];\n const extra: Array<{ key: string; locale: Locale }> = [];\n\n for (const locale of locales) {\n keySets.set(locale, new Set(compileCatalog(catalogs[locale]).keys()));\n }\n\n const base = locales[0];\n const baseKeys = keySets.get(base)!;\n\n for (const locale of locales) {\n if (locale === base) continue;\n const targetKeys = keySets.get(locale)!;\n\n for (const key of baseKeys) {\n if (!targetKeys.has(key)) missing.push({ key, locale });\n }\n\n for (const key of targetKeys) {\n if (!baseKeys.has(key)) extra.push({ key, locale });\n }\n }\n\n return { extra, missing };\n}\n"],"mappings":"mHAgBA,SAAgB,gBAAgB,EAAkB,EAAmC,CACnF,EAAe,CAAO,EAEtB,IAAM,EAAY,EAAgB,CAAM,EAClC,EAAa,IAAI,KAAK,YAAY,CAAS,CAAC,CAAC,gBAAgB,CAAC,CAAC,iBAC/D,EAA4B,CAAC,EAE7B,OAAS,EAAmB,IAAsB,CAClD,UAAO,GAAS,SAEpB,IAAI,EAAgB,CAAI,EAAG,CACzB,IAAK,IAAM,KAAW,EACf,OAAO,OAAO,EAAK,OAAQ,CAAO,GAAG,EAAO,KAAK,CAAE,MAAK,OAAQ,EAAW,SAAQ,CAAC,EAG3F,MACF,CAEA,IAAK,GAAM,CAAC,EAAU,KAAU,OAAO,QAAQ,CAAI,EAAG,MAAM,EAAO,EAAM,GAAG,EAAI,GAAG,IAAa,CAAQ,CAFxG,CAGF,EAEA,IAAK,GAAM,CAAC,EAAK,KAAS,OAAO,QAAQ,CAAO,EAAG,MAAM,EAAM,CAAG,EAElE,OAAO,CACT,CAGA,SAAgB,gBAAmC,EAA0C,CAC3F,IAAM,EAAU,OAAO,KAAK,CAAQ,EAC9B,EAAU,IAAI,IACd,EAAkD,CAAC,EACnD,EAAgD,CAAC,EAEvD,IAAK,IAAM,KAAU,EACnB,EAAQ,IAAI,EAAQ,IAAI,IAAI,EAAe,EAAS,EAAO,CAAC,CAAC,KAAK,CAAC,CAAC,EAGtE,IAAM,EAAO,EAAQ,GACf,EAAW,EAAQ,IAAI,CAAI,EAEjC,IAAK,IAAM,KAAU,EAAS,CAC5B,GAAI,IAAW,EAAM,SACrB,IAAM,EAAa,EAAQ,IAAI,CAAM,EAErC,IAAK,IAAM,KAAO,EACX,EAAW,IAAI,CAAG,GAAG,EAAQ,KAAK,CAAE,MAAK,QAAO,CAAC,EAGxD,IAAK,IAAM,KAAO,EACX,EAAS,IAAI,CAAG,GAAG,EAAM,KAAK,CAAE,MAAK,QAAO,CAAC,CAEtD,CAEA,MAAO,CAAE,QAAO,SAAQ,CAC1B"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vielzeug/lingua",
3
- "version": "3.0.0",
4
- "description": "Explicit typed localization with pluralization, lazy locale loading, and SSR hydration",
3
+ "version": "26.10.0",
4
+ "description": "Typed i18n with pluralization and lazy locale loading",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/helmuthdu/vielzeug",
@@ -28,6 +28,11 @@
28
28
  "require": "./dist/format.cjs",
29
29
  "types": "./dist/format.d.ts"
30
30
  },
31
+ "./ripple": {
32
+ "import": "./dist/ripple.js",
33
+ "require": "./dist/ripple.cjs",
34
+ "types": "./dist/ripple.d.ts"
35
+ },
31
36
  "./validate": {
32
37
  "import": "./dist/validate.js",
33
38
  "require": "./dist/validate.cjs",
@@ -39,6 +44,9 @@
39
44
  "format": [
40
45
  "dist/format.d.ts"
41
46
  ],
47
+ "ripple": [
48
+ "dist/ripple.d.ts"
49
+ ],
42
50
  "validate": [
43
51
  "dist/validate.d.ts"
44
52
  ]
@@ -61,10 +69,19 @@
61
69
  "typecheck": "tsc -p tsconfig.json --noEmit",
62
70
  "verify:exports": "node ./scripts/verify-exports.mjs"
63
71
  },
72
+ "peerDependencies": {
73
+ "@vielzeug/ripple": "^26.10.0"
74
+ },
75
+ "peerDependenciesMeta": {
76
+ "@vielzeug/ripple": {
77
+ "optional": true
78
+ }
79
+ },
64
80
  "devDependencies": {
65
- "@types/node": "^26.4.1",
81
+ "@types/node": "^26.6.2",
82
+ "@vielzeug/ripple": "26.10.0",
66
83
  "typescript": "^6.0.3",
67
- "vite": "^8.2.2",
68
- "vitest": "^5.0.0"
84
+ "vite": "^8.3.0",
85
+ "vitest": "^5.0.1"
69
86
  }
70
87
  }