@intlayer/use-intl 9.0.0-canary.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. package/README.md +330 -0
  2. package/dist/cjs/_virtual/_rolldown/runtime.cjs +29 -0
  3. package/dist/cjs/core/createFormatter.cjs +23 -0
  4. package/dist/cjs/core/createFormatter.cjs.map +1 -0
  5. package/dist/cjs/core/createTranslator.cjs +30 -0
  6. package/dist/cjs/core/createTranslator.cjs.map +1 -0
  7. package/dist/cjs/core/errors.cjs +42 -0
  8. package/dist/cjs/core/errors.cjs.map +1 -0
  9. package/dist/cjs/core/hasLocale.cjs +23 -0
  10. package/dist/cjs/core/hasLocale.cjs.map +1 -0
  11. package/dist/cjs/core/index.cjs +13 -0
  12. package/dist/cjs/core/initializeConfig.cjs +25 -0
  13. package/dist/cjs/core/initializeConfig.cjs.map +1 -0
  14. package/dist/cjs/core/types.cjs +0 -0
  15. package/dist/cjs/index.cjs +30 -0
  16. package/dist/cjs/plugin/index.cjs +80 -0
  17. package/dist/cjs/plugin/index.cjs.map +1 -0
  18. package/dist/cjs/react/IntlProvider.cjs +30 -0
  19. package/dist/cjs/react/IntlProvider.cjs.map +1 -0
  20. package/dist/cjs/react/helpers.cjs +49 -0
  21. package/dist/cjs/react/helpers.cjs.map +1 -0
  22. package/dist/cjs/react/index.cjs +27 -0
  23. package/dist/cjs/react/index.cjs.map +1 -0
  24. package/dist/cjs/react/useLocale.cjs +20 -0
  25. package/dist/cjs/react/useLocale.cjs.map +1 -0
  26. package/dist/cjs/react/useTranslations.cjs +39 -0
  27. package/dist/cjs/react/useTranslations.cjs.map +1 -0
  28. package/dist/cjs/shared/intlFormatter.cjs +63 -0
  29. package/dist/cjs/shared/intlFormatter.cjs.map +1 -0
  30. package/dist/cjs/shared/namespaceTranslator.cjs +122 -0
  31. package/dist/cjs/shared/namespaceTranslator.cjs.map +1 -0
  32. package/dist/cjs/shared/translateFunctionTypes.cjs +0 -0
  33. package/dist/cjs/useDictionary.cjs +37 -0
  34. package/dist/cjs/useDictionary.cjs.map +1 -0
  35. package/dist/cjs/useDictionaryDynamic.cjs +31 -0
  36. package/dist/cjs/useDictionaryDynamic.cjs.map +1 -0
  37. package/dist/esm/core/createFormatter.mjs +22 -0
  38. package/dist/esm/core/createFormatter.mjs.map +1 -0
  39. package/dist/esm/core/createTranslator.mjs +28 -0
  40. package/dist/esm/core/createTranslator.mjs.map +1 -0
  41. package/dist/esm/core/errors.mjs +39 -0
  42. package/dist/esm/core/errors.mjs.map +1 -0
  43. package/dist/esm/core/hasLocale.mjs +21 -0
  44. package/dist/esm/core/hasLocale.mjs.map +1 -0
  45. package/dist/esm/core/index.mjs +7 -0
  46. package/dist/esm/core/initializeConfig.mjs +23 -0
  47. package/dist/esm/core/initializeConfig.mjs.map +1 -0
  48. package/dist/esm/core/types.mjs +0 -0
  49. package/dist/esm/index.mjs +14 -0
  50. package/dist/esm/plugin/index.mjs +76 -0
  51. package/dist/esm/plugin/index.mjs.map +1 -0
  52. package/dist/esm/react/IntlProvider.mjs +28 -0
  53. package/dist/esm/react/IntlProvider.mjs.map +1 -0
  54. package/dist/esm/react/helpers.mjs +44 -0
  55. package/dist/esm/react/helpers.mjs.map +1 -0
  56. package/dist/esm/react/index.mjs +17 -0
  57. package/dist/esm/react/index.mjs.map +1 -0
  58. package/dist/esm/react/useLocale.mjs +18 -0
  59. package/dist/esm/react/useLocale.mjs.map +1 -0
  60. package/dist/esm/react/useTranslations.mjs +37 -0
  61. package/dist/esm/react/useTranslations.mjs.map +1 -0
  62. package/dist/esm/shared/intlFormatter.mjs +61 -0
  63. package/dist/esm/shared/intlFormatter.mjs.map +1 -0
  64. package/dist/esm/shared/namespaceTranslator.mjs +119 -0
  65. package/dist/esm/shared/namespaceTranslator.mjs.map +1 -0
  66. package/dist/esm/shared/translateFunctionTypes.mjs +0 -0
  67. package/dist/esm/useDictionary.mjs +35 -0
  68. package/dist/esm/useDictionary.mjs.map +1 -0
  69. package/dist/esm/useDictionaryDynamic.mjs +29 -0
  70. package/dist/esm/useDictionaryDynamic.mjs.map +1 -0
  71. package/dist/types/core/createFormatter.d.ts +21 -0
  72. package/dist/types/core/createFormatter.d.ts.map +1 -0
  73. package/dist/types/core/createTranslator.d.ts +56 -0
  74. package/dist/types/core/createTranslator.d.ts.map +1 -0
  75. package/dist/types/core/errors.d.ts +31 -0
  76. package/dist/types/core/errors.d.ts.map +1 -0
  77. package/dist/types/core/hasLocale.d.ts +18 -0
  78. package/dist/types/core/hasLocale.d.ts.map +1 -0
  79. package/dist/types/core/index.d.ts +7 -0
  80. package/dist/types/core/initializeConfig.d.ts +14 -0
  81. package/dist/types/core/initializeConfig.d.ts.map +1 -0
  82. package/dist/types/core/types.d.ts +2 -0
  83. package/dist/types/index.d.ts +14 -0
  84. package/dist/types/plugin/index.d.ts +22 -0
  85. package/dist/types/plugin/index.d.ts.map +1 -0
  86. package/dist/types/react/IntlProvider.d.ts +29 -0
  87. package/dist/types/react/IntlProvider.d.ts.map +1 -0
  88. package/dist/types/react/helpers.d.ts +31 -0
  89. package/dist/types/react/helpers.d.ts.map +1 -0
  90. package/dist/types/react/index.d.ts +16 -0
  91. package/dist/types/react/index.d.ts.map +1 -0
  92. package/dist/types/react/useLocale.d.ts +12 -0
  93. package/dist/types/react/useLocale.d.ts.map +1 -0
  94. package/dist/types/react/useTranslations.d.ts +44 -0
  95. package/dist/types/react/useTranslations.d.ts.map +1 -0
  96. package/dist/types/shared/intlFormatter.d.ts +19 -0
  97. package/dist/types/shared/intlFormatter.d.ts.map +1 -0
  98. package/dist/types/shared/namespaceTranslator.d.ts +51 -0
  99. package/dist/types/shared/namespaceTranslator.d.ts.map +1 -0
  100. package/dist/types/shared/translateFunctionTypes.d.ts +34 -0
  101. package/dist/types/shared/translateFunctionTypes.d.ts.map +1 -0
  102. package/dist/types/useDictionary.d.ts +23 -0
  103. package/dist/types/useDictionary.d.ts.map +1 -0
  104. package/dist/types/useDictionaryDynamic.d.ts +18 -0
  105. package/dist/types/useDictionaryDynamic.d.ts.map +1 -0
  106. package/package.json +131 -0
@@ -0,0 +1,80 @@
1
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
2
+ const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
3
+ let _intlayer_config_colors = require("@intlayer/config/colors");
4
+ _intlayer_config_colors = require_runtime.__toESM(_intlayer_config_colors);
5
+ let _intlayer_config_logger = require("@intlayer/config/logger");
6
+ let node_path = require("node:path");
7
+ let _intlayer_chokidar_utils = require("@intlayer/chokidar/utils");
8
+ let _intlayer_config_node = require("@intlayer/config/node");
9
+ let vite_intlayer = require("vite-intlayer");
10
+
11
+ //#region src/plugin/index.ts
12
+ /**
13
+ * Caller configurations for use-intl's translation entry points.
14
+ *
15
+ * Tells the intlayer field-usage analyser how to extract the dictionary key
16
+ * (namespace) and consumed fields from `useTranslations` / `createTranslator`
17
+ * call sites, enabling accurate dictionary pruning for projects using
18
+ * `@intlayer/use-intl`.
19
+ */
20
+ const USE_INTL_COMPAT_CALLERS = [{
21
+ callerName: "useTranslations",
22
+ importSources: [
23
+ "use-intl",
24
+ "use-intl/react",
25
+ "@intlayer/use-intl"
26
+ ],
27
+ namespace: {
28
+ from: "argument",
29
+ index: 0
30
+ },
31
+ translationFunction: "return-value"
32
+ }, {
33
+ callerName: "createTranslator",
34
+ importSources: [
35
+ "use-intl",
36
+ "use-intl/core",
37
+ "@intlayer/use-intl"
38
+ ],
39
+ namespace: {
40
+ from: "option",
41
+ argumentIndex: 0,
42
+ property: "namespace"
43
+ },
44
+ translationFunction: "return-value"
45
+ }];
46
+ /**
47
+ * A Vite plugin for use-intl compat that wraps vite-intlayer and configures
48
+ * resolve aliases so `use-intl` imports are served by `@intlayer/use-intl`.
49
+ *
50
+ * @example
51
+ * ```ts
52
+ * // vite.config.ts
53
+ * import useIntlVitePlugin from '@intlayer/use-intl/plugin';
54
+ *
55
+ * export default defineConfig({
56
+ * plugins: [useIntlVitePlugin()],
57
+ * });
58
+ * ```
59
+ */
60
+ const useIntlVitePlugin = (options) => {
61
+ const intlayerConfig = (0, _intlayer_config_node.getConfiguration)();
62
+ const appLogger = (0, _intlayer_config_logger.getAppLogger)(intlayerConfig);
63
+ (0, _intlayer_chokidar_utils.runOnce)((0, node_path.join)(intlayerConfig.system.baseDir, ".intlayer", "cache", "intlayer-issues-invitation.lock"), () => {
64
+ appLogger([(0, _intlayer_config_logger.colorize)("Please report any issues you met on GitHub:", _intlayer_config_colors.GREY), (0, _intlayer_config_logger.colorize)("https://github.com/aymericzip/intlayer/issues", _intlayer_config_colors.GREY_LIGHT)]);
65
+ }, { cacheTimeoutMs: 1e3 * 60 * 60 });
66
+ const basePlugins = (0, vite_intlayer.intlayer)({
67
+ ...options,
68
+ compatCallers: [...options?.compatCallers ?? [], ...USE_INTL_COMPAT_CALLERS]
69
+ });
70
+ const compatPlugin = {
71
+ name: "vite-use-intl-compat-plugin",
72
+ config: () => ({ resolve: { alias: { "use-intl": "@intlayer/use-intl" } } })
73
+ };
74
+ return [...Array.isArray(basePlugins) ? basePlugins : [basePlugins], compatPlugin];
75
+ };
76
+
77
+ //#endregion
78
+ exports.default = useIntlVitePlugin;
79
+ exports.useIntlVitePlugin = useIntlVitePlugin;
80
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","names":["ANSIColors"],"sources":["../../../src/plugin/index.ts"],"sourcesContent":["import { join } from 'node:path';\nimport { runOnce } from '@intlayer/chokidar/utils';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport { getConfiguration } from '@intlayer/config/node';\nimport type { PluginOption } from 'vite';\nimport { type CompatCallerConfig, intlayer } from 'vite-intlayer';\n\n/**\n * Caller configurations for use-intl's translation entry points.\n *\n * Tells the intlayer field-usage analyser how to extract the dictionary key\n * (namespace) and consumed fields from `useTranslations` / `createTranslator`\n * call sites, enabling accurate dictionary pruning for projects using\n * `@intlayer/use-intl`.\n */\nconst USE_INTL_COMPAT_CALLERS: CompatCallerConfig[] = [\n {\n callerName: 'useTranslations',\n importSources: ['use-intl', 'use-intl/react', '@intlayer/use-intl'],\n namespace: { from: 'argument', index: 0 },\n translationFunction: 'return-value',\n },\n {\n callerName: 'createTranslator',\n importSources: ['use-intl', 'use-intl/core', '@intlayer/use-intl'],\n namespace: { from: 'option', argumentIndex: 0, property: 'namespace' },\n translationFunction: 'return-value',\n },\n];\n\n/**\n * A Vite plugin for use-intl compat that wraps vite-intlayer and configures\n * resolve aliases so `use-intl` imports are served by `@intlayer/use-intl`.\n *\n * @example\n * ```ts\n * // vite.config.ts\n * import useIntlVitePlugin from '@intlayer/use-intl/plugin';\n *\n * export default defineConfig({\n * plugins: [useIntlVitePlugin()],\n * });\n * ```\n */\nexport const useIntlVitePlugin = (\n options?: Parameters<typeof intlayer>[0]\n): PluginOption[] => {\n const intlayerConfig = getConfiguration();\n const appLogger = getAppLogger(intlayerConfig);\n\n runOnce(\n join(\n intlayerConfig.system.baseDir,\n '.intlayer',\n 'cache',\n 'intlayer-issues-invitation.lock'\n ),\n () => {\n appLogger([\n colorize(\n 'Please report any issues you met on GitHub:',\n ANSIColors.GREY\n ),\n colorize(\n 'https://github.com/aymericzip/intlayer/issues',\n ANSIColors.GREY_LIGHT\n ),\n ]);\n },\n {\n cacheTimeoutMs: 1000 * 60 * 60, // 1 hour\n }\n );\n\n const basePlugins = intlayer({\n ...options,\n compatCallers: [\n ...(options?.compatCallers ?? []),\n ...USE_INTL_COMPAT_CALLERS,\n ],\n });\n\n const compatPlugin: PluginOption = {\n name: 'vite-use-intl-compat-plugin',\n config: () => ({\n resolve: {\n alias: {\n 'use-intl': '@intlayer/use-intl',\n },\n },\n }),\n };\n\n return [\n ...(Array.isArray(basePlugins) ? basePlugins : [basePlugins]),\n compatPlugin,\n ];\n};\n\nexport default useIntlVitePlugin;\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAgBA,MAAM,0BAAgD,CACpD;CACE,YAAY;CACZ,eAAe;EAAC;EAAY;EAAkB;EAAqB;CACnE,WAAW;EAAE,MAAM;EAAY,OAAO;EAAG;CACzC,qBAAqB;CACtB,EACD;CACE,YAAY;CACZ,eAAe;EAAC;EAAY;EAAiB;EAAqB;CAClE,WAAW;EAAE,MAAM;EAAU,eAAe;EAAG,UAAU;EAAa;CACtE,qBAAqB;CACtB,CACF;;;;;;;;;;;;;;;AAgBD,MAAa,qBACX,YACmB;CACnB,MAAM,8DAAmC;CACzC,MAAM,sDAAyB,eAAe;AAE9C,2DAEI,eAAe,OAAO,SACtB,aACA,SACA,kCACD,QACK;AACJ,YAAU,uCAEN,+CACAA,wBAAW,KACZ,wCAEC,iDACAA,wBAAW,WACZ,CACF,CAAC;IAEJ,EACE,gBAAgB,MAAO,KAAK,IAC7B,CACF;CAED,MAAM,0CAAuB;EAC3B,GAAG;EACH,eAAe,CACb,GAAI,SAAS,iBAAiB,EAAE,EAChC,GAAG,wBACJ;EACF,CAAC;CAEF,MAAM,eAA6B;EACjC,MAAM;EACN,eAAe,EACb,SAAS,EACP,OAAO,EACL,YAAY,sBACb,EACF,EACF;EACF;AAED,QAAO,CACL,GAAI,MAAM,QAAQ,YAAY,GAAG,cAAc,CAAC,YAAY,EAC5D,aACD"}
@@ -0,0 +1,30 @@
1
+ 'use client';
2
+
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+ const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
5
+ let react_intlayer = require("react-intlayer");
6
+ let react_jsx_runtime = require("react/jsx-runtime");
7
+ let _intlayer_config_built = require("@intlayer/config/built");
8
+ let _intlayer_config_colors = require("@intlayer/config/colors");
9
+ let _intlayer_config_logger = require("@intlayer/config/logger");
10
+
11
+ //#region src/react/IntlProvider.tsx
12
+ /**
13
+ * Drop-in for use-intl's `IntlProvider`.
14
+ *
15
+ * Wraps Intlayer's `IntlayerProvider`, seeding the client locale from the
16
+ * `locale` prop. `messages`, `formats`, `now`, `timeZone`, `onError`, and
17
+ * `getMessageFallback` are accepted for API compatibility but have no effect —
18
+ * Intlayer uses its own compiled dictionaries.
19
+ */
20
+ const IntlProvider = ({ locale, children, messages: _messages, formats: _formats, now: _now, timeZone: _timeZone, onError: _onError, getMessageFallback: _getMessageFallback }) => {
21
+ if (process.env.NODE_ENV === "development" && typeof _messages !== "undefined") (0, _intlayer_config_logger.getAppLogger)({ log: _intlayer_config_built.log })(`${(0, _intlayer_config_logger.colorize)("IntlProvider", _intlayer_config_colors.CYAN)} do not pass the messages prop with intlayer. Messages are loaded automatically under the hood for bundle optimization reason`);
22
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_intlayer.IntlayerProvider, {
23
+ locale,
24
+ children
25
+ }, String(locale));
26
+ };
27
+
28
+ //#endregion
29
+ exports.IntlProvider = IntlProvider;
30
+ //# sourceMappingURL=IntlProvider.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IntlProvider.cjs","names":["CYAN","IntlayerProvider"],"sources":["../../../src/react/IntlProvider.tsx"],"sourcesContent":["'use client';\n\nimport { log } from '@intlayer/config/built';\nimport { CYAN } from '@intlayer/config/colors';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { IntlayerProvider } from 'react-intlayer';\nimport type { ComponentProps } from 'react';\nimport type { IntlProvider as _IntlProvider } from 'use-intl';\n\n/**\n * Drop-in for use-intl's `IntlProvider`.\n *\n * Wraps Intlayer's `IntlayerProvider`, seeding the client locale from the\n * `locale` prop. `messages`, `formats`, `now`, `timeZone`, `onError`, and\n * `getMessageFallback` are accepted for API compatibility but have no effect —\n * Intlayer uses its own compiled dictionaries.\n */\nexport const IntlProvider: typeof _IntlProvider = ({\n locale,\n children,\n messages: _messages,\n formats: _formats,\n now: _now,\n timeZone: _timeZone,\n onError: _onError,\n getMessageFallback: _getMessageFallback,\n}) => {\n if (\n process.env.NODE_ENV === 'development' &&\n typeof _messages !== 'undefined'\n ) {\n const appLogger = getAppLogger({ log });\n appLogger(\n `${colorize('IntlProvider', CYAN)} do not pass the messages prop with intlayer. Messages are loaded automatically under the hood for bundle optimization reason`\n );\n }\n\n // `key={locale}` re-seeds the client locale context when the locale changes,\n // so consumers re-render in the new language.\n return (\n <IntlayerProvider\n key={String(locale)}\n locale={locale as LocalesValues}\n >\n {children}\n </IntlayerProvider>\n );\n};\n\n/**\n * Props accepted by {@link IntlProvider}. `messages` is deprecated — Intlayer\n * loads content from compiled dictionaries automatically.\n */\nexport type IntlProviderProps = Omit<\n ComponentProps<typeof _IntlProvider>,\n 'messages' | 'locale'\n> & {\n /**\n * @deprecated has no use case with intlayer. Messages are loaded\n * automatically under the hood for bundle optimization reason.\n */\n messages?: never;\n /** The active locale. */\n locale: LocalesValues;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAkBA,MAAa,gBAAsC,EACjD,QACA,UACA,UAAU,WACV,SAAS,UACT,KAAK,MACL,UAAU,WACV,SAAS,UACT,oBAAoB,0BAChB;AACJ,KACE,QAAQ,IAAI,aAAa,iBACzB,OAAO,cAAc,YAGrB,2CAD+B,EAAE,iCAAK,CAC7B,CACP,yCAAY,gBAAgBA,6BAAK,CAAC,+HACnC;AAKH,QACE,2CAACC,iCAAD;EAEU;EAEP;EACgB,EAJZ,OAAO,OAAO,CAIF"}
@@ -0,0 +1,49 @@
1
+ 'use client';
2
+
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+ const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
5
+ const require_shared_intlFormatter = require('../shared/intlFormatter.cjs');
6
+ let react_intlayer = require("react-intlayer");
7
+ let _intlayer_config_built = require("@intlayer/config/built");
8
+ let _intlayer_config_colors = require("@intlayer/config/colors");
9
+ let _intlayer_config_logger = require("@intlayer/config/logger");
10
+
11
+ //#region src/react/helpers.ts
12
+ /**
13
+ * Drop-in for use-intl's `useNow`.
14
+ * Returns the current `Date`. The `updateInterval` option is ignored.
15
+ */
16
+ const useNow = () => /* @__PURE__ */ new Date();
17
+ /**
18
+ * Drop-in for use-intl's `useTimeZone`.
19
+ * Returns the system time zone resolved from `Intl.DateTimeFormat`.
20
+ */
21
+ const useTimeZone = () => Intl.DateTimeFormat().resolvedOptions().timeZone;
22
+ /**
23
+ * Drop-in for use-intl's `useMessages`.
24
+ *
25
+ * @deprecated useMessages has no use case with intlayer.
26
+ * Messages are loaded automatically under the hood.
27
+ * @returns An empty object.
28
+ */
29
+ const useMessages = () => {
30
+ if (process.env.NODE_ENV === "development") (0, _intlayer_config_logger.getAppLogger)({ log: _intlayer_config_built.log })(`${(0, _intlayer_config_logger.colorize)("useMessages", _intlayer_config_colors.CYAN)} has no use case with intlayer. Messages are loaded automatically under the hood for bundle optimization reason`);
31
+ return {};
32
+ };
33
+ /**
34
+ * Drop-in for use-intl's `useFormatter`.
35
+ * Returns locale-aware formatters backed by the native `Intl.*` APIs:
36
+ * `dateTime`, `number`, `dateTimeRange`, `relativeTime`, `list`, and
37
+ * `displayName`.
38
+ */
39
+ const useFormatter = () => {
40
+ const { locale } = (0, react_intlayer.useLocale)();
41
+ return require_shared_intlFormatter.buildIntlFormatter(locale ?? "en");
42
+ };
43
+
44
+ //#endregion
45
+ exports.useFormatter = useFormatter;
46
+ exports.useMessages = useMessages;
47
+ exports.useNow = useNow;
48
+ exports.useTimeZone = useTimeZone;
49
+ //# sourceMappingURL=helpers.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.cjs","names":["CYAN","buildIntlFormatter"],"sources":["../../../src/react/helpers.ts"],"sourcesContent":["'use client';\n\nimport { log } from '@intlayer/config/built';\nimport { CYAN } from '@intlayer/config/colors';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport { useLocale as useLocaleIntlayer } from 'react-intlayer';\nimport type {\n useFormatter as _useFormatter,\n useMessages as _useMessages,\n useNow as _useNow,\n useTimeZone as _useTimeZone,\n} from 'use-intl';\nimport { buildIntlFormatter } from '../shared/intlFormatter';\n\n/**\n * Drop-in for use-intl's `useNow`.\n * Returns the current `Date`. The `updateInterval` option is ignored.\n */\nexport const useNow: typeof _useNow = () => new Date();\n\n/**\n * Drop-in for use-intl's `useTimeZone`.\n * Returns the system time zone resolved from `Intl.DateTimeFormat`.\n */\nexport const useTimeZone: typeof _useTimeZone = () =>\n Intl.DateTimeFormat().resolvedOptions().timeZone;\n\n/**\n * Drop-in for use-intl's `useMessages`.\n *\n * @deprecated useMessages has no use case with intlayer.\n * Messages are loaded automatically under the hood.\n * @returns An empty object.\n */\nexport const useMessages: typeof _useMessages = () => {\n if (process.env.NODE_ENV === 'development') {\n const appLogger = getAppLogger({ log });\n appLogger(\n `${colorize('useMessages', CYAN)} has no use case with intlayer. Messages are loaded automatically under the hood for bundle optimization reason`\n );\n }\n\n return {} as ReturnType<typeof _useMessages>;\n};\n\n/**\n * Drop-in for use-intl's `useFormatter`.\n * Returns locale-aware formatters backed by the native `Intl.*` APIs:\n * `dateTime`, `number`, `dateTimeRange`, `relativeTime`, `list`, and\n * `displayName`.\n */\nexport const useFormatter: typeof _useFormatter = () => {\n const { locale } = useLocaleIntlayer();\n return buildIntlFormatter((locale as string) ?? 'en');\n};\n"],"mappings":";;;;;;;;;;;;;;;AAkBA,MAAa,+BAA+B,IAAI,MAAM;;;;;AAMtD,MAAa,oBACX,KAAK,gBAAgB,CAAC,iBAAiB,CAAC;;;;;;;;AAS1C,MAAa,oBAAyC;AACpD,KAAI,QAAQ,IAAI,aAAa,cAE3B,2CAD+B,EAAE,iCAAK,CAC7B,CACP,yCAAY,eAAeA,6BAAK,CAAC,iHAClC;AAGH,QAAO,EAAE;;;;;;;;AASX,MAAa,qBAA2C;CACtD,MAAM,EAAE,0CAA8B;AACtC,QAAOC,gDAAoB,UAAqB,KAAK"}
@@ -0,0 +1,27 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_useDictionaryDynamic = require('../useDictionaryDynamic.cjs');
3
+ const require_react_IntlProvider = require('./IntlProvider.cjs');
4
+ const require_react_helpers = require('./helpers.cjs');
5
+ const require_react_useLocale = require('./useLocale.cjs');
6
+ const require_react_useTranslations = require('./useTranslations.cjs');
7
+ const require_useDictionary = require('../useDictionary.cjs');
8
+
9
+ //#region src/react/index.ts
10
+ /**
11
+ * @internal Private use-intl export, kept so aliased `_useExtracted` imports
12
+ * resolve. Not part of the supported public surface.
13
+ */
14
+ const _useExtracted = () => ({});
15
+
16
+ //#endregion
17
+ exports.IntlProvider = require_react_IntlProvider.IntlProvider;
18
+ exports._useExtracted = _useExtracted;
19
+ exports.useDictionary = require_useDictionary.useDictionary;
20
+ exports.useDictionaryDynamic = require_useDictionaryDynamic.useDictionaryDynamic;
21
+ exports.useFormatter = require_react_helpers.useFormatter;
22
+ exports.useLocale = require_react_useLocale.useLocale;
23
+ exports.useMessages = require_react_helpers.useMessages;
24
+ exports.useNow = require_react_helpers.useNow;
25
+ exports.useTimeZone = require_react_helpers.useTimeZone;
26
+ exports.useTranslations = require_react_useTranslations.useTranslations;
27
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","names":[],"sources":["../../../src/react/index.ts"],"sourcesContent":["export { IntlProvider, type IntlProviderProps } from './IntlProvider';\nexport { useFormatter, useMessages, useNow, useTimeZone } from './helpers';\nexport { useLocale } from './useLocale';\nexport { useTranslations } from './useTranslations';\nexport { useDictionary } from '../useDictionary';\nexport { useDictionaryDynamic } from '../useDictionaryDynamic';\n\n/**\n * @internal Private use-intl export, kept so aliased `_useExtracted` imports\n * resolve. Not part of the supported public surface.\n */\nexport const _useExtracted = (): Record<string, never> => ({});\n"],"mappings":";;;;;;;;;;;;;AAWA,MAAa,uBAA8C,EAAE"}
@@ -0,0 +1,20 @@
1
+ 'use client';
2
+
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+ const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
5
+ let react_intlayer = require("react-intlayer");
6
+
7
+ //#region src/react/useLocale.ts
8
+ /**
9
+ * Drop-in for use-intl's `useLocale`.
10
+ *
11
+ * Returns the active locale string from Intlayer's client context.
12
+ */
13
+ const useLocale = () => {
14
+ const { locale } = (0, react_intlayer.useLocale)();
15
+ return locale;
16
+ };
17
+
18
+ //#endregion
19
+ exports.useLocale = useLocale;
20
+ //# sourceMappingURL=useLocale.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLocale.cjs","names":[],"sources":["../../../src/react/useLocale.ts"],"sourcesContent":["'use client';\n\nimport { useLocale as useLocaleIntlayer } from 'react-intlayer';\nimport type { useLocale as _useLocale } from 'use-intl';\n\n/**\n * Drop-in for use-intl's `useLocale`.\n *\n * Returns the active locale string from Intlayer's client context.\n */\nexport const useLocale: typeof _useLocale = () => {\n const { locale } = useLocaleIntlayer();\n return locale as ReturnType<typeof _useLocale>;\n};\n"],"mappings":";;;;;;;;;;;;AAUA,MAAa,kBAAqC;CAChD,MAAM,EAAE,0CAA8B;AACtC,QAAO"}
@@ -0,0 +1,39 @@
1
+ 'use client';
2
+
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+ const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
5
+ const require_shared_namespaceTranslator = require('../shared/namespaceTranslator.cjs');
6
+ let react_intlayer = require("react-intlayer");
7
+ let react = require("react");
8
+
9
+ //#region src/react/useTranslations.ts
10
+ /**
11
+ * Drop-in for use-intl's `useTranslations`.
12
+ *
13
+ * Messages support ICU MessageFormat syntax: simple arguments (`{name}`),
14
+ * plural (`{count, plural, one {…} other {…}}`, `#`), select, and formatted
15
+ * arguments (`{value, number}`). Rich text is available through `t.rich()`
16
+ * and `t.markup()`.
17
+ *
18
+ * @example
19
+ * ```tsx
20
+ * const t = useTranslations('about');
21
+ * t('counter.label'); // ✓ typed
22
+ * t('items', { count: 3 }); // ICU plural
23
+ *
24
+ * // Scoped to a nested object (use-intl idiom)
25
+ * const t = useTranslations('about.counter');
26
+ * t('label'); // resolves about → counter.label
27
+ *
28
+ * // Rich text
29
+ * t.rich('terms', { link: (chunks) => <a href="/terms">{chunks}</a> });
30
+ * ```
31
+ */
32
+ const useTranslations = ((namespace) => {
33
+ const { locale: currentLocale } = (0, react.useContext)(react_intlayer.IntlayerClientContext) ?? {};
34
+ return (0, react.useMemo)(() => require_shared_namespaceTranslator.createNamespaceTranslator(currentLocale, namespace), [currentLocale, namespace]);
35
+ });
36
+
37
+ //#endregion
38
+ exports.useTranslations = useTranslations;
39
+ //# sourceMappingURL=useTranslations.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTranslations.cjs","names":["IntlayerClientContext","createNamespaceTranslator"],"sources":["../../../src/react/useTranslations.ts"],"sourcesContent":["'use client';\n\nimport type {\n DictionaryKeys,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { IntlayerClientContext } from 'react-intlayer';\nimport { useContext, useMemo } from 'react';\nimport { createNamespaceTranslator } from '../shared/namespaceTranslator';\nimport type {\n LooseTranslateFunction,\n TranslateFunction,\n} from '../shared/translateFunctionTypes';\n\n/**\n * Overload set for {@link useTranslations}:\n *\n * 1. A bare dictionary key → fully-typed `t()` (autocompleted dot-paths).\n * 2. A nested namespace `'dictionary.sub.scope'` → `t()` accepts relative\n * `string` paths, matching use-intl's scoped-namespace behaviour.\n * 3. No namespace → root scope; the first segment of each key designates\n * the dictionary (`t('about.title')`).\n */\ntype UseTranslations = {\n <N extends DictionaryKeys>(namespace: N): TranslateFunction<N>;\n (namespace: `${string}.${string}`): LooseTranslateFunction;\n (): LooseTranslateFunction;\n};\n\n/**\n * Drop-in for use-intl's `useTranslations`.\n *\n * Messages support ICU MessageFormat syntax: simple arguments (`{name}`),\n * plural (`{count, plural, one {…} other {…}}`, `#`), select, and formatted\n * arguments (`{value, number}`). Rich text is available through `t.rich()`\n * and `t.markup()`.\n *\n * @example\n * ```tsx\n * const t = useTranslations('about');\n * t('counter.label'); // ✓ typed\n * t('items', { count: 3 }); // ICU plural\n *\n * // Scoped to a nested object (use-intl idiom)\n * const t = useTranslations('about.counter');\n * t('label'); // resolves about → counter.label\n *\n * // Rich text\n * t.rich('terms', { link: (chunks) => <a href=\"/terms\">{chunks}</a> });\n * ```\n */\nexport const useTranslations = ((namespace?: string) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext) ?? {};\n\n return useMemo(\n () => createNamespaceTranslator(currentLocale as LocalesValues, namespace),\n [currentLocale, namespace]\n );\n}) as UseTranslations;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmDA,MAAa,oBAAoB,cAAuB;CACtD,MAAM,EAAE,QAAQ,wCAA6BA,qCAAsB,IAAI,EAAE;AAEzE,iCACQC,6DAA0B,eAAgC,UAAU,EAC1E,CAAC,eAAe,UAAU,CAC3B"}
@@ -0,0 +1,63 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+
3
+ //#region src/shared/intlFormatter.ts
4
+ /** Time units orderable by their duration in seconds. */
5
+ const RELATIVE_TIME_UNITS = [
6
+ ["year", 31536e3],
7
+ ["month", 2628e3],
8
+ ["week", 604800],
9
+ ["day", 86400],
10
+ ["hour", 3600],
11
+ ["minute", 60],
12
+ ["second", 1]
13
+ ];
14
+ const toDate = (value) => value instanceof Date ? value : new Date(value);
15
+ /**
16
+ * Builds a use-intl compatible formatter backed by the native `Intl.*` APIs
17
+ * for the given locale.
18
+ *
19
+ * Shared by `useFormatter` (React hook) and `createFormatter` (non-React core).
20
+ *
21
+ * @param locale - The locale used by every `Intl.*` formatter instance.
22
+ * @returns A formatter exposing `dateTime`, `number`, `dateTimeRange`,
23
+ * `relativeTime`, `list`, and `displayName`.
24
+ */
25
+ const buildIntlFormatter = (locale) => ({
26
+ dateTime: (value, options) => new Intl.DateTimeFormat(locale, options).format(value),
27
+ number: (value, options) => new Intl.NumberFormat(locale, options).format(value),
28
+ /** Formats a date range with `Intl.DateTimeFormat#formatRange`. */
29
+ dateTimeRange: (start, end, options) => new Intl.DateTimeFormat(locale, options).formatRange(toDate(start), toDate(end)),
30
+ /**
31
+ * Formats a date relative to now (or a reference date), automatically
32
+ * selecting the largest fitting unit.
33
+ */
34
+ relativeTime: (date, nowOrOptions) => {
35
+ const options = nowOrOptions instanceof Date || typeof nowOrOptions === "number" ? { now: nowOrOptions } : nowOrOptions ?? {};
36
+ const nowDate = options.now !== void 0 ? toDate(options.now) : /* @__PURE__ */ new Date();
37
+ const diffInSeconds = (toDate(date).getTime() - nowDate.getTime()) / 1e3;
38
+ let unit = options.unit;
39
+ if (!unit) {
40
+ const absoluteDiff = Math.abs(diffInSeconds);
41
+ unit = RELATIVE_TIME_UNITS.find(([, unitSeconds]) => absoluteDiff >= unitSeconds)?.[0] ?? "second";
42
+ }
43
+ const unitSeconds = RELATIVE_TIME_UNITS.find(([unitName]) => unitName === unit)?.[1] ?? 1;
44
+ return new Intl.RelativeTimeFormat(locale, {
45
+ numeric: "auto",
46
+ style: options.style
47
+ }).format(Math.round(diffInSeconds / unitSeconds), unit);
48
+ },
49
+ /** Formats a list with `Intl.ListFormat`. */
50
+ list: (value, options) => new Intl.ListFormat(locale, options).format(value),
51
+ displayName: (value, optionsOrFormat, extraOptions) => {
52
+ const resolvedOptions = typeof optionsOrFormat === "string" ? extraOptions : optionsOrFormat;
53
+ try {
54
+ return new Intl.DisplayNames([locale], resolvedOptions ?? { type: "language" }).of(value) ?? value;
55
+ } catch {
56
+ return value;
57
+ }
58
+ }
59
+ });
60
+
61
+ //#endregion
62
+ exports.buildIntlFormatter = buildIntlFormatter;
63
+ //# sourceMappingURL=intlFormatter.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"intlFormatter.cjs","names":[],"sources":["../../../src/shared/intlFormatter.ts"],"sourcesContent":["import type { createFormatter as _createFormatter } from 'use-intl';\n\n/** The formatter object shape exposed by use-intl. */\nexport type Formatter = ReturnType<typeof _createFormatter>;\n\n/** Time units orderable by their duration in seconds. */\nconst RELATIVE_TIME_UNITS: [Intl.RelativeTimeFormatUnit, number][] = [\n ['year', 31536000],\n ['month', 2628000],\n ['week', 604800],\n ['day', 86400],\n ['hour', 3600],\n ['minute', 60],\n ['second', 1],\n];\n\nconst toDate = (value: Date | number | string): Date =>\n value instanceof Date ? value : new Date(value);\n\n/**\n * Builds a use-intl compatible formatter backed by the native `Intl.*` APIs\n * for the given locale.\n *\n * Shared by `useFormatter` (React hook) and `createFormatter` (non-React core).\n *\n * @param locale - The locale used by every `Intl.*` formatter instance.\n * @returns A formatter exposing `dateTime`, `number`, `dateTimeRange`,\n * `relativeTime`, `list`, and `displayName`.\n */\nexport const buildIntlFormatter = (locale: string): Formatter =>\n ({\n dateTime: (value: Date | number, options?: Intl.DateTimeFormatOptions) =>\n new Intl.DateTimeFormat(locale, options).format(value),\n\n number: (value: number | bigint, options?: Intl.NumberFormatOptions) =>\n new Intl.NumberFormat(locale, options).format(value),\n\n /** Formats a date range with `Intl.DateTimeFormat#formatRange`. */\n dateTimeRange: (\n start: Date | number,\n end: Date | number,\n options?: Intl.DateTimeFormatOptions\n ) =>\n new Intl.DateTimeFormat(locale, options).formatRange(\n toDate(start),\n toDate(end)\n ),\n\n /**\n * Formats a date relative to now (or a reference date), automatically\n * selecting the largest fitting unit.\n */\n relativeTime: (\n date: Date | number | string,\n nowOrOptions?:\n | Date\n | number\n | {\n now?: Date | number;\n unit?: Intl.RelativeTimeFormatUnit;\n style?: Intl.RelativeTimeFormatStyle;\n numberingSystem?: string;\n }\n ) => {\n const options =\n nowOrOptions instanceof Date || typeof nowOrOptions === 'number'\n ? { now: nowOrOptions }\n : (nowOrOptions ?? {});\n\n const nowDate =\n options.now !== undefined ? toDate(options.now) : new Date();\n const diffInSeconds = (toDate(date).getTime() - nowDate.getTime()) / 1000;\n\n let unit = options.unit;\n if (!unit) {\n const absoluteDiff = Math.abs(diffInSeconds);\n unit =\n RELATIVE_TIME_UNITS.find(\n ([, unitSeconds]) => absoluteDiff >= unitSeconds\n )?.[0] ?? 'second';\n }\n\n const unitSeconds =\n RELATIVE_TIME_UNITS.find(([unitName]) => unitName === unit)?.[1] ?? 1;\n\n return new Intl.RelativeTimeFormat(locale, {\n numeric: 'auto',\n style: options.style,\n }).format(Math.round(diffInSeconds / unitSeconds), unit);\n },\n\n /** Formats a list with `Intl.ListFormat`. */\n list: (value: Iterable<string>, options?: Intl.ListFormatOptions): string =>\n new Intl.ListFormat(locale, options).format(value),\n\n displayName: (\n value: string,\n optionsOrFormat?: Intl.DisplayNamesOptions | string,\n extraOptions?: Intl.DisplayNamesOptions\n ): string => {\n const resolvedOptions =\n typeof optionsOrFormat === 'string' ? extraOptions : optionsOrFormat;\n try {\n return (\n new Intl.DisplayNames(\n [locale],\n resolvedOptions ?? { type: 'language' }\n ).of(value) ?? value\n );\n } catch {\n return value;\n }\n },\n }) as unknown as Formatter;\n"],"mappings":";;;;AAMA,MAAM,sBAA+D;CACnE,CAAC,QAAQ,QAAS;CAClB,CAAC,SAAS,OAAQ;CAClB,CAAC,QAAQ,OAAO;CAChB,CAAC,OAAO,MAAM;CACd,CAAC,QAAQ,KAAK;CACd,CAAC,UAAU,GAAG;CACd,CAAC,UAAU,EAAE;CACd;AAED,MAAM,UAAU,UACd,iBAAiB,OAAO,QAAQ,IAAI,KAAK,MAAM;;;;;;;;;;;AAYjD,MAAa,sBAAsB,YAChC;CACC,WAAW,OAAsB,YAC/B,IAAI,KAAK,eAAe,QAAQ,QAAQ,CAAC,OAAO,MAAM;CAExD,SAAS,OAAwB,YAC/B,IAAI,KAAK,aAAa,QAAQ,QAAQ,CAAC,OAAO,MAAM;;CAGtD,gBACE,OACA,KACA,YAEA,IAAI,KAAK,eAAe,QAAQ,QAAQ,CAAC,YACvC,OAAO,MAAM,EACb,OAAO,IAAI,CACZ;;;;;CAMH,eACE,MACA,iBASG;EACH,MAAM,UACJ,wBAAwB,QAAQ,OAAO,iBAAiB,WACpD,EAAE,KAAK,cAAc,GACpB,gBAAgB,EAAE;EAEzB,MAAM,UACJ,QAAQ,QAAQ,SAAY,OAAO,QAAQ,IAAI,mBAAG,IAAI,MAAM;EAC9D,MAAM,iBAAiB,OAAO,KAAK,CAAC,SAAS,GAAG,QAAQ,SAAS,IAAI;EAErE,IAAI,OAAO,QAAQ;AACnB,MAAI,CAAC,MAAM;GACT,MAAM,eAAe,KAAK,IAAI,cAAc;AAC5C,UACE,oBAAoB,MACjB,GAAG,iBAAiB,gBAAgB,YACtC,GAAG,MAAM;;EAGd,MAAM,cACJ,oBAAoB,MAAM,CAAC,cAAc,aAAa,KAAK,GAAG,MAAM;AAEtE,SAAO,IAAI,KAAK,mBAAmB,QAAQ;GACzC,SAAS;GACT,OAAO,QAAQ;GAChB,CAAC,CAAC,OAAO,KAAK,MAAM,gBAAgB,YAAY,EAAE,KAAK;;;CAI1D,OAAO,OAAyB,YAC9B,IAAI,KAAK,WAAW,QAAQ,QAAQ,CAAC,OAAO,MAAM;CAEpD,cACE,OACA,iBACA,iBACW;EACX,MAAM,kBACJ,OAAO,oBAAoB,WAAW,eAAe;AACvD,MAAI;AACF,UACE,IAAI,KAAK,aACP,CAAC,OAAO,EACR,mBAAmB,EAAE,MAAM,YAAY,CACxC,CAAC,GAAG,MAAM,IAAI;UAEX;AACN,UAAO;;;CAGZ"}
@@ -0,0 +1,122 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
3
+ let _intlayer_core_interpreter = require("@intlayer/core/interpreter");
4
+ let _intlayer_core_messageFormat = require("@intlayer/core/messageFormat");
5
+ let react = require("react");
6
+ let react_jsx_runtime = require("react/jsx-runtime");
7
+
8
+ //#region src/shared/namespaceTranslator.tsx
9
+ /**
10
+ * Reads a dotted `path` (e.g. `counter.label`) out of a nested object value.
11
+ *
12
+ * @param objectValue - The object to read from.
13
+ * @param path - Dot-separated path. An empty path returns `objectValue`.
14
+ * @returns The value found at `path`, or `undefined` when any segment is absent.
15
+ */
16
+ const navigatePath = (objectValue, path) => {
17
+ if (!path) return objectValue;
18
+ const parts = path.split(".");
19
+ let current = objectValue;
20
+ for (const part of parts) {
21
+ if (current === null || current === void 0 || typeof current !== "object") return;
22
+ current = current[part];
23
+ }
24
+ return current;
25
+ };
26
+ /** Splits rich values into scalar interpolation values and tag renderers. */
27
+ const splitRichValues = (values = {}) => {
28
+ const scalarValues = {};
29
+ const renderers = {};
30
+ for (const [valueKey, value] of Object.entries(values)) if (typeof value === "function") renderers[valueKey] = value;
31
+ else scalarValues[valueKey] = value;
32
+ return {
33
+ scalarValues,
34
+ renderers
35
+ };
36
+ };
37
+ const renderRichTokens = (tokens, renderers) => tokens.map((token, tokenIndex) => {
38
+ if (typeof token === "string") return token;
39
+ const children = renderRichTokens(token.children, renderers);
40
+ const renderer = renderers[token.tag];
41
+ if (typeof renderer === "function") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.Fragment, { children: renderer(children) }, tokenIndex);
42
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.Fragment, { children }, tokenIndex);
43
+ });
44
+ const renderMarkupTokens = (tokens, renderers) => tokens.map((token) => {
45
+ if (typeof token === "string") return token;
46
+ const children = renderMarkupTokens(token.children, renderers);
47
+ const renderer = renderers[token.tag];
48
+ if (typeof renderer === "function") return renderer(children);
49
+ return children;
50
+ }).join("");
51
+ /**
52
+ * The untyped runtime translator shared by `useTranslations` (React hook) and
53
+ * `createTranslator` (non-React core).
54
+ *
55
+ * Behaviour matches use-intl / next-intl:
56
+ * - namespace `'about'` → keys resolved inside the `about` dictionary
57
+ * - namespace `'about.counter'` → dictionary `about`, key prefix `counter`
58
+ * - no namespace → the first segment of each key is the dictionary key
59
+ * - messages support ICU syntax (plural, select, `#`, formatted arguments)
60
+ * - `t.rich` / `t.markup` map `<tag>chunks</tag>` through the provided
61
+ * renderers; `t.raw` returns the raw value; `t.has` checks existence
62
+ *
63
+ * @param locale - The locale dictionaries are resolved for.
64
+ * @param namespace - Optional dictionary key, optionally with a nested scope.
65
+ * @returns A translate function augmented with `has`, `raw`, `rich`, `markup`.
66
+ */
67
+ const createNamespaceTranslator = (locale, namespace) => {
68
+ const [dictionaryKey, ...prefixSegments] = (namespace ?? "").split(".");
69
+ const keyPrefix = prefixSegments.join(".");
70
+ const lookup = (key) => {
71
+ let targetDictionaryKey = dictionaryKey;
72
+ let path = keyPrefix ? `${keyPrefix}.${key}` : key;
73
+ if (!targetDictionaryKey) {
74
+ const [firstSegment, ...restSegments] = key.split(".");
75
+ targetDictionaryKey = firstSegment;
76
+ path = restSegments.join(".");
77
+ }
78
+ try {
79
+ return navigatePath((0, _intlayer_core_interpreter.getIntlayer)(targetDictionaryKey, locale), path);
80
+ } catch {
81
+ return;
82
+ }
83
+ };
84
+ const resolveToString = (key, values = {}) => {
85
+ const rawValue = lookup(key);
86
+ if (rawValue === null || rawValue === void 0) return void 0;
87
+ return (0, _intlayer_core_messageFormat.resolveMessage)(rawValue, values, locale, "icu");
88
+ };
89
+ const missingKeyFallback = (key) => namespace ? `${namespace}.${key}` : key;
90
+ const translate = (key, values) => resolveToString(key, values) ?? missingKeyFallback(key);
91
+ return Object.assign(translate, {
92
+ /** Returns `true` if the given key exists in the namespace. */
93
+ has: (key) => lookup(key) !== void 0,
94
+ /** Returns the raw unprocessed content for the given key. */
95
+ raw: (key) => lookup(key),
96
+ /**
97
+ * Resolves a message containing `<tag>chunks</tag>` markup, mapping each
98
+ * tag through the matching renderer in `values`.
99
+ */
100
+ rich: (key, values) => {
101
+ const { scalarValues, renderers } = splitRichValues(values);
102
+ const message = resolveToString(key, scalarValues);
103
+ if (message === void 0) return missingKeyFallback(key);
104
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: renderRichTokens((0, _intlayer_core_messageFormat.parseTaggedMessage)(message), renderers) });
105
+ },
106
+ /**
107
+ * Resolves a message containing `<tag>chunks</tag>` markup into a string,
108
+ * mapping each tag through the matching string renderer in `values`.
109
+ */
110
+ markup: (key, values) => {
111
+ const { scalarValues, renderers } = splitRichValues(values);
112
+ const message = resolveToString(key, scalarValues);
113
+ if (message === void 0) return missingKeyFallback(key);
114
+ return renderMarkupTokens((0, _intlayer_core_messageFormat.parseTaggedMessage)(message), renderers);
115
+ }
116
+ });
117
+ };
118
+
119
+ //#endregion
120
+ exports.createNamespaceTranslator = createNamespaceTranslator;
121
+ exports.navigatePath = navigatePath;
122
+ //# sourceMappingURL=namespaceTranslator.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"namespaceTranslator.cjs","names":["Fragment"],"sources":["../../../src/shared/namespaceTranslator.tsx"],"sourcesContent":["import { getIntlayer } from '@intlayer/core/interpreter';\nimport {\n type MessageValues,\n parseTaggedMessage,\n resolveMessage,\n type TaggedMessageToken,\n} from '@intlayer/core/messageFormat';\nimport type {\n DictionaryKeys,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { Fragment, type ReactNode } from 'react';\n\n/** Chunk renderer used by `t.rich()` — maps tag children to a React node. */\nexport type RichChunkRenderer = (chunks: ReactNode) => ReactNode;\n\n/** Chunk renderer used by `t.markup()` — maps tag children to a string. */\nexport type MarkupChunkRenderer = (chunks: string) => string;\n\n/**\n * Reads a dotted `path` (e.g. `counter.label`) out of a nested object value.\n *\n * @param objectValue - The object to read from.\n * @param path - Dot-separated path. An empty path returns `objectValue`.\n * @returns The value found at `path`, or `undefined` when any segment is absent.\n */\nexport const navigatePath = (objectValue: unknown, path: string): unknown => {\n if (!path) return objectValue;\n const parts = path.split('.');\n let current: unknown = objectValue;\n for (const part of parts) {\n if (\n current === null ||\n current === undefined ||\n typeof current !== 'object'\n ) {\n return undefined;\n }\n current = (current as Record<string, unknown>)[part];\n }\n return current;\n};\n\n/** Splits rich values into scalar interpolation values and tag renderers. */\nconst splitRichValues = (\n values: Record<string, unknown> = {}\n): { scalarValues: MessageValues; renderers: Record<string, unknown> } => {\n const scalarValues: MessageValues = {};\n const renderers: Record<string, unknown> = {};\n\n for (const [valueKey, value] of Object.entries(values)) {\n if (typeof value === 'function') renderers[valueKey] = value;\n else scalarValues[valueKey] = value;\n }\n\n return { scalarValues, renderers };\n};\n\nconst renderRichTokens = (\n tokens: TaggedMessageToken[],\n renderers: Record<string, unknown>\n): ReactNode[] =>\n tokens.map((token, tokenIndex) => {\n if (typeof token === 'string') return token;\n\n const children = renderRichTokens(token.children, renderers);\n const renderer = renderers[token.tag];\n\n if (typeof renderer === 'function') {\n return (\n <Fragment key={tokenIndex}>\n {(renderer as RichChunkRenderer)(children)}\n </Fragment>\n );\n }\n\n // No renderer provided for the tag — render its children unwrapped\n return <Fragment key={tokenIndex}>{children}</Fragment>;\n });\n\nconst renderMarkupTokens = (\n tokens: TaggedMessageToken[],\n renderers: Record<string, unknown>\n): string =>\n tokens\n .map((token) => {\n if (typeof token === 'string') return token;\n\n const children = renderMarkupTokens(token.children, renderers);\n const renderer = renderers[token.tag];\n\n if (typeof renderer === 'function') {\n return (renderer as MarkupChunkRenderer)(children);\n }\n\n return children;\n })\n .join('');\n\n/**\n * The untyped runtime translator shared by `useTranslations` (React hook) and\n * `createTranslator` (non-React core).\n *\n * Behaviour matches use-intl / next-intl:\n * - namespace `'about'` → keys resolved inside the `about` dictionary\n * - namespace `'about.counter'` → dictionary `about`, key prefix `counter`\n * - no namespace → the first segment of each key is the dictionary key\n * - messages support ICU syntax (plural, select, `#`, formatted arguments)\n * - `t.rich` / `t.markup` map `<tag>chunks</tag>` through the provided\n * renderers; `t.raw` returns the raw value; `t.has` checks existence\n *\n * @param locale - The locale dictionaries are resolved for.\n * @param namespace - Optional dictionary key, optionally with a nested scope.\n * @returns A translate function augmented with `has`, `raw`, `rich`, `markup`.\n */\nexport const createNamespaceTranslator = (\n locale: LocalesValues,\n namespace?: string\n) => {\n const [dictionaryKey, ...prefixSegments] = (namespace ?? '').split('.');\n const keyPrefix = prefixSegments.join('.');\n\n const lookup = (key: string): unknown => {\n let targetDictionaryKey = dictionaryKey;\n let path = keyPrefix ? `${keyPrefix}.${key}` : key;\n\n if (!targetDictionaryKey) {\n // Root scope — the first key segment designates the dictionary\n const [firstSegment, ...restSegments] = key.split('.');\n targetDictionaryKey = firstSegment;\n path = restSegments.join('.');\n }\n\n try {\n const dictionary = getIntlayer(\n targetDictionaryKey as DictionaryKeys,\n locale\n );\n return navigatePath(dictionary, path);\n } catch {\n return undefined;\n }\n };\n\n const resolveToString = (\n key: string,\n values: MessageValues = {}\n ): string | undefined => {\n const rawValue = lookup(key);\n if (rawValue === null || rawValue === undefined) return undefined;\n return resolveMessage(rawValue, values, locale, 'icu');\n };\n\n const missingKeyFallback = (key: string): string =>\n namespace ? `${namespace}.${key}` : key;\n\n const translate = (key: string, values?: MessageValues): string =>\n resolveToString(key, values) ?? missingKeyFallback(key);\n\n return Object.assign(translate, {\n /** Returns `true` if the given key exists in the namespace. */\n has: (key: string): boolean => lookup(key) !== undefined,\n\n /** Returns the raw unprocessed content for the given key. */\n raw: (key: string): unknown => lookup(key),\n\n /**\n * Resolves a message containing `<tag>chunks</tag>` markup, mapping each\n * tag through the matching renderer in `values`.\n */\n rich: (key: string, values?: Record<string, unknown>): ReactNode => {\n const { scalarValues, renderers } = splitRichValues(values);\n const message = resolveToString(key, scalarValues);\n if (message === undefined) return missingKeyFallback(key);\n return <>{renderRichTokens(parseTaggedMessage(message), renderers)}</>;\n },\n\n /**\n * Resolves a message containing `<tag>chunks</tag>` markup into a string,\n * mapping each tag through the matching string renderer in `values`.\n */\n markup: (key: string, values?: Record<string, unknown>): string => {\n const { scalarValues, renderers } = splitRichValues(values);\n const message = resolveToString(key, scalarValues);\n if (message === undefined) return missingKeyFallback(key);\n return renderMarkupTokens(parseTaggedMessage(message), renderers);\n },\n });\n};\n\nexport type CompatTranslator = ReturnType<typeof createNamespaceTranslator>;\n"],"mappings":";;;;;;;;;;;;;;;AA0BA,MAAa,gBAAgB,aAAsB,SAA0B;AAC3E,KAAI,CAAC,KAAM,QAAO;CAClB,MAAM,QAAQ,KAAK,MAAM,IAAI;CAC7B,IAAI,UAAmB;AACvB,MAAK,MAAM,QAAQ,OAAO;AACxB,MACE,YAAY,QACZ,YAAY,UACZ,OAAO,YAAY,SAEnB;AAEF,YAAW,QAAoC;;AAEjD,QAAO;;;AAIT,MAAM,mBACJ,SAAkC,EAAE,KACoC;CACxE,MAAM,eAA8B,EAAE;CACtC,MAAM,YAAqC,EAAE;AAE7C,MAAK,MAAM,CAAC,UAAU,UAAU,OAAO,QAAQ,OAAO,CACpD,KAAI,OAAO,UAAU,WAAY,WAAU,YAAY;KAClD,cAAa,YAAY;AAGhC,QAAO;EAAE;EAAc;EAAW;;AAGpC,MAAM,oBACJ,QACA,cAEA,OAAO,KAAK,OAAO,eAAe;AAChC,KAAI,OAAO,UAAU,SAAU,QAAO;CAEtC,MAAM,WAAW,iBAAiB,MAAM,UAAU,UAAU;CAC5D,MAAM,WAAW,UAAU,MAAM;AAEjC,KAAI,OAAO,aAAa,WACtB,QACE,2CAACA,gBAAD,YACI,SAA+B,SAAS,EACjC,EAFI,WAEJ;AAKf,QAAO,2CAACA,gBAAD,EAA4B,UAAoB,EAAjC,WAAiC;EACvD;AAEJ,MAAM,sBACJ,QACA,cAEA,OACG,KAAK,UAAU;AACd,KAAI,OAAO,UAAU,SAAU,QAAO;CAEtC,MAAM,WAAW,mBAAmB,MAAM,UAAU,UAAU;CAC9D,MAAM,WAAW,UAAU,MAAM;AAEjC,KAAI,OAAO,aAAa,WACtB,QAAQ,SAAiC,SAAS;AAGpD,QAAO;EACP,CACD,KAAK,GAAG;;;;;;;;;;;;;;;;;AAkBb,MAAa,6BACX,QACA,cACG;CACH,MAAM,CAAC,eAAe,GAAG,mBAAmB,aAAa,IAAI,MAAM,IAAI;CACvE,MAAM,YAAY,eAAe,KAAK,IAAI;CAE1C,MAAM,UAAU,QAAyB;EACvC,IAAI,sBAAsB;EAC1B,IAAI,OAAO,YAAY,GAAG,UAAU,GAAG,QAAQ;AAE/C,MAAI,CAAC,qBAAqB;GAExB,MAAM,CAAC,cAAc,GAAG,gBAAgB,IAAI,MAAM,IAAI;AACtD,yBAAsB;AACtB,UAAO,aAAa,KAAK,IAAI;;AAG/B,MAAI;AAKF,UAAO,yDAHL,qBACA,OAE4B,EAAE,KAAK;UAC/B;AACN;;;CAIJ,MAAM,mBACJ,KACA,SAAwB,EAAE,KACH;EACvB,MAAM,WAAW,OAAO,IAAI;AAC5B,MAAI,aAAa,QAAQ,aAAa,OAAW,QAAO;AACxD,0DAAsB,UAAU,QAAQ,QAAQ,MAAM;;CAGxD,MAAM,sBAAsB,QAC1B,YAAY,GAAG,UAAU,GAAG,QAAQ;CAEtC,MAAM,aAAa,KAAa,WAC9B,gBAAgB,KAAK,OAAO,IAAI,mBAAmB,IAAI;AAEzD,QAAO,OAAO,OAAO,WAAW;;EAE9B,MAAM,QAAyB,OAAO,IAAI,KAAK;;EAG/C,MAAM,QAAyB,OAAO,IAAI;;;;;EAM1C,OAAO,KAAa,WAAgD;GAClE,MAAM,EAAE,cAAc,cAAc,gBAAgB,OAAO;GAC3D,MAAM,UAAU,gBAAgB,KAAK,aAAa;AAClD,OAAI,YAAY,OAAW,QAAO,mBAAmB,IAAI;AACzD,UAAO,mFAAG,sEAAoC,QAAQ,EAAE,UAAU,EAAI;;;;;;EAOxE,SAAS,KAAa,WAA6C;GACjE,MAAM,EAAE,cAAc,cAAc,gBAAgB,OAAO;GAC3D,MAAM,UAAU,gBAAgB,KAAK,aAAa;AAClD,OAAI,YAAY,OAAW,QAAO,mBAAmB,IAAI;AACzD,UAAO,wEAAsC,QAAQ,EAAE,UAAU;;EAEpE,CAAC"}
File without changes
@@ -0,0 +1,37 @@
1
+ 'use client';
2
+
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+ const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
5
+ const require_shared_namespaceTranslator = require('./shared/namespaceTranslator.cjs');
6
+ let react_intlayer = require("react-intlayer");
7
+
8
+ //#region src/useDictionary.ts
9
+ /**
10
+ * Dictionary-accepting variant of `useTranslations`.
11
+ *
12
+ * Used internally by the build-time optimization: instead of looking up the
13
+ * dictionary at runtime by key, the babel/swc plugin pre-imports the dictionary
14
+ * JSON at build time and passes it directly here. This enables tree-shaking of
15
+ * unused locale content.
16
+ *
17
+ * @example (generated by the plugin, not written manually)
18
+ * import _abc from '.intlayer/dictionaries/about.json' with { type: 'json' };
19
+ * const t = useDictionary(_abc);
20
+ */
21
+ const useDictionary = (dictionary, namespacePrefix) => {
22
+ const content = (0, react_intlayer.useDictionary)(dictionary);
23
+ const resolveKey = (key) => namespacePrefix ? `${namespacePrefix}.${key}` : key;
24
+ return Object.assign((lookup, params) => {
25
+ const rawValue = require_shared_namespaceTranslator.navigatePath(content, resolveKey(String(lookup)));
26
+ const text = String(rawValue ?? resolveKey(String(lookup)));
27
+ if (!params) return text;
28
+ return text.replace(/\{(\w+)\}/g, (_match, key) => params[key] != null ? String(params[key]) : `{${key}}`);
29
+ }, {
30
+ has: (lookup) => require_shared_namespaceTranslator.navigatePath(content, resolveKey(String(lookup))) != null,
31
+ raw: (lookup) => require_shared_namespaceTranslator.navigatePath(content, resolveKey(String(lookup)))
32
+ });
33
+ };
34
+
35
+ //#endregion
36
+ exports.useDictionary = useDictionary;
37
+ //# sourceMappingURL=useDictionary.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDictionary.cjs","names":["navigatePath"],"sources":["../../src/useDictionary.ts"],"sourcesContent":["'use client';\n\nimport type { ValidDotPathsFor } from '@intlayer/core/transpiler';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport { useDictionary as useDictionaryBase } from 'react-intlayer';\nimport { navigatePath } from './shared/namespaceTranslator';\n\n/**\n * Dictionary-accepting variant of `useTranslations`.\n *\n * Used internally by the build-time optimization: instead of looking up the\n * dictionary at runtime by key, the babel/swc plugin pre-imports the dictionary\n * JSON at build time and passes it directly here. This enables tree-shaking of\n * unused locale content.\n *\n * @example (generated by the plugin, not written manually)\n * import _abc from '.intlayer/dictionaries/about.json' with { type: 'json' };\n * const t = useDictionary(_abc);\n */\nexport const useDictionary = <T extends Dictionary>(\n dictionary: T,\n namespacePrefix?: string\n) => {\n const content = useDictionaryBase(dictionary);\n\n const resolveKey = (key: string): string =>\n namespacePrefix ? `${namespacePrefix}.${key}` : key;\n\n return Object.assign(\n <P extends ValidDotPathsFor<string>>(\n lookup: P,\n params?: Record<string, unknown>\n ): string => {\n const rawValue = navigatePath(content, resolveKey(String(lookup)));\n const text = String(rawValue ?? resolveKey(String(lookup)));\n if (!params) return text;\n return text.replace(/\\{(\\w+)\\}/g, (_match, key) =>\n params[key] != null ? String(params[key]) : `{${key}}`\n );\n },\n {\n has: <P extends ValidDotPathsFor<string>>(lookup: P): boolean =>\n navigatePath(content, resolveKey(String(lookup))) != null,\n raw: <P extends ValidDotPathsFor<string>>(lookup: P): unknown =>\n navigatePath(content, resolveKey(String(lookup))),\n }\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAmBA,MAAa,iBACX,YACA,oBACG;CACH,MAAM,4CAA4B,WAAW;CAE7C,MAAM,cAAc,QAClB,kBAAkB,GAAG,gBAAgB,GAAG,QAAQ;AAElD,QAAO,OAAO,QAEV,QACA,WACW;EACX,MAAM,WAAWA,gDAAa,SAAS,WAAW,OAAO,OAAO,CAAC,CAAC;EAClE,MAAM,OAAO,OAAO,YAAY,WAAW,OAAO,OAAO,CAAC,CAAC;AAC3D,MAAI,CAAC,OAAQ,QAAO;AACpB,SAAO,KAAK,QAAQ,eAAe,QAAQ,QACzC,OAAO,QAAQ,OAAO,OAAO,OAAO,KAAK,GAAG,IAAI,IAAI,GACrD;IAEH;EACE,MAA0C,WACxCA,gDAAa,SAAS,WAAW,OAAO,OAAO,CAAC,CAAC,IAAI;EACvD,MAA0C,WACxCA,gDAAa,SAAS,WAAW,OAAO,OAAO,CAAC,CAAC;EACpD,CACF"}
@@ -0,0 +1,31 @@
1
+ 'use client';
2
+
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+ const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
5
+ const require_shared_namespaceTranslator = require('./shared/namespaceTranslator.cjs');
6
+ let react_intlayer = require("react-intlayer");
7
+
8
+ //#region src/useDictionaryDynamic.ts
9
+ /**
10
+ * Dynamic dictionary-accepting variant of `useTranslations`.
11
+ *
12
+ * Counterpart to {@link useDictionary} for dictionaries imported lazily per
13
+ * locale. Used internally by the build-time optimization.
14
+ */
15
+ const useDictionaryDynamic = (dictionaryPromise, key, namespacePrefix) => {
16
+ const content = (0, react_intlayer.useDictionaryDynamic)(dictionaryPromise, key);
17
+ const resolveKey = (lookupKey) => namespacePrefix ? `${namespacePrefix}.${lookupKey}` : lookupKey;
18
+ return Object.assign((lookup, params) => {
19
+ const rawValue = require_shared_namespaceTranslator.navigatePath(content, resolveKey(String(lookup)));
20
+ const text = String(rawValue ?? resolveKey(String(lookup)));
21
+ if (!params) return text;
22
+ return text.replace(/\{(\w+)\}/g, (_match, key) => params[key] != null ? String(params[key]) : `{${key}}`);
23
+ }, {
24
+ has: (lookup) => require_shared_namespaceTranslator.navigatePath(content, resolveKey(String(lookup))) != null,
25
+ raw: (lookup) => require_shared_namespaceTranslator.navigatePath(content, resolveKey(String(lookup)))
26
+ });
27
+ };
28
+
29
+ //#endregion
30
+ exports.useDictionaryDynamic = useDictionaryDynamic;
31
+ //# sourceMappingURL=useDictionaryDynamic.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDictionaryDynamic.cjs","names":["navigatePath"],"sources":["../../src/useDictionaryDynamic.ts"],"sourcesContent":["'use client';\n\nimport type { ValidDotPathsFor } from '@intlayer/core/transpiler';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type { StrictModeLocaleMap } from '@intlayer/types/module_augmentation';\nimport { useDictionaryDynamic as useDictionaryDynamicBase } from 'react-intlayer';\nimport { navigatePath } from './shared/namespaceTranslator';\n\n/**\n * Dynamic dictionary-accepting variant of `useTranslations`.\n *\n * Counterpart to {@link useDictionary} for dictionaries imported lazily per\n * locale. Used internally by the build-time optimization.\n */\nexport const useDictionaryDynamic = <\n const T extends Dictionary,\n const K extends string,\n>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n key: K,\n namespacePrefix?: string\n) => {\n const content = useDictionaryDynamicBase<T, K>(dictionaryPromise, key);\n\n const resolveKey = (lookupKey: string): string =>\n namespacePrefix ? `${namespacePrefix}.${lookupKey}` : lookupKey;\n\n return Object.assign(\n <P extends ValidDotPathsFor<string>>(\n lookup: P,\n params?: Record<string, unknown>\n ): string => {\n const rawValue = navigatePath(content, resolveKey(String(lookup)));\n const text = String(rawValue ?? resolveKey(String(lookup)));\n if (!params) return text;\n return text.replace(/\\{(\\w+)\\}/g, (_match, key) =>\n params[key] != null ? String(params[key]) : `{${key}}`\n );\n },\n {\n has: <P extends ValidDotPathsFor<string>>(lookup: P): boolean =>\n navigatePath(content, resolveKey(String(lookup))) != null,\n raw: <P extends ValidDotPathsFor<string>>(lookup: P): unknown =>\n navigatePath(content, resolveKey(String(lookup))),\n }\n );\n};\n"],"mappings":";;;;;;;;;;;;;;AAcA,MAAa,wBAIX,mBACA,KACA,oBACG;CACH,MAAM,mDAAyC,mBAAmB,IAAI;CAEtE,MAAM,cAAc,cAClB,kBAAkB,GAAG,gBAAgB,GAAG,cAAc;AAExD,QAAO,OAAO,QAEV,QACA,WACW;EACX,MAAM,WAAWA,gDAAa,SAAS,WAAW,OAAO,OAAO,CAAC,CAAC;EAClE,MAAM,OAAO,OAAO,YAAY,WAAW,OAAO,OAAO,CAAC,CAAC;AAC3D,MAAI,CAAC,OAAQ,QAAO;AACpB,SAAO,KAAK,QAAQ,eAAe,QAAQ,QACzC,OAAO,QAAQ,OAAO,OAAO,OAAO,KAAK,GAAG,IAAI,IAAI,GACrD;IAEH;EACE,MAA0C,WACxCA,gDAAa,SAAS,WAAW,OAAO,OAAO,CAAC,CAAC,IAAI;EACvD,MAA0C,WACxCA,gDAAa,SAAS,WAAW,OAAO,OAAO,CAAC,CAAC;EACpD,CACF"}
@@ -0,0 +1,22 @@
1
+ import { buildIntlFormatter } from "../shared/intlFormatter.mjs";
2
+
3
+ //#region src/core/createFormatter.ts
4
+ /**
5
+ * Drop-in for use-intl's `createFormatter`.
6
+ *
7
+ * Returns locale-aware formatters backed by the native `Intl.*` APIs:
8
+ * `dateTime`, `number`, `dateTimeRange`, `relativeTime`, `list`, and
9
+ * `displayName`. `now`, `timeZone`, `formats`, and `onError` are accepted for
10
+ * API compatibility but only `locale` influences the output.
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * const format = createFormatter({ locale: 'en' });
15
+ * format.number(1234.5, { style: 'currency', currency: 'USD' });
16
+ * ```
17
+ */
18
+ const createFormatter = ({ locale }) => buildIntlFormatter(locale);
19
+
20
+ //#endregion
21
+ export { createFormatter };
22
+ //# sourceMappingURL=createFormatter.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createFormatter.mjs","names":[],"sources":["../../../src/core/createFormatter.ts"],"sourcesContent":["import type { createFormatter as _createFormatter } from 'use-intl';\nimport { buildIntlFormatter } from '../shared/intlFormatter';\n\n/**\n * Drop-in for use-intl's `createFormatter`.\n *\n * Returns locale-aware formatters backed by the native `Intl.*` APIs:\n * `dateTime`, `number`, `dateTimeRange`, `relativeTime`, `list`, and\n * `displayName`. `now`, `timeZone`, `formats`, and `onError` are accepted for\n * API compatibility but only `locale` influences the output.\n *\n * @example\n * ```ts\n * const format = createFormatter({ locale: 'en' });\n * format.number(1234.5, { style: 'currency', currency: 'USD' });\n * ```\n */\nexport const createFormatter: typeof _createFormatter = ({ locale }) =>\n buildIntlFormatter(locale);\n"],"mappings":";;;;;;;;;;;;;;;;;AAiBA,MAAa,mBAA4C,EAAE,aACzD,mBAAmB,OAAO"}