@intlayer/core 6.1.5 → 6.1.6-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.
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/localization/localeDetector.ts"],"sourcesContent":["import { LocalesValues, type Locales } from '@intlayer/config/client';\nimport Negotiator from 'negotiator';\nimport { localeResolver } from './localeResolver';\n\n/**\n * Detects the locale from the request headers\n *\n * Headers are provided by the browser and can be used to determine the user's preferred language\n */\nexport const localeDetector = (\n headers: Record<string, string | undefined>,\n locales?: Locales[],\n defaultLocale?: Locales\n): LocalesValues => {\n const languages = new Negotiator({ headers }).languages();\n\n return localeResolver(languages as Locales[], locales, defaultLocale);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,wBAAuB;AACvB,4BAA+B;AAOxB,MAAM,iBAAiB,CAC5B,SACA,SACA,kBACkB;AAClB,QAAM,YAAY,IAAI,kBAAAA,QAAW,EAAE,QAAQ,CAAC,EAAE,UAAU;AAExD,aAAO,sCAAe,WAAwB,SAAS,aAAa;AACtE;","names":["Negotiator"]}
1
+ {"version":3,"sources":["../../../src/localization/localeDetector.ts"],"sourcesContent":["import { type Locales } from '@intlayer/config/client';\nimport Negotiator from 'negotiator';\nimport { localeResolver } from './localeResolver';\n\n/**\n * Detects the locale from the request headers\n *\n * Headers are provided by the browser and can be used to determine the user's preferred language\n */\nexport const localeDetector = (\n headers: Record<string, string | undefined>,\n locales?: Locales[],\n defaultLocale?: Locales\n): Locales => {\n const languages = new Negotiator({ headers }).languages();\n\n return localeResolver(languages as Locales[], locales, defaultLocale);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,wBAAuB;AACvB,4BAA+B;AAOxB,MAAM,iBAAiB,CAC5B,SACA,SACA,kBACY;AACZ,QAAM,YAAY,IAAI,kBAAAA,QAAW,EAAE,QAAQ,CAAC,EAAE,UAAU;AAExD,aAAO,sCAAe,WAAwB,SAAS,aAAa;AACtE;","names":["Negotiator"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/localization/localeResolver.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/config/client';\n\n/**\n * Resolves the most specific locale from a user-provided list,\n * or falls back to the default locale if no match is found.\n */\nexport const localeResolver = (\n selectedLocale: LocalesValues | LocalesValues[],\n locales: LocalesValues[] = configuration.internationalization.locales,\n defaultLocale: LocalesValues = configuration.internationalization\n .defaultLocale\n): LocalesValues => {\n // Ensure we can handle both a single locale or an array of locales uniformly\n const requestedLocales = [selectedLocale].flat();\n\n // Simple helper to normalize locale strings (e.g. \"en-US\" => \"en-us\")\n const normalize = (locale: string): string => locale.trim().toLowerCase();\n\n try {\n // Check each requested locale in order\n for (const requested of requestedLocales) {\n const normalizedRequested = normalize(requested);\n\n // 1) Attempt exact match\n const exactMatch = locales.find(\n (loc) => normalize(loc) === normalizedRequested\n );\n if (exactMatch) {\n return exactMatch;\n }\n\n // 2) Attempt partial match on language subtag\n // e.g. if requested is \"en-US\" and not found,\n // see if \"en\" is available among locales\n const [requestedLang] = normalizedRequested.split('-');\n const partialMatch = locales.find(\n (loc) => normalize(loc).split('-')[0] === requestedLang\n );\n if (partialMatch) {\n return partialMatch;\n }\n }\n } catch (_error) {\n // If anything unexpected happened, fall back to default\n }\n\n // If no match was found, return the default\n return defaultLocale;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA0B;AAOnB,MAAM,iBAAiB,CAC5B,gBACA,UAA2B,aAAAA,QAAc,qBAAqB,SAC9D,gBAA+B,aAAAA,QAAc,qBAC1C,kBACe;AAElB,QAAM,mBAAmB,CAAC,cAAc,EAAE,KAAK;AAG/C,QAAM,YAAY,CAAC,WAA2B,OAAO,KAAK,EAAE,YAAY;AAExE,MAAI;AAEF,eAAW,aAAa,kBAAkB;AACxC,YAAM,sBAAsB,UAAU,SAAS;AAG/C,YAAM,aAAa,QAAQ;AAAA,QACzB,CAAC,QAAQ,UAAU,GAAG,MAAM;AAAA,MAC9B;AACA,UAAI,YAAY;AACd,eAAO;AAAA,MACT;AAKA,YAAM,CAAC,aAAa,IAAI,oBAAoB,MAAM,GAAG;AACrD,YAAM,eAAe,QAAQ;AAAA,QAC3B,CAAC,QAAQ,UAAU,GAAG,EAAE,MAAM,GAAG,EAAE,CAAC,MAAM;AAAA,MAC5C;AACA,UAAI,cAAc;AAChB,eAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF,SAAS,QAAQ;AAAA,EAEjB;AAGA,SAAO;AACT;","names":["configuration"]}
1
+ {"version":3,"sources":["../../../src/localization/localeResolver.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { Locales, LocalesValues } from '@intlayer/config/client';\n\n/**\n * Resolves the most specific locale from a user-provided list,\n * or falls back to the default locale if no match is found.\n */\nexport const localeResolver = (\n selectedLocale: LocalesValues | LocalesValues[],\n locales: LocalesValues[] = configuration.internationalization.locales,\n defaultLocale: LocalesValues = configuration.internationalization\n .defaultLocale\n): Locales => {\n // Ensure we can handle both a single locale or an array of locales uniformly\n const requestedLocales = [selectedLocale].flat();\n\n // Simple helper to normalize locale strings (e.g. \"en-US\" => \"en-us\")\n const normalize = (locale: string): string => locale.trim().toLowerCase();\n\n try {\n // Check each requested locale in order\n for (const requested of requestedLocales) {\n const normalizedRequested = normalize(requested);\n\n // 1) Attempt exact match\n const exactMatch = locales.find(\n (loc) => normalize(loc) === normalizedRequested\n );\n if (exactMatch) {\n return exactMatch as Locales;\n }\n\n // 2) Attempt partial match on language subtag\n // e.g. if requested is \"en-US\" and not found,\n // see if \"en\" is available among locales\n const [requestedLang] = normalizedRequested.split('-');\n const partialMatch = locales.find(\n (loc) => normalize(loc).split('-')[0] === requestedLang\n );\n if (partialMatch) {\n return partialMatch as Locales;\n }\n }\n } catch (_error) {\n // If anything unexpected happened, fall back to default\n }\n\n // If no match was found, return the default\n return defaultLocale as Locales;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA0B;AAOnB,MAAM,iBAAiB,CAC5B,gBACA,UAA2B,aAAAA,QAAc,qBAAqB,SAC9D,gBAA+B,aAAAA,QAAc,qBAC1C,kBACS;AAEZ,QAAM,mBAAmB,CAAC,cAAc,EAAE,KAAK;AAG/C,QAAM,YAAY,CAAC,WAA2B,OAAO,KAAK,EAAE,YAAY;AAExE,MAAI;AAEF,eAAW,aAAa,kBAAkB;AACxC,YAAM,sBAAsB,UAAU,SAAS;AAG/C,YAAM,aAAa,QAAQ;AAAA,QACzB,CAAC,QAAQ,UAAU,GAAG,MAAM;AAAA,MAC9B;AACA,UAAI,YAAY;AACd,eAAO;AAAA,MACT;AAKA,YAAM,CAAC,aAAa,IAAI,oBAAoB,MAAM,GAAG;AACrD,YAAM,eAAe,QAAQ;AAAA,QAC3B,CAAC,QAAQ,UAAU,GAAG,EAAE,MAAM,GAAG,EAAE,CAAC,MAAM;AAAA,MAC5C;AACA,UAAI,cAAc;AAChB,eAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF,SAAS,QAAQ;AAAA,EAEjB;AAGA,SAAO;AACT;","names":["configuration"]}
@@ -30,7 +30,25 @@ const createCachedConstructor = (Ctor) => {
30
30
  if (Ctor.name === "DisplayNames" && typeof Intl?.DisplayNames !== "function") {
31
31
  if (process.env.NODE_ENV === "development") {
32
32
  console.warn(
33
- `Intl.DisplayNames is not supported; falling back to raw locale (${locales}). Consider adding a polyfill as https://formatjs.io/docs/polyfills/intl-displaynames/`
33
+ [
34
+ `// Intl.DisplayNames is not supported; falling back to raw locale (${locales}). `,
35
+ `// Consider adding a polyfill as https://formatjs.io/docs/polyfills/intl-displaynames/`,
36
+ ``,
37
+ `import 'intl';`,
38
+ `import '@formatjs/intl-getcanonicallocales/polyfill';`,
39
+ `import '@formatjs/intl-locale/polyfill';`,
40
+ `import '@formatjs/intl-pluralrules/polyfill';`,
41
+ `import '@formatjs/intl-displaynames/polyfill';`,
42
+ `import '@formatjs/intl-listformat/polyfill';`,
43
+ `import '@formatjs/intl-numberformat/polyfill';`,
44
+ `import '@formatjs/intl-relativetimeformat/polyfill';`,
45
+ `import '@formatjs/intl-datetimeformat/polyfill';`,
46
+ ``,
47
+ `// Optionally add locale data`,
48
+ `import '@formatjs/intl-pluralrules/locale-data/fr';`,
49
+ `import '@formatjs/intl-numberformat/locale-data/fr';`,
50
+ `import '@formatjs/intl-datetimeformat/locale-data/fr';`
51
+ ].join("\n")
34
52
  );
35
53
  }
36
54
  return locales;
@@ -1 +1 @@
1
- {"version":3,"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/config/client';\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 (...args: any) => 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 (locales?: LocalesValues, options?: Options) => Instance\n : T extends new (locales: any) => infer Instance\n ? new (locales?: LocalesValues) => 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 console.warn(\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 }\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.\nconst 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":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAwBA,oBAA4C;AA8B5C,MAAM,WAAW,CAAC,SAAwB,YACxC,KAAK,UAAU,CAAC,SAAS,OAAO,CAAC;AAKnC,MAAM,0BAA0B,CAC9B,SACG;AACH,QAAM,QAAQ,oBAAI,IAA6B;AAE/C,WAAS,QAAQ,SAAyB,SAAe;AAEvD,QACE,KAAK,SAAS,kBACd,OAAQ,MAAc,iBAAiB,YACvC;AACA,UAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,gBAAQ;AAAA,UACN,mEAAmE,OAAO;AAAA,QAE5E;AAAA,MACF;AACA,aAAO;AAAA,IACT;AAEA,UAAM,MAAM,SAAS,WAAW,sBAAQ,SAAS,OAAO;AACxD,QAAI,WAAwC,MAAM,IAAI,GAAG;AAEzD,QAAI,CAAC,UAAU;AACb,iBAAW,IAAI,KAAK,SAAkB,OAAgB;AACtD,YAAM,IAAI,KAAK,QAA2B;AAAA,IAC5C;AAEA,WAAO;AAAA,EACT;AAGA,EAAC,QAAgB,YAAa,KAAa;AAE3C,SAAO;AACT;AAGO,MAAM,mBAAmB,MAC9B,IAAI,MAAM,MAA0B;AAAA,EAClC,KAAK,CAAC,QAAQ,MAAM,aAAa;AAC/B,UAAM,QAAQ,QAAQ,IAAI,QAAQ,MAAM,QAAQ;AAGhD,WAAO,OAAO,UAAU,cAAc,SAAS,KAAK,OAAO,IAAI,CAAC,IAC5D,wBAAwB,KAAK,IAC7B;AAAA,EACN;AACF,CAAC;AAGH,MAAM,aAAa,iBAAiB;","names":[]}
1
+ {"version":3,"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/config/client';\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 (...args: any) => 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 (locales?: LocalesValues, options?: Options) => Instance\n : T extends new (locales: any) => infer Instance\n ? new (locales?: LocalesValues) => 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 console.warn(\n [\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-getcanonicallocales/polyfill';`,\n `import '@formatjs/intl-locale/polyfill';`,\n `import '@formatjs/intl-pluralrules/polyfill';`,\n `import '@formatjs/intl-displaynames/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 }\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.\nconst 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":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAwBA,oBAA4C;AA8B5C,MAAM,WAAW,CAAC,SAAwB,YACxC,KAAK,UAAU,CAAC,SAAS,OAAO,CAAC;AAKnC,MAAM,0BAA0B,CAC9B,SACG;AACH,QAAM,QAAQ,oBAAI,IAA6B;AAE/C,WAAS,QAAQ,SAAyB,SAAe;AAEvD,QACE,KAAK,SAAS,kBACd,OAAQ,MAAc,iBAAiB,YACvC;AACA,UAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,gBAAQ;AAAA,UACN;AAAA,YACE,sEAAsE,OAAO;AAAA,YAC7E;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,UACF,EAAE,KAAK,IAAI;AAAA,QACb;AAAA,MACF;AACA,aAAO;AAAA,IACT;AAEA,UAAM,MAAM,SAAS,WAAW,sBAAQ,SAAS,OAAO;AACxD,QAAI,WAAwC,MAAM,IAAI,GAAG;AAEzD,QAAI,CAAC,UAAU;AACb,iBAAW,IAAI,KAAK,SAAkB,OAAgB;AACtD,YAAM,IAAI,KAAK,QAA2B;AAAA,IAC5C;AAEA,WAAO;AAAA,EACT;AAGA,EAAC,QAAgB,YAAa,KAAa;AAE3C,SAAO;AACT;AAGO,MAAM,mBAAmB,MAC9B,IAAI,MAAM,MAA0B;AAAA,EAClC,KAAK,CAAC,QAAQ,MAAM,aAAa;AAC/B,UAAM,QAAQ,QAAQ,IAAI,QAAQ,MAAM,QAAQ;AAGhD,WAAO,OAAO,UAAU,cAAc,SAAS,KAAK,OAAO,IAAI,CAAC,IAC5D,wBAAwB,KAAK,IAC7B;AAAA,EACN;AACF,CAAC;AAGH,MAAM,aAAa,iBAAiB;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/localization/localeDetector.ts"],"sourcesContent":["import { LocalesValues, type Locales } from '@intlayer/config/client';\nimport Negotiator from 'negotiator';\nimport { localeResolver } from './localeResolver';\n\n/**\n * Detects the locale from the request headers\n *\n * Headers are provided by the browser and can be used to determine the user's preferred language\n */\nexport const localeDetector = (\n headers: Record<string, string | undefined>,\n locales?: Locales[],\n defaultLocale?: Locales\n): LocalesValues => {\n const languages = new Negotiator({ headers }).languages();\n\n return localeResolver(languages as Locales[], locales, defaultLocale);\n};\n"],"mappings":"AACA,OAAO,gBAAgB;AACvB,SAAS,sBAAsB;AAOxB,MAAM,iBAAiB,CAC5B,SACA,SACA,kBACkB;AAClB,QAAM,YAAY,IAAI,WAAW,EAAE,QAAQ,CAAC,EAAE,UAAU;AAExD,SAAO,eAAe,WAAwB,SAAS,aAAa;AACtE;","names":[]}
1
+ {"version":3,"sources":["../../../src/localization/localeDetector.ts"],"sourcesContent":["import { type Locales } from '@intlayer/config/client';\nimport Negotiator from 'negotiator';\nimport { localeResolver } from './localeResolver';\n\n/**\n * Detects the locale from the request headers\n *\n * Headers are provided by the browser and can be used to determine the user's preferred language\n */\nexport const localeDetector = (\n headers: Record<string, string | undefined>,\n locales?: Locales[],\n defaultLocale?: Locales\n): Locales => {\n const languages = new Negotiator({ headers }).languages();\n\n return localeResolver(languages as Locales[], locales, defaultLocale);\n};\n"],"mappings":"AACA,OAAO,gBAAgB;AACvB,SAAS,sBAAsB;AAOxB,MAAM,iBAAiB,CAC5B,SACA,SACA,kBACY;AACZ,QAAM,YAAY,IAAI,WAAW,EAAE,QAAQ,CAAC,EAAE,UAAU;AAExD,SAAO,eAAe,WAAwB,SAAS,aAAa;AACtE;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/localization/localeResolver.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/config/client';\n\n/**\n * Resolves the most specific locale from a user-provided list,\n * or falls back to the default locale if no match is found.\n */\nexport const localeResolver = (\n selectedLocale: LocalesValues | LocalesValues[],\n locales: LocalesValues[] = configuration.internationalization.locales,\n defaultLocale: LocalesValues = configuration.internationalization\n .defaultLocale\n): LocalesValues => {\n // Ensure we can handle both a single locale or an array of locales uniformly\n const requestedLocales = [selectedLocale].flat();\n\n // Simple helper to normalize locale strings (e.g. \"en-US\" => \"en-us\")\n const normalize = (locale: string): string => locale.trim().toLowerCase();\n\n try {\n // Check each requested locale in order\n for (const requested of requestedLocales) {\n const normalizedRequested = normalize(requested);\n\n // 1) Attempt exact match\n const exactMatch = locales.find(\n (loc) => normalize(loc) === normalizedRequested\n );\n if (exactMatch) {\n return exactMatch;\n }\n\n // 2) Attempt partial match on language subtag\n // e.g. if requested is \"en-US\" and not found,\n // see if \"en\" is available among locales\n const [requestedLang] = normalizedRequested.split('-');\n const partialMatch = locales.find(\n (loc) => normalize(loc).split('-')[0] === requestedLang\n );\n if (partialMatch) {\n return partialMatch;\n }\n }\n } catch (_error) {\n // If anything unexpected happened, fall back to default\n }\n\n // If no match was found, return the default\n return defaultLocale;\n};\n"],"mappings":"AAAA,OAAO,mBAAmB;AAOnB,MAAM,iBAAiB,CAC5B,gBACA,UAA2B,cAAc,qBAAqB,SAC9D,gBAA+B,cAAc,qBAC1C,kBACe;AAElB,QAAM,mBAAmB,CAAC,cAAc,EAAE,KAAK;AAG/C,QAAM,YAAY,CAAC,WAA2B,OAAO,KAAK,EAAE,YAAY;AAExE,MAAI;AAEF,eAAW,aAAa,kBAAkB;AACxC,YAAM,sBAAsB,UAAU,SAAS;AAG/C,YAAM,aAAa,QAAQ;AAAA,QACzB,CAAC,QAAQ,UAAU,GAAG,MAAM;AAAA,MAC9B;AACA,UAAI,YAAY;AACd,eAAO;AAAA,MACT;AAKA,YAAM,CAAC,aAAa,IAAI,oBAAoB,MAAM,GAAG;AACrD,YAAM,eAAe,QAAQ;AAAA,QAC3B,CAAC,QAAQ,UAAU,GAAG,EAAE,MAAM,GAAG,EAAE,CAAC,MAAM;AAAA,MAC5C;AACA,UAAI,cAAc;AAChB,eAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF,SAAS,QAAQ;AAAA,EAEjB;AAGA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../../src/localization/localeResolver.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { Locales, LocalesValues } from '@intlayer/config/client';\n\n/**\n * Resolves the most specific locale from a user-provided list,\n * or falls back to the default locale if no match is found.\n */\nexport const localeResolver = (\n selectedLocale: LocalesValues | LocalesValues[],\n locales: LocalesValues[] = configuration.internationalization.locales,\n defaultLocale: LocalesValues = configuration.internationalization\n .defaultLocale\n): Locales => {\n // Ensure we can handle both a single locale or an array of locales uniformly\n const requestedLocales = [selectedLocale].flat();\n\n // Simple helper to normalize locale strings (e.g. \"en-US\" => \"en-us\")\n const normalize = (locale: string): string => locale.trim().toLowerCase();\n\n try {\n // Check each requested locale in order\n for (const requested of requestedLocales) {\n const normalizedRequested = normalize(requested);\n\n // 1) Attempt exact match\n const exactMatch = locales.find(\n (loc) => normalize(loc) === normalizedRequested\n );\n if (exactMatch) {\n return exactMatch as Locales;\n }\n\n // 2) Attempt partial match on language subtag\n // e.g. if requested is \"en-US\" and not found,\n // see if \"en\" is available among locales\n const [requestedLang] = normalizedRequested.split('-');\n const partialMatch = locales.find(\n (loc) => normalize(loc).split('-')[0] === requestedLang\n );\n if (partialMatch) {\n return partialMatch as Locales;\n }\n }\n } catch (_error) {\n // If anything unexpected happened, fall back to default\n }\n\n // If no match was found, return the default\n return defaultLocale as Locales;\n};\n"],"mappings":"AAAA,OAAO,mBAAmB;AAOnB,MAAM,iBAAiB,CAC5B,gBACA,UAA2B,cAAc,qBAAqB,SAC9D,gBAA+B,cAAc,qBAC1C,kBACS;AAEZ,QAAM,mBAAmB,CAAC,cAAc,EAAE,KAAK;AAG/C,QAAM,YAAY,CAAC,WAA2B,OAAO,KAAK,EAAE,YAAY;AAExE,MAAI;AAEF,eAAW,aAAa,kBAAkB;AACxC,YAAM,sBAAsB,UAAU,SAAS;AAG/C,YAAM,aAAa,QAAQ;AAAA,QACzB,CAAC,QAAQ,UAAU,GAAG,MAAM;AAAA,MAC9B;AACA,UAAI,YAAY;AACd,eAAO;AAAA,MACT;AAKA,YAAM,CAAC,aAAa,IAAI,oBAAoB,MAAM,GAAG;AACrD,YAAM,eAAe,QAAQ;AAAA,QAC3B,CAAC,QAAQ,UAAU,GAAG,EAAE,MAAM,GAAG,EAAE,CAAC,MAAM;AAAA,MAC5C;AACA,UAAI,cAAc;AAChB,eAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF,SAAS,QAAQ;AAAA,EAEjB;AAGA,SAAO;AACT;","names":[]}
@@ -6,7 +6,25 @@ const createCachedConstructor = (Ctor) => {
6
6
  if (Ctor.name === "DisplayNames" && typeof Intl?.DisplayNames !== "function") {
7
7
  if (process.env.NODE_ENV === "development") {
8
8
  console.warn(
9
- `Intl.DisplayNames is not supported; falling back to raw locale (${locales}). Consider adding a polyfill as https://formatjs.io/docs/polyfills/intl-displaynames/`
9
+ [
10
+ `// Intl.DisplayNames is not supported; falling back to raw locale (${locales}). `,
11
+ `// Consider adding a polyfill as https://formatjs.io/docs/polyfills/intl-displaynames/`,
12
+ ``,
13
+ `import 'intl';`,
14
+ `import '@formatjs/intl-getcanonicallocales/polyfill';`,
15
+ `import '@formatjs/intl-locale/polyfill';`,
16
+ `import '@formatjs/intl-pluralrules/polyfill';`,
17
+ `import '@formatjs/intl-displaynames/polyfill';`,
18
+ `import '@formatjs/intl-listformat/polyfill';`,
19
+ `import '@formatjs/intl-numberformat/polyfill';`,
20
+ `import '@formatjs/intl-relativetimeformat/polyfill';`,
21
+ `import '@formatjs/intl-datetimeformat/polyfill';`,
22
+ ``,
23
+ `// Optionally add locale data`,
24
+ `import '@formatjs/intl-pluralrules/locale-data/fr';`,
25
+ `import '@formatjs/intl-numberformat/locale-data/fr';`,
26
+ `import '@formatjs/intl-datetimeformat/locale-data/fr';`
27
+ ].join("\n")
10
28
  );
11
29
  }
12
30
  return locales;
@@ -1 +1 @@
1
- {"version":3,"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/config/client';\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 (...args: any) => 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 (locales?: LocalesValues, options?: Options) => Instance\n : T extends new (locales: any) => infer Instance\n ? new (locales?: LocalesValues) => 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 console.warn(\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 }\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.\nconst 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":"AAwBA,SAAS,eAAmC;AA8B5C,MAAM,WAAW,CAAC,SAAwB,YACxC,KAAK,UAAU,CAAC,SAAS,OAAO,CAAC;AAKnC,MAAM,0BAA0B,CAC9B,SACG;AACH,QAAM,QAAQ,oBAAI,IAA6B;AAE/C,WAAS,QAAQ,SAAyB,SAAe;AAEvD,QACE,KAAK,SAAS,kBACd,OAAQ,MAAc,iBAAiB,YACvC;AACA,UAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,gBAAQ;AAAA,UACN,mEAAmE,OAAO;AAAA,QAE5E;AAAA,MACF;AACA,aAAO;AAAA,IACT;AAEA,UAAM,MAAM,SAAS,WAAW,QAAQ,SAAS,OAAO;AACxD,QAAI,WAAwC,MAAM,IAAI,GAAG;AAEzD,QAAI,CAAC,UAAU;AACb,iBAAW,IAAI,KAAK,SAAkB,OAAgB;AACtD,YAAM,IAAI,KAAK,QAA2B;AAAA,IAC5C;AAEA,WAAO;AAAA,EACT;AAGA,EAAC,QAAgB,YAAa,KAAa;AAE3C,SAAO;AACT;AAGO,MAAM,mBAAmB,MAC9B,IAAI,MAAM,MAA0B;AAAA,EAClC,KAAK,CAAC,QAAQ,MAAM,aAAa;AAC/B,UAAM,QAAQ,QAAQ,IAAI,QAAQ,MAAM,QAAQ;AAGhD,WAAO,OAAO,UAAU,cAAc,SAAS,KAAK,OAAO,IAAI,CAAC,IAC5D,wBAAwB,KAAK,IAC7B;AAAA,EACN;AACF,CAAC;AAGH,MAAM,aAAa,iBAAiB;","names":[]}
1
+ {"version":3,"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/config/client';\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 (...args: any) => 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 (locales?: LocalesValues, options?: Options) => Instance\n : T extends new (locales: any) => infer Instance\n ? new (locales?: LocalesValues) => 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 console.warn(\n [\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-getcanonicallocales/polyfill';`,\n `import '@formatjs/intl-locale/polyfill';`,\n `import '@formatjs/intl-pluralrules/polyfill';`,\n `import '@formatjs/intl-displaynames/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 }\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.\nconst 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":"AAwBA,SAAS,eAAmC;AA8B5C,MAAM,WAAW,CAAC,SAAwB,YACxC,KAAK,UAAU,CAAC,SAAS,OAAO,CAAC;AAKnC,MAAM,0BAA0B,CAC9B,SACG;AACH,QAAM,QAAQ,oBAAI,IAA6B;AAE/C,WAAS,QAAQ,SAAyB,SAAe;AAEvD,QACE,KAAK,SAAS,kBACd,OAAQ,MAAc,iBAAiB,YACvC;AACA,UAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,gBAAQ;AAAA,UACN;AAAA,YACE,sEAAsE,OAAO;AAAA,YAC7E;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,UACF,EAAE,KAAK,IAAI;AAAA,QACb;AAAA,MACF;AACA,aAAO;AAAA,IACT;AAEA,UAAM,MAAM,SAAS,WAAW,QAAQ,SAAS,OAAO;AACxD,QAAI,WAAwC,MAAM,IAAI,GAAG;AAEzD,QAAI,CAAC,UAAU;AACb,iBAAW,IAAI,KAAK,SAAkB,OAAgB;AACtD,YAAM,IAAI,KAAK,QAA2B;AAAA,IAC5C;AAEA,WAAO;AAAA,EACT;AAGA,EAAC,QAAgB,YAAa,KAAa;AAE3C,SAAO;AACT;AAGO,MAAM,mBAAmB,MAC9B,IAAI,MAAM,MAA0B;AAAA,EAClC,KAAK,CAAC,QAAQ,MAAM,aAAa;AAC/B,UAAM,QAAQ,QAAQ,IAAI,QAAQ,MAAM,QAAQ;AAGhD,WAAO,OAAO,UAAU,cAAc,SAAS,KAAK,OAAO,IAAI,CAAC,IAC5D,wBAAwB,KAAK,IAC7B;AAAA,EACN;AACF,CAAC;AAGH,MAAM,aAAa,iBAAiB;","names":[]}
@@ -1,8 +1,8 @@
1
- import { LocalesValues, type Locales } from '@intlayer/config/client';
1
+ import { type Locales } from '@intlayer/config/client';
2
2
  /**
3
3
  * Detects the locale from the request headers
4
4
  *
5
5
  * Headers are provided by the browser and can be used to determine the user's preferred language
6
6
  */
7
- export declare const localeDetector: (headers: Record<string, string | undefined>, locales?: Locales[], defaultLocale?: Locales) => LocalesValues;
7
+ export declare const localeDetector: (headers: Record<string, string | undefined>, locales?: Locales[], defaultLocale?: Locales) => Locales;
8
8
  //# sourceMappingURL=localeDetector.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"localeDetector.d.ts","sourceRoot":"","sources":["../../../src/localization/localeDetector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,KAAK,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAItE;;;;GAIG;AACH,eAAO,MAAM,cAAc,GACzB,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,EAC3C,UAAU,OAAO,EAAE,EACnB,gBAAgB,OAAO,KACtB,aAIF,CAAC"}
1
+ {"version":3,"file":"localeDetector.d.ts","sourceRoot":"","sources":["../../../src/localization/localeDetector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAIvD;;;;GAIG;AACH,eAAO,MAAM,cAAc,GACzB,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,EAC3C,UAAU,OAAO,EAAE,EACnB,gBAAgB,OAAO,KACtB,OAIF,CAAC"}
@@ -1,7 +1,7 @@
1
- import type { LocalesValues } from '@intlayer/config/client';
1
+ import type { Locales, LocalesValues } from '@intlayer/config/client';
2
2
  /**
3
3
  * Resolves the most specific locale from a user-provided list,
4
4
  * or falls back to the default locale if no match is found.
5
5
  */
6
- export declare const localeResolver: (selectedLocale: LocalesValues | LocalesValues[], locales?: LocalesValues[], defaultLocale?: LocalesValues) => LocalesValues;
6
+ export declare const localeResolver: (selectedLocale: LocalesValues | LocalesValues[], locales?: LocalesValues[], defaultLocale?: LocalesValues) => Locales;
7
7
  //# sourceMappingURL=localeResolver.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"localeResolver.d.ts","sourceRoot":"","sources":["../../../src/localization/localeResolver.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAE7D;;;GAGG;AACH,eAAO,MAAM,cAAc,GACzB,gBAAgB,aAAa,GAAG,aAAa,EAAE,EAC/C,UAAS,aAAa,EAA+C,EACrE,gBAAe,aACC,KACf,aAqCF,CAAC"}
1
+ {"version":3,"file":"localeResolver.d.ts","sourceRoot":"","sources":["../../../src/localization/localeResolver.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAEtE;;;GAGG;AACH,eAAO,MAAM,cAAc,GACzB,gBAAgB,aAAa,GAAG,aAAa,EAAE,EAC/C,UAAS,aAAa,EAA+C,EACrE,gBAAe,aACC,KACf,OAqCF,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"intl.d.ts","sourceRoot":"","sources":["../../../src/utils/intl.ts"],"names":[],"mappings":"AAwBA,OAAO,EAAW,KAAK,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAKtE,KAAK,gBAAgB,GAAG;KACrB,CAAC,IAAI,MAAM,OAAO,IAAI,IAAI,CAAC,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,KAAK,GAAG,IAAI,EAAE,GAAG,KAAK,GAAG,GACzE,CAAC,GACD,KAAK,GAAG,CAAC,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC;CAC7B,CAAC;AAGF,KAAK,8BAA8B,CAAC,CAAC,IAAI,CAAC,SAAS,KACjD,OAAO,EAAE,GAAG,EACZ,OAAO,CAAC,EAAE,MAAM,OAAO,KACpB,MAAM,QAAQ,GACf,KAAK,OAAO,CAAC,EAAE,aAAa,EAAE,OAAO,CAAC,EAAE,OAAO,KAAK,QAAQ,GAC5D,CAAC,SAAS,KAAK,OAAO,EAAE,GAAG,KAAK,MAAM,QAAQ,GAC5C,KAAK,OAAO,CAAC,EAAE,aAAa,KAAK,QAAQ,GACzC,CAAC,CAAC;AAGR,KAAK,WAAW,GAAG;KAChB,CAAC,IAAI,MAAM,OAAO,IAAI,GAAG,CAAC,SAAS,MAAM,gBAAgB,GACtD,8BAA8B,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,GAChD,CAAC,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC;CACrB,CAAC;AAgDF,eAAO,MAAM,gBAAgB,QAAO,WAUN,CAAC;AAG/B,QAAA,MAAM,UAAU,aAAqB,CAAC;AAkBtC,OAAO,EAAE,UAAU,IAAI,IAAI,EAAE,CAAC"}
1
+ {"version":3,"file":"intl.d.ts","sourceRoot":"","sources":["../../../src/utils/intl.ts"],"names":[],"mappings":"AAwBA,OAAO,EAAW,KAAK,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAKtE,KAAK,gBAAgB,GAAG;KACrB,CAAC,IAAI,MAAM,OAAO,IAAI,IAAI,CAAC,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,KAAK,GAAG,IAAI,EAAE,GAAG,KAAK,GAAG,GACzE,CAAC,GACD,KAAK,GAAG,CAAC,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC;CAC7B,CAAC;AAGF,KAAK,8BAA8B,CAAC,CAAC,IAAI,CAAC,SAAS,KACjD,OAAO,EAAE,GAAG,EACZ,OAAO,CAAC,EAAE,MAAM,OAAO,KACpB,MAAM,QAAQ,GACf,KAAK,OAAO,CAAC,EAAE,aAAa,EAAE,OAAO,CAAC,EAAE,OAAO,KAAK,QAAQ,GAC5D,CAAC,SAAS,KAAK,OAAO,EAAE,GAAG,KAAK,MAAM,QAAQ,GAC5C,KAAK,OAAO,CAAC,EAAE,aAAa,KAAK,QAAQ,GACzC,CAAC,CAAC;AAGR,KAAK,WAAW,GAAG;KAChB,CAAC,IAAI,MAAM,OAAO,IAAI,GAAG,CAAC,SAAS,MAAM,gBAAgB,GACtD,8BAA8B,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,GAChD,CAAC,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC;CACrB,CAAC;AAiEF,eAAO,MAAM,gBAAgB,QAAO,WAUN,CAAC;AAG/B,QAAA,MAAM,UAAU,aAAqB,CAAC;AAkBtC,OAAO,EAAE,UAAU,IAAI,IAAI,EAAE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intlayer/core",
3
- "version": "6.1.5",
3
+ "version": "6.1.6-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": [
@@ -156,10 +156,10 @@
156
156
  ],
157
157
  "dependencies": {
158
158
  "negotiator": "^1.0.0",
159
- "@intlayer/api": "6.1.5",
160
- "@intlayer/config": "6.1.5",
161
- "@intlayer/dictionaries-entry": "6.1.5",
162
- "@intlayer/unmerged-dictionaries-entry": "6.1.5"
159
+ "@intlayer/dictionaries-entry": "6.1.6-canary.0",
160
+ "@intlayer/config": "6.1.6-canary.0",
161
+ "@intlayer/api": "6.1.6-canary.0",
162
+ "@intlayer/unmerged-dictionaries-entry": "6.1.6-canary.0"
163
163
  },
164
164
  "devDependencies": {
165
165
  "@types/negotiator": "^0.6.3",
@@ -173,17 +173,17 @@
173
173
  "tsup": "^8.5.0",
174
174
  "typescript": "^5.9.2",
175
175
  "vitest": "^3.2.4",
176
- "@utils/ts-config": "1.0.4",
177
176
  "@utils/eslint-config": "1.0.4",
178
- "@utils/ts-config-types": "1.0.4",
179
- "@utils/tsup-config": "1.0.4"
177
+ "@utils/tsup-config": "1.0.4",
178
+ "@utils/ts-config": "1.0.4",
179
+ "@utils/ts-config-types": "1.0.4"
180
180
  },
181
181
  "peerDependencies": {
182
- "@intlayer/dictionaries-entry": "6.1.5",
183
- "@intlayer/config": "6.1.5",
184
- "@intlayer/api": "6.1.5",
185
- "@intlayer/unmerged-dictionaries-entry": "6.1.5",
186
- "intlayer": "6.1.5"
182
+ "@intlayer/api": "6.1.6-canary.0",
183
+ "@intlayer/config": "6.1.6-canary.0",
184
+ "@intlayer/dictionaries-entry": "6.1.6-canary.0",
185
+ "@intlayer/unmerged-dictionaries-entry": "6.1.6-canary.0",
186
+ "intlayer": "6.1.6-canary.0"
187
187
  },
188
188
  "peerDependenciesMeta": {
189
189
  "intlayer": {