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,38 @@
|
|
|
1
|
-
import{getIntlayer
|
|
1
|
+
import { getIntlayer } from "../getIntlayer.mjs";
|
|
2
|
+
import { getServerContext } from "./serverContext.mjs";
|
|
3
|
+
import { IntlayerServerContext } from "./IntlayerServerProvider.mjs";
|
|
4
|
+
|
|
5
|
+
//#region src/server/useI18n.ts
|
|
6
|
+
/**
|
|
7
|
+
* Hook that provides a translation function `t()` for accessing nested content by key.
|
|
8
|
+
* This hook mimics the pattern found in libraries like i18next, next-intl, and vue-i18n.
|
|
9
|
+
*
|
|
10
|
+
* @param namespace - The dictionary key to scope translations to
|
|
11
|
+
* @param locale - Optional locale override. If not provided, uses the current context locale
|
|
12
|
+
* @returns A translation function `t(key)` that returns the translated content for the given key
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```tsx
|
|
16
|
+
* const t = useI18n('IndexPage');
|
|
17
|
+
* const title = t('title'); // Returns translated string for 'IndexPage.title'
|
|
18
|
+
* const nestedContent = t('section.subtitle'); // Returns 'IndexPage.section.subtitle'
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
const useI18n = (namespace, locale) => {
|
|
22
|
+
const dictionaryContent = getIntlayer(namespace, locale ?? getServerContext(IntlayerServerContext));
|
|
23
|
+
const t = (path) => {
|
|
24
|
+
if (!path) return dictionaryContent;
|
|
25
|
+
const pathArray = path.split(".");
|
|
26
|
+
let current = dictionaryContent;
|
|
27
|
+
for (const key of pathArray) {
|
|
28
|
+
current = current?.[key];
|
|
29
|
+
if (current === void 0) return dictionaryContent;
|
|
30
|
+
}
|
|
31
|
+
return current;
|
|
32
|
+
};
|
|
33
|
+
return t;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
//#endregion
|
|
37
|
+
export { useI18n };
|
|
2
38
|
//# sourceMappingURL=useI18n.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useI18n.mjs","names":[],"sources":["../../../src/server/useI18n.ts"],"sourcesContent":["import type { ValidDotPathsFor } from '@intlayer/core/transpiler';\nimport type { DictionaryKeys, DictionaryRegistryContent, LocalesValues } from '@intlayer/types/module_augmentation';\nimport type { GetSubPath } from '@intlayer/types/dictionary';\nimport { getIntlayer } from '../getIntlayer';\nimport type { DeepTransformContent } from '../plugins';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\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 * ```\n */\nexport const useI18n = <T extends DictionaryKeys>(\n namespace: T,\n locale?: LocalesValues\n) => {\n const localeTarget =\n locale ?? getServerContext<LocalesValues>(IntlayerServerContext);\n\n // Get the dictionary content for the namespace\n const dictionaryContent = getIntlayer(namespace, localeTarget);\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 ): GetSubPath<DeepTransformContent<DictionaryRegistryContent<T>>, P> => {\n if (!path) {\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":"
|
|
1
|
+
{"version":3,"file":"useI18n.mjs","names":[],"sources":["../../../src/server/useI18n.ts"],"sourcesContent":["import type { ValidDotPathsFor } from '@intlayer/core/transpiler';\nimport type { DictionaryKeys, DictionaryRegistryContent, LocalesValues } from '@intlayer/types/module_augmentation';\nimport type { GetSubPath } from '@intlayer/types/dictionary';\nimport { getIntlayer } from '../getIntlayer';\nimport type { DeepTransformContent } from '../plugins';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\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 * ```\n */\nexport const useI18n = <T extends DictionaryKeys>(\n namespace: T,\n locale?: LocalesValues\n) => {\n const localeTarget =\n locale ?? getServerContext<LocalesValues>(IntlayerServerContext);\n\n // Get the dictionary content for the namespace\n const dictionaryContent = getIntlayer(namespace, localeTarget);\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 ): GetSubPath<DeepTransformContent<DictionaryRegistryContent<T>>, P> => {\n if (!path) {\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":";;;;;;;;;;;;;;;;;;;;AAuBA,MAAa,WACX,WACA,WACG;CAKH,MAAM,oBAAoB,YAAY,WAHpC,UAAU,iBAAgC,sBAAsB,CAGJ;CAI9D,MAAM,KACJ,SACsE;AACtE,MAAI,CAAC,KACH,QAAO;EAGT,MAAM,YAAa,KAAgB,MAAM,IAAI;EAC7C,IAAI,UAAe;AAEnB,OAAK,MAAM,OAAO,WAAW;AAC3B,aAAU,UAAU;AACpB,OAAI,YAAY,OAEd,QAAO;;AAIX,SAAO;;AAGT,QAAO"}
|
|
@@ -1,2 +1,17 @@
|
|
|
1
|
-
import{getIntlayer
|
|
1
|
+
import { getIntlayer } from "../getIntlayer.mjs";
|
|
2
|
+
import { getServerContext } from "./serverContext.mjs";
|
|
3
|
+
import { IntlayerServerContext } from "./IntlayerServerProvider.mjs";
|
|
4
|
+
|
|
5
|
+
//#region src/server/useIntlayer.ts
|
|
6
|
+
/**
|
|
7
|
+
* On the server side, Hook that picking one dictionary by its key and return the content
|
|
8
|
+
*
|
|
9
|
+
* If the locale is not provided, it will use the locale from the server context
|
|
10
|
+
*/
|
|
11
|
+
const useIntlayer = (key, locale, fallbackLocale) => {
|
|
12
|
+
return getIntlayer(key, locale ?? getServerContext(IntlayerServerContext) ?? fallbackLocale);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
16
|
+
export { useIntlayer };
|
|
2
17
|
//# sourceMappingURL=useIntlayer.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIntlayer.mjs","names":[],"sources":["../../../src/server/useIntlayer.ts"],"sourcesContent":["import type { DeclaredLocales, DictionaryKeys, LocalesValues } from '@intlayer/types/module_augmentation';\nimport { getIntlayer } from '../getIntlayer';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\n\n/**\n * On the server side, Hook that picking one dictionary by its key and return the content\n *\n * If the locale is not provided, it will use the locale from the server context\n */\nexport const useIntlayer = <\n T extends DictionaryKeys,\n L extends LocalesValues = DeclaredLocales,\n>(\n key: T,\n locale?: L,\n fallbackLocale?: DeclaredLocales\n) => {\n const localeTarget =\n locale ??\n getServerContext<LocalesValues>(IntlayerServerContext) ??\n fallbackLocale;\n\n return getIntlayer<T, L>(key, localeTarget as L);\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useIntlayer.mjs","names":[],"sources":["../../../src/server/useIntlayer.ts"],"sourcesContent":["import type { DeclaredLocales, DictionaryKeys, LocalesValues } from '@intlayer/types/module_augmentation';\nimport { getIntlayer } from '../getIntlayer';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\n\n/**\n * On the server side, Hook that picking one dictionary by its key and return the content\n *\n * If the locale is not provided, it will use the locale from the server context\n */\nexport const useIntlayer = <\n T extends DictionaryKeys,\n L extends LocalesValues = DeclaredLocales,\n>(\n key: T,\n locale?: L,\n fallbackLocale?: DeclaredLocales\n) => {\n const localeTarget =\n locale ??\n getServerContext<LocalesValues>(IntlayerServerContext) ??\n fallbackLocale;\n\n return getIntlayer<T, L>(key, localeTarget as L);\n};\n"],"mappings":";;;;;;;;;;AAUA,MAAa,eAIX,KACA,QACA,mBACG;AAMH,QAAO,YAAkB,KAJvB,UACA,iBAAgC,sBAAsB,IACtD,eAE8C"}
|
|
@@ -1,2 +1,12 @@
|
|
|
1
|
-
import
|
|
1
|
+
import react from "react";
|
|
2
|
+
|
|
3
|
+
//#region src/server/useLoadDynamic.ts
|
|
4
|
+
const useLoadDynamic = (_key, promise) => {
|
|
5
|
+
/** @ts-ignore remove error Property 'cache' does not exist on type 'typeof React'. */
|
|
6
|
+
const cachedPromise = react.cache(async () => await promise)();
|
|
7
|
+
return react.use(cachedPromise);
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
//#endregion
|
|
11
|
+
export { useLoadDynamic };
|
|
2
12
|
//# sourceMappingURL=useLoadDynamic.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLoadDynamic.mjs","names":[],"sources":["../../../src/server/useLoadDynamic.ts"],"sourcesContent":["import react from 'react';\n\nexport const useLoadDynamic = <T>(_key: string, promise: Promise<T>): T => {\n /** @ts-ignore remove error Property 'cache' does not exist on type 'typeof React'. */\n const cachedPromise = react.cache(async () => await promise)();\n\n /** @ts-ignore remove error Property 'use' does not exist on type 'typeof React'. */\n const dictionary = react.use(cachedPromise);\n\n return dictionary;\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useLoadDynamic.mjs","names":[],"sources":["../../../src/server/useLoadDynamic.ts"],"sourcesContent":["import react from 'react';\n\nexport const useLoadDynamic = <T>(_key: string, promise: Promise<T>): T => {\n /** @ts-ignore remove error Property 'cache' does not exist on type 'typeof React'. */\n const cachedPromise = react.cache(async () => await promise)();\n\n /** @ts-ignore remove error Property 'use' does not exist on type 'typeof React'. */\n const dictionary = react.use(cachedPromise);\n\n return dictionary;\n};\n"],"mappings":";;;AAEA,MAAa,kBAAqB,MAAc,YAA2B;;CAEzE,MAAM,gBAAgB,MAAM,MAAM,YAAY,MAAM,QAAQ,EAAE;AAK9D,QAFmB,MAAM,IAAI,cAAc"}
|
|
@@ -1,2 +1,22 @@
|
|
|
1
|
-
import{getServerContext
|
|
1
|
+
import { getServerContext } from "./serverContext.mjs";
|
|
2
|
+
import { IntlayerServerContext } from "./IntlayerServerProvider.mjs";
|
|
3
|
+
import configuration from "@intlayer/config/built";
|
|
4
|
+
|
|
5
|
+
//#region src/server/useLocale.ts
|
|
6
|
+
/**
|
|
7
|
+
* On the server side, Hook that picking one dictionary by its key and return the content
|
|
8
|
+
*
|
|
9
|
+
* If the locale is not provided, it will use the locale from the server context
|
|
10
|
+
*/
|
|
11
|
+
const useLocale = () => {
|
|
12
|
+
const { defaultLocale, locales: availableLocales } = configuration?.internationalization ?? {};
|
|
13
|
+
return {
|
|
14
|
+
locale: getServerContext(IntlayerServerContext) ?? defaultLocale,
|
|
15
|
+
defaultLocale,
|
|
16
|
+
availableLocales
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
//#endregion
|
|
21
|
+
export { useLocale };
|
|
2
22
|
//# sourceMappingURL=useLocale.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocale.mjs","names":[],"sources":["../../../src/server/useLocale.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { DeclaredLocales } from '@intlayer/types/module_augmentation';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\n\ntype UseLocaleResult = {\n locale: DeclaredLocales;\n defaultLocale: DeclaredLocales;\n availableLocales: DeclaredLocales[];\n};\n\n/**\n * On the server side, Hook that picking one dictionary by its key and return the content\n *\n * If the locale is not provided, it will use the locale from the server context\n */\nexport const useLocale = (): UseLocaleResult => {\n const { defaultLocale, locales: availableLocales } =\n configuration?.internationalization ?? {};\n\n const locale = (getServerContext(IntlayerServerContext) ??\n defaultLocale) as DeclaredLocales;\n\n return { locale, defaultLocale, availableLocales };\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useLocale.mjs","names":[],"sources":["../../../src/server/useLocale.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { DeclaredLocales } from '@intlayer/types/module_augmentation';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\n\ntype UseLocaleResult = {\n locale: DeclaredLocales;\n defaultLocale: DeclaredLocales;\n availableLocales: DeclaredLocales[];\n};\n\n/**\n * On the server side, Hook that picking one dictionary by its key and return the content\n *\n * If the locale is not provided, it will use the locale from the server context\n */\nexport const useLocale = (): UseLocaleResult => {\n const { defaultLocale, locales: availableLocales } =\n configuration?.internationalization ?? {};\n\n const locale = (getServerContext(IntlayerServerContext) ??\n defaultLocale) as DeclaredLocales;\n\n return { locale, defaultLocale, availableLocales };\n};\n"],"mappings":";;;;;;;;;;AAgBA,MAAa,kBAAmC;CAC9C,MAAM,EAAE,eAAe,SAAS,qBAC9B,eAAe,wBAAwB,EAAE;AAK3C,QAAO;EAAE,QAHO,iBAAiB,sBAAsB,IACrD;EAEe;EAAe;EAAkB"}
|
|
@@ -5,13 +5,13 @@ import { FC, JSX } from "react";
|
|
|
5
5
|
//#region src/html/HTMLRenderer.d.ts
|
|
6
6
|
declare const defaultHTMLComponents: {} & {
|
|
7
7
|
object?: FC<react.DetailedHTMLProps<react.ObjectHTMLAttributes<HTMLObjectElement>, HTMLObjectElement>>;
|
|
8
|
+
html?: FC<react.DetailedHTMLProps<react.HtmlHTMLAttributes<HTMLHtmlElement>, HTMLHtmlElement>>;
|
|
8
9
|
hr?: FC<react.DetailedHTMLProps<react.HTMLAttributes<HTMLHRElement>, HTMLHRElement>>;
|
|
9
10
|
th?: FC<react.DetailedHTMLProps<react.ThHTMLAttributes<HTMLTableHeaderCellElement>, HTMLTableHeaderCellElement>>;
|
|
10
11
|
tr?: FC<react.DetailedHTMLProps<react.HTMLAttributes<HTMLTableRowElement>, HTMLTableRowElement>>;
|
|
11
12
|
small?: FC<react.DetailedHTMLProps<react.HTMLAttributes<HTMLElement>, HTMLElement>>;
|
|
12
13
|
sub?: FC<react.DetailedHTMLProps<react.HTMLAttributes<HTMLElement>, HTMLElement>>;
|
|
13
14
|
sup?: FC<react.DetailedHTMLProps<react.HTMLAttributes<HTMLElement>, HTMLElement>>;
|
|
14
|
-
html?: FC<react.DetailedHTMLProps<react.HtmlHTMLAttributes<HTMLHtmlElement>, HTMLHtmlElement>>;
|
|
15
15
|
head?: FC<react.DetailedHTMLProps<react.HTMLAttributes<HTMLHeadElement>, HTMLHeadElement>>;
|
|
16
16
|
body?: FC<react.DetailedHTMLProps<react.HTMLAttributes<HTMLBodyElement>, HTMLBodyElement>>;
|
|
17
17
|
main?: FC<react.DetailedHTMLProps<react.HTMLAttributes<HTMLElement>, HTMLElement>>;
|
package/dist/types/plugins.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { HTMLComponents } from "./html/HTMLComponentTypes.js";
|
|
|
3
3
|
import { DeepTransformContent as DeepTransformContent$1, IInterpreterPluginState as IInterpreterPluginState$1, Plugins } from "@intlayer/core/interpreter";
|
|
4
4
|
import { DeclaredLocales, LocalesValues } from "@intlayer/types/module_augmentation";
|
|
5
5
|
import { ReactNode } from "react";
|
|
6
|
+
import * as NodeTypes from "@intlayer/types/nodeType";
|
|
6
7
|
import { NodeType } from "@intlayer/types/nodeType";
|
|
7
8
|
|
|
8
9
|
//#region src/plugins.d.ts
|
|
@@ -26,7 +27,7 @@ declare const reactNodePlugins: Plugins;
|
|
|
26
27
|
* --------------------------------------------- */
|
|
27
28
|
type InsertionCond<T> = T extends {
|
|
28
29
|
nodeType: NodeType | string;
|
|
29
|
-
[
|
|
30
|
+
[NodeTypes.INSERTION]: string;
|
|
30
31
|
fields: readonly string[];
|
|
31
32
|
} ? <V extends { [K in T['fields'][number]]: ReactNode }>(values: V) => V[keyof V] extends string | number ? IntlayerNode<string> : IntlayerNode<ReactNode> : never;
|
|
32
33
|
/** Insertion plugin for React. Handles component/node insertion. */
|
|
@@ -42,7 +43,7 @@ type MarkdownStringCond<T> = T extends string ? IntlayerNode<string, {
|
|
|
42
43
|
declare const markdownStringPlugin: Plugins;
|
|
43
44
|
type MarkdownCond<T> = T extends {
|
|
44
45
|
nodeType: NodeType | string;
|
|
45
|
-
[
|
|
46
|
+
[NodeTypes.MARKDOWN]: infer M;
|
|
46
47
|
tags?: infer U;
|
|
47
48
|
metadata?: infer V;
|
|
48
49
|
} ? IntlayerNode<M, {
|
|
@@ -63,7 +64,7 @@ declare const markdownPlugin: Plugins;
|
|
|
63
64
|
*/
|
|
64
65
|
type HTMLPluginCond<T> = T extends {
|
|
65
66
|
nodeType: NodeType | string;
|
|
66
|
-
[
|
|
67
|
+
[NodeTypes.HTML]: infer I;
|
|
67
68
|
tags?: infer U;
|
|
68
69
|
} ? IntlayerNode<I, {
|
|
69
70
|
use: (components?: HTMLComponents<'permissive', U>) => ReactNode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugins.d.ts","names":[],"sources":["../../src/plugins.tsx"],"mappings":"
|
|
1
|
+
{"version":3,"file":"plugins.d.ts","names":[],"sources":["../../src/plugins.tsx"],"mappings":";;;;;;;;;;;AA2CA;KAAY,gBAAA,MAAsB,CAAA,2BAC9B,YAAA,CAAa,CAAA;;cAIJ,mBAAA,EAAqB,OAAA;;;;KA4BtB,aAAA,MAAmB,CAAA;EAC7B,KAAA;EACA,GAAA;AAAA,IAEE,SAAA;;cAIS,gBAAA,EAAkB,OAAA;;AApC/B;;KAiEY,aAAA,MAAmB,CAAA;EAC7B,QAAA,EAAU,QAAA;EAAA,CACT,SAAA,CAAU,SAAA;EACX,MAAA;AAAA,uBAEqB,CAAA,qBAAsB,SAAA,IACvC,MAAA,EAAQ,CAAA,KACL,CAAA,OAAQ,CAAA,4BACT,YAAA,WACA,YAAA,CAAa,SAAA;;cA4BR,eAAA,EAAiB,OAAA;;;;KAkFlB,kBAAA,MAAwB,CAAA,kBAChC,YAAA;EAGI,QAAA,EAAU,oBAAA;EACV,GAAA,GAAM,UAAA,EAAY,cAAA,uBAAqC,SAAA;AAAA;;cAMlD,oBAAA,EAAsB,OAAA;AAAA,KA8EvB,YAAA,MAAkB,CAAA;EAC5B,QAAA,EAAU,QAAA;EAAA,CACT,SAAA,CAAU,QAAA;EACX,IAAA;EACA,QAAA;AAAA,IAEE,YAAA,CACE,CAAA;EAEE,GAAA,GAAM,UAAA,GAAa,cAAA,eAA6B,CAAA,MAAO,SAAA;EACvD,QAAA,EAAU,oBAAA,CAAqB,CAAA;AAAA;AAAA,cAK1B,cAAA,EAAgB,OAAA;;;;;;;;;;;;KAmCjB,cAAA,MAAoB,CAAA;EAC9B,QAAA,EAAU,QAAA;EAAA,CACT,SAAA,CAAU,IAAA;EACX,IAAA;AAAA,IAEE,YAAA,CACE,CAAA;EAEE,GAAA,GAAM,UAAA,GAAa,cAAA,eAA6B,CAAA,MAAO,SAAA;AAAA;;cAMlD,UAAA,EAAY,OAAA;;;;KAoCb,uBAAA,mBAA0C,aAAA;EACpD,SAAA,EAAW,aAAA,CAAc,CAAA;EACzB,iBAAA,EAAmB,gBAAA,CAAiB,CAAA;EACpC,cAAA,EAAgB,aAAA,CAAc,CAAA;EAC9B,aAAA,EAAe,YAAA,CAAa,CAAA;EAC5B,SAAA,EAAW,cAAA,CAAe,CAAA;AAAA;;;;AAlM5B;;KA0MY,uBAAA,GAA0B,IAAA,CACpC,yBAAA;EAGA,SAAA;EACA,iBAAA;EACA,aAAA;EACA,SAAA;EACA,cAAA;AAAA;AAAA,KAGU,oBAAA,cAEA,aAAA,GAAgB,eAAA,IACxB,sBAAA,CAAyB,CAAA,EAAG,uBAAA,EAAyB,CAAA;;;;;cAM5C,UAAA,GACX,MAAA,GAAS,aAAA,EACT,QAAA,eACC,OAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-intlayer",
|
|
3
|
-
"version": "8.4.
|
|
3
|
+
"version": "8.4.5",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Easily internationalize i18n your React applications with type-safe multilingual content management.",
|
|
6
6
|
"keywords": [
|
|
@@ -115,14 +115,14 @@
|
|
|
115
115
|
"typecheck": "tsc --noEmit --project tsconfig.types.json"
|
|
116
116
|
},
|
|
117
117
|
"dependencies": {
|
|
118
|
-
"@intlayer/api": "8.4.
|
|
119
|
-
"@intlayer/config": "8.4.
|
|
120
|
-
"@intlayer/core": "8.4.
|
|
121
|
-
"@intlayer/dictionaries-entry": "8.4.
|
|
122
|
-
"@intlayer/editor": "8.4.
|
|
123
|
-
"@intlayer/editor-react": "8.4.
|
|
124
|
-
"@intlayer/types": "8.4.
|
|
125
|
-
"intlayer": "8.4.
|
|
118
|
+
"@intlayer/api": "8.4.5",
|
|
119
|
+
"@intlayer/config": "8.4.5",
|
|
120
|
+
"@intlayer/core": "8.4.5",
|
|
121
|
+
"@intlayer/dictionaries-entry": "8.4.5",
|
|
122
|
+
"@intlayer/editor": "8.4.5",
|
|
123
|
+
"@intlayer/editor-react": "8.4.5",
|
|
124
|
+
"@intlayer/types": "8.4.5",
|
|
125
|
+
"intlayer": "8.4.5"
|
|
126
126
|
},
|
|
127
127
|
"devDependencies": {
|
|
128
128
|
"@craco/types": "7.1.0",
|