preact-intlayer 8.4.4 → 8.4.6
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/IntlayerNode.cjs +16 -1
- package/dist/cjs/IntlayerNode.cjs.map +1 -1
- package/dist/cjs/UI/ContentSelector.cjs +96 -1
- package/dist/cjs/UI/ContentSelector.cjs.map +1 -1
- package/dist/cjs/_virtual/_rolldown/runtime.cjs +29 -0
- package/dist/cjs/client/IntlayerProvider.cjs +88 -1
- package/dist/cjs/client/IntlayerProvider.cjs.map +1 -0
- package/dist/cjs/client/format/index.cjs +18 -1
- package/dist/cjs/client/format/useCompact.cjs +27 -1
- package/dist/cjs/client/format/useCompact.cjs.map +1 -1
- package/dist/cjs/client/format/useCurrency.cjs +41 -1
- package/dist/cjs/client/format/useCurrency.cjs.map +1 -1
- package/dist/cjs/client/format/useDate.cjs +43 -1
- package/dist/cjs/client/format/useDate.cjs.map +1 -1
- package/dist/cjs/client/format/useIntl.cjs +33 -1
- package/dist/cjs/client/format/useIntl.cjs.map +1 -1
- package/dist/cjs/client/format/useList.cjs +38 -1
- package/dist/cjs/client/format/useList.cjs.map +1 -1
- package/dist/cjs/client/format/useNumber.cjs +39 -1
- package/dist/cjs/client/format/useNumber.cjs.map +1 -1
- package/dist/cjs/client/format/usePercentage.cjs +35 -1
- package/dist/cjs/client/format/usePercentage.cjs.map +1 -1
- package/dist/cjs/client/format/useRelativeTime.cjs +35 -1
- package/dist/cjs/client/format/useRelativeTime.cjs.map +1 -1
- package/dist/cjs/client/format/useUnit.cjs +34 -1
- package/dist/cjs/client/format/useUnit.cjs.map +1 -1
- package/dist/cjs/client/index.cjs +32 -1
- package/dist/cjs/client/t.cjs +19 -1
- package/dist/cjs/client/t.cjs.map +1 -1
- package/dist/cjs/client/useContent.cjs +19 -1
- package/dist/cjs/client/useContent.cjs.map +1 -1
- package/dist/cjs/client/useDictionary.cjs +25 -1
- package/dist/cjs/client/useDictionary.cjs.map +1 -1
- package/dist/cjs/client/useDictionaryAsync.cjs +22 -1
- package/dist/cjs/client/useDictionaryAsync.cjs.map +1 -1
- package/dist/cjs/client/useDictionaryDynamic.cjs +21 -1
- package/dist/cjs/client/useDictionaryDynamic.cjs.map +1 -1
- package/dist/cjs/client/useIntlayer.cjs +40 -1
- package/dist/cjs/client/useIntlayer.cjs.map +1 -1
- package/dist/cjs/client/useLoadDynamic.cjs +27 -1
- package/dist/cjs/client/useLoadDynamic.cjs.map +1 -1
- package/dist/cjs/client/useLocale.cjs +54 -1
- package/dist/cjs/client/useLocale.cjs.map +1 -1
- package/dist/cjs/client/useLocaleBase.cjs +24 -1
- package/dist/cjs/client/useLocaleBase.cjs.map +1 -1
- package/dist/cjs/client/useLocaleStorage.cjs +59 -1
- package/dist/cjs/client/useLocaleStorage.cjs.map +1 -1
- package/dist/cjs/client/useTraduction.cjs +35 -1
- package/dist/cjs/client/useTraduction.cjs.map +1 -1
- package/dist/cjs/editor/ContentSelector.cjs +24 -1
- package/dist/cjs/editor/ContentSelector.cjs.map +1 -1
- package/dist/cjs/editor/EditorProvider.cjs +12 -1
- package/dist/cjs/editor/EditorProvider.cjs.map +1 -0
- package/dist/cjs/editor/useEditor.cjs +38 -1
- package/dist/cjs/editor/useEditor.cjs.map +1 -0
- package/dist/cjs/getDictionary.cjs +10 -1
- package/dist/cjs/getDictionary.cjs.map +1 -1
- package/dist/cjs/getIntlayer.cjs +10 -1
- package/dist/cjs/getIntlayer.cjs.map +1 -1
- package/dist/cjs/html/HTMLProvider.cjs +17 -1
- package/dist/cjs/html/HTMLProvider.cjs.map +1 -1
- package/dist/cjs/html/HTMLRenderer.cjs +54 -1
- package/dist/cjs/html/HTMLRenderer.cjs.map +1 -1
- package/dist/cjs/html/index.cjs +10 -1
- package/dist/cjs/index.cjs +57 -1
- package/dist/cjs/markdown/MarkdownProvider.cjs +54 -1
- package/dist/cjs/markdown/MarkdownProvider.cjs.map +1 -1
- package/dist/cjs/markdown/MarkdownRenderer.cjs +77 -1
- package/dist/cjs/markdown/MarkdownRenderer.cjs.map +1 -1
- package/dist/cjs/markdown/MarkdownRendererPlugin.cjs +26 -1
- package/dist/cjs/markdown/MarkdownRendererPlugin.cjs.map +1 -1
- package/dist/cjs/markdown/compiler.cjs +24 -1
- package/dist/cjs/markdown/compiler.cjs.map +1 -1
- package/dist/cjs/markdown/index.cjs +23 -1
- package/dist/cjs/markdown/runtime.cjs +18 -1
- package/dist/cjs/markdown/runtime.cjs.map +1 -1
- package/dist/cjs/plugins.cjs +239 -1
- package/dist/cjs/plugins.cjs.map +1 -1
- package/dist/cjs/preactElement/renderPreactElement.cjs +42 -1
- package/dist/cjs/preactElement/renderPreactElement.cjs.map +1 -1
- package/dist/esm/IntlayerNode.mjs +14 -1
- package/dist/esm/IntlayerNode.mjs.map +1 -1
- package/dist/esm/UI/ContentSelector.mjs +94 -1
- package/dist/esm/UI/ContentSelector.mjs.map +1 -1
- package/dist/esm/client/IntlayerProvider.mjs +82 -1
- package/dist/esm/client/IntlayerProvider.mjs.map +1 -0
- package/dist/esm/client/format/index.mjs +10 -1
- package/dist/esm/client/format/useCompact.mjs +25 -1
- package/dist/esm/client/format/useCompact.mjs.map +1 -1
- package/dist/esm/client/format/useCurrency.mjs +39 -1
- package/dist/esm/client/format/useCurrency.mjs.map +1 -1
- package/dist/esm/client/format/useDate.mjs +41 -1
- package/dist/esm/client/format/useDate.mjs.map +1 -1
- package/dist/esm/client/format/useIntl.mjs +31 -1
- package/dist/esm/client/format/useIntl.mjs.map +1 -1
- package/dist/esm/client/format/useList.mjs +36 -1
- package/dist/esm/client/format/useList.mjs.map +1 -1
- package/dist/esm/client/format/useNumber.mjs +37 -1
- package/dist/esm/client/format/useNumber.mjs.map +1 -1
- package/dist/esm/client/format/usePercentage.mjs +33 -1
- package/dist/esm/client/format/usePercentage.mjs.map +1 -1
- package/dist/esm/client/format/useRelativeTime.mjs +33 -1
- package/dist/esm/client/format/useRelativeTime.mjs.map +1 -1
- package/dist/esm/client/format/useUnit.mjs +32 -1
- package/dist/esm/client/format/useUnit.mjs.map +1 -1
- package/dist/esm/client/index.mjs +13 -1
- package/dist/esm/client/t.mjs +17 -1
- package/dist/esm/client/t.mjs.map +1 -1
- package/dist/esm/client/useContent.mjs +18 -1
- package/dist/esm/client/useContent.mjs.map +1 -1
- package/dist/esm/client/useDictionary.mjs +23 -1
- package/dist/esm/client/useDictionary.mjs.map +1 -1
- package/dist/esm/client/useDictionaryAsync.mjs +19 -1
- package/dist/esm/client/useDictionaryAsync.mjs.map +1 -1
- package/dist/esm/client/useDictionaryDynamic.mjs +19 -1
- package/dist/esm/client/useDictionaryDynamic.mjs.map +1 -1
- package/dist/esm/client/useIntlayer.mjs +38 -1
- package/dist/esm/client/useIntlayer.mjs.map +1 -1
- package/dist/esm/client/useLoadDynamic.mjs +25 -1
- package/dist/esm/client/useLoadDynamic.mjs.map +1 -1
- package/dist/esm/client/useLocale.mjs +51 -1
- package/dist/esm/client/useLocale.mjs.map +1 -1
- package/dist/esm/client/useLocaleBase.mjs +21 -1
- package/dist/esm/client/useLocaleBase.mjs.map +1 -1
- package/dist/esm/client/useLocaleStorage.mjs +52 -1
- package/dist/esm/client/useLocaleStorage.mjs.map +1 -1
- package/dist/esm/client/useTraduction.mjs +33 -1
- package/dist/esm/client/useTraduction.mjs.map +1 -1
- package/dist/esm/editor/ContentSelector.mjs +22 -1
- package/dist/esm/editor/ContentSelector.mjs.map +1 -1
- package/dist/esm/editor/EditorProvider.mjs +11 -1
- package/dist/esm/editor/EditorProvider.mjs.map +1 -0
- package/dist/esm/editor/useEditor.mjs +36 -1
- package/dist/esm/editor/useEditor.mjs.map +1 -0
- 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/esm/html/HTMLProvider.mjs +14 -1
- package/dist/esm/html/HTMLProvider.mjs.map +1 -1
- package/dist/esm/html/HTMLRenderer.mjs +49 -1
- package/dist/esm/html/HTMLRenderer.mjs.map +1 -1
- package/dist/esm/html/index.mjs +4 -1
- package/dist/esm/index.mjs +22 -1
- package/dist/esm/markdown/MarkdownProvider.mjs +51 -1
- package/dist/esm/markdown/MarkdownProvider.mjs.map +1 -1
- package/dist/esm/markdown/MarkdownRenderer.mjs +73 -1
- package/dist/esm/markdown/MarkdownRenderer.mjs.map +1 -1
- package/dist/esm/markdown/MarkdownRendererPlugin.mjs +23 -1
- package/dist/esm/markdown/MarkdownRendererPlugin.mjs.map +1 -1
- package/dist/esm/markdown/compiler.mjs +17 -1
- package/dist/esm/markdown/compiler.mjs.map +1 -1
- package/dist/esm/markdown/index.mjs +7 -1
- package/dist/esm/markdown/runtime.mjs +15 -1
- package/dist/esm/markdown/runtime.mjs.map +1 -1
- package/dist/esm/plugins.mjs +229 -1
- package/dist/esm/plugins.mjs.map +1 -1
- package/dist/esm/preactElement/renderPreactElement.mjs +40 -1
- package/dist/esm/preactElement/renderPreactElement.mjs.map +1 -1
- package/dist/types/IntlayerNode.d.ts +23 -2
- package/dist/types/IntlayerNode.d.ts.map +1 -0
- package/dist/types/client/IntlayerProvider.d.ts +53 -2
- package/dist/types/client/IntlayerProvider.d.ts.map +1 -0
- package/dist/types/client/format/useIntl.d.ts +26 -2
- package/dist/types/client/format/useIntl.d.ts.map +1 -0
- package/dist/types/client/index.d.ts +11 -11
- package/dist/types/client/t.d.ts +13 -2
- package/dist/types/client/t.d.ts.map +1 -0
- package/dist/types/client/useDictionary.d.ts +16 -2
- package/dist/types/client/useDictionary.d.ts.map +1 -0
- package/dist/types/client/useDictionaryAsync.d.ts +13 -2
- package/dist/types/client/useDictionaryAsync.d.ts.map +1 -0
- package/dist/types/client/useDictionaryDynamic.d.ts +16 -2
- package/dist/types/client/useDictionaryDynamic.d.ts.map +1 -0
- package/dist/types/client/useIntlayer.d.ts +28 -2
- package/dist/types/client/useIntlayer.d.ts.map +1 -0
- package/dist/types/client/useLoadDynamic.d.ts +5 -2
- package/dist/types/client/useLoadDynamic.d.ts.map +1 -0
- package/dist/types/client/useLocale.d.ts +43 -2
- package/dist/types/client/useLocale.d.ts.map +1 -0
- package/dist/types/client/useLocaleBase.d.ts +16 -2
- package/dist/types/client/useLocaleBase.d.ts.map +1 -0
- package/dist/types/client/useLocaleStorage.d.ts +45 -2
- package/dist/types/client/useLocaleStorage.d.ts.map +1 -0
- package/dist/types/getDictionary.d.ts +1 -1
- package/dist/types/getIntlayer.d.ts +1 -1
- package/dist/types/html/HTMLProvider.d.ts +18 -2
- package/dist/types/html/HTMLProvider.d.ts.map +1 -0
- package/dist/types/html/HTMLRenderer.d.ts +61 -2
- package/dist/types/html/HTMLRenderer.d.ts.map +1 -0
- package/dist/types/html/index.d.ts +2 -2
- package/dist/types/html/types.d.ts +38 -2
- package/dist/types/html/types.d.ts.map +1 -0
- package/dist/types/index.d.ts +19 -19
- package/dist/types/markdown/MarkdownProvider.d.ts +52 -2
- package/dist/types/markdown/MarkdownProvider.d.ts.map +1 -0
- package/dist/types/markdown/MarkdownRenderer.d.ts +61 -2
- package/dist/types/markdown/MarkdownRenderer.d.ts.map +1 -0
- package/dist/types/markdown/MarkdownRendererPlugin.d.ts +23 -2
- package/dist/types/markdown/MarkdownRendererPlugin.d.ts.map +1 -0
- package/dist/types/markdown/compiler.d.ts +14 -2
- package/dist/types/markdown/compiler.d.ts.map +1 -0
- package/dist/types/markdown/index.d.ts +5 -5
- package/dist/types/markdown/runtime.d.ts +10 -2
- package/dist/types/markdown/runtime.d.ts.map +1 -0
- package/dist/types/plugins.d.ts +96 -2
- package/dist/types/plugins.d.ts.map +1 -0
- package/package.json +7 -7
- package/dist/cjs/IntlayerProvider-sM1gzsx7.cjs +0 -2
- package/dist/cjs/IntlayerProvider-sM1gzsx7.cjs.map +0 -1
- package/dist/esm/IntlayerProvider-ClOcEK3A.mjs +0 -2
- package/dist/esm/IntlayerProvider-ClOcEK3A.mjs.map +0 -1
- package/dist/types/HTMLProvider-8sO8DU8H.d.ts +0 -18
- package/dist/types/HTMLProvider-8sO8DU8H.d.ts.map +0 -1
- package/dist/types/HTMLRenderer-NNa_9oMD.d.ts +0 -61
- package/dist/types/HTMLRenderer-NNa_9oMD.d.ts.map +0 -1
- package/dist/types/IntlayerNode-CIzFHYnC.d.ts +0 -23
- package/dist/types/IntlayerNode-CIzFHYnC.d.ts.map +0 -1
- package/dist/types/IntlayerProvider-aV596OL4.d.ts +0 -53
- package/dist/types/IntlayerProvider-aV596OL4.d.ts.map +0 -1
- package/dist/types/MarkdownProvider-chUIO05u.d.ts +0 -52
- package/dist/types/MarkdownProvider-chUIO05u.d.ts.map +0 -1
- package/dist/types/MarkdownRenderer-BMhuurZW.d.ts +0 -61
- package/dist/types/MarkdownRenderer-BMhuurZW.d.ts.map +0 -1
- package/dist/types/MarkdownRendererPlugin-DFRVdHCA.d.ts +0 -23
- package/dist/types/MarkdownRendererPlugin-DFRVdHCA.d.ts.map +0 -1
- package/dist/types/compiler-BB0gAVbe.d.ts +0 -14
- package/dist/types/compiler-BB0gAVbe.d.ts.map +0 -1
- package/dist/types/plugins-D6OB94dO.d.ts +0 -95
- package/dist/types/plugins-D6OB94dO.d.ts.map +0 -1
- package/dist/types/runtime-BMHAtT-R.d.ts +0 -10
- package/dist/types/runtime-BMHAtT-R.d.ts.map +0 -1
- package/dist/types/t-CalXqnSB.d.ts +0 -13
- package/dist/types/t-CalXqnSB.d.ts.map +0 -1
- package/dist/types/types-B3Kzdco6.d.ts +0 -38
- package/dist/types/types-B3Kzdco6.d.ts.map +0 -1
- package/dist/types/useDictionary-cjQAc1l1.d.ts +0 -16
- package/dist/types/useDictionary-cjQAc1l1.d.ts.map +0 -1
- package/dist/types/useDictionaryAsync-CDCcBnXn.d.ts +0 -13
- package/dist/types/useDictionaryAsync-CDCcBnXn.d.ts.map +0 -1
- package/dist/types/useDictionaryDynamic-BQgaM0vp.d.ts +0 -16
- package/dist/types/useDictionaryDynamic-BQgaM0vp.d.ts.map +0 -1
- package/dist/types/useIntl-DfzrSGu4.d.ts +0 -26
- package/dist/types/useIntl-DfzrSGu4.d.ts.map +0 -1
- package/dist/types/useIntlayer-BINmW9T1.d.ts +0 -28
- package/dist/types/useIntlayer-BINmW9T1.d.ts.map +0 -1
- package/dist/types/useLoadDynamic-DFXHehpF.d.ts +0 -5
- package/dist/types/useLoadDynamic-DFXHehpF.d.ts.map +0 -1
- package/dist/types/useLocale-BDQ4yLc5.d.ts +0 -43
- package/dist/types/useLocale-BDQ4yLc5.d.ts.map +0 -1
- package/dist/types/useLocaleBase-1L1RLyXD.d.ts +0 -16
- package/dist/types/useLocaleBase-1L1RLyXD.d.ts.map +0 -1
- package/dist/types/useLocaleStorage-BwH9gqN5.d.ts +0 -45
- package/dist/types/useLocaleStorage-BwH9gqN5.d.ts.map +0 -1
|
@@ -1,2 +1,34 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import { IntlayerClientContext } from "../IntlayerProvider.mjs";
|
|
2
|
+
import { useCallback, useContext } from "preact/hooks";
|
|
3
|
+
import { percentage } from "@intlayer/core/formatters";
|
|
4
|
+
|
|
5
|
+
//#region src/client/format/usePercentage.ts
|
|
6
|
+
/**
|
|
7
|
+
* React hook to provide a percentage formatter function
|
|
8
|
+
* based on the current application locale.
|
|
9
|
+
*
|
|
10
|
+
* This hook retrieves the active locale using {@link useLocaleBase}
|
|
11
|
+
* and memoizes a `createPercentage` instance for that locale.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```tsx
|
|
15
|
+
* const formatPercentage = usePercentage();
|
|
16
|
+
*
|
|
17
|
+
* const result = formatPercentage(0.875, { maximumFractionDigits: 1 });
|
|
18
|
+
* // "87.5%" (depending on locale)
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @returns {(value: string | number, options?: Omit<PercentageOptions, "value">) => string}
|
|
22
|
+
* A function that formats numbers or numeric strings into localized percentages.
|
|
23
|
+
*/
|
|
24
|
+
const usePercentage = () => {
|
|
25
|
+
const { locale } = useContext(IntlayerClientContext);
|
|
26
|
+
return useCallback((...args) => percentage(args[0], {
|
|
27
|
+
...args[1],
|
|
28
|
+
locale: args[1]?.locale ?? locale
|
|
29
|
+
}), [locale]);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
//#endregion
|
|
33
|
+
export { usePercentage };
|
|
2
34
|
//# sourceMappingURL=usePercentage.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePercentage.mjs","names":[],"sources":["../../../../src/client/format/usePercentage.ts"],"sourcesContent":["import { percentage } from '@intlayer/core/formatters';\nimport { useCallback, useContext } from 'preact/hooks';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * React hook to provide a percentage formatter function\n * based on the current application locale.\n *\n * This hook retrieves the active locale using {@link useLocaleBase}\n * and memoizes a `createPercentage` instance for that locale.\n *\n * @example\n * ```tsx\n * const formatPercentage = usePercentage();\n *\n * const result = formatPercentage(0.875, { maximumFractionDigits: 1 });\n * // \"87.5%\" (depending on locale)\n * ```\n *\n * @returns {(value: string | number, options?: Omit<PercentageOptions, \"value\">) => string}\n * A function that formats numbers or numeric strings into localized percentages.\n */\nexport const usePercentage = () => {\n const { locale } = useContext(IntlayerClientContext);\n\n return useCallback(\n (...args: Parameters<typeof percentage>) =>\n percentage(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n }),\n [locale]\n );\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"usePercentage.mjs","names":[],"sources":["../../../../src/client/format/usePercentage.ts"],"sourcesContent":["import { percentage } from '@intlayer/core/formatters';\nimport { useCallback, useContext } from 'preact/hooks';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * React hook to provide a percentage formatter function\n * based on the current application locale.\n *\n * This hook retrieves the active locale using {@link useLocaleBase}\n * and memoizes a `createPercentage` instance for that locale.\n *\n * @example\n * ```tsx\n * const formatPercentage = usePercentage();\n *\n * const result = formatPercentage(0.875, { maximumFractionDigits: 1 });\n * // \"87.5%\" (depending on locale)\n * ```\n *\n * @returns {(value: string | number, options?: Omit<PercentageOptions, \"value\">) => string}\n * A function that formats numbers or numeric strings into localized percentages.\n */\nexport const usePercentage = () => {\n const { locale } = useContext(IntlayerClientContext);\n\n return useCallback(\n (...args: Parameters<typeof percentage>) =>\n percentage(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n }),\n [locale]\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAsBA,MAAa,sBAAsB;CACjC,MAAM,EAAE,WAAW,WAAW,sBAAsB;AAEpD,QAAO,aACJ,GAAG,SACF,WAAW,KAAK,IAAI;EAClB,GAAG,KAAK;EACR,QAAQ,KAAK,IAAI,UAAU;EAC5B,CAAC,EACJ,CAAC,OAAO,CACT"}
|
|
@@ -1,2 +1,34 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import { IntlayerClientContext } from "../IntlayerProvider.mjs";
|
|
2
|
+
import { useCallback, useContext } from "preact/hooks";
|
|
3
|
+
import { relativeTime } from "@intlayer/core/formatters";
|
|
4
|
+
|
|
5
|
+
//#region src/client/format/useRelativeTime.ts
|
|
6
|
+
/**
|
|
7
|
+
* Client-side React hook for accessing a localized relative time formatter.
|
|
8
|
+
*
|
|
9
|
+
* This hook:
|
|
10
|
+
* - Reads the current locale from {@link useLocaleBase}.
|
|
11
|
+
* - Creates a new relative time formatter with {@link createRelativeTime}.
|
|
12
|
+
* - Returns a function that can format time differences into localized strings.
|
|
13
|
+
*
|
|
14
|
+
* Example:
|
|
15
|
+
* ```tsx
|
|
16
|
+
* const relativeTime = useRelativeTime();
|
|
17
|
+
* const formatted = relativeTime(new Date("2024-08-01"), new Date());
|
|
18
|
+
* // e.g., "2 weeks ago"
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @returns {ReturnType<typeof createRelativeTime>} A relative time formatting function
|
|
22
|
+
* bound to the current client locale.
|
|
23
|
+
*/
|
|
24
|
+
const useRelativeTime = () => {
|
|
25
|
+
const { locale } = useContext(IntlayerClientContext);
|
|
26
|
+
return useCallback((...args) => relativeTime(args[0], args[1], {
|
|
27
|
+
...args[2],
|
|
28
|
+
locale: args[2]?.locale ?? locale
|
|
29
|
+
}), [locale]);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
//#endregion
|
|
33
|
+
export { useRelativeTime };
|
|
2
34
|
//# sourceMappingURL=useRelativeTime.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRelativeTime.mjs","names":[],"sources":["../../../../src/client/format/useRelativeTime.ts"],"sourcesContent":["import { relativeTime } from '@intlayer/core/formatters';\nimport { useCallback, useContext } from 'preact/hooks';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * Client-side React hook for accessing a localized relative time formatter.\n *\n * This hook:\n * - Reads the current locale from {@link useLocaleBase}.\n * - Creates a new relative time formatter with {@link createRelativeTime}.\n * - Returns a function that can format time differences into localized strings.\n *\n * Example:\n * ```tsx\n * const relativeTime = useRelativeTime();\n * const formatted = relativeTime(new Date(\"2024-08-01\"), new Date());\n * // e.g., \"2 weeks ago\"\n * ```\n *\n * @returns {ReturnType<typeof createRelativeTime>} A relative time formatting function\n * bound to the current client locale.\n */\nexport const useRelativeTime = () => {\n const { locale } = useContext(IntlayerClientContext);\n\n return useCallback(\n (...args: Parameters<typeof relativeTime>) =>\n relativeTime(args[0], args[1], {\n ...args[2],\n locale: args[2]?.locale ?? locale,\n }),\n [locale]\n );\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useRelativeTime.mjs","names":[],"sources":["../../../../src/client/format/useRelativeTime.ts"],"sourcesContent":["import { relativeTime } from '@intlayer/core/formatters';\nimport { useCallback, useContext } from 'preact/hooks';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * Client-side React hook for accessing a localized relative time formatter.\n *\n * This hook:\n * - Reads the current locale from {@link useLocaleBase}.\n * - Creates a new relative time formatter with {@link createRelativeTime}.\n * - Returns a function that can format time differences into localized strings.\n *\n * Example:\n * ```tsx\n * const relativeTime = useRelativeTime();\n * const formatted = relativeTime(new Date(\"2024-08-01\"), new Date());\n * // e.g., \"2 weeks ago\"\n * ```\n *\n * @returns {ReturnType<typeof createRelativeTime>} A relative time formatting function\n * bound to the current client locale.\n */\nexport const useRelativeTime = () => {\n const { locale } = useContext(IntlayerClientContext);\n\n return useCallback(\n (...args: Parameters<typeof relativeTime>) =>\n relativeTime(args[0], args[1], {\n ...args[2],\n locale: args[2]?.locale ?? locale,\n }),\n [locale]\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAsBA,MAAa,wBAAwB;CACnC,MAAM,EAAE,WAAW,WAAW,sBAAsB;AAEpD,QAAO,aACJ,GAAG,SACF,aAAa,KAAK,IAAI,KAAK,IAAI;EAC7B,GAAG,KAAK;EACR,QAAQ,KAAK,IAAI,UAAU;EAC5B,CAAC,EACJ,CAAC,OAAO,CACT"}
|
|
@@ -1,2 +1,33 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import { IntlayerClientContext } from "../IntlayerProvider.mjs";
|
|
2
|
+
import { useCallback, useContext } from "preact/hooks";
|
|
3
|
+
import { units } from "@intlayer/core/formatters";
|
|
4
|
+
|
|
5
|
+
//#region src/client/format/useUnit.ts
|
|
6
|
+
/**
|
|
7
|
+
* React hook that provides a unit formatting function
|
|
8
|
+
* based on the current locale from {@link useLocaleBase}.
|
|
9
|
+
*
|
|
10
|
+
* This hook wraps {@link createUnit} to return a formatter
|
|
11
|
+
* that can convert values into human-readable localized units
|
|
12
|
+
* (e.g., "10 km", "5 lbs").
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```tsx
|
|
16
|
+
* const formatUnit = useUnit();
|
|
17
|
+
* const distance = formatUnit(10, { unit: "kilometer" });
|
|
18
|
+
* // "10 km" (depending on locale)
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @returns {Function} A unit formatting function that accepts a value and optional formatting options.
|
|
22
|
+
*/
|
|
23
|
+
const useUnit = () => {
|
|
24
|
+
const { locale } = useContext(IntlayerClientContext);
|
|
25
|
+
return useCallback((...args) => units(args[0], {
|
|
26
|
+
...args[1],
|
|
27
|
+
locale: args[1]?.locale ?? locale
|
|
28
|
+
}), [locale]);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
//#endregion
|
|
32
|
+
export { useUnit };
|
|
2
33
|
//# sourceMappingURL=useUnit.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useUnit.mjs","names":[],"sources":["../../../../src/client/format/useUnit.ts"],"sourcesContent":["import { units } from '@intlayer/core/formatters';\nimport { useCallback, useContext } from 'preact/hooks';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * React hook that provides a unit formatting function\n * based on the current locale from {@link useLocaleBase}.\n *\n * This hook wraps {@link createUnit} to return a formatter\n * that can convert values into human-readable localized units\n * (e.g., \"10 km\", \"5 lbs\").\n *\n * @example\n * ```tsx\n * const formatUnit = useUnit();\n * const distance = formatUnit(10, { unit: \"kilometer\" });\n * // \"10 km\" (depending on locale)\n * ```\n *\n * @returns {Function} A unit formatting function that accepts a value and optional formatting options.\n */\nexport const useUnit = () => {\n const { locale } = useContext(IntlayerClientContext);\n\n return useCallback(\n (...args: Parameters<typeof units>) =>\n units(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n }),\n [locale]\n );\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useUnit.mjs","names":[],"sources":["../../../../src/client/format/useUnit.ts"],"sourcesContent":["import { units } from '@intlayer/core/formatters';\nimport { useCallback, useContext } from 'preact/hooks';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * React hook that provides a unit formatting function\n * based on the current locale from {@link useLocaleBase}.\n *\n * This hook wraps {@link createUnit} to return a formatter\n * that can convert values into human-readable localized units\n * (e.g., \"10 km\", \"5 lbs\").\n *\n * @example\n * ```tsx\n * const formatUnit = useUnit();\n * const distance = formatUnit(10, { unit: \"kilometer\" });\n * // \"10 km\" (depending on locale)\n * ```\n *\n * @returns {Function} A unit formatting function that accepts a value and optional formatting options.\n */\nexport const useUnit = () => {\n const { locale } = useContext(IntlayerClientContext);\n\n return useCallback(\n (...args: Parameters<typeof units>) =>\n units(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n }),\n [locale]\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAqBA,MAAa,gBAAgB;CAC3B,MAAM,EAAE,WAAW,WAAW,sBAAsB;AAEpD,QAAO,aACJ,GAAG,SACF,MAAM,KAAK,IAAI;EACb,GAAG,KAAK;EACR,QAAQ,KAAK,IAAI,UAAU;EAC5B,CAAC,EACJ,CAAC,OAAO,CACT"}
|
|
@@ -1 +1,13 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import { localeCookie, localeInStorage, setLocaleCookie, setLocaleInStorage, useLocaleCookie, useLocaleStorage } from "./useLocaleStorage.mjs";
|
|
2
|
+
import { IntlayerClientContext, IntlayerProvider, IntlayerProviderContent, useIntlayerContext } from "./IntlayerProvider.mjs";
|
|
3
|
+
import { useIntl } from "./format/useIntl.mjs";
|
|
4
|
+
import { t } from "./t.mjs";
|
|
5
|
+
import { useDictionary } from "./useDictionary.mjs";
|
|
6
|
+
import { useDictionaryAsync } from "./useDictionaryAsync.mjs";
|
|
7
|
+
import { useLoadDynamic } from "./useLoadDynamic.mjs";
|
|
8
|
+
import { useDictionaryDynamic } from "./useDictionaryDynamic.mjs";
|
|
9
|
+
import { useIntlayer } from "./useIntlayer.mjs";
|
|
10
|
+
import { useLocale } from "./useLocale.mjs";
|
|
11
|
+
import { useLocaleBase } from "./useLocaleBase.mjs";
|
|
12
|
+
|
|
13
|
+
export { IntlayerClientContext, IntlayerProvider, IntlayerProviderContent, localeCookie, localeInStorage, setLocaleCookie, setLocaleInStorage, t, useDictionary, useDictionaryAsync, useDictionaryDynamic, useIntl, useIntlayer, useIntlayerContext, useLoadDynamic, useLocale, useLocaleBase, useLocaleCookie, useLocaleStorage };
|
package/dist/esm/client/t.mjs
CHANGED
|
@@ -1,2 +1,18 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import { IntlayerClientContext } from "./IntlayerProvider.mjs";
|
|
2
|
+
import { getTranslation } from "@intlayer/core/interpreter";
|
|
3
|
+
import { useContext } from "preact/hooks";
|
|
4
|
+
|
|
5
|
+
//#region src/client/t.ts
|
|
6
|
+
/**
|
|
7
|
+
* On the client side, this function returns the translation of the provided multilang content.
|
|
8
|
+
*
|
|
9
|
+
* If the locale is not provided, it will use the locale from the client context
|
|
10
|
+
*/
|
|
11
|
+
const t = (multilangContent, locale) => {
|
|
12
|
+
const { locale: currentLocale } = useContext(IntlayerClientContext);
|
|
13
|
+
return getTranslation(multilangContent, locale ?? currentLocale);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
//#endregion
|
|
17
|
+
export { t };
|
|
2
18
|
//# sourceMappingURL=t.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"t.mjs","names":[],"sources":["../../../src/client/t.ts"],"sourcesContent":["import { getTranslation } from '@intlayer/core/interpreter';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport type { StrictModeLocaleMap } from '@intlayer/types/module_augmentation';\nimport { useContext } from 'preact/hooks';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * On the client side, this function returns the translation of the provided multilang content.\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const t = <Content = string>(\n multilangContent: StrictModeLocaleMap<Content>,\n locale?: Locale\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n const localeTarget = locale ?? currentLocale;\n\n return getTranslation<Content>(multilangContent, localeTarget);\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"t.mjs","names":[],"sources":["../../../src/client/t.ts"],"sourcesContent":["import { getTranslation } from '@intlayer/core/interpreter';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport type { StrictModeLocaleMap } from '@intlayer/types/module_augmentation';\nimport { useContext } from 'preact/hooks';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * On the client side, this function returns the translation of the provided multilang content.\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const t = <Content = string>(\n multilangContent: StrictModeLocaleMap<Content>,\n locale?: Locale\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n const localeTarget = locale ?? currentLocale;\n\n return getTranslation<Content>(multilangContent, localeTarget);\n};\n"],"mappings":";;;;;;;;;;AAWA,MAAa,KACX,kBACA,WACG;CACH,MAAM,EAAE,QAAQ,kBAAkB,WAAW,sBAAsB;AAGnE,QAAO,eAAwB,kBAFV,UAAU,cAE+B"}
|
|
@@ -1,2 +1,19 @@
|
|
|
1
|
-
import{useLocaleBase
|
|
1
|
+
import { useLocaleBase } from "./useLocaleBase.mjs";
|
|
2
|
+
import { useTranslation } from "./useTraduction.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/client/useContent.ts
|
|
5
|
+
/**
|
|
6
|
+
* On the client side, hook to get the translation content based on the locale
|
|
7
|
+
*/
|
|
8
|
+
const useContent = (languageContent) => {
|
|
9
|
+
const { locale } = useLocaleBase();
|
|
10
|
+
return {
|
|
11
|
+
locale,
|
|
12
|
+
content: useTranslation(languageContent),
|
|
13
|
+
t: useTranslation
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
export { useContent };
|
|
2
19
|
//# sourceMappingURL=useContent.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useContent.mjs","names":[],"sources":["../../../src/client/useContent.ts"],"sourcesContent":["import type { StrictModeLocaleMap } from '@intlayer/types/module_augmentation';\nimport { useLocaleBase } from './useLocaleBase';\nimport { useTranslation } from './useTraduction';\n\n/**\n * On the client side, hook to get the translation content based on the locale\n */\nexport const useContent = <Content>(\n languageContent: StrictModeLocaleMap<Content>\n) => {\n const { locale } = useLocaleBase();\n\n const content = useTranslation(languageContent);\n\n return {\n locale,\n content,\n t: useTranslation,\n };\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useContent.mjs","names":[],"sources":["../../../src/client/useContent.ts"],"sourcesContent":["import type { StrictModeLocaleMap } from '@intlayer/types/module_augmentation';\nimport { useLocaleBase } from './useLocaleBase';\nimport { useTranslation } from './useTraduction';\n\n/**\n * On the client side, hook to get the translation content based on the locale\n */\nexport const useContent = <Content>(\n languageContent: StrictModeLocaleMap<Content>\n) => {\n const { locale } = useLocaleBase();\n\n const content = useTranslation(languageContent);\n\n return {\n locale,\n content,\n t: useTranslation,\n };\n};\n"],"mappings":";;;;;;;AAOA,MAAa,cACX,oBACG;CACH,MAAM,EAAE,WAAW,eAAe;AAIlC,QAAO;EACL;EACA,SAJc,eAAe,gBAAgB;EAK7C,GAAG;EACJ"}
|
|
@@ -1,2 +1,24 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import { getDictionary } from "../getDictionary.mjs";
|
|
2
|
+
import { IntlayerClientContext } from "./IntlayerProvider.mjs";
|
|
3
|
+
import { useContext, useMemo } from "preact/hooks";
|
|
4
|
+
|
|
5
|
+
//#region src/client/useDictionary.ts
|
|
6
|
+
/**
|
|
7
|
+
* On the server side, Hook that transform a dictionary and return the content
|
|
8
|
+
*
|
|
9
|
+
* If the locale is not provided, it will use the locale from the client context
|
|
10
|
+
*/
|
|
11
|
+
const useDictionary = (dictionary, locale) => {
|
|
12
|
+
const { locale: currentLocale } = useContext(IntlayerClientContext);
|
|
13
|
+
return useMemo(() => {
|
|
14
|
+
return getDictionary(dictionary, locale ?? currentLocale);
|
|
15
|
+
}, [
|
|
16
|
+
dictionary.key,
|
|
17
|
+
currentLocale,
|
|
18
|
+
locale
|
|
19
|
+
]);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
export { useDictionary };
|
|
2
24
|
//# sourceMappingURL=useDictionary.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionary.mjs","names":[],"sources":["../../../src/client/useDictionary.ts"],"sourcesContent":["import type { Dictionary } 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 * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useDictionary = <\n T extends Dictionary,\n L extends LocalesValues = DeclaredLocales,\n>(\n dictionary: T,\n locale?: L\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n\n return useMemo(() => {\n const localeTarget = locale ?? currentLocale;\n\n return getDictionary<T, L>(dictionary, localeTarget as L);\n }, [dictionary.key, currentLocale, locale]);\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useDictionary.mjs","names":[],"sources":["../../../src/client/useDictionary.ts"],"sourcesContent":["import type { Dictionary } 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 * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useDictionary = <\n T extends Dictionary,\n L extends LocalesValues = DeclaredLocales,\n>(\n dictionary: T,\n locale?: L\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n\n return useMemo(() => {\n const localeTarget = locale ?? currentLocale;\n\n return getDictionary<T, L>(dictionary, localeTarget as L);\n }, [dictionary.key, currentLocale, locale]);\n};\n"],"mappings":";;;;;;;;;;AAcA,MAAa,iBAIX,YACA,WACG;CACH,MAAM,EAAE,QAAQ,kBAAkB,WAAW,sBAAsB;AAEnE,QAAO,cAAc;AAGnB,SAAO,cAAoB,YAFN,UAAU,cAE0B;IACxD;EAAC,WAAW;EAAK;EAAe;EAAO,CAAC"}
|
|
@@ -1,2 +1,20 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import { IntlayerClientContext } from "./IntlayerProvider.mjs";
|
|
2
|
+
import { useDictionary } from "./useDictionary.mjs";
|
|
3
|
+
import configuration from "@intlayer/config/built";
|
|
4
|
+
import { useContext, useMemo } from "preact/hooks";
|
|
5
|
+
|
|
6
|
+
//#region src/client/useDictionaryAsync.ts
|
|
7
|
+
/**
|
|
8
|
+
* On the server side, Hook that transform a dictionary and return the content
|
|
9
|
+
*
|
|
10
|
+
* If the locale is not provided, it will use the locale from the client context
|
|
11
|
+
*/
|
|
12
|
+
const useDictionaryAsync = async (dictionaryPromise, locale) => {
|
|
13
|
+
const { locale: currentLocale } = useContext(IntlayerClientContext);
|
|
14
|
+
const localeTarget = useMemo(() => locale ?? currentLocale ?? configuration?.internationalization.defaultLocale, [currentLocale, locale]);
|
|
15
|
+
return useDictionary(await useMemo(async () => await dictionaryPromise[localeTarget]?.(), [dictionaryPromise, localeTarget]), localeTarget);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
export { useDictionaryAsync };
|
|
2
20
|
//# sourceMappingURL=useDictionaryAsync.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionaryAsync.mjs","names":[],"sources":["../../../src/client/useDictionaryAsync.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { useContext, useMemo } from 'preact/hooks';\nimport { IntlayerClientContext } from './IntlayerProvider';\nimport { useDictionary } from './useDictionary';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useDictionaryAsync = async <T extends Dictionary>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n locale?: LocalesValues\n): Promise<T> => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n\n const localeTarget = useMemo(\n () =>\n locale ??\n currentLocale ??\n configuration?.internationalization.defaultLocale,\n [currentLocale, locale]\n );\n\n const dictionary = await useMemo(\n async () =>\n (await dictionaryPromise[\n localeTarget as keyof typeof dictionaryPromise\n ]?.()) as T,\n [dictionaryPromise, localeTarget]\n );\n\n return useDictionary(dictionary, localeTarget) as any;\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useDictionaryAsync.mjs","names":[],"sources":["../../../src/client/useDictionaryAsync.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { useContext, useMemo } from 'preact/hooks';\nimport { IntlayerClientContext } from './IntlayerProvider';\nimport { useDictionary } from './useDictionary';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useDictionaryAsync = async <T extends Dictionary>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n locale?: LocalesValues\n): Promise<T> => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n\n const localeTarget = useMemo(\n () =>\n locale ??\n currentLocale ??\n configuration?.internationalization.defaultLocale,\n [currentLocale, locale]\n );\n\n const dictionary = await useMemo(\n async () =>\n (await dictionaryPromise[\n localeTarget as keyof typeof dictionaryPromise\n ]?.()) as T,\n [dictionaryPromise, localeTarget]\n );\n\n return useDictionary(dictionary, localeTarget) as any;\n};\n"],"mappings":";;;;;;;;;;;AAeA,MAAa,qBAAqB,OAChC,mBACA,WACe;CACf,MAAM,EAAE,QAAQ,kBAAkB,WAAW,sBAAsB;CAEnE,MAAM,eAAe,cAEjB,UACA,iBACA,eAAe,qBAAqB,eACtC,CAAC,eAAe,OAAO,CACxB;AAUD,QAAO,cARY,MAAM,QACvB,YACG,MAAM,kBACL,iBACG,EACP,CAAC,mBAAmB,aAAa,CAClC,EAEgC,aAAa"}
|
|
@@ -1,2 +1,20 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import { IntlayerClientContext } from "./IntlayerProvider.mjs";
|
|
2
|
+
import { useDictionary } from "./useDictionary.mjs";
|
|
3
|
+
import { useLoadDynamic } from "./useLoadDynamic.mjs";
|
|
4
|
+
import { useContext, useMemo } from "preact/hooks";
|
|
5
|
+
|
|
6
|
+
//#region src/client/useDictionaryDynamic.ts
|
|
7
|
+
/**
|
|
8
|
+
* On the server side, Hook that transform a dictionary and return the content
|
|
9
|
+
*
|
|
10
|
+
* If the locale is not provided, it will use the locale from the client context
|
|
11
|
+
*/
|
|
12
|
+
const useDictionaryDynamic = (dictionaryPromise, key, locale) => {
|
|
13
|
+
const { locale: currentLocale } = useContext(IntlayerClientContext);
|
|
14
|
+
const localeTarget = useMemo(() => locale ?? currentLocale, [currentLocale, locale]);
|
|
15
|
+
return useDictionary(useLoadDynamic(`${String(key)}.${localeTarget}`, dictionaryPromise[localeTarget]?.()), localeTarget);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
export { useDictionaryDynamic };
|
|
2
20
|
//# sourceMappingURL=useDictionaryDynamic.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionaryDynamic.mjs","names":[],"sources":["../../../src/client/useDictionaryDynamic.ts"],"sourcesContent":["import type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DictionaryKeys,\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { useContext, useMemo } from 'preact/hooks';\nimport { IntlayerClientContext } from './IntlayerProvider';\nimport { useDictionary } from './useDictionary';\nimport { useLoadDynamic } from './useLoadDynamic';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useDictionaryDynamic = <\n T extends Dictionary,\n K extends DictionaryKeys,\n>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n key: K,\n locale?: LocalesValues\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n const localeTarget = useMemo(\n () => locale ?? currentLocale,\n [currentLocale, locale]\n );\n\n const dictionary = useLoadDynamic<T>(\n `${String(key)}.${localeTarget}`,\n (dictionaryPromise as any)[localeTarget]?.()\n ) as T;\n\n return useDictionary(dictionary, localeTarget);\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useDictionaryDynamic.mjs","names":[],"sources":["../../../src/client/useDictionaryDynamic.ts"],"sourcesContent":["import type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DictionaryKeys,\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { useContext, useMemo } from 'preact/hooks';\nimport { IntlayerClientContext } from './IntlayerProvider';\nimport { useDictionary } from './useDictionary';\nimport { useLoadDynamic } from './useLoadDynamic';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useDictionaryDynamic = <\n T extends Dictionary,\n K extends DictionaryKeys,\n>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n key: K,\n locale?: LocalesValues\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n const localeTarget = useMemo(\n () => locale ?? currentLocale,\n [currentLocale, locale]\n );\n\n const dictionary = useLoadDynamic<T>(\n `${String(key)}.${localeTarget}`,\n (dictionaryPromise as any)[localeTarget]?.()\n ) as T;\n\n return useDictionary(dictionary, localeTarget);\n};\n"],"mappings":";;;;;;;;;;;AAgBA,MAAa,wBAIX,mBACA,KACA,WACG;CACH,MAAM,EAAE,QAAQ,kBAAkB,WAAW,sBAAsB;CACnE,MAAM,eAAe,cACb,UAAU,eAChB,CAAC,eAAe,OAAO,CACxB;AAOD,QAAO,cALY,eACjB,GAAG,OAAO,IAAI,CAAC,GAAG,gBACjB,kBAA0B,iBAAiB,CAC7C,EAEgC,aAAa"}
|
|
@@ -1,2 +1,39 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import { getIntlayer } from "../getIntlayer.mjs";
|
|
2
|
+
import { IntlayerClientContext } from "./IntlayerProvider.mjs";
|
|
3
|
+
import { useContext, useMemo } from "preact/hooks";
|
|
4
|
+
|
|
5
|
+
//#region src/client/useIntlayer.ts
|
|
6
|
+
/**
|
|
7
|
+
* Preact hook that picks one dictionary by its key and returns its content.
|
|
8
|
+
*
|
|
9
|
+
* If the locale is not provided, it will use the locale from the client context.
|
|
10
|
+
*
|
|
11
|
+
* @param key - The unique key of the dictionary to retrieve.
|
|
12
|
+
* @param locale - Optional locale to override the current context locale.
|
|
13
|
+
* @returns The transformed dictionary content.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```tsx
|
|
17
|
+
* import { useIntlayer } from 'preact-intlayer';
|
|
18
|
+
*
|
|
19
|
+
* const MyComponent = () => {
|
|
20
|
+
* const content = useIntlayer('my-dictionary-key');
|
|
21
|
+
*
|
|
22
|
+
* return <div>{content.myField.value}</div>;
|
|
23
|
+
* };
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
const useIntlayer = (key, locale) => {
|
|
27
|
+
const { locale: currentLocale } = useContext(IntlayerClientContext);
|
|
28
|
+
return useMemo(() => {
|
|
29
|
+
return getIntlayer(key, locale ?? currentLocale);
|
|
30
|
+
}, [
|
|
31
|
+
key,
|
|
32
|
+
currentLocale,
|
|
33
|
+
locale
|
|
34
|
+
]);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
export { useIntlayer };
|
|
2
39
|
//# sourceMappingURL=useIntlayer.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIntlayer.mjs","names":[],"sources":["../../../src/client/useIntlayer.ts"],"sourcesContent":["import type {\n DictionaryKeys,\n DictionaryRegistryContent,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { useContext, useMemo } from 'preact/hooks';\nimport { getIntlayer } from '../getIntlayer';\nimport type { DeepTransformContent } from '../plugins';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * Preact hook that picks one dictionary by its key and returns its content.\n *\n * If the locale is not provided, it will use the locale from the client context.\n *\n * @param key - The unique key of the dictionary to retrieve.\n * @param locale - Optional locale to override the current context locale.\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 *\n * return <div>{content.myField.value}</div>;\n * };\n * ```\n */\nexport const useIntlayer = <T extends DictionaryKeys, L extends LocalesValues>(\n key: T,\n locale?: L\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n\n return useMemo(() => {\n const localeTarget = locale ?? currentLocale;\n\n // @ts-ignore Type instantiation is excessively deep and possibly infinite\n return getIntlayer<T, L>(key, localeTarget as L) as DeepTransformContent<\n DictionaryRegistryContent<T>\n >;\n }, [key, currentLocale, locale]);\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useIntlayer.mjs","names":[],"sources":["../../../src/client/useIntlayer.ts"],"sourcesContent":["import type {\n DictionaryKeys,\n DictionaryRegistryContent,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { useContext, useMemo } from 'preact/hooks';\nimport { getIntlayer } from '../getIntlayer';\nimport type { DeepTransformContent } from '../plugins';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * Preact hook that picks one dictionary by its key and returns its content.\n *\n * If the locale is not provided, it will use the locale from the client context.\n *\n * @param key - The unique key of the dictionary to retrieve.\n * @param locale - Optional locale to override the current context locale.\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 *\n * return <div>{content.myField.value}</div>;\n * };\n * ```\n */\nexport const useIntlayer = <T extends DictionaryKeys, L extends LocalesValues>(\n key: T,\n locale?: L\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n\n return useMemo(() => {\n const localeTarget = locale ?? currentLocale;\n\n // @ts-ignore Type instantiation is excessively deep and possibly infinite\n return getIntlayer<T, L>(key, localeTarget as L) as DeepTransformContent<\n DictionaryRegistryContent<T>\n >;\n }, [key, currentLocale, locale]);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,MAAa,eACX,KACA,WACG;CACH,MAAM,EAAE,QAAQ,kBAAkB,WAAW,sBAAsB;AAEnE,QAAO,cAAc;AAInB,SAAO,YAAkB,KAHJ,UAAU,cAGiB;IAG/C;EAAC;EAAK;EAAe;EAAO,CAAC"}
|
|
@@ -1,2 +1,26 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/client/useLoadDynamic.ts
|
|
2
|
+
const createSuspender = (promise) => {
|
|
3
|
+
let status = "pending";
|
|
4
|
+
let result;
|
|
5
|
+
const suspender = promise.then((r) => {
|
|
6
|
+
status = "success";
|
|
7
|
+
result = r;
|
|
8
|
+
}, (e) => {
|
|
9
|
+
status = "error";
|
|
10
|
+
result = e;
|
|
11
|
+
});
|
|
12
|
+
return { read() {
|
|
13
|
+
if (status === "pending") throw suspender;
|
|
14
|
+
if (status === "error") throw result;
|
|
15
|
+
return result;
|
|
16
|
+
} };
|
|
17
|
+
};
|
|
18
|
+
const cache = /* @__PURE__ */ new Map();
|
|
19
|
+
const useLoadDynamic = (key, promise) => {
|
|
20
|
+
if (!cache.has(key)) cache.set(key, createSuspender(promise));
|
|
21
|
+
return cache.get(key).read();
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
export { useLoadDynamic };
|
|
2
26
|
//# sourceMappingURL=useLoadDynamic.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLoadDynamic.mjs","names":[],"sources":["../../../src/client/useLoadDynamic.ts"],"sourcesContent":["type Status = 'pending' | 'success' | 'error';\n\nconst createSuspender = <T>(promise: Promise<T>) => {\n let status: Status = 'pending';\n let result: T;\n const suspender = promise.then(\n (r) => {\n status = 'success';\n result = r;\n },\n (e) => {\n status = 'error';\n result = e as any;\n }\n );\n\n return {\n read() {\n if (status === 'pending') throw suspender;\n if (status === 'error') throw result;\n return result!;\n },\n };\n};\n\nconst cache = new Map<string, ReturnType<typeof createSuspender>>();\n\nexport const useLoadDynamic = <T>(key: string, promise: Promise<T>): T => {\n if (!cache.has(key)) {\n cache.set(key, createSuspender(promise));\n }\n\n return (cache.get(key)! as ReturnType<typeof createSuspender>).read() as T;\n};\n"],"mappings":"AAEA,MAAM,
|
|
1
|
+
{"version":3,"file":"useLoadDynamic.mjs","names":[],"sources":["../../../src/client/useLoadDynamic.ts"],"sourcesContent":["type Status = 'pending' | 'success' | 'error';\n\nconst createSuspender = <T>(promise: Promise<T>) => {\n let status: Status = 'pending';\n let result: T;\n const suspender = promise.then(\n (r) => {\n status = 'success';\n result = r;\n },\n (e) => {\n status = 'error';\n result = e as any;\n }\n );\n\n return {\n read() {\n if (status === 'pending') throw suspender;\n if (status === 'error') throw result;\n return result!;\n },\n };\n};\n\nconst cache = new Map<string, ReturnType<typeof createSuspender>>();\n\nexport const useLoadDynamic = <T>(key: string, promise: Promise<T>): T => {\n if (!cache.has(key)) {\n cache.set(key, createSuspender(promise));\n }\n\n return (cache.get(key)! as ReturnType<typeof createSuspender>).read() as T;\n};\n"],"mappings":";AAEA,MAAM,mBAAsB,YAAwB;CAClD,IAAI,SAAiB;CACrB,IAAI;CACJ,MAAM,YAAY,QAAQ,MACvB,MAAM;AACL,WAAS;AACT,WAAS;KAEV,MAAM;AACL,WAAS;AACT,WAAS;GAEZ;AAED,QAAO,EACL,OAAO;AACL,MAAI,WAAW,UAAW,OAAM;AAChC,MAAI,WAAW,QAAS,OAAM;AAC9B,SAAO;IAEV;;AAGH,MAAM,wBAAQ,IAAI,KAAiD;AAEnE,MAAa,kBAAqB,KAAa,YAA2B;AACxE,KAAI,CAAC,MAAM,IAAI,IAAI,CACjB,OAAM,IAAI,KAAK,gBAAgB,QAAQ,CAAC;AAG1C,QAAQ,MAAM,IAAI,IAAI,CAAyC,MAAM"}
|
|
@@ -1,2 +1,52 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import { setLocaleInStorage } from "./useLocaleStorage.mjs";
|
|
2
|
+
import { IntlayerClientContext } from "./IntlayerProvider.mjs";
|
|
3
|
+
import configuration from "@intlayer/config/built";
|
|
4
|
+
import { useContext } from "preact/hooks";
|
|
5
|
+
|
|
6
|
+
//#region src/client/useLocale.ts
|
|
7
|
+
/**
|
|
8
|
+
* Preact hook to get the current locale and related locale management functions.
|
|
9
|
+
*
|
|
10
|
+
* @param props - Optional properties for the hook.
|
|
11
|
+
* @returns An object containing the current locale, default locale, available locales, and a function to update the locale.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```tsx
|
|
15
|
+
* import { useLocale } from 'preact-intlayer';
|
|
16
|
+
*
|
|
17
|
+
* const LocaleSwitcher = () => {
|
|
18
|
+
* const { locale, setLocale, availableLocales } = useLocale();
|
|
19
|
+
*
|
|
20
|
+
* return (
|
|
21
|
+
* <select value={locale} onChange={(e) => setLocale(e.target.value)}>
|
|
22
|
+
* {availableLocales.map((loc) => (
|
|
23
|
+
* <option key={loc} value={loc}>{loc}</option>
|
|
24
|
+
* ))}
|
|
25
|
+
* </select>
|
|
26
|
+
* );
|
|
27
|
+
* };
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
const useLocale = ({ isCookieEnabled, onLocaleChange } = {}) => {
|
|
31
|
+
const { defaultLocale, locales: availableLocales } = configuration?.internationalization ?? {};
|
|
32
|
+
const { locale, setLocale: setLocaleState, isCookieEnabled: isCookieEnabledContext } = useContext(IntlayerClientContext);
|
|
33
|
+
const setLocale = (locale) => {
|
|
34
|
+
if (!availableLocales?.map(String).includes(locale)) {
|
|
35
|
+
console.error(`Locale ${locale} is not available`);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
setLocaleState(locale);
|
|
39
|
+
setLocaleInStorage(locale, isCookieEnabled ?? isCookieEnabledContext ?? true);
|
|
40
|
+
onLocaleChange?.(locale);
|
|
41
|
+
};
|
|
42
|
+
return {
|
|
43
|
+
locale,
|
|
44
|
+
defaultLocale,
|
|
45
|
+
availableLocales,
|
|
46
|
+
setLocale
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
//#endregion
|
|
51
|
+
export { useLocale };
|
|
2
52
|
//# sourceMappingURL=useLocale.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocale.mjs","names":[],"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { useContext } from 'preact/hooks';\nimport { IntlayerClientContext } from './IntlayerProvider';\nimport { setLocaleInStorage } from './useLocaleStorage';\n\ntype useLocaleProps = {\n isCookieEnabled?: boolean;\n onLocaleChange?: (locale: LocalesValues) => void;\n};\n\n/**\n * Preact hook to get the current locale and related locale management functions.\n *\n * @param props - Optional properties for the hook.\n * @returns An object containing the current locale, default locale, available locales, and a function to update the locale.\n *\n * @example\n * ```tsx\n * import { useLocale } from 'preact-intlayer';\n *\n * const LocaleSwitcher = () => {\n * const { locale, setLocale, availableLocales } = useLocale();\n *\n * return (\n * <select value={locale} onChange={(e) => setLocale(e.target.value)}>\n * {availableLocales.map((loc) => (\n * <option key={loc} value={loc}>{loc}</option>\n * ))}\n * </select>\n * );\n * };\n * ```\n */\nexport const useLocale = ({\n isCookieEnabled,\n onLocaleChange,\n}: useLocaleProps = {}) => {\n const { defaultLocale, locales: availableLocales } =\n configuration?.internationalization ?? {};\n\n const {\n locale,\n setLocale: setLocaleState,\n isCookieEnabled: isCookieEnabledContext,\n } = useContext(IntlayerClientContext);\n\n const setLocale = (locale: LocalesValues) => {\n if (!availableLocales?.map(String).includes(locale)) {\n console.error(`Locale ${locale} is not available`);\n return;\n }\n\n setLocaleState(locale);\n\n setLocaleInStorage(\n locale,\n isCookieEnabled ?? isCookieEnabledContext ?? true\n );\n\n onLocaleChange?.(locale);\n };\n\n return {\n locale, // Current locale\n defaultLocale, // Principal locale defined in config\n availableLocales, // List of the available locales defined in config\n setLocale, // Function to set the locale\n };\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useLocale.mjs","names":[],"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { useContext } from 'preact/hooks';\nimport { IntlayerClientContext } from './IntlayerProvider';\nimport { setLocaleInStorage } from './useLocaleStorage';\n\ntype useLocaleProps = {\n isCookieEnabled?: boolean;\n onLocaleChange?: (locale: LocalesValues) => void;\n};\n\n/**\n * Preact hook to get the current locale and related locale management functions.\n *\n * @param props - Optional properties for the hook.\n * @returns An object containing the current locale, default locale, available locales, and a function to update the locale.\n *\n * @example\n * ```tsx\n * import { useLocale } from 'preact-intlayer';\n *\n * const LocaleSwitcher = () => {\n * const { locale, setLocale, availableLocales } = useLocale();\n *\n * return (\n * <select value={locale} onChange={(e) => setLocale(e.target.value)}>\n * {availableLocales.map((loc) => (\n * <option key={loc} value={loc}>{loc}</option>\n * ))}\n * </select>\n * );\n * };\n * ```\n */\nexport const useLocale = ({\n isCookieEnabled,\n onLocaleChange,\n}: useLocaleProps = {}) => {\n const { defaultLocale, locales: availableLocales } =\n configuration?.internationalization ?? {};\n\n const {\n locale,\n setLocale: setLocaleState,\n isCookieEnabled: isCookieEnabledContext,\n } = useContext(IntlayerClientContext);\n\n const setLocale = (locale: LocalesValues) => {\n if (!availableLocales?.map(String).includes(locale)) {\n console.error(`Locale ${locale} is not available`);\n return;\n }\n\n setLocaleState(locale);\n\n setLocaleInStorage(\n locale,\n isCookieEnabled ?? isCookieEnabledContext ?? true\n );\n\n onLocaleChange?.(locale);\n };\n\n return {\n locale, // Current locale\n defaultLocale, // Principal locale defined in config\n availableLocales, // List of the available locales defined in config\n setLocale, // Function to set the locale\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,MAAa,aAAa,EACxB,iBACA,mBACkB,EAAE,KAAK;CACzB,MAAM,EAAE,eAAe,SAAS,qBAC9B,eAAe,wBAAwB,EAAE;CAE3C,MAAM,EACJ,QACA,WAAW,gBACX,iBAAiB,2BACf,WAAW,sBAAsB;CAErC,MAAM,aAAa,WAA0B;AAC3C,MAAI,CAAC,kBAAkB,IAAI,OAAO,CAAC,SAAS,OAAO,EAAE;AACnD,WAAQ,MAAM,UAAU,OAAO,mBAAmB;AAClD;;AAGF,iBAAe,OAAO;AAEtB,qBACE,QACA,mBAAmB,0BAA0B,KAC9C;AAED,mBAAiB,OAAO;;AAG1B,QAAO;EACL;EACA;EACA;EACA;EACD"}
|
|
@@ -1,2 +1,22 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import { IntlayerClientContext } from "./IntlayerProvider.mjs";
|
|
2
|
+
import configuration from "@intlayer/config/built";
|
|
3
|
+
import { useContext } from "preact/hooks";
|
|
4
|
+
|
|
5
|
+
//#region src/client/useLocaleBase.ts
|
|
6
|
+
const { defaultLocale, locales: availableLocales } = configuration.internationalization;
|
|
7
|
+
/**
|
|
8
|
+
* On the client side, hook to get the current locale and all related fields
|
|
9
|
+
*/
|
|
10
|
+
const useLocaleBase = () => {
|
|
11
|
+
const { locale, setLocale } = useContext(IntlayerClientContext);
|
|
12
|
+
return {
|
|
13
|
+
locale,
|
|
14
|
+
defaultLocale,
|
|
15
|
+
availableLocales,
|
|
16
|
+
setLocale
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
//#endregion
|
|
21
|
+
export { useLocaleBase };
|
|
2
22
|
//# sourceMappingURL=useLocaleBase.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocaleBase.mjs","names":[],"sources":["../../../src/client/useLocaleBase.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { useContext } from 'preact/hooks';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\nconst { defaultLocale, locales: availableLocales } =\n configuration.internationalization;\n\n/**\n * On the client side, hook to get the current locale and all related fields\n */\nexport const useLocaleBase = () => {\n const { locale, setLocale } = useContext(IntlayerClientContext);\n\n return {\n locale, // Current locale\n defaultLocale, // Principal locale defined in config\n availableLocales, // List of the available locales defined in config\n setLocale, // Function to set the locale\n };\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useLocaleBase.mjs","names":[],"sources":["../../../src/client/useLocaleBase.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { useContext } from 'preact/hooks';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\nconst { defaultLocale, locales: availableLocales } =\n configuration.internationalization;\n\n/**\n * On the client side, hook to get the current locale and all related fields\n */\nexport const useLocaleBase = () => {\n const { locale, setLocale } = useContext(IntlayerClientContext);\n\n return {\n locale, // Current locale\n defaultLocale, // Principal locale defined in config\n availableLocales, // List of the available locales defined in config\n setLocale, // Function to set the locale\n };\n};\n"],"mappings":";;;;;AAIA,MAAM,EAAE,eAAe,SAAS,qBAC9B,cAAc;;;;AAKhB,MAAa,sBAAsB;CACjC,MAAM,EAAE,QAAQ,cAAc,WAAW,sBAAsB;AAE/D,QAAO;EACL;EACA;EACA;EACA;EACD"}
|
|
@@ -1,2 +1,53 @@
|
|
|
1
|
-
import{useMemo
|
|
1
|
+
import { useMemo } from "preact/hooks";
|
|
2
|
+
import { localeStorageOptions } from "@intlayer/core/localization";
|
|
3
|
+
import { LocaleStorage, getLocaleFromStorage, setLocaleInStorage as setLocaleInStorage$1 } from "@intlayer/core/utils";
|
|
4
|
+
|
|
5
|
+
//#region src/client/useLocaleStorage.ts
|
|
6
|
+
/**
|
|
7
|
+
* Get the locale cookie
|
|
8
|
+
*/
|
|
9
|
+
const localeInStorage = getLocaleFromStorage(localeStorageOptions);
|
|
10
|
+
/**
|
|
11
|
+
* @deprecated Use localeInStorage instead
|
|
12
|
+
*
|
|
13
|
+
* Get the locale cookie
|
|
14
|
+
*/
|
|
15
|
+
const localeCookie = localeInStorage;
|
|
16
|
+
/**
|
|
17
|
+
* Set the locale cookie
|
|
18
|
+
*/
|
|
19
|
+
const setLocaleInStorage = (locale, isCookieEnabled) => setLocaleInStorage$1(locale, {
|
|
20
|
+
...localeStorageOptions,
|
|
21
|
+
isCookieEnabled
|
|
22
|
+
});
|
|
23
|
+
/**
|
|
24
|
+
* @deprecated Use setLocaleInStorage instead
|
|
25
|
+
*
|
|
26
|
+
* Set the locale cookie
|
|
27
|
+
*/
|
|
28
|
+
const setLocaleCookie = setLocaleInStorage;
|
|
29
|
+
/**
|
|
30
|
+
* Hook that provides the locale storage and a function to set it
|
|
31
|
+
*/
|
|
32
|
+
const useLocaleStorage = (isCookieEnabled) => useMemo(() => LocaleStorage({
|
|
33
|
+
...localeStorageOptions,
|
|
34
|
+
isCookieEnabled
|
|
35
|
+
}), [isCookieEnabled]);
|
|
36
|
+
/**
|
|
37
|
+
* @deprecated Use useLocaleStorage instead
|
|
38
|
+
*
|
|
39
|
+
* For GDPR compliance, use useLocaleStorage instead
|
|
40
|
+
*
|
|
41
|
+
* Hook that provides the locale cookie and a function to set it
|
|
42
|
+
*/
|
|
43
|
+
const useLocaleCookie = (isCookieEnabled) => {
|
|
44
|
+
const storage = useLocaleStorage(isCookieEnabled);
|
|
45
|
+
return {
|
|
46
|
+
localeCookie: storage.getLocale(),
|
|
47
|
+
setLocaleCookie: storage.setLocale
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
//#endregion
|
|
52
|
+
export { localeCookie, localeInStorage, setLocaleCookie, setLocaleInStorage, useLocaleCookie, useLocaleStorage };
|
|
2
53
|
//# sourceMappingURL=useLocaleStorage.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocaleStorage.mjs","names":["setLocaleInStorageCore"],"sources":["../../../src/client/useLocaleStorage.ts"],"sourcesContent":["import { localeStorageOptions } from '@intlayer/core/localization';\nimport {\n getLocaleFromStorage,\n LocaleStorage,\n setLocaleInStorage as setLocaleInStorageCore,\n} from '@intlayer/core/utils';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { useMemo } from 'preact/hooks';\n\n/**\n * Get the locale cookie\n */\nexport const localeInStorage = getLocaleFromStorage(localeStorageOptions);\n/**\n * @deprecated Use localeInStorage instead\n *\n * Get the locale cookie\n */\nexport const localeCookie = localeInStorage;\n\n/**\n * Set the locale cookie\n */\nexport const setLocaleInStorage = (\n locale: LocalesValues,\n isCookieEnabled: boolean\n) =>\n setLocaleInStorageCore(locale, {\n ...localeStorageOptions,\n isCookieEnabled,\n });\n\n/**\n * @deprecated Use setLocaleInStorage instead\n *\n * Set the locale cookie\n */\nexport const setLocaleCookie = setLocaleInStorage;\n\n/**\n * Hook that provides the locale storage and a function to set it\n */\nexport const useLocaleStorage = (isCookieEnabled?: boolean) =>\n useMemo(\n () =>\n LocaleStorage({\n ...localeStorageOptions,\n isCookieEnabled,\n }),\n [isCookieEnabled]\n );\n\n/**\n * @deprecated Use useLocaleStorage instead\n *\n * For GDPR compliance, use useLocaleStorage instead\n *\n * Hook that provides the locale cookie and a function to set it\n */\nexport const useLocaleCookie = (isCookieEnabled?: boolean) => {\n const storage = useLocaleStorage(isCookieEnabled);\n return {\n localeCookie: storage.getLocale(),\n setLocaleCookie: storage.setLocale,\n };\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useLocaleStorage.mjs","names":["setLocaleInStorageCore"],"sources":["../../../src/client/useLocaleStorage.ts"],"sourcesContent":["import { localeStorageOptions } from '@intlayer/core/localization';\nimport {\n getLocaleFromStorage,\n LocaleStorage,\n setLocaleInStorage as setLocaleInStorageCore,\n} from '@intlayer/core/utils';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { useMemo } from 'preact/hooks';\n\n/**\n * Get the locale cookie\n */\nexport const localeInStorage = getLocaleFromStorage(localeStorageOptions);\n/**\n * @deprecated Use localeInStorage instead\n *\n * Get the locale cookie\n */\nexport const localeCookie = localeInStorage;\n\n/**\n * Set the locale cookie\n */\nexport const setLocaleInStorage = (\n locale: LocalesValues,\n isCookieEnabled: boolean\n) =>\n setLocaleInStorageCore(locale, {\n ...localeStorageOptions,\n isCookieEnabled,\n });\n\n/**\n * @deprecated Use setLocaleInStorage instead\n *\n * Set the locale cookie\n */\nexport const setLocaleCookie = setLocaleInStorage;\n\n/**\n * Hook that provides the locale storage and a function to set it\n */\nexport const useLocaleStorage = (isCookieEnabled?: boolean) =>\n useMemo(\n () =>\n LocaleStorage({\n ...localeStorageOptions,\n isCookieEnabled,\n }),\n [isCookieEnabled]\n );\n\n/**\n * @deprecated Use useLocaleStorage instead\n *\n * For GDPR compliance, use useLocaleStorage instead\n *\n * Hook that provides the locale cookie and a function to set it\n */\nexport const useLocaleCookie = (isCookieEnabled?: boolean) => {\n const storage = useLocaleStorage(isCookieEnabled);\n return {\n localeCookie: storage.getLocale(),\n setLocaleCookie: storage.setLocale,\n };\n};\n"],"mappings":";;;;;;;;AAYA,MAAa,kBAAkB,qBAAqB,qBAAqB;;;;;;AAMzE,MAAa,eAAe;;;;AAK5B,MAAa,sBACX,QACA,oBAEAA,qBAAuB,QAAQ;CAC7B,GAAG;CACH;CACD,CAAC;;;;;;AAOJ,MAAa,kBAAkB;;;;AAK/B,MAAa,oBAAoB,oBAC/B,cAEI,cAAc;CACZ,GAAG;CACH;CACD,CAAC,EACJ,CAAC,gBAAgB,CAClB;;;;;;;;AASH,MAAa,mBAAmB,oBAA8B;CAC5D,MAAM,UAAU,iBAAiB,gBAAgB;AACjD,QAAO;EACL,cAAc,QAAQ,WAAW;EACjC,iBAAiB,QAAQ;EAC1B"}
|