@intlayer/use-intl 9.0.0-canary.2 → 9.0.0-canary.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/{react → client}/IntlProvider.cjs +1 -1
- package/dist/cjs/client/IntlProvider.cjs.map +1 -0
- package/dist/cjs/{react → client}/helpers.cjs +1 -1
- package/dist/cjs/client/helpers.cjs.map +1 -0
- package/dist/cjs/client/index.cjs +27 -0
- package/dist/cjs/client/index.cjs.map +1 -0
- package/dist/cjs/{react → client}/useLocale.cjs +1 -1
- package/dist/cjs/client/useLocale.cjs.map +1 -0
- package/dist/cjs/{react → client}/useTranslations.cjs +1 -1
- package/dist/cjs/client/useTranslations.cjs.map +1 -0
- package/dist/cjs/core/initializeConfig.cjs.map +1 -1
- package/dist/cjs/index.cjs +14 -14
- package/dist/esm/{react → client}/IntlProvider.mjs +1 -1
- package/dist/esm/client/IntlProvider.mjs.map +1 -0
- package/dist/esm/{react → client}/helpers.mjs +1 -1
- package/dist/esm/client/helpers.mjs.map +1 -0
- package/dist/esm/{react → client}/index.mjs +3 -3
- package/dist/esm/client/index.mjs.map +1 -0
- package/dist/esm/{react → client}/useLocale.mjs +1 -1
- package/dist/esm/client/useLocale.mjs.map +1 -0
- package/dist/esm/{react → client}/useTranslations.mjs +2 -2
- package/dist/esm/client/useTranslations.mjs.map +1 -0
- package/dist/esm/core/createFormatter.mjs.map +1 -1
- package/dist/esm/core/createTranslator.mjs.map +1 -1
- package/dist/esm/core/errors.mjs.map +1 -1
- package/dist/esm/core/hasLocale.mjs.map +1 -1
- package/dist/esm/core/initializeConfig.mjs.map +1 -1
- package/dist/esm/index.mjs +8 -7
- package/dist/esm/plugin/index.mjs +3 -36
- package/dist/esm/plugin/index.mjs.map +1 -1
- package/dist/esm/shared/intlFormatter.mjs.map +1 -1
- package/dist/esm/shared/namespaceTranslator.mjs +56 -35
- package/dist/esm/shared/namespaceTranslator.mjs.map +1 -1
- package/dist/esm/useDictionary.mjs +10 -15
- package/dist/esm/useDictionary.mjs.map +1 -1
- package/dist/esm/useDictionaryDynamic.mjs +7 -15
- package/dist/esm/useDictionaryDynamic.mjs.map +1 -1
- package/dist/types/{react → client}/IntlProvider.d.ts +4 -4
- package/dist/types/client/IntlProvider.d.ts.map +1 -0
- package/dist/types/{react → client}/helpers.d.ts +1 -2
- package/dist/types/client/helpers.d.ts.map +1 -0
- package/dist/types/{react → client}/index.d.ts +3 -4
- package/dist/types/client/index.d.ts.map +1 -0
- package/dist/types/{react → client}/useLocale.d.ts +1 -2
- package/dist/types/client/useLocale.d.ts.map +1 -0
- package/dist/types/{react → client}/useTranslations.d.ts +5 -5
- package/dist/types/client/useTranslations.d.ts.map +1 -0
- package/dist/types/core/createFormatter.d.ts +0 -1
- package/dist/types/core/createFormatter.d.ts.map +1 -1
- package/dist/types/core/createTranslator.d.ts +9 -7
- package/dist/types/core/createTranslator.d.ts.map +1 -1
- package/dist/types/core/errors.d.ts.map +1 -1
- package/dist/types/core/hasLocale.d.ts +0 -1
- package/dist/types/core/hasLocale.d.ts.map +1 -1
- package/dist/types/core/index.d.ts +1 -1
- package/dist/types/core/initializeConfig.d.ts +0 -1
- package/dist/types/core/initializeConfig.d.ts.map +1 -1
- package/dist/types/core/types.d.ts +1 -1
- package/dist/types/index.d.ts +11 -8
- package/dist/types/plugin/index.d.ts +0 -1
- package/dist/types/plugin/index.d.ts.map +1 -1
- package/dist/types/shared/intlFormatter.d.ts +0 -1
- package/dist/types/shared/intlFormatter.d.ts.map +1 -1
- package/dist/types/shared/namespaceTranslator.d.ts +33 -12
- package/dist/types/shared/namespaceTranslator.d.ts.map +1 -1
- package/dist/types/shared/translateFunctionTypes.d.ts +53 -8
- package/dist/types/shared/translateFunctionTypes.d.ts.map +1 -1
- package/dist/types/useDictionary.d.ts +15 -6
- package/dist/types/useDictionary.d.ts.map +1 -1
- package/dist/types/useDictionaryDynamic.d.ts +12 -7
- package/dist/types/useDictionaryDynamic.d.ts.map +1 -1
- package/package.json +18 -22
- package/dist/cjs/react/IntlProvider.cjs.map +0 -1
- package/dist/cjs/react/helpers.cjs.map +0 -1
- package/dist/cjs/react/index.cjs +0 -27
- package/dist/cjs/react/index.cjs.map +0 -1
- package/dist/cjs/react/useLocale.cjs.map +0 -1
- package/dist/cjs/react/useTranslations.cjs.map +0 -1
- package/dist/esm/react/IntlProvider.mjs.map +0 -1
- package/dist/esm/react/helpers.mjs.map +0 -1
- package/dist/esm/react/index.mjs.map +0 -1
- package/dist/esm/react/useLocale.mjs.map +0 -1
- package/dist/esm/react/useTranslations.mjs.map +0 -1
- package/dist/types/react/IntlProvider.d.ts.map +0 -1
- package/dist/types/react/helpers.d.ts.map +0 -1
- package/dist/types/react/index.d.ts.map +0 -1
- package/dist/types/react/useLocale.d.ts.map +0 -1
- package/dist/types/react/useTranslations.d.ts.map +0 -1
|
@@ -8,7 +8,7 @@ let _intlayer_config_built = require("@intlayer/config/built");
|
|
|
8
8
|
let _intlayer_config_colors = require("@intlayer/config/colors");
|
|
9
9
|
let _intlayer_config_logger = require("@intlayer/config/logger");
|
|
10
10
|
|
|
11
|
-
//#region src/
|
|
11
|
+
//#region src/client/IntlProvider.tsx
|
|
12
12
|
/**
|
|
13
13
|
* Drop-in for use-intl's `IntlProvider`.
|
|
14
14
|
*
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IntlProvider.cjs","names":["CYAN","IntlayerProvider"],"sources":["../../../src/client/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 type { ComponentProps } from 'react';\nimport { IntlayerProvider } from 'react-intlayer';\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 key={String(locale)} locale={locale as LocalesValues}>\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;EAA+C;EAC5C;EACgB,EAFI,OAAO,OAAO,CAElB"}
|
|
@@ -8,7 +8,7 @@ let _intlayer_config_built = require("@intlayer/config/built");
|
|
|
8
8
|
let _intlayer_config_colors = require("@intlayer/config/colors");
|
|
9
9
|
let _intlayer_config_logger = require("@intlayer/config/logger");
|
|
10
10
|
|
|
11
|
-
//#region src/
|
|
11
|
+
//#region src/client/helpers.ts
|
|
12
12
|
/**
|
|
13
13
|
* Drop-in for use-intl's `useNow`.
|
|
14
14
|
* Returns the current `Date`. The `updateInterval` option is ignored.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.cjs","names":["CYAN","buildIntlFormatter"],"sources":["../../../src/client/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_useDictionary = require('../useDictionary.cjs');
|
|
4
|
+
const require_client_helpers = require('./helpers.cjs');
|
|
5
|
+
const require_client_IntlProvider = require('./IntlProvider.cjs');
|
|
6
|
+
const require_client_useLocale = require('./useLocale.cjs');
|
|
7
|
+
const require_client_useTranslations = require('./useTranslations.cjs');
|
|
8
|
+
|
|
9
|
+
//#region src/client/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_client_IntlProvider.IntlProvider;
|
|
18
|
+
exports._useExtracted = _useExtracted;
|
|
19
|
+
exports.useDictionary = require_useDictionary.useDictionary;
|
|
20
|
+
exports.useDictionaryDynamic = require_useDictionaryDynamic.useDictionaryDynamic;
|
|
21
|
+
exports.useFormatter = require_client_helpers.useFormatter;
|
|
22
|
+
exports.useLocale = require_client_useLocale.useLocale;
|
|
23
|
+
exports.useMessages = require_client_helpers.useMessages;
|
|
24
|
+
exports.useNow = require_client_helpers.useNow;
|
|
25
|
+
exports.useTimeZone = require_client_helpers.useTimeZone;
|
|
26
|
+
exports.useTranslations = require_client_useTranslations.useTranslations;
|
|
27
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","names":[],"sources":["../../../src/client/index.ts"],"sourcesContent":["export { useDictionary } from '../useDictionary';\nexport { useDictionaryDynamic } from '../useDictionaryDynamic';\nexport { useFormatter, useMessages, useNow, useTimeZone } from './helpers';\nexport { IntlProvider, type IntlProviderProps } from './IntlProvider';\nexport { useLocale } from './useLocale';\nexport { useTranslations } from './useTranslations';\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"}
|
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
4
4
|
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
5
5
|
let react_intlayer = require("react-intlayer");
|
|
6
6
|
|
|
7
|
-
//#region src/
|
|
7
|
+
//#region src/client/useLocale.ts
|
|
8
8
|
/**
|
|
9
9
|
* Drop-in for use-intl's `useLocale`.
|
|
10
10
|
*
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useLocale.cjs","names":[],"sources":["../../../src/client/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"}
|
|
@@ -6,7 +6,7 @@ const require_shared_namespaceTranslator = require('../shared/namespaceTranslato
|
|
|
6
6
|
let react_intlayer = require("react-intlayer");
|
|
7
7
|
let react = require("react");
|
|
8
8
|
|
|
9
|
-
//#region src/
|
|
9
|
+
//#region src/client/useTranslations.ts
|
|
10
10
|
/**
|
|
11
11
|
* Drop-in for use-intl's `useTranslations`.
|
|
12
12
|
*
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTranslations.cjs","names":["IntlayerClientContext","createNamespaceTranslator"],"sources":["../../../src/client/useTranslations.ts"],"sourcesContent":["'use client';\n\nimport type {\n DictionaryKeys,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { useContext, useMemo } from 'react';\nimport { IntlayerClientContext } from 'react-intlayer';\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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initializeConfig.cjs","names":[],"sources":["../../../src/core/initializeConfig.ts"],"sourcesContent":["import type { initializeConfig as _initializeConfig } from 'use-intl';\n\n/**\n * Drop-in for use-intl's `initializeConfig`.\n *\n * Enhances an incoming config with defaults. With intlayer, `messages` and\n * `formats` are not consumed at runtime (content comes from compiled\n * dictionaries) but the shape is preserved so callers keep type-checking.\n */\nexport const initializeConfig: typeof _initializeConfig = ({\n formats,\n getMessageFallback,\n messages,\n onError,\n ...rest\n}) => {\n const finalOnError = onError ?? ((error) => error);\n const finalGetMessageFallback =\n getMessageFallback
|
|
1
|
+
{"version":3,"file":"initializeConfig.cjs","names":[],"sources":["../../../src/core/initializeConfig.ts"],"sourcesContent":["import type { initializeConfig as _initializeConfig } from 'use-intl';\n\n/**\n * Drop-in for use-intl's `initializeConfig`.\n *\n * Enhances an incoming config with defaults. With intlayer, `messages` and\n * `formats` are not consumed at runtime (content comes from compiled\n * dictionaries) but the shape is preserved so callers keep type-checking.\n */\nexport const initializeConfig: typeof _initializeConfig = ({\n formats,\n getMessageFallback,\n messages,\n onError,\n ...rest\n}) => {\n const finalOnError = onError ?? ((error) => error);\n const finalGetMessageFallback =\n getMessageFallback ??\n (({ key, namespace }) => [namespace, key].filter(Boolean).join('.'));\n\n return {\n ...rest,\n formats: formats || undefined,\n messages: messages || undefined,\n onError: finalOnError,\n getMessageFallback: finalGetMessageFallback,\n };\n};\n"],"mappings":";;;;;;;;;;AASA,MAAa,oBAA8C,EACzD,SACA,oBACA,UACA,SACA,GAAG,WACC;CACJ,MAAM,eAAe,aAAa,UAAU;CAC5C,MAAM,0BACJ,wBACE,EAAE,KAAK,gBAAgB,CAAC,WAAW,IAAI,CAAC,OAAO,QAAQ,CAAC,KAAK,IAAI;AAErE,QAAO;EACL,GAAG;EACH,SAAS,WAAW;EACpB,UAAU,YAAY;EACtB,SAAS;EACT,oBAAoB;EACrB"}
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_useDictionaryDynamic = require('./useDictionaryDynamic.cjs');
|
|
3
|
+
const require_useDictionary = require('./useDictionary.cjs');
|
|
4
|
+
const require_client_helpers = require('./client/helpers.cjs');
|
|
5
|
+
const require_client_IntlProvider = require('./client/IntlProvider.cjs');
|
|
6
|
+
const require_client_useLocale = require('./client/useLocale.cjs');
|
|
7
|
+
const require_client_useTranslations = require('./client/useTranslations.cjs');
|
|
8
|
+
const require_client_index = require('./client/index.cjs');
|
|
3
9
|
const require_core_createFormatter = require('./core/createFormatter.cjs');
|
|
4
10
|
const require_core_createTranslator = require('./core/createTranslator.cjs');
|
|
5
11
|
const require_core_errors = require('./core/errors.cjs');
|
|
6
12
|
const require_core_hasLocale = require('./core/hasLocale.cjs');
|
|
7
13
|
const require_core_initializeConfig = require('./core/initializeConfig.cjs');
|
|
8
|
-
const require_react_IntlProvider = require('./react/IntlProvider.cjs');
|
|
9
|
-
const require_react_helpers = require('./react/helpers.cjs');
|
|
10
|
-
const require_react_useLocale = require('./react/useLocale.cjs');
|
|
11
|
-
const require_react_useTranslations = require('./react/useTranslations.cjs');
|
|
12
|
-
const require_useDictionary = require('./useDictionary.cjs');
|
|
13
|
-
const require_react_index = require('./react/index.cjs');
|
|
14
14
|
|
|
15
15
|
exports.IntlError = require_core_errors.IntlError;
|
|
16
16
|
exports.IntlErrorCode = require_core_errors.IntlErrorCode;
|
|
17
|
-
exports.IntlProvider =
|
|
18
|
-
exports._useExtracted =
|
|
17
|
+
exports.IntlProvider = require_client_IntlProvider.IntlProvider;
|
|
18
|
+
exports._useExtracted = require_client_index._useExtracted;
|
|
19
19
|
exports.createFormatter = require_core_createFormatter.createFormatter;
|
|
20
20
|
exports.createTranslator = require_core_createTranslator.createTranslator;
|
|
21
21
|
exports.hasLocale = require_core_hasLocale.hasLocale;
|
|
22
22
|
exports.initializeConfig = require_core_initializeConfig.initializeConfig;
|
|
23
23
|
exports.useDictionary = require_useDictionary.useDictionary;
|
|
24
24
|
exports.useDictionaryDynamic = require_useDictionaryDynamic.useDictionaryDynamic;
|
|
25
|
-
exports.useFormatter =
|
|
26
|
-
exports.useLocale =
|
|
27
|
-
exports.useMessages =
|
|
28
|
-
exports.useNow =
|
|
29
|
-
exports.useTimeZone =
|
|
30
|
-
exports.useTranslations =
|
|
25
|
+
exports.useFormatter = require_client_helpers.useFormatter;
|
|
26
|
+
exports.useLocale = require_client_useLocale.useLocale;
|
|
27
|
+
exports.useMessages = require_client_helpers.useMessages;
|
|
28
|
+
exports.useNow = require_client_helpers.useNow;
|
|
29
|
+
exports.useTimeZone = require_client_helpers.useTimeZone;
|
|
30
|
+
exports.useTranslations = require_client_useTranslations.useTranslations;
|
|
@@ -6,7 +6,7 @@ import { log } from "@intlayer/config/built";
|
|
|
6
6
|
import { CYAN } from "@intlayer/config/colors";
|
|
7
7
|
import { colorize, getAppLogger } from "@intlayer/config/logger";
|
|
8
8
|
|
|
9
|
-
//#region src/
|
|
9
|
+
//#region src/client/IntlProvider.tsx
|
|
10
10
|
/**
|
|
11
11
|
* Drop-in for use-intl's `IntlProvider`.
|
|
12
12
|
*
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IntlProvider.mjs","names":[],"sources":["../../../src/client/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 type { ComponentProps } from 'react';\nimport { IntlayerProvider } from 'react-intlayer';\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 key={String(locale)} locale={locale as LocalesValues}>\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;CACJ,IAEE,OAAO,cAAc,aAGrB,AADkB,aAAa,EAAE,IAAI,CAC7B,CAAC,CACP,GAAG,SAAS,gBAAgB,IAAI,EAAE,8HACpC;CAKF,OACE,oBAAC,kBAAD;EAA+C;EAC5C;CACe,GAFK,OAAO,MAAM,CAElB;AAEtB"}
|
|
@@ -6,7 +6,7 @@ import { log } from "@intlayer/config/built";
|
|
|
6
6
|
import { CYAN } from "@intlayer/config/colors";
|
|
7
7
|
import { colorize, getAppLogger } from "@intlayer/config/logger";
|
|
8
8
|
|
|
9
|
-
//#region src/
|
|
9
|
+
//#region src/client/helpers.ts
|
|
10
10
|
/**
|
|
11
11
|
* Drop-in for use-intl's `useNow`.
|
|
12
12
|
* Returns the current `Date`. The `updateInterval` option is ignored.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.mjs","names":["useLocaleIntlayer"],"sources":["../../../src/client/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,KAAK;;;;;AAMrD,MAAa,oBACX,KAAK,eAAe,CAAC,CAAC,gBAAgB,CAAC,CAAC;;;;;;;;AAS1C,MAAa,oBAAyC;CAGlD,AADkB,aAAa,EAAE,IAAI,CAC7B,CAAC,CACP,GAAG,SAAS,eAAe,IAAI,EAAE,gHACnC;CAGF,OAAO,CAAC;AACV;;;;;;;AAQA,MAAa,qBAA2C;CACtD,MAAM,EAAE,WAAWA,UAAkB;CACrC,OAAO,mBAAoB,UAAqB,IAAI;AACtD"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { useDictionaryDynamic } from "../useDictionaryDynamic.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { useDictionary } from "../useDictionary.mjs";
|
|
3
3
|
import { useFormatter, useMessages, useNow, useTimeZone } from "./helpers.mjs";
|
|
4
|
+
import { IntlProvider } from "./IntlProvider.mjs";
|
|
4
5
|
import { useLocale } from "./useLocale.mjs";
|
|
5
6
|
import { useTranslations } from "./useTranslations.mjs";
|
|
6
|
-
import { useDictionary } from "../useDictionary.mjs";
|
|
7
7
|
|
|
8
|
-
//#region src/
|
|
8
|
+
//#region src/client/index.ts
|
|
9
9
|
/**
|
|
10
10
|
* @internal Private use-intl export, kept so aliased `_useExtracted` imports
|
|
11
11
|
* resolve. Not part of the supported public surface.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/client/index.ts"],"sourcesContent":["export { useDictionary } from '../useDictionary';\nexport { useDictionaryDynamic } from '../useDictionaryDynamic';\nexport { useFormatter, useMessages, useNow, useTimeZone } from './helpers';\nexport { IntlProvider, type IntlProviderProps } from './IntlProvider';\nexport { useLocale } from './useLocale';\nexport { useTranslations } from './useTranslations';\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,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useLocale.mjs","names":["useLocaleIntlayer"],"sources":["../../../src/client/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,WAAWA,YAAkB;CACrC,OAAO;AACT"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import { createNamespaceTranslator } from "../shared/namespaceTranslator.mjs";
|
|
4
|
-
import { IntlayerClientContext } from "react-intlayer";
|
|
5
4
|
import { useContext, useMemo } from "react";
|
|
5
|
+
import { IntlayerClientContext } from "react-intlayer";
|
|
6
6
|
|
|
7
|
-
//#region src/
|
|
7
|
+
//#region src/client/useTranslations.ts
|
|
8
8
|
/**
|
|
9
9
|
* Drop-in for use-intl's `useTranslations`.
|
|
10
10
|
*
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTranslations.mjs","names":[],"sources":["../../../src/client/useTranslations.ts"],"sourcesContent":["'use client';\n\nimport type {\n DictionaryKeys,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { useContext, useMemo } from 'react';\nimport { IntlayerClientContext } from 'react-intlayer';\nimport { createNamespaceTranslator } from '../shared/namespaceTranslator';\nimport type {\n LooseTranslateFunction,\n TranslateFunction,\n TranslateFunctionForNamespace,\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 * dot-paths under the scope, typed against the dictionary, matching\n * 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 <N extends `${string}.${string}`>(\n namespace: N\n ): TranslateFunctionForNamespace<N>;\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuDA,MAAa,oBAAoB,cAAuB;CACtD,MAAM,EAAE,QAAQ,kBAAkB,WAAW,qBAAqB,KAAK,CAAC;CAExE,OAAO,cACC,0BAA0B,eAAgC,SAAS,GACzE,CAAC,eAAe,SAAS,CAC3B;AACF"}
|
|
@@ -1 +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,
|
|
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,MAAM"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createTranslator.mjs","names":[],"sources":["../../../src/core/createTranslator.ts"],"sourcesContent":["import { log } from '@intlayer/config/built';\nimport { CYAN } from '@intlayer/config/colors';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport type {\n DictionaryKeys,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { createNamespaceTranslator } from '../shared/namespaceTranslator';\nimport type {\n LooseTranslateFunction,\n TranslateFunction,\n} from '../shared/translateFunctionTypes';\n\n/**\n * Configuration accepted by {@link createTranslator}.\n *\n * Mirrors use-intl's `IntlConfig`, but `messages`, `formats`, `now`,\n * `timeZone`, `onError`, and `getMessageFallback` have no effect — Intlayer\n * resolves content from its own compiled dictionaries.\n */\nexport type CreateTranslatorConfig<N extends DictionaryKeys> = {\n /** The locale dictionaries are resolved for. */\n locale: LocalesValues;\n /** A bare dictionary key, or a nested `'dictionary.scope'` namespace. */\n namespace?: N | (string & {});\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} & Record<string, unknown>;\n\n/**\n * Overload set for {@link createTranslator}:\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 *
|
|
1
|
+
{"version":3,"file":"createTranslator.mjs","names":[],"sources":["../../../src/core/createTranslator.ts"],"sourcesContent":["import { log } from '@intlayer/config/built';\nimport { CYAN } from '@intlayer/config/colors';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport type {\n DictionaryKeys,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { createNamespaceTranslator } from '../shared/namespaceTranslator';\nimport type {\n LooseTranslateFunction,\n TranslateFunction,\n TranslateFunctionForNamespace,\n} from '../shared/translateFunctionTypes';\n\n/**\n * Configuration accepted by {@link createTranslator}.\n *\n * Mirrors use-intl's `IntlConfig`, but `messages`, `formats`, `now`,\n * `timeZone`, `onError`, and `getMessageFallback` have no effect — Intlayer\n * resolves content from its own compiled dictionaries.\n */\nexport type CreateTranslatorConfig<N extends DictionaryKeys> = {\n /** The locale dictionaries are resolved for. */\n locale: LocalesValues;\n /** A bare dictionary key, or a nested `'dictionary.scope'` namespace. */\n namespace?: N | (string & {});\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} & Record<string, unknown>;\n\n/**\n * Overload set for {@link createTranslator}:\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 * dot-paths under the scope, typed against the dictionary, matching\n * 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 CreateTranslator = {\n <N extends DictionaryKeys>(\n config: CreateTranslatorConfig<N> & { namespace: N }\n ): TranslateFunction<N>;\n <N extends `${string}.${string}`>(\n config: CreateTranslatorConfig<DictionaryKeys> & { namespace: N }\n ): TranslateFunctionForNamespace<N>;\n (config: CreateTranslatorConfig<DictionaryKeys>): LooseTranslateFunction;\n};\n\n/**\n * Drop-in for use-intl's `createTranslator`.\n *\n * Returns a translate function (with `rich`, `markup`, `raw`, `has`) that\n * resolves messages from Intlayer's compiled dictionaries for the given\n * `locale`. Messages support ICU MessageFormat syntax.\n *\n * @example\n * ```ts\n * const t = createTranslator({ locale: 'en', namespace: 'about' });\n * t('counter.label'); // ✓ typed\n * t('items', { count: 3 }); // ICU plural\n * ```\n */\nexport const createTranslator = (({\n locale,\n namespace,\n messages: _messages,\n}: CreateTranslatorConfig<DictionaryKeys>) => {\n if (process.env.NODE_ENV === 'development' && _messages !== undefined) {\n const appLogger = getAppLogger({ log });\n appLogger(\n `${colorize('createTranslator', CYAN)} do not pass the messages option with intlayer. Messages are loaded automatically under the hood for bundle optimization reason`\n );\n }\n\n return createNamespaceTranslator(locale, namespace);\n}) as CreateTranslator;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAmEA,MAAa,qBAAqB,EAChC,QACA,WACA,UAAU,gBACkC;CAC5C,IAA8C,cAAc,QAE1D,AADkB,aAAa,EAAE,IAAI,CAC7B,CAAC,CACP,GAAG,SAAS,oBAAoB,IAAI,EAAE,gIACxC;CAGF,OAAO,0BAA0B,QAAQ,SAAS;AACpD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.mjs","names":[],"sources":["../../../src/core/errors.ts"],"sourcesContent":["/**\n * Drop-in for use-intl's `IntlErrorCode` enum.\n *\n * Re-implemented locally (rather than re-exported) because `use-intl` is\n * aliased to this package at build time, so importing its runtime value would\n * be circular.\n */\nexport enum IntlErrorCode {\n MISSING_MESSAGE = 'MISSING_MESSAGE',\n MISSING_FORMAT = 'MISSING_FORMAT',\n ENVIRONMENT_FALLBACK = 'ENVIRONMENT_FALLBACK',\n INSUFFICIENT_PATH = 'INSUFFICIENT_PATH',\n INVALID_MESSAGE = 'INVALID_MESSAGE',\n INVALID_KEY = 'INVALID_KEY',\n FORMATTING_ERROR = 'FORMATTING_ERROR',\n}\n\n/**\n * Drop-in for use-intl's `IntlError`.\n *\n * Carries the {@link IntlErrorCode} and the original message, matching\n * use-intl's error shape so consumer `onError` handlers keep working.\n */\nexport class IntlError extends Error {\n public readonly code: IntlErrorCode;\n public readonly originalMessage: string | undefined;\n\n constructor(code: IntlErrorCode, originalMessage?: string) {\n let message: string = code;\n if (originalMessage) {\n message += `: ${originalMessage}`;\n }\n super(message);\n\n this.code = code;\n if (originalMessage) {\n this.originalMessage = originalMessage;\n }\n }\n}\n"],"mappings":";;;;;;;;AAOA,IAAY,gBAAL;
|
|
1
|
+
{"version":3,"file":"errors.mjs","names":[],"sources":["../../../src/core/errors.ts"],"sourcesContent":["/**\n * Drop-in for use-intl's `IntlErrorCode` enum.\n *\n * Re-implemented locally (rather than re-exported) because `use-intl` is\n * aliased to this package at build time, so importing its runtime value would\n * be circular.\n */\nexport enum IntlErrorCode {\n MISSING_MESSAGE = 'MISSING_MESSAGE',\n MISSING_FORMAT = 'MISSING_FORMAT',\n ENVIRONMENT_FALLBACK = 'ENVIRONMENT_FALLBACK',\n INSUFFICIENT_PATH = 'INSUFFICIENT_PATH',\n INVALID_MESSAGE = 'INVALID_MESSAGE',\n INVALID_KEY = 'INVALID_KEY',\n FORMATTING_ERROR = 'FORMATTING_ERROR',\n}\n\n/**\n * Drop-in for use-intl's `IntlError`.\n *\n * Carries the {@link IntlErrorCode} and the original message, matching\n * use-intl's error shape so consumer `onError` handlers keep working.\n */\nexport class IntlError extends Error {\n public readonly code: IntlErrorCode;\n public readonly originalMessage: string | undefined;\n\n constructor(code: IntlErrorCode, originalMessage?: string) {\n let message: string = code;\n if (originalMessage) {\n message += `: ${originalMessage}`;\n }\n super(message);\n\n this.code = code;\n if (originalMessage) {\n this.originalMessage = originalMessage;\n }\n }\n}\n"],"mappings":";;;;;;;;AAOA,IAAY,gBAAL;CACL;CACA;CACA;CACA;CACA;CACA;CACA;;AACF;;;;;;;AAQA,IAAa,YAAb,cAA+B,MAAM;CACnC,AAAgB;CAChB,AAAgB;CAEhB,YAAY,MAAqB,iBAA0B;EACzD,IAAI,UAAkB;EACtB,IAAI,iBACF,WAAW,KAAK;EAElB,MAAM,OAAO;EAEb,KAAK,OAAO;EACZ,IAAI,iBACF,KAAK,kBAAkB;CAE3B;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hasLocale.mjs","names":[],"sources":["../../../src/core/hasLocale.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport type { hasLocale as _hasLocale } from 'use-intl';\n\n/**\n * Drop-in for use-intl's `hasLocale`.\n *\n * Narrows a locale candidate to the given locales list. When the list is\n * omitted, the locales configured in intlayer are used.\n *\n * @example\n * ```ts\n * if (hasLocale(['en', 'fr'], requested)) { … }\n * ```\n */\nexport const hasLocale: typeof _hasLocale = ((\n locales: readonly string[],\n candidate: unknown\n): boolean => {\n const availableLocales =\n locales ?? internationalization?.locales?.map(String) ?? [];\n return availableLocales.includes(candidate as string);\n}) as typeof _hasLocale;\n"],"mappings":";;;;;;;;;;;;;;AAcA,MAAa,cACX,SACA,cACY;
|
|
1
|
+
{"version":3,"file":"hasLocale.mjs","names":[],"sources":["../../../src/core/hasLocale.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport type { hasLocale as _hasLocale } from 'use-intl';\n\n/**\n * Drop-in for use-intl's `hasLocale`.\n *\n * Narrows a locale candidate to the given locales list. When the list is\n * omitted, the locales configured in intlayer are used.\n *\n * @example\n * ```ts\n * if (hasLocale(['en', 'fr'], requested)) { … }\n * ```\n */\nexport const hasLocale: typeof _hasLocale = ((\n locales: readonly string[],\n candidate: unknown\n): boolean => {\n const availableLocales =\n locales ?? internationalization?.locales?.map(String) ?? [];\n return availableLocales.includes(candidate as string);\n}) as typeof _hasLocale;\n"],"mappings":";;;;;;;;;;;;;;AAcA,MAAa,cACX,SACA,cACY;CAGZ,QADE,WAAW,sBAAsB,SAAS,IAAI,MAAM,KAAK,CAAC,EACrC,CAAC,SAAS,SAAmB;AACtD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initializeConfig.mjs","names":[],"sources":["../../../src/core/initializeConfig.ts"],"sourcesContent":["import type { initializeConfig as _initializeConfig } from 'use-intl';\n\n/**\n * Drop-in for use-intl's `initializeConfig`.\n *\n * Enhances an incoming config with defaults. With intlayer, `messages` and\n * `formats` are not consumed at runtime (content comes from compiled\n * dictionaries) but the shape is preserved so callers keep type-checking.\n */\nexport const initializeConfig: typeof _initializeConfig = ({\n formats,\n getMessageFallback,\n messages,\n onError,\n ...rest\n}) => {\n const finalOnError = onError ?? ((error) => error);\n const finalGetMessageFallback =\n getMessageFallback
|
|
1
|
+
{"version":3,"file":"initializeConfig.mjs","names":[],"sources":["../../../src/core/initializeConfig.ts"],"sourcesContent":["import type { initializeConfig as _initializeConfig } from 'use-intl';\n\n/**\n * Drop-in for use-intl's `initializeConfig`.\n *\n * Enhances an incoming config with defaults. With intlayer, `messages` and\n * `formats` are not consumed at runtime (content comes from compiled\n * dictionaries) but the shape is preserved so callers keep type-checking.\n */\nexport const initializeConfig: typeof _initializeConfig = ({\n formats,\n getMessageFallback,\n messages,\n onError,\n ...rest\n}) => {\n const finalOnError = onError ?? ((error) => error);\n const finalGetMessageFallback =\n getMessageFallback ??\n (({ key, namespace }) => [namespace, key].filter(Boolean).join('.'));\n\n return {\n ...rest,\n formats: formats || undefined,\n messages: messages || undefined,\n onError: finalOnError,\n getMessageFallback: finalGetMessageFallback,\n };\n};\n"],"mappings":";;;;;;;;AASA,MAAa,oBAA8C,EACzD,SACA,oBACA,UACA,SACA,GAAG,WACC;CACJ,MAAM,eAAe,aAAa,UAAU;CAC5C,MAAM,0BACJ,wBACE,EAAE,KAAK,gBAAgB,CAAC,WAAW,GAAG,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG;CAEpE,OAAO;EACL,GAAG;EACH,SAAS,WAAW;EACpB,UAAU,YAAY;EACtB,SAAS;EACT,oBAAoB;CACtB;AACF"}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
+
import { createDictionaryTranslator } from "./shared/namespaceTranslator.mjs";
|
|
1
2
|
import { useDictionaryDynamic } from "./useDictionaryDynamic.mjs";
|
|
3
|
+
import { useDictionary } from "./useDictionary.mjs";
|
|
4
|
+
import { useFormatter, useMessages, useNow, useTimeZone } from "./client/helpers.mjs";
|
|
5
|
+
import { IntlProvider } from "./client/IntlProvider.mjs";
|
|
6
|
+
import { useLocale } from "./client/useLocale.mjs";
|
|
7
|
+
import { useTranslations } from "./client/useTranslations.mjs";
|
|
8
|
+
import { _useExtracted } from "./client/index.mjs";
|
|
2
9
|
import { createFormatter } from "./core/createFormatter.mjs";
|
|
3
10
|
import { createTranslator } from "./core/createTranslator.mjs";
|
|
4
11
|
import { IntlError, IntlErrorCode } from "./core/errors.mjs";
|
|
5
12
|
import { hasLocale } from "./core/hasLocale.mjs";
|
|
6
13
|
import { initializeConfig } from "./core/initializeConfig.mjs";
|
|
7
|
-
import { IntlProvider } from "./react/IntlProvider.mjs";
|
|
8
|
-
import { useFormatter, useMessages, useNow, useTimeZone } from "./react/helpers.mjs";
|
|
9
|
-
import { useLocale } from "./react/useLocale.mjs";
|
|
10
|
-
import { useTranslations } from "./react/useTranslations.mjs";
|
|
11
|
-
import { useDictionary } from "./useDictionary.mjs";
|
|
12
|
-
import { _useExtracted } from "./react/index.mjs";
|
|
13
14
|
|
|
14
|
-
export { IntlError, IntlErrorCode, IntlProvider, _useExtracted, createFormatter, createTranslator, hasLocale, initializeConfig, useDictionary, useDictionaryDynamic, useFormatter, useLocale, useMessages, useNow, useTimeZone, useTranslations };
|
|
15
|
+
export { IntlError, IntlErrorCode, IntlProvider, _useExtracted, createDictionaryTranslator, createFormatter, createTranslator, hasLocale, initializeConfig, useDictionary, useDictionaryDynamic, useFormatter, useLocale, useMessages, useNow, useTimeZone, useTranslations };
|
|
@@ -1,46 +1,13 @@
|
|
|
1
1
|
import * as ANSIColors from "@intlayer/config/colors";
|
|
2
2
|
import { colorize, getAppLogger } from "@intlayer/config/logger";
|
|
3
3
|
import { join } from "node:path";
|
|
4
|
-
import {
|
|
4
|
+
import { USE_INTL_CALLERS } from "@intlayer/config/callers";
|
|
5
5
|
import { getConfiguration } from "@intlayer/config/node";
|
|
6
|
+
import { runOnce } from "@intlayer/engine/utils";
|
|
6
7
|
import { intlayer } from "vite-intlayer";
|
|
7
8
|
|
|
8
9
|
//#region src/plugin/index.ts
|
|
9
10
|
/**
|
|
10
|
-
* Caller configurations for use-intl's translation entry points.
|
|
11
|
-
*
|
|
12
|
-
* Tells the intlayer field-usage analyser how to extract the dictionary key
|
|
13
|
-
* (namespace) and consumed fields from `useTranslations` / `createTranslator`
|
|
14
|
-
* call sites, enabling accurate dictionary pruning for projects using
|
|
15
|
-
* `@intlayer/use-intl`.
|
|
16
|
-
*/
|
|
17
|
-
const USE_INTL_COMPAT_CALLERS = [{
|
|
18
|
-
callerName: "useTranslations",
|
|
19
|
-
importSources: [
|
|
20
|
-
"use-intl",
|
|
21
|
-
"use-intl/react",
|
|
22
|
-
"@intlayer/use-intl"
|
|
23
|
-
],
|
|
24
|
-
namespace: {
|
|
25
|
-
from: "argument",
|
|
26
|
-
index: 0
|
|
27
|
-
},
|
|
28
|
-
translationFunction: "return-value"
|
|
29
|
-
}, {
|
|
30
|
-
callerName: "createTranslator",
|
|
31
|
-
importSources: [
|
|
32
|
-
"use-intl",
|
|
33
|
-
"use-intl/core",
|
|
34
|
-
"@intlayer/use-intl"
|
|
35
|
-
],
|
|
36
|
-
namespace: {
|
|
37
|
-
from: "option",
|
|
38
|
-
argumentIndex: 0,
|
|
39
|
-
property: "namespace"
|
|
40
|
-
},
|
|
41
|
-
translationFunction: "return-value"
|
|
42
|
-
}];
|
|
43
|
-
/**
|
|
44
11
|
* A Vite plugin for use-intl compat that wraps vite-intlayer and configures
|
|
45
12
|
* resolve aliases so `use-intl` imports are served by `@intlayer/use-intl`.
|
|
46
13
|
*
|
|
@@ -62,7 +29,7 @@ const useIntlVitePlugin = (options) => {
|
|
|
62
29
|
}, { cacheTimeoutMs: 1e3 * 60 * 60 });
|
|
63
30
|
const basePlugins = intlayer({
|
|
64
31
|
...options,
|
|
65
|
-
compatCallers: [...options?.compatCallers ?? [], ...
|
|
32
|
+
compatCallers: [...options?.compatCallers ?? [], ...USE_INTL_CALLERS]
|
|
66
33
|
});
|
|
67
34
|
const compatPlugin = {
|
|
68
35
|
name: "vite-use-intl-compat-plugin",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/plugin/index.ts"],"sourcesContent":["import { join } from 'node:path';\nimport {
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/plugin/index.ts"],"sourcesContent":["import { join } from 'node:path';\nimport { USE_INTL_CALLERS } from '@intlayer/config/callers';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport { getConfiguration } from '@intlayer/config/node';\nimport { runOnce } from '@intlayer/engine/utils';\nimport type { PluginOption } from 'vite';\nimport { intlayer } from 'vite-intlayer';\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: [...(options?.compatCallers ?? []), ...USE_INTL_CALLERS],\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":";;;;;;;;;;;;;;;;;;;;;;;AAuBA,MAAa,qBACX,YACmB;CACnB,MAAM,iBAAiB,iBAAiB;CACxC,MAAM,YAAY,aAAa,cAAc;CAE7C,QACE,KACE,eAAe,OAAO,SACtB,aACA,SACA,iCACF,SACM;EACJ,UAAU,CACR,SACE,+CACA,WAAW,IACb,GACA,SACE,iDACA,WAAW,UACb,CACF,CAAC;CACH,GACA,EACE,gBAAgB,MAAO,KAAK,GAC9B,CACF;CAEA,MAAM,cAAc,SAAS;EAC3B,GAAG;EACH,eAAe,CAAC,GAAI,SAAS,iBAAiB,CAAC,GAAI,GAAG,gBAAgB;CACxE,CAAC;CAED,MAAM,eAA6B;EACjC,MAAM;EACN,eAAe,EACb,SAAS,EACP,OAAO,EACL,YAAY,qBACd,EACF,EACF;CACF;CAEA,OAAO,CACL,GAAI,MAAM,QAAQ,WAAW,IAAI,cAAc,CAAC,WAAW,GAC3D,YACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intlFormatter.mjs","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,
|
|
1
|
+
{"version":3,"file":"intlFormatter.mjs","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,OAAQ;CACjB,CAAC,SAAS,MAAO;CACjB,CAAC,QAAQ,MAAM;CACf,CAAC,OAAO,KAAK;CACb,CAAC,QAAQ,IAAI;CACb,CAAC,UAAU,EAAE;CACb,CAAC,UAAU,CAAC;AACd;AAEA,MAAM,UAAU,UACd,iBAAiB,OAAO,QAAQ,IAAI,KAAK,KAAK;;;;;;;;;;;AAYhD,MAAa,sBAAsB,YAChC;CACC,WAAW,OAAsB,YAC/B,IAAI,KAAK,eAAe,QAAQ,OAAO,CAAC,CAAC,OAAO,KAAK;CAEvD,SAAS,OAAwB,YAC/B,IAAI,KAAK,aAAa,QAAQ,OAAO,CAAC,CAAC,OAAO,KAAK;;CAGrD,gBACE,OACA,KACA,YAEA,IAAI,KAAK,eAAe,QAAQ,OAAO,CAAC,CAAC,YACvC,OAAO,KAAK,GACZ,OAAO,GAAG,CACZ;;;;;CAMF,eACE,MACA,iBASG;EACH,MAAM,UACJ,wBAAwB,QAAQ,OAAO,iBAAiB,WACpD,EAAE,KAAK,aAAa,IACnB,gBAAgB,CAAC;EAExB,MAAM,UACJ,QAAQ,QAAQ,SAAY,OAAO,QAAQ,GAAG,oBAAI,IAAI,KAAK;EAC7D,MAAM,iBAAiB,OAAO,IAAI,CAAC,CAAC,QAAQ,IAAI,QAAQ,QAAQ,KAAK;EAErE,IAAI,OAAO,QAAQ;EACnB,IAAI,CAAC,MAAM;GACT,MAAM,eAAe,KAAK,IAAI,aAAa;GAC3C,OACE,oBAAoB,MACjB,GAAG,iBAAiB,gBAAgB,WACvC,CAAC,GAAG,MAAM;EACd;EAEA,MAAM,cACJ,oBAAoB,MAAM,CAAC,cAAc,aAAa,IAAI,CAAC,GAAG,MAAM;EAEtE,OAAO,IAAI,KAAK,mBAAmB,QAAQ;GACzC,SAAS;GACT,OAAO,QAAQ;EACjB,CAAC,CAAC,CAAC,OAAO,KAAK,MAAM,gBAAgB,WAAW,GAAG,IAAI;CACzD;;CAGA,OAAO,OAAyB,YAC9B,IAAI,KAAK,WAAW,QAAQ,OAAO,CAAC,CAAC,OAAO,KAAK;CAEnD,cACE,OACA,iBACA,iBACW;EACX,MAAM,kBACJ,OAAO,oBAAoB,WAAW,eAAe;EACvD,IAAI;GACF,OACE,IAAI,KAAK,aACP,CAAC,MAAM,GACP,mBAAmB,EAAE,MAAM,WAAW,CACxC,CAAC,CAAC,GAAG,KAAK,KAAK;EAEnB,QAAQ;GACN,OAAO;EACT;CACF;AACF"}
|
|
@@ -1,26 +1,10 @@
|
|
|
1
|
-
import { getIntlayer } from "@intlayer/core/interpreter";
|
|
2
|
-
import { parseTaggedMessage, resolveMessage } from "@intlayer/core/messageFormat";
|
|
3
1
|
import { Fragment } from "react";
|
|
2
|
+
import { getIntlayer } from "@intlayer/core/interpreter";
|
|
3
|
+
import { navigatePath, navigatePath as navigatePath$1, parseTaggedMessage, resolveMessage } from "@intlayer/core/messageFormat";
|
|
4
|
+
import { getDictionaries } from "@intlayer/dictionaries-entry";
|
|
4
5
|
import { Fragment as Fragment$1, jsx } from "react/jsx-runtime";
|
|
5
6
|
|
|
6
7
|
//#region src/shared/namespaceTranslator.tsx
|
|
7
|
-
/**
|
|
8
|
-
* Reads a dotted `path` (e.g. `counter.label`) out of a nested object value.
|
|
9
|
-
*
|
|
10
|
-
* @param objectValue - The object to read from.
|
|
11
|
-
* @param path - Dot-separated path. An empty path returns `objectValue`.
|
|
12
|
-
* @returns The value found at `path`, or `undefined` when any segment is absent.
|
|
13
|
-
*/
|
|
14
|
-
const navigatePath = (objectValue, path) => {
|
|
15
|
-
if (!path) return objectValue;
|
|
16
|
-
const parts = path.split(".");
|
|
17
|
-
let current = objectValue;
|
|
18
|
-
for (const part of parts) {
|
|
19
|
-
if (current === null || current === void 0 || typeof current !== "object") return;
|
|
20
|
-
current = current[part];
|
|
21
|
-
}
|
|
22
|
-
return current;
|
|
23
|
-
};
|
|
24
8
|
/** Splits rich values into scalar interpolation values and tag renderers. */
|
|
25
9
|
const splitRichValues = (values = {}) => {
|
|
26
10
|
const scalarValues = {};
|
|
@@ -65,26 +49,63 @@ const renderMarkupTokens = (tokens, renderers) => tokens.map((token) => {
|
|
|
65
49
|
const createNamespaceTranslator = (locale, namespace) => {
|
|
66
50
|
const [dictionaryKey, ...prefixSegments] = (namespace ?? "").split(".");
|
|
67
51
|
const keyPrefix = prefixSegments.join(".");
|
|
68
|
-
const lookup = (
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
52
|
+
const lookup = (lookupKey) => lookupNamespaceKey(locale, dictionaryKey ?? "", keyPrefix, lookupKey);
|
|
53
|
+
return createLookupTranslator(locale, lookup, (key) => namespace ? `${namespace}.${key}` : key);
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Key-based lookup used by {@link createNamespaceTranslator}: resolves the
|
|
57
|
+
* dictionary through the runtime registry (`getIntlayer`).
|
|
58
|
+
*/
|
|
59
|
+
const lookupNamespaceKey = (locale, dictionaryKey, keyPrefix, key) => {
|
|
60
|
+
let targetDictionaryKey = dictionaryKey;
|
|
61
|
+
let path = keyPrefix ? `${keyPrefix}.${key}` : key;
|
|
62
|
+
const dictionaries = getDictionaries();
|
|
63
|
+
if (!targetDictionaryKey) {
|
|
64
|
+
const [firstSegment, ...restSegments] = key.split(".");
|
|
65
|
+
targetDictionaryKey = firstSegment ?? key;
|
|
66
|
+
path = restSegments.join(".");
|
|
67
|
+
if (!dictionaries[targetDictionaryKey]) for (const dictKey of Object.keys(dictionaries)) try {
|
|
68
|
+
const result = navigatePath$1(getIntlayer(dictKey, locale), key);
|
|
69
|
+
if (result !== void 0) return result;
|
|
70
|
+
} catch {}
|
|
71
|
+
}
|
|
72
|
+
try {
|
|
73
|
+
return navigatePath$1(getIntlayer(targetDictionaryKey, locale), path);
|
|
74
|
+
} catch {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* Dictionary-bound translator used by the build-optimized `useDictionary` /
|
|
80
|
+
* `getDictionary` variants: instead of resolving the dictionary by key at
|
|
81
|
+
* runtime, the pre-resolved content is supplied directly (the babel/swc
|
|
82
|
+
* optimize pass imports the dictionary JSON at build time).
|
|
83
|
+
*
|
|
84
|
+
* @param locale - The locale messages are resolved for.
|
|
85
|
+
* @param content - The dictionary content, already resolved for `locale`.
|
|
86
|
+
* @param namespacePrefix - Optional key prefix for nested namespaces
|
|
87
|
+
* (`useTranslations('about.counter')` → content of `about`, prefix `counter`).
|
|
88
|
+
* @returns A translate function augmented with `has`, `raw`, `rich`, `markup`.
|
|
89
|
+
*/
|
|
90
|
+
const createDictionaryTranslator = (locale, content, namespacePrefix) => {
|
|
91
|
+
const resolveKey = (key) => namespacePrefix ? `${namespacePrefix}.${key}` : key;
|
|
92
|
+
return createLookupTranslator(locale, (key) => navigatePath$1(content, resolveKey(key)), resolveKey);
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* The untyped runtime translator core shared by every factory above:
|
|
96
|
+
* ICU message resolution plus the `has` / `raw` / `rich` / `markup` helpers.
|
|
97
|
+
*
|
|
98
|
+
* @param locale - The locale messages are resolved for.
|
|
99
|
+
* @param lookup - Reads the raw content value for a message key.
|
|
100
|
+
* @param missingKeyFallback - Builds the echoed key on lookup miss
|
|
101
|
+
* (use-intl convention: `namespace.key`).
|
|
102
|
+
*/
|
|
103
|
+
const createLookupTranslator = (locale, lookup, missingKeyFallback) => {
|
|
82
104
|
const resolveToString = (key, values = {}) => {
|
|
83
105
|
const rawValue = lookup(key);
|
|
84
106
|
if (rawValue === null || rawValue === void 0) return void 0;
|
|
85
107
|
return resolveMessage(rawValue, values, locale, "icu");
|
|
86
108
|
};
|
|
87
|
-
const missingKeyFallback = (key) => namespace ? `${namespace}.${key}` : key;
|
|
88
109
|
const translate = (key, values) => resolveToString(key, values) ?? missingKeyFallback(key);
|
|
89
110
|
return Object.assign(translate, {
|
|
90
111
|
/** Returns `true` if the given key exists in the namespace. */
|
|
@@ -115,5 +136,5 @@ const createNamespaceTranslator = (locale, namespace) => {
|
|
|
115
136
|
};
|
|
116
137
|
|
|
117
138
|
//#endregion
|
|
118
|
-
export { createNamespaceTranslator, navigatePath };
|
|
139
|
+
export { createDictionaryTranslator, createNamespaceTranslator, navigatePath };
|
|
119
140
|
//# sourceMappingURL=namespaceTranslator.mjs.map
|