@vielzeug/lingua 2.4.1 → 3.0.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/README.md +9 -28
- package/dist/_resources.cjs +1 -1
- package/dist/_resources.cjs.map +1 -1
- package/dist/_resources.d.ts +9 -3
- package/dist/_resources.d.ts.map +1 -1
- package/dist/_resources.js +19 -22
- package/dist/_resources.js.map +1 -1
- package/dist/_template.cjs +1 -1
- package/dist/_template.cjs.map +1 -1
- package/dist/_template.d.ts +2 -1
- package/dist/_template.d.ts.map +1 -1
- package/dist/_template.js +12 -3
- package/dist/_template.js.map +1 -1
- package/dist/catalog.cjs +1 -1
- package/dist/catalog.cjs.map +1 -1
- package/dist/catalog.d.ts +8 -8
- package/dist/catalog.d.ts.map +1 -1
- package/dist/catalog.js +10 -5
- package/dist/catalog.js.map +1 -1
- package/dist/errors.cjs +1 -1
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.d.ts +4 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +3 -3
- package/dist/errors.js.map +1 -1
- package/dist/i18n.cjs +1 -1
- package/dist/i18n.cjs.map +1 -1
- package/dist/i18n.d.ts +6 -7
- package/dist/i18n.d.ts.map +1 -1
- package/dist/i18n.js +68 -55
- package/dist/i18n.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -5
- package/dist/lingua.cjs +1 -1
- package/dist/lingua.cjs.map +1 -1
- package/dist/lingua.iife.js +1 -1
- package/dist/lingua.iife.js.map +1 -1
- package/dist/lingua.js +1 -1
- package/dist/lingua.js.map +1 -1
- package/dist/translator.cjs +1 -1
- package/dist/translator.cjs.map +1 -1
- package/dist/translator.d.ts +15 -10
- package/dist/translator.d.ts.map +1 -1
- package/dist/translator.js +41 -32
- package/dist/translator.js.map +1 -1
- package/dist/types.d.ts +38 -14
- package/dist/types.d.ts.map +1 -1
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -1,56 +1,37 @@
|
|
|
1
1
|
# @vielzeug/lingua
|
|
2
2
|
|
|
3
|
-
>
|
|
4
|
-
|
|
5
|
-
`@vielzeug/lingua` provides immutable translators for fixed locales and a stateful i18n store for locale changes and optional lazy catalogs.
|
|
3
|
+
> Typed i18n with pluralization and lazy locale loading
|
|
6
4
|
|
|
7
5
|
## Installation
|
|
8
6
|
|
|
9
7
|
```sh
|
|
10
8
|
pnpm add @vielzeug/lingua
|
|
9
|
+
npm install @vielzeug/lingua
|
|
10
|
+
yarn add @vielzeug/lingua
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
## Quick Start
|
|
14
14
|
|
|
15
15
|
```ts
|
|
16
|
-
import {
|
|
16
|
+
import { createTranslator } from '@vielzeug/lingua';
|
|
17
17
|
|
|
18
|
-
const translator =
|
|
18
|
+
const translator = createTranslator({
|
|
19
19
|
greeting: 'Hello, {name}!',
|
|
20
20
|
inbox: { plural: { one: 'One message', other: '{count} messages' } },
|
|
21
|
-
});
|
|
21
|
+
}, { locale: 'en' });
|
|
22
22
|
|
|
23
23
|
translator.translate('greeting', { values: { name: 'Ada' } });
|
|
24
24
|
translator.translate('inbox', { count: 3 });
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
-
## Integration Patterns
|
|
28
|
-
|
|
29
|
-
Use `translate()` for string interpolation and `segments()` for UI values. Give UI values consumer-owned keys before passing them; Lingua returns same values without cloning or mutation.
|
|
30
|
-
|
|
31
|
-
```ts
|
|
32
|
-
const retry = { key: 'retry', href: '/retry' };
|
|
33
|
-
translator.segments('greeting', { values: { name: retry } });
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
Use `createTranslationStore()` only when locale changes at runtime. Its stable `subscribe` and `getSnapshot` methods work directly with platform subscription APIs such as React `useSyncExternalStore`; hydrate client store from server `serialize()` state before first render. Missing keys return key, and absent interpolation values return `{name}` by default.
|
|
37
|
-
|
|
38
|
-
Keep arrays and application metadata outside catalogs. Store message keys with application definitions, then translate labels while building UI options.
|
|
39
|
-
|
|
40
|
-
## Exports
|
|
41
|
-
|
|
42
|
-
- `createCatalogTranslator` — immutable translator for one fixed-locale catalog.
|
|
43
|
-
- `createTranslator` — immutable translator for fixed locale-keyed catalogs.
|
|
44
|
-
- `createTranslationStore` / `hydrateTranslationStore` — mutable locale state, lazy catalog loading, and SSR state.
|
|
45
|
-
- `createFormatter` from `@vielzeug/lingua/format`.
|
|
46
|
-
- `validateCatalog` from `@vielzeug/lingua/validate`.
|
|
47
|
-
|
|
48
27
|
## Documentation
|
|
49
28
|
|
|
50
29
|
- [Overview](https://vielzeug.dev/lingua/)
|
|
51
30
|
- [Usage Guide](https://vielzeug.dev/lingua/usage)
|
|
52
31
|
- [API Reference](https://vielzeug.dev/lingua/api)
|
|
32
|
+
- [Examples](https://vielzeug.dev/lingua/examples)
|
|
33
|
+
- [Migration Guide](https://vielzeug.dev/lingua/migration)
|
|
53
34
|
|
|
54
35
|
## License
|
|
55
36
|
|
|
56
|
-
MIT © Helmuth Saatkamp
|
|
37
|
+
MIT © [Helmuth Saatkamp](https://github.com/helmuthdu) — part of the [Vielzeug](https://github.com/helmuthdu/vielzeug) monorepo.
|
package/dist/_resources.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
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=
|
|
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=(e,r)=>{i.set(n.canonicalLocale(e),{catalog:r,compiled:t.compileCatalog(r)})};for(let[e,t]of Object.entries(r.catalogs??{}))o(e,t);return{catalogMap(){return new Map([...i].map(([e,{compiled:t}])=>[e,t]))},hydrate:o,isLoaded(e){return i.has(n.canonicalLocale(e))},load:async t=>{let s=n.canonicalLocale(t);if(i.has(s))return!1;let c=a.get(s);if(c)return await c,!1;if(!r.loadCatalog)throw new e.LinguaMissingCatalogError(`No catalog source provided for locale "${s}".`);let l=Promise.resolve(r.loadCatalog(s)).then(e=>{o(s,e),a.delete(s)},e=>{throw a.delete(s),e});return a.set(s,l),await l,!0},state(e){let t={};for(let[e,{catalog:n}]of i)t[e]=n;return{catalogs:t,locale:e,version:4}}}}exports.createCatalogStore=r;
|
|
2
2
|
//# sourceMappingURL=_resources.cjs.map
|
package/dist/_resources.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_resources.cjs","names":[],"sources":["../src/_resources.ts"],"sourcesContent":["import { type CompiledCatalog, compileCatalog } from './_catalog';\nimport { canonicalLocale } from './_locale';\nimport { LinguaMissingCatalogError } from './errors';\nimport type { Catalog,
|
|
1
|
+
{"version":3,"file":"_resources.cjs","names":[],"sources":["../src/_resources.ts"],"sourcesContent":["import { type CompiledCatalog, compileCatalog } from './_catalog';\nimport { canonicalLocale } from './_locale';\nimport { LinguaMissingCatalogError } from './errors';\nimport type { Catalog, Catalogs, Locale, TranslationState } from './types';\n\ntype CatalogStoreOptions<C extends Catalog> = {\n readonly catalogs?: Catalogs<C>;\n readonly loadCatalog?: (locale: Locale) => Promise<C> | C;\n};\n\n/** One catalog state machine owns loaded catalogs and in-flight loading work. */\nexport function createCatalogStore<C extends Catalog>(options: CatalogStoreOptions<C>) {\n const loaded = new Map<Locale, { readonly catalog: C; readonly compiled: CompiledCatalog }>();\n const tasks = new Map<Locale, Promise<void>>();\n\n const hydrate = (locale: Locale, catalog: C): void => {\n loaded.set(canonicalLocale(locale), { catalog, compiled: compileCatalog(catalog) });\n };\n\n for (const [locale, catalog] of Object.entries(options.catalogs ?? {})) hydrate(locale, catalog);\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 existing = tasks.get(locale);\n\n if (existing) {\n await existing;\n\n return false;\n }\n\n if (!options.loadCatalog) {\n throw new LinguaMissingCatalogError(`No catalog source provided for locale \"${locale}\".`);\n }\n\n const task = Promise.resolve(options.loadCatalog(locale)).then(\n (catalog) => {\n hydrate(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 hydrate,\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: 4 };\n },\n };\n}\n"],"mappings":"uFAWA,SAAgB,EAAsC,EAAiC,CACrF,IAAM,EAAS,IAAI,IACb,EAAQ,IAAI,IAEZ,GAAW,EAAgB,IAAqB,CACpD,EAAO,IAAI,EAAA,gBAAgB,CAAM,EAAG,CAAE,UAAS,SAAU,EAAA,eAAe,CAAO,CAAE,CAAC,CACpF,EAEA,IAAK,GAAM,CAAC,EAAQ,KAAY,OAAO,QAAQ,EAAQ,UAAY,CAAC,CAAC,EAAG,EAAQ,EAAQ,CAAO,EAoC/F,MAAO,CACL,YAAmD,CACjD,OAAO,IAAI,IAAI,CAAC,GAAG,CAAM,CAAC,CAAC,KAAK,CAAC,EAAQ,CAAE,eAAgB,CAAC,EAAQ,CAAQ,CAAC,CAAC,CAChF,EACA,UACA,SAAS,EAAyB,CAChC,OAAO,EAAO,IAAI,EAAA,gBAAgB,CAAM,CAAC,CAC3C,EACA,UA1CkB,IAA8C,CAChE,IAAM,EAAS,EAAA,gBAAgB,CAAe,EAE9C,GAAI,EAAO,IAAI,CAAM,EAAG,MAAO,GAE/B,IAAM,EAAW,EAAM,IAAI,CAAM,EAEjC,GAAI,EAGF,OAFA,MAAM,EAEC,GAGT,GAAI,CAAC,EAAQ,YACX,MAAM,IAAI,EAAA,0BAA0B,0CAA0C,EAAO,GAAG,EAG1F,IAAM,EAAO,QAAQ,QAAQ,EAAQ,YAAY,CAAM,CAAC,CAAC,CAAC,KACvD,GAAY,CACX,EAAQ,EAAQ,CAAO,EACvB,EAAM,OAAO,CAAM,CACrB,EACC,GAAmB,CAElB,MADA,EAAM,OAAO,CAAM,EACb,CACR,CACF,EAKA,OAHA,EAAM,IAAI,EAAQ,CAAI,EACtB,MAAM,EAEC,EACT,EAWE,MAAM,EAAqC,CACzC,IAAM,EAAwB,CAAC,EAE/B,IAAK,GAAM,CAAC,EAAc,CAAE,cAAc,EAAQ,EAAS,GAAgB,EAE3E,MAAO,CAAE,WAAU,SAAQ,QAAS,CAAE,CACxC,CACF,CACF"}
|
package/dist/_resources.d.ts
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import { type CompiledCatalog } from './_catalog';
|
|
2
|
-
import type { Catalog,
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
import type { Catalog, Catalogs, Locale, TranslationState } from './types';
|
|
3
|
+
type CatalogStoreOptions<C extends Catalog> = {
|
|
4
|
+
readonly catalogs?: Catalogs<C>;
|
|
5
|
+
readonly loadCatalog?: (locale: Locale) => Promise<C> | C;
|
|
6
|
+
};
|
|
7
|
+
/** One catalog state machine owns loaded catalogs and in-flight loading work. */
|
|
8
|
+
export declare function createCatalogStore<C extends Catalog>(options: CatalogStoreOptions<C>): {
|
|
5
9
|
catalogMap(): ReadonlyMap<Locale, CompiledCatalog>;
|
|
10
|
+
hydrate: (locale: Locale, catalog: C) => void;
|
|
6
11
|
isLoaded(locale: Locale): boolean;
|
|
7
12
|
load: (requestedLocale: Locale) => Promise<boolean>;
|
|
8
13
|
state(locale: Locale): TranslationState<C>;
|
|
9
14
|
};
|
|
15
|
+
export {};
|
|
10
16
|
//# sourceMappingURL=_resources.d.ts.map
|
package/dist/_resources.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_resources.d.ts","sourceRoot":"","sources":["../src/_resources.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,eAAe,EAAkB,MAAM,YAAY,CAAC;AAGlE,OAAO,KAAK,EAAE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"_resources.d.ts","sourceRoot":"","sources":["../src/_resources.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,eAAe,EAAkB,MAAM,YAAY,CAAC;AAGlE,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAE3E,KAAK,mBAAmB,CAAC,CAAC,SAAS,OAAO,IAAI;IAC5C,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;IAChC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;CAC3D,CAAC;AAEF,iFAAiF;AACjF,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,OAAO,EAAE,OAAO,EAAE,mBAAmB,CAAC,CAAC,CAAC;kBA6CnE,WAAW,CAAC,MAAM,EAAE,eAAe,CAAC;sBAzC3B,MAAM,WAAW,CAAC,KAAG,IAAI;qBA6C/B,MAAM,GAAG,OAAO;4BAvCE,MAAM,KAAG,OAAO,CAAC,OAAO,CAAC;kBA2C9C,MAAM,GAAG,gBAAgB,CAAC,CAAC,CAAC;EAQ7C"}
|
package/dist/_resources.js
CHANGED
|
@@ -3,44 +3,41 @@ import { compileCatalog as t } from "./_catalog.js";
|
|
|
3
3
|
import { canonicalLocale as n } from "./_locale.js";
|
|
4
4
|
//#region src/_resources.ts
|
|
5
5
|
function r(r) {
|
|
6
|
-
let i = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map(), o =
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
catalog: n,
|
|
11
|
-
compiled: t(n)
|
|
6
|
+
let i = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map(), o = (e, r) => {
|
|
7
|
+
i.set(n(e), {
|
|
8
|
+
catalog: r,
|
|
9
|
+
compiled: t(r)
|
|
12
10
|
});
|
|
13
11
|
};
|
|
14
|
-
for (let [e, t] of
|
|
12
|
+
for (let [e, t] of Object.entries(r.catalogs ?? {})) o(e, t);
|
|
15
13
|
return {
|
|
16
14
|
catalogMap() {
|
|
17
|
-
return new Map([...
|
|
15
|
+
return new Map([...i].map(([e, { compiled: t }]) => [e, t]));
|
|
18
16
|
},
|
|
17
|
+
hydrate: o,
|
|
19
18
|
isLoaded(e) {
|
|
20
|
-
return
|
|
19
|
+
return i.has(n(e));
|
|
21
20
|
},
|
|
22
21
|
load: async (t) => {
|
|
23
|
-
let
|
|
24
|
-
if (
|
|
25
|
-
let c =
|
|
26
|
-
if (
|
|
27
|
-
if (
|
|
28
|
-
let l =
|
|
29
|
-
|
|
30
|
-
let u = c().then((e) => {
|
|
31
|
-
s(r, e), o.delete(r);
|
|
22
|
+
let s = n(t);
|
|
23
|
+
if (i.has(s)) return !1;
|
|
24
|
+
let c = a.get(s);
|
|
25
|
+
if (c) return await c, !1;
|
|
26
|
+
if (!r.loadCatalog) throw new e(`No catalog source provided for locale "${s}".`);
|
|
27
|
+
let l = Promise.resolve(r.loadCatalog(s)).then((e) => {
|
|
28
|
+
o(s, e), a.delete(s);
|
|
32
29
|
}, (e) => {
|
|
33
|
-
throw
|
|
30
|
+
throw a.delete(s), e;
|
|
34
31
|
});
|
|
35
|
-
return
|
|
32
|
+
return a.set(s, l), await l, !0;
|
|
36
33
|
},
|
|
37
34
|
state(e) {
|
|
38
35
|
let t = {};
|
|
39
|
-
for (let [e, { catalog: n }] of
|
|
36
|
+
for (let [e, { catalog: n }] of i) t[e] = n;
|
|
40
37
|
return {
|
|
41
38
|
catalogs: t,
|
|
42
39
|
locale: e,
|
|
43
|
-
version:
|
|
40
|
+
version: 4
|
|
44
41
|
};
|
|
45
42
|
}
|
|
46
43
|
};
|
package/dist/_resources.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_resources.js","names":[],"sources":["../src/_resources.ts"],"sourcesContent":["import { type CompiledCatalog, compileCatalog } from './_catalog';\nimport { canonicalLocale } from './_locale';\nimport { LinguaMissingCatalogError } from './errors';\nimport type { Catalog,
|
|
1
|
+
{"version":3,"file":"_resources.js","names":[],"sources":["../src/_resources.ts"],"sourcesContent":["import { type CompiledCatalog, compileCatalog } from './_catalog';\nimport { canonicalLocale } from './_locale';\nimport { LinguaMissingCatalogError } from './errors';\nimport type { Catalog, Catalogs, Locale, TranslationState } from './types';\n\ntype CatalogStoreOptions<C extends Catalog> = {\n readonly catalogs?: Catalogs<C>;\n readonly loadCatalog?: (locale: Locale) => Promise<C> | C;\n};\n\n/** One catalog state machine owns loaded catalogs and in-flight loading work. */\nexport function createCatalogStore<C extends Catalog>(options: CatalogStoreOptions<C>) {\n const loaded = new Map<Locale, { readonly catalog: C; readonly compiled: CompiledCatalog }>();\n const tasks = new Map<Locale, Promise<void>>();\n\n const hydrate = (locale: Locale, catalog: C): void => {\n loaded.set(canonicalLocale(locale), { catalog, compiled: compileCatalog(catalog) });\n };\n\n for (const [locale, catalog] of Object.entries(options.catalogs ?? {})) hydrate(locale, catalog);\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 existing = tasks.get(locale);\n\n if (existing) {\n await existing;\n\n return false;\n }\n\n if (!options.loadCatalog) {\n throw new LinguaMissingCatalogError(`No catalog source provided for locale \"${locale}\".`);\n }\n\n const task = Promise.resolve(options.loadCatalog(locale)).then(\n (catalog) => {\n hydrate(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 hydrate,\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: 4 };\n },\n };\n}\n"],"mappings":";;;;AAWA,SAAgB,EAAsC,GAAiC;CACrF,IAAM,oBAAS,IAAI,IAAyE,GACtF,oBAAQ,IAAI,IAA2B,GAEvC,KAAW,GAAgB,MAAqB;EACpD,EAAO,IAAI,EAAgB,CAAM,GAAG;GAAE;GAAS,UAAU,EAAe,CAAO;EAAE,CAAC;CACpF;CAEA,KAAK,IAAM,CAAC,GAAQ,MAAY,OAAO,QAAQ,EAAQ,YAAY,CAAC,CAAC,GAAG,EAAQ,GAAQ,CAAO;CAoC/F,OAAO;EACL,aAAmD;GACjD,OAAO,IAAI,IAAI,CAAC,GAAG,CAAM,CAAC,CAAC,KAAK,CAAC,GAAQ,EAAE,mBAAgB,CAAC,GAAQ,CAAQ,CAAC,CAAC;EAChF;EACA;EACA,SAAS,GAAyB;GAChC,OAAO,EAAO,IAAI,EAAgB,CAAM,CAAC;EAC3C;EACA,aA1CkB,MAA8C;GAChE,IAAM,IAAS,EAAgB,CAAe;GAE9C,IAAI,EAAO,IAAI,CAAM,GAAG,OAAO;GAE/B,IAAM,IAAW,EAAM,IAAI,CAAM;GAEjC,IAAI,GAGF,OAFA,MAAM,GAEC;GAGT,IAAI,CAAC,EAAQ,aACX,MAAM,IAAI,EAA0B,0CAA0C,EAAO,GAAG;GAG1F,IAAM,IAAO,QAAQ,QAAQ,EAAQ,YAAY,CAAM,CAAC,CAAC,CAAC,MACvD,MAAY;IAEX,AADA,EAAQ,GAAQ,CAAO,GACvB,EAAM,OAAO,CAAM;GACrB,IACC,MAAmB;IAElB,MADA,EAAM,OAAO,CAAM,GACb;GACR,CACF;GAKA,OAHA,EAAM,IAAI,GAAQ,CAAI,GACtB,MAAM,GAEC;EACT;EAWE,MAAM,GAAqC;GACzC,IAAM,IAAwB,CAAC;GAE/B,KAAK,IAAM,CAAC,GAAc,EAAE,iBAAc,GAAQ,EAAS,KAAgB;GAE3E,OAAO;IAAE;IAAU;IAAQ,SAAS;GAAE;EACxC;CACF;AACF"}
|
package/dist/_template.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
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}
|
|
1
|
+
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({type:`text`,value:i});continue}Object.hasOwn(t,i.value)?r.push({type:`value`,value:t[i.value]}):r.push({type:`text`,value:n(i.value)})}return r}exports.compileTemplate=t,exports.renderParts=r,exports.renderText=n;
|
|
2
2
|
//# sourceMappingURL=_template.cjs.map
|
package/dist/_template.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_template.cjs","names":[],"sources":["../src/_template.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"_template.cjs","names":[],"sources":["../src/_template.ts"],"sourcesContent":["import type { Part } from './types';\n\nexport 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 renderParts<V>(\n parts: Template,\n values: Record<string, V | number>,\n missing: (name: string) => string,\n): Array<Part<V | number>> {\n const result: Array<Part<V | number>> = [];\n\n for (const part of parts) {\n if (typeof part === 'string') {\n if (part !== '') result.push({ type: 'text', value: part });\n\n continue;\n }\n\n if (Object.hasOwn(values, part.value)) {\n result.push({ type: 'value', value: values[part.value]! as V | number });\n } else {\n result.push({ type: 'text', value: missing(part.value) });\n }\n }\n\n return result;\n}\n"],"mappings":"AAKA,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,EACyB,CACzB,IAAM,EAAkC,CAAC,EAEzC,IAAK,IAAM,KAAQ,EAAO,CACxB,GAAI,OAAO,GAAS,SAAU,CACxB,IAAS,IAAI,EAAO,KAAK,CAAE,KAAM,OAAQ,MAAO,CAAK,CAAC,EAE1D,QACF,CAEI,OAAO,OAAO,EAAQ,EAAK,KAAK,EAClC,EAAO,KAAK,CAAE,KAAM,QAAS,MAAO,EAAO,EAAK,MAAsB,CAAC,EAEvE,EAAO,KAAK,CAAE,KAAM,OAAQ,MAAO,EAAQ,EAAK,KAAK,CAAE,CAAC,CAE5D,CAEA,OAAO,CACT"}
|
package/dist/_template.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import type { Part } from './types';
|
|
1
2
|
export type TemplatePart = string | {
|
|
2
3
|
readonly value: string;
|
|
3
4
|
};
|
|
4
5
|
export type Template = readonly TemplatePart[];
|
|
5
6
|
export declare function compileTemplate(value: string): Template;
|
|
6
7
|
export declare function renderText(parts: Template, values: Record<string, unknown>, missing: (name: string) => string): string;
|
|
7
|
-
export declare function
|
|
8
|
+
export declare function renderParts<V>(parts: Template, values: Record<string, V | number>, missing: (name: string) => string): Array<Part<V | number>>;
|
|
8
9
|
//# sourceMappingURL=_template.d.ts.map
|
package/dist/_template.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_template.d.ts","sourceRoot":"","sources":["../src/_template.ts"],"names":[],"mappings":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{
|
|
|
19
19
|
let r = [];
|
|
20
20
|
for (let i of e) {
|
|
21
21
|
if (typeof i == "string") {
|
|
22
|
-
i !== "" && r.push(
|
|
22
|
+
i !== "" && r.push({
|
|
23
|
+
type: "text",
|
|
24
|
+
value: i
|
|
25
|
+
});
|
|
23
26
|
continue;
|
|
24
27
|
}
|
|
25
|
-
|
|
28
|
+
Object.hasOwn(t, i.value) ? r.push({
|
|
29
|
+
type: "value",
|
|
30
|
+
value: t[i.value]
|
|
31
|
+
}) : r.push({
|
|
32
|
+
type: "text",
|
|
33
|
+
value: n(i.value)
|
|
34
|
+
});
|
|
26
35
|
}
|
|
27
36
|
return r;
|
|
28
37
|
}
|
|
29
38
|
//#endregion
|
|
30
|
-
export { t as compileTemplate, r as
|
|
39
|
+
export { t as compileTemplate, r as renderParts, n as renderText };
|
|
31
40
|
|
|
32
41
|
//# sourceMappingURL=_template.js.map
|
package/dist/_template.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_template.js","names":[],"sources":["../src/_template.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"_template.js","names":[],"sources":["../src/_template.ts"],"sourcesContent":["import type { Part } from './types';\n\nexport 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 renderParts<V>(\n parts: Template,\n values: Record<string, V | number>,\n missing: (name: string) => string,\n): Array<Part<V | number>> {\n const result: Array<Part<V | number>> = [];\n\n for (const part of parts) {\n if (typeof part === 'string') {\n if (part !== '') result.push({ type: 'text', value: part });\n\n continue;\n }\n\n if (Object.hasOwn(values, part.value)) {\n result.push({ type: 'value', value: values[part.value]! as V | number });\n } else {\n result.push({ type: 'text', value: missing(part.value) });\n }\n }\n\n return result;\n}\n"],"mappings":";AAKA,IAAM,IAAgB;AAEtB,SAAgB,EAAgB,GAAyB;CACvD,IAAM,IAAwB,CAAC,GAC3B,IAAS;CAEb,KAAK,IAAM,KAAS,EAAM,SAAS,CAAa,GAAG;EACjD,IAAM,IAAQ,EAAM,SAAS;EAK7B,AAHI,IAAQ,KAAQ,EAAM,KAAK,EAAM,MAAM,GAAQ,CAAK,CAAC,GAEzD,EAAM,KAAK,EAAE,OAAO,EAAM,GAAG,CAAC,GAC9B,IAAS,IAAQ,EAAM,EAAE,CAAC;CAC5B;CAIA,OAFI,IAAS,EAAM,UAAQ,EAAM,KAAK,EAAM,MAAM,CAAM,CAAC,GAElD;AACT;AAEA,SAAgB,EACd,GACA,GACA,GACQ;CACR,OAAO,EACJ,KAAK,MAAS;EACb,IAAI,OAAO,KAAS,UAAU,OAAO;EAErC,IAAM,IAAQ,OAAO,OAAO,GAAQ,EAAK,KAAK,IAAI,EAAO,EAAK,SAAS,KAAA;EAEvE,OAAO,KAAS,OAAO,EAAQ,EAAK,KAAK,IAAI,OAAO,CAAK;CAC3D,CAAC,CAAC,CACD,KAAK,EAAE;AACZ;AAEA,SAAgB,EACd,GACA,GACA,GACyB;CACzB,IAAM,IAAkC,CAAC;CAEzC,KAAK,IAAM,KAAQ,GAAO;EACxB,IAAI,OAAO,KAAS,UAAU;GAC5B,AAAI,MAAS,MAAI,EAAO,KAAK;IAAE,MAAM;IAAQ,OAAO;GAAK,CAAC;GAE1D;EACF;EAEA,AAAI,OAAO,OAAO,GAAQ,EAAK,KAAK,IAClC,EAAO,KAAK;GAAE,MAAM;GAAS,OAAO,EAAO,EAAK;EAAsB,CAAC,IAEvE,EAAO,KAAK;GAAE,MAAM;GAAQ,OAAO,EAAQ,EAAK,KAAK;EAAE,CAAC;CAE5D;CAEA,OAAO;AACT"}
|
package/dist/catalog.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("./_catalog.cjs");function
|
|
1
|
+
const e=require("./errors.cjs"),t=require("./_catalog.cjs");function n(n){if(typeof n==`object`&&n&&`serialize`in n&&`getSnapshot`in n){let r=n,i=r.serialize().catalogs[r.locale];if(!i)throw new e.LinguaMissingCatalogError(`No catalog loaded for locale "${r.locale}".`);return[...t.compileCatalog(i).keys()]}return[...t.compileCatalog(n).keys()]}exports.catalogKeys=n;
|
|
2
2
|
//# sourceMappingURL=catalog.cjs.map
|
package/dist/catalog.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"catalog.cjs","names":[],"sources":["../src/catalog.ts"],"sourcesContent":["import { compileCatalog } from './_catalog';\nimport type {
|
|
1
|
+
{"version":3,"file":"catalog.cjs","names":[],"sources":["../src/catalog.ts"],"sourcesContent":["import { compileCatalog } from './_catalog';\nimport { LinguaMissingCatalogError } from './errors';\nimport type { I18n } from './i18n';\nimport type { Catalog, MessageKey } 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 `MessageKey<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 an `I18n` instance 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 an i18n instance — uses current locale's catalog\n * const i18n = createI18n({ catalogs: { en: messages }, locale: 'en' });\n * const allKeys = catalogKeys(i18n);\n * ```\n */\nexport function catalogKeys<C extends Catalog>(i18n: I18n<C>): ReadonlyArray<MessageKey<C>>;\nexport function catalogKeys<C extends Catalog>(catalog: C): ReadonlyArray<MessageKey<C>>;\nexport function catalogKeys(source: unknown): ReadonlyArray<MessageKey<Catalog>> {\n if (typeof source === 'object' && source !== null && 'serialize' in source && 'getSnapshot' in source) {\n const i18n = source as I18n;\n const catalog = i18n.serialize().catalogs[i18n.locale];\n\n if (!catalog) throw new LinguaMissingCatalogError(`No catalog loaded for locale \"${i18n.locale}\".`);\n\n return [...compileCatalog(catalog).keys()] as unknown as ReadonlyArray<MessageKey<Catalog>>;\n }\n\n return [...compileCatalog(source as Catalog).keys()] as unknown as ReadonlyArray<MessageKey<Catalog>>;\n}\n"],"mappings":"4DA6BA,SAAgB,EAAY,EAAqD,CAC/E,GAAI,OAAO,GAAW,UAAY,GAAmB,cAAe,GAAU,gBAAiB,EAAQ,CACrG,IAAM,EAAO,EACP,EAAU,EAAK,UAAU,CAAC,CAAC,SAAS,EAAK,QAE/C,GAAI,CAAC,EAAS,MAAM,IAAI,EAAA,0BAA0B,iCAAiC,EAAK,OAAO,GAAG,EAElG,MAAO,CAAC,GAAG,EAAA,eAAe,CAAO,CAAC,CAAC,KAAK,CAAC,CAC3C,CAEA,MAAO,CAAC,GAAG,EAAA,eAAe,CAAiB,CAAC,CAAC,KAAK,CAAC,CACrD"}
|
package/dist/catalog.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { Catalog,
|
|
1
|
+
import type { I18n } from './i18n';
|
|
2
|
+
import type { Catalog, MessageKey } from './types';
|
|
3
3
|
/** Enumerate every message key in a catalog as a dotted path.
|
|
4
4
|
*
|
|
5
5
|
* Traverses nested grouping objects and explicit `{ plural: ... }` messages,
|
|
6
|
-
* producing the same dotted paths that `
|
|
6
|
+
* producing the same dotted paths that `MessageKey<C>` represents at the type
|
|
7
7
|
* level. Use this to derive key arrays from the catalog itself instead of
|
|
8
8
|
* maintaining a parallel list that can go stale.
|
|
9
9
|
*
|
|
10
|
-
* Pass
|
|
10
|
+
* Pass an `I18n` instance to enumerate keys from its current locale catalog
|
|
11
11
|
* without specifying a locale explicitly.
|
|
12
12
|
*
|
|
13
13
|
* @example
|
|
@@ -17,11 +17,11 @@ import type { Catalog, TextKey } from './types';
|
|
|
17
17
|
* };
|
|
18
18
|
* const keys = catalogKeys(messages); // ['nav.home', 'nav.settings']
|
|
19
19
|
*
|
|
20
|
-
* // From
|
|
21
|
-
* const i18n =
|
|
20
|
+
* // From an i18n instance — uses current locale's catalog
|
|
21
|
+
* const i18n = createI18n({ catalogs: { en: messages }, locale: 'en' });
|
|
22
22
|
* const allKeys = catalogKeys(i18n);
|
|
23
23
|
* ```
|
|
24
24
|
*/
|
|
25
|
-
export declare function catalogKeys<C extends Catalog>(
|
|
26
|
-
export declare function catalogKeys<C extends Catalog>(catalog: C): ReadonlyArray<
|
|
25
|
+
export declare function catalogKeys<C extends Catalog>(i18n: I18n<C>): ReadonlyArray<MessageKey<C>>;
|
|
26
|
+
export declare function catalogKeys<C extends Catalog>(catalog: C): ReadonlyArray<MessageKey<C>>;
|
|
27
27
|
//# sourceMappingURL=catalog.d.ts.map
|
package/dist/catalog.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"catalog.d.ts","sourceRoot":"","sources":["../src/catalog.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"catalog.d.ts","sourceRoot":"","sources":["../src/catalog.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAEnD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,GAAG,aAAa,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;AAC5F,wBAAgB,WAAW,CAAC,CAAC,SAAS,OAAO,EAAE,OAAO,EAAE,CAAC,GAAG,aAAa,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC"}
|
package/dist/catalog.js
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LinguaMissingCatalogError as e } from "./errors.js";
|
|
2
|
+
import { compileCatalog as t } from "./_catalog.js";
|
|
2
3
|
//#region src/catalog.ts
|
|
3
|
-
function
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
function n(n) {
|
|
5
|
+
if (typeof n == "object" && n && "serialize" in n && "getSnapshot" in n) {
|
|
6
|
+
let r = n, i = r.serialize().catalogs[r.locale];
|
|
7
|
+
if (!i) throw new e(`No catalog loaded for locale "${r.locale}".`);
|
|
8
|
+
return [...t(i).keys()];
|
|
9
|
+
}
|
|
10
|
+
return [...t(n).keys()];
|
|
6
11
|
}
|
|
7
12
|
//#endregion
|
|
8
|
-
export {
|
|
13
|
+
export { n as catalogKeys };
|
|
9
14
|
|
|
10
15
|
//# sourceMappingURL=catalog.js.map
|
package/dist/catalog.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"catalog.js","names":[],"sources":["../src/catalog.ts"],"sourcesContent":["import { compileCatalog } from './_catalog';\nimport type {
|
|
1
|
+
{"version":3,"file":"catalog.js","names":[],"sources":["../src/catalog.ts"],"sourcesContent":["import { compileCatalog } from './_catalog';\nimport { LinguaMissingCatalogError } from './errors';\nimport type { I18n } from './i18n';\nimport type { Catalog, MessageKey } 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 `MessageKey<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 an `I18n` instance 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 an i18n instance — uses current locale's catalog\n * const i18n = createI18n({ catalogs: { en: messages }, locale: 'en' });\n * const allKeys = catalogKeys(i18n);\n * ```\n */\nexport function catalogKeys<C extends Catalog>(i18n: I18n<C>): ReadonlyArray<MessageKey<C>>;\nexport function catalogKeys<C extends Catalog>(catalog: C): ReadonlyArray<MessageKey<C>>;\nexport function catalogKeys(source: unknown): ReadonlyArray<MessageKey<Catalog>> {\n if (typeof source === 'object' && source !== null && 'serialize' in source && 'getSnapshot' in source) {\n const i18n = source as I18n;\n const catalog = i18n.serialize().catalogs[i18n.locale];\n\n if (!catalog) throw new LinguaMissingCatalogError(`No catalog loaded for locale \"${i18n.locale}\".`);\n\n return [...compileCatalog(catalog).keys()] as unknown as ReadonlyArray<MessageKey<Catalog>>;\n }\n\n return [...compileCatalog(source as Catalog).keys()] as unknown as ReadonlyArray<MessageKey<Catalog>>;\n}\n"],"mappings":";;;AA6BA,SAAgB,EAAY,GAAqD;CAC/E,IAAI,OAAO,KAAW,YAAY,KAAmB,eAAe,KAAU,iBAAiB,GAAQ;EACrG,IAAM,IAAO,GACP,IAAU,EAAK,UAAU,CAAC,CAAC,SAAS,EAAK;EAE/C,IAAI,CAAC,GAAS,MAAM,IAAI,EAA0B,iCAAiC,EAAK,OAAO,GAAG;EAElG,OAAO,CAAC,GAAG,EAAe,CAAO,CAAC,CAAC,KAAK,CAAC;CAC3C;CAEA,OAAO,CAAC,GAAG,EAAe,CAAiB,CAAC,CAAC,KAAK,CAAC;AACrD"}
|
package/dist/errors.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var e=class extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}},t=class extends e{constructor(){super(`Operation called on a disposed
|
|
1
|
+
var e=class extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}},t=class extends e{constructor(){super(`Operation called on a disposed i18n instance.`)}},n=class extends e{},r=class extends e{},i=class extends e{},a=class extends e{},o=class extends e{},s=class extends e{},c=class extends e{};exports.LinguaDisposedError=t,exports.LinguaError=e,exports.LinguaInvalidCatalogError=n,exports.LinguaInvalidLocaleError=r,exports.LinguaInvalidPluralCountError=i,exports.LinguaInvalidStateError=a,exports.LinguaMissingCatalogError=o,exports.LinguaMissingKeyError=s,exports.LinguaMissingValueError=c;
|
|
2
2
|
//# sourceMappingURL=errors.cjs.map
|
package/dist/errors.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.cjs","names":[],"sources":["../src/errors.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\nexport class LinguaDisposedError extends LinguaError {\n constructor() {\n super('Operation called on a disposed
|
|
1
|
+
{"version":3,"file":"errors.cjs","names":[],"sources":["../src/errors.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\nexport class LinguaDisposedError extends LinguaError {\n constructor() {\n super('Operation called on a disposed i18n instance.');\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 {}\nexport class LinguaMissingKeyError extends LinguaError {}\nexport class LinguaMissingValueError extends LinguaError {}\n"],"mappings":"AAAA,IAAa,EAAb,cAAiC,KAAM,CACrC,YAAY,EAAiB,EAAqB,CAChD,MAAM,EAAS,CAAI,EACnB,KAAK,KAAO,WAAW,KACvB,OAAO,eAAe,KAAM,WAAW,SAAS,CAClD,CACF,EAEa,EAAb,cAAyC,CAAY,CACnD,aAAc,CACZ,MAAM,+CAA+C,CACvD,CACF,EAEa,EAAb,cAA+C,CAAY,CAAC,EAC/C,EAAb,cAA8C,CAAY,CAAC,EAC9C,EAAb,cAAmD,CAAY,CAAC,EACnD,EAAb,cAA6C,CAAY,CAAC,EAC7C,EAAb,cAA+C,CAAY,CAAC,EAC/C,EAAb,cAA2C,CAAY,CAAC,EAC3C,EAAb,cAA6C,CAAY,CAAC"}
|
package/dist/errors.d.ts
CHANGED
|
@@ -14,4 +14,8 @@ export declare class LinguaInvalidStateError extends LinguaError {
|
|
|
14
14
|
}
|
|
15
15
|
export declare class LinguaMissingCatalogError extends LinguaError {
|
|
16
16
|
}
|
|
17
|
+
export declare class LinguaMissingKeyError extends LinguaError {
|
|
18
|
+
}
|
|
19
|
+
export declare class LinguaMissingValueError extends LinguaError {
|
|
20
|
+
}
|
|
17
21
|
//# sourceMappingURL=errors.d.ts.map
|
package/dist/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,WAAY,SAAQ,KAAK;gBACxB,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,YAAY;CAKjD;AAED,qBAAa,mBAAoB,SAAQ,WAAW;;CAInD;AAED,qBAAa,yBAA0B,SAAQ,WAAW;CAAG;AAC7D,qBAAa,wBAAyB,SAAQ,WAAW;CAAG;AAC5D,qBAAa,6BAA8B,SAAQ,WAAW;CAAG;AACjE,qBAAa,uBAAwB,SAAQ,WAAW;CAAG;AAC3D,qBAAa,yBAA0B,SAAQ,WAAW;CAAG"}
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,WAAY,SAAQ,KAAK;gBACxB,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,YAAY;CAKjD;AAED,qBAAa,mBAAoB,SAAQ,WAAW;;CAInD;AAED,qBAAa,yBAA0B,SAAQ,WAAW;CAAG;AAC7D,qBAAa,wBAAyB,SAAQ,WAAW;CAAG;AAC5D,qBAAa,6BAA8B,SAAQ,WAAW;CAAG;AACjE,qBAAa,uBAAwB,SAAQ,WAAW;CAAG;AAC3D,qBAAa,yBAA0B,SAAQ,WAAW;CAAG;AAC7D,qBAAa,qBAAsB,SAAQ,WAAW;CAAG;AACzD,qBAAa,uBAAwB,SAAQ,WAAW;CAAG"}
|
package/dist/errors.js
CHANGED
|
@@ -5,10 +5,10 @@ var e = class extends Error {
|
|
|
5
5
|
}
|
|
6
6
|
}, t = class extends e {
|
|
7
7
|
constructor() {
|
|
8
|
-
super("Operation called on a disposed
|
|
8
|
+
super("Operation called on a disposed i18n instance.");
|
|
9
9
|
}
|
|
10
|
-
}, n = class extends e {}, r = class extends e {}, i = class extends e {}, a = class extends e {}, o = class extends e {};
|
|
10
|
+
}, n = class extends e {}, r = class extends e {}, i = class extends e {}, a = class extends e {}, o = class extends e {}, s = class extends e {}, c = class extends e {};
|
|
11
11
|
//#endregion
|
|
12
|
-
export { t as LinguaDisposedError, e as LinguaError, n as LinguaInvalidCatalogError, r as LinguaInvalidLocaleError, i as LinguaInvalidPluralCountError, a as LinguaInvalidStateError, o as LinguaMissingCatalogError };
|
|
12
|
+
export { t as LinguaDisposedError, e as LinguaError, n as LinguaInvalidCatalogError, r as LinguaInvalidLocaleError, i as LinguaInvalidPluralCountError, a as LinguaInvalidStateError, o as LinguaMissingCatalogError, s as LinguaMissingKeyError, c as LinguaMissingValueError };
|
|
13
13
|
|
|
14
14
|
//# sourceMappingURL=errors.js.map
|
package/dist/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","names":[],"sources":["../src/errors.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\nexport class LinguaDisposedError extends LinguaError {\n constructor() {\n super('Operation called on a disposed
|
|
1
|
+
{"version":3,"file":"errors.js","names":[],"sources":["../src/errors.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\nexport class LinguaDisposedError extends LinguaError {\n constructor() {\n super('Operation called on a disposed i18n instance.');\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 {}\nexport class LinguaMissingKeyError extends LinguaError {}\nexport class LinguaMissingValueError extends LinguaError {}\n"],"mappings":";AAAA,IAAa,IAAb,cAAiC,MAAM;CACrC,YAAY,GAAiB,GAAqB;EAGhD,AAFA,MAAM,GAAS,CAAI,GACnB,KAAK,OAAO,WAAW,MACvB,OAAO,eAAe,MAAM,WAAW,SAAS;CAClD;AACF,GAEa,IAAb,cAAyC,EAAY;CACnD,cAAc;EACZ,MAAM,+CAA+C;CACvD;AACF,GAEa,IAAb,cAA+C,EAAY,CAAC,GAC/C,IAAb,cAA8C,EAAY,CAAC,GAC9C,IAAb,cAAmD,EAAY,CAAC,GACnD,IAAb,cAA6C,EAAY,CAAC,GAC7C,IAAb,cAA+C,EAAY,CAAC,GAC/C,IAAb,cAA2C,EAAY,CAAC,GAC3C,IAAb,cAA6C,EAAY,CAAC"}
|
package/dist/i18n.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
require("./_dev.cjs");const e=require("./errors.cjs"),t=require("./_locale.cjs"),n=require("./_resources.cjs"),r=require("./translator.cjs");function i(i){
|
|
1
|
+
require("./_dev.cjs");const e=require("./errors.cjs"),t=require("./_locale.cjs"),n=require("./_resources.cjs"),r=require("./translator.cjs");function i(i){if(i.state&&i.state.version!==4)throw new e.LinguaInvalidStateError(`Unsupported lingua state version: ${String(i.state.version)}.`);let a=i.fallback,o=(Array.isArray(a)?a:a?[a]:[]).map(t.canonicalLocale),s=new AbortController,c=new Set,l=!1,u=t.canonicalLocale(i.locale??i.state?.locale??`en`),d=0,f=0,p=n.createCatalogStore({catalogs:i.catalogs,loadCatalog:i.loadCatalog});if(i.state)for(let[e,t]of Object.entries(i.state.catalogs))p.hydrate(e,t);let m=async e=>{let t=[];for(let n of new Set([e,...o]))await p.load(n)&&t.push(n);return t},h=()=>{let n=t.localeChain(u,o).some(p.isLoaded)?i.missing:()=>{throw new e.LinguaMissingCatalogError(`No catalog loaded for locale "${u}". Call load() before translating.`)};return{locale:u,revision:d,translator:r.createTranslatorFromCompiled(p.catalogMap(),{fallback:a,locale:u,missing:n})}},g=h(),_=()=>{if(l)throw new e.LinguaDisposedError},v=()=>{l||(l=!0,c.clear(),s.abort())},y=e=>{try{e(g)}catch{}},b=()=>{d++,g=h();for(let e of[...c])y(e)},x=e=>t.localeChain(u,o).includes(e);return{get disposalSignal(){return s.signal},dispose:v,get disposed(){return l},getSnapshot(){return g},isLoaded(e){return!l&&p.isLoaded(e?.locale??u)},async load(e){_();let n=t.canonicalLocale(e?.locale??u),r=await m(n);_(),r.some(x)&&b()},get locale(){return u},parts(e,t){return g.translator.partsDynamic(e,t)},partsDynamic(e,t){return g.translator.partsDynamic(e,t)},serialize(){return _(),p.state(u)},async setLocale(e){_();let n=t.canonicalLocale(e),r=++f,i=await m(n);if(_(),r===f){if(n===u){i.some(x)&&b();return}u=n,b()}},subscribe(e,t){if(_(),t?.signal?.aborted)return()=>{};let n=()=>{c.delete(e),t?.signal?.removeEventListener(`abort`,n)};return t?.signal?.addEventListener(`abort`,n,{once:!0}),c.add(e),t?.immediate&&y(e),n},[Symbol.dispose]:v,translate(e,t={}){return g.translator.translateDynamic(e,t)},translateDynamic(e,t){return g.translator.translateDynamic(e,t)}}}exports.createI18n=i;
|
|
2
2
|
//# sourceMappingURL=i18n.cjs.map
|
package/dist/i18n.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"i18n.cjs","names":[],"sources":["../src/i18n.ts"],"sourcesContent":["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
|
|
1
|
+
{"version":3,"file":"i18n.cjs","names":[],"sources":["../src/i18n.ts"],"sourcesContent":["import { error as logError } from './_dev';\nimport { canonicalLocale, localeChain } from './_locale';\nimport { createCatalogStore } from './_resources';\nimport { LinguaDisposedError, LinguaInvalidStateError, LinguaMissingCatalogError } from './errors';\nimport { createTranslatorFromCompiled, type Translator } from './translator';\nimport type { Catalog, I18nOptions, Locale, SubscribeOptions, TranslationState } from './types';\n\nexport type I18nSnapshot<C extends Catalog = Catalog> = {\n readonly locale: Locale;\n readonly revision: number;\n readonly translator: Translator<C>;\n};\n\nexport type I18n<C extends Catalog = Catalog> = Translator<C> & {\n [Symbol.dispose](): void;\n readonly disposalSignal: AbortSignal;\n dispose(): void;\n readonly disposed: boolean;\n getSnapshot(): I18nSnapshot<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: I18nSnapshot<C>) => void, options?: SubscribeOptions): () => void;\n};\n\nexport function createI18n<C extends Catalog>(options: I18nOptions<C>): I18n<C> {\n if (options.state && options.state.version !== 4) {\n throw new LinguaInvalidStateError(`Unsupported lingua state version: ${String(options.state.version)}.`);\n }\n\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: I18nSnapshot<C>) => void>();\n let disposed = false;\n let locale = canonicalLocale(options.locale ?? options.state?.locale ?? 'en');\n let revision = 0;\n let transition = 0;\n\n const catalogs = createCatalogStore<C>({ catalogs: options.catalogs, loadCatalog: options.loadCatalog });\n\n // Hydrate from serialized state (SSR).\n if (options.state) {\n for (const [stateLocale, catalog] of Object.entries(options.state.catalogs)) {\n catalogs.hydrate(stateLocale, catalog);\n }\n }\n\n const loadTargets = async (target: Locale): Promise<readonly Locale[]> => {\n const changed: Locale[] = [];\n\n for (const candidate of new Set([target, ...fallbackLocales])) {\n if (await catalogs.load(candidate)) changed.push(candidate);\n }\n\n return changed;\n };\n\n const buildSnapshot = (): I18nSnapshot<C> => {\n const ready = localeChain(locale, fallbackLocales).some(catalogs.isLoaded);\n const missing = ready\n ? options.missing\n : () => {\n throw new LinguaMissingCatalogError(\n `No catalog loaded for locale \"${locale}\". Call load() before translating.`,\n );\n };\n\n return {\n locale,\n revision,\n translator: createTranslatorFromCompiled<C>(catalogs.catalogMap(), { fallback, locale, missing }),\n };\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: I18nSnapshot<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 loadTargets(targetLocale);\n\n assertLive();\n if (changed.some(relevant)) notify();\n },\n get locale() {\n return locale;\n },\n parts(key: string, translateOptions) {\n return snapshot.translator.partsDynamic(key, translateOptions);\n },\n partsDynamic(key, translateOptions) {\n return snapshot.translator.partsDynamic(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 const request = ++transition;\n const changed = await loadTargets(next);\n\n assertLive();\n if (request !== transition) return;\n\n if (next === locale) {\n if (changed.some(relevant)) notify();\n\n return;\n }\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 I18n<C>;\n}\n"],"mappings":"6IA0BA,SAAgB,EAA8B,EAAkC,CAC9E,GAAI,EAAQ,OAAS,EAAQ,MAAM,UAAY,EAC7C,MAAM,IAAI,EAAA,wBAAwB,qCAAqC,OAAO,EAAQ,MAAM,OAAO,EAAE,EAAE,EAGzG,IAAM,EAAW,EAAQ,SACnB,GAAmB,MAAM,QAAQ,CAAQ,EAAI,EAAW,EAAW,CAAC,CAAQ,EAAI,CAAC,EAAA,CAAG,IAAI,EAAA,eAAe,EACvG,EAAa,IAAI,gBACjB,EAAc,IAAI,IACpB,EAAW,GACX,EAAS,EAAA,gBAAgB,EAAQ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S,WAAW,iBAAiB,EAAK,CAAgB,CACnE,CACF,CACF"}
|
package/dist/i18n.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { type Translator } from './translator';
|
|
2
|
-
import type { Catalog, Locale, SubscribeOptions, TranslationState
|
|
3
|
-
export type
|
|
2
|
+
import type { Catalog, I18nOptions, Locale, SubscribeOptions, TranslationState } from './types';
|
|
3
|
+
export type I18nSnapshot<C extends Catalog = Catalog> = {
|
|
4
4
|
readonly locale: Locale;
|
|
5
5
|
readonly revision: number;
|
|
6
6
|
readonly translator: Translator<C>;
|
|
7
7
|
};
|
|
8
|
-
export type
|
|
8
|
+
export type I18n<C extends Catalog = Catalog> = Translator<C> & {
|
|
9
9
|
[Symbol.dispose](): void;
|
|
10
10
|
readonly disposalSignal: AbortSignal;
|
|
11
11
|
dispose(): void;
|
|
12
12
|
readonly disposed: boolean;
|
|
13
|
-
getSnapshot():
|
|
13
|
+
getSnapshot(): I18nSnapshot<C>;
|
|
14
14
|
isLoaded(options?: {
|
|
15
15
|
locale?: Locale;
|
|
16
16
|
}): boolean;
|
|
@@ -19,8 +19,7 @@ export type TranslationStore<C extends Catalog = Catalog> = Translator<C> & {
|
|
|
19
19
|
}): Promise<void>;
|
|
20
20
|
serialize(): TranslationState<C>;
|
|
21
21
|
setLocale(locale: Locale): Promise<void>;
|
|
22
|
-
subscribe(listener: (snapshot:
|
|
22
|
+
subscribe(listener: (snapshot: I18nSnapshot<C>) => void, options?: SubscribeOptions): () => void;
|
|
23
23
|
};
|
|
24
|
-
export declare function
|
|
25
|
-
export declare function hydrateTranslationStore<C extends Catalog>(state: TranslationState<C>, options?: Omit<TranslationStoreOptions<C>, 'locale' | 'catalogs'>): TranslationStore<C>;
|
|
24
|
+
export declare function createI18n<C extends Catalog>(options: I18nOptions<C>): I18n<C>;
|
|
26
25
|
//# sourceMappingURL=i18n.d.ts.map
|
package/dist/i18n.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
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