preact-intlayer 8.12.4 → 9.0.0-canary.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/client/useDictionary.cjs +14 -5
- package/dist/cjs/client/useDictionary.cjs.map +1 -1
- package/dist/cjs/client/useDictionaryDynamic.cjs +24 -6
- package/dist/cjs/client/useDictionaryDynamic.cjs.map +1 -1
- package/dist/cjs/client/useIntlayer.cjs +16 -5
- package/dist/cjs/client/useIntlayer.cjs.map +1 -1
- package/dist/cjs/getDictionary.cjs +8 -1
- package/dist/cjs/getDictionary.cjs.map +1 -1
- package/dist/cjs/getIntlayer.cjs +8 -1
- package/dist/cjs/getIntlayer.cjs.map +1 -1
- package/dist/esm/client/useDictionary.mjs +14 -5
- package/dist/esm/client/useDictionary.mjs.map +1 -1
- package/dist/esm/client/useDictionaryDynamic.mjs +25 -7
- package/dist/esm/client/useDictionaryDynamic.mjs.map +1 -1
- package/dist/esm/client/useIntlayer.mjs +16 -5
- package/dist/esm/client/useIntlayer.mjs.map +1 -1
- package/dist/esm/getDictionary.mjs +8 -1
- package/dist/esm/getDictionary.mjs.map +1 -1
- package/dist/esm/getIntlayer.mjs +8 -1
- package/dist/esm/getIntlayer.mjs.map +1 -1
- package/dist/types/client/useContent.d.ts +2 -2
- package/dist/types/client/useContent.d.ts.map +1 -1
- package/dist/types/client/useDictionary.d.ts +6 -4
- package/dist/types/client/useDictionary.d.ts.map +1 -1
- package/dist/types/client/useDictionaryDynamic.d.ts +11 -7
- package/dist/types/client/useDictionaryDynamic.d.ts.map +1 -1
- package/dist/types/client/useIntlayer.d.ts +12 -5
- package/dist/types/client/useIntlayer.d.ts.map +1 -1
- package/dist/types/client/useLocaleBase.d.ts +3 -3
- package/dist/types/client/useLocaleBase.d.ts.map +1 -1
- package/dist/types/client/useLocaleStorage.d.ts +5 -5
- package/dist/types/client/useLocaleStorage.d.ts.map +1 -1
- package/dist/types/format/useCompact.d.ts +2 -2
- package/dist/types/format/useCompact.d.ts.map +1 -1
- package/dist/types/format/useCurrency.d.ts +2 -2
- package/dist/types/format/useCurrency.d.ts.map +1 -1
- package/dist/types/format/useList.d.ts +2 -2
- package/dist/types/format/useList.d.ts.map +1 -1
- package/dist/types/format/useNumber.d.ts +2 -2
- package/dist/types/format/useNumber.d.ts.map +1 -1
- package/dist/types/format/usePercentage.d.ts +2 -2
- package/dist/types/format/usePercentage.d.ts.map +1 -1
- package/dist/types/format/useRelativeTime.d.ts +2 -2
- package/dist/types/format/useRelativeTime.d.ts.map +1 -1
- package/dist/types/format/useUnit.d.ts +2 -2
- package/dist/types/format/useUnit.d.ts.map +1 -1
- package/dist/types/getDictionary.d.ts +8 -3
- package/dist/types/getDictionary.d.ts.map +1 -1
- package/dist/types/getIntlayer.d.ts +7 -2
- package/dist/types/getIntlayer.d.ts.map +1 -1
- package/dist/types/intlayer/dist/types/index.d.ts +4 -0
- package/package.json +8 -8
|
@@ -3,21 +3,30 @@ const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
|
3
3
|
const require_getDictionary = require('../getDictionary.cjs');
|
|
4
4
|
const require_client_IntlayerProvider = require('./IntlayerProvider.cjs');
|
|
5
5
|
let preact_hooks = require("preact/hooks");
|
|
6
|
+
let _intlayer_core_dictionaryManipulator = require("@intlayer/core/dictionaryManipulator");
|
|
6
7
|
|
|
7
8
|
//#region src/client/useDictionary.ts
|
|
8
9
|
/**
|
|
9
|
-
*
|
|
10
|
+
* Preact hook that transforms a dictionary (or qualified dictionary group) and
|
|
11
|
+
* returns the content.
|
|
10
12
|
*
|
|
11
|
-
* If the locale is not provided
|
|
13
|
+
* If the locale is not provided (directly or through the selector), it will use
|
|
14
|
+
* the locale from the client context.
|
|
12
15
|
*/
|
|
13
|
-
const useDictionary = (dictionary,
|
|
16
|
+
const useDictionary = (dictionary, localeOrSelector) => {
|
|
14
17
|
const { locale: currentLocale } = (0, preact_hooks.useContext)(require_client_IntlayerProvider.IntlayerClientContext) ?? {};
|
|
18
|
+
const isSelector = typeof localeOrSelector === "object" && localeOrSelector !== null;
|
|
19
|
+
const localeOrSelectorIdentity = isSelector ? `${localeOrSelector.locale ?? ""}|${(0, _intlayer_core_dictionaryManipulator.getDictionarySelectorCacheKey)(localeOrSelector)}` : localeOrSelector;
|
|
15
20
|
return (0, preact_hooks.useMemo)(() => {
|
|
16
|
-
return require_getDictionary.getDictionary(dictionary,
|
|
21
|
+
if (isSelector) return require_getDictionary.getDictionary(dictionary, {
|
|
22
|
+
...localeOrSelector,
|
|
23
|
+
locale: localeOrSelector.locale ?? currentLocale
|
|
24
|
+
});
|
|
25
|
+
return require_getDictionary.getDictionary(dictionary, localeOrSelector ?? currentLocale);
|
|
17
26
|
}, [
|
|
18
27
|
dictionary.key,
|
|
19
28
|
currentLocale,
|
|
20
|
-
|
|
29
|
+
localeOrSelectorIdentity
|
|
21
30
|
]);
|
|
22
31
|
};
|
|
23
32
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionary.cjs","names":["IntlayerClientContext","getDictionary"],"sources":["../../../src/client/useDictionary.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"useDictionary.cjs","names":["IntlayerClientContext","getDictionary"],"sources":["../../../src/client/useDictionary.ts"],"sourcesContent":["import { getDictionarySelectorCacheKey } from '@intlayer/core/dictionaryManipulator';\nimport type {\n Dictionary,\n DictionarySelector,\n DictionarySelectorForGroup,\n QualifiedDictionaryGroup,\n} from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { useContext, useMemo } from 'preact/hooks';\nimport { getDictionary } from '../getDictionary';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * Preact hook that transforms a dictionary (or qualified dictionary group) and\n * returns the content.\n *\n * If the locale is not provided (directly or through the selector), it will use\n * the locale from the client context.\n */\nexport const useDictionary = <\n const T extends Dictionary | QualifiedDictionaryGroup,\n const A extends\n | LocalesValues\n | DictionarySelectorForGroup<T> = DeclaredLocales,\n>(\n dictionary: T,\n localeOrSelector?: A\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext) ?? {};\n\n const isSelector =\n typeof localeOrSelector === 'object' && localeOrSelector !== null;\n\n // Stable identity of the second argument for memoization\n const localeOrSelectorIdentity = isSelector\n ? `${localeOrSelector.locale ?? ''}|${getDictionarySelectorCacheKey(localeOrSelector)}`\n : localeOrSelector;\n\n return useMemo(() => {\n if (isSelector) {\n return getDictionary(dictionary, {\n ...localeOrSelector,\n locale: localeOrSelector.locale ?? currentLocale,\n } as A);\n }\n\n const localeTarget = (localeOrSelector ?? currentLocale) as A;\n\n return getDictionary<T, A>(dictionary, localeTarget);\n }, [dictionary.key, currentLocale, localeOrSelectorIdentity]);\n};\n"],"mappings":";;;;;;;;;;;;;;;AAsBA,MAAa,iBAMX,YACA,qBACG;CACH,MAAM,EAAE,QAAQ,+CAA6BA,sDAAsB,IAAI,EAAE;CAEzE,MAAM,aACJ,OAAO,qBAAqB,YAAY,qBAAqB;CAG/D,MAAM,2BAA2B,aAC7B,GAAG,iBAAiB,UAAU,GAAG,2EAAiC,iBAAiB,KACnF;AAEJ,wCAAqB;AACnB,MAAI,WACF,QAAOC,oCAAc,YAAY;GAC/B,GAAG;GACH,QAAQ,iBAAiB,UAAU;GACpC,CAAM;AAKT,SAAOA,oCAAoB,YAFL,oBAAoB,cAEU;IACnD;EAAC,WAAW;EAAK;EAAe;EAAyB,CAAC"}
|
|
@@ -1,20 +1,38 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
3
|
const require_client_useLoadDynamic = require('./useLoadDynamic.cjs');
|
|
4
|
+
const require_getDictionary = require('../getDictionary.cjs');
|
|
4
5
|
const require_client_IntlayerProvider = require('./IntlayerProvider.cjs');
|
|
5
|
-
|
|
6
|
+
let _intlayer_config_built = require("@intlayer/config/built");
|
|
6
7
|
let preact_hooks = require("preact/hooks");
|
|
8
|
+
let _intlayer_core_dictionaryManipulator = require("@intlayer/core/dictionaryManipulator");
|
|
7
9
|
|
|
8
10
|
//#region src/client/useDictionaryDynamic.ts
|
|
9
11
|
/**
|
|
10
|
-
*
|
|
12
|
+
* Preact hook that lazily loads a dictionary and returns its content.
|
|
11
13
|
*
|
|
12
|
-
*
|
|
14
|
+
* The dictionary entry is either a plain dynamic loader map
|
|
15
|
+
* (`locale → loader`) or a qualified one (`locale → …qualifier → loader`,
|
|
16
|
+
* tagged with the qualifier dimensions). For qualified maps, only the chunk(s)
|
|
17
|
+
* the selector targets are loaded.
|
|
18
|
+
*
|
|
19
|
+
* If the locale is not provided (directly or through the selector), the client
|
|
20
|
+
* context locale is used.
|
|
13
21
|
*/
|
|
14
|
-
const useDictionaryDynamic = (dictionaryPromise, key,
|
|
22
|
+
const useDictionaryDynamic = (dictionaryPromise, key, localeOrSelector) => {
|
|
15
23
|
const { locale: currentLocale } = (0, preact_hooks.useContext)(require_client_IntlayerProvider.IntlayerClientContext) ?? {};
|
|
16
|
-
const
|
|
17
|
-
|
|
24
|
+
const { locale: selectorLocale, selector } = (0, _intlayer_core_dictionaryManipulator.parseDictionarySelector)(localeOrSelector);
|
|
25
|
+
const localeTarget = selectorLocale ?? currentLocale ?? _intlayer_config_built.internationalization.defaultLocale;
|
|
26
|
+
if ((0, _intlayer_core_dictionaryManipulator.isQualifiedDynamicLoaderMap)(dictionaryPromise)) return (0, _intlayer_core_dictionaryManipulator.resolveQualifiedDynamicContent)({
|
|
27
|
+
loaderMap: dictionaryPromise,
|
|
28
|
+
key: String(key),
|
|
29
|
+
locale: localeTarget,
|
|
30
|
+
selector,
|
|
31
|
+
loadChunk: (cacheKey, promise) => require_client_useLoadDynamic.useLoadDynamic(cacheKey, promise),
|
|
32
|
+
transform: (dictionary) => require_getDictionary.getDictionary(dictionary, localeTarget)
|
|
33
|
+
});
|
|
34
|
+
const plainLoaders = dictionaryPromise;
|
|
35
|
+
return require_getDictionary.getDictionary(require_client_useLoadDynamic.useLoadDynamic(`${String(key)}.${localeTarget}`, plainLoaders[localeTarget]?.()), localeTarget);
|
|
18
36
|
};
|
|
19
37
|
|
|
20
38
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionaryDynamic.cjs","names":["IntlayerClientContext","
|
|
1
|
+
{"version":3,"file":"useDictionaryDynamic.cjs","names":["IntlayerClientContext","internationalization","loadDynamicChunk","getDictionary"],"sources":["../../../src/client/useDictionaryDynamic.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport {\n isQualifiedDynamicLoaderMap,\n parseDictionarySelector,\n type QualifiedDynamicLoaderMap,\n resolveQualifiedDynamicContent,\n} from '@intlayer/core/dictionaryManipulator';\nimport type {\n Dictionary,\n DictionarySelector,\n} from '@intlayer/types/dictionary';\nimport type {\n DictionaryKeys,\n DictionarySelectorForKey,\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { useContext } from 'preact/hooks';\nimport { getDictionary } from '../getDictionary';\nimport { IntlayerClientContext } from './IntlayerProvider';\n// `useLoadDynamic` is a suspender cache, not a hook — aliased to a non-hook\n// name so it can be invoked in loops / conditionally (collection chunks).\nimport { useLoadDynamic as loadDynamicChunk } from './useLoadDynamic';\n\n/**\n * Preact hook that lazily loads a dictionary and returns its content.\n *\n * The dictionary entry is either a plain dynamic loader map\n * (`locale → loader`) or a qualified one (`locale → …qualifier → loader`,\n * tagged with the qualifier dimensions). For qualified maps, only the chunk(s)\n * the selector targets are loaded.\n *\n * If the locale is not provided (directly or through the selector), the client\n * context locale is used.\n */\nexport const useDictionaryDynamic = <\n const T extends Dictionary,\n const K extends DictionaryKeys,\n const A extends LocalesValues | DictionarySelectorForKey<K> = LocalesValues,\n>(\n dictionaryPromise:\n | StrictModeLocaleMap<() => Promise<T>>\n | QualifiedDynamicLoaderMap,\n key: K,\n localeOrSelector?: A\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext) ?? {};\n\n const { locale: selectorLocale, selector } =\n parseDictionarySelector<LocalesValues>(localeOrSelector);\n\n const localeTarget =\n selectorLocale ?? currentLocale ?? internationalization.defaultLocale;\n\n if (isQualifiedDynamicLoaderMap(dictionaryPromise)) {\n return resolveQualifiedDynamicContent({\n loaderMap: dictionaryPromise,\n key: String(key),\n locale: localeTarget,\n selector,\n loadChunk: (cacheKey, promise) => loadDynamicChunk(cacheKey, promise),\n transform: (dictionary) => getDictionary(dictionary, localeTarget),\n });\n }\n\n const plainLoaders = dictionaryPromise as StrictModeLocaleMap<\n () => Promise<T>\n >;\n\n const dictionary = loadDynamicChunk<T>(\n `${String(key)}.${localeTarget}`,\n plainLoaders[localeTarget as keyof typeof plainLoaders]?.() as Promise<T>\n );\n\n return getDictionary(dictionary, localeTarget);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAmCA,MAAa,wBAKX,mBAGA,KACA,qBACG;CACH,MAAM,EAAE,QAAQ,+CAA6BA,sDAAsB,IAAI,EAAE;CAEzE,MAAM,EAAE,QAAQ,gBAAgB,+EACS,iBAAiB;CAE1D,MAAM,eACJ,kBAAkB,iBAAiBC,4CAAqB;AAE1D,2EAAgC,kBAAkB,CAChD,iFAAsC;EACpC,WAAW;EACX,KAAK,OAAO,IAAI;EAChB,QAAQ;EACR;EACA,YAAY,UAAU,YAAYC,6CAAiB,UAAU,QAAQ;EACrE,YAAY,eAAeC,oCAAc,YAAY,aAAa;EACnE,CAAC;CAGJ,MAAM,eAAe;AASrB,QAAOA,oCALYD,6CACjB,GAAG,OAAO,IAAI,CAAC,GAAG,gBAClB,aAAa,iBAA8C,CAG9B,EAAE,aAAa"}
|
|
@@ -3,15 +3,20 @@ const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
|
3
3
|
const require_getIntlayer = require('../getIntlayer.cjs');
|
|
4
4
|
const require_client_IntlayerProvider = require('./IntlayerProvider.cjs');
|
|
5
5
|
let preact_hooks = require("preact/hooks");
|
|
6
|
+
let _intlayer_core_dictionaryManipulator = require("@intlayer/core/dictionaryManipulator");
|
|
6
7
|
|
|
7
8
|
//#region src/client/useIntlayer.ts
|
|
8
9
|
/**
|
|
9
10
|
* Preact hook that picks one dictionary by its key and returns its content.
|
|
10
11
|
*
|
|
11
|
-
*
|
|
12
|
+
* The second argument is either a locale or a selector object:
|
|
13
|
+
* - `{ item: 2 }` — collection item (omit `item` to get every item as array)
|
|
14
|
+
* - `{ variant: 'black-friday' }` — named variant (omit for the `default` one)
|
|
15
|
+
* - `{ id: 'prod_abc', ...metaFields }` — meta record
|
|
16
|
+
* - `locale` composes with any selector and overrides the context locale
|
|
12
17
|
*
|
|
13
18
|
* @param key - The unique key of the dictionary to retrieve.
|
|
14
|
-
* @param
|
|
19
|
+
* @param localeOrSelector - Optional locale or selector.
|
|
15
20
|
* @returns The transformed dictionary content.
|
|
16
21
|
*
|
|
17
22
|
* @example
|
|
@@ -20,19 +25,25 @@ let preact_hooks = require("preact/hooks");
|
|
|
20
25
|
*
|
|
21
26
|
* const MyComponent = () => {
|
|
22
27
|
* const content = useIntlayer('my-dictionary-key');
|
|
28
|
+
* const faq2 = useIntlayer('faq', { item: 2 });
|
|
23
29
|
*
|
|
24
30
|
* return <div>{content.myField.value}</div>;
|
|
25
31
|
* };
|
|
26
32
|
* ```
|
|
27
33
|
*/
|
|
28
|
-
const useIntlayer = (key,
|
|
34
|
+
const useIntlayer = (key, localeOrSelector) => {
|
|
29
35
|
const { locale: currentLocale } = (0, preact_hooks.useContext)(require_client_IntlayerProvider.IntlayerClientContext) ?? {};
|
|
36
|
+
const isSelector = typeof localeOrSelector === "object" && localeOrSelector !== null;
|
|
30
37
|
return (0, preact_hooks.useMemo)(() => {
|
|
31
|
-
return require_getIntlayer.getIntlayer(key,
|
|
38
|
+
if (isSelector) return require_getIntlayer.getIntlayer(key, {
|
|
39
|
+
...localeOrSelector,
|
|
40
|
+
locale: localeOrSelector.locale ?? currentLocale
|
|
41
|
+
});
|
|
42
|
+
return require_getIntlayer.getIntlayer(key, localeOrSelector ?? currentLocale);
|
|
32
43
|
}, [
|
|
33
44
|
key,
|
|
34
45
|
currentLocale,
|
|
35
|
-
locale
|
|
46
|
+
isSelector ? `${localeOrSelector.locale ?? ""}|${(0, _intlayer_core_dictionaryManipulator.getDictionarySelectorCacheKey)(localeOrSelector)}` : localeOrSelector
|
|
36
47
|
]);
|
|
37
48
|
};
|
|
38
49
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIntlayer.cjs","names":["IntlayerClientContext","getIntlayer"],"sources":["../../../src/client/useIntlayer.ts"],"sourcesContent":["import type {\n DictionaryKeys,\n
|
|
1
|
+
{"version":3,"file":"useIntlayer.cjs","names":["IntlayerClientContext","getIntlayer"],"sources":["../../../src/client/useIntlayer.ts"],"sourcesContent":["import { getDictionarySelectorCacheKey } from '@intlayer/core/dictionaryManipulator';\nimport type { DictionarySelector } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n DictionarySelectorForKey,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { useContext, useMemo } from 'preact/hooks';\nimport { getIntlayer } from '../getIntlayer';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * Preact hook that picks one dictionary by its key and returns its content.\n *\n * The second argument is either a locale or a selector object:\n * - `{ item: 2 }` — collection item (omit `item` to get every item as array)\n * - `{ variant: 'black-friday' }` — named variant (omit for the `default` one)\n * - `{ id: 'prod_abc', ...metaFields }` — meta record\n * - `locale` composes with any selector and overrides the context locale\n *\n * @param key - The unique key of the dictionary to retrieve.\n * @param localeOrSelector - Optional locale or selector.\n * @returns The transformed dictionary content.\n *\n * @example\n * ```tsx\n * import { useIntlayer } from 'preact-intlayer';\n *\n * const MyComponent = () => {\n * const content = useIntlayer('my-dictionary-key');\n * const faq2 = useIntlayer('faq', { item: 2 });\n *\n * return <div>{content.myField.value}</div>;\n * };\n * ```\n */\nexport const useIntlayer = <\n const T extends DictionaryKeys,\n const A extends LocalesValues | DictionarySelectorForKey<T> = DeclaredLocales,\n>(\n key: T,\n localeOrSelector?: A\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext) ?? {};\n\n const isSelector =\n typeof localeOrSelector === 'object' && localeOrSelector !== null;\n\n // Stable identity of the second argument for memoization\n const localeOrSelectorIdentity = isSelector\n ? `${localeOrSelector.locale ?? ''}|${getDictionarySelectorCacheKey(localeOrSelector)}`\n : localeOrSelector;\n\n return useMemo(() => {\n if (isSelector) {\n return getIntlayer(key, {\n ...localeOrSelector,\n locale: localeOrSelector.locale ?? currentLocale,\n } as A);\n }\n\n const localeTarget = (localeOrSelector ?? currentLocale) as A;\n\n return getIntlayer<T, A>(key, localeTarget);\n }, [key, currentLocale, localeOrSelectorIdentity]);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCA,MAAa,eAIX,KACA,qBACG;CACH,MAAM,EAAE,QAAQ,+CAA6BA,sDAAsB,IAAI,EAAE;CAEzE,MAAM,aACJ,OAAO,qBAAqB,YAAY,qBAAqB;AAO/D,wCAAqB;AACnB,MAAI,WACF,QAAOC,gCAAY,KAAK;GACtB,GAAG;GACH,QAAQ,iBAAiB,UAAU;GACpC,CAAM;AAKT,SAAOA,gCAAkB,KAFH,oBAAoB,cAEC;IAC1C;EAAC;EAAK;EAfwB,aAC7B,GAAG,iBAAiB,UAAU,GAAG,2EAAiC,iBAAiB,KACnF;EAa6C,CAAC"}
|
|
@@ -4,7 +4,14 @@ const require_plugins = require('./plugins.cjs');
|
|
|
4
4
|
let _intlayer_core_interpreter = require("@intlayer/core/interpreter");
|
|
5
5
|
|
|
6
6
|
//#region src/getDictionary.ts
|
|
7
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Transforms a dictionary (or qualified dictionary group) and returns its
|
|
9
|
+
* content for the given locale or selector (`{ item }`, `{ variant }`,
|
|
10
|
+
* `{ id, ...meta }`, optionally combined with `locale`).
|
|
11
|
+
*/
|
|
12
|
+
const getDictionary = (dictionary, localeOrSelector) => {
|
|
13
|
+
return (0, _intlayer_core_interpreter.getDictionary)(dictionary, localeOrSelector, require_plugins.getPlugins(typeof localeOrSelector === "object" && localeOrSelector !== null ? localeOrSelector.locale : localeOrSelector));
|
|
14
|
+
};
|
|
8
15
|
|
|
9
16
|
//#endregion
|
|
10
17
|
exports.getDictionary = getDictionary;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getDictionary.cjs","names":["getPlugins"],"sources":["../../src/getDictionary.ts"],"sourcesContent":["import { getDictionary as getDictionaryCore } from '@intlayer/core/interpreter';\nimport type {
|
|
1
|
+
{"version":3,"file":"getDictionary.cjs","names":["getPlugins"],"sources":["../../src/getDictionary.ts"],"sourcesContent":["import { getDictionary as getDictionaryCore } from '@intlayer/core/interpreter';\nimport type {\n Dictionary,\n DictionarySelector,\n DictionarySelectorForGroup,\n QualifiedDictionaryGroup,\n ResolveQualifiedDictionaryContent,\n} from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n ExtractSelectorLocale,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { type DeepTransformContent, getPlugins } from './plugins';\n\n/**\n * Transforms a dictionary (or qualified dictionary group) and returns its\n * content for the given locale or selector (`{ item }`, `{ variant }`,\n * `{ id, ...meta }`, optionally combined with `locale`).\n */\nexport const getDictionary = <\n const T extends Dictionary | QualifiedDictionaryGroup,\n const A extends\n | LocalesValues\n | DictionarySelectorForGroup<T> = DeclaredLocales,\n>(\n dictionary: T,\n localeOrSelector?: A\n): DeepTransformContent<\n ResolveQualifiedDictionaryContent<T, A>,\n ExtractSelectorLocale<A>\n> => {\n const locale = (\n typeof localeOrSelector === 'object' && localeOrSelector !== null\n ? localeOrSelector.locale\n : localeOrSelector\n ) as LocalesValues | undefined;\n\n return getDictionaryCore(\n dictionary,\n localeOrSelector,\n getPlugins(locale)\n ) as any;\n};\n"],"mappings":";;;;;;;;;;;AAoBA,MAAa,iBAMX,YACA,qBAIG;AAOH,sDACE,YACA,kBACAA,2BARA,OAAO,qBAAqB,YAAY,qBAAqB,OACzD,iBAAiB,SACjB,iBAMc,CACnB"}
|
package/dist/cjs/getIntlayer.cjs
CHANGED
|
@@ -4,7 +4,14 @@ const require_plugins = require('./plugins.cjs');
|
|
|
4
4
|
let _intlayer_core_interpreter = require("@intlayer/core/interpreter");
|
|
5
5
|
|
|
6
6
|
//#region src/getIntlayer.ts
|
|
7
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Picks one dictionary by its key and returns its content for the given
|
|
9
|
+
* locale or selector (`{ item }`, `{ variant }`, `{ id, ...meta }`,
|
|
10
|
+
* optionally combined with `locale`).
|
|
11
|
+
*/
|
|
12
|
+
const getIntlayer = (key, localeOrSelector) => {
|
|
13
|
+
return (0, _intlayer_core_interpreter.getIntlayer)(key, localeOrSelector, require_plugins.getPlugins(typeof localeOrSelector === "object" && localeOrSelector !== null ? localeOrSelector.locale : localeOrSelector));
|
|
14
|
+
};
|
|
8
15
|
|
|
9
16
|
//#endregion
|
|
10
17
|
exports.getIntlayer = getIntlayer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getIntlayer.cjs","names":["getPlugins"],"sources":["../../src/getIntlayer.ts"],"sourcesContent":["import { getIntlayer as getIntlayerCore } from '@intlayer/core/interpreter';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n
|
|
1
|
+
{"version":3,"file":"getIntlayer.cjs","names":["getPlugins"],"sources":["../../src/getIntlayer.ts"],"sourcesContent":["import { getIntlayer as getIntlayerCore } from '@intlayer/core/interpreter';\nimport type { DictionarySelector } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n DictionaryRegistryResult,\n DictionarySelectorForKey,\n ExtractSelectorLocale,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { type DeepTransformContent, getPlugins } from './plugins';\n\n/**\n * Picks one dictionary by its key and returns its content for the given\n * locale or selector (`{ item }`, `{ variant }`, `{ id, ...meta }`,\n * optionally combined with `locale`).\n */\nexport const getIntlayer = <\n const T extends DictionaryKeys,\n const A extends LocalesValues | DictionarySelectorForKey<T> = DeclaredLocales,\n>(\n key: T,\n localeOrSelector?: A\n): DeepTransformContent<\n DictionaryRegistryResult<T, A>,\n ExtractSelectorLocale<A>\n> => {\n const locale = (\n typeof localeOrSelector === 'object' && localeOrSelector !== null\n ? localeOrSelector.locale\n : localeOrSelector\n ) as LocalesValues | undefined;\n\n return getIntlayerCore(key, localeOrSelector, getPlugins(locale)) as any;\n};\n"],"mappings":";;;;;;;;;;;AAiBA,MAAa,eAIX,KACA,qBAIG;AAOH,oDAAuB,KAAK,kBAAkBA,2BAL5C,OAAO,qBAAqB,YAAY,qBAAqB,OACzD,iBAAiB,SACjB,iBAG0D,CAAC"}
|
|
@@ -1,21 +1,30 @@
|
|
|
1
1
|
import { getDictionary } from "../getDictionary.mjs";
|
|
2
2
|
import { IntlayerClientContext } from "./IntlayerProvider.mjs";
|
|
3
3
|
import { useContext, useMemo } from "preact/hooks";
|
|
4
|
+
import { getDictionarySelectorCacheKey } from "@intlayer/core/dictionaryManipulator";
|
|
4
5
|
|
|
5
6
|
//#region src/client/useDictionary.ts
|
|
6
7
|
/**
|
|
7
|
-
*
|
|
8
|
+
* Preact hook that transforms a dictionary (or qualified dictionary group) and
|
|
9
|
+
* returns the content.
|
|
8
10
|
*
|
|
9
|
-
* If the locale is not provided
|
|
11
|
+
* If the locale is not provided (directly or through the selector), it will use
|
|
12
|
+
* the locale from the client context.
|
|
10
13
|
*/
|
|
11
|
-
const useDictionary = (dictionary,
|
|
14
|
+
const useDictionary = (dictionary, localeOrSelector) => {
|
|
12
15
|
const { locale: currentLocale } = useContext(IntlayerClientContext) ?? {};
|
|
16
|
+
const isSelector = typeof localeOrSelector === "object" && localeOrSelector !== null;
|
|
17
|
+
const localeOrSelectorIdentity = isSelector ? `${localeOrSelector.locale ?? ""}|${getDictionarySelectorCacheKey(localeOrSelector)}` : localeOrSelector;
|
|
13
18
|
return useMemo(() => {
|
|
14
|
-
return getDictionary(dictionary,
|
|
19
|
+
if (isSelector) return getDictionary(dictionary, {
|
|
20
|
+
...localeOrSelector,
|
|
21
|
+
locale: localeOrSelector.locale ?? currentLocale
|
|
22
|
+
});
|
|
23
|
+
return getDictionary(dictionary, localeOrSelector ?? currentLocale);
|
|
15
24
|
}, [
|
|
16
25
|
dictionary.key,
|
|
17
26
|
currentLocale,
|
|
18
|
-
|
|
27
|
+
localeOrSelectorIdentity
|
|
19
28
|
]);
|
|
20
29
|
};
|
|
21
30
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionary.mjs","names":[],"sources":["../../../src/client/useDictionary.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"useDictionary.mjs","names":[],"sources":["../../../src/client/useDictionary.ts"],"sourcesContent":["import { getDictionarySelectorCacheKey } from '@intlayer/core/dictionaryManipulator';\nimport type {\n Dictionary,\n DictionarySelector,\n DictionarySelectorForGroup,\n QualifiedDictionaryGroup,\n} from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { useContext, useMemo } from 'preact/hooks';\nimport { getDictionary } from '../getDictionary';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * Preact hook that transforms a dictionary (or qualified dictionary group) and\n * returns the content.\n *\n * If the locale is not provided (directly or through the selector), it will use\n * the locale from the client context.\n */\nexport const useDictionary = <\n const T extends Dictionary | QualifiedDictionaryGroup,\n const A extends\n | LocalesValues\n | DictionarySelectorForGroup<T> = DeclaredLocales,\n>(\n dictionary: T,\n localeOrSelector?: A\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext) ?? {};\n\n const isSelector =\n typeof localeOrSelector === 'object' && localeOrSelector !== null;\n\n // Stable identity of the second argument for memoization\n const localeOrSelectorIdentity = isSelector\n ? `${localeOrSelector.locale ?? ''}|${getDictionarySelectorCacheKey(localeOrSelector)}`\n : localeOrSelector;\n\n return useMemo(() => {\n if (isSelector) {\n return getDictionary(dictionary, {\n ...localeOrSelector,\n locale: localeOrSelector.locale ?? currentLocale,\n } as A);\n }\n\n const localeTarget = (localeOrSelector ?? currentLocale) as A;\n\n return getDictionary<T, A>(dictionary, localeTarget);\n }, [dictionary.key, currentLocale, localeOrSelectorIdentity]);\n};\n"],"mappings":";;;;;;;;;;;;;AAsBA,MAAa,iBAMX,YACA,qBACG;CACH,MAAM,EAAE,QAAQ,kBAAkB,WAAW,sBAAsB,IAAI,EAAE;CAEzE,MAAM,aACJ,OAAO,qBAAqB,YAAY,qBAAqB;CAG/D,MAAM,2BAA2B,aAC7B,GAAG,iBAAiB,UAAU,GAAG,GAAG,8BAA8B,iBAAiB,KACnF;AAEJ,QAAO,cAAc;AACnB,MAAI,WACF,QAAO,cAAc,YAAY;GAC/B,GAAG;GACH,QAAQ,iBAAiB,UAAU;GACpC,CAAM;AAKT,SAAO,cAAoB,YAFL,oBAAoB,cAEU;IACnD;EAAC,WAAW;EAAK;EAAe;EAAyB,CAAC"}
|
|
@@ -1,18 +1,36 @@
|
|
|
1
1
|
import { useLoadDynamic } from "./useLoadDynamic.mjs";
|
|
2
|
+
import { getDictionary } from "../getDictionary.mjs";
|
|
2
3
|
import { IntlayerClientContext } from "./IntlayerProvider.mjs";
|
|
3
|
-
import {
|
|
4
|
-
import { useContext
|
|
4
|
+
import { internationalization } from "@intlayer/config/built";
|
|
5
|
+
import { useContext } from "preact/hooks";
|
|
6
|
+
import { isQualifiedDynamicLoaderMap, parseDictionarySelector, resolveQualifiedDynamicContent } from "@intlayer/core/dictionaryManipulator";
|
|
5
7
|
|
|
6
8
|
//#region src/client/useDictionaryDynamic.ts
|
|
7
9
|
/**
|
|
8
|
-
*
|
|
10
|
+
* Preact hook that lazily loads a dictionary and returns its content.
|
|
9
11
|
*
|
|
10
|
-
*
|
|
12
|
+
* The dictionary entry is either a plain dynamic loader map
|
|
13
|
+
* (`locale → loader`) or a qualified one (`locale → …qualifier → loader`,
|
|
14
|
+
* tagged with the qualifier dimensions). For qualified maps, only the chunk(s)
|
|
15
|
+
* the selector targets are loaded.
|
|
16
|
+
*
|
|
17
|
+
* If the locale is not provided (directly or through the selector), the client
|
|
18
|
+
* context locale is used.
|
|
11
19
|
*/
|
|
12
|
-
const useDictionaryDynamic = (dictionaryPromise, key,
|
|
20
|
+
const useDictionaryDynamic = (dictionaryPromise, key, localeOrSelector) => {
|
|
13
21
|
const { locale: currentLocale } = useContext(IntlayerClientContext) ?? {};
|
|
14
|
-
const
|
|
15
|
-
|
|
22
|
+
const { locale: selectorLocale, selector } = parseDictionarySelector(localeOrSelector);
|
|
23
|
+
const localeTarget = selectorLocale ?? currentLocale ?? internationalization.defaultLocale;
|
|
24
|
+
if (isQualifiedDynamicLoaderMap(dictionaryPromise)) return resolveQualifiedDynamicContent({
|
|
25
|
+
loaderMap: dictionaryPromise,
|
|
26
|
+
key: String(key),
|
|
27
|
+
locale: localeTarget,
|
|
28
|
+
selector,
|
|
29
|
+
loadChunk: (cacheKey, promise) => useLoadDynamic(cacheKey, promise),
|
|
30
|
+
transform: (dictionary) => getDictionary(dictionary, localeTarget)
|
|
31
|
+
});
|
|
32
|
+
const plainLoaders = dictionaryPromise;
|
|
33
|
+
return getDictionary(useLoadDynamic(`${String(key)}.${localeTarget}`, plainLoaders[localeTarget]?.()), localeTarget);
|
|
16
34
|
};
|
|
17
35
|
|
|
18
36
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionaryDynamic.mjs","names":[],"sources":["../../../src/client/useDictionaryDynamic.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"useDictionaryDynamic.mjs","names":["loadDynamicChunk"],"sources":["../../../src/client/useDictionaryDynamic.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport {\n isQualifiedDynamicLoaderMap,\n parseDictionarySelector,\n type QualifiedDynamicLoaderMap,\n resolveQualifiedDynamicContent,\n} from '@intlayer/core/dictionaryManipulator';\nimport type {\n Dictionary,\n DictionarySelector,\n} from '@intlayer/types/dictionary';\nimport type {\n DictionaryKeys,\n DictionarySelectorForKey,\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { useContext } from 'preact/hooks';\nimport { getDictionary } from '../getDictionary';\nimport { IntlayerClientContext } from './IntlayerProvider';\n// `useLoadDynamic` is a suspender cache, not a hook — aliased to a non-hook\n// name so it can be invoked in loops / conditionally (collection chunks).\nimport { useLoadDynamic as loadDynamicChunk } from './useLoadDynamic';\n\n/**\n * Preact hook that lazily loads a dictionary and returns its content.\n *\n * The dictionary entry is either a plain dynamic loader map\n * (`locale → loader`) or a qualified one (`locale → …qualifier → loader`,\n * tagged with the qualifier dimensions). For qualified maps, only the chunk(s)\n * the selector targets are loaded.\n *\n * If the locale is not provided (directly or through the selector), the client\n * context locale is used.\n */\nexport const useDictionaryDynamic = <\n const T extends Dictionary,\n const K extends DictionaryKeys,\n const A extends LocalesValues | DictionarySelectorForKey<K> = LocalesValues,\n>(\n dictionaryPromise:\n | StrictModeLocaleMap<() => Promise<T>>\n | QualifiedDynamicLoaderMap,\n key: K,\n localeOrSelector?: A\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext) ?? {};\n\n const { locale: selectorLocale, selector } =\n parseDictionarySelector<LocalesValues>(localeOrSelector);\n\n const localeTarget =\n selectorLocale ?? currentLocale ?? internationalization.defaultLocale;\n\n if (isQualifiedDynamicLoaderMap(dictionaryPromise)) {\n return resolveQualifiedDynamicContent({\n loaderMap: dictionaryPromise,\n key: String(key),\n locale: localeTarget,\n selector,\n loadChunk: (cacheKey, promise) => loadDynamicChunk(cacheKey, promise),\n transform: (dictionary) => getDictionary(dictionary, localeTarget),\n });\n }\n\n const plainLoaders = dictionaryPromise as StrictModeLocaleMap<\n () => Promise<T>\n >;\n\n const dictionary = loadDynamicChunk<T>(\n `${String(key)}.${localeTarget}`,\n plainLoaders[localeTarget as keyof typeof plainLoaders]?.() as Promise<T>\n );\n\n return getDictionary(dictionary, localeTarget);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAmCA,MAAa,wBAKX,mBAGA,KACA,qBACG;CACH,MAAM,EAAE,QAAQ,kBAAkB,WAAW,sBAAsB,IAAI,EAAE;CAEzE,MAAM,EAAE,QAAQ,gBAAgB,aAC9B,wBAAuC,iBAAiB;CAE1D,MAAM,eACJ,kBAAkB,iBAAiB,qBAAqB;AAE1D,KAAI,4BAA4B,kBAAkB,CAChD,QAAO,+BAA+B;EACpC,WAAW;EACX,KAAK,OAAO,IAAI;EAChB,QAAQ;EACR;EACA,YAAY,UAAU,YAAYA,eAAiB,UAAU,QAAQ;EACrE,YAAY,eAAe,cAAc,YAAY,aAAa;EACnE,CAAC;CAGJ,MAAM,eAAe;AASrB,QAAO,cALYA,eACjB,GAAG,OAAO,IAAI,CAAC,GAAG,gBAClB,aAAa,iBAA8C,CAG9B,EAAE,aAAa"}
|
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
import { getIntlayer } from "../getIntlayer.mjs";
|
|
2
2
|
import { IntlayerClientContext } from "./IntlayerProvider.mjs";
|
|
3
3
|
import { useContext, useMemo } from "preact/hooks";
|
|
4
|
+
import { getDictionarySelectorCacheKey } from "@intlayer/core/dictionaryManipulator";
|
|
4
5
|
|
|
5
6
|
//#region src/client/useIntlayer.ts
|
|
6
7
|
/**
|
|
7
8
|
* Preact hook that picks one dictionary by its key and returns its content.
|
|
8
9
|
*
|
|
9
|
-
*
|
|
10
|
+
* The second argument is either a locale or a selector object:
|
|
11
|
+
* - `{ item: 2 }` — collection item (omit `item` to get every item as array)
|
|
12
|
+
* - `{ variant: 'black-friday' }` — named variant (omit for the `default` one)
|
|
13
|
+
* - `{ id: 'prod_abc', ...metaFields }` — meta record
|
|
14
|
+
* - `locale` composes with any selector and overrides the context locale
|
|
10
15
|
*
|
|
11
16
|
* @param key - The unique key of the dictionary to retrieve.
|
|
12
|
-
* @param
|
|
17
|
+
* @param localeOrSelector - Optional locale or selector.
|
|
13
18
|
* @returns The transformed dictionary content.
|
|
14
19
|
*
|
|
15
20
|
* @example
|
|
@@ -18,19 +23,25 @@ import { useContext, useMemo } from "preact/hooks";
|
|
|
18
23
|
*
|
|
19
24
|
* const MyComponent = () => {
|
|
20
25
|
* const content = useIntlayer('my-dictionary-key');
|
|
26
|
+
* const faq2 = useIntlayer('faq', { item: 2 });
|
|
21
27
|
*
|
|
22
28
|
* return <div>{content.myField.value}</div>;
|
|
23
29
|
* };
|
|
24
30
|
* ```
|
|
25
31
|
*/
|
|
26
|
-
const useIntlayer = (key,
|
|
32
|
+
const useIntlayer = (key, localeOrSelector) => {
|
|
27
33
|
const { locale: currentLocale } = useContext(IntlayerClientContext) ?? {};
|
|
34
|
+
const isSelector = typeof localeOrSelector === "object" && localeOrSelector !== null;
|
|
28
35
|
return useMemo(() => {
|
|
29
|
-
return getIntlayer(key,
|
|
36
|
+
if (isSelector) return getIntlayer(key, {
|
|
37
|
+
...localeOrSelector,
|
|
38
|
+
locale: localeOrSelector.locale ?? currentLocale
|
|
39
|
+
});
|
|
40
|
+
return getIntlayer(key, localeOrSelector ?? currentLocale);
|
|
30
41
|
}, [
|
|
31
42
|
key,
|
|
32
43
|
currentLocale,
|
|
33
|
-
locale
|
|
44
|
+
isSelector ? `${localeOrSelector.locale ?? ""}|${getDictionarySelectorCacheKey(localeOrSelector)}` : localeOrSelector
|
|
34
45
|
]);
|
|
35
46
|
};
|
|
36
47
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIntlayer.mjs","names":[],"sources":["../../../src/client/useIntlayer.ts"],"sourcesContent":["import type {\n DictionaryKeys,\n
|
|
1
|
+
{"version":3,"file":"useIntlayer.mjs","names":[],"sources":["../../../src/client/useIntlayer.ts"],"sourcesContent":["import { getDictionarySelectorCacheKey } from '@intlayer/core/dictionaryManipulator';\nimport type { DictionarySelector } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n DictionarySelectorForKey,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { useContext, useMemo } from 'preact/hooks';\nimport { getIntlayer } from '../getIntlayer';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * Preact hook that picks one dictionary by its key and returns its content.\n *\n * The second argument is either a locale or a selector object:\n * - `{ item: 2 }` — collection item (omit `item` to get every item as array)\n * - `{ variant: 'black-friday' }` — named variant (omit for the `default` one)\n * - `{ id: 'prod_abc', ...metaFields }` — meta record\n * - `locale` composes with any selector and overrides the context locale\n *\n * @param key - The unique key of the dictionary to retrieve.\n * @param localeOrSelector - Optional locale or selector.\n * @returns The transformed dictionary content.\n *\n * @example\n * ```tsx\n * import { useIntlayer } from 'preact-intlayer';\n *\n * const MyComponent = () => {\n * const content = useIntlayer('my-dictionary-key');\n * const faq2 = useIntlayer('faq', { item: 2 });\n *\n * return <div>{content.myField.value}</div>;\n * };\n * ```\n */\nexport const useIntlayer = <\n const T extends DictionaryKeys,\n const A extends LocalesValues | DictionarySelectorForKey<T> = DeclaredLocales,\n>(\n key: T,\n localeOrSelector?: A\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext) ?? {};\n\n const isSelector =\n typeof localeOrSelector === 'object' && localeOrSelector !== null;\n\n // Stable identity of the second argument for memoization\n const localeOrSelectorIdentity = isSelector\n ? `${localeOrSelector.locale ?? ''}|${getDictionarySelectorCacheKey(localeOrSelector)}`\n : localeOrSelector;\n\n return useMemo(() => {\n if (isSelector) {\n return getIntlayer(key, {\n ...localeOrSelector,\n locale: localeOrSelector.locale ?? currentLocale,\n } as A);\n }\n\n const localeTarget = (localeOrSelector ?? currentLocale) as A;\n\n return getIntlayer<T, A>(key, localeTarget);\n }, [key, currentLocale, localeOrSelectorIdentity]);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCA,MAAa,eAIX,KACA,qBACG;CACH,MAAM,EAAE,QAAQ,kBAAkB,WAAW,sBAAsB,IAAI,EAAE;CAEzE,MAAM,aACJ,OAAO,qBAAqB,YAAY,qBAAqB;AAO/D,QAAO,cAAc;AACnB,MAAI,WACF,QAAO,YAAY,KAAK;GACtB,GAAG;GACH,QAAQ,iBAAiB,UAAU;GACpC,CAAM;AAKT,SAAO,YAAkB,KAFH,oBAAoB,cAEC;IAC1C;EAAC;EAAK;EAfwB,aAC7B,GAAG,iBAAiB,UAAU,GAAG,GAAG,8BAA8B,iBAAiB,KACnF;EAa6C,CAAC"}
|
|
@@ -2,7 +2,14 @@ import { getPlugins } from "./plugins.mjs";
|
|
|
2
2
|
import { getDictionary as getDictionary$1 } from "@intlayer/core/interpreter";
|
|
3
3
|
|
|
4
4
|
//#region src/getDictionary.ts
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Transforms a dictionary (or qualified dictionary group) and returns its
|
|
7
|
+
* content for the given locale or selector (`{ item }`, `{ variant }`,
|
|
8
|
+
* `{ id, ...meta }`, optionally combined with `locale`).
|
|
9
|
+
*/
|
|
10
|
+
const getDictionary = (dictionary, localeOrSelector) => {
|
|
11
|
+
return getDictionary$1(dictionary, localeOrSelector, getPlugins(typeof localeOrSelector === "object" && localeOrSelector !== null ? localeOrSelector.locale : localeOrSelector));
|
|
12
|
+
};
|
|
6
13
|
|
|
7
14
|
//#endregion
|
|
8
15
|
export { getDictionary };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getDictionary.mjs","names":["getDictionaryCore"],"sources":["../../src/getDictionary.ts"],"sourcesContent":["import { getDictionary as getDictionaryCore } from '@intlayer/core/interpreter';\nimport type {
|
|
1
|
+
{"version":3,"file":"getDictionary.mjs","names":["getDictionaryCore"],"sources":["../../src/getDictionary.ts"],"sourcesContent":["import { getDictionary as getDictionaryCore } from '@intlayer/core/interpreter';\nimport type {\n Dictionary,\n DictionarySelector,\n DictionarySelectorForGroup,\n QualifiedDictionaryGroup,\n ResolveQualifiedDictionaryContent,\n} from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n ExtractSelectorLocale,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { type DeepTransformContent, getPlugins } from './plugins';\n\n/**\n * Transforms a dictionary (or qualified dictionary group) and returns its\n * content for the given locale or selector (`{ item }`, `{ variant }`,\n * `{ id, ...meta }`, optionally combined with `locale`).\n */\nexport const getDictionary = <\n const T extends Dictionary | QualifiedDictionaryGroup,\n const A extends\n | LocalesValues\n | DictionarySelectorForGroup<T> = DeclaredLocales,\n>(\n dictionary: T,\n localeOrSelector?: A\n): DeepTransformContent<\n ResolveQualifiedDictionaryContent<T, A>,\n ExtractSelectorLocale<A>\n> => {\n const locale = (\n typeof localeOrSelector === 'object' && localeOrSelector !== null\n ? localeOrSelector.locale\n : localeOrSelector\n ) as LocalesValues | undefined;\n\n return getDictionaryCore(\n dictionary,\n localeOrSelector,\n getPlugins(locale)\n ) as any;\n};\n"],"mappings":";;;;;;;;;AAoBA,MAAa,iBAMX,YACA,qBAIG;AAOH,QAAOA,gBACL,YACA,kBACA,WARA,OAAO,qBAAqB,YAAY,qBAAqB,OACzD,iBAAiB,SACjB,iBAMc,CACnB"}
|
package/dist/esm/getIntlayer.mjs
CHANGED
|
@@ -2,7 +2,14 @@ import { getPlugins } from "./plugins.mjs";
|
|
|
2
2
|
import { getIntlayer as getIntlayer$1 } from "@intlayer/core/interpreter";
|
|
3
3
|
|
|
4
4
|
//#region src/getIntlayer.ts
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Picks one dictionary by its key and returns its content for the given
|
|
7
|
+
* locale or selector (`{ item }`, `{ variant }`, `{ id, ...meta }`,
|
|
8
|
+
* optionally combined with `locale`).
|
|
9
|
+
*/
|
|
10
|
+
const getIntlayer = (key, localeOrSelector) => {
|
|
11
|
+
return getIntlayer$1(key, localeOrSelector, getPlugins(typeof localeOrSelector === "object" && localeOrSelector !== null ? localeOrSelector.locale : localeOrSelector));
|
|
12
|
+
};
|
|
6
13
|
|
|
7
14
|
//#endregion
|
|
8
15
|
export { getIntlayer };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getIntlayer.mjs","names":["getIntlayerCore"],"sources":["../../src/getIntlayer.ts"],"sourcesContent":["import { getIntlayer as getIntlayerCore } from '@intlayer/core/interpreter';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n
|
|
1
|
+
{"version":3,"file":"getIntlayer.mjs","names":["getIntlayerCore"],"sources":["../../src/getIntlayer.ts"],"sourcesContent":["import { getIntlayer as getIntlayerCore } from '@intlayer/core/interpreter';\nimport type { DictionarySelector } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n DictionaryRegistryResult,\n DictionarySelectorForKey,\n ExtractSelectorLocale,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { type DeepTransformContent, getPlugins } from './plugins';\n\n/**\n * Picks one dictionary by its key and returns its content for the given\n * locale or selector (`{ item }`, `{ variant }`, `{ id, ...meta }`,\n * optionally combined with `locale`).\n */\nexport const getIntlayer = <\n const T extends DictionaryKeys,\n const A extends LocalesValues | DictionarySelectorForKey<T> = DeclaredLocales,\n>(\n key: T,\n localeOrSelector?: A\n): DeepTransformContent<\n DictionaryRegistryResult<T, A>,\n ExtractSelectorLocale<A>\n> => {\n const locale = (\n typeof localeOrSelector === 'object' && localeOrSelector !== null\n ? localeOrSelector.locale\n : localeOrSelector\n ) as LocalesValues | undefined;\n\n return getIntlayerCore(key, localeOrSelector, getPlugins(locale)) as any;\n};\n"],"mappings":";;;;;;;;;AAiBA,MAAa,eAIX,KACA,qBAIG;AAOH,QAAOA,cAAgB,KAAK,kBAAkB,WAL5C,OAAO,qBAAqB,YAAY,qBAAqB,OACzD,iBAAiB,SACjB,iBAG0D,CAAC"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
import { LocalesValues as LocalesValues$1 } from "../intlayer/dist/types/index.js";
|
|
1
2
|
import { StrictModeLocaleMap } from "@intlayer/types/module_augmentation";
|
|
2
|
-
import * as _$_intlayer_types0 from "@intlayer/types";
|
|
3
3
|
|
|
4
4
|
//#region src/client/useContent.d.ts
|
|
5
5
|
/**
|
|
6
6
|
* On the client side, hook to get the translation content based on the locale
|
|
7
7
|
*/
|
|
8
8
|
declare const useContent: <Content>(languageContent: StrictModeLocaleMap<Content>) => {
|
|
9
|
-
locale:
|
|
9
|
+
locale: LocalesValues$1;
|
|
10
10
|
content: Content;
|
|
11
11
|
t: <Content_1 = string>(languageContent: StrictModeLocaleMap<Content_1>) => Content_1;
|
|
12
12
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useContent.d.ts","names":[],"sources":["../../../src/client/useContent.ts"],"mappings":";;;;;;;cAOa,UAAA,YACX,eAAA,EAAiB,mBAAA,CAAoB,OAAA;UAAD,
|
|
1
|
+
{"version":3,"file":"useContent.d.ts","names":[],"sources":["../../../src/client/useContent.ts"],"mappings":";;;;;;;cAOa,UAAA,YACX,eAAA,EAAiB,mBAAA,CAAoB,OAAA;UAAD,eAAA"}
|
|
@@ -2,15 +2,17 @@ import { IInterpreterPluginState as IInterpreterPluginState$1 } from "../plugins
|
|
|
2
2
|
import * as _$_intlayer_core_interpreter0 from "@intlayer/core/interpreter";
|
|
3
3
|
import { DeclaredLocales, LocalesValues } from "@intlayer/types/module_augmentation";
|
|
4
4
|
import * as _$_intlayer_types0 from "@intlayer/types";
|
|
5
|
-
import { Dictionary } from "@intlayer/types/dictionary";
|
|
5
|
+
import { Dictionary, DictionarySelectorForGroup, QualifiedDictionaryGroup } from "@intlayer/types/dictionary";
|
|
6
6
|
|
|
7
7
|
//#region src/client/useDictionary.d.ts
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
9
|
+
* Preact hook that transforms a dictionary (or qualified dictionary group) and
|
|
10
|
+
* returns the content.
|
|
10
11
|
*
|
|
11
|
-
* If the locale is not provided
|
|
12
|
+
* If the locale is not provided (directly or through the selector), it will use
|
|
13
|
+
* the locale from the client context.
|
|
12
14
|
*/
|
|
13
|
-
declare const useDictionary: <const T extends Dictionary, const
|
|
15
|
+
declare const useDictionary: <const T extends Dictionary | QualifiedDictionaryGroup, const A extends LocalesValues | DictionarySelectorForGroup<T> = DeclaredLocales>(dictionary: T, localeOrSelector?: A) => _$_intlayer_core_interpreter0.DeepTransformContent<_$_intlayer_types0.ResolveQualifiedDictionaryContent<T, A>, IInterpreterPluginState$1, _$_intlayer_types0.ExtractSelectorLocale<A>>;
|
|
14
16
|
//#endregion
|
|
15
17
|
export { useDictionary };
|
|
16
18
|
//# sourceMappingURL=useDictionary.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionary.d.ts","names":[],"sources":["../../../src/client/useDictionary.ts"],"mappings":";;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"useDictionary.d.ts","names":[],"sources":["../../../src/client/useDictionary.ts"],"mappings":";;;;;;;;;;;;AAsBA;;cAAa,aAAA,mBACK,UAAA,GAAa,wBAAA,kBAEzB,aAAA,GACA,0BAAA,CAA2B,CAAA,IAAK,eAAA,EAEpC,UAAA,EAAY,CAAA,EACZ,gBAAA,GAAmB,CAAA,KAAC,6BAAA,CAAA,oBAAA,CAAA,kBAAA,CAAA,iCAAA,CAAA,CAAA,EAAA,CAAA,GAAA,yBAAA,EAAA,kBAAA,CAAA,qBAAA,CAAA,CAAA"}
|
|
@@ -1,16 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import * as _$_intlayer_core_interpreter0 from "@intlayer/core/interpreter";
|
|
3
|
-
import { DictionaryKeys, LocalesValues, StrictModeLocaleMap } from "@intlayer/types/module_augmentation";
|
|
4
|
-
import * as _$_intlayer_types0 from "@intlayer/types";
|
|
1
|
+
import { DictionaryKeys, DictionarySelectorForKey, LocalesValues, StrictModeLocaleMap } from "@intlayer/types/module_augmentation";
|
|
5
2
|
import { Dictionary } from "@intlayer/types/dictionary";
|
|
3
|
+
import { QualifiedDynamicLoaderMap } from "@intlayer/core/dictionaryManipulator";
|
|
6
4
|
|
|
7
5
|
//#region src/client/useDictionaryDynamic.d.ts
|
|
8
6
|
/**
|
|
9
|
-
*
|
|
7
|
+
* Preact hook that lazily loads a dictionary and returns its content.
|
|
10
8
|
*
|
|
11
|
-
*
|
|
9
|
+
* The dictionary entry is either a plain dynamic loader map
|
|
10
|
+
* (`locale → loader`) or a qualified one (`locale → …qualifier → loader`,
|
|
11
|
+
* tagged with the qualifier dimensions). For qualified maps, only the chunk(s)
|
|
12
|
+
* the selector targets are loaded.
|
|
13
|
+
*
|
|
14
|
+
* If the locale is not provided (directly or through the selector), the client
|
|
15
|
+
* context locale is used.
|
|
12
16
|
*/
|
|
13
|
-
declare const useDictionaryDynamic: <const T extends Dictionary, const K extends DictionaryKeys>(dictionaryPromise: StrictModeLocaleMap<() => Promise<T
|
|
17
|
+
declare const useDictionaryDynamic: <const T extends Dictionary, const K extends DictionaryKeys, const A extends LocalesValues | DictionarySelectorForKey<K> = LocalesValues>(dictionaryPromise: StrictModeLocaleMap<() => Promise<T>> | QualifiedDynamicLoaderMap, key: K, localeOrSelector?: A) => any;
|
|
14
18
|
//#endregion
|
|
15
19
|
export { useDictionaryDynamic };
|
|
16
20
|
//# sourceMappingURL=useDictionaryDynamic.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionaryDynamic.d.ts","names":[],"sources":["../../../src/client/useDictionaryDynamic.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useDictionaryDynamic.d.ts","names":[],"sources":["../../../src/client/useDictionaryDynamic.ts"],"mappings":";;;;;;;AAmCA;;;;;;;;;cAAa,oBAAA,mBACK,UAAA,kBACA,cAAA,kBACA,aAAA,GAAgB,wBAAA,CAAyB,CAAA,IAAK,aAAA,EAE9D,iBAAA,EACI,mBAAA,OAA0B,OAAA,CAAQ,CAAA,KAClC,yBAAA,EACJ,GAAA,EAAK,CAAA,EACL,gBAAA,GAAmB,CAAA"}
|
|
@@ -1,14 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import { IInterpreterPluginState as IInterpreterPluginState$1 } from "../plugins.js";
|
|
2
|
+
import * as _$_intlayer_core_interpreter0 from "@intlayer/core/interpreter";
|
|
3
|
+
import { DeclaredLocales, DictionaryKeys, DictionarySelectorForKey, LocalesValues } from "@intlayer/types/module_augmentation";
|
|
4
|
+
import * as _$_intlayer_types0 from "@intlayer/types";
|
|
3
5
|
|
|
4
6
|
//#region src/client/useIntlayer.d.ts
|
|
5
7
|
/**
|
|
6
8
|
* Preact hook that picks one dictionary by its key and returns its content.
|
|
7
9
|
*
|
|
8
|
-
*
|
|
10
|
+
* The second argument is either a locale or a selector object:
|
|
11
|
+
* - `{ item: 2 }` — collection item (omit `item` to get every item as array)
|
|
12
|
+
* - `{ variant: 'black-friday' }` — named variant (omit for the `default` one)
|
|
13
|
+
* - `{ id: 'prod_abc', ...metaFields }` — meta record
|
|
14
|
+
* - `locale` composes with any selector and overrides the context locale
|
|
9
15
|
*
|
|
10
16
|
* @param key - The unique key of the dictionary to retrieve.
|
|
11
|
-
* @param
|
|
17
|
+
* @param localeOrSelector - Optional locale or selector.
|
|
12
18
|
* @returns The transformed dictionary content.
|
|
13
19
|
*
|
|
14
20
|
* @example
|
|
@@ -17,12 +23,13 @@ import { DictionaryKeys, DictionaryRegistryContent, LocalesValues } from "@intla
|
|
|
17
23
|
*
|
|
18
24
|
* const MyComponent = () => {
|
|
19
25
|
* const content = useIntlayer('my-dictionary-key');
|
|
26
|
+
* const faq2 = useIntlayer('faq', { item: 2 });
|
|
20
27
|
*
|
|
21
28
|
* return <div>{content.myField.value}</div>;
|
|
22
29
|
* };
|
|
23
30
|
* ```
|
|
24
31
|
*/
|
|
25
|
-
declare const useIntlayer: <const T extends DictionaryKeys, const
|
|
32
|
+
declare const useIntlayer: <const T extends DictionaryKeys, const A extends LocalesValues | DictionarySelectorForKey<T> = DeclaredLocales>(key: T, localeOrSelector?: A) => _$_intlayer_core_interpreter0.DeepTransformContent<_$_intlayer_types0.DictionaryRegistryResult<T, A>, IInterpreterPluginState$1, _$_intlayer_types0.ExtractSelectorLocale<A>>;
|
|
26
33
|
//#endregion
|
|
27
34
|
export { useIntlayer };
|
|
28
35
|
//# sourceMappingURL=useIntlayer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIntlayer.d.ts","names":[],"sources":["../../../src/client/useIntlayer.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useIntlayer.d.ts","names":[],"sources":["../../../src/client/useIntlayer.ts"],"mappings":";;;;;;;;;;;AAqCA;;;;;;;;;;;;;;;;;;;;cAAa,WAAA,mBACK,cAAA,kBACA,aAAA,GAAgB,wBAAA,CAAyB,CAAA,IAAK,eAAA,EAE9D,GAAA,EAAK,CAAA,EACL,gBAAA,GAAmB,CAAA,KAAC,6BAAA,CAAA,oBAAA,CAAA,kBAAA,CAAA,wBAAA,CAAA,CAAA,EAAA,CAAA,GAAA,yBAAA,EAAA,kBAAA,CAAA,qBAAA,CAAA,CAAA"}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { LocalesValues } from "../intlayer/dist/types/index.js";
|
|
2
2
|
|
|
3
3
|
//#region src/client/useLocaleBase.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* On the client side, hook to get the current locale and all related fields
|
|
6
6
|
*/
|
|
7
7
|
declare const useLocaleBase: () => {
|
|
8
|
-
locale:
|
|
8
|
+
locale: LocalesValues;
|
|
9
9
|
defaultLocale: any;
|
|
10
10
|
availableLocales: any;
|
|
11
|
-
setLocale: (newLocale:
|
|
11
|
+
setLocale: (newLocale: LocalesValues) => void;
|
|
12
12
|
};
|
|
13
13
|
//#endregion
|
|
14
14
|
export { useLocaleBase };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocaleBase.d.ts","names":[],"sources":["../../../src/client/useLocaleBase.ts"],"mappings":";;;;;;cASa,aAAA;UASZ,
|
|
1
|
+
{"version":3,"file":"useLocaleBase.d.ts","names":[],"sources":["../../../src/client/useLocaleBase.ts"],"mappings":";;;;;;cASa,aAAA;UASZ,aAAA;;;yBAAA,aAAA;AAAA"}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
+
import { Locale } from "../intlayer/dist/types/index.js";
|
|
1
2
|
import { LocalesValues } from "@intlayer/types/module_augmentation";
|
|
2
|
-
import * as _$_intlayer_types0 from "@intlayer/types";
|
|
3
3
|
|
|
4
4
|
//#region src/client/useLocaleStorage.d.ts
|
|
5
5
|
/**
|
|
6
6
|
* Get the locale cookie
|
|
7
7
|
*/
|
|
8
|
-
declare const localeInStorage:
|
|
8
|
+
declare const localeInStorage: Locale;
|
|
9
9
|
/**
|
|
10
10
|
* @deprecated Use localeInStorage instead
|
|
11
11
|
*
|
|
12
12
|
* Get the locale cookie
|
|
13
13
|
*/
|
|
14
|
-
declare const localeCookie:
|
|
14
|
+
declare const localeCookie: Locale;
|
|
15
15
|
/**
|
|
16
16
|
* Set the locale cookie
|
|
17
17
|
*/
|
|
@@ -26,7 +26,7 @@ declare const setLocaleCookie: (locale: LocalesValues, isCookieEnabled: boolean)
|
|
|
26
26
|
* Hook that provides the locale storage and a function to set it
|
|
27
27
|
*/
|
|
28
28
|
declare const useLocaleStorage: (isCookieEnabled?: boolean) => {
|
|
29
|
-
getLocale: () =>
|
|
29
|
+
getLocale: () => Locale;
|
|
30
30
|
setLocale: (locale: LocalesValues) => void;
|
|
31
31
|
};
|
|
32
32
|
/**
|
|
@@ -37,7 +37,7 @@ declare const useLocaleStorage: (isCookieEnabled?: boolean) => {
|
|
|
37
37
|
* Hook that provides the locale cookie and a function to set it
|
|
38
38
|
*/
|
|
39
39
|
declare const useLocaleCookie: (isCookieEnabled?: boolean) => {
|
|
40
|
-
getLocale: () =>
|
|
40
|
+
getLocale: () => Locale;
|
|
41
41
|
setLocale: (locale: LocalesValues) => void;
|
|
42
42
|
};
|
|
43
43
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocaleStorage.d.ts","names":[],"sources":["../../../src/client/useLocaleStorage.ts"],"mappings":";;;;;;;cAYa,eAAA,EAAkE,
|
|
1
|
+
{"version":3,"file":"useLocaleStorage.d.ts","names":[],"sources":["../../../src/client/useLocaleStorage.ts"],"mappings":";;;;;;;cAYa,eAAA,EAAkE,MAAA;;;;;AAM/E;cAAa,YAAA,EAA8B,MAAA;;;;cAK9B,kBAAA,GACX,MAAA,EAAQ,aAAA,EACR,eAAA;;;;;;cAYW,eAAA,GAAe,MAAA,EAblB,aAAA,EAAa,eAAA;;;AAavB;cAKa,gBAAA,GAAoB,eAAA;mBAQ9B,MAAA;sBAAA,aAAA;AAAA;;;;;AARH;;;cAiBa,eAAA,GAAe,eAAA;mBAAmB,MAAA;sBAAA,aAAA;AAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { LocalesValues } from "../intlayer/dist/types/index.js";
|
|
2
2
|
|
|
3
3
|
//#region src/format/useCompact.d.ts
|
|
4
4
|
/**
|
|
@@ -12,7 +12,7 @@ import * as _$_intlayer_types0 from "@intlayer/types";
|
|
|
12
12
|
* ```
|
|
13
13
|
*/
|
|
14
14
|
declare const useCompact: () => (value: string | number, options?: Intl.NumberFormatOptions & {
|
|
15
|
-
locale?:
|
|
15
|
+
locale?: LocalesValues;
|
|
16
16
|
}) => string;
|
|
17
17
|
//#endregion
|
|
18
18
|
export { useCompact };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCompact.d.ts","names":[],"sources":["../../../src/format/useCompact.ts"],"mappings":";;;;;;AAcA;;;;;;;cAAa,UAAA,SAAU,KAAA,mBAAA,OAAA,GAAA,IAAA,CAAA,mBAAA;WAAA,
|
|
1
|
+
{"version":3,"file":"useCompact.d.ts","names":[],"sources":["../../../src/format/useCompact.ts"],"mappings":";;;;;;AAcA;;;;;;;cAAa,UAAA,SAAU,KAAA,mBAAA,OAAA,GAAA,IAAA,CAAA,mBAAA;WAAA,aAAA;AAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { LocalesValues } from "../intlayer/dist/types/index.js";
|
|
2
2
|
|
|
3
3
|
//#region src/format/useCurrency.d.ts
|
|
4
4
|
/**
|
|
@@ -26,7 +26,7 @@ import * as _$_intlayer_types0 from "@intlayer/types";
|
|
|
26
26
|
* ```
|
|
27
27
|
*/
|
|
28
28
|
declare const useCurrency: () => (value: string | number, options?: Intl.NumberFormatOptions & {
|
|
29
|
-
locale?:
|
|
29
|
+
locale?: LocalesValues;
|
|
30
30
|
}) => string;
|
|
31
31
|
//#endregion
|
|
32
32
|
export { useCurrency };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCurrency.d.ts","names":[],"sources":["../../../src/format/useCurrency.ts"],"mappings":";;;;;;AA4BA;;;;;;;;;;;;;;;;;;;;;cAAa,WAAA,SAAW,KAAA,mBAAA,OAAA,GAAA,IAAA,CAAA,mBAAA;WAAA,
|
|
1
|
+
{"version":3,"file":"useCurrency.d.ts","names":[],"sources":["../../../src/format/useCurrency.ts"],"mappings":";;;;;;AA4BA;;;;;;;;;;;;;;;;;;;;;cAAa,WAAA,SAAW,KAAA,mBAAA,OAAA,GAAA,IAAA,CAAA,mBAAA;WAAA,aAAA;AAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { LocalesValues } from "../intlayer/dist/types/index.js";
|
|
2
2
|
|
|
3
3
|
//#region src/format/useList.d.ts
|
|
4
4
|
/**
|
|
@@ -27,7 +27,7 @@ declare const useList: () => (values: (string | number)[], options?: {
|
|
|
27
27
|
type?: "conjunction" | "disjunction" | "unit";
|
|
28
28
|
style?: "long" | "short" | "narrow";
|
|
29
29
|
} & {
|
|
30
|
-
locale?:
|
|
30
|
+
locale?: LocalesValues;
|
|
31
31
|
}) => string;
|
|
32
32
|
//#endregion
|
|
33
33
|
export { useList };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useList.d.ts","names":[],"sources":["../../../src/format/useList.ts"],"mappings":";;;;;;AAyBA;;;;;;;;;;;;;;;;;;cAAa,OAAA,SAAO,MAAA,uBAAA,OAAA;;;;;WAWnB,
|
|
1
|
+
{"version":3,"file":"useList.d.ts","names":[],"sources":["../../../src/format/useList.ts"],"mappings":";;;;;;AAyBA;;;;;;;;;;;;;;;;;;cAAa,OAAA,SAAO,MAAA,uBAAA,OAAA;;;;;WAWnB,aAAA;AAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { LocalesValues } from "../intlayer/dist/types/index.js";
|
|
2
2
|
|
|
3
3
|
//#region src/format/useNumber.d.ts
|
|
4
4
|
/**
|
|
@@ -24,7 +24,7 @@ import * as _$_intlayer_types0 from "@intlayer/types";
|
|
|
24
24
|
* A number formatting function bound to the active locale.
|
|
25
25
|
*/
|
|
26
26
|
declare const useNumber: () => (value: string | number, args_1?: Intl.NumberFormatOptions & {
|
|
27
|
-
locale?:
|
|
27
|
+
locale?: LocalesValues;
|
|
28
28
|
}) => string;
|
|
29
29
|
//#endregion
|
|
30
30
|
export { useNumber };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useNumber.d.ts","names":[],"sources":["../../../src/format/useNumber.ts"],"mappings":";;;;;;AA0BA;;;;;;;;;;;;;;;;;;;cAAa,SAAA,SAAS,KAAA,mBAAA,MAAA,GAAA,IAAA,CAAA,mBAAA;WAAA,
|
|
1
|
+
{"version":3,"file":"useNumber.d.ts","names":[],"sources":["../../../src/format/useNumber.ts"],"mappings":";;;;;;AA0BA;;;;;;;;;;;;;;;;;;;cAAa,SAAA,SAAS,KAAA,mBAAA,MAAA,GAAA,IAAA,CAAA,mBAAA;WAAA,aAAA;AAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { LocalesValues } from "../intlayer/dist/types/index.js";
|
|
2
2
|
|
|
3
3
|
//#region src/format/usePercentage.d.ts
|
|
4
4
|
/**
|
|
@@ -20,7 +20,7 @@ import * as _$_intlayer_types0 from "@intlayer/types";
|
|
|
20
20
|
* A function that formats numbers or numeric strings into localized percentages.
|
|
21
21
|
*/
|
|
22
22
|
declare const usePercentage: () => (value: string | number, args_1?: Intl.NumberFormatOptions & {
|
|
23
|
-
locale?:
|
|
23
|
+
locale?: LocalesValues;
|
|
24
24
|
}) => string;
|
|
25
25
|
//#endregion
|
|
26
26
|
export { usePercentage };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePercentage.d.ts","names":[],"sources":["../../../src/format/usePercentage.ts"],"mappings":";;;;;;AAsBA;;;;;;;;;;;;;;;cAAa,aAAA,SAAa,KAAA,mBAAA,MAAA,GAAA,IAAA,CAAA,mBAAA;WAAA,
|
|
1
|
+
{"version":3,"file":"usePercentage.d.ts","names":[],"sources":["../../../src/format/usePercentage.ts"],"mappings":";;;;;;AAsBA;;;;;;;;;;;;;;;cAAa,aAAA,SAAa,KAAA,mBAAA,MAAA,GAAA,IAAA,CAAA,mBAAA;WAAA,aAAA;AAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { LocalesValues } from "../intlayer/dist/types/index.js";
|
|
2
2
|
|
|
3
3
|
//#region src/format/useRelativeTime.d.ts
|
|
4
4
|
/**
|
|
@@ -20,7 +20,7 @@ import * as _$_intlayer_types0 from "@intlayer/types";
|
|
|
20
20
|
* bound to the current client locale.
|
|
21
21
|
*/
|
|
22
22
|
declare const useRelativeTime: () => (from: string | number | Date, to?: string | number | Date, options?: Intl.RelativeTimeFormatOptions & {
|
|
23
|
-
locale?:
|
|
23
|
+
locale?: LocalesValues;
|
|
24
24
|
unit?: Intl.RelativeTimeFormatUnit;
|
|
25
25
|
}) => string;
|
|
26
26
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRelativeTime.d.ts","names":[],"sources":["../../../src/format/useRelativeTime.ts"],"mappings":";;;;;;AAsBA;;;;;;;;;;;;;;;cAAa,eAAA,SAAe,IAAA,oBAAA,IAAA,EAAA,EAAA,qBAAA,IAAA,EAAA,OAAA,GAAA,IAAA,CAAA,yBAAA;WAAA,
|
|
1
|
+
{"version":3,"file":"useRelativeTime.d.ts","names":[],"sources":["../../../src/format/useRelativeTime.ts"],"mappings":";;;;;;AAsBA;;;;;;;;;;;;;;;cAAa,eAAA,SAAe,IAAA,oBAAA,IAAA,EAAA,EAAA,qBAAA,IAAA,EAAA,OAAA,GAAA,IAAA,CAAA,yBAAA;WAAA,aAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { LocalesValues } from "../intlayer/dist/types/index.js";
|
|
2
2
|
|
|
3
3
|
//#region src/format/useUnit.d.ts
|
|
4
4
|
/**
|
|
@@ -19,7 +19,7 @@ import * as _$_intlayer_types0 from "@intlayer/types";
|
|
|
19
19
|
* @returns {Function} A unit formatting function that accepts a value and optional formatting options.
|
|
20
20
|
*/
|
|
21
21
|
declare const useUnit: () => (value: string | number, options?: Intl.NumberFormatOptions & {
|
|
22
|
-
locale?:
|
|
22
|
+
locale?: LocalesValues;
|
|
23
23
|
}) => string;
|
|
24
24
|
//#endregion
|
|
25
25
|
export { useUnit };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useUnit.d.ts","names":[],"sources":["../../../src/format/useUnit.ts"],"mappings":";;;;;;AAqBA;;;;;;;;;;;;;;cAAa,OAAA,SAAO,KAAA,mBAAA,OAAA,GAAA,IAAA,CAAA,mBAAA;WAAA,
|
|
1
|
+
{"version":3,"file":"useUnit.d.ts","names":[],"sources":["../../../src/format/useUnit.ts"],"mappings":";;;;;;AAqBA;;;;;;;;;;;;;;cAAa,OAAA,SAAO,KAAA,mBAAA,OAAA,GAAA,IAAA,CAAA,mBAAA;WAAA,aAAA;AAAA"}
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import { DeepTransformContent } from "./plugins.js";
|
|
2
|
-
import { DeclaredLocales, LocalesValues } from "@intlayer/types/module_augmentation";
|
|
3
|
-
import { Dictionary } from "@intlayer/types/dictionary";
|
|
2
|
+
import { DeclaredLocales, ExtractSelectorLocale, LocalesValues } from "@intlayer/types/module_augmentation";
|
|
3
|
+
import { Dictionary, DictionarySelectorForGroup, QualifiedDictionaryGroup, ResolveQualifiedDictionaryContent } from "@intlayer/types/dictionary";
|
|
4
4
|
|
|
5
5
|
//#region src/getDictionary.d.ts
|
|
6
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Transforms a dictionary (or qualified dictionary group) and returns its
|
|
8
|
+
* content for the given locale or selector (`{ item }`, `{ variant }`,
|
|
9
|
+
* `{ id, ...meta }`, optionally combined with `locale`).
|
|
10
|
+
*/
|
|
11
|
+
declare const getDictionary: <const T extends Dictionary | QualifiedDictionaryGroup, const A extends LocalesValues | DictionarySelectorForGroup<T> = DeclaredLocales>(dictionary: T, localeOrSelector?: A) => DeepTransformContent<ResolveQualifiedDictionaryContent<T, A>, ExtractSelectorLocale<A>>;
|
|
7
12
|
//#endregion
|
|
8
13
|
export { getDictionary };
|
|
9
14
|
//# sourceMappingURL=getDictionary.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getDictionary.d.ts","names":[],"sources":["../../src/getDictionary.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"getDictionary.d.ts","names":[],"sources":["../../src/getDictionary.ts"],"mappings":";;;;;;;AAoBA;;;cAAa,aAAA,mBACK,UAAA,GAAa,wBAAA,kBAEzB,aAAA,GACA,0BAAA,CAA2B,CAAA,IAAK,eAAA,EAEpC,UAAA,EAAY,CAAA,EACZ,gBAAA,GAAmB,CAAA,KAClB,oBAAA,CACD,iCAAA,CAAkC,CAAA,EAAG,CAAA,GACrC,qBAAA,CAAsB,CAAA"}
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import { DeepTransformContent } from "./plugins.js";
|
|
2
|
-
import { DeclaredLocales, DictionaryKeys,
|
|
2
|
+
import { DeclaredLocales, DictionaryKeys, DictionaryRegistryResult, DictionarySelectorForKey, ExtractSelectorLocale, LocalesValues } from "@intlayer/types/module_augmentation";
|
|
3
3
|
|
|
4
4
|
//#region src/getIntlayer.d.ts
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Picks one dictionary by its key and returns its content for the given
|
|
7
|
+
* locale or selector (`{ item }`, `{ variant }`, `{ id, ...meta }`,
|
|
8
|
+
* optionally combined with `locale`).
|
|
9
|
+
*/
|
|
10
|
+
declare const getIntlayer: <const T extends DictionaryKeys, const A extends LocalesValues | DictionarySelectorForKey<T> = DeclaredLocales>(key: T, localeOrSelector?: A) => DeepTransformContent<DictionaryRegistryResult<T, A>, ExtractSelectorLocale<A>>;
|
|
6
11
|
//#endregion
|
|
7
12
|
export { getIntlayer };
|
|
8
13
|
//# sourceMappingURL=getIntlayer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getIntlayer.d.ts","names":[],"sources":["../../src/getIntlayer.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"getIntlayer.d.ts","names":[],"sources":["../../src/getIntlayer.ts"],"mappings":";;;;;;AAiBA;;;cAAa,WAAA,mBACK,cAAA,kBACA,aAAA,GAAgB,wBAAA,CAAyB,CAAA,IAAK,eAAA,EAE9D,GAAA,EAAK,CAAA,EACL,gBAAA,GAAmB,CAAA,KAClB,oBAAA,CACD,wBAAA,CAAyB,CAAA,EAAG,CAAA,GAC5B,qBAAA,CAAsB,CAAA"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { LocalesValues as LocalesValues$1 } from "@intlayer/types/module_augmentation";
|
|
2
|
+
import { Locale as Locale$1 } from "@intlayer/types/allLocales";
|
|
3
|
+
import { Dictionary } from "@intlayer/types/dictionary";
|
|
4
|
+
export { type Locale$1 as Locale, type LocalesValues$1 as LocalesValues };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "preact-intlayer",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "9.0.0-canary.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Easily internationalize i18n your Preact applications with type-safe multilingual content management.",
|
|
6
6
|
"keywords": [
|
|
@@ -100,15 +100,15 @@
|
|
|
100
100
|
"typecheck": "tsc --noEmit --project tsconfig.types.json"
|
|
101
101
|
},
|
|
102
102
|
"dependencies": {
|
|
103
|
-
"@intlayer/api": "
|
|
104
|
-
"@intlayer/chokidar": "
|
|
105
|
-
"@intlayer/config": "
|
|
106
|
-
"@intlayer/core": "
|
|
107
|
-
"@intlayer/editor": "
|
|
108
|
-
"@intlayer/types": "
|
|
103
|
+
"@intlayer/api": "9.0.0-canary.0",
|
|
104
|
+
"@intlayer/chokidar": "9.0.0-canary.0",
|
|
105
|
+
"@intlayer/config": "9.0.0-canary.0",
|
|
106
|
+
"@intlayer/core": "9.0.0-canary.0",
|
|
107
|
+
"@intlayer/editor": "9.0.0-canary.0",
|
|
108
|
+
"@intlayer/types": "9.0.0-canary.0"
|
|
109
109
|
},
|
|
110
110
|
"devDependencies": {
|
|
111
|
-
"@types/node": "25.9.
|
|
111
|
+
"@types/node": "25.9.3",
|
|
112
112
|
"@utils/ts-config": "1.0.4",
|
|
113
113
|
"@utils/ts-config-types": "1.0.4",
|
|
114
114
|
"@utils/tsdown-config": "1.0.4",
|