react-intlayer 8.4.3 → 8.4.5
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 +17 -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 -1
- package/dist/cjs/client/IntlayerProvider.cjs +92 -1
- package/dist/cjs/client/IntlayerProvider.cjs.map +1 -1
- package/dist/cjs/client/format/index.cjs +20 -1
- package/dist/cjs/client/format/useCompact.cjs +29 -1
- package/dist/cjs/client/format/useCompact.cjs.map +1 -1
- package/dist/cjs/client/format/useCurrency.cjs +43 -1
- package/dist/cjs/client/format/useCurrency.cjs.map +1 -1
- package/dist/cjs/client/format/useDate.cjs +45 -1
- package/dist/cjs/client/format/useDate.cjs.map +1 -1
- package/dist/cjs/client/format/useIntl.cjs +45 -1
- package/dist/cjs/client/format/useIntl.cjs.map +1 -1
- package/dist/cjs/client/format/useList.cjs +40 -1
- package/dist/cjs/client/format/useList.cjs.map +1 -1
- package/dist/cjs/client/format/useNumber.cjs +41 -1
- package/dist/cjs/client/format/useNumber.cjs.map +1 -1
- package/dist/cjs/client/format/usePercentage.cjs +37 -1
- package/dist/cjs/client/format/usePercentage.cjs.map +1 -1
- package/dist/cjs/client/format/useRelativeTime.cjs +37 -1
- package/dist/cjs/client/format/useRelativeTime.cjs.map +1 -1
- package/dist/cjs/client/format/useUnit.cjs +36 -1
- package/dist/cjs/client/format/useUnit.cjs.map +1 -1
- package/dist/cjs/client/index.cjs +34 -1
- package/dist/cjs/client/t.cjs +40 -1
- package/dist/cjs/client/t.cjs.map +1 -1
- package/dist/cjs/client/useDictionary.cjs +27 -1
- package/dist/cjs/client/useDictionary.cjs.map +1 -1
- package/dist/cjs/client/useDictionaryAsync.cjs +24 -1
- package/dist/cjs/client/useDictionaryAsync.cjs.map +1 -1
- package/dist/cjs/client/useDictionaryDynamic.cjs +25 -1
- package/dist/cjs/client/useDictionaryDynamic.cjs.map +1 -1
- package/dist/cjs/client/useI18n.cjs +45 -1
- package/dist/cjs/client/useI18n.cjs.map +1 -1
- package/dist/cjs/client/useIntlayer.cjs +42 -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 +60 -1
- package/dist/cjs/client/useLocale.cjs.map +1 -1
- package/dist/cjs/client/useLocaleBase.cjs +26 -1
- package/dist/cjs/client/useLocaleBase.cjs.map +1 -1
- package/dist/cjs/client/useLocaleStorage.cjs +62 -1
- package/dist/cjs/client/useLocaleStorage.cjs.map +1 -1
- package/dist/cjs/client/useRewriteURL.cjs +42 -1
- package/dist/cjs/client/useRewriteURL.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 +18 -1
- package/dist/cjs/editor/ContentSelector.cjs.map +1 -1
- package/dist/cjs/editor/EditorProvider.cjs +11 -1
- package/dist/cjs/editor/EditorProvider.cjs.map +1 -1
- package/dist/cjs/editor/useEditor.cjs +39 -1
- package/dist/cjs/editor/useEditor.cjs.map +1 -1
- 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 +18 -1
- package/dist/cjs/html/HTMLProvider.cjs.map +1 -1
- package/dist/cjs/html/HTMLRenderer.cjs +60 -1
- package/dist/cjs/html/HTMLRenderer.cjs.map +1 -1
- package/dist/cjs/html/HTMLRendererPlugin.cjs +23 -1
- package/dist/cjs/html/HTMLRendererPlugin.cjs.map +1 -1
- package/dist/cjs/html/index.cjs +12 -1
- package/dist/cjs/index.cjs +52 -1
- package/dist/cjs/markdown/MarkdownProvider.cjs +80 -1
- package/dist/cjs/markdown/MarkdownProvider.cjs.map +1 -1
- package/dist/cjs/markdown/MarkdownRenderer.cjs +201 -1
- package/dist/cjs/markdown/MarkdownRenderer.cjs.map +1 -1
- package/dist/cjs/markdown/MarkdownRendererPlugin.cjs +17 -1
- package/dist/cjs/markdown/MarkdownRendererPlugin.cjs.map +1 -1
- package/dist/cjs/markdown/index.cjs +24 -1
- package/dist/cjs/markdown/processor.cjs +66 -1
- package/dist/cjs/markdown/processor.cjs.map +1 -1
- package/dist/cjs/markdown/runtime.cjs +43 -1
- package/dist/cjs/markdown/runtime.cjs.map +1 -1
- package/dist/cjs/plugins.cjs +200 -1
- package/dist/cjs/plugins.cjs.map +1 -1
- package/dist/cjs/reactElement/renderReactElement.cjs +52 -1
- package/dist/cjs/reactElement/renderReactElement.cjs.map +1 -1
- package/dist/cjs/server/IntlayerServerProvider.cjs +34 -1
- package/dist/cjs/server/IntlayerServerProvider.cjs.map +1 -1
- package/dist/cjs/server/format/index.cjs +18 -1
- package/dist/cjs/server/format/useCompact.cjs +27 -1
- package/dist/cjs/server/format/useCompact.cjs.map +1 -1
- package/dist/cjs/server/format/useCurrency.cjs +38 -1
- package/dist/cjs/server/format/useCurrency.cjs.map +1 -1
- package/dist/cjs/server/format/useDate.cjs +43 -1
- package/dist/cjs/server/format/useDate.cjs.map +1 -1
- package/dist/cjs/server/format/useIntl.cjs +44 -1
- package/dist/cjs/server/format/useIntl.cjs.map +1 -1
- package/dist/cjs/server/format/useList.cjs +35 -1
- package/dist/cjs/server/format/useList.cjs.map +1 -1
- package/dist/cjs/server/format/useNumber.cjs +39 -1
- package/dist/cjs/server/format/useNumber.cjs.map +1 -1
- package/dist/cjs/server/format/usePercentage.cjs +35 -1
- package/dist/cjs/server/format/usePercentage.cjs.map +1 -1
- package/dist/cjs/server/format/useRelativeTime.cjs +35 -1
- package/dist/cjs/server/format/useRelativeTime.cjs.map +1 -1
- package/dist/cjs/server/format/useUnit.cjs +34 -1
- package/dist/cjs/server/format/useUnit.cjs.map +1 -1
- package/dist/cjs/server/index.cjs +24 -1
- package/dist/cjs/server/serverContext.cjs +58 -1
- package/dist/cjs/server/serverContext.cjs.map +1 -1
- package/dist/cjs/server/t.cjs +35 -1
- package/dist/cjs/server/t.cjs.map +1 -1
- package/dist/cjs/server/useDictionary.cjs +17 -1
- package/dist/cjs/server/useDictionary.cjs.map +1 -1
- package/dist/cjs/server/useDictionaryAsync.cjs +21 -1
- package/dist/cjs/server/useDictionaryAsync.cjs.map +1 -1
- package/dist/cjs/server/useDictionaryDynamic.cjs +22 -1
- package/dist/cjs/server/useDictionaryDynamic.cjs.map +1 -1
- package/dist/cjs/server/useI18n.cjs +38 -1
- package/dist/cjs/server/useI18n.cjs.map +1 -1
- package/dist/cjs/server/useIntlayer.cjs +17 -1
- package/dist/cjs/server/useIntlayer.cjs.map +1 -1
- package/dist/cjs/server/useLoadDynamic.cjs +14 -1
- package/dist/cjs/server/useLoadDynamic.cjs.map +1 -1
- package/dist/cjs/server/useLocale.cjs +24 -1
- package/dist/cjs/server/useLocale.cjs.map +1 -1
- package/dist/esm/IntlayerNode.mjs +15 -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 +86 -1
- package/dist/esm/client/IntlayerProvider.mjs.map +1 -1
- package/dist/esm/client/format/index.mjs +11 -1
- package/dist/esm/client/format/useCompact.mjs +27 -1
- package/dist/esm/client/format/useCompact.mjs.map +1 -1
- package/dist/esm/client/format/useCurrency.mjs +41 -1
- package/dist/esm/client/format/useCurrency.mjs.map +1 -1
- package/dist/esm/client/format/useDate.mjs +43 -1
- package/dist/esm/client/format/useDate.mjs.map +1 -1
- package/dist/esm/client/format/useIntl.mjs +43 -1
- package/dist/esm/client/format/useIntl.mjs.map +1 -1
- package/dist/esm/client/format/useList.mjs +38 -1
- package/dist/esm/client/format/useList.mjs.map +1 -1
- package/dist/esm/client/format/useNumber.mjs +39 -1
- package/dist/esm/client/format/useNumber.mjs.map +1 -1
- package/dist/esm/client/format/usePercentage.mjs +35 -1
- package/dist/esm/client/format/usePercentage.mjs.map +1 -1
- package/dist/esm/client/format/useRelativeTime.mjs +35 -1
- package/dist/esm/client/format/useRelativeTime.mjs.map +1 -1
- package/dist/esm/client/format/useUnit.mjs +34 -1
- package/dist/esm/client/format/useUnit.mjs.map +1 -1
- package/dist/esm/client/index.mjs +14 -1
- package/dist/esm/client/t.mjs +38 -1
- package/dist/esm/client/t.mjs.map +1 -1
- package/dist/esm/client/useDictionary.mjs +25 -1
- package/dist/esm/client/useDictionary.mjs.map +1 -1
- package/dist/esm/client/useDictionaryAsync.mjs +21 -1
- package/dist/esm/client/useDictionaryAsync.mjs.map +1 -1
- package/dist/esm/client/useDictionaryDynamic.mjs +22 -1
- package/dist/esm/client/useDictionaryDynamic.mjs.map +1 -1
- package/dist/esm/client/useI18n.mjs +43 -1
- package/dist/esm/client/useI18n.mjs.map +1 -1
- package/dist/esm/client/useIntlayer.mjs +40 -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 +57 -1
- package/dist/esm/client/useLocale.mjs.map +1 -1
- package/dist/esm/client/useLocaleBase.mjs +23 -1
- package/dist/esm/client/useLocaleBase.mjs.map +1 -1
- package/dist/esm/client/useLocaleStorage.mjs +55 -1
- package/dist/esm/client/useLocaleStorage.mjs.map +1 -1
- package/dist/esm/client/useRewriteURL.mjs +39 -1
- package/dist/esm/client/useRewriteURL.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 +16 -1
- package/dist/esm/editor/ContentSelector.mjs.map +1 -1
- package/dist/esm/editor/EditorProvider.mjs +10 -1
- package/dist/esm/editor/EditorProvider.mjs.map +1 -1
- package/dist/esm/editor/useEditor.mjs +37 -1
- package/dist/esm/editor/useEditor.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/esm/html/HTMLProvider.mjs +15 -1
- package/dist/esm/html/HTMLProvider.mjs.map +1 -1
- package/dist/esm/html/HTMLRenderer.mjs +55 -1
- package/dist/esm/html/HTMLRenderer.mjs.map +1 -1
- package/dist/esm/html/HTMLRendererPlugin.mjs +21 -1
- package/dist/esm/html/HTMLRendererPlugin.mjs.map +1 -1
- package/dist/esm/html/index.mjs +5 -1
- package/dist/esm/index.mjs +21 -1
- package/dist/esm/markdown/MarkdownProvider.mjs +77 -1
- package/dist/esm/markdown/MarkdownProvider.mjs.map +1 -1
- package/dist/esm/markdown/MarkdownRenderer.mjs +197 -1
- package/dist/esm/markdown/MarkdownRenderer.mjs.map +1 -1
- package/dist/esm/markdown/MarkdownRendererPlugin.mjs +16 -1
- package/dist/esm/markdown/MarkdownRendererPlugin.mjs.map +1 -1
- package/dist/esm/markdown/index.mjs +7 -1
- package/dist/esm/markdown/processor.mjs +58 -1
- package/dist/esm/markdown/processor.mjs.map +1 -1
- package/dist/esm/markdown/runtime.mjs +39 -1
- package/dist/esm/markdown/runtime.mjs.map +1 -1
- package/dist/esm/plugins.mjs +190 -1
- package/dist/esm/plugins.mjs.map +1 -1
- package/dist/esm/reactElement/renderReactElement.mjs +50 -1
- package/dist/esm/reactElement/renderReactElement.mjs.map +1 -1
- package/dist/esm/server/IntlayerServerProvider.mjs +28 -1
- package/dist/esm/server/IntlayerServerProvider.mjs.map +1 -1
- package/dist/esm/server/format/index.mjs +10 -1
- package/dist/esm/server/format/useCompact.mjs +25 -1
- package/dist/esm/server/format/useCompact.mjs.map +1 -1
- package/dist/esm/server/format/useCurrency.mjs +36 -1
- package/dist/esm/server/format/useCurrency.mjs.map +1 -1
- package/dist/esm/server/format/useDate.mjs +41 -1
- package/dist/esm/server/format/useDate.mjs.map +1 -1
- package/dist/esm/server/format/useIntl.mjs +41 -1
- package/dist/esm/server/format/useIntl.mjs.map +1 -1
- package/dist/esm/server/format/useList.mjs +33 -1
- package/dist/esm/server/format/useList.mjs.map +1 -1
- package/dist/esm/server/format/useNumber.mjs +37 -1
- package/dist/esm/server/format/useNumber.mjs.map +1 -1
- package/dist/esm/server/format/usePercentage.mjs +33 -1
- package/dist/esm/server/format/usePercentage.mjs.map +1 -1
- package/dist/esm/server/format/useRelativeTime.mjs +33 -1
- package/dist/esm/server/format/useRelativeTime.mjs.map +1 -1
- package/dist/esm/server/format/useUnit.mjs +32 -1
- package/dist/esm/server/format/useUnit.mjs.map +1 -1
- package/dist/esm/server/index.mjs +12 -1
- package/dist/esm/server/serverContext.mjs +54 -1
- package/dist/esm/server/serverContext.mjs.map +1 -1
- package/dist/esm/server/t.mjs +33 -1
- package/dist/esm/server/t.mjs.map +1 -1
- package/dist/esm/server/useDictionary.mjs +16 -1
- package/dist/esm/server/useDictionary.mjs.map +1 -1
- package/dist/esm/server/useDictionaryAsync.mjs +18 -1
- package/dist/esm/server/useDictionaryAsync.mjs.map +1 -1
- package/dist/esm/server/useDictionaryDynamic.mjs +19 -1
- package/dist/esm/server/useDictionaryDynamic.mjs.map +1 -1
- package/dist/esm/server/useI18n.mjs +37 -1
- package/dist/esm/server/useI18n.mjs.map +1 -1
- package/dist/esm/server/useIntlayer.mjs +16 -1
- package/dist/esm/server/useIntlayer.mjs.map +1 -1
- package/dist/esm/server/useLoadDynamic.mjs +11 -1
- package/dist/esm/server/useLoadDynamic.mjs.map +1 -1
- package/dist/esm/server/useLocale.mjs +21 -1
- package/dist/esm/server/useLocale.mjs.map +1 -1
- package/dist/types/html/HTMLRenderer.d.ts +1 -1
- package/dist/types/plugins.d.ts +4 -3
- package/dist/types/plugins.d.ts.map +1 -1
- package/package.json +9 -9
|
@@ -1,2 +1,42 @@
|
|
|
1
|
-
import{getServerContext
|
|
1
|
+
import { getServerContext } from "../serverContext.mjs";
|
|
2
|
+
import { IntlayerServerContext } from "../IntlayerServerProvider.mjs";
|
|
3
|
+
import { date } from "@intlayer/core/formatters";
|
|
4
|
+
|
|
5
|
+
//#region src/server/format/useDate.ts
|
|
6
|
+
/**
|
|
7
|
+
* React client hook that provides a localized date/time formatter
|
|
8
|
+
* bound to the current application locale.
|
|
9
|
+
*
|
|
10
|
+
* @returns {(date: Date | string | number, options?: DateProps) => string}
|
|
11
|
+
* A function to format dates or timestamps into localized date/time strings.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```tsx
|
|
15
|
+
* const formatDate = useDate();
|
|
16
|
+
*
|
|
17
|
+
* formatDate(new Date("2025-01-01"));
|
|
18
|
+
* // "Jan 1, 2025"
|
|
19
|
+
*
|
|
20
|
+
* formatDate("2025-01-01T15:30:00Z", {
|
|
21
|
+
* dateStyle: "full",
|
|
22
|
+
* timeStyle: "short",
|
|
23
|
+
* });
|
|
24
|
+
* // "Wednesday, January 1, 2025 at 3:30 PM"
|
|
25
|
+
*
|
|
26
|
+
* formatDate(1735689600000, { locale: "fr-FR", dateStyle: "long" });
|
|
27
|
+
* // "1 janvier 2025"
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* @see createDate
|
|
31
|
+
*/
|
|
32
|
+
const useDate = () => {
|
|
33
|
+
const locale = getServerContext(IntlayerServerContext);
|
|
34
|
+
return (...args) => date(args[0], {
|
|
35
|
+
...args[1],
|
|
36
|
+
locale: args[1]?.locale ?? locale
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
//#endregion
|
|
41
|
+
export { useDate };
|
|
2
42
|
//# sourceMappingURL=useDate.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDate.mjs","names":[],"sources":["../../../../src/server/format/useDate.ts"],"sourcesContent":["import { date } from '@intlayer/core/formatters';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { IntlayerServerContext } from '../IntlayerServerProvider';\nimport { getServerContext } from '../serverContext';\n\n/**\n * React client hook that provides a localized date/time formatter\n * bound to the current application locale.\n *\n * @returns {(date: Date | string | number, options?: DateProps) => string}\n * A function to format dates or timestamps into localized date/time strings.\n *\n * @example\n * ```tsx\n * const formatDate = useDate();\n *\n * formatDate(new Date(\"2025-01-01\"));\n * // \"Jan 1, 2025\"\n *\n * formatDate(\"2025-01-01T15:30:00Z\", {\n * dateStyle: \"full\",\n * timeStyle: \"short\",\n * });\n * // \"Wednesday, January 1, 2025 at 3:30 PM\"\n *\n * formatDate(1735689600000, { locale: \"fr-FR\", dateStyle: \"long\" });\n * // \"1 janvier 2025\"\n * ```\n *\n * @see createDate\n */\nexport const useDate = () => {\n const locale = getServerContext<LocalesValues>(IntlayerServerContext);\n\n return (...args: Parameters<typeof date>) =>\n date(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n });\n};\n"],"mappings":"+
|
|
1
|
+
{"version":3,"file":"useDate.mjs","names":[],"sources":["../../../../src/server/format/useDate.ts"],"sourcesContent":["import { date } from '@intlayer/core/formatters';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { IntlayerServerContext } from '../IntlayerServerProvider';\nimport { getServerContext } from '../serverContext';\n\n/**\n * React client hook that provides a localized date/time formatter\n * bound to the current application locale.\n *\n * @returns {(date: Date | string | number, options?: DateProps) => string}\n * A function to format dates or timestamps into localized date/time strings.\n *\n * @example\n * ```tsx\n * const formatDate = useDate();\n *\n * formatDate(new Date(\"2025-01-01\"));\n * // \"Jan 1, 2025\"\n *\n * formatDate(\"2025-01-01T15:30:00Z\", {\n * dateStyle: \"full\",\n * timeStyle: \"short\",\n * });\n * // \"Wednesday, January 1, 2025 at 3:30 PM\"\n *\n * formatDate(1735689600000, { locale: \"fr-FR\", dateStyle: \"long\" });\n * // \"1 janvier 2025\"\n * ```\n *\n * @see createDate\n */\nexport const useDate = () => {\n const locale = getServerContext<LocalesValues>(IntlayerServerContext);\n\n return (...args: Parameters<typeof date>) =>\n date(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n });\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,MAAa,gBAAgB;CAC3B,MAAM,SAAS,iBAAgC,sBAAsB;AAErE,SAAQ,GAAG,SACT,KAAK,KAAK,IAAI;EACZ,GAAG,KAAK;EACR,QAAQ,KAAK,IAAI,UAAU;EAC5B,CAAC"}
|
|
@@ -1,2 +1,42 @@
|
|
|
1
|
-
import{getServerContext
|
|
1
|
+
import { getServerContext } from "../serverContext.mjs";
|
|
2
|
+
import { IntlayerServerContext } from "../IntlayerServerProvider.mjs";
|
|
3
|
+
import configuration from "@intlayer/config/built";
|
|
4
|
+
import { bindIntl } from "@intlayer/core/formatters";
|
|
5
|
+
|
|
6
|
+
//#region src/server/format/useIntl.ts
|
|
7
|
+
/**
|
|
8
|
+
* React client hook that provides a locale-bound `Intl` object.
|
|
9
|
+
*
|
|
10
|
+
* It acts exactly like the native `Intl` object, but acts as a proxy to:
|
|
11
|
+
* 1. Inject the current locale automatically if none is provided.
|
|
12
|
+
* 2. Use the performance-optimized `CachedIntl` under the hood.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```tsx
|
|
16
|
+
* const intl = useIntl(); // uses context locale
|
|
17
|
+
*
|
|
18
|
+
* // Standard API, but no need to pass 'en-US' as the first argument
|
|
19
|
+
* const formatted = new intl.NumberFormat({
|
|
20
|
+
* style: 'currency',
|
|
21
|
+
* currency: 'USD'
|
|
22
|
+
* }).format(123.45);
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```tsx
|
|
27
|
+
* const intl = useIntl();
|
|
28
|
+
*
|
|
29
|
+
* // You can still override the locale if needed
|
|
30
|
+
* const date = new intl.DateTimeFormat({ locale: 'fr-FR' }).format(new Date());
|
|
31
|
+
* // or
|
|
32
|
+
* const date2 = new intl.DateTimeFormat('fr-FR').format(new Date());
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
const useIntl = (locale) => {
|
|
36
|
+
const currentLocale = getServerContext(IntlayerServerContext);
|
|
37
|
+
return bindIntl(locale ?? currentLocale ?? configuration?.internationalization?.defaultLocale);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
//#endregion
|
|
41
|
+
export { useIntl };
|
|
2
42
|
//# sourceMappingURL=useIntl.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIntl.mjs","names":[],"sources":["../../../../src/server/format/useIntl.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { bindIntl, type WrappedIntl } from '@intlayer/core/formatters';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { IntlayerServerContext } from '../IntlayerServerProvider';\nimport { getServerContext } from '../serverContext';\n\n/**\n * React client hook that provides a locale-bound `Intl` object.\n *\n * It acts exactly like the native `Intl` object, but acts as a proxy to:\n * 1. Inject the current locale automatically if none is provided.\n * 2. Use the performance-optimized `CachedIntl` under the hood.\n *\n * @example\n * ```tsx\n * const intl = useIntl(); // uses context locale\n *\n * // Standard API, but no need to pass 'en-US' as the first argument\n * const formatted = new intl.NumberFormat({\n * style: 'currency',\n * currency: 'USD'\n * }).format(123.45);\n * ```\n *\n * @example\n * ```tsx\n * const intl = useIntl();\n *\n * // You can still override the locale if needed\n * const date = new intl.DateTimeFormat({ locale: 'fr-FR' }).format(new Date());\n * // or\n * const date2 = new intl.DateTimeFormat('fr-FR').format(new Date());\n * ```\n */\nexport const useIntl = (locale?: LocalesValues): WrappedIntl => {\n const currentLocale = getServerContext<LocalesValues>(IntlayerServerContext);\n\n return bindIntl(\n locale ??\n currentLocale ??\n configuration?.internationalization?.defaultLocale\n );\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useIntl.mjs","names":[],"sources":["../../../../src/server/format/useIntl.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { bindIntl, type WrappedIntl } from '@intlayer/core/formatters';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { IntlayerServerContext } from '../IntlayerServerProvider';\nimport { getServerContext } from '../serverContext';\n\n/**\n * React client hook that provides a locale-bound `Intl` object.\n *\n * It acts exactly like the native `Intl` object, but acts as a proxy to:\n * 1. Inject the current locale automatically if none is provided.\n * 2. Use the performance-optimized `CachedIntl` under the hood.\n *\n * @example\n * ```tsx\n * const intl = useIntl(); // uses context locale\n *\n * // Standard API, but no need to pass 'en-US' as the first argument\n * const formatted = new intl.NumberFormat({\n * style: 'currency',\n * currency: 'USD'\n * }).format(123.45);\n * ```\n *\n * @example\n * ```tsx\n * const intl = useIntl();\n *\n * // You can still override the locale if needed\n * const date = new intl.DateTimeFormat({ locale: 'fr-FR' }).format(new Date());\n * // or\n * const date2 = new intl.DateTimeFormat('fr-FR').format(new Date());\n * ```\n */\nexport const useIntl = (locale?: LocalesValues): WrappedIntl => {\n const currentLocale = getServerContext<LocalesValues>(IntlayerServerContext);\n\n return bindIntl(\n locale ??\n currentLocale ??\n configuration?.internationalization?.defaultLocale\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,MAAa,WAAW,WAAwC;CAC9D,MAAM,gBAAgB,iBAAgC,sBAAsB;AAE5E,QAAO,SACL,UACE,iBACA,eAAe,sBAAsB,cACxC"}
|
|
@@ -1,2 +1,34 @@
|
|
|
1
|
-
import{getServerContext
|
|
1
|
+
import { getServerContext } from "../serverContext.mjs";
|
|
2
|
+
import { IntlayerServerContext } from "../IntlayerServerProvider.mjs";
|
|
3
|
+
import { list } from "@intlayer/core/formatters";
|
|
4
|
+
|
|
5
|
+
//#region src/server/format/useList.ts
|
|
6
|
+
/**
|
|
7
|
+
* React server hook that provides a list formatter
|
|
8
|
+
* bound to the current application locale.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```tsx
|
|
12
|
+
* const formatList = useList();
|
|
13
|
+
*
|
|
14
|
+
* formatList(['apple', 'banana', 'orange']);
|
|
15
|
+
* // "apple, banana, and orange"
|
|
16
|
+
*
|
|
17
|
+
* formatList(['red', 'green', 'blue'], { type: 'disjunction' });
|
|
18
|
+
* // "red, green, or blue"
|
|
19
|
+
*
|
|
20
|
+
* formatList([1, 2, 3], { type: 'unit', locale: 'de-DE' });
|
|
21
|
+
* // "1, 2 und 3"
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
const useList = () => {
|
|
25
|
+
const locale = getServerContext(IntlayerServerContext);
|
|
26
|
+
return (...args) => list(args[0], {
|
|
27
|
+
...args[1],
|
|
28
|
+
locale: args[1]?.locale ?? locale
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
//#endregion
|
|
33
|
+
export { useList };
|
|
2
34
|
//# sourceMappingURL=useList.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useList.mjs","names":[],"sources":["../../../../src/server/format/useList.ts"],"sourcesContent":["import { list } from '@intlayer/core/formatters';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { IntlayerServerContext } from '../IntlayerServerProvider';\nimport { getServerContext } from '../serverContext';\n\n/**\n * React server hook that provides a list formatter\n * bound to the current application locale.\n *\n * @example\n * ```tsx\n * const formatList = useList();\n *\n * formatList(['apple', 'banana', 'orange']);\n * // \"apple, banana, and orange\"\n *\n * formatList(['red', 'green', 'blue'], { type: 'disjunction' });\n * // \"red, green, or blue\"\n *\n * formatList([1, 2, 3], { type: 'unit', locale: 'de-DE' });\n * // \"1, 2 und 3\"\n * ```\n */\nexport const useList = () => {\n const locale = getServerContext<LocalesValues>(IntlayerServerContext);\n\n return (...args: Parameters<typeof list>) =>\n list(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n });\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useList.mjs","names":[],"sources":["../../../../src/server/format/useList.ts"],"sourcesContent":["import { list } from '@intlayer/core/formatters';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { IntlayerServerContext } from '../IntlayerServerProvider';\nimport { getServerContext } from '../serverContext';\n\n/**\n * React server hook that provides a list formatter\n * bound to the current application locale.\n *\n * @example\n * ```tsx\n * const formatList = useList();\n *\n * formatList(['apple', 'banana', 'orange']);\n * // \"apple, banana, and orange\"\n *\n * formatList(['red', 'green', 'blue'], { type: 'disjunction' });\n * // \"red, green, or blue\"\n *\n * formatList([1, 2, 3], { type: 'unit', locale: 'de-DE' });\n * // \"1, 2 und 3\"\n * ```\n */\nexport const useList = () => {\n const locale = getServerContext<LocalesValues>(IntlayerServerContext);\n\n return (...args: Parameters<typeof list>) =>\n list(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n });\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAuBA,MAAa,gBAAgB;CAC3B,MAAM,SAAS,iBAAgC,sBAAsB;AAErE,SAAQ,GAAG,SACT,KAAK,KAAK,IAAI;EACZ,GAAG,KAAK;EACR,QAAQ,KAAK,IAAI,UAAU;EAC5B,CAAC"}
|
|
@@ -1,2 +1,38 @@
|
|
|
1
|
-
import{getServerContext
|
|
1
|
+
import { getServerContext } from "../serverContext.mjs";
|
|
2
|
+
import { IntlayerServerContext } from "../IntlayerServerProvider.mjs";
|
|
3
|
+
import { number } from "@intlayer/core/formatters";
|
|
4
|
+
|
|
5
|
+
//#region src/server/format/useNumber.ts
|
|
6
|
+
/**
|
|
7
|
+
* React client hook that provides a localized number formatter.
|
|
8
|
+
*
|
|
9
|
+
* Uses the current locale from {@link useLocaleBase} and returns
|
|
10
|
+
* a function that can be used to format numbers consistently
|
|
11
|
+
* according to the user's locale.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```tsx
|
|
15
|
+
* const formatNumber = useNumber();
|
|
16
|
+
*
|
|
17
|
+
* formatNumber(12345);
|
|
18
|
+
* // e.g. "12,345" (en-US)
|
|
19
|
+
* // e.g. "12 345" (fr-FR)
|
|
20
|
+
*
|
|
21
|
+
* formatNumber(0.75, { style: "percent" });
|
|
22
|
+
* // e.g. "75%"
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @returns {(value: string | number, options?: import("../createNumber").NumberProps) => string}
|
|
26
|
+
* A number formatting function bound to the active locale.
|
|
27
|
+
*/
|
|
28
|
+
const useNumber = () => {
|
|
29
|
+
const locale = getServerContext(IntlayerServerContext);
|
|
30
|
+
return (...args) => number(args[0], {
|
|
31
|
+
...args[1],
|
|
32
|
+
locale: args[1]?.locale ?? locale
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
//#endregion
|
|
37
|
+
export { useNumber };
|
|
2
38
|
//# sourceMappingURL=useNumber.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useNumber.mjs","names":[],"sources":["../../../../src/server/format/useNumber.ts"],"sourcesContent":["import { number } from '@intlayer/core/formatters';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { IntlayerServerContext } from '../IntlayerServerProvider';\nimport { getServerContext } from '../serverContext';\n\n/**\n * React client hook that provides a localized number formatter.\n *\n * Uses the current locale from {@link useLocaleBase} and returns\n * a function that can be used to format numbers consistently\n * according to the user's locale.\n *\n * @example\n * ```tsx\n * const formatNumber = useNumber();\n *\n * formatNumber(12345);\n * // e.g. \"12,345\" (en-US)\n * // e.g. \"12 345\" (fr-FR)\n *\n * formatNumber(0.75, { style: \"percent\" });\n * // e.g. \"75%\"\n * ```\n *\n * @returns {(value: string | number, options?: import(\"../createNumber\").NumberProps) => string}\n * A number formatting function bound to the active locale.\n */\nexport const useNumber = () => {\n const locale = getServerContext<LocalesValues>(IntlayerServerContext);\n\n return (...args: Parameters<typeof number>) =>\n number(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n });\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useNumber.mjs","names":[],"sources":["../../../../src/server/format/useNumber.ts"],"sourcesContent":["import { number } from '@intlayer/core/formatters';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { IntlayerServerContext } from '../IntlayerServerProvider';\nimport { getServerContext } from '../serverContext';\n\n/**\n * React client hook that provides a localized number formatter.\n *\n * Uses the current locale from {@link useLocaleBase} and returns\n * a function that can be used to format numbers consistently\n * according to the user's locale.\n *\n * @example\n * ```tsx\n * const formatNumber = useNumber();\n *\n * formatNumber(12345);\n * // e.g. \"12,345\" (en-US)\n * // e.g. \"12 345\" (fr-FR)\n *\n * formatNumber(0.75, { style: \"percent\" });\n * // e.g. \"75%\"\n * ```\n *\n * @returns {(value: string | number, options?: import(\"../createNumber\").NumberProps) => string}\n * A number formatting function bound to the active locale.\n */\nexport const useNumber = () => {\n const locale = getServerContext<LocalesValues>(IntlayerServerContext);\n\n return (...args: Parameters<typeof number>) =>\n number(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n });\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,MAAa,kBAAkB;CAC7B,MAAM,SAAS,iBAAgC,sBAAsB;AAErE,SAAQ,GAAG,SACT,OAAO,KAAK,IAAI;EACd,GAAG,KAAK;EACR,QAAQ,KAAK,IAAI,UAAU;EAC5B,CAAC"}
|
|
@@ -1,2 +1,34 @@
|
|
|
1
|
-
import{getServerContext
|
|
1
|
+
import { getServerContext } from "../serverContext.mjs";
|
|
2
|
+
import { IntlayerServerContext } from "../IntlayerServerProvider.mjs";
|
|
3
|
+
import { percentage } from "@intlayer/core/formatters";
|
|
4
|
+
|
|
5
|
+
//#region src/server/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 = getServerContext(IntlayerServerContext);
|
|
26
|
+
return (...args) => percentage(args[0], {
|
|
27
|
+
...args[1],
|
|
28
|
+
locale: args[1]?.locale ?? locale
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
//#endregion
|
|
33
|
+
export { usePercentage };
|
|
2
34
|
//# sourceMappingURL=usePercentage.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePercentage.mjs","names":[],"sources":["../../../../src/server/format/usePercentage.ts"],"sourcesContent":["import { percentage } from '@intlayer/core/formatters';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { IntlayerServerContext } from '../IntlayerServerProvider';\nimport { getServerContext } from '../serverContext';\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 = getServerContext<LocalesValues>(IntlayerServerContext);\n\n return (...args: Parameters<typeof percentage>) =>\n percentage(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n });\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"usePercentage.mjs","names":[],"sources":["../../../../src/server/format/usePercentage.ts"],"sourcesContent":["import { percentage } from '@intlayer/core/formatters';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { IntlayerServerContext } from '../IntlayerServerProvider';\nimport { getServerContext } from '../serverContext';\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 = getServerContext<LocalesValues>(IntlayerServerContext);\n\n return (...args: Parameters<typeof percentage>) =>\n percentage(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n });\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAuBA,MAAa,sBAAsB;CACjC,MAAM,SAAS,iBAAgC,sBAAsB;AAErE,SAAQ,GAAG,SACT,WAAW,KAAK,IAAI;EAClB,GAAG,KAAK;EACR,QAAQ,KAAK,IAAI,UAAU;EAC5B,CAAC"}
|
|
@@ -1,2 +1,34 @@
|
|
|
1
|
-
import{getServerContext
|
|
1
|
+
import { getServerContext } from "../serverContext.mjs";
|
|
2
|
+
import { IntlayerServerContext } from "../IntlayerServerProvider.mjs";
|
|
3
|
+
import { relativeTime } from "@intlayer/core/formatters";
|
|
4
|
+
|
|
5
|
+
//#region src/server/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 = getServerContext(IntlayerServerContext);
|
|
26
|
+
return (...args) => relativeTime(args[0], args[1] ?? /* @__PURE__ */ new Date(), {
|
|
27
|
+
...args[2],
|
|
28
|
+
locale: args[2]?.locale ?? locale
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
//#endregion
|
|
33
|
+
export { useRelativeTime };
|
|
2
34
|
//# sourceMappingURL=useRelativeTime.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRelativeTime.mjs","names":[],"sources":["../../../../src/server/format/useRelativeTime.ts"],"sourcesContent":["import { relativeTime } from '@intlayer/core/formatters';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { IntlayerServerContext } from '../IntlayerServerProvider';\nimport { getServerContext } from '../serverContext';\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 = getServerContext<LocalesValues>(IntlayerServerContext);\n\n return (...args: Parameters<typeof relativeTime>) =>\n relativeTime(args[0], args[1] ?? new Date(), {\n ...args[2],\n locale: args[2]?.locale ?? locale,\n });\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useRelativeTime.mjs","names":[],"sources":["../../../../src/server/format/useRelativeTime.ts"],"sourcesContent":["import { relativeTime } from '@intlayer/core/formatters';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { IntlayerServerContext } from '../IntlayerServerProvider';\nimport { getServerContext } from '../serverContext';\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 = getServerContext<LocalesValues>(IntlayerServerContext);\n\n return (...args: Parameters<typeof relativeTime>) =>\n relativeTime(args[0], args[1] ?? new Date(), {\n ...args[2],\n locale: args[2]?.locale ?? locale,\n });\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAuBA,MAAa,wBAAwB;CACnC,MAAM,SAAS,iBAAgC,sBAAsB;AAErE,SAAQ,GAAG,SACT,aAAa,KAAK,IAAI,KAAK,sBAAM,IAAI,MAAM,EAAE;EAC3C,GAAG,KAAK;EACR,QAAQ,KAAK,IAAI,UAAU;EAC5B,CAAC"}
|
|
@@ -1,2 +1,33 @@
|
|
|
1
|
-
import{getServerContext
|
|
1
|
+
import { getServerContext } from "../serverContext.mjs";
|
|
2
|
+
import { IntlayerServerContext } from "../IntlayerServerProvider.mjs";
|
|
3
|
+
import { units } from "@intlayer/core/formatters";
|
|
4
|
+
|
|
5
|
+
//#region src/server/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 = getServerContext(IntlayerServerContext);
|
|
25
|
+
return (...args) => units(args[0], {
|
|
26
|
+
...args[1],
|
|
27
|
+
locale: args[1]?.locale ?? locale
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
//#endregion
|
|
32
|
+
export { useUnit };
|
|
2
33
|
//# sourceMappingURL=useUnit.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useUnit.mjs","names":[],"sources":["../../../../src/server/format/useUnit.ts"],"sourcesContent":["import { units } from '@intlayer/core/formatters';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { IntlayerServerContext } from '../IntlayerServerProvider';\nimport { getServerContext } from '../serverContext';\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 = getServerContext<LocalesValues>(IntlayerServerContext);\n\n return (...args: Parameters<typeof units>) =>\n units(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n });\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useUnit.mjs","names":[],"sources":["../../../../src/server/format/useUnit.ts"],"sourcesContent":["import { units } from '@intlayer/core/formatters';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { IntlayerServerContext } from '../IntlayerServerProvider';\nimport { getServerContext } from '../serverContext';\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 = getServerContext<LocalesValues>(IntlayerServerContext);\n\n return (...args: Parameters<typeof units>) =>\n units(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n });\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAsBA,MAAa,gBAAgB;CAC3B,MAAM,SAAS,iBAAgC,sBAAsB;AAErE,SAAQ,GAAG,SACT,MAAM,KAAK,IAAI;EACb,GAAG,KAAK;EACR,QAAQ,KAAK,IAAI,UAAU;EAC5B,CAAC"}
|
|
@@ -1 +1,12 @@
|
|
|
1
|
-
import{IntlayerServerContext
|
|
1
|
+
import { IntlayerServerContext, IntlayerServerProvider, locale } from "./IntlayerServerProvider.mjs";
|
|
2
|
+
import { t } from "./t.mjs";
|
|
3
|
+
import { useI18n } from "./useI18n.mjs";
|
|
4
|
+
import { useIntlayer } from "./useIntlayer.mjs";
|
|
5
|
+
import { useDictionary } from "./useDictionary.mjs";
|
|
6
|
+
import { useDictionaryAsync } from "./useDictionaryAsync.mjs";
|
|
7
|
+
import { useLocale } from "./useLocale.mjs";
|
|
8
|
+
import { useLoadDynamic } from "./useLoadDynamic.mjs";
|
|
9
|
+
import { useDictionaryDynamic } from "./useDictionaryDynamic.mjs";
|
|
10
|
+
import { useIntl } from "./format/useIntl.mjs";
|
|
11
|
+
|
|
12
|
+
export { IntlayerServerContext as IntlayerServer, IntlayerServerProvider, locale, t, useDictionary, useDictionaryAsync, useDictionaryDynamic, useI18n, useIntl, useIntlayer, useLoadDynamic, useLocale };
|
|
@@ -1,2 +1,55 @@
|
|
|
1
|
-
import
|
|
1
|
+
import react from "react";
|
|
2
|
+
|
|
3
|
+
//#region src/server/serverContext.tsx
|
|
4
|
+
/**
|
|
5
|
+
* Creates a new datastore for a given server context.
|
|
6
|
+
* Attempts to closely mimic the `createContext` API.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* const IntlayerServer = createServerContext<string | null>(null);
|
|
10
|
+
*
|
|
11
|
+
* <IntlayerServer value={locale}>
|
|
12
|
+
* {children}
|
|
13
|
+
* </IntlayerServer>
|
|
14
|
+
*/
|
|
15
|
+
const cacheFallback = () => () => ({ value: void 0 });
|
|
16
|
+
const createServerContext = (defaultValue) => {
|
|
17
|
+
throwInClient();
|
|
18
|
+
const getCache = (react.cache ?? cacheFallback)(() => ({ value: void 0 }));
|
|
19
|
+
const Provider = ({ children, value }) => {
|
|
20
|
+
getCache().value = value;
|
|
21
|
+
return children;
|
|
22
|
+
};
|
|
23
|
+
const ServerContext = Provider;
|
|
24
|
+
ServerContext.Provider = Provider;
|
|
25
|
+
ServerContext.Consumer = (props) => {
|
|
26
|
+
const store = getCache();
|
|
27
|
+
return props.children(store ? store.value : defaultValue);
|
|
28
|
+
};
|
|
29
|
+
ServerContext._storage = getCache;
|
|
30
|
+
ServerContext._defaultValue = defaultValue;
|
|
31
|
+
return ServerContext;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Fetches a value present in a given server context.
|
|
35
|
+
* Attempts to closely mimic the `useContext` API.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* getServerContext(IntlayerServer);
|
|
39
|
+
*/
|
|
40
|
+
const getServerContext = ({ _storage, _defaultValue }) => {
|
|
41
|
+
const store = _storage();
|
|
42
|
+
if (!store) return _defaultValue;
|
|
43
|
+
return store.value;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Throws if called within a client component environment.
|
|
47
|
+
* Useful to help prevent mistakes.
|
|
48
|
+
*/
|
|
49
|
+
const throwInClient = () => {
|
|
50
|
+
if (typeof window !== "undefined") throw new Error(`createServerContext only works in Server Components`);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
//#endregion
|
|
54
|
+
export { createServerContext, getServerContext };
|
|
2
55
|
//# sourceMappingURL=serverContext.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serverContext.mjs","names":[],"sources":["../../../src/server/serverContext.tsx"],"sourcesContent":["/**\n * Creates a new datastore for a given server context.\n * Attempts to closely mimic the `createContext` API.\n *\n * @example\n * const IntlayerServer = createServerContext<string | null>(null);\n *\n * <IntlayerServer value={locale}>\n * {children}\n * </IntlayerServer>\n */\nimport react, { type FC, type PropsWithChildren, type ReactNode } from 'react';\n\ntype CacheType<T> = () => { value: T | undefined };\n\nconst cacheFallback = () => () => ({ value: undefined });\n\nexport const createServerContext = <T,>(defaultValue?: T): ServerContext<T> => {\n throwInClient();\n\n /** @ts-ignore remove error Property 'cache' does not exist on type 'typeof React'. */\n const cache = react.cache<CacheType<T>> ?? cacheFallback;\n\n const getCache = cache(() => ({\n value: undefined,\n }));\n\n const Provider: FC<PropsWithChildren<{ value?: T }>> = ({\n children,\n value,\n }) => {\n getCache().value = value;\n return children;\n };\n\n const ServerContext = Provider as ServerContext<T>;\n ServerContext.Provider = Provider;\n ServerContext.Consumer = (props) => {\n const store = getCache();\n return props.children(store ? store.value : defaultValue);\n };\n ServerContext._storage = getCache;\n ServerContext._defaultValue = defaultValue;\n\n return ServerContext;\n};\n\n/**\n * Fetches a value present in a given server context.\n * Attempts to closely mimic the `useContext` API.\n *\n * @example\n * getServerContext(IntlayerServer);\n */\nexport const getServerContext = <T,>({\n _storage,\n _defaultValue,\n}: ServerContext<T>) => {\n // throwInClient();\n const store = _storage();\n if (!store) return _defaultValue;\n return store.value;\n};\n\ntype ServerContext<T> = FC<PropsWithChildren<{ value?: T }>> & {\n Provider: FC<PropsWithChildren<{ value?: T }>>;\n Consumer: FC<\n PropsWithChildren<{ children: (context: T | undefined) => ReactNode }>\n >;\n _storage: () => { value: T | undefined };\n _defaultValue: T | undefined;\n};\n\n/**\n * Throws if called within a client component environment.\n * Useful to help prevent mistakes.\n */\nconst throwInClient = (): undefined | never => {\n // If window.document is defined we're in a client component\n if (typeof window !== 'undefined') {\n throw new Error(`createServerContext only works in Server Components`);\n }\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"serverContext.mjs","names":[],"sources":["../../../src/server/serverContext.tsx"],"sourcesContent":["/**\n * Creates a new datastore for a given server context.\n * Attempts to closely mimic the `createContext` API.\n *\n * @example\n * const IntlayerServer = createServerContext<string | null>(null);\n *\n * <IntlayerServer value={locale}>\n * {children}\n * </IntlayerServer>\n */\nimport react, { type FC, type PropsWithChildren, type ReactNode } from 'react';\n\ntype CacheType<T> = () => { value: T | undefined };\n\nconst cacheFallback = () => () => ({ value: undefined });\n\nexport const createServerContext = <T,>(defaultValue?: T): ServerContext<T> => {\n throwInClient();\n\n /** @ts-ignore remove error Property 'cache' does not exist on type 'typeof React'. */\n const cache = react.cache<CacheType<T>> ?? cacheFallback;\n\n const getCache = cache(() => ({\n value: undefined,\n }));\n\n const Provider: FC<PropsWithChildren<{ value?: T }>> = ({\n children,\n value,\n }) => {\n getCache().value = value;\n return children;\n };\n\n const ServerContext = Provider as ServerContext<T>;\n ServerContext.Provider = Provider;\n ServerContext.Consumer = (props) => {\n const store = getCache();\n return props.children(store ? store.value : defaultValue);\n };\n ServerContext._storage = getCache;\n ServerContext._defaultValue = defaultValue;\n\n return ServerContext;\n};\n\n/**\n * Fetches a value present in a given server context.\n * Attempts to closely mimic the `useContext` API.\n *\n * @example\n * getServerContext(IntlayerServer);\n */\nexport const getServerContext = <T,>({\n _storage,\n _defaultValue,\n}: ServerContext<T>) => {\n // throwInClient();\n const store = _storage();\n if (!store) return _defaultValue;\n return store.value;\n};\n\ntype ServerContext<T> = FC<PropsWithChildren<{ value?: T }>> & {\n Provider: FC<PropsWithChildren<{ value?: T }>>;\n Consumer: FC<\n PropsWithChildren<{ children: (context: T | undefined) => ReactNode }>\n >;\n _storage: () => { value: T | undefined };\n _defaultValue: T | undefined;\n};\n\n/**\n * Throws if called within a client component environment.\n * Useful to help prevent mistakes.\n */\nconst throwInClient = (): undefined | never => {\n // If window.document is defined we're in a client component\n if (typeof window !== 'undefined') {\n throw new Error(`createServerContext only works in Server Components`);\n }\n};\n"],"mappings":";;;;;;;;;;;;;;AAeA,MAAM,6BAA6B,EAAE,OAAO,QAAW;AAEvD,MAAa,uBAA2B,iBAAuC;AAC7E,gBAAe;CAKf,MAAM,YAFQ,MAAM,SAAuB,sBAEb,EAC5B,OAAO,QACR,EAAE;CAEH,MAAM,YAAkD,EACtD,UACA,YACI;AACJ,YAAU,CAAC,QAAQ;AACnB,SAAO;;CAGT,MAAM,gBAAgB;AACtB,eAAc,WAAW;AACzB,eAAc,YAAY,UAAU;EAClC,MAAM,QAAQ,UAAU;AACxB,SAAO,MAAM,SAAS,QAAQ,MAAM,QAAQ,aAAa;;AAE3D,eAAc,WAAW;AACzB,eAAc,gBAAgB;AAE9B,QAAO;;;;;;;;;AAUT,MAAa,oBAAwB,EACnC,UACA,oBACsB;CAEtB,MAAM,QAAQ,UAAU;AACxB,KAAI,CAAC,MAAO,QAAO;AACnB,QAAO,MAAM;;;;;;AAgBf,MAAM,sBAAyC;AAE7C,KAAI,OAAO,WAAW,YACpB,OAAM,IAAI,MAAM,sDAAsD"}
|
package/dist/esm/server/t.mjs
CHANGED
|
@@ -1,2 +1,34 @@
|
|
|
1
|
-
import{getServerContext
|
|
1
|
+
import { getServerContext } from "./serverContext.mjs";
|
|
2
|
+
import { IntlayerServerContext } from "./IntlayerServerProvider.mjs";
|
|
3
|
+
import { getTranslation } from "@intlayer/core/interpreter";
|
|
4
|
+
|
|
5
|
+
//#region src/server/t.ts
|
|
6
|
+
/**
|
|
7
|
+
* On the server side, hook to get the translation content based on the locale
|
|
8
|
+
*
|
|
9
|
+
* If not locale found, it will return the content related to the default locale.
|
|
10
|
+
*
|
|
11
|
+
* Return either the content editor, or the content itself depending on the configuration.
|
|
12
|
+
*
|
|
13
|
+
* Usage:
|
|
14
|
+
*
|
|
15
|
+
* ```ts
|
|
16
|
+
* const content = t<string>({
|
|
17
|
+
* en: 'Hello',
|
|
18
|
+
* fr: 'Bonjour',
|
|
19
|
+
* }, 'fr');
|
|
20
|
+
* // 'Bonjour'
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* Using TypeScript:
|
|
24
|
+
* - this function will require each locale to be defined if defined in the project configuration.
|
|
25
|
+
* - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.
|
|
26
|
+
*/
|
|
27
|
+
const t = (multilangContent, locale) => {
|
|
28
|
+
const currentLocale = getServerContext(IntlayerServerContext);
|
|
29
|
+
return getTranslation(multilangContent, locale ?? currentLocale);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
//#endregion
|
|
33
|
+
export { t };
|
|
2
34
|
//# sourceMappingURL=t.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"t.mjs","names":[],"sources":["../../../src/server/t.ts"],"sourcesContent":["import { getTranslation } from '@intlayer/core/interpreter';\nimport type { DeclaredLocales, LocalesValues, StrictModeLocaleMap } from '@intlayer/types/module_augmentation';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\n\n/**\n * On the server side, hook to get the translation content based on the locale\n *\n * If not locale found, it will return the content related to the default locale.\n *\n * Return either the content editor, or the content itself depending on the configuration.\n *\n * Usage:\n *\n * ```ts\n * const content = t<string>({\n * en: 'Hello',\n * fr: 'Bonjour',\n * }, 'fr');\n * // 'Bonjour'\n * ```\n *\n * Using TypeScript:\n * - this function will require each locale to be defined if defined in the project configuration.\n * - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.\n */\nexport const t = <Content = string, L extends LocalesValues = DeclaredLocales>(\n multilangContent: StrictModeLocaleMap<Content>,\n locale?: L\n) => {\n const currentLocale = getServerContext<LocalesValues>(IntlayerServerContext);\n const localeTarget = locale ?? (currentLocale as LocalesValues);\n\n return getTranslation<Content>(multilangContent, localeTarget);\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"t.mjs","names":[],"sources":["../../../src/server/t.ts"],"sourcesContent":["import { getTranslation } from '@intlayer/core/interpreter';\nimport type { DeclaredLocales, LocalesValues, StrictModeLocaleMap } from '@intlayer/types/module_augmentation';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\n\n/**\n * On the server side, hook to get the translation content based on the locale\n *\n * If not locale found, it will return the content related to the default locale.\n *\n * Return either the content editor, or the content itself depending on the configuration.\n *\n * Usage:\n *\n * ```ts\n * const content = t<string>({\n * en: 'Hello',\n * fr: 'Bonjour',\n * }, 'fr');\n * // 'Bonjour'\n * ```\n *\n * Using TypeScript:\n * - this function will require each locale to be defined if defined in the project configuration.\n * - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.\n */\nexport const t = <Content = string, L extends LocalesValues = DeclaredLocales>(\n multilangContent: StrictModeLocaleMap<Content>,\n locale?: L\n) => {\n const currentLocale = getServerContext<LocalesValues>(IntlayerServerContext);\n const localeTarget = locale ?? (currentLocale as LocalesValues);\n\n return getTranslation<Content>(multilangContent, localeTarget);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,MAAa,KACX,kBACA,WACG;CACH,MAAM,gBAAgB,iBAAgC,sBAAsB;AAG5E,QAAO,eAAwB,kBAFV,UAAW,cAE8B"}
|
|
@@ -1,2 +1,17 @@
|
|
|
1
|
-
import{getDictionary
|
|
1
|
+
import { getDictionary } from "../getDictionary.mjs";
|
|
2
|
+
import { getServerContext } from "./serverContext.mjs";
|
|
3
|
+
import { IntlayerServerContext } from "./IntlayerServerProvider.mjs";
|
|
4
|
+
|
|
5
|
+
//#region src/server/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 server context
|
|
10
|
+
*/
|
|
11
|
+
const useDictionary = (dictionary, locale, fallbackLocale) => {
|
|
12
|
+
return getDictionary(dictionary, locale ?? getServerContext(IntlayerServerContext) ?? fallbackLocale);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
16
|
+
export { useDictionary };
|
|
2
17
|
//# sourceMappingURL=useDictionary.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionary.mjs","names":[],"sources":["../../../src/server/useDictionary.ts"],"sourcesContent":["import type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { getDictionary } from '../getDictionary';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\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 server context\n */\nexport const useDictionary = <\n T extends Dictionary,\n L extends LocalesValues = DeclaredLocales,\n>(\n dictionary: T,\n locale?: L,\n fallbackLocale?: DeclaredLocales\n) => {\n const localeTarget =\n locale ??\n getServerContext<LocalesValues>(IntlayerServerContext) ??\n fallbackLocale;\n\n return getDictionary<T, L>(dictionary, localeTarget as L);\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useDictionary.mjs","names":[],"sources":["../../../src/server/useDictionary.ts"],"sourcesContent":["import type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { getDictionary } from '../getDictionary';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\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 server context\n */\nexport const useDictionary = <\n T extends Dictionary,\n L extends LocalesValues = DeclaredLocales,\n>(\n dictionary: T,\n locale?: L,\n fallbackLocale?: DeclaredLocales\n) => {\n const localeTarget =\n locale ??\n getServerContext<LocalesValues>(IntlayerServerContext) ??\n fallbackLocale;\n\n return getDictionary<T, L>(dictionary, localeTarget as L);\n};\n"],"mappings":";;;;;;;;;;AAcA,MAAa,iBAIX,YACA,QACA,mBACG;AAMH,QAAO,cAAoB,YAJzB,UACA,iBAAgC,sBAAsB,IACtD,eAEuD"}
|
|
@@ -1,2 +1,19 @@
|
|
|
1
|
-
import{getServerContext
|
|
1
|
+
import { getServerContext } from "./serverContext.mjs";
|
|
2
|
+
import { IntlayerServerContext } from "./IntlayerServerProvider.mjs";
|
|
3
|
+
import { useDictionary } from "./useDictionary.mjs";
|
|
4
|
+
import configuration from "@intlayer/config/built";
|
|
5
|
+
|
|
6
|
+
//#region src/server/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 server context
|
|
11
|
+
*/
|
|
12
|
+
const useDictionaryAsync = async (dictionaryPromise, locale, fallbackLocale) => {
|
|
13
|
+
const localeTarget = locale ?? getServerContext(IntlayerServerContext) ?? fallbackLocale ?? configuration?.internationalization.defaultLocale;
|
|
14
|
+
return useDictionary(await dictionaryPromise[localeTarget]?.(), localeTarget);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
export { useDictionaryAsync };
|
|
2
19
|
//# sourceMappingURL=useDictionaryAsync.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionaryAsync.mjs","names":[],"sources":["../../../src/server/useDictionaryAsync.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\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 server context\n */\nexport const useDictionaryAsync = async <\n T extends Dictionary,\n L extends LocalesValues = DeclaredLocales,\n>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n locale?: L,\n fallbackLocale?: DeclaredLocales\n) => {\n const localeTarget =\n locale ??\n getServerContext<LocalesValues>(IntlayerServerContext) ??\n fallbackLocale ??\n configuration?.internationalization.defaultLocale;\n\n const dictionary = await (dictionaryPromise as any)[localeTarget]?.();\n\n return useDictionary<T, L>(dictionary, localeTarget as L);\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useDictionaryAsync.mjs","names":[],"sources":["../../../src/server/useDictionaryAsync.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\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 server context\n */\nexport const useDictionaryAsync = async <\n T extends Dictionary,\n L extends LocalesValues = DeclaredLocales,\n>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n locale?: L,\n fallbackLocale?: DeclaredLocales\n) => {\n const localeTarget =\n locale ??\n getServerContext<LocalesValues>(IntlayerServerContext) ??\n fallbackLocale ??\n configuration?.internationalization.defaultLocale;\n\n const dictionary = await (dictionaryPromise as any)[localeTarget]?.();\n\n return useDictionary<T, L>(dictionary, localeTarget as L);\n};\n"],"mappings":";;;;;;;;;;;AAgBA,MAAa,qBAAqB,OAIhC,mBACA,QACA,mBACG;CACH,MAAM,eACJ,UACA,iBAAgC,sBAAsB,IACtD,kBACA,eAAe,qBAAqB;AAItC,QAAO,cAFY,MAAO,kBAA0B,iBAAiB,EAE9B,aAAkB"}
|
|
@@ -1,2 +1,20 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { getServerContext } from "./serverContext.mjs";
|
|
2
|
+
import { IntlayerServerContext } from "./IntlayerServerProvider.mjs";
|
|
3
|
+
import { useDictionary } from "./useDictionary.mjs";
|
|
4
|
+
import { useLoadDynamic } from "./useLoadDynamic.mjs";
|
|
5
|
+
import configuration from "@intlayer/config/built";
|
|
6
|
+
|
|
7
|
+
//#region src/server/useDictionaryDynamic.ts
|
|
8
|
+
/**
|
|
9
|
+
* On the server side, Hook that transform a dictionary and return the content
|
|
10
|
+
*
|
|
11
|
+
* If the locale is not provided, it will use the locale from the server context
|
|
12
|
+
*/
|
|
13
|
+
const useDictionaryDynamic = (dictionaryPromise, key, locale, fallbackLocale) => {
|
|
14
|
+
const localeTarget = locale ?? getServerContext(IntlayerServerContext) ?? fallbackLocale ?? configuration?.internationalization.defaultLocale;
|
|
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/server/useDictionaryDynamic.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\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 server context\n */\nexport const useDictionaryDynamic = <\n T extends Dictionary,\n L extends LocalesValues = DeclaredLocales,\n>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n key: string,\n locale?: L,\n fallbackLocale?: DeclaredLocales\n) => {\n const localeTarget =\n locale ??\n getServerContext<LocalesValues>(IntlayerServerContext) ??\n fallbackLocale ??\n configuration?.internationalization.defaultLocale;\n\n const dictionary = useLoadDynamic<T>(\n `${String(key)}.${localeTarget}`,\n (dictionaryPromise as any)[localeTarget]?.()\n );\n\n return useDictionary<T, L>(dictionary, localeTarget as L);\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useDictionaryDynamic.mjs","names":[],"sources":["../../../src/server/useDictionaryDynamic.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\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 server context\n */\nexport const useDictionaryDynamic = <\n T extends Dictionary,\n L extends LocalesValues = DeclaredLocales,\n>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n key: string,\n locale?: L,\n fallbackLocale?: DeclaredLocales\n) => {\n const localeTarget =\n locale ??\n getServerContext<LocalesValues>(IntlayerServerContext) ??\n fallbackLocale ??\n configuration?.internationalization.defaultLocale;\n\n const dictionary = useLoadDynamic<T>(\n `${String(key)}.${localeTarget}`,\n (dictionaryPromise as any)[localeTarget]?.()\n );\n\n return useDictionary<T, L>(dictionary, localeTarget as L);\n};\n"],"mappings":";;;;;;;;;;;;AAiBA,MAAa,wBAIX,mBACA,KACA,QACA,mBACG;CACH,MAAM,eACJ,UACA,iBAAgC,sBAAsB,IACtD,kBACA,eAAe,qBAAqB;AAOtC,QAAO,cALY,eACjB,GAAG,OAAO,IAAI,CAAC,GAAG,gBACjB,kBAA0B,iBAAiB,CAC7C,EAEsC,aAAkB"}
|