@intlayer/core 7.5.0 → 7.5.2-canary.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/utils/intl.cjs +23 -19
- package/dist/cjs/utils/intl.cjs.map +1 -1
- package/dist/esm/utils/intl.mjs +26 -19
- package/dist/esm/utils/intl.mjs.map +1 -1
- package/dist/types/deepTransformPlugins/getFilterTranslationsOnlyContent.d.ts +8 -8
- package/dist/types/deepTransformPlugins/getFilterTranslationsOnlyContent.d.ts.map +1 -1
- package/dist/types/deepTransformPlugins/getFilteredLocalesContent.d.ts +8 -8
- package/dist/types/deepTransformPlugins/getFilteredLocalesContent.d.ts.map +1 -1
- package/dist/types/utils/intl.d.ts.map +1 -1
- package/package.json +6 -6
package/dist/cjs/utils/intl.cjs
CHANGED
|
@@ -7,25 +7,29 @@ const createCachedConstructor = (Ctor) => {
|
|
|
7
7
|
const cache = /* @__PURE__ */ new Map();
|
|
8
8
|
function Wrapped(locales, options) {
|
|
9
9
|
if (Ctor.name === "DisplayNames" && typeof Intl?.DisplayNames !== "function") {
|
|
10
|
-
if (process.env.NODE_ENV === "development")
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
10
|
+
if (process.env.NODE_ENV === "development") {
|
|
11
|
+
const message = [
|
|
12
|
+
`// Intl.DisplayNames is not supported; falling back to raw locale (${locales}). `,
|
|
13
|
+
`// Consider adding a polyfill as https://formatjs.io/docs/polyfills/intl-displaynames/`,
|
|
14
|
+
``,
|
|
15
|
+
`import 'intl';`,
|
|
16
|
+
`import '@formatjs/intl-displaynames/polyfill';`,
|
|
17
|
+
`import '@formatjs/intl-getcanonicallocales/polyfill';`,
|
|
18
|
+
`import '@formatjs/intl-locale/polyfill';`,
|
|
19
|
+
`import '@formatjs/intl-pluralrules/polyfill';`,
|
|
20
|
+
`import '@formatjs/intl-listformat/polyfill';`,
|
|
21
|
+
`import '@formatjs/intl-numberformat/polyfill';`,
|
|
22
|
+
`import '@formatjs/intl-relativetimeformat/polyfill';`,
|
|
23
|
+
`import '@formatjs/intl-datetimeformat/polyfill';`,
|
|
24
|
+
``,
|
|
25
|
+
`// Optionally add locale data`,
|
|
26
|
+
`import '@formatjs/intl-pluralrules/locale-data/fr';`,
|
|
27
|
+
`import '@formatjs/intl-numberformat/locale-data/fr';`,
|
|
28
|
+
`import '@formatjs/intl-datetimeformat/locale-data/fr';`
|
|
29
|
+
].join("\n");
|
|
30
|
+
console.warn(message);
|
|
31
|
+
throw new Error(message);
|
|
32
|
+
}
|
|
29
33
|
return locales;
|
|
30
34
|
}
|
|
31
35
|
const key = cacheKey(locales ?? _intlayer_types.Locales.ENGLISH, options);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intl.cjs","names":["Locales","instance: InstanceType<T> | undefined"],"sources":["../../../src/utils/intl.ts"],"sourcesContent":["// Cached Intl helper – drop‑in replacement for the global `Intl` object.\n// ‑‑‑\n// • Uses a `Proxy` to lazily wrap every *constructor* hanging off `Intl` (NumberFormat, DateTimeFormat, …).\n// • Each wrapped constructor keeps an in‑memory cache keyed by `[locales, options]` so that identical requests\n// reuse the same heavy instance instead of reparsing CLDR data every time.\n// • A polyfill warning for `Intl.DisplayNames` is emitted only once and only in dev.\n// • The public API is fully type‑safe and mirrors the native `Intl` surface exactly –\n// you can treat `CachedIntl` just like the built‑in `Intl`.\n//\n// Usage examples:\n// ---------------\n// import { CachedIntl } from \"./cached-intl\";\n//\n// const nf = CachedIntl.NumberFormat(\"en-US\", { style: \"currency\", currency: \"USD\" });\n// console.log(nf.format(1234));\n//\n// const dn = CachedIntl.DisplayNames([\"fr\"], { type: \"language\" });\n// console.log(dn.of(\"en\")); // → \"anglais\"\n//\n// You can also spin up an isolated instance with its own caches (handy in test suites):\n// const TestIntl = createCachedIntl();\n//\n// ---------------------------------------------------------------------\n\nimport { Locales, type LocalesValues } from '@intlayer/types';\n\n// Helper type that picks just the constructor members off `typeof Intl`.\n// The \"capital‑letter\" heuristic is 100 % accurate today and keeps the\n// mapping short‑lived, so we don't have to manually list every constructor.\ntype IntlConstructors = {\n [K in keyof typeof Intl as (typeof Intl)[K] extends new (\n ...args: any\n ) => any\n ? K\n : never]: (typeof Intl)[K];\n};\n\n// Type wrapper to replace locale arguments with LocalesValues\ntype ReplaceLocaleWithLocalesValues<T> = T extends new (\n locales: any,\n options?: infer Options\n) => infer Instance\n ? new (\n locales?: LocalesValues,\n options?: Options\n ) => Instance\n : T extends new (\n locales: any\n ) => infer Instance\n ? new (\n locales?: LocalesValues\n ) => Instance\n : T;\n\n// Wrapped Intl type with LocalesValues\ntype WrappedIntl = {\n [K in keyof typeof Intl]: K extends keyof IntlConstructors\n ? ReplaceLocaleWithLocalesValues<(typeof Intl)[K]>\n : (typeof Intl)[K];\n};\n\n// Generic cache key – JSON.stringify is fine because locale strings are short\n// and option objects are small and deterministic.\nconst cacheKey = (locales: LocalesValues, options: unknown) =>\n JSON.stringify([locales, options]);\n\n// Generic wrapper for any `new Intl.*()` constructor.\n// Returns a constructable function (usable with or without `new`) that\n// pulls instances from a Map cache when possible.\nconst createCachedConstructor = <T extends new (...args: any[]) => any>(\n Ctor: T\n) => {\n const cache = new Map<string, InstanceType<T>>();\n\n function Wrapped(locales?: LocalesValues, options?: any) {\n // Special case – guard older runtimes missing DisplayNames.\n if (\n Ctor.name === 'DisplayNames' &&\n typeof (Intl as any)?.DisplayNames !== 'function'\n ) {\n if (process.env.NODE_ENV === 'development') {\n
|
|
1
|
+
{"version":3,"file":"intl.cjs","names":["Locales","instance: InstanceType<T> | undefined"],"sources":["../../../src/utils/intl.ts"],"sourcesContent":["// Cached Intl helper – drop‑in replacement for the global `Intl` object.\n// ‑‑‑\n// • Uses a `Proxy` to lazily wrap every *constructor* hanging off `Intl` (NumberFormat, DateTimeFormat, …).\n// • Each wrapped constructor keeps an in‑memory cache keyed by `[locales, options]` so that identical requests\n// reuse the same heavy instance instead of reparsing CLDR data every time.\n// • A polyfill warning for `Intl.DisplayNames` is emitted only once and only in dev.\n// • The public API is fully type‑safe and mirrors the native `Intl` surface exactly –\n// you can treat `CachedIntl` just like the built‑in `Intl`.\n//\n// Usage examples:\n// ---------------\n// import { CachedIntl } from \"./cached-intl\";\n//\n// const nf = CachedIntl.NumberFormat(\"en-US\", { style: \"currency\", currency: \"USD\" });\n// console.log(nf.format(1234));\n//\n// const dn = CachedIntl.DisplayNames([\"fr\"], { type: \"language\" });\n// console.log(dn.of(\"en\")); // → \"anglais\"\n//\n// You can also spin up an isolated instance with its own caches (handy in test suites):\n// const TestIntl = createCachedIntl();\n//\n// ---------------------------------------------------------------------\n\nimport { Locales, type LocalesValues } from '@intlayer/types';\n\n// Helper type that picks just the constructor members off `typeof Intl`.\n// The \"capital‑letter\" heuristic is 100 % accurate today and keeps the\n// mapping short‑lived, so we don't have to manually list every constructor.\ntype IntlConstructors = {\n [K in keyof typeof Intl as (typeof Intl)[K] extends new (\n ...args: any\n ) => any\n ? K\n : never]: (typeof Intl)[K];\n};\n\n// Type wrapper to replace locale arguments with LocalesValues\ntype ReplaceLocaleWithLocalesValues<T> = T extends new (\n locales: any,\n options?: infer Options\n) => infer Instance\n ? new (\n locales?: LocalesValues,\n options?: Options\n ) => Instance\n : T extends new (\n locales: any\n ) => infer Instance\n ? new (\n locales?: LocalesValues\n ) => Instance\n : T;\n\n// Wrapped Intl type with LocalesValues\ntype WrappedIntl = {\n [K in keyof typeof Intl]: K extends keyof IntlConstructors\n ? ReplaceLocaleWithLocalesValues<(typeof Intl)[K]>\n : (typeof Intl)[K];\n};\n\n// Generic cache key – JSON.stringify is fine because locale strings are short\n// and option objects are small and deterministic.\nconst cacheKey = (locales: LocalesValues, options: unknown) =>\n JSON.stringify([locales, options]);\n\n// Generic wrapper for any `new Intl.*()` constructor.\n// Returns a constructable function (usable with or without `new`) that\n// pulls instances from a Map cache when possible.\nconst createCachedConstructor = <T extends new (...args: any[]) => any>(\n Ctor: T\n) => {\n const cache = new Map<string, InstanceType<T>>();\n\n function Wrapped(locales?: LocalesValues, options?: any) {\n // Special case – guard older runtimes missing DisplayNames.\n if (\n Ctor.name === 'DisplayNames' &&\n typeof (Intl as any)?.DisplayNames !== 'function'\n ) {\n if (process.env.NODE_ENV === 'development') {\n const message = [\n `// Intl.DisplayNames is not supported; falling back to raw locale (${locales}). `,\n `// Consider adding a polyfill as https://formatjs.io/docs/polyfills/intl-displaynames/`,\n ``,\n `import 'intl';`,\n `import '@formatjs/intl-displaynames/polyfill';`,\n `import '@formatjs/intl-getcanonicallocales/polyfill';`,\n `import '@formatjs/intl-locale/polyfill';`,\n `import '@formatjs/intl-pluralrules/polyfill';`,\n `import '@formatjs/intl-listformat/polyfill';`,\n `import '@formatjs/intl-numberformat/polyfill';`,\n `import '@formatjs/intl-relativetimeformat/polyfill';`,\n `import '@formatjs/intl-datetimeformat/polyfill';`,\n ``,\n `// Optionally add locale data`,\n `import '@formatjs/intl-pluralrules/locale-data/fr';`,\n `import '@formatjs/intl-numberformat/locale-data/fr';`,\n `import '@formatjs/intl-datetimeformat/locale-data/fr';`,\n ].join('\\n');\n\n console.warn(message);\n throw new Error(message);\n }\n return locales as any;\n }\n\n const key = cacheKey(locales ?? Locales.ENGLISH, options);\n let instance: InstanceType<T> | undefined = cache.get(key);\n\n if (!instance) {\n instance = new Ctor(locales as never, options as never);\n cache.set(key, instance as InstanceType<T>);\n }\n\n return instance as InstanceType<T>;\n }\n\n // Ensure it behaves like a constructor when used with `new`.\n (Wrapped as any).prototype = (Ctor as any).prototype;\n\n return Wrapped as unknown as ReplaceLocaleWithLocalesValues<T>;\n};\n\n// Factory that turns the global `Intl` into a cached clone.\nexport const createCachedIntl = (): WrappedIntl =>\n new Proxy(Intl as IntlConstructors, {\n get: (target, prop, receiver) => {\n const value = Reflect.get(target, prop, receiver);\n\n // Wrap *only* constructor functions (safest heuristic: they start with a capital letter).\n return typeof value === 'function' && /^[A-Z]/.test(String(prop))\n ? createCachedConstructor(value)\n : value;\n },\n }) as unknown as WrappedIntl;\n\n// Singleton – import this in application code if you just want shared caches.\nexport const CachedIntl = createCachedIntl();\n\n// new CachedIntl.DisplayNames(Locales.FRENCH, { type: 'language' });\n// new CachedIntl.DisplayNames('fr', { type: 'language' });\n// new CachedIntl.DateTimeFormat('fr', {\n// year: 'numeric',\n// month: 'long',\n// day: 'numeric',\n// });\n// new CachedIntl.NumberFormat('fr', {\n// style: 'currency',\n// currency: 'EUR',\n// });\n// new CachedIntl.Collator('fr', { sensitivity: 'base' });\n// new CachedIntl.PluralRules('fr');\n// new CachedIntl.RelativeTimeFormat('fr', { numeric: 'auto' });\n// new CachedIntl.ListFormat('fr', { type: 'conjunction' });\n\nexport { CachedIntl as Intl };\n"],"mappings":";;;;AA+DA,MAAM,YAAY,SAAwB,YACxC,KAAK,UAAU,CAAC,SAAS,QAAQ,CAAC;AAKpC,MAAM,2BACJ,SACG;CACH,MAAM,wBAAQ,IAAI,KAA8B;CAEhD,SAAS,QAAQ,SAAyB,SAAe;AAEvD,MACE,KAAK,SAAS,kBACd,OAAQ,MAAc,iBAAiB,YACvC;AACA,OAAI,QAAQ,IAAI,aAAa,eAAe;IAC1C,MAAM,UAAU;KACd,sEAAsE,QAAQ;KAC9E;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACD,CAAC,KAAK,KAAK;AAEZ,YAAQ,KAAK,QAAQ;AACrB,UAAM,IAAI,MAAM,QAAQ;;AAE1B,UAAO;;EAGT,MAAM,MAAM,SAAS,WAAWA,wBAAQ,SAAS,QAAQ;EACzD,IAAIC,WAAwC,MAAM,IAAI,IAAI;AAE1D,MAAI,CAAC,UAAU;AACb,cAAW,IAAI,KAAK,SAAkB,QAAiB;AACvD,SAAM,IAAI,KAAK,SAA4B;;AAG7C,SAAO;;AAIT,CAAC,QAAgB,YAAa,KAAa;AAE3C,QAAO;;AAIT,MAAa,yBACX,IAAI,MAAM,MAA0B,EAClC,MAAM,QAAQ,MAAM,aAAa;CAC/B,MAAM,QAAQ,QAAQ,IAAI,QAAQ,MAAM,SAAS;AAGjD,QAAO,OAAO,UAAU,cAAc,SAAS,KAAK,OAAO,KAAK,CAAC,GAC7D,wBAAwB,MAAM,GAC9B;GAEP,CAAC;AAGJ,MAAa,aAAa,kBAAkB"}
|
package/dist/esm/utils/intl.mjs
CHANGED
|
@@ -5,25 +5,32 @@ const cacheKey = (locales, options) => JSON.stringify([locales, options]);
|
|
|
5
5
|
const createCachedConstructor = (Ctor) => {
|
|
6
6
|
const cache = /* @__PURE__ */ new Map();
|
|
7
7
|
function Wrapped(locales, options) {
|
|
8
|
-
if (Ctor.name === "DisplayNames" && typeof Intl?.DisplayNames !== "function")
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
8
|
+
if (Ctor.name === "DisplayNames" && typeof Intl?.DisplayNames !== "function") {
|
|
9
|
+
{
|
|
10
|
+
const message = [
|
|
11
|
+
`// Intl.DisplayNames is not supported; falling back to raw locale (${locales}). `,
|
|
12
|
+
`// Consider adding a polyfill as https://formatjs.io/docs/polyfills/intl-displaynames/`,
|
|
13
|
+
``,
|
|
14
|
+
`import 'intl';`,
|
|
15
|
+
`import '@formatjs/intl-displaynames/polyfill';`,
|
|
16
|
+
`import '@formatjs/intl-getcanonicallocales/polyfill';`,
|
|
17
|
+
`import '@formatjs/intl-locale/polyfill';`,
|
|
18
|
+
`import '@formatjs/intl-pluralrules/polyfill';`,
|
|
19
|
+
`import '@formatjs/intl-listformat/polyfill';`,
|
|
20
|
+
`import '@formatjs/intl-numberformat/polyfill';`,
|
|
21
|
+
`import '@formatjs/intl-relativetimeformat/polyfill';`,
|
|
22
|
+
`import '@formatjs/intl-datetimeformat/polyfill';`,
|
|
23
|
+
``,
|
|
24
|
+
`// Optionally add locale data`,
|
|
25
|
+
`import '@formatjs/intl-pluralrules/locale-data/fr';`,
|
|
26
|
+
`import '@formatjs/intl-numberformat/locale-data/fr';`,
|
|
27
|
+
`import '@formatjs/intl-datetimeformat/locale-data/fr';`
|
|
28
|
+
].join("\n");
|
|
29
|
+
console.warn(message);
|
|
30
|
+
throw new Error(message);
|
|
31
|
+
}
|
|
32
|
+
return locales;
|
|
33
|
+
}
|
|
27
34
|
const key = cacheKey(locales ?? Locales.ENGLISH, options);
|
|
28
35
|
let instance = cache.get(key);
|
|
29
36
|
if (!instance) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intl.mjs","names":["instance: InstanceType<T> | undefined"],"sources":["../../../src/utils/intl.ts"],"sourcesContent":["// Cached Intl helper – drop‑in replacement for the global `Intl` object.\n// ‑‑‑\n// • Uses a `Proxy` to lazily wrap every *constructor* hanging off `Intl` (NumberFormat, DateTimeFormat, …).\n// • Each wrapped constructor keeps an in‑memory cache keyed by `[locales, options]` so that identical requests\n// reuse the same heavy instance instead of reparsing CLDR data every time.\n// • A polyfill warning for `Intl.DisplayNames` is emitted only once and only in dev.\n// • The public API is fully type‑safe and mirrors the native `Intl` surface exactly –\n// you can treat `CachedIntl` just like the built‑in `Intl`.\n//\n// Usage examples:\n// ---------------\n// import { CachedIntl } from \"./cached-intl\";\n//\n// const nf = CachedIntl.NumberFormat(\"en-US\", { style: \"currency\", currency: \"USD\" });\n// console.log(nf.format(1234));\n//\n// const dn = CachedIntl.DisplayNames([\"fr\"], { type: \"language\" });\n// console.log(dn.of(\"en\")); // → \"anglais\"\n//\n// You can also spin up an isolated instance with its own caches (handy in test suites):\n// const TestIntl = createCachedIntl();\n//\n// ---------------------------------------------------------------------\n\nimport { Locales, type LocalesValues } from '@intlayer/types';\n\n// Helper type that picks just the constructor members off `typeof Intl`.\n// The \"capital‑letter\" heuristic is 100 % accurate today and keeps the\n// mapping short‑lived, so we don't have to manually list every constructor.\ntype IntlConstructors = {\n [K in keyof typeof Intl as (typeof Intl)[K] extends new (\n ...args: any\n ) => any\n ? K\n : never]: (typeof Intl)[K];\n};\n\n// Type wrapper to replace locale arguments with LocalesValues\ntype ReplaceLocaleWithLocalesValues<T> = T extends new (\n locales: any,\n options?: infer Options\n) => infer Instance\n ? new (\n locales?: LocalesValues,\n options?: Options\n ) => Instance\n : T extends new (\n locales: any\n ) => infer Instance\n ? new (\n locales?: LocalesValues\n ) => Instance\n : T;\n\n// Wrapped Intl type with LocalesValues\ntype WrappedIntl = {\n [K in keyof typeof Intl]: K extends keyof IntlConstructors\n ? ReplaceLocaleWithLocalesValues<(typeof Intl)[K]>\n : (typeof Intl)[K];\n};\n\n// Generic cache key – JSON.stringify is fine because locale strings are short\n// and option objects are small and deterministic.\nconst cacheKey = (locales: LocalesValues, options: unknown) =>\n JSON.stringify([locales, options]);\n\n// Generic wrapper for any `new Intl.*()` constructor.\n// Returns a constructable function (usable with or without `new`) that\n// pulls instances from a Map cache when possible.\nconst createCachedConstructor = <T extends new (...args: any[]) => any>(\n Ctor: T\n) => {\n const cache = new Map<string, InstanceType<T>>();\n\n function Wrapped(locales?: LocalesValues, options?: any) {\n // Special case – guard older runtimes missing DisplayNames.\n if (\n Ctor.name === 'DisplayNames' &&\n typeof (Intl as any)?.DisplayNames !== 'function'\n ) {\n if (process.env.NODE_ENV === 'development') {\n
|
|
1
|
+
{"version":3,"file":"intl.mjs","names":["instance: InstanceType<T> | undefined"],"sources":["../../../src/utils/intl.ts"],"sourcesContent":["// Cached Intl helper – drop‑in replacement for the global `Intl` object.\n// ‑‑‑\n// • Uses a `Proxy` to lazily wrap every *constructor* hanging off `Intl` (NumberFormat, DateTimeFormat, …).\n// • Each wrapped constructor keeps an in‑memory cache keyed by `[locales, options]` so that identical requests\n// reuse the same heavy instance instead of reparsing CLDR data every time.\n// • A polyfill warning for `Intl.DisplayNames` is emitted only once and only in dev.\n// • The public API is fully type‑safe and mirrors the native `Intl` surface exactly –\n// you can treat `CachedIntl` just like the built‑in `Intl`.\n//\n// Usage examples:\n// ---------------\n// import { CachedIntl } from \"./cached-intl\";\n//\n// const nf = CachedIntl.NumberFormat(\"en-US\", { style: \"currency\", currency: \"USD\" });\n// console.log(nf.format(1234));\n//\n// const dn = CachedIntl.DisplayNames([\"fr\"], { type: \"language\" });\n// console.log(dn.of(\"en\")); // → \"anglais\"\n//\n// You can also spin up an isolated instance with its own caches (handy in test suites):\n// const TestIntl = createCachedIntl();\n//\n// ---------------------------------------------------------------------\n\nimport { Locales, type LocalesValues } from '@intlayer/types';\n\n// Helper type that picks just the constructor members off `typeof Intl`.\n// The \"capital‑letter\" heuristic is 100 % accurate today and keeps the\n// mapping short‑lived, so we don't have to manually list every constructor.\ntype IntlConstructors = {\n [K in keyof typeof Intl as (typeof Intl)[K] extends new (\n ...args: any\n ) => any\n ? K\n : never]: (typeof Intl)[K];\n};\n\n// Type wrapper to replace locale arguments with LocalesValues\ntype ReplaceLocaleWithLocalesValues<T> = T extends new (\n locales: any,\n options?: infer Options\n) => infer Instance\n ? new (\n locales?: LocalesValues,\n options?: Options\n ) => Instance\n : T extends new (\n locales: any\n ) => infer Instance\n ? new (\n locales?: LocalesValues\n ) => Instance\n : T;\n\n// Wrapped Intl type with LocalesValues\ntype WrappedIntl = {\n [K in keyof typeof Intl]: K extends keyof IntlConstructors\n ? ReplaceLocaleWithLocalesValues<(typeof Intl)[K]>\n : (typeof Intl)[K];\n};\n\n// Generic cache key – JSON.stringify is fine because locale strings are short\n// and option objects are small and deterministic.\nconst cacheKey = (locales: LocalesValues, options: unknown) =>\n JSON.stringify([locales, options]);\n\n// Generic wrapper for any `new Intl.*()` constructor.\n// Returns a constructable function (usable with or without `new`) that\n// pulls instances from a Map cache when possible.\nconst createCachedConstructor = <T extends new (...args: any[]) => any>(\n Ctor: T\n) => {\n const cache = new Map<string, InstanceType<T>>();\n\n function Wrapped(locales?: LocalesValues, options?: any) {\n // Special case – guard older runtimes missing DisplayNames.\n if (\n Ctor.name === 'DisplayNames' &&\n typeof (Intl as any)?.DisplayNames !== 'function'\n ) {\n if (process.env.NODE_ENV === 'development') {\n const message = [\n `// Intl.DisplayNames is not supported; falling back to raw locale (${locales}). `,\n `// Consider adding a polyfill as https://formatjs.io/docs/polyfills/intl-displaynames/`,\n ``,\n `import 'intl';`,\n `import '@formatjs/intl-displaynames/polyfill';`,\n `import '@formatjs/intl-getcanonicallocales/polyfill';`,\n `import '@formatjs/intl-locale/polyfill';`,\n `import '@formatjs/intl-pluralrules/polyfill';`,\n `import '@formatjs/intl-listformat/polyfill';`,\n `import '@formatjs/intl-numberformat/polyfill';`,\n `import '@formatjs/intl-relativetimeformat/polyfill';`,\n `import '@formatjs/intl-datetimeformat/polyfill';`,\n ``,\n `// Optionally add locale data`,\n `import '@formatjs/intl-pluralrules/locale-data/fr';`,\n `import '@formatjs/intl-numberformat/locale-data/fr';`,\n `import '@formatjs/intl-datetimeformat/locale-data/fr';`,\n ].join('\\n');\n\n console.warn(message);\n throw new Error(message);\n }\n return locales as any;\n }\n\n const key = cacheKey(locales ?? Locales.ENGLISH, options);\n let instance: InstanceType<T> | undefined = cache.get(key);\n\n if (!instance) {\n instance = new Ctor(locales as never, options as never);\n cache.set(key, instance as InstanceType<T>);\n }\n\n return instance as InstanceType<T>;\n }\n\n // Ensure it behaves like a constructor when used with `new`.\n (Wrapped as any).prototype = (Ctor as any).prototype;\n\n return Wrapped as unknown as ReplaceLocaleWithLocalesValues<T>;\n};\n\n// Factory that turns the global `Intl` into a cached clone.\nexport const createCachedIntl = (): WrappedIntl =>\n new Proxy(Intl as IntlConstructors, {\n get: (target, prop, receiver) => {\n const value = Reflect.get(target, prop, receiver);\n\n // Wrap *only* constructor functions (safest heuristic: they start with a capital letter).\n return typeof value === 'function' && /^[A-Z]/.test(String(prop))\n ? createCachedConstructor(value)\n : value;\n },\n }) as unknown as WrappedIntl;\n\n// Singleton – import this in application code if you just want shared caches.\nexport const CachedIntl = createCachedIntl();\n\n// new CachedIntl.DisplayNames(Locales.FRENCH, { type: 'language' });\n// new CachedIntl.DisplayNames('fr', { type: 'language' });\n// new CachedIntl.DateTimeFormat('fr', {\n// year: 'numeric',\n// month: 'long',\n// day: 'numeric',\n// });\n// new CachedIntl.NumberFormat('fr', {\n// style: 'currency',\n// currency: 'EUR',\n// });\n// new CachedIntl.Collator('fr', { sensitivity: 'base' });\n// new CachedIntl.PluralRules('fr');\n// new CachedIntl.RelativeTimeFormat('fr', { numeric: 'auto' });\n// new CachedIntl.ListFormat('fr', { type: 'conjunction' });\n\nexport { CachedIntl as Intl };\n"],"mappings":";;;AA+DA,MAAM,YAAY,SAAwB,YACxC,KAAK,UAAU,CAAC,SAAS,QAAQ,CAAC;AAKpC,MAAM,2BACJ,SACG;CACH,MAAM,wBAAQ,IAAI,KAA8B;CAEhD,SAAS,QAAQ,SAAyB,SAAe;AAEvD,MACE,KAAK,SAAS,kBACd,OAAQ,MAAc,iBAAiB,YACvC;GAC4C;IAC1C,MAAM,UAAU;KACd,sEAAsE,QAAQ;KAC9E;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACD,CAAC,KAAK,KAAK;AAEZ,YAAQ,KAAK,QAAQ;AACrB,UAAM,IAAI,MAAM,QAAQ;;AAE1B,UAAO;;EAGT,MAAM,MAAM,SAAS,WAAW,QAAQ,SAAS,QAAQ;EACzD,IAAIA,WAAwC,MAAM,IAAI,IAAI;AAE1D,MAAI,CAAC,UAAU;AACb,cAAW,IAAI,KAAK,SAAkB,QAAiB;AACvD,SAAM,IAAI,KAAK,SAA4B;;AAG7C,SAAO;;AAIT,CAAC,QAAgB,YAAa,KAAa;AAE3C,QAAO;;AAIT,MAAa,yBACX,IAAI,MAAM,MAA0B,EAClC,MAAM,QAAQ,MAAM,aAAa;CAC/B,MAAM,QAAQ,QAAQ,IAAI,QAAQ,MAAM,SAAS;AAGjD,QAAO,OAAO,UAAU,cAAc,SAAS,KAAK,OAAO,KAAK,CAAC,GAC7D,wBAAwB,MAAM,GAC9B;GAEP,CAAC;AAGJ,MAAa,aAAa,kBAAkB"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DeepTransformContent, NodeProps, Plugins } from "../interpreter/getContent/plugins.js";
|
|
2
2
|
import "../interpreter/index.js";
|
|
3
|
-
import * as
|
|
3
|
+
import * as _intlayer_types6 from "@intlayer/types";
|
|
4
4
|
import { ContentNode, DeclaredLocales, Dictionary, LocalesValues } from "@intlayer/types";
|
|
5
5
|
|
|
6
6
|
//#region src/deepTransformPlugins/getFilterTranslationsOnlyContent.d.ts
|
|
@@ -16,12 +16,12 @@ declare const getFilterTranslationsOnlyContent: <T extends ContentNode, L extend
|
|
|
16
16
|
declare const getFilterTranslationsOnlyDictionary: (dictionary: Dictionary, locale?: LocalesValues, fallback?: LocalesValues) => {
|
|
17
17
|
content: any;
|
|
18
18
|
$schema?: string;
|
|
19
|
-
id?:
|
|
19
|
+
id?: _intlayer_types6.DictionaryId;
|
|
20
20
|
projectIds?: string[];
|
|
21
|
-
localId?:
|
|
22
|
-
localIds?:
|
|
23
|
-
format?:
|
|
24
|
-
key:
|
|
21
|
+
localId?: _intlayer_types6.LocalDictionaryId;
|
|
22
|
+
localIds?: _intlayer_types6.LocalDictionaryId[];
|
|
23
|
+
format?: _intlayer_types6.DictionaryFormat;
|
|
24
|
+
key: _intlayer_types6.DictionaryKey;
|
|
25
25
|
title?: string;
|
|
26
26
|
description?: string;
|
|
27
27
|
versions?: string[];
|
|
@@ -29,11 +29,11 @@ declare const getFilterTranslationsOnlyDictionary: (dictionary: Dictionary, loca
|
|
|
29
29
|
filePath?: string;
|
|
30
30
|
tags?: string[];
|
|
31
31
|
locale?: LocalesValues;
|
|
32
|
-
fill?:
|
|
32
|
+
fill?: _intlayer_types6.Fill;
|
|
33
33
|
filled?: true;
|
|
34
34
|
priority?: number;
|
|
35
35
|
live?: boolean;
|
|
36
|
-
location?:
|
|
36
|
+
location?: _intlayer_types6.DictionaryLocation;
|
|
37
37
|
};
|
|
38
38
|
//#endregion
|
|
39
39
|
export { filterTranslationsOnlyPlugin, getFilterTranslationsOnlyContent, getFilterTranslationsOnlyDictionary };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getFilterTranslationsOnlyContent.d.ts","names":[],"sources":["../../../src/deepTransformPlugins/getFilterTranslationsOnlyContent.ts"],"sourcesContent":[],"mappings":";;;;;;;cAoCa,uCACH,0BACG,kBACV;;AAHH;;;;;AAuFa,cAAA,gCAkBZ,EAAA,CAAA,UAjBW,WAiBX,EAAA,UAhBW,aAgBX,GAhB2B,eAgB3B,CAAA,CAAA,IAAA,EAdO,CAcP,EAAA,MAAA,EAbS,CAaT,EAAA,SAAA,EAZY,SAYZ,EAAA,QAAA,CAAA,EAXY,aAWZ,EAAA,GADO,oBACP,CAD4B,CAC5B,CAAA;AAjBW,cAmBC,mCAnBD,EAAA,CAAA,UAAA,EAoBE,UApBF,EAAA,MAAA,CAAA,EAqBF,aArBE,EAAA,QAAA,CAAA,EAuBC,aAvBD,EAAA,GAAA;EACA,OAAA,EAAA,GAAA;EAAgB,OAAA,CAAA,EAAA,MAAA;EAEpB,EAAA,CAAA,EAoBkB,
|
|
1
|
+
{"version":3,"file":"getFilterTranslationsOnlyContent.d.ts","names":[],"sources":["../../../src/deepTransformPlugins/getFilterTranslationsOnlyContent.ts"],"sourcesContent":[],"mappings":";;;;;;;cAoCa,uCACH,0BACG,kBACV;;AAHH;;;;;AAuFa,cAAA,gCAkBZ,EAAA,CAAA,UAjBW,WAiBX,EAAA,UAhBW,aAgBX,GAhB2B,eAgB3B,CAAA,CAAA,IAAA,EAdO,CAcP,EAAA,MAAA,EAbS,CAaT,EAAA,SAAA,EAZY,SAYZ,EAAA,QAAA,CAAA,EAXY,aAWZ,EAAA,GADO,oBACP,CAD4B,CAC5B,CAAA;AAjBW,cAmBC,mCAnBD,EAAA,CAAA,UAAA,EAoBE,UApBF,EAAA,MAAA,CAAA,EAqBF,aArBE,EAAA,QAAA,CAAA,EAuBC,aAvBD,EAAA,GAAA;EACA,OAAA,EAAA,GAAA;EAAgB,OAAA,CAAA,EAAA,MAAA;EAEpB,EAAA,CAAA,EAoBkB,gBAAA,CAAA,YApBlB;EACE,UAAA,CAAA,EAAA,MAAA,EAAA;EACG,OAAA,CAAA,oCAAA;EACA,QAAA,CAAA,sCAAA;EAUgB,MAAA,CAAA,mCAAA;EAArB,GAAA,gCAAA;EAAoB,KAAA,CAAA,EAAA,MAAA;EAGf,WAAA,CAAA,EAAA,MAAA;EACC,QAAA,CAAA,EAAA,MAAA,EAAA;EACJ,OAAA,CAAA,EAAA,MAAA;EAEG,QAAA,CAAA,EAAA,MAAA;EAAa,IAAA,CAAA,EAAA,MAAA,EAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NodeProps } from "../interpreter/getContent/plugins.js";
|
|
2
2
|
import "../interpreter/index.js";
|
|
3
|
-
import * as
|
|
3
|
+
import * as _intlayer_types14 from "@intlayer/types";
|
|
4
4
|
import { ContentNode, Dictionary, LocalesValues } from "@intlayer/types";
|
|
5
5
|
|
|
6
6
|
//#region src/deepTransformPlugins/getFilteredLocalesContent.d.ts
|
|
@@ -8,12 +8,12 @@ declare const getFilteredLocalesContent: (node: ContentNode, locales: LocalesVal
|
|
|
8
8
|
declare const getFilteredLocalesDictionary: (dictionary: Dictionary, locale: LocalesValues | LocalesValues[]) => {
|
|
9
9
|
content: any;
|
|
10
10
|
$schema?: string;
|
|
11
|
-
id?:
|
|
11
|
+
id?: _intlayer_types14.DictionaryId;
|
|
12
12
|
projectIds?: string[];
|
|
13
|
-
localId?:
|
|
14
|
-
localIds?:
|
|
15
|
-
format?:
|
|
16
|
-
key:
|
|
13
|
+
localId?: _intlayer_types14.LocalDictionaryId;
|
|
14
|
+
localIds?: _intlayer_types14.LocalDictionaryId[];
|
|
15
|
+
format?: _intlayer_types14.DictionaryFormat;
|
|
16
|
+
key: _intlayer_types14.DictionaryKey;
|
|
17
17
|
title?: string;
|
|
18
18
|
description?: string;
|
|
19
19
|
versions?: string[];
|
|
@@ -21,11 +21,11 @@ declare const getFilteredLocalesDictionary: (dictionary: Dictionary, locale: Loc
|
|
|
21
21
|
filePath?: string;
|
|
22
22
|
tags?: string[];
|
|
23
23
|
locale?: LocalesValues;
|
|
24
|
-
fill?:
|
|
24
|
+
fill?: _intlayer_types14.Fill;
|
|
25
25
|
filled?: true;
|
|
26
26
|
priority?: number;
|
|
27
27
|
live?: boolean;
|
|
28
|
-
location?:
|
|
28
|
+
location?: _intlayer_types14.DictionaryLocation;
|
|
29
29
|
};
|
|
30
30
|
//#endregion
|
|
31
31
|
export { getFilteredLocalesContent, getFilteredLocalesDictionary };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getFilteredLocalesContent.d.ts","names":[],"sources":["../../../src/deepTransformPlugins/getFilteredLocalesContent.ts"],"sourcesContent":[],"mappings":";;;;;;cAsCa,kCACL,sBACG,gBAAgB,4BACd;cAwBA,2CACC,oBACJ,gBAAgB;;;EA7Bb,EAAA,CAAA,EA6B0B,
|
|
1
|
+
{"version":3,"file":"getFilteredLocalesContent.d.ts","names":[],"sources":["../../../src/deepTransformPlugins/getFilteredLocalesContent.ts"],"sourcesContent":[],"mappings":";;;;;;cAsCa,kCACL,sBACG,gBAAgB,4BACd;cAwBA,2CACC,oBACJ,gBAAgB;;;EA7Bb,EAAA,CAAA,EA6B0B,iBAAA,CAAA,YAbtC;EAfO,UAAA,CAAA,EAAA,MAAA,EAAA;EACG,OAAA,CAAA,qCAAA;EAAgB,QAAA,CAAA,uCAAA;EACd,MAAA,CAAA,oCAAA;EAAS,GAAA,iCAAA;EAwBT,KAAA,CAAA,EAAA,MAAA;EACC,WAAA,CAAA,EAAA,MAAA;EACJ,QAAA,CAAA,EAAA,MAAA,EAAA;EAAgB,OAAA,CAAA,EAAA,MAAA;EAAa,QAAA,CAAA,EAAA,MAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intl.d.ts","names":[],"sources":["../../../src/utils/intl.ts"],"sourcesContent":[],"mappings":";;;KA6BK,gBAAA,wBACgB,gBAAgB,MAAM,yCAGrC,oBACgB,MAAM,IAVkC;KAczD,8BARgB,CAAA,CAAA,CAAA,GAQoB,CARpB,UAAA,KAAA,OAAA,EAAA,GAAA,EAAA,OAAA,CAAA,EAAA,KAAA,QAAA,EAAA,GAAA,KAAA,SAAA,IAAA,KAAA,OAAA,CAAA,EAaL,aAbK,EAAA,OAAA,CAAA,EAcL,OAdK,EAAA,GAeZ,QAfY,GAgBjB,CAhBiB,UAAA,KAAA,OAAA,EAAA,GAAA,EAAA,GAAA,KAAA,SAAA,IAAA,KAAA,OAAA,CAAA,EAoBH,aApBG,EAAA,GAqBV,QArBU,GAsBf,CAtBe;KAyBhB,WAAA,GAzBgC,QAAM,MAAA,OA0BtB,IA1BsB,GA0Bf,CA1Be,SAAA,MA0BC,gBA1BD,GA2BrC,8BA3BqC,CAAA,CAAA,OA2BE,IA3BF,CAAA,CA2BQ,CA3BR,CAAA,CAAA,GAAA,CAAA,OA4B7B,IA5B6B,CAAA,CA4BvB,CA5BuB,CAAA,EAGrC;AACgB,
|
|
1
|
+
{"version":3,"file":"intl.d.ts","names":[],"sources":["../../../src/utils/intl.ts"],"sourcesContent":[],"mappings":";;;KA6BK,gBAAA,wBACgB,gBAAgB,MAAM,yCAGrC,oBACgB,MAAM,IAVkC;KAczD,8BARgB,CAAA,CAAA,CAAA,GAQoB,CARpB,UAAA,KAAA,OAAA,EAAA,GAAA,EAAA,OAAA,CAAA,EAAA,KAAA,QAAA,EAAA,GAAA,KAAA,SAAA,IAAA,KAAA,OAAA,CAAA,EAaL,aAbK,EAAA,OAAA,CAAA,EAcL,OAdK,EAAA,GAeZ,QAfY,GAgBjB,CAhBiB,UAAA,KAAA,OAAA,EAAA,GAAA,EAAA,GAAA,KAAA,SAAA,IAAA,KAAA,OAAA,CAAA,EAoBH,aApBG,EAAA,GAqBV,QArBU,GAsBf,CAtBe;KAyBhB,WAAA,GAzBgC,QAAM,MAAA,OA0BtB,IA1BsB,GA0Bf,CA1Be,SAAA,MA0BC,gBA1BD,GA2BrC,8BA3BqC,CAAA,CAAA,OA2BE,IA3BF,CAAA,CA2BQ,CA3BR,CAAA,CAAA,GAAA,CAAA,OA4B7B,IA5B6B,CAAA,CA4BvB,CA5BuB,CAAA,EAGrC;AACgB,cA2FT,gBA3FS,EAAA,GAAA,GA2Fc,WA3Fd;AAAM,cAwGf,UAxGe,EAwGL,WAxGK"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intlayer/core",
|
|
3
|
-
"version": "7.5.0",
|
|
3
|
+
"version": "7.5.2-canary.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Includes core Intlayer functions like translation, dictionary, and utility functions shared across multiple packages.",
|
|
6
6
|
"keywords": [
|
|
@@ -107,11 +107,11 @@
|
|
|
107
107
|
"typecheck": "tsc --noEmit --project tsconfig.types.json"
|
|
108
108
|
},
|
|
109
109
|
"dependencies": {
|
|
110
|
-
"@intlayer/api": "7.5.0",
|
|
111
|
-
"@intlayer/config": "7.5.0",
|
|
112
|
-
"@intlayer/dictionaries-entry": "7.5.0",
|
|
113
|
-
"@intlayer/types": "7.5.0",
|
|
114
|
-
"@intlayer/unmerged-dictionaries-entry": "7.5.0",
|
|
110
|
+
"@intlayer/api": "7.5.2-canary.0",
|
|
111
|
+
"@intlayer/config": "7.5.2-canary.0",
|
|
112
|
+
"@intlayer/dictionaries-entry": "7.5.2-canary.0",
|
|
113
|
+
"@intlayer/types": "7.5.2-canary.0",
|
|
114
|
+
"@intlayer/unmerged-dictionaries-entry": "7.5.2-canary.0",
|
|
115
115
|
"defu": "6.1.4"
|
|
116
116
|
},
|
|
117
117
|
"devDependencies": {
|