react-intlayer 8.1.2 → 8.1.3
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 +1 -17
- package/dist/cjs/IntlayerNode.cjs.map +1 -1
- package/dist/cjs/UI/ContentSelector.cjs +1 -96
- package/dist/cjs/UI/ContentSelector.cjs.map +1 -1
- package/dist/cjs/_virtual/_rolldown/runtime.cjs +1 -29
- package/dist/cjs/client/IntlayerProvider.cjs +1 -92
- package/dist/cjs/client/IntlayerProvider.cjs.map +1 -1
- package/dist/cjs/client/format/index.cjs +1 -20
- package/dist/cjs/client/format/useCompact.cjs +1 -29
- package/dist/cjs/client/format/useCompact.cjs.map +1 -1
- package/dist/cjs/client/format/useCurrency.cjs +1 -43
- package/dist/cjs/client/format/useCurrency.cjs.map +1 -1
- package/dist/cjs/client/format/useDate.cjs +1 -45
- package/dist/cjs/client/format/useDate.cjs.map +1 -1
- package/dist/cjs/client/format/useIntl.cjs +1 -45
- package/dist/cjs/client/format/useIntl.cjs.map +1 -1
- package/dist/cjs/client/format/useList.cjs +1 -40
- package/dist/cjs/client/format/useList.cjs.map +1 -1
- package/dist/cjs/client/format/useNumber.cjs +1 -41
- package/dist/cjs/client/format/useNumber.cjs.map +1 -1
- package/dist/cjs/client/format/usePercentage.cjs +1 -37
- package/dist/cjs/client/format/usePercentage.cjs.map +1 -1
- package/dist/cjs/client/format/useRelativeTime.cjs +1 -37
- package/dist/cjs/client/format/useRelativeTime.cjs.map +1 -1
- package/dist/cjs/client/format/useUnit.cjs +1 -36
- package/dist/cjs/client/format/useUnit.cjs.map +1 -1
- package/dist/cjs/client/index.cjs +1 -34
- package/dist/cjs/client/t.cjs +1 -40
- package/dist/cjs/client/t.cjs.map +1 -1
- package/dist/cjs/client/useDictionary.cjs +1 -27
- package/dist/cjs/client/useDictionary.cjs.map +1 -1
- package/dist/cjs/client/useDictionaryAsync.cjs +1 -24
- package/dist/cjs/client/useDictionaryAsync.cjs.map +1 -1
- package/dist/cjs/client/useDictionaryDynamic.cjs +1 -25
- package/dist/cjs/client/useDictionaryDynamic.cjs.map +1 -1
- package/dist/cjs/client/useI18n.cjs +1 -45
- package/dist/cjs/client/useI18n.cjs.map +1 -1
- package/dist/cjs/client/useIntlayer.cjs +1 -42
- package/dist/cjs/client/useIntlayer.cjs.map +1 -1
- package/dist/cjs/client/useLoadDynamic.cjs +1 -27
- package/dist/cjs/client/useLoadDynamic.cjs.map +1 -1
- package/dist/cjs/client/useLocale.cjs +1 -60
- package/dist/cjs/client/useLocale.cjs.map +1 -1
- package/dist/cjs/client/useLocaleBase.cjs +1 -26
- package/dist/cjs/client/useLocaleBase.cjs.map +1 -1
- package/dist/cjs/client/useLocaleStorage.cjs +1 -61
- package/dist/cjs/client/useLocaleStorage.cjs.map +1 -1
- package/dist/cjs/client/useRewriteURL.cjs +1 -42
- package/dist/cjs/client/useRewriteURL.cjs.map +1 -1
- package/dist/cjs/client/useTraduction.cjs +1 -35
- package/dist/cjs/client/useTraduction.cjs.map +1 -1
- package/dist/cjs/editor/ContentSelectorWrapper.cjs +1 -55
- package/dist/cjs/editor/ContentSelectorWrapper.cjs.map +1 -1
- package/dist/cjs/editor/IntlayerEditorProvider.cjs +1 -61
- package/dist/cjs/editor/IntlayerEditorProvider.cjs.map +1 -1
- package/dist/cjs/editor/index.cjs +1 -4
- package/dist/cjs/editor/useEditedContentRenderer.cjs +1 -40
- package/dist/cjs/editor/useEditedContentRenderer.cjs.map +1 -1
- package/dist/cjs/getDictionary.cjs +1 -19
- package/dist/cjs/getDictionary.cjs.map +1 -1
- package/dist/cjs/getIntlayer.cjs +1 -19
- package/dist/cjs/getIntlayer.cjs.map +1 -1
- package/dist/cjs/html/HTMLProvider.cjs +1 -18
- package/dist/cjs/html/HTMLProvider.cjs.map +1 -1
- package/dist/cjs/html/HTMLRenderer.cjs +1 -59
- package/dist/cjs/html/HTMLRenderer.cjs.map +1 -1
- package/dist/cjs/html/HTMLRendererPlugin.cjs +1 -36
- package/dist/cjs/html/HTMLRendererPlugin.cjs.map +1 -1
- package/dist/cjs/html/index.cjs +1 -12
- package/dist/cjs/index.cjs +1 -52
- package/dist/cjs/markdown/MarkdownProvider.cjs +1 -77
- package/dist/cjs/markdown/MarkdownProvider.cjs.map +1 -1
- package/dist/cjs/markdown/MarkdownRenderer.cjs +1 -199
- package/dist/cjs/markdown/MarkdownRenderer.cjs.map +1 -1
- package/dist/cjs/markdown/MarkdownRendererPlugin.cjs +1 -33
- package/dist/cjs/markdown/MarkdownRendererPlugin.cjs.map +1 -1
- package/dist/cjs/markdown/index.cjs +1 -25
- package/dist/cjs/markdown/processor.cjs +1 -66
- package/dist/cjs/markdown/processor.cjs.map +1 -1
- package/dist/cjs/markdown/runtime.cjs +1 -43
- package/dist/cjs/markdown/runtime.cjs.map +1 -1
- package/dist/cjs/plugins.cjs +1 -179
- package/dist/cjs/plugins.cjs.map +1 -1
- package/dist/cjs/reactElement/renderReactElement.cjs +1 -52
- package/dist/cjs/reactElement/renderReactElement.cjs.map +1 -1
- package/dist/cjs/server/IntlayerServerProvider.cjs +1 -34
- package/dist/cjs/server/IntlayerServerProvider.cjs.map +1 -1
- package/dist/cjs/server/format/index.cjs +1 -18
- package/dist/cjs/server/format/useCompact.cjs +1 -27
- package/dist/cjs/server/format/useCompact.cjs.map +1 -1
- package/dist/cjs/server/format/useCurrency.cjs +1 -38
- package/dist/cjs/server/format/useCurrency.cjs.map +1 -1
- package/dist/cjs/server/format/useDate.cjs +1 -43
- package/dist/cjs/server/format/useDate.cjs.map +1 -1
- package/dist/cjs/server/format/useIntl.cjs +1 -44
- package/dist/cjs/server/format/useIntl.cjs.map +1 -1
- package/dist/cjs/server/format/useList.cjs +1 -35
- package/dist/cjs/server/format/useList.cjs.map +1 -1
- package/dist/cjs/server/format/useNumber.cjs +1 -39
- package/dist/cjs/server/format/useNumber.cjs.map +1 -1
- package/dist/cjs/server/format/usePercentage.cjs +1 -35
- package/dist/cjs/server/format/usePercentage.cjs.map +1 -1
- package/dist/cjs/server/format/useRelativeTime.cjs +1 -35
- package/dist/cjs/server/format/useRelativeTime.cjs.map +1 -1
- package/dist/cjs/server/format/useUnit.cjs +1 -34
- package/dist/cjs/server/format/useUnit.cjs.map +1 -1
- package/dist/cjs/server/index.cjs +1 -24
- package/dist/cjs/server/serverContext.cjs +1 -58
- package/dist/cjs/server/serverContext.cjs.map +1 -1
- package/dist/cjs/server/t.cjs +1 -35
- package/dist/cjs/server/t.cjs.map +1 -1
- package/dist/cjs/server/useDictionary.cjs +1 -17
- package/dist/cjs/server/useDictionary.cjs.map +1 -1
- package/dist/cjs/server/useDictionaryAsync.cjs +1 -21
- package/dist/cjs/server/useDictionaryAsync.cjs.map +1 -1
- package/dist/cjs/server/useDictionaryDynamic.cjs +1 -22
- package/dist/cjs/server/useDictionaryDynamic.cjs.map +1 -1
- package/dist/cjs/server/useI18n.cjs +1 -38
- package/dist/cjs/server/useI18n.cjs.map +1 -1
- package/dist/cjs/server/useIntlayer.cjs +1 -17
- package/dist/cjs/server/useIntlayer.cjs.map +1 -1
- package/dist/cjs/server/useLoadDynamic.cjs +1 -14
- package/dist/cjs/server/useLoadDynamic.cjs.map +1 -1
- package/dist/cjs/server/useLocale.cjs +1 -24
- package/dist/cjs/server/useLocale.cjs.map +1 -1
- package/dist/esm/IntlayerNode.mjs +1 -15
- package/dist/esm/IntlayerNode.mjs.map +1 -1
- package/dist/esm/UI/ContentSelector.mjs +1 -94
- package/dist/esm/UI/ContentSelector.mjs.map +1 -1
- package/dist/esm/client/IntlayerProvider.mjs +1 -86
- package/dist/esm/client/IntlayerProvider.mjs.map +1 -1
- package/dist/esm/client/format/index.mjs +1 -11
- package/dist/esm/client/format/useCompact.mjs +1 -27
- package/dist/esm/client/format/useCompact.mjs.map +1 -1
- package/dist/esm/client/format/useCurrency.mjs +1 -41
- package/dist/esm/client/format/useCurrency.mjs.map +1 -1
- package/dist/esm/client/format/useDate.mjs +1 -43
- package/dist/esm/client/format/useDate.mjs.map +1 -1
- package/dist/esm/client/format/useIntl.mjs +1 -43
- package/dist/esm/client/format/useIntl.mjs.map +1 -1
- package/dist/esm/client/format/useList.mjs +1 -38
- package/dist/esm/client/format/useList.mjs.map +1 -1
- package/dist/esm/client/format/useNumber.mjs +1 -39
- package/dist/esm/client/format/useNumber.mjs.map +1 -1
- package/dist/esm/client/format/usePercentage.mjs +1 -35
- package/dist/esm/client/format/usePercentage.mjs.map +1 -1
- package/dist/esm/client/format/useRelativeTime.mjs +1 -35
- package/dist/esm/client/format/useRelativeTime.mjs.map +1 -1
- package/dist/esm/client/format/useUnit.mjs +1 -34
- package/dist/esm/client/format/useUnit.mjs.map +1 -1
- package/dist/esm/client/index.mjs +1 -14
- package/dist/esm/client/t.mjs +1 -38
- package/dist/esm/client/t.mjs.map +1 -1
- package/dist/esm/client/useDictionary.mjs +1 -25
- package/dist/esm/client/useDictionary.mjs.map +1 -1
- package/dist/esm/client/useDictionaryAsync.mjs +1 -21
- package/dist/esm/client/useDictionaryAsync.mjs.map +1 -1
- package/dist/esm/client/useDictionaryDynamic.mjs +1 -22
- package/dist/esm/client/useDictionaryDynamic.mjs.map +1 -1
- package/dist/esm/client/useI18n.mjs +1 -43
- package/dist/esm/client/useI18n.mjs.map +1 -1
- package/dist/esm/client/useIntlayer.mjs +1 -40
- package/dist/esm/client/useIntlayer.mjs.map +1 -1
- package/dist/esm/client/useLoadDynamic.mjs +1 -25
- package/dist/esm/client/useLoadDynamic.mjs.map +1 -1
- package/dist/esm/client/useLocale.mjs +1 -57
- package/dist/esm/client/useLocale.mjs.map +1 -1
- package/dist/esm/client/useLocaleBase.mjs +1 -23
- package/dist/esm/client/useLocaleBase.mjs.map +1 -1
- package/dist/esm/client/useLocaleStorage.mjs +1 -54
- package/dist/esm/client/useLocaleStorage.mjs.map +1 -1
- package/dist/esm/client/useRewriteURL.mjs +1 -39
- package/dist/esm/client/useRewriteURL.mjs.map +1 -1
- package/dist/esm/client/useTraduction.mjs +1 -33
- package/dist/esm/client/useTraduction.mjs.map +1 -1
- package/dist/esm/editor/ContentSelectorWrapper.mjs +1 -53
- package/dist/esm/editor/ContentSelectorWrapper.mjs.map +1 -1
- package/dist/esm/editor/IntlayerEditorProvider.mjs +1 -58
- package/dist/esm/editor/IntlayerEditorProvider.mjs.map +1 -1
- package/dist/esm/editor/index.mjs +1 -3
- package/dist/esm/editor/useEditedContentRenderer.mjs +1 -37
- package/dist/esm/editor/useEditedContentRenderer.mjs.map +1 -1
- package/dist/esm/getDictionary.mjs +1 -17
- package/dist/esm/getDictionary.mjs.map +1 -1
- package/dist/esm/getIntlayer.mjs +1 -17
- package/dist/esm/getIntlayer.mjs.map +1 -1
- package/dist/esm/html/HTMLProvider.mjs +1 -15
- package/dist/esm/html/HTMLProvider.mjs.map +1 -1
- package/dist/esm/html/HTMLRenderer.mjs +1 -54
- package/dist/esm/html/HTMLRenderer.mjs.map +1 -1
- package/dist/esm/html/HTMLRendererPlugin.mjs +1 -34
- package/dist/esm/html/HTMLRendererPlugin.mjs.map +1 -1
- package/dist/esm/html/index.mjs +1 -5
- package/dist/esm/index.mjs +1 -21
- package/dist/esm/markdown/MarkdownProvider.mjs +1 -74
- package/dist/esm/markdown/MarkdownProvider.mjs.map +1 -1
- package/dist/esm/markdown/MarkdownRenderer.mjs +1 -195
- package/dist/esm/markdown/MarkdownRenderer.mjs.map +1 -1
- package/dist/esm/markdown/MarkdownRendererPlugin.mjs +1 -30
- package/dist/esm/markdown/MarkdownRendererPlugin.mjs.map +1 -1
- package/dist/esm/markdown/index.mjs +1 -7
- package/dist/esm/markdown/processor.mjs +1 -58
- package/dist/esm/markdown/processor.mjs.map +1 -1
- package/dist/esm/markdown/runtime.mjs +1 -39
- package/dist/esm/markdown/runtime.mjs.map +1 -1
- package/dist/esm/plugins.mjs +1 -172
- package/dist/esm/plugins.mjs.map +1 -1
- package/dist/esm/reactElement/renderReactElement.mjs +1 -50
- package/dist/esm/reactElement/renderReactElement.mjs.map +1 -1
- package/dist/esm/server/IntlayerServerProvider.mjs +1 -28
- package/dist/esm/server/IntlayerServerProvider.mjs.map +1 -1
- package/dist/esm/server/format/index.mjs +1 -10
- package/dist/esm/server/format/useCompact.mjs +1 -25
- package/dist/esm/server/format/useCompact.mjs.map +1 -1
- package/dist/esm/server/format/useCurrency.mjs +1 -36
- package/dist/esm/server/format/useCurrency.mjs.map +1 -1
- package/dist/esm/server/format/useDate.mjs +1 -41
- package/dist/esm/server/format/useDate.mjs.map +1 -1
- package/dist/esm/server/format/useIntl.mjs +1 -41
- package/dist/esm/server/format/useIntl.mjs.map +1 -1
- package/dist/esm/server/format/useList.mjs +1 -33
- package/dist/esm/server/format/useList.mjs.map +1 -1
- package/dist/esm/server/format/useNumber.mjs +1 -37
- package/dist/esm/server/format/useNumber.mjs.map +1 -1
- package/dist/esm/server/format/usePercentage.mjs +1 -33
- package/dist/esm/server/format/usePercentage.mjs.map +1 -1
- package/dist/esm/server/format/useRelativeTime.mjs +1 -33
- package/dist/esm/server/format/useRelativeTime.mjs.map +1 -1
- package/dist/esm/server/format/useUnit.mjs +1 -32
- package/dist/esm/server/format/useUnit.mjs.map +1 -1
- package/dist/esm/server/index.mjs +1 -12
- package/dist/esm/server/serverContext.mjs +1 -54
- package/dist/esm/server/serverContext.mjs.map +1 -1
- package/dist/esm/server/t.mjs +1 -33
- package/dist/esm/server/t.mjs.map +1 -1
- package/dist/esm/server/useDictionary.mjs +1 -16
- package/dist/esm/server/useDictionary.mjs.map +1 -1
- package/dist/esm/server/useDictionaryAsync.mjs +1 -18
- package/dist/esm/server/useDictionaryAsync.mjs.map +1 -1
- package/dist/esm/server/useDictionaryDynamic.mjs +1 -19
- package/dist/esm/server/useDictionaryDynamic.mjs.map +1 -1
- package/dist/esm/server/useI18n.mjs +1 -37
- package/dist/esm/server/useI18n.mjs.map +1 -1
- package/dist/esm/server/useIntlayer.mjs +1 -16
- package/dist/esm/server/useIntlayer.mjs.map +1 -1
- package/dist/esm/server/useLoadDynamic.mjs +1 -11
- package/dist/esm/server/useLoadDynamic.mjs.map +1 -1
- package/dist/esm/server/useLocale.mjs +1 -21
- package/dist/esm/server/useLocale.mjs.map +1 -1
- package/dist/types/IntlayerNode.d.ts +1 -1
- package/dist/types/client/format/useDate.d.ts +1 -1
- package/dist/types/client/useDictionary.d.ts +2 -2
- package/dist/types/client/useDictionary.d.ts.map +1 -1
- package/dist/types/client/useDictionaryDynamic.d.ts +2 -2
- package/dist/types/client/useDictionaryDynamic.d.ts.map +1 -1
- package/dist/types/client/useI18n.d.ts +3 -3
- package/dist/types/client/useI18n.d.ts.map +1 -1
- package/dist/types/client/useIntlayer.d.ts +2 -2
- package/dist/types/client/useIntlayer.d.ts.map +1 -1
- package/dist/types/editor/ContentSelectorWrapper.d.ts +1 -1
- package/dist/types/editor/ContentSelectorWrapper.d.ts.map +1 -1
- package/dist/types/getDictionary.d.ts +1 -1
- package/dist/types/getIntlayer.d.ts +1 -1
- package/dist/types/getIntlayer.d.ts.map +1 -1
- package/dist/types/html/HTMLComponentTypes.d.ts +1 -1
- package/dist/types/html/HTMLRenderer.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/markdown/MarkdownRendererPlugin.d.ts.map +1 -1
- package/dist/types/markdown/processor.d.ts +1 -1
- package/dist/types/markdown/runtime.d.ts +1 -1
- package/dist/types/plugins.d.ts +1 -1
- package/dist/types/plugins.d.ts.map +1 -1
- package/dist/types/server/format/useCompact.d.ts +1 -1
- package/dist/types/server/format/useCurrency.d.ts +1 -1
- package/dist/types/server/format/useDate.d.ts +1 -1
- package/dist/types/server/format/useList.d.ts +1 -1
- package/dist/types/server/format/useNumber.d.ts +1 -1
- package/dist/types/server/format/usePercentage.d.ts +1 -1
- package/dist/types/server/format/useRelativeTime.d.ts +1 -1
- package/dist/types/server/format/useUnit.d.ts +1 -1
- package/dist/types/server/useDictionary.d.ts +2 -2
- package/dist/types/server/useDictionary.d.ts.map +1 -1
- package/dist/types/server/useDictionaryAsync.d.ts +2 -2
- package/dist/types/server/useDictionaryAsync.d.ts.map +1 -1
- package/dist/types/server/useDictionaryDynamic.d.ts +2 -2
- package/dist/types/server/useDictionaryDynamic.d.ts.map +1 -1
- package/dist/types/server/useI18n.d.ts +3 -3
- package/dist/types/server/useI18n.d.ts.map +1 -1
- package/dist/types/server/useIntlayer.d.ts +2 -2
- package/dist/types/server/useIntlayer.d.ts.map +1 -1
- package/package.json +9 -9
|
@@ -1,22 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { IntlayerClientContext } from "./IntlayerProvider.mjs";
|
|
4
|
-
import { useDictionary } from "./useDictionary.mjs";
|
|
5
|
-
import { useContext, useMemo } from "react";
|
|
6
|
-
import configuration from "@intlayer/config/built";
|
|
7
|
-
|
|
8
|
-
//#region src/client/useDictionaryAsync.ts
|
|
9
|
-
/**
|
|
10
|
-
* On the server side, Hook that transform a dictionary and return the content
|
|
11
|
-
*
|
|
12
|
-
* If the locale is not provided, it will use the locale from the client context
|
|
13
|
-
*/
|
|
14
|
-
const useDictionaryAsync = async (dictionaryPromise, locale) => {
|
|
15
|
-
const { locale: currentLocale } = useContext(IntlayerClientContext);
|
|
16
|
-
const localeTarget = useMemo(() => locale ?? currentLocale ?? configuration?.internationalization.defaultLocale, [currentLocale, locale]);
|
|
17
|
-
return useDictionary(await useMemo(async () => await dictionaryPromise[localeTarget]?.(), [dictionaryPromise, localeTarget]), localeTarget);
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
//#endregion
|
|
21
|
-
export { useDictionaryAsync };
|
|
1
|
+
"use client";import{IntlayerClientContext as e}from"./IntlayerProvider.mjs";import{useDictionary as t}from"./useDictionary.mjs";import{useContext as n,useMemo as r}from"react";import i from"@intlayer/config/built";const a=async(a,o)=>{let{locale:s}=n(e),c=r(()=>o??s??i?.internationalization.defaultLocale,[s,o]);return t(await r(async()=>await a[c]?.(),[a,c]),c)};export{a as useDictionaryAsync};
|
|
22
2
|
//# sourceMappingURL=useDictionaryAsync.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionaryAsync.mjs","names":[],"sources":["../../../src/client/useDictionaryAsync.ts"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\nimport type {\n DeclaredLocales,\n Dictionary,\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types';\nimport { useContext, useMemo } from 'react';\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 <\n T extends Dictionary,\n L extends LocalesValues = DeclaredLocales,\n>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n locale?: L\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<T, L>(dictionary, localeTarget as L) as any;\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useDictionaryAsync.mjs","names":[],"sources":["../../../src/client/useDictionaryAsync.ts"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\nimport type {\n DeclaredLocales,\n Dictionary,\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types';\nimport { useContext, useMemo } from 'react';\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 <\n T extends Dictionary,\n L extends LocalesValues = DeclaredLocales,\n>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n locale?: L\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<T, L>(dictionary, localeTarget as L) as any;\n};\n"],"mappings":"sNAkBA,MAAa,EAAqB,MAIhC,EACA,IACe,CACf,GAAM,CAAE,OAAQ,GAAkB,EAAW,EAAsB,CAE7D,EAAe,MAEjB,GACA,GACA,GAAe,qBAAqB,cACtC,CAAC,EAAe,EAAO,CACxB,CAUD,OAAO,EARY,MAAM,EACvB,SACG,MAAM,EACL,MACG,CACP,CAAC,EAAmB,EAAa,CAClC,CAEsC,EAAkB"}
|
|
@@ -1,23 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { IntlayerClientContext } from "./IntlayerProvider.mjs";
|
|
4
|
-
import { useDictionary } from "./useDictionary.mjs";
|
|
5
|
-
import { useLoadDynamic } from "./useLoadDynamic.mjs";
|
|
6
|
-
import { useContext, useMemo } from "react";
|
|
7
|
-
import configuration from "@intlayer/config/built";
|
|
8
|
-
|
|
9
|
-
//#region src/client/useDictionaryDynamic.ts
|
|
10
|
-
/**
|
|
11
|
-
* On the server side, Hook that transform a dictionary and return the content
|
|
12
|
-
*
|
|
13
|
-
* If the locale is not provided, it will use the locale from the client context
|
|
14
|
-
*/
|
|
15
|
-
const useDictionaryDynamic = (dictionaryPromise, key, locale) => {
|
|
16
|
-
const { locale: currentLocale } = useContext(IntlayerClientContext);
|
|
17
|
-
const localeTarget = useMemo(() => locale ?? currentLocale ?? configuration?.internationalization.defaultLocale, [currentLocale, locale]);
|
|
18
|
-
return useDictionary(useLoadDynamic(`${String(key)}.${localeTarget}`, dictionaryPromise[localeTarget]?.()), localeTarget);
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
//#endregion
|
|
22
|
-
export { useDictionaryDynamic };
|
|
1
|
+
"use client";import{IntlayerClientContext as e}from"./IntlayerProvider.mjs";import{useDictionary as t}from"./useDictionary.mjs";import{useLoadDynamic as n}from"./useLoadDynamic.mjs";import{useContext as r,useMemo as i}from"react";import a from"@intlayer/config/built";const o=(o,s,c)=>{let{locale:l}=r(e),u=i(()=>c??l??a?.internationalization.defaultLocale,[l,c]);return t(n(`${String(s)}.${u}`,o[u]?.()),u)};export{o as useDictionaryDynamic};
|
|
23
2
|
//# sourceMappingURL=useDictionaryDynamic.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionaryDynamic.mjs","names":[],"sources":["../../../src/client/useDictionaryDynamic.ts"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\nimport type {\n Dictionary,\n DictionaryKeys,\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types';\nimport { useContext, useMemo } from 'react';\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 () =>\n locale ??\n currentLocale ??\n configuration?.internationalization.defaultLocale,\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":["'use client';\n\nimport configuration from '@intlayer/config/built';\nimport type {\n Dictionary,\n DictionaryKeys,\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types';\nimport { useContext, useMemo } from 'react';\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 () =>\n locale ??\n currentLocale ??\n configuration?.internationalization.defaultLocale,\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":"4QAmBA,MAAa,GAIX,EACA,EACA,IACG,CACH,GAAM,CAAE,OAAQ,GAAkB,EAAW,EAAsB,CAC7D,EAAe,MAEjB,GACA,GACA,GAAe,qBAAqB,cACtC,CAAC,EAAe,EAAO,CACxB,CAOD,OAAO,EALY,EACjB,GAAG,OAAO,EAAI,CAAC,GAAG,IACjB,EAA0B,MAAiB,CAC7C,CAEgC,EAAa"}
|
|
@@ -1,44 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { IntlayerClientContext } from "./IntlayerProvider.mjs";
|
|
4
|
-
import { useContext, useMemo } from "react";
|
|
5
|
-
import { getIntlayer } from "@intlayer/core";
|
|
6
|
-
|
|
7
|
-
//#region src/client/useI18n.ts
|
|
8
|
-
/**
|
|
9
|
-
* Hook that provides a translation function `t()` for accessing nested content by key.
|
|
10
|
-
* This hook mimics the pattern found in libraries like i18next, next-intl, and vue-i18n.
|
|
11
|
-
*
|
|
12
|
-
* @param namespace - The dictionary key to scope translations to
|
|
13
|
-
* @param locale - Optional locale override. If not provided, uses the current context locale
|
|
14
|
-
* @returns A translation function `t(key)` that returns the translated content for the given key
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```tsx
|
|
18
|
-
* const t = useI18n('IndexPage');
|
|
19
|
-
* const title = t('title'); // Returns translated string for 'IndexPage.title'
|
|
20
|
-
* const nestedContent = t('section.subtitle'); // Returns 'IndexPage.section.subtitle'
|
|
21
|
-
* // For attributes like `aria-label`, use `.value` to get the plain string
|
|
22
|
-
* const ariaLabel = t('button.ariaLabel').value; // 'Close modal'
|
|
23
|
-
* ```
|
|
24
|
-
*/
|
|
25
|
-
const useI18n = (namespace, locale) => {
|
|
26
|
-
const { locale: currentLocale } = useContext(IntlayerClientContext);
|
|
27
|
-
const localeTarget = useMemo(() => locale ?? currentLocale, [currentLocale, locale]);
|
|
28
|
-
const dictionaryContent = useMemo(() => getIntlayer(namespace, localeTarget), [namespace, localeTarget]);
|
|
29
|
-
const t = (path) => {
|
|
30
|
-
if (!path) return dictionaryContent;
|
|
31
|
-
const pathArray = path.split(".");
|
|
32
|
-
let current = dictionaryContent;
|
|
33
|
-
for (const key of pathArray) {
|
|
34
|
-
current = current?.[key];
|
|
35
|
-
if (current === void 0) return dictionaryContent;
|
|
36
|
-
}
|
|
37
|
-
return current;
|
|
38
|
-
};
|
|
39
|
-
return t;
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
//#endregion
|
|
43
|
-
export { useI18n };
|
|
1
|
+
"use client";import{IntlayerClientContext as e}from"./IntlayerProvider.mjs";import{useContext as t,useMemo as n}from"react";import{getIntlayer as r}from"@intlayer/core/interpreter";const i=(i,a)=>{let{locale:o}=t(e),s=n(()=>a??o,[o,a]),c=n(()=>r(i,s),[i,s]);return e=>{if(!e)return c;let t=e.split(`.`),n=c;for(let e of t)if(n=n?.[e],n===void 0)return c;return n}};export{i as useI18n};
|
|
44
2
|
//# sourceMappingURL=useI18n.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useI18n.mjs","names":[],"sources":["../../../src/client/useI18n.ts"],"sourcesContent":["'use client';\n\nimport { getIntlayer
|
|
1
|
+
{"version":3,"file":"useI18n.mjs","names":[],"sources":["../../../src/client/useI18n.ts"],"sourcesContent":["'use client';\n\nimport { getIntlayer } from '@intlayer/core/interpreter';\nimport type { ValidDotPathsFor } from '@intlayer/core/transpiler';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n DictionaryRegistryContent,\n GetSubPath,\n LocalesValues,\n} from '@intlayer/types';\nimport { useContext, useMemo } from 'react';\nimport type { DeepTransformContent } from '../plugins';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * Hook that provides a translation function `t()` for accessing nested content by key.\n * This hook mimics the pattern found in libraries like i18next, next-intl, and vue-i18n.\n *\n * @param namespace - The dictionary key to scope translations to\n * @param locale - Optional locale override. If not provided, uses the current context locale\n * @returns A translation function `t(key)` that returns the translated content for the given key\n *\n * @example\n * ```tsx\n * const t = useI18n('IndexPage');\n * const title = t('title'); // Returns translated string for 'IndexPage.title'\n * const nestedContent = t('section.subtitle'); // Returns 'IndexPage.section.subtitle'\n * // For attributes like `aria-label`, use `.value` to get the plain string\n * const ariaLabel = t('button.ariaLabel').value; // 'Close modal'\n * ```\n */\nexport const useI18n = <\n T extends DictionaryKeys,\n L extends LocalesValues = DeclaredLocales,\n>(\n namespace: T,\n locale?: L\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n const localeTarget = useMemo(\n () => locale ?? currentLocale,\n [currentLocale, locale]\n );\n\n // Get the dictionary content for the namespace\n // @ts-ignore Type instantiation is excessively deep and possibly infinite\n const dictionaryContent: DeepTransformContent<DictionaryRegistryContent<T>> =\n useMemo(\n () => getIntlayer<T, L>(namespace, localeTarget as L),\n [namespace, localeTarget]\n );\n\n // Return the translation function\n // @ts-ignore Type instantiation is excessively deep and possibly infinite\n const t = <P extends ValidDotPathsFor<T>>(\n path: P\n // @ts-ignore Type instantiation is excessively deep and possibly infinite\n ): GetSubPath<DeepTransformContent<DictionaryRegistryContent<T>>, P> => {\n if (!path) {\n // @ts-ignore Type instantiation is excessively deep and possibly infinite\n return dictionaryContent as any;\n }\n\n const pathArray = (path as string).split('.');\n let current: any = dictionaryContent;\n\n for (const key of pathArray) {\n current = current?.[key];\n if (current === undefined) {\n // Return the whole dictionary as fallback if path is not found\n return dictionaryContent as any;\n }\n }\n\n return current;\n };\n\n return t;\n};\n"],"mappings":"qLAgCA,MAAa,GAIX,EACA,IACG,CACH,GAAM,CAAE,OAAQ,GAAkB,EAAW,EAAsB,CAC7D,EAAe,MACb,GAAU,EAChB,CAAC,EAAe,EAAO,CACxB,CAIK,EACJ,MACQ,EAAkB,EAAW,EAAkB,CACrD,CAAC,EAAW,EAAa,CAC1B,CA2BH,MAtBE,IAEsE,CACtE,GAAI,CAAC,EAEH,OAAO,EAGT,IAAM,EAAa,EAAgB,MAAM,IAAI,CACzC,EAAe,EAEnB,IAAK,IAAM,KAAO,EAEhB,GADA,EAAU,IAAU,GAChB,IAAY,IAAA,GAEd,OAAO,EAIX,OAAO"}
|
|
@@ -1,41 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { IntlayerClientContext } from "./IntlayerProvider.mjs";
|
|
4
|
-
import { getIntlayer } from "../getIntlayer.mjs";
|
|
5
|
-
import { useContext, useMemo } from "react";
|
|
6
|
-
|
|
7
|
-
//#region src/client/useIntlayer.ts
|
|
8
|
-
/**
|
|
9
|
-
* Client-side hook that picks one dictionary by its key and returns its content.
|
|
10
|
-
*
|
|
11
|
-
* If the locale is not provided, it will use the locale from the client context.
|
|
12
|
-
*
|
|
13
|
-
* @param key - The unique key of the dictionary to retrieve.
|
|
14
|
-
* @param locale - Optional locale to override the current context locale.
|
|
15
|
-
* @returns The dictionary content for the specified locale.
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```tsx
|
|
19
|
-
* import { useIntlayer } from 'react-intlayer';
|
|
20
|
-
*
|
|
21
|
-
* const MyComponent = () => {
|
|
22
|
-
* const content = useIntlayer('my-dictionary-key');
|
|
23
|
-
*
|
|
24
|
-
* return <div>{content.myField.value}</div>;
|
|
25
|
-
* };
|
|
26
|
-
* ```
|
|
27
|
-
*/
|
|
28
|
-
const useIntlayer = (key, locale) => {
|
|
29
|
-
const { locale: currentLocale } = useContext(IntlayerClientContext);
|
|
30
|
-
return useMemo(() => {
|
|
31
|
-
return getIntlayer(key, locale ?? currentLocale);
|
|
32
|
-
}, [
|
|
33
|
-
key,
|
|
34
|
-
currentLocale,
|
|
35
|
-
locale
|
|
36
|
-
]);
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
//#endregion
|
|
40
|
-
export { useIntlayer };
|
|
1
|
+
"use client";import{IntlayerClientContext as e}from"./IntlayerProvider.mjs";import{getIntlayer as t}from"../getIntlayer.mjs";import{useContext as n,useMemo as r}from"react";const i=(i,a)=>{let{locale:o}=n(e);return r(()=>t(i,a??o),[i,o,a])};export{i as useIntlayer};
|
|
41
2
|
//# sourceMappingURL=useIntlayer.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIntlayer.mjs","names":[],"sources":["../../../src/client/useIntlayer.ts"],"sourcesContent":["'use client';\n\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n LocalesValues,\n} from '@intlayer/types';\nimport { useContext, useMemo } from 'react';\nimport { getIntlayer } from '../getIntlayer';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * Client-side 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 dictionary content for the specified locale.\n *\n * @example\n * ```tsx\n * import { useIntlayer } from 'react-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 = <\n T extends DictionaryKeys,\n L extends LocalesValues = DeclaredLocales,\n>(\n key: T,\n locale?: L\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n\n return useMemo(() => {\n const localeTarget = locale ?? (currentLocale as L);\n\n return getIntlayer<T, L>(key, localeTarget);\n }, [key, currentLocale, locale]);\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useIntlayer.mjs","names":[],"sources":["../../../src/client/useIntlayer.ts"],"sourcesContent":["'use client';\n\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n LocalesValues,\n} from '@intlayer/types';\nimport { useContext, useMemo } from 'react';\nimport { getIntlayer } from '../getIntlayer';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * Client-side 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 dictionary content for the specified locale.\n *\n * @example\n * ```tsx\n * import { useIntlayer } from 'react-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 = <\n T extends DictionaryKeys,\n L extends LocalesValues = DeclaredLocales,\n>(\n key: T,\n locale?: L\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n\n return useMemo(() => {\n const localeTarget = locale ?? (currentLocale as L);\n\n return getIntlayer<T, L>(key, localeTarget);\n }, [key, currentLocale, locale]);\n};\n"],"mappings":"6KA+BA,MAAa,GAIX,EACA,IACG,CACH,GAAM,CAAE,OAAQ,GAAkB,EAAW,EAAsB,CAEnE,OAAO,MAGE,EAAkB,EAFJ,GAAW,EAEW,CAC1C,CAAC,EAAK,EAAe,EAAO,CAAC"}
|
|
@@ -1,26 +1,2 @@
|
|
|
1
|
-
|
|
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 };
|
|
1
|
+
const e=e=>{let t=`pending`,n,r=e.then(e=>{t=`success`,n=e},e=>{t=`error`,n=e});return{read(){if(t===`pending`)throw r;if(t===`error`)throw n;return n}}},t=new Map,n=(n,r)=>(t.has(n)||t.set(n,e(r)),t.get(n).read());export{n as useLoadDynamic};
|
|
26
2
|
//# 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":"
|
|
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,EAAsB,GAAwB,CAClD,IAAI,EAAiB,UACjB,EACE,EAAY,EAAQ,KACvB,GAAM,CACL,EAAS,UACT,EAAS,GAEV,GAAM,CACL,EAAS,QACT,EAAS,GAEZ,CAED,MAAO,CACL,MAAO,CACL,GAAI,IAAW,UAAW,MAAM,EAChC,GAAI,IAAW,QAAS,MAAM,EAC9B,OAAO,GAEV,EAGG,EAAQ,IAAI,IAEL,GAAqB,EAAa,KACxC,EAAM,IAAI,EAAI,EACjB,EAAM,IAAI,EAAK,EAAgB,EAAQ,CAAC,CAGlC,EAAM,IAAI,EAAI,CAAyC,MAAM"}
|
|
@@ -1,58 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { setLocaleInStorage } from "./useLocaleStorage.mjs";
|
|
4
|
-
import { IntlayerClientContext } from "./IntlayerProvider.mjs";
|
|
5
|
-
import { useCallback, useContext } from "react";
|
|
6
|
-
import configuration from "@intlayer/config/built";
|
|
7
|
-
|
|
8
|
-
//#region src/client/useLocale.ts
|
|
9
|
-
/**
|
|
10
|
-
* Client-side hook to get the current locale and related locale management functions.
|
|
11
|
-
*
|
|
12
|
-
* @param props - Optional properties for the hook.
|
|
13
|
-
* @returns An object containing the current locale, default locale, available locales, and a function to update the locale.
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* ```tsx
|
|
17
|
-
* import { useLocale } from 'react-intlayer';
|
|
18
|
-
*
|
|
19
|
-
* const LocaleSwitcher = () => {
|
|
20
|
-
* const { locale, setLocale, availableLocales } = useLocale();
|
|
21
|
-
*
|
|
22
|
-
* return (
|
|
23
|
-
* <select value={locale} onChange={(e) => setLocale(e.target.value)}>
|
|
24
|
-
* {availableLocales.map((loc) => (
|
|
25
|
-
* <option key={loc} value={loc}>{loc}</option>
|
|
26
|
-
* ))}
|
|
27
|
-
* </select>
|
|
28
|
-
* );
|
|
29
|
-
* };
|
|
30
|
-
* ```
|
|
31
|
-
*/
|
|
32
|
-
const useLocale = ({ isCookieEnabled, onLocaleChange } = {}) => {
|
|
33
|
-
const { defaultLocale, locales: availableLocales } = configuration?.internationalization ?? {};
|
|
34
|
-
const { locale, setLocale: setLocaleState, isCookieEnabled: isCookieEnabledContext } = useContext(IntlayerClientContext);
|
|
35
|
-
return {
|
|
36
|
-
locale,
|
|
37
|
-
defaultLocale,
|
|
38
|
-
availableLocales,
|
|
39
|
-
setLocale: useCallback((locale) => {
|
|
40
|
-
if (!availableLocales?.map(String).includes(locale)) {
|
|
41
|
-
console.error(`Locale ${locale} is not available`);
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
setLocaleState(locale);
|
|
45
|
-
setLocaleInStorage(locale, isCookieEnabled ?? isCookieEnabledContext ?? true);
|
|
46
|
-
onLocaleChange?.(locale);
|
|
47
|
-
}, [
|
|
48
|
-
availableLocales,
|
|
49
|
-
onLocaleChange,
|
|
50
|
-
setLocaleState,
|
|
51
|
-
isCookieEnabled
|
|
52
|
-
])
|
|
53
|
-
};
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
//#endregion
|
|
57
|
-
export { useLocale };
|
|
1
|
+
"use client";import{setLocaleInStorage as e}from"./useLocaleStorage.mjs";import{IntlayerClientContext as t}from"./IntlayerProvider.mjs";import{useCallback as n,useContext as r}from"react";import i from"@intlayer/config/built";const a=({isCookieEnabled:a,onLocaleChange:o}={})=>{let{defaultLocale:s,locales:c}=i?.internationalization??{},{locale:l,setLocale:u,isCookieEnabled:d}=r(t);return{locale:l,defaultLocale:s,availableLocales:c,setLocale:n(t=>{if(!c?.map(String).includes(t)){console.error(`Locale ${t} is not available`);return}u(t),e(t,a??d??!0),o?.(t)},[c,o,u,a])}};export{a as useLocale};
|
|
58
2
|
//# sourceMappingURL=useLocale.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocale.mjs","names":[],"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\nimport type { DeclaredLocales, LocalesValues } from '@intlayer/types';\nimport { useCallback, useContext } from 'react';\nimport { IntlayerClientContext } from './IntlayerProvider';\nimport { setLocaleInStorage } from './useLocaleStorage';\n\ntype UseLocaleProps = {\n isCookieEnabled?: boolean;\n onLocaleChange?: (locale: LocalesValues) => void;\n};\n\ntype UseLocaleResult = {\n locale: DeclaredLocales;\n defaultLocale: DeclaredLocales;\n availableLocales: DeclaredLocales[];\n setLocale: (locale: LocalesValues) => void;\n};\n\n/**\n * Client-side 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 'react-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 = {}): UseLocaleResult => {\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 = useCallback(\n (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 setLocaleInStorage(\n locale,\n isCookieEnabled ?? isCookieEnabledContext ?? true\n );\n onLocaleChange?.(locale);\n },\n [availableLocales, onLocaleChange, setLocaleState, isCookieEnabled]\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 } as UseLocaleResult;\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useLocale.mjs","names":[],"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\nimport type { DeclaredLocales, LocalesValues } from '@intlayer/types';\nimport { useCallback, useContext } from 'react';\nimport { IntlayerClientContext } from './IntlayerProvider';\nimport { setLocaleInStorage } from './useLocaleStorage';\n\ntype UseLocaleProps = {\n isCookieEnabled?: boolean;\n onLocaleChange?: (locale: LocalesValues) => void;\n};\n\ntype UseLocaleResult = {\n locale: DeclaredLocales;\n defaultLocale: DeclaredLocales;\n availableLocales: DeclaredLocales[];\n setLocale: (locale: LocalesValues) => void;\n};\n\n/**\n * Client-side 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 'react-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 = {}): UseLocaleResult => {\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 = useCallback(\n (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 setLocaleInStorage(\n locale,\n isCookieEnabled ?? isCookieEnabledContext ?? true\n );\n onLocaleChange?.(locale);\n },\n [availableLocales, onLocaleChange, setLocaleState, isCookieEnabled]\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 } as UseLocaleResult;\n};\n"],"mappings":"kOA2CA,MAAa,GAAa,CACxB,kBACA,kBACkB,EAAE,GAAsB,CAC1C,GAAM,CAAE,gBAAe,QAAS,GAC9B,GAAe,sBAAwB,EAAE,CAErC,CACJ,SACA,UAAW,EACX,gBAAiB,GACf,EAAW,EAAsB,CAmBrC,MAAO,CACL,SACA,gBACA,mBACA,UArBgB,EACf,GAA0B,CACzB,GAAI,CAAC,GAAkB,IAAI,OAAO,CAAC,SAAS,EAAO,CAAE,CACnD,QAAQ,MAAM,UAAU,EAAO,mBAAmB,CAClD,OAGF,EAAe,EAAO,CACtB,EACE,EACA,GAAmB,GAA0B,GAC9C,CACD,IAAiB,EAAO,EAE1B,CAAC,EAAkB,EAAgB,EAAgB,EAAgB,CACpE,CAOA"}
|
|
@@ -1,24 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { IntlayerClientContext } from "./IntlayerProvider.mjs";
|
|
4
|
-
import { useContext } from "react";
|
|
5
|
-
import configuration from "@intlayer/config/built";
|
|
6
|
-
|
|
7
|
-
//#region src/client/useLocaleBase.ts
|
|
8
|
-
const { defaultLocale, locales: availableLocales } = configuration.internationalization;
|
|
9
|
-
/**
|
|
10
|
-
* On the client side, hook to get the current locale and all related fields
|
|
11
|
-
*/
|
|
12
|
-
const useLocaleBase = () => {
|
|
13
|
-
const { locale, setLocale } = useContext(IntlayerClientContext);
|
|
14
|
-
return {
|
|
15
|
-
locale,
|
|
16
|
-
defaultLocale,
|
|
17
|
-
availableLocales,
|
|
18
|
-
setLocale
|
|
19
|
-
};
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
//#endregion
|
|
23
|
-
export { useLocaleBase };
|
|
1
|
+
"use client";import{IntlayerClientContext as e}from"./IntlayerProvider.mjs";import{useContext as t}from"react";import n from"@intlayer/config/built";const{defaultLocale:r,locales:i}=n.internationalization,a=()=>{let{locale:n,setLocale:a}=t(e);return{locale:n,defaultLocale:r,availableLocales:i,setLocale:a}};export{a as useLocaleBase};
|
|
24
2
|
//# sourceMappingURL=useLocaleBase.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocaleBase.mjs","names":[],"sources":["../../../src/client/useLocaleBase.ts"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\nimport { useContext } from 'react';\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":["'use client';\n\nimport configuration from '@intlayer/config/built';\nimport { useContext } from 'react';\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":"qJAMA,KAAM,CAAE,gBAAe,QAAS,GAC9B,EAAc,qBAKH,MAAsB,CACjC,GAAM,CAAE,SAAQ,aAAc,EAAW,EAAsB,CAE/D,MAAO,CACL,SACA,gBACA,mBACA,YACD"}
|
|
@@ -1,55 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { LocaleStorage, getLocaleFromStorage, localeStorageOptions, setLocaleInStorage as setLocaleInStorage$1 } from "@intlayer/core";
|
|
3
|
-
|
|
4
|
-
//#region src/client/useLocaleStorage.ts
|
|
5
|
-
/**
|
|
6
|
-
* Get the locale cookie
|
|
7
|
-
*/
|
|
8
|
-
/**
|
|
9
|
-
* Get the locale cookie
|
|
10
|
-
*/
|
|
11
|
-
const localeInStorage = getLocaleFromStorage(localeStorageOptions);
|
|
12
|
-
/**
|
|
13
|
-
* @deprecated Use localeInStorage instead
|
|
14
|
-
*
|
|
15
|
-
* Get the locale cookie
|
|
16
|
-
*/
|
|
17
|
-
const localeCookie = localeInStorage;
|
|
18
|
-
/**
|
|
19
|
-
* Set the locale cookie
|
|
20
|
-
*/
|
|
21
|
-
const setLocaleInStorage = (locale, isCookieEnabled) => setLocaleInStorage$1(locale, {
|
|
22
|
-
...localeStorageOptions,
|
|
23
|
-
isCookieEnabled
|
|
24
|
-
});
|
|
25
|
-
/**
|
|
26
|
-
* @deprecated Use setLocaleInStorage instead
|
|
27
|
-
*
|
|
28
|
-
* Set the locale cookie
|
|
29
|
-
*/
|
|
30
|
-
const setLocaleCookie = setLocaleInStorage;
|
|
31
|
-
/**
|
|
32
|
-
* Hook that provides the locale cookie and a function to set it
|
|
33
|
-
*/
|
|
34
|
-
const useLocaleStorage = (isCookieEnabled) => useMemo(() => LocaleStorage({
|
|
35
|
-
...localeStorageOptions,
|
|
36
|
-
isCookieEnabled
|
|
37
|
-
}), [isCookieEnabled]);
|
|
38
|
-
/**
|
|
39
|
-
* @deprecated Use useLocaleStorage instead
|
|
40
|
-
*
|
|
41
|
-
* For GDPR compliance, use useLocaleStorage instead
|
|
42
|
-
*
|
|
43
|
-
* Hook that provides the locale cookie and a function to set it
|
|
44
|
-
*/
|
|
45
|
-
const useLocaleCookie = (isCookieEnabled) => {
|
|
46
|
-
const storage = useLocaleStorage(isCookieEnabled);
|
|
47
|
-
return {
|
|
48
|
-
localeCookie: storage.getLocale(),
|
|
49
|
-
setLocaleCookie: storage.setLocale
|
|
50
|
-
};
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
//#endregion
|
|
54
|
-
export { localeCookie, localeInStorage, setLocaleCookie, setLocaleInStorage, useLocaleCookie, useLocaleStorage };
|
|
1
|
+
import{useMemo as e}from"react";import{LocaleStorage as t,getLocaleFromStorage as n,setLocaleInStorage as r}from"@intlayer/core/utils";import{localeStorageOptions as i}from"@intlayer/core/localization";const a=n(i),o=a,s=(e,t)=>r(e,{...i,isCookieEnabled:t}),c=s,l=n=>e(()=>t({...i,isCookieEnabled:n}),[n]),u=e=>{let t=l(e);return{localeCookie:t.getLocale(),setLocaleCookie:t.setLocale}};export{o as localeCookie,a as localeInStorage,c as setLocaleCookie,s as setLocaleInStorage,u as useLocaleCookie,l as useLocaleStorage};
|
|
55
2
|
//# sourceMappingURL=useLocaleStorage.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocaleStorage.mjs","names":["setLocaleInStorageCore"],"sources":["../../../src/client/useLocaleStorage.ts"],"sourcesContent":["import {\n getLocaleFromStorage,\n LocaleStorage,\n
|
|
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';\nimport { useMemo } from 'react';\n\n/**\n * Get the locale cookie\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 cookie 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\n return {\n localeCookie: storage.getLocale(),\n setLocaleCookie: storage.setLocale,\n };\n};\n"],"mappings":"0MAeA,MAAa,EAAkB,EAAqB,EAAqB,CAM5D,EAAe,EAKf,GACX,EACA,IAEAA,EAAuB,EAAQ,CAC7B,GAAG,EACH,kBACD,CAAC,CAOS,EAAkB,EAKlB,EAAoB,GAC/B,MAEI,EAAc,CACZ,GAAG,EACH,kBACD,CAAC,CACJ,CAAC,EAAgB,CAClB,CASU,EAAmB,GAA8B,CAC5D,IAAM,EAAU,EAAiB,EAAgB,CAEjD,MAAO,CACL,aAAc,EAAQ,WAAW,CACjC,gBAAiB,EAAQ,UAC1B"}
|
|
@@ -1,40 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { useLocale } from "./useLocale.mjs";
|
|
4
|
-
import { useEffect } from "react";
|
|
5
|
-
import { getRewritePath } from "@intlayer/core";
|
|
6
|
-
import configuration from "@intlayer/config/built";
|
|
7
|
-
|
|
8
|
-
//#region src/client/useRewriteURL.ts
|
|
9
|
-
/**
|
|
10
|
-
* Client-side hook to manage URL rewrites without triggering a router navigation.
|
|
11
|
-
* It uses `window.history.replaceState` to update the URL in the address bar.
|
|
12
|
-
*
|
|
13
|
-
* This hook is useful to "prettify" the URL when the user lands on a canonical path
|
|
14
|
-
* that has a localized alias defined in `intlayer.config.ts`.
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```tsx
|
|
18
|
-
* import { useRewriteURL } from 'react-intlayer';
|
|
19
|
-
*
|
|
20
|
-
* const MyComponent = () => {
|
|
21
|
-
* useRewriteURL();
|
|
22
|
-
*
|
|
23
|
-
* return <div>My Component</div>;
|
|
24
|
-
* };
|
|
25
|
-
* ```
|
|
26
|
-
*/
|
|
27
|
-
const useRewriteURL = () => {
|
|
28
|
-
const { locale } = useLocale();
|
|
29
|
-
const rewrite = configuration?.routing?.rewrite;
|
|
30
|
-
useEffect(() => {
|
|
31
|
-
if (typeof window === "undefined" || !rewrite) return;
|
|
32
|
-
const pathname = window.location.pathname;
|
|
33
|
-
const targetPath = getRewritePath(pathname, locale, rewrite);
|
|
34
|
-
if (targetPath && targetPath !== pathname) window.history.replaceState(window.history.state, "", targetPath + window.location.search + window.location.hash);
|
|
35
|
-
}, [locale, rewrite]);
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
//#endregion
|
|
39
|
-
export { useRewriteURL };
|
|
1
|
+
"use client";import{useLocale as e}from"./useLocale.mjs";import{useEffect as t}from"react";import n from"@intlayer/config/built";import{getRewritePath as r}from"@intlayer/core/localization";const i=()=>{let{locale:i}=e(),a=n?.routing?.rewrite;t(()=>{if(typeof window>`u`||!a)return;let e=window.location.pathname,t=r(e,i,a);t&&t!==e&&window.history.replaceState(window.history.state,``,t+window.location.search+window.location.hash)},[i,a])};export{i as useRewriteURL};
|
|
40
2
|
//# sourceMappingURL=useRewriteURL.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRewriteURL.mjs","names":[],"sources":["../../../src/client/useRewriteURL.ts"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\nimport { getRewritePath } from '@intlayer/core';\nimport { useEffect } from 'react';\nimport { useLocale } from './useLocale';\n\n/**\n * Client-side hook to manage URL rewrites without triggering a router navigation.\n * It uses `window.history.replaceState` to update the URL in the address bar.\n *\n * This hook is useful to \"prettify\" the URL when the user lands on a canonical path\n * that has a localized alias defined in `intlayer.config.ts`.\n *\n * @example\n * ```tsx\n * import { useRewriteURL } from 'react-intlayer';\n *\n * const MyComponent = () => {\n * useRewriteURL();\n *\n * return <div>My Component</div>;\n * };\n * ```\n */\nexport const useRewriteURL = (): void => {\n const { locale } = useLocale();\n const rewrite = configuration?.routing?.rewrite;\n\n useEffect(() => {\n if (typeof window === 'undefined' || !rewrite) return;\n\n const pathname = window.location.pathname;\n const targetPath = getRewritePath(pathname, locale, rewrite);\n\n if (targetPath && targetPath !== pathname) {\n window.history.replaceState(\n window.history.state,\n '',\n targetPath + window.location.search + window.location.hash\n );\n }\n }, [locale, rewrite]);\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useRewriteURL.mjs","names":[],"sources":["../../../src/client/useRewriteURL.ts"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\nimport { getRewritePath } from '@intlayer/core/localization';\nimport { useEffect } from 'react';\nimport { useLocale } from './useLocale';\n\n/**\n * Client-side hook to manage URL rewrites without triggering a router navigation.\n * It uses `window.history.replaceState` to update the URL in the address bar.\n *\n * This hook is useful to \"prettify\" the URL when the user lands on a canonical path\n * that has a localized alias defined in `intlayer.config.ts`.\n *\n * @example\n * ```tsx\n * import { useRewriteURL } from 'react-intlayer';\n *\n * const MyComponent = () => {\n * useRewriteURL();\n *\n * return <div>My Component</div>;\n * };\n * ```\n */\nexport const useRewriteURL = (): void => {\n const { locale } = useLocale();\n const rewrite = configuration?.routing?.rewrite;\n\n useEffect(() => {\n if (typeof window === 'undefined' || !rewrite) return;\n\n const pathname = window.location.pathname;\n const targetPath = getRewritePath(pathname, locale, rewrite);\n\n if (targetPath && targetPath !== pathname) {\n window.history.replaceState(\n window.history.state,\n '',\n targetPath + window.location.search + window.location.hash\n );\n }\n }, [locale, rewrite]);\n};\n"],"mappings":"8LAyBA,MAAa,MAA4B,CACvC,GAAM,CAAE,UAAW,GAAW,CACxB,EAAU,GAAe,SAAS,QAExC,MAAgB,CACd,GAAI,OAAO,OAAW,KAAe,CAAC,EAAS,OAE/C,IAAM,EAAW,OAAO,SAAS,SAC3B,EAAa,EAAe,EAAU,EAAQ,EAAQ,CAExD,GAAc,IAAe,GAC/B,OAAO,QAAQ,aACb,OAAO,QAAQ,MACf,GACA,EAAa,OAAO,SAAS,OAAS,OAAO,SAAS,KACvD,EAEF,CAAC,EAAQ,EAAQ,CAAC"}
|
|
@@ -1,34 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { useContext, useMemo } from "react";
|
|
3
|
-
import { getTranslation } from "@intlayer/core";
|
|
4
|
-
|
|
5
|
-
//#region src/client/useTraduction.ts
|
|
6
|
-
/**
|
|
7
|
-
* On the client side, Hook that picking one dictionary by its id and return the content.
|
|
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
|
-
* ```tsx
|
|
16
|
-
* const content = useTranslation<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 useTranslation = (languageContent) => {
|
|
28
|
-
const { locale } = useContext(IntlayerClientContext);
|
|
29
|
-
return useMemo(() => getTranslation(languageContent, locale), [languageContent, locale]);
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
//#endregion
|
|
33
|
-
export { useTranslation };
|
|
1
|
+
import{IntlayerClientContext as e}from"./IntlayerProvider.mjs";import{useContext as t,useMemo as n}from"react";import{getTranslation as r}from"@intlayer/core/interpreter";const i=i=>{let{locale:a}=t(e);return n(()=>r(i,a),[i,a])};export{i as useTranslation};
|
|
34
2
|
//# sourceMappingURL=useTraduction.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTraduction.mjs","names":[],"sources":["../../../src/client/useTraduction.ts"],"sourcesContent":["import { getTranslation } from '@intlayer/core';\nimport type { StrictModeLocaleMap } from '@intlayer/types';\nimport { useContext, useMemo } from 'react';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * On the client side, Hook that picking one dictionary by its id and return the content.\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 * ```tsx\n * const content = useTranslation<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 useTranslation = <Content = string>(\n languageContent: StrictModeLocaleMap<Content>\n): Content => {\n const { locale } = useContext(IntlayerClientContext);\n\n return useMemo(\n () => getTranslation(languageContent, locale),\n [languageContent, locale]\n );\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useTraduction.mjs","names":[],"sources":["../../../src/client/useTraduction.ts"],"sourcesContent":["import { getTranslation } from '@intlayer/core/interpreter';\nimport type { StrictModeLocaleMap } from '@intlayer/types';\nimport { useContext, useMemo } from 'react';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * On the client side, Hook that picking one dictionary by its id and return the content.\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 * ```tsx\n * const content = useTranslation<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 useTranslation = <Content = string>(\n languageContent: StrictModeLocaleMap<Content>\n): Content => {\n const { locale } = useContext(IntlayerClientContext);\n\n return useMemo(\n () => getTranslation(languageContent, locale),\n [languageContent, locale]\n );\n};\n"],"mappings":"2KA0BA,MAAa,EACX,GACY,CACZ,GAAM,CAAE,UAAW,EAAW,EAAsB,CAEpD,OAAO,MACC,EAAe,EAAiB,EAAO,CAC7C,CAAC,EAAiB,EAAO,CAC1B"}
|
|
@@ -1,54 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { useIntlayerContext } from "../client/IntlayerProvider.mjs";
|
|
4
|
-
import { ContentSelector } from "../UI/ContentSelector.mjs";
|
|
5
|
-
import { useCallback, useMemo } from "react";
|
|
6
|
-
import { jsx } from "react/jsx-runtime";
|
|
7
|
-
import { isSameKeyPath } from "@intlayer/core";
|
|
8
|
-
import { NodeType } from "@intlayer/types";
|
|
9
|
-
import { MessageKey, useCommunicator, useEditorEnabled, useFocusDictionary } from "@intlayer/editor-react";
|
|
10
|
-
|
|
11
|
-
//#region src/editor/ContentSelectorWrapper.tsx
|
|
12
|
-
const ContentSelectorWrapperContent = ({ children, dictionaryKey, keyPath }) => {
|
|
13
|
-
const { focusedContent, setFocusedContent } = useFocusDictionary();
|
|
14
|
-
const { postMessage, senderId } = useCommunicator();
|
|
15
|
-
const filteredKeyPath = useMemo(() => keyPath.filter((key) => key.type !== NodeType.Translation), [keyPath]);
|
|
16
|
-
return /* @__PURE__ */ jsx(ContentSelector, {
|
|
17
|
-
onPress: useCallback(() => setFocusedContent({
|
|
18
|
-
dictionaryKey,
|
|
19
|
-
keyPath: filteredKeyPath
|
|
20
|
-
}), [dictionaryKey, filteredKeyPath]),
|
|
21
|
-
onHover: useCallback(() => postMessage({
|
|
22
|
-
type: `${MessageKey.INTLAYER_HOVERED_CONTENT_CHANGED}/post`,
|
|
23
|
-
data: {
|
|
24
|
-
dictionaryKey,
|
|
25
|
-
keyPath: filteredKeyPath
|
|
26
|
-
},
|
|
27
|
-
senderId
|
|
28
|
-
}), [dictionaryKey, filteredKeyPath]),
|
|
29
|
-
onUnhover: useCallback(() => postMessage({
|
|
30
|
-
type: `${MessageKey.INTLAYER_HOVERED_CONTENT_CHANGED}/post`,
|
|
31
|
-
data: null,
|
|
32
|
-
senderId
|
|
33
|
-
}), [senderId]),
|
|
34
|
-
isSelecting: useMemo(() => (focusedContent?.dictionaryKey === dictionaryKey && (focusedContent?.keyPath?.length ?? 0) > 0 && isSameKeyPath(focusedContent?.keyPath ?? [], filteredKeyPath)) ?? false, [
|
|
35
|
-
focusedContent,
|
|
36
|
-
filteredKeyPath,
|
|
37
|
-
dictionaryKey
|
|
38
|
-
]),
|
|
39
|
-
children
|
|
40
|
-
});
|
|
41
|
-
};
|
|
42
|
-
const ContentSelectorRenderer = ({ children, ...props }) => {
|
|
43
|
-
const { enabled } = useEditorEnabled();
|
|
44
|
-
const { disableEditor } = useIntlayerContext();
|
|
45
|
-
if (enabled && !disableEditor) return /* @__PURE__ */ jsx(ContentSelectorWrapperContent, {
|
|
46
|
-
...props,
|
|
47
|
-
children
|
|
48
|
-
});
|
|
49
|
-
return children;
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
//#endregion
|
|
53
|
-
export { ContentSelectorRenderer };
|
|
1
|
+
"use client";import{useIntlayerContext as e}from"../client/IntlayerProvider.mjs";import{ContentSelector as t}from"../UI/ContentSelector.mjs";import{useCallback as n,useMemo as r}from"react";import{jsx as i}from"react/jsx-runtime";import{NodeType as a}from"@intlayer/types";import{isSameKeyPath as o}from"@intlayer/core/utils";import{MessageKey as s,useCommunicator as c,useEditorEnabled as l,useFocusDictionary as u}from"@intlayer/editor-react";const d=({children:e,dictionaryKey:l,keyPath:d})=>{let{focusedContent:f,setFocusedContent:p}=u(),{postMessage:m,senderId:h}=c(),g=r(()=>d.filter(e=>e.type!==a.Translation),[d]);return i(t,{onPress:n(()=>p({dictionaryKey:l,keyPath:g}),[l,g]),onHover:n(()=>m({type:`${s.INTLAYER_HOVERED_CONTENT_CHANGED}/post`,data:{dictionaryKey:l,keyPath:g},senderId:h}),[l,g]),onUnhover:n(()=>m({type:`${s.INTLAYER_HOVERED_CONTENT_CHANGED}/post`,data:null,senderId:h}),[h]),isSelecting:r(()=>(f?.dictionaryKey===l&&(f?.keyPath?.length??0)>0&&o(f?.keyPath??[],g))??!1,[f,g,l]),children:e})},f=({children:t,...n})=>{let{enabled:r}=l(),{disableEditor:a}=e();return r&&!a?i(d,{...n,children:t}):t};export{f as ContentSelectorRenderer};
|
|
54
2
|
//# sourceMappingURL=ContentSelectorWrapper.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContentSelectorWrapper.mjs","names":[],"sources":["../../../src/editor/ContentSelectorWrapper.tsx"],"sourcesContent":["'use client';\n\nimport {
|
|
1
|
+
{"version":3,"file":"ContentSelectorWrapper.mjs","names":[],"sources":["../../../src/editor/ContentSelectorWrapper.tsx"],"sourcesContent":["'use client';\n\nimport type { NodeProps } from '@intlayer/core/interpreter';\nimport { isSameKeyPath } from '@intlayer/core/utils';\nimport {\n MessageKey,\n useCommunicator,\n useEditorEnabled,\n useFocusDictionary,\n} from '@intlayer/editor-react';\nimport { NodeType } from '@intlayer/types';\nimport { type FC, type HTMLAttributes, useCallback, useMemo } from 'react';\nimport { useIntlayerContext } from '../client';\nimport { ContentSelector } from '../UI/ContentSelector';\n\nexport type ContentSelectorWrapperProps = NodeProps &\n Omit<HTMLAttributes<HTMLDivElement>, 'children'>;\n\nconst ContentSelectorWrapperContent: FC<ContentSelectorWrapperProps> = ({\n children,\n dictionaryKey,\n keyPath,\n}) => {\n const { focusedContent, setFocusedContent } = useFocusDictionary();\n const { postMessage, senderId } = useCommunicator();\n\n // Filter out translation nodes for more flexibility with the editor that can have different format\n const filteredKeyPath = useMemo(\n () => keyPath.filter((key) => key.type !== NodeType.Translation),\n [keyPath]\n );\n\n const handleSelect = useCallback(\n () =>\n setFocusedContent({\n dictionaryKey,\n keyPath: filteredKeyPath,\n }),\n [dictionaryKey, filteredKeyPath]\n );\n\n const handleHover = useCallback(\n () =>\n postMessage({\n type: `${MessageKey.INTLAYER_HOVERED_CONTENT_CHANGED}/post`,\n data: {\n dictionaryKey,\n keyPath: filteredKeyPath,\n },\n senderId,\n }),\n [dictionaryKey, filteredKeyPath]\n );\n\n const handleUnhover = useCallback(\n () =>\n postMessage({\n type: `${MessageKey.INTLAYER_HOVERED_CONTENT_CHANGED}/post`,\n data: null,\n senderId,\n }),\n [senderId]\n );\n\n const isSelected = useMemo(\n () =>\n (focusedContent?.dictionaryKey === dictionaryKey &&\n (focusedContent?.keyPath?.length ?? 0) > 0 &&\n isSameKeyPath(focusedContent?.keyPath ?? [], filteredKeyPath)) ??\n false,\n [focusedContent, filteredKeyPath, dictionaryKey]\n );\n\n return (\n <ContentSelector\n onPress={handleSelect}\n onHover={handleHover}\n onUnhover={handleUnhover}\n isSelecting={isSelected}\n >\n {children}\n </ContentSelector>\n );\n};\n\nexport const ContentSelectorRenderer: FC<ContentSelectorWrapperProps> = ({\n children,\n ...props\n}) => {\n const { enabled } = useEditorEnabled();\n const { disableEditor } = useIntlayerContext();\n\n if (enabled && !disableEditor) {\n return (\n <ContentSelectorWrapperContent {...props}>\n {children}\n </ContentSelectorWrapperContent>\n );\n }\n\n return children;\n};\n"],"mappings":"6bAkBA,MAAM,GAAkE,CACtE,WACA,gBACA,aACI,CACJ,GAAM,CAAE,iBAAgB,qBAAsB,GAAoB,CAC5D,CAAE,cAAa,YAAa,GAAiB,CAG7C,EAAkB,MAChB,EAAQ,OAAQ,GAAQ,EAAI,OAAS,EAAS,YAAY,CAChE,CAAC,EAAQ,CACV,CA2CD,OACE,EAAC,EAAA,CACC,QA3CiB,MAEjB,EAAkB,CAChB,gBACA,QAAS,EACV,CAAC,CACJ,CAAC,EAAe,EAAgB,CACjC,CAqCG,QAnCgB,MAEhB,EAAY,CACV,KAAM,GAAG,EAAW,iCAAiC,OACrD,KAAM,CACJ,gBACA,QAAS,EACV,CACD,WACD,CAAC,CACJ,CAAC,EAAe,EAAgB,CACjC,CAyBG,UAvBkB,MAElB,EAAY,CACV,KAAM,GAAG,EAAW,iCAAiC,OACrD,KAAM,KACN,WACD,CAAC,CACJ,CAAC,EAAS,CACX,CAgBG,YAde,OAEd,GAAgB,gBAAkB,IAChC,GAAgB,SAAS,QAAU,GAAK,GACzC,EAAc,GAAgB,SAAW,EAAE,CAAE,EAAgB,GAC/D,GACF,CAAC,EAAgB,EAAiB,EAAc,CACjD,CASI,YACe,EAIT,GAA4D,CACvE,WACA,GAAG,KACC,CACJ,GAAM,CAAE,WAAY,GAAkB,CAChC,CAAE,iBAAkB,GAAoB,CAU9C,OARI,GAAW,CAAC,EAEZ,EAAC,EAAA,CAA8B,GAAI,EAChC,YAC6B,CAI7B"}
|