@intlayer/react-i18next 8.12.5-canary.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/README.md +330 -0
  2. package/dist/cjs/I18nextProvider.cjs +25 -0
  3. package/dist/cjs/I18nextProvider.cjs.map +1 -0
  4. package/dist/cjs/Trans.cjs +64 -0
  5. package/dist/cjs/Trans.cjs.map +1 -0
  6. package/dist/cjs/_virtual/_rolldown/runtime.cjs +29 -0
  7. package/dist/cjs/helpers.cjs +67 -0
  8. package/dist/cjs/helpers.cjs.map +1 -0
  9. package/dist/cjs/index.cjs +49 -0
  10. package/dist/cjs/index.cjs.map +1 -0
  11. package/dist/cjs/initReactI18next.cjs +24 -0
  12. package/dist/cjs/initReactI18next.cjs.map +1 -0
  13. package/dist/cjs/plugin/index.cjs +62 -0
  14. package/dist/cjs/plugin/index.cjs.map +1 -0
  15. package/dist/cjs/useDictionary.cjs +64 -0
  16. package/dist/cjs/useDictionary.cjs.map +1 -0
  17. package/dist/cjs/useDictionaryDynamic.cjs +49 -0
  18. package/dist/cjs/useDictionaryDynamic.cjs.map +1 -0
  19. package/dist/cjs/useTranslation.cjs +109 -0
  20. package/dist/cjs/useTranslation.cjs.map +1 -0
  21. package/dist/cjs/useTranslationDictionary.cjs +57 -0
  22. package/dist/cjs/useTranslationDictionary.cjs.map +1 -0
  23. package/dist/cjs/useTranslationDictionaryDynamic.cjs +49 -0
  24. package/dist/cjs/useTranslationDictionaryDynamic.cjs.map +1 -0
  25. package/dist/cjs/withTranslation.cjs +28 -0
  26. package/dist/cjs/withTranslation.cjs.map +1 -0
  27. package/dist/esm/I18nextProvider.mjs +23 -0
  28. package/dist/esm/I18nextProvider.mjs.map +1 -0
  29. package/dist/esm/Trans.mjs +62 -0
  30. package/dist/esm/Trans.mjs.map +1 -0
  31. package/dist/esm/helpers.mjs +54 -0
  32. package/dist/esm/helpers.mjs.map +1 -0
  33. package/dist/esm/index.mjs +28 -0
  34. package/dist/esm/index.mjs.map +1 -0
  35. package/dist/esm/initReactI18next.mjs +23 -0
  36. package/dist/esm/initReactI18next.mjs.map +1 -0
  37. package/dist/esm/plugin/index.mjs +58 -0
  38. package/dist/esm/plugin/index.mjs.map +1 -0
  39. package/dist/esm/useDictionary.mjs +62 -0
  40. package/dist/esm/useDictionary.mjs.map +1 -0
  41. package/dist/esm/useDictionaryDynamic.mjs +47 -0
  42. package/dist/esm/useDictionaryDynamic.mjs.map +1 -0
  43. package/dist/esm/useTranslation.mjs +107 -0
  44. package/dist/esm/useTranslation.mjs.map +1 -0
  45. package/dist/esm/useTranslationDictionary.mjs +55 -0
  46. package/dist/esm/useTranslationDictionary.mjs.map +1 -0
  47. package/dist/esm/useTranslationDictionaryDynamic.mjs +47 -0
  48. package/dist/esm/useTranslationDictionaryDynamic.mjs.map +1 -0
  49. package/dist/esm/withTranslation.mjs +26 -0
  50. package/dist/esm/withTranslation.mjs.map +1 -0
  51. package/dist/types/I18nextProvider.d.ts +13 -0
  52. package/dist/types/I18nextProvider.d.ts.map +1 -0
  53. package/dist/types/Trans.d.ts +22 -0
  54. package/dist/types/Trans.d.ts.map +1 -0
  55. package/dist/types/helpers.d.ts +35 -0
  56. package/dist/types/helpers.d.ts.map +1 -0
  57. package/dist/types/index.d.ts +27 -0
  58. package/dist/types/index.d.ts.map +1 -0
  59. package/dist/types/initReactI18next.d.ts +16 -0
  60. package/dist/types/initReactI18next.d.ts.map +1 -0
  61. package/dist/types/plugin/index.d.ts +12 -0
  62. package/dist/types/plugin/index.d.ts.map +1 -0
  63. package/dist/types/useDictionary.d.ts +32 -0
  64. package/dist/types/useDictionary.d.ts.map +1 -0
  65. package/dist/types/useDictionaryDynamic.d.ts +22 -0
  66. package/dist/types/useDictionaryDynamic.d.ts.map +1 -0
  67. package/dist/types/useTranslation.d.ts +43 -0
  68. package/dist/types/useTranslation.d.ts.map +1 -0
  69. package/dist/types/useTranslationDictionary.d.ts +29 -0
  70. package/dist/types/useTranslationDictionary.d.ts.map +1 -0
  71. package/dist/types/useTranslationDictionaryDynamic.d.ts +22 -0
  72. package/dist/types/useTranslationDictionaryDynamic.d.ts.map +1 -0
  73. package/dist/types/withTranslation.d.ts +10 -0
  74. package/dist/types/withTranslation.d.ts.map +1 -0
  75. package/package.json +118 -0
@@ -0,0 +1,54 @@
1
+ import { useTranslation } from "./useTranslation.mjs";
2
+ import * as React from "react";
3
+ import { jsx } from "react/jsx-runtime";
4
+
5
+ //#region src/helpers.tsx
6
+ const I18nContext = React.createContext({ i18n: null });
7
+ const Translation = ({ children, ns, keyPrefix }) => {
8
+ const { t, i18n } = useTranslation(ns, { keyPrefix });
9
+ return children(t, {
10
+ i18n,
11
+ lng: i18n.language
12
+ }, true);
13
+ };
14
+ const nodesToString = (children, _i18nOptions, _i18n, _i18nKey) => {
15
+ if (typeof children === "string" || typeof children === "number") return String(children);
16
+ if (!children) return "";
17
+ if (Array.isArray(children)) return children.map((c) => nodesToString(c)).join("");
18
+ const childElement = children;
19
+ if (childElement.props?.children) return nodesToString(childElement.props.children);
20
+ return "";
21
+ };
22
+ let globalI18n = null;
23
+ let globalDefaults = {};
24
+ const setI18n = (instance) => {
25
+ globalI18n = instance;
26
+ };
27
+ const getI18n = () => {
28
+ return globalI18n;
29
+ };
30
+ const setDefaults = (options) => {
31
+ globalDefaults = options;
32
+ };
33
+ const getDefaults = () => {
34
+ return globalDefaults;
35
+ };
36
+ const useSSR = (_initialI18nStore, _initialLanguage) => {};
37
+ const withSSR = () => {
38
+ const Hoc = (WrappedComponent) => {
39
+ const Component = (props) => /* @__PURE__ */ jsx(WrappedComponent, { ...props });
40
+ const ExtendedComponent = Component;
41
+ ExtendedComponent.getInitialProps = async (_ctx) => ({});
42
+ return ExtendedComponent;
43
+ };
44
+ return Hoc;
45
+ };
46
+ const composeInitialProps = (_ForComponent) => async (_ctx) => ({});
47
+ const getInitialProps = () => ({
48
+ initialI18nStore: {},
49
+ initialLanguage: "en"
50
+ });
51
+
52
+ //#endregion
53
+ export { I18nContext, Translation, composeInitialProps, getDefaults, getI18n, getInitialProps, nodesToString, setDefaults, setI18n, useSSR, withSSR };
54
+ //# sourceMappingURL=helpers.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.mjs","names":[],"sources":["../../src/helpers.tsx"],"sourcesContent":["import type { i18n, TFunction } from 'i18next';\nimport * as React from 'react';\nimport { useTranslation } from './useTranslation';\n\n// Context\nexport const I18nContext = React.createContext<{ i18n: i18n }>({\n i18n: null as unknown as i18n,\n});\n\nexport interface TranslationProps {\n children: (\n t: TFunction,\n options: { i18n: i18n; lng: string },\n ready: boolean\n ) => React.ReactNode;\n ns?: string | string[];\n keyPrefix?: string;\n}\n\n// Translation Render-Prop Component\nexport const Translation = ({\n children,\n ns,\n keyPrefix,\n}: TranslationProps): React.ReactElement => {\n const { t, i18n } = useTranslation(ns, { keyPrefix });\n return children(\n t as unknown as TFunction,\n { i18n: i18n as unknown as i18n, lng: i18n.language },\n true\n ) as React.ReactElement;\n};\n\n// nodesToString implementation\nexport const nodesToString = (\n children: React.ReactNode,\n _i18nOptions?: unknown,\n _i18n?: unknown,\n _i18nKey?: string\n): string => {\n if (typeof children === 'string' || typeof children === 'number') {\n return String(children);\n }\n if (!children) return '';\n if (Array.isArray(children)) {\n return children.map((c) => nodesToString(c)).join('');\n }\n const childElement = children as React.ReactElement<{\n children?: React.ReactNode;\n }>;\n\n if (childElement.props?.children) {\n return nodesToString(childElement.props.children);\n }\n\n return '';\n};\n\n// Global Instance Getters/Setters\nlet globalI18n: i18n | null = null;\nlet globalDefaults: unknown = {};\n\nexport const setI18n = (instance: i18n): void => {\n globalI18n = instance;\n};\n\nexport const getI18n = (): i18n => {\n return globalI18n as i18n;\n};\n\nexport const setDefaults = (options: unknown): void => {\n globalDefaults = options;\n};\n\nexport const getDefaults = (): unknown => {\n return globalDefaults;\n};\n\n// SSR Stubs\nexport const useSSR = (\n _initialI18nStore: unknown,\n _initialLanguage: string\n): void => {};\n\nexport const withSSR = () => {\n const Hoc = <P extends object>(\n WrappedComponent: React.ComponentType<P>\n ): React.ComponentType<P> => {\n const Component = (props: P) => <WrappedComponent {...props} />;\n const ExtendedComponent = Component as typeof Component & {\n getInitialProps: (ctx: unknown) => Promise<Record<string, unknown>>;\n };\n ExtendedComponent.getInitialProps = async (_ctx: unknown) => ({});\n return ExtendedComponent;\n };\n return Hoc;\n};\n\nexport const composeInitialProps =\n (_ForComponent: unknown) => async (_ctx: unknown) => ({});\n\nexport const getInitialProps = () => ({\n initialI18nStore: {},\n initialLanguage: 'en',\n});\n"],"mappings":";;;;;AAKA,MAAa,cAAc,MAAM,cAA8B,EAC7D,MAAM,MACP,CAAC;AAaF,MAAa,eAAe,EAC1B,UACA,IACA,gBAC0C;CAC1C,MAAM,EAAE,GAAG,SAAS,eAAe,IAAI,EAAE,WAAW,CAAC;AACrD,QAAO,SACL,GACA;EAAQ;EAAyB,KAAK,KAAK;EAAU,EACrD,KACD;;AAIH,MAAa,iBACX,UACA,cACA,OACA,aACW;AACX,KAAI,OAAO,aAAa,YAAY,OAAO,aAAa,SACtD,QAAO,OAAO,SAAS;AAEzB,KAAI,CAAC,SAAU,QAAO;AACtB,KAAI,MAAM,QAAQ,SAAS,CACzB,QAAO,SAAS,KAAK,MAAM,cAAc,EAAE,CAAC,CAAC,KAAK,GAAG;CAEvD,MAAM,eAAe;AAIrB,KAAI,aAAa,OAAO,SACtB,QAAO,cAAc,aAAa,MAAM,SAAS;AAGnD,QAAO;;AAIT,IAAI,aAA0B;AAC9B,IAAI,iBAA0B,EAAE;AAEhC,MAAa,WAAW,aAAyB;AAC/C,cAAa;;AAGf,MAAa,gBAAsB;AACjC,QAAO;;AAGT,MAAa,eAAe,YAA2B;AACrD,kBAAiB;;AAGnB,MAAa,oBAA6B;AACxC,QAAO;;AAIT,MAAa,UACX,mBACA,qBACS;AAEX,MAAa,gBAAgB;CAC3B,MAAM,OACJ,qBAC2B;EAC3B,MAAM,aAAa,UAAa,oBAAC,kBAAD,EAAkB,GAAI,OAAS;EAC/D,MAAM,oBAAoB;AAG1B,oBAAkB,kBAAkB,OAAO,UAAmB,EAAE;AAChE,SAAO;;AAET,QAAO;;AAGT,MAAa,uBACV,kBAA2B,OAAO,UAAmB,EAAE;AAE1D,MAAa,yBAAyB;CACpC,kBAAkB,EAAE;CACpB,iBAAiB;CAClB"}
@@ -0,0 +1,28 @@
1
+ import { useTranslation } from "./useTranslation.mjs";
2
+ import { withTranslation } from "./withTranslation.mjs";
3
+ import { Trans } from "./Trans.mjs";
4
+ import { useDictionaryDynamic } from "./useDictionaryDynamic.mjs";
5
+ import { I18nextProvider } from "./I18nextProvider.mjs";
6
+ import { I18nContext as I18nContext$1, Translation as Translation$1, composeInitialProps as composeInitialProps$1, getDefaults as getDefaults$1, getI18n as getI18n$1, getInitialProps as getInitialProps$1, nodesToString as nodesToString$1, setDefaults as setDefaults$1, setI18n as setI18n$1, useSSR as useSSR$1, withSSR as withSSR$1 } from "./helpers.mjs";
7
+ import { initReactI18next } from "./initReactI18next.mjs";
8
+ import { useDictionary } from "./useDictionary.mjs";
9
+
10
+ //#region src/index.ts
11
+ const nodesToString = nodesToString$1;
12
+ const setDefaults = setDefaults$1;
13
+ const getDefaults = getDefaults$1;
14
+ const setI18n = setI18n$1;
15
+ const getI18n = getI18n$1;
16
+ const composeInitialProps = composeInitialProps$1;
17
+ const getInitialProps = getInitialProps$1;
18
+ const useSSR = useSSR$1;
19
+ const withSSR = withSSR$1;
20
+ const Translation = Translation$1;
21
+ const I18nContext = I18nContext$1;
22
+ const TransWithoutContext = Trans;
23
+ const IcuTrans = Trans;
24
+ const IcuTransWithoutContext = Trans;
25
+
26
+ //#endregion
27
+ export { I18nContext, I18nextProvider, IcuTrans, IcuTransWithoutContext, Trans, TransWithoutContext, Translation, composeInitialProps, getDefaults, getI18n, getInitialProps, initReactI18next, nodesToString, setDefaults, setI18n, useDictionary, useDictionaryDynamic, useSSR, useTranslation, withSSR, withTranslation };
28
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":["nodesToStringImpl","setDefaultsImpl","getDefaultsImpl","setI18nImpl","getI18nImpl","composeInitialPropsImpl","getInitialPropsImpl","useSSRImpl","withSSRImpl","TranslationImpl","I18nContextImpl"],"sources":["../../src/index.ts"],"sourcesContent":["import type {\n composeInitialProps as _composeInitialProps,\n getDefaults as _getDefaults,\n getI18n as _getI18n,\n getInitialProps as _getInitialProps,\n I18nContext as _I18nContext,\n setDefaults as _setDefaults,\n setI18n as _setI18n,\n Trans as _Trans,\n Translation as _Translation,\n TransWithoutContext as _TransWithoutContext,\n useSSR as _useSSR,\n withSSR as _withSSR,\n} from 'react-i18next';\n\nimport {\n composeInitialProps as composeInitialPropsImpl,\n getDefaults as getDefaultsImpl,\n getI18n as getI18nImpl,\n getInitialProps as getInitialPropsImpl,\n I18nContext as I18nContextImpl,\n nodesToString as nodesToStringImpl,\n setDefaults as setDefaultsImpl,\n setI18n as setI18nImpl,\n Translation as TranslationImpl,\n useSSR as useSSRImpl,\n withSSR as withSSRImpl,\n} from './helpers';\n\nimport { Trans } from './Trans';\n\n// Re-export common types from react-i18next so consumers don't need both packages\nexport type {\n I18nextProviderProps,\n TransProps,\n UseTranslationOptions,\n UseTranslationResponse,\n WithTranslation,\n WithTranslationProps,\n} from 'react-i18next';\nexport { I18nextProvider } from './I18nextProvider';\nexport { initReactI18next } from './initReactI18next';\nexport { useDictionary } from './useDictionary';\nexport { useDictionaryDynamic } from './useDictionaryDynamic';\nexport { useTranslation } from './useTranslation';\nexport { withTranslation } from './withTranslation';\nexport { Trans };\n\n// Wrap and export all implementation functions.\n// `nodesToString` is not part of react-i18next's public type surface in all\n// supported versions, so the local implementation's inferred type is exposed.\nexport const nodesToString = nodesToStringImpl;\nexport const setDefaults = setDefaultsImpl as typeof _setDefaults;\nexport const getDefaults = getDefaultsImpl as typeof _getDefaults;\nexport const setI18n = setI18nImpl as typeof _setI18n;\nexport const getI18n = getI18nImpl as typeof _getI18n;\nexport const composeInitialProps =\n composeInitialPropsImpl as typeof _composeInitialProps;\nexport const getInitialProps = getInitialPropsImpl as typeof _getInitialProps;\nexport const useSSR = useSSRImpl as typeof _useSSR;\nexport const withSSR = withSSRImpl as typeof _withSSR;\nexport const Translation = TranslationImpl as typeof _Translation;\nexport const I18nContext = I18nContextImpl as typeof _I18nContext;\n\nexport const TransWithoutContext = Trans as typeof _TransWithoutContext;\n// `IcuTrans` / `IcuTransWithoutContext` are aliases for the standard `Trans`\n// component (they only differ by interpolation engine, which the compat shim\n// does not distinguish). They are typed against `Trans` for broad version\n// compatibility, since the dedicated ICU exports are not present in every\n// supported react-i18next release.\nexport const IcuTrans = Trans as typeof _Trans;\nexport const IcuTransWithoutContext = Trans as typeof _Trans;\n"],"mappings":";;;;;;;;;;AAmDA,MAAa,gBAAgBA;AAC7B,MAAa,cAAcC;AAC3B,MAAa,cAAcC;AAC3B,MAAa,UAAUC;AACvB,MAAa,UAAUC;AACvB,MAAa,sBACXC;AACF,MAAa,kBAAkBC;AAC/B,MAAa,SAASC;AACtB,MAAa,UAAUC;AACvB,MAAa,cAAcC;AAC3B,MAAa,cAAcC;AAE3B,MAAa,sBAAsB;AAMnC,MAAa,WAAW;AACxB,MAAa,yBAAyB"}
@@ -0,0 +1,23 @@
1
+ import { setDefaults, setI18n } from "./helpers.mjs";
2
+
3
+ //#region src/initReactI18next.ts
4
+ /**
5
+ * Drop-in for react-i18next's `initReactI18next` plugin.
6
+ *
7
+ * Implemented locally rather than re-exported from `react-i18next`: when the
8
+ * compat alias plugin is enabled, `react-i18next` resolves back to this package,
9
+ * so a re-export would be self-referential (resolving to `undefined`). The
10
+ * plugin records the i18n instance via the compat `setI18n`/`setDefaults`
11
+ * helpers; actual translation is served by Intlayer.
12
+ */
13
+ const initReactI18next = {
14
+ type: "3rdParty",
15
+ init: (instance) => {
16
+ setI18n(instance);
17
+ setDefaults({});
18
+ }
19
+ };
20
+
21
+ //#endregion
22
+ export { initReactI18next };
23
+ //# sourceMappingURL=initReactI18next.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"initReactI18next.mjs","names":[],"sources":["../../src/initReactI18next.ts"],"sourcesContent":["import type { initReactI18next as _initReactI18next } from 'react-i18next';\nimport { setDefaults, setI18n } from './helpers';\n\n/**\n * Drop-in for react-i18next's `initReactI18next` plugin.\n *\n * Implemented locally rather than re-exported from `react-i18next`: when the\n * compat alias plugin is enabled, `react-i18next` resolves back to this package,\n * so a re-export would be self-referential (resolving to `undefined`). The\n * plugin records the i18n instance via the compat `setI18n`/`setDefaults`\n * helpers; actual translation is served by Intlayer.\n */\nexport const initReactI18next: typeof _initReactI18next = {\n type: '3rdParty' as const,\n init: (instance) => {\n setI18n(instance as never);\n setDefaults({});\n },\n};\n"],"mappings":";;;;;;;;;;;;AAYA,MAAa,mBAA6C;CACxD,MAAM;CACN,OAAO,aAAa;AAClB,UAAQ,SAAkB;AAC1B,cAAY,EAAE,CAAC;;CAElB"}
@@ -0,0 +1,58 @@
1
+ import * as ANSIColors from "@intlayer/config/colors";
2
+ import { colorize, getAppLogger } from "@intlayer/config/logger";
3
+ import { join } from "node:path";
4
+ import { runOnce } from "@intlayer/chokidar/utils";
5
+ import { getConfiguration } from "@intlayer/config/node";
6
+ import { intlayer } from "vite-intlayer";
7
+
8
+ //#region src/plugin/index.ts
9
+ /**
10
+ * Caller configurations for `react-i18next`'s `useTranslation` hook.
11
+ *
12
+ * Tells the intlayer field-usage analyser how to extract the dictionary key
13
+ * (namespace) and consumed fields from `useTranslation` call sites, enabling
14
+ * accurate dictionary pruning for projects using `@intlayer/react-i18next`.
15
+ */
16
+ const REACT_I18NEXT_COMPAT_CALLERS = [{
17
+ callerName: "useTranslation",
18
+ importSources: ["react-i18next", "@intlayer/react-i18next"],
19
+ namespace: {
20
+ from: "argument",
21
+ index: 0
22
+ },
23
+ keyPrefix: {
24
+ from: "option",
25
+ argumentIndex: 1,
26
+ property: "keyPrefix"
27
+ },
28
+ translationFunction: "destructured-t"
29
+ }];
30
+ /**
31
+ * A Vite plugin for react-i18next compat that wraps vite-intlayer
32
+ * and configures resolve aliases for react-i18next and i18next.
33
+ */
34
+ const reactI18nextVitePlugin = (options) => {
35
+ const intlayerConfig = getConfiguration();
36
+ const appLogger = getAppLogger(intlayerConfig);
37
+ runOnce(join(intlayerConfig.system.baseDir, ".intlayer", "cache", "intlayer-issues-invitation.lock"), () => {
38
+ appLogger([colorize("Please report any issues you met on GitHub:", ANSIColors.GREY), colorize("https://github.com/aymericzip/intlayer/issues", ANSIColors.GREY_LIGHT)]);
39
+ }, { cacheTimeoutMs: 1e3 * 60 * 60 });
40
+ const basePlugins = intlayer({
41
+ ...options,
42
+ compatCallers: [...options?.compatCallers ?? [], ...REACT_I18NEXT_COMPAT_CALLERS]
43
+ });
44
+ const compatPlugin = {
45
+ name: "vite-react-i18next-compat-plugin",
46
+ config: () => {
47
+ return { resolve: { alias: {
48
+ "react-i18next": "@intlayer/react-i18next",
49
+ i18next: "@intlayer/i18next"
50
+ } } };
51
+ }
52
+ };
53
+ return [...Array.isArray(basePlugins) ? basePlugins : [basePlugins], compatPlugin];
54
+ };
55
+
56
+ //#endregion
57
+ export { reactI18nextVitePlugin as default, reactI18nextVitePlugin };
58
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../../src/plugin/index.ts"],"sourcesContent":["import { join } from 'node:path';\nimport { runOnce } from '@intlayer/chokidar/utils';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport { getConfiguration } from '@intlayer/config/node';\nimport type { PluginOption } from 'vite';\nimport { type CompatCallerConfig, intlayer } from 'vite-intlayer';\n\n/**\n * Caller configurations for `react-i18next`'s `useTranslation` hook.\n *\n * Tells the intlayer field-usage analyser how to extract the dictionary key\n * (namespace) and consumed fields from `useTranslation` call sites, enabling\n * accurate dictionary pruning for projects using `@intlayer/react-i18next`.\n */\nconst REACT_I18NEXT_COMPAT_CALLERS: CompatCallerConfig[] = [\n {\n callerName: 'useTranslation',\n importSources: ['react-i18next', '@intlayer/react-i18next'],\n namespace: { from: 'argument', index: 0 },\n keyPrefix: { from: 'option', argumentIndex: 1, property: 'keyPrefix' },\n translationFunction: 'destructured-t',\n },\n];\n\n/**\n * A Vite plugin for react-i18next compat that wraps vite-intlayer\n * and configures resolve aliases for react-i18next and i18next.\n */\nexport const reactI18nextVitePlugin = (\n options?: Parameters<typeof intlayer>[0]\n): PluginOption[] => {\n const intlayerConfig = getConfiguration();\n const appLogger = getAppLogger(intlayerConfig);\n\n runOnce(\n join(\n intlayerConfig.system.baseDir,\n '.intlayer',\n 'cache',\n 'intlayer-issues-invitation.lock'\n ),\n () => {\n appLogger([\n colorize(\n 'Please report any issues you met on GitHub:',\n ANSIColors.GREY\n ),\n colorize(\n 'https://github.com/aymericzip/intlayer/issues',\n ANSIColors.GREY_LIGHT\n ),\n ]);\n },\n {\n cacheTimeoutMs: 1000 * 60 * 60, // 1 hour\n }\n );\n\n const basePlugins = intlayer({\n ...options,\n compatCallers: [\n ...(options?.compatCallers ?? []),\n ...REACT_I18NEXT_COMPAT_CALLERS,\n ],\n });\n\n const compatPlugin: PluginOption = {\n name: 'vite-react-i18next-compat-plugin',\n config: () => {\n return {\n resolve: {\n alias: {\n 'react-i18next': '@intlayer/react-i18next',\n i18next: '@intlayer/i18next',\n },\n },\n };\n },\n };\n\n return [\n ...(Array.isArray(basePlugins) ? basePlugins : [basePlugins]),\n compatPlugin,\n ];\n};\n\nexport default reactI18nextVitePlugin;\n"],"mappings":";;;;;;;;;;;;;;;AAeA,MAAM,+BAAqD,CACzD;CACE,YAAY;CACZ,eAAe,CAAC,iBAAiB,0BAA0B;CAC3D,WAAW;EAAE,MAAM;EAAY,OAAO;EAAG;CACzC,WAAW;EAAE,MAAM;EAAU,eAAe;EAAG,UAAU;EAAa;CACtE,qBAAqB;CACtB,CACF;;;;;AAMD,MAAa,0BACX,YACmB;CACnB,MAAM,iBAAiB,kBAAkB;CACzC,MAAM,YAAY,aAAa,eAAe;AAE9C,SACE,KACE,eAAe,OAAO,SACtB,aACA,SACA,kCACD,QACK;AACJ,YAAU,CACR,SACE,+CACA,WAAW,KACZ,EACD,SACE,iDACA,WAAW,WACZ,CACF,CAAC;IAEJ,EACE,gBAAgB,MAAO,KAAK,IAC7B,CACF;CAED,MAAM,cAAc,SAAS;EAC3B,GAAG;EACH,eAAe,CACb,GAAI,SAAS,iBAAiB,EAAE,EAChC,GAAG,6BACJ;EACF,CAAC;CAEF,MAAM,eAA6B;EACjC,MAAM;EACN,cAAc;AACZ,UAAO,EACL,SAAS,EACP,OAAO;IACL,iBAAiB;IACjB,SAAS;IACV,EACF,EACF;;EAEJ;AAED,QAAO,CACL,GAAI,MAAM,QAAQ,YAAY,GAAG,cAAc,CAAC,YAAY,EAC5D,aACD"}
@@ -0,0 +1,62 @@
1
+ 'use client';
2
+
3
+ import { useMemo } from "react";
4
+ import { useDictionary as useDictionary$1, useLocale } from "react-intlayer";
5
+
6
+ //#region src/useDictionary.ts
7
+ const navigatePath = (objectValue, path) => {
8
+ if (!path) return objectValue;
9
+ let current = objectValue;
10
+ for (const part of path.split(".")) {
11
+ if (current === null || current === void 0 || typeof current !== "object") return;
12
+ current = current[part];
13
+ }
14
+ return current;
15
+ };
16
+ /**
17
+ * Dictionary-accepting variant of `useTranslation`.
18
+ *
19
+ * Used internally by the SWC optimization: instead of looking up the dictionary
20
+ * at runtime by key, the SWC plugin pre-imports the dictionary JSON at build time
21
+ * and passes it directly here. This enables tree-shaking of unused locale content.
22
+ *
23
+ * For a nested namespace (`useTranslation('about.counter')`), the SWC passes the
24
+ * key prefix (`'counter'`) as the second argument.
25
+ *
26
+ * @example (generated by SWC, not written manually)
27
+ * import _abc from '.intlayer/dictionaries/about.json' with { type: 'json' };
28
+ * const { t } = useDictionary(_abc);
29
+ */
30
+ const useDictionary = (dictionary, keyPrefix, options) => {
31
+ const content = useDictionary$1(dictionary);
32
+ const { locale, setLocale, availableLocales } = useLocale();
33
+ const i18n = useMemo(() => ({
34
+ language: locale,
35
+ languages: availableLocales ?? [],
36
+ changeLanguage: async (lng) => {
37
+ setLocale(lng);
38
+ },
39
+ isInitialized: true
40
+ }), [
41
+ locale,
42
+ availableLocales,
43
+ setLocale
44
+ ]);
45
+ const prefix = (typeof keyPrefix === "object" ? keyPrefix : options)?.keyPrefix ?? (typeof keyPrefix === "string" ? keyPrefix : void 0);
46
+ const t = (key, params) => {
47
+ const lookupKey = prefix ? `${prefix}.${String(key)}` : String(key);
48
+ const rawValue = navigatePath(content, lookupKey);
49
+ const str = String(rawValue ?? lookupKey);
50
+ if (!params) return str;
51
+ return str.replace(/\{\{(\w+)\}\}/g, (_, name) => params[name] != null ? String(params[name]) : `{{${name}}}`);
52
+ };
53
+ return {
54
+ t,
55
+ i18n,
56
+ ready: true
57
+ };
58
+ };
59
+
60
+ //#endregion
61
+ export { useDictionary };
62
+ //# sourceMappingURL=useDictionary.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDictionary.mjs","names":["useDictionaryBase"],"sources":["../../src/useDictionary.ts"],"sourcesContent":["'use client';\n\nimport type { ValidDotPathsFor } from '@intlayer/core/transpiler';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { useMemo } from 'react';\nimport type { UseTranslationOptions } from 'react-i18next';\nimport { useDictionary as useDictionaryBase, useLocale } from 'react-intlayer';\n\nconst navigatePath = (objectValue: unknown, path: string): unknown => {\n if (!path) return objectValue;\n let current: unknown = objectValue;\n for (const part of path.split('.')) {\n if (\n current === null ||\n current === undefined ||\n typeof current !== 'object'\n ) {\n return undefined;\n }\n current = (current as Record<string, unknown>)[part];\n }\n return current;\n};\n\n/**\n * Dictionary-accepting variant of `useTranslation`.\n *\n * Used internally by the SWC optimization: instead of looking up the dictionary\n * at runtime by key, the SWC plugin pre-imports the dictionary JSON at build time\n * and passes it directly here. This enables tree-shaking of unused locale content.\n *\n * For a nested namespace (`useTranslation('about.counter')`), the SWC passes the\n * key prefix (`'counter'`) as the second argument.\n *\n * @example (generated by SWC, not written manually)\n * import _abc from '.intlayer/dictionaries/about.json' with { type: 'json' };\n * const { t } = useDictionary(_abc);\n */\nexport const useDictionary = <T extends Dictionary>(\n dictionary: T,\n keyPrefix?: string | UseTranslationOptions<string>,\n options?: UseTranslationOptions<string>\n) => {\n const content = useDictionaryBase(dictionary);\n const { locale, setLocale, availableLocales } = useLocale();\n\n const i18n = useMemo(\n () => ({\n language: locale as string,\n languages: (availableLocales ?? []) as string[],\n changeLanguage: async (lng: string) => {\n setLocale(lng as LocalesValues);\n },\n isInitialized: true,\n }),\n [locale, availableLocales, setLocale]\n );\n\n const resolvedOptions = typeof keyPrefix === 'object' ? keyPrefix : options;\n const prefix =\n resolvedOptions?.keyPrefix ??\n (typeof keyPrefix === 'string' ? keyPrefix : undefined);\n\n const t = <P extends ValidDotPathsFor<any>>(\n key: P,\n params?: Record<string, unknown>\n ): string => {\n const lookupKey = prefix ? `${prefix}.${String(key)}` : String(key);\n const rawValue = navigatePath(content, lookupKey);\n const str = String(rawValue ?? lookupKey);\n\n if (!params) return str;\n\n return str.replace(/\\{\\{(\\w+)\\}\\}/g, (_, name) =>\n params[name] != null ? String(params[name]) : `{{${name}}}`\n );\n };\n\n return { t, i18n, ready: true };\n};\n"],"mappings":";;;;;;AASA,MAAM,gBAAgB,aAAsB,SAA0B;AACpE,KAAI,CAAC,KAAM,QAAO;CAClB,IAAI,UAAmB;AACvB,MAAK,MAAM,QAAQ,KAAK,MAAM,IAAI,EAAE;AAClC,MACE,YAAY,QACZ,YAAY,UACZ,OAAO,YAAY,SAEnB;AAEF,YAAW,QAAoC;;AAEjD,QAAO;;;;;;;;;;;;;;;;AAiBT,MAAa,iBACX,YACA,WACA,YACG;CACH,MAAM,UAAUA,gBAAkB,WAAW;CAC7C,MAAM,EAAE,QAAQ,WAAW,qBAAqB,WAAW;CAE3D,MAAM,OAAO,eACJ;EACL,UAAU;EACV,WAAY,oBAAoB,EAAE;EAClC,gBAAgB,OAAO,QAAgB;AACrC,aAAU,IAAqB;;EAEjC,eAAe;EAChB,GACD;EAAC;EAAQ;EAAkB;EAAU,CACtC;CAGD,MAAM,UADkB,OAAO,cAAc,WAAW,YAAY,UAEjD,cAChB,OAAO,cAAc,WAAW,YAAY;CAE/C,MAAM,KACJ,KACA,WACW;EACX,MAAM,YAAY,SAAS,GAAG,OAAO,GAAG,OAAO,IAAI,KAAK,OAAO,IAAI;EACnE,MAAM,WAAW,aAAa,SAAS,UAAU;EACjD,MAAM,MAAM,OAAO,YAAY,UAAU;AAEzC,MAAI,CAAC,OAAQ,QAAO;AAEpB,SAAO,IAAI,QAAQ,mBAAmB,GAAG,SACvC,OAAO,SAAS,OAAO,OAAO,OAAO,MAAM,GAAG,KAAK,KAAK,IACzD;;AAGH,QAAO;EAAE;EAAG;EAAM,OAAO;EAAM"}
@@ -0,0 +1,47 @@
1
+ 'use client';
2
+
3
+ import { useMemo } from "react";
4
+ import { useDictionaryDynamic as useDictionaryDynamic$1, useLocale } from "react-intlayer";
5
+
6
+ //#region src/useDictionaryDynamic.ts
7
+ /**
8
+ * Dynamic dictionary-accepting variant of `useTranslation`.
9
+ */
10
+ const useDictionaryDynamic = (dictionaryPromise, key, options) => {
11
+ const content = useDictionaryDynamic$1(dictionaryPromise, key);
12
+ const { locale, setLocale, availableLocales } = useLocale();
13
+ const i18n = useMemo(() => ({
14
+ language: locale,
15
+ languages: availableLocales ?? [],
16
+ changeLanguage: async (lng) => {
17
+ setLocale(lng);
18
+ },
19
+ isInitialized: true
20
+ }), [
21
+ locale,
22
+ availableLocales,
23
+ setLocale
24
+ ]);
25
+ const prefix = options?.keyPrefix;
26
+ const t = (lookup, params) => {
27
+ const lookupKey = prefix ? `${prefix}.${String(lookup)}` : String(lookup);
28
+ const parts = lookupKey.split(".");
29
+ let current = content;
30
+ for (const part of parts) {
31
+ if (current == null) break;
32
+ current = current[part];
33
+ }
34
+ const str = String(current ?? lookupKey);
35
+ if (!params) return str;
36
+ return str.replace(/\{\{(\w+)\}\}/g, (_, k) => params[k] != null ? String(params[k]) : `{{${k}}}`);
37
+ };
38
+ return {
39
+ t,
40
+ i18n,
41
+ ready: true
42
+ };
43
+ };
44
+
45
+ //#endregion
46
+ export { useDictionaryDynamic };
47
+ //# sourceMappingURL=useDictionaryDynamic.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDictionaryDynamic.mjs","names":["useDictionaryDynamicBase"],"sources":["../../src/useDictionaryDynamic.ts"],"sourcesContent":["'use client';\n\nimport type { ValidDotPathsFor } from '@intlayer/core/transpiler';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type { StrictModeLocaleMap } from '@intlayer/types/module_augmentation';\nimport { useMemo } from 'react';\nimport type { UseTranslationOptions } from 'react-i18next';\nimport {\n useDictionaryDynamic as useDictionaryDynamicBase,\n useLocale,\n} from 'react-intlayer';\n\n/**\n * Dynamic dictionary-accepting variant of `useTranslation`.\n */\nexport const useDictionaryDynamic = <\n const T extends Dictionary,\n const K extends string,\n>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n key: K,\n options?: UseTranslationOptions<string>\n) => {\n const content = useDictionaryDynamicBase<T, any>(\n dictionaryPromise,\n key as any\n );\n const { locale, setLocale, availableLocales } = useLocale();\n\n const i18n = useMemo(\n () => ({\n language: locale as string,\n languages: (availableLocales ?? []) as string[],\n changeLanguage: async (lng: string) => {\n setLocale(lng as any);\n },\n isInitialized: true,\n }),\n [locale, availableLocales, setLocale]\n );\n\n const prefix = options?.keyPrefix;\n\n const t = <P extends ValidDotPathsFor<any>>(\n lookup: P,\n params?: Record<string, unknown>\n ): string => {\n const lookupKey = prefix ? `${prefix}.${String(lookup)}` : String(lookup);\n const parts = lookupKey.split('.');\n let current: any = content;\n\n for (const part of parts) {\n if (current == null) break;\n current = current[part];\n }\n\n const str = String(current ?? lookupKey);\n\n if (!params) return str;\n\n return str.replace(/\\{\\{(\\w+)\\}\\}/g, (_, k) =>\n params[k] != null ? String(params[k]) : `{{${k}}}`\n );\n };\n\n return { t, i18n, ready: true };\n};\n"],"mappings":";;;;;;;;;AAeA,MAAa,wBAIX,mBACA,KACA,YACG;CACH,MAAM,UAAUA,uBACd,mBACA,IACD;CACD,MAAM,EAAE,QAAQ,WAAW,qBAAqB,WAAW;CAE3D,MAAM,OAAO,eACJ;EACL,UAAU;EACV,WAAY,oBAAoB,EAAE;EAClC,gBAAgB,OAAO,QAAgB;AACrC,aAAU,IAAW;;EAEvB,eAAe;EAChB,GACD;EAAC;EAAQ;EAAkB;EAAU,CACtC;CAED,MAAM,SAAS,SAAS;CAExB,MAAM,KACJ,QACA,WACW;EACX,MAAM,YAAY,SAAS,GAAG,OAAO,GAAG,OAAO,OAAO,KAAK,OAAO,OAAO;EACzE,MAAM,QAAQ,UAAU,MAAM,IAAI;EAClC,IAAI,UAAe;AAEnB,OAAK,MAAM,QAAQ,OAAO;AACxB,OAAI,WAAW,KAAM;AACrB,aAAU,QAAQ;;EAGpB,MAAM,MAAM,OAAO,WAAW,UAAU;AAExC,MAAI,CAAC,OAAQ,QAAO;AAEpB,SAAO,IAAI,QAAQ,mBAAmB,GAAG,MACvC,OAAO,MAAM,OAAO,OAAO,OAAO,GAAG,GAAG,KAAK,EAAE,IAChD;;AAGH,QAAO;EAAE;EAAG;EAAM,OAAO;EAAM"}
@@ -0,0 +1,107 @@
1
+ 'use client';
2
+
3
+ import { getHTMLTextDir } from "@intlayer/core/localization";
4
+ import { resolveMessage } from "@intlayer/core/messageFormat";
5
+ import { getInterpolationValues, resolveTranslation } from "@intlayer/i18next";
6
+ import { useMemo } from "react";
7
+ import { useLocale } from "react-intlayer";
8
+
9
+ //#region src/useTranslation.ts
10
+ /**
11
+ * Drop-in for react-i18next's `useTranslation`.
12
+ *
13
+ * Translation lookup goes through the shared i18next-dialect resolver:
14
+ * namespace prefixes (`ns:key`), the `ns` option, plural suffixes
15
+ * (`key_one`/`key_other` via `Intl.PluralRules`), context suffixes
16
+ * (`key_male`), `$t()` nesting, `defaultValue` and `{{var}}` interpolation
17
+ * are all supported.
18
+ *
19
+ * The returned `t()` is typed against the intlayer dictionary for namespace N:
20
+ * keys are autocompleted and dot-paths are validated at compile time.
21
+ *
22
+ * @example
23
+ * ```tsx
24
+ * const { t } = useTranslation('about');
25
+ * t('counter.label'); // ✓ typed; compile error if key doesn't exist
26
+ * t('items', { count: 3 }); // plural suffix resolution
27
+ * ```
28
+ */
29
+ const useTranslation = (ns, options) => {
30
+ const namespace = Array.isArray(ns) ? ns[0] ?? "translation" : ns ?? "translation";
31
+ const { locale, setLocale, availableLocales } = useLocale();
32
+ const keyPrefix = options?.keyPrefix;
33
+ /**
34
+ * @param key - A valid dot-notation path within the namespace N dictionary.
35
+ * @param optionsOrDefaultValue - i18next `t()` options (interpolation
36
+ * values, `count`, `context`, `ns`, `defaultValue`, …) or a default
37
+ * value string.
38
+ */
39
+ const translate = useMemo(() => {
40
+ const resolveSingleKey = (key, translateOptions) => resolveTranslation({
41
+ locale,
42
+ namespace,
43
+ key: keyPrefix ? `${keyPrefix}.${key}` : key,
44
+ options: translateOptions
45
+ });
46
+ return (key, optionsOrDefaultValue, extraOptions) => {
47
+ const translateOptions = typeof optionsOrDefaultValue === "string" ? {
48
+ defaultValue: optionsOrDefaultValue,
49
+ ...extraOptions
50
+ } : optionsOrDefaultValue ?? {};
51
+ const keys = Array.isArray(key) ? key : [key];
52
+ for (const candidateKey of keys) {
53
+ const resolved = resolveSingleKey(candidateKey, translateOptions);
54
+ if (resolved !== void 0) return resolved;
55
+ }
56
+ const defaultValue = translateOptions.defaultValue;
57
+ if (typeof defaultValue === "string") return resolveMessage(defaultValue, getInterpolationValues(translateOptions), locale, "i18next");
58
+ return keys[keys.length - 1];
59
+ };
60
+ }, [
61
+ locale,
62
+ namespace,
63
+ keyPrefix
64
+ ]);
65
+ return {
66
+ t: translate,
67
+ i18n: useMemo(() => ({
68
+ language: locale,
69
+ languages: availableLocales ?? [],
70
+ resolvedLanguage: locale,
71
+ isInitialized: true,
72
+ changeLanguage: async (newLanguage) => {
73
+ setLocale(newLanguage);
74
+ },
75
+ dir: (language) => {
76
+ return getHTMLTextDir(language ?? locale) === "rtl" ? "rtl" : "ltr";
77
+ },
78
+ exists: (key, existsOptions) => resolveTranslation({
79
+ locale,
80
+ namespace,
81
+ key,
82
+ options: existsOptions
83
+ }) !== void 0,
84
+ t: translate,
85
+ getFixedT: (language, fixedNamespace) => (key, fixedOptions) => {
86
+ const resolved = resolveTranslation({
87
+ locale: language ?? locale,
88
+ namespace: fixedNamespace ?? namespace,
89
+ key,
90
+ options: fixedOptions
91
+ });
92
+ return resolved !== void 0 ? resolved : key;
93
+ }
94
+ }), [
95
+ locale,
96
+ availableLocales,
97
+ setLocale,
98
+ namespace,
99
+ translate
100
+ ]),
101
+ ready: true
102
+ };
103
+ };
104
+
105
+ //#endregion
106
+ export { useTranslation };
107
+ //# sourceMappingURL=useTranslation.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTranslation.mjs","names":[],"sources":["../../src/useTranslation.ts"],"sourcesContent":["'use client';\n\nimport { getHTMLTextDir } from '@intlayer/core/localization';\nimport { resolveMessage } from '@intlayer/core/messageFormat';\nimport type { ValidDotPathsFor } from '@intlayer/core/transpiler';\nimport { getInterpolationValues, resolveTranslation } from '@intlayer/i18next';\nimport type {\n DictionaryKeys,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport type { TOptions } from 'i18next';\nimport { useMemo } from 'react';\nimport type { UseTranslationOptions } from 'react-i18next';\nimport { useLocale } from 'react-intlayer';\n\n/**\n * Drop-in for react-i18next's `useTranslation`.\n *\n * Translation lookup goes through the shared i18next-dialect resolver:\n * namespace prefixes (`ns:key`), the `ns` option, plural suffixes\n * (`key_one`/`key_other` via `Intl.PluralRules`), context suffixes\n * (`key_male`), `$t()` nesting, `defaultValue` and `{{var}}` interpolation\n * are all supported.\n *\n * The returned `t()` is typed against the intlayer dictionary for namespace N:\n * keys are autocompleted and dot-paths are validated at compile time.\n *\n * @example\n * ```tsx\n * const { t } = useTranslation('about');\n * t('counter.label'); // ✓ typed; compile error if key doesn't exist\n * t('items', { count: 3 }); // plural suffix resolution\n * ```\n */\nexport const useTranslation = <N extends DictionaryKeys>(\n ns?: N | N[],\n options?: UseTranslationOptions<string>\n) => {\n const namespace = (\n Array.isArray(ns) ? (ns[0] ?? 'translation') : (ns ?? 'translation')\n ) as N;\n\n const { locale, setLocale, availableLocales } = useLocale();\n\n const keyPrefix = options?.keyPrefix;\n\n /**\n * @param key - A valid dot-notation path within the namespace N dictionary.\n * @param optionsOrDefaultValue - i18next `t()` options (interpolation\n * values, `count`, `context`, `ns`, `defaultValue`, …) or a default\n * value string.\n */\n const translate = useMemo(() => {\n const resolveSingleKey = (\n key: string,\n translateOptions?: TOptions\n ): unknown =>\n resolveTranslation({\n locale: locale as LocalesValues,\n namespace,\n key: keyPrefix ? `${keyPrefix}.${key}` : key,\n options: translateOptions,\n });\n\n return (\n key: string | string[],\n optionsOrDefaultValue?: TOptions | string,\n extraOptions?: TOptions\n ): string => {\n const translateOptions: TOptions =\n typeof optionsOrDefaultValue === 'string'\n ? { defaultValue: optionsOrDefaultValue, ...extraOptions }\n : (optionsOrDefaultValue ?? {});\n\n const keys = Array.isArray(key) ? key : [key];\n\n for (const candidateKey of keys) {\n const resolved = resolveSingleKey(candidateKey, translateOptions);\n if (resolved !== undefined) return resolved as string;\n }\n\n const defaultValue = translateOptions.defaultValue;\n if (typeof defaultValue === 'string') {\n return resolveMessage(\n defaultValue,\n getInterpolationValues(translateOptions),\n locale as LocalesValues,\n 'i18next'\n );\n }\n\n return keys[keys.length - 1];\n };\n }, [locale, namespace, keyPrefix]);\n\n const i18n = useMemo(\n () => ({\n language: locale as string,\n languages: (availableLocales ?? []) as string[],\n resolvedLanguage: locale as string,\n isInitialized: true,\n changeLanguage: async (newLanguage: string) => {\n setLocale(newLanguage as LocalesValues);\n },\n dir: (language?: string): 'ltr' | 'rtl' => {\n const direction = getHTMLTextDir((language ?? locale) as LocalesValues);\n return direction === 'rtl' ? 'rtl' : 'ltr';\n },\n exists: (key: string, existsOptions?: TOptions): boolean =>\n resolveTranslation({\n locale: locale as LocalesValues,\n namespace,\n key,\n options: existsOptions,\n }) !== undefined,\n t: translate,\n getFixedT:\n (language?: string | null, fixedNamespace?: string | null) =>\n (key: string, fixedOptions?: TOptions): string => {\n const resolved = resolveTranslation({\n locale: (language ?? locale) as LocalesValues,\n namespace: fixedNamespace ?? namespace,\n key,\n options: fixedOptions,\n });\n return resolved !== undefined ? (resolved as string) : key;\n },\n }),\n [locale, availableLocales, setLocale, namespace, translate]\n );\n\n /** Typed facade over the untyped runtime translate function. */\n const t = translate as <P extends ValidDotPathsFor<N>>(\n key: P | P[],\n optionsOrDefaultValue?: TOptions | string,\n extraOptions?: TOptions\n ) => string;\n\n return { t, i18n, ready: true };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,MAAa,kBACX,IACA,YACG;CACH,MAAM,YACJ,MAAM,QAAQ,GAAG,GAAI,GAAG,MAAM,gBAAkB,MAAM;CAGxD,MAAM,EAAE,QAAQ,WAAW,qBAAqB,WAAW;CAE3D,MAAM,YAAY,SAAS;;;;;;;CAQ3B,MAAM,YAAY,cAAc;EAC9B,MAAM,oBACJ,KACA,qBAEA,mBAAmB;GACT;GACR;GACA,KAAK,YAAY,GAAG,UAAU,GAAG,QAAQ;GACzC,SAAS;GACV,CAAC;AAEJ,UACE,KACA,uBACA,iBACW;GACX,MAAM,mBACJ,OAAO,0BAA0B,WAC7B;IAAE,cAAc;IAAuB,GAAG;IAAc,GACvD,yBAAyB,EAAE;GAElC,MAAM,OAAO,MAAM,QAAQ,IAAI,GAAG,MAAM,CAAC,IAAI;AAE7C,QAAK,MAAM,gBAAgB,MAAM;IAC/B,MAAM,WAAW,iBAAiB,cAAc,iBAAiB;AACjE,QAAI,aAAa,OAAW,QAAO;;GAGrC,MAAM,eAAe,iBAAiB;AACtC,OAAI,OAAO,iBAAiB,SAC1B,QAAO,eACL,cACA,uBAAuB,iBAAiB,EACxC,QACA,UACD;AAGH,UAAO,KAAK,KAAK,SAAS;;IAE3B;EAAC;EAAQ;EAAW;EAAU,CAAC;AA6ClC,QAAO;EAAE;EAAG,MA3CC,eACJ;GACL,UAAU;GACV,WAAY,oBAAoB,EAAE;GAClC,kBAAkB;GAClB,eAAe;GACf,gBAAgB,OAAO,gBAAwB;AAC7C,cAAU,YAA6B;;GAEzC,MAAM,aAAqC;AAEzC,WADkB,eAAgB,YAAY,OAC9B,KAAK,QAAQ,QAAQ;;GAEvC,SAAS,KAAa,kBACpB,mBAAmB;IACT;IACR;IACA;IACA,SAAS;IACV,CAAC,KAAK;GACT,GAAG;GACH,YACG,UAA0B,oBAC1B,KAAa,iBAAoC;IAChD,MAAM,WAAW,mBAAmB;KAClC,QAAS,YAAY;KACrB,WAAW,kBAAkB;KAC7B;KACA,SAAS;KACV,CAAC;AACF,WAAO,aAAa,SAAa,WAAsB;;GAE5D,GACD;GAAC;GAAQ;GAAkB;GAAW;GAAW;GAAU,CAU7C;EAAE,OAAO;EAAM"}
@@ -0,0 +1,55 @@
1
+ 'use client';
2
+
3
+ import { useMemo } from "react";
4
+ import { useDictionary, useLocale } from "react-intlayer";
5
+
6
+ //#region src/useTranslationDictionary.ts
7
+ /**
8
+ * Dictionary-accepting variant of `useTranslation`.
9
+ *
10
+ * Used internally by the SWC optimization: instead of looking up the dictionary
11
+ * at runtime by key, the SWC plugin pre-imports the dictionary JSON at build time
12
+ * and passes it directly here. This enables tree-shaking of unused locale content.
13
+ *
14
+ * @example (generated by SWC, not written manually)
15
+ * import _abc from '.intlayer/dictionaries/about.json' with { type: 'json' };
16
+ * const { t } = useTranslationDictionary(_abc);
17
+ */
18
+ const useTranslationDictionary = (dictionary, keyPrefix, options) => {
19
+ const content = useDictionary(dictionary);
20
+ const { locale, setLocale, availableLocales } = useLocale();
21
+ const i18n = useMemo(() => ({
22
+ language: locale,
23
+ languages: availableLocales ?? [],
24
+ changeLanguage: async (lng) => {
25
+ setLocale(lng);
26
+ },
27
+ isInitialized: true
28
+ }), [
29
+ locale,
30
+ availableLocales,
31
+ setLocale
32
+ ]);
33
+ const prefix = options?.keyPrefix ?? keyPrefix;
34
+ const t = (key, params) => {
35
+ const lookupKey = prefix ? `${prefix}.${String(key)}` : String(key);
36
+ const parts = lookupKey.split(".");
37
+ let current = content;
38
+ for (const part of parts) {
39
+ if (current == null) break;
40
+ current = current[part];
41
+ }
42
+ const str = String(current ?? lookupKey);
43
+ if (!params) return str;
44
+ return str.replace(/\{\{(\w+)\}\}/g, (_, k) => params[k] != null ? String(params[k]) : `{{${k}}}`);
45
+ };
46
+ return {
47
+ t,
48
+ i18n,
49
+ ready: true
50
+ };
51
+ };
52
+
53
+ //#endregion
54
+ export { useTranslationDictionary };
55
+ //# sourceMappingURL=useTranslationDictionary.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTranslationDictionary.mjs","names":[],"sources":["../../src/useTranslationDictionary.ts"],"sourcesContent":["'use client';\n\nimport type { ValidDotPathsFor } from '@intlayer/core/transpiler';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type { UseTranslationOptions } from 'i18next';\nimport { useMemo } from 'react';\nimport { useDictionary, useLocale } from 'react-intlayer';\n\n/**\n * Dictionary-accepting variant of `useTranslation`.\n *\n * Used internally by the SWC optimization: instead of looking up the dictionary\n * at runtime by key, the SWC plugin pre-imports the dictionary JSON at build time\n * and passes it directly here. This enables tree-shaking of unused locale content.\n *\n * @example (generated by SWC, not written manually)\n * import _abc from '.intlayer/dictionaries/about.json' with { type: 'json' };\n * const { t } = useTranslationDictionary(_abc);\n */\nexport const useTranslationDictionary = <T extends Dictionary>(\n dictionary: T,\n keyPrefix?: string,\n options?: UseTranslationOptions<string>\n) => {\n // reuse useDictionary which handles locale + getDictionary\n const content = useDictionary(dictionary);\n const { locale, setLocale, availableLocales } = useLocale();\n\n const i18n = useMemo(\n () => ({\n language: locale as string,\n languages: (availableLocales ?? []) as string[],\n changeLanguage: async (lng: string) => {\n setLocale(lng as any);\n },\n isInitialized: true,\n }),\n [locale, availableLocales, setLocale]\n );\n\n const prefix = options?.keyPrefix ?? keyPrefix;\n\n const t = <P extends ValidDotPathsFor<any>>(\n key: P,\n params?: Record<string, unknown>\n ): string => {\n const lookupKey = prefix ? `${prefix}.${String(key)}` : String(key);\n const parts = lookupKey.split('.');\n let current: any = content;\n for (const part of parts) {\n if (current == null) break;\n current = current[part];\n }\n const str = String(current ?? lookupKey);\n if (!params) return str;\n return str.replace(/\\{\\{(\\w+)\\}\\}/g, (_, k) =>\n params[k] != null ? String(params[k]) : `{{${k}}}`\n );\n };\n\n return { t, i18n, ready: true };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;AAmBA,MAAa,4BACX,YACA,WACA,YACG;CAEH,MAAM,UAAU,cAAc,WAAW;CACzC,MAAM,EAAE,QAAQ,WAAW,qBAAqB,WAAW;CAE3D,MAAM,OAAO,eACJ;EACL,UAAU;EACV,WAAY,oBAAoB,EAAE;EAClC,gBAAgB,OAAO,QAAgB;AACrC,aAAU,IAAW;;EAEvB,eAAe;EAChB,GACD;EAAC;EAAQ;EAAkB;EAAU,CACtC;CAED,MAAM,SAAS,SAAS,aAAa;CAErC,MAAM,KACJ,KACA,WACW;EACX,MAAM,YAAY,SAAS,GAAG,OAAO,GAAG,OAAO,IAAI,KAAK,OAAO,IAAI;EACnE,MAAM,QAAQ,UAAU,MAAM,IAAI;EAClC,IAAI,UAAe;AACnB,OAAK,MAAM,QAAQ,OAAO;AACxB,OAAI,WAAW,KAAM;AACrB,aAAU,QAAQ;;EAEpB,MAAM,MAAM,OAAO,WAAW,UAAU;AACxC,MAAI,CAAC,OAAQ,QAAO;AACpB,SAAO,IAAI,QAAQ,mBAAmB,GAAG,MACvC,OAAO,MAAM,OAAO,OAAO,OAAO,GAAG,GAAG,KAAK,EAAE,IAChD;;AAGH,QAAO;EAAE;EAAG;EAAM,OAAO;EAAM"}
@@ -0,0 +1,47 @@
1
+ 'use client';
2
+
3
+ import { useMemo } from "react";
4
+ import { useDictionaryDynamic, useLocale } from "react-intlayer";
5
+
6
+ //#region src/useTranslationDictionaryDynamic.ts
7
+ /**
8
+ * Dynamic dictionary-accepting variant of `useTranslation`.
9
+ */
10
+ const useTranslationDictionaryDynamic = (dictionaryPromise, key, keyPrefix, options) => {
11
+ const content = useDictionaryDynamic(dictionaryPromise, key);
12
+ const { locale, setLocale, availableLocales } = useLocale();
13
+ const i18n = useMemo(() => ({
14
+ language: locale,
15
+ languages: availableLocales ?? [],
16
+ changeLanguage: async (lng) => {
17
+ setLocale(lng);
18
+ },
19
+ isInitialized: true
20
+ }), [
21
+ locale,
22
+ availableLocales,
23
+ setLocale
24
+ ]);
25
+ const prefix = options?.keyPrefix ?? keyPrefix;
26
+ const t = (lookup, params) => {
27
+ const lookupKey = prefix ? `${prefix}.${String(lookup)}` : String(lookup);
28
+ const parts = lookupKey.split(".");
29
+ let current = content;
30
+ for (const part of parts) {
31
+ if (current == null) break;
32
+ current = current[part];
33
+ }
34
+ const str = String(current ?? lookupKey);
35
+ if (!params) return str;
36
+ return str.replace(/\{\{(\w+)\}\}/g, (_, k) => params[k] != null ? String(params[k]) : `{{${k}}}`);
37
+ };
38
+ return {
39
+ t,
40
+ i18n,
41
+ ready: true
42
+ };
43
+ };
44
+
45
+ //#endregion
46
+ export { useTranslationDictionaryDynamic };
47
+ //# sourceMappingURL=useTranslationDictionaryDynamic.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTranslationDictionaryDynamic.mjs","names":[],"sources":["../../src/useTranslationDictionaryDynamic.ts"],"sourcesContent":["'use client';\n\nimport type { ValidDotPathsFor } from '@intlayer/core/transpiler';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type { StrictModeLocaleMap } from '@intlayer/types/module_augmentation';\nimport type { UseTranslationOptions } from 'i18next';\nimport { useMemo } from 'react';\nimport { useDictionaryDynamic, useLocale } from 'react-intlayer';\n\n/**\n * Dynamic dictionary-accepting variant of `useTranslation`.\n */\nexport const useTranslationDictionaryDynamic = <\n const T extends Dictionary,\n const K extends string,\n>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n key: K,\n keyPrefix?: string,\n options?: UseTranslationOptions<string>\n) => {\n const content = useDictionaryDynamic<T, any>(dictionaryPromise, key as any);\n const { locale, setLocale, availableLocales } = useLocale();\n\n const i18n = useMemo(\n () => ({\n language: locale as string,\n languages: (availableLocales ?? []) as string[],\n changeLanguage: async (lng: string) => {\n setLocale(lng as any);\n },\n isInitialized: true,\n }),\n [locale, availableLocales, setLocale]\n );\n\n const prefix = options?.keyPrefix ?? keyPrefix;\n\n const t = <P extends ValidDotPathsFor<any>>(\n lookup: P,\n params?: Record<string, unknown>\n ): string => {\n const lookupKey = prefix ? `${prefix}.${String(lookup)}` : String(lookup);\n const parts = lookupKey.split('.');\n let current: any = content;\n for (const part of parts) {\n if (current == null) break;\n current = current[part];\n }\n const str = String(current ?? lookupKey);\n if (!params) return str;\n return str.replace(/\\{\\{(\\w+)\\}\\}/g, (_, k) =>\n params[k] != null ? String(params[k]) : `{{${k}}}`\n );\n };\n\n return { t, i18n, ready: true };\n};\n"],"mappings":";;;;;;;;;AAYA,MAAa,mCAIX,mBACA,KACA,WACA,YACG;CACH,MAAM,UAAU,qBAA6B,mBAAmB,IAAW;CAC3E,MAAM,EAAE,QAAQ,WAAW,qBAAqB,WAAW;CAE3D,MAAM,OAAO,eACJ;EACL,UAAU;EACV,WAAY,oBAAoB,EAAE;EAClC,gBAAgB,OAAO,QAAgB;AACrC,aAAU,IAAW;;EAEvB,eAAe;EAChB,GACD;EAAC;EAAQ;EAAkB;EAAU,CACtC;CAED,MAAM,SAAS,SAAS,aAAa;CAErC,MAAM,KACJ,QACA,WACW;EACX,MAAM,YAAY,SAAS,GAAG,OAAO,GAAG,OAAO,OAAO,KAAK,OAAO,OAAO;EACzE,MAAM,QAAQ,UAAU,MAAM,IAAI;EAClC,IAAI,UAAe;AACnB,OAAK,MAAM,QAAQ,OAAO;AACxB,OAAI,WAAW,KAAM;AACrB,aAAU,QAAQ;;EAEpB,MAAM,MAAM,OAAO,WAAW,UAAU;AACxC,MAAI,CAAC,OAAQ,QAAO;AACpB,SAAO,IAAI,QAAQ,mBAAmB,GAAG,MACvC,OAAO,MAAM,OAAO,OAAO,OAAO,GAAG,GAAG,KAAK,EAAE,IAChD;;AAGH,QAAO;EAAE;EAAG;EAAM,OAAO;EAAM"}
@@ -0,0 +1,26 @@
1
+ 'use client';
2
+
3
+ import { useTranslation } from "./useTranslation.mjs";
4
+ import { jsx } from "react/jsx-runtime";
5
+
6
+ //#region src/withTranslation.tsx
7
+ /**
8
+ * Drop-in for react-i18next's `withTranslation` HOC.
9
+ */
10
+ const withTranslation = ((ns, options) => (WrappedComponent) => {
11
+ const WithTranslation = (props) => {
12
+ const { t, i18n } = useTranslation(ns, options);
13
+ return /* @__PURE__ */ jsx(WrappedComponent, {
14
+ ...props,
15
+ t,
16
+ i18n,
17
+ tReady: true
18
+ });
19
+ };
20
+ WithTranslation.displayName = `withTranslation(${WrappedComponent.displayName ?? WrappedComponent.name ?? "Component"})`;
21
+ return WithTranslation;
22
+ });
23
+
24
+ //#endregion
25
+ export { withTranslation };
26
+ //# sourceMappingURL=withTranslation.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"withTranslation.mjs","names":[],"sources":["../../src/withTranslation.tsx"],"sourcesContent":["'use client';\n\nimport type * as React from 'react';\nimport type {\n withTranslation as _withTranslation,\n UseTranslationOptions,\n} from 'react-i18next';\nimport { useTranslation } from './useTranslation';\n\n/**\n * Drop-in for react-i18next's `withTranslation` HOC.\n */\nexport const withTranslation: typeof _withTranslation = ((\n ns?: string | string[],\n options?: UseTranslationOptions<string>\n) =>\n <P extends { t: unknown; i18n: unknown; tReady: boolean }>(\n WrappedComponent: React.ComponentType<P>\n ) => {\n const WithTranslation = (props: Omit<P, 't' | 'i18n' | 'tReady'>) => {\n const { t, i18n } = useTranslation(ns, options);\n return (\n <WrappedComponent\n {...(props as unknown as P)}\n t={t}\n i18n={i18n}\n tReady\n />\n );\n };\n WithTranslation.displayName = `withTranslation(${\n WrappedComponent.displayName ?? WrappedComponent.name ?? 'Component'\n })`;\n return WithTranslation as unknown as React.ComponentType<\n Omit<P, 't' | 'i18n' | 'tReady'>\n >;\n }) as typeof _withTranslation;\n"],"mappings":";;;;;;;;;AAYA,MAAa,oBACX,IACA,aAGE,qBACG;CACH,MAAM,mBAAmB,UAA4C;EACnE,MAAM,EAAE,GAAG,SAAS,eAAe,IAAI,QAAQ;AAC/C,SACE,oBAAC,kBAAD;GACE,GAAK;GACF;GACG;GACN;GACA;;AAGN,iBAAgB,cAAc,mBAC5B,iBAAiB,eAAe,iBAAiB,QAAQ,YAC1D;AACD,QAAO"}
@@ -0,0 +1,13 @@
1
+ import { I18nextProvider as I18nextProvider$1 } from "react-i18next";
2
+
3
+ //#region src/I18nextProvider.d.ts
4
+ /**
5
+ * Drop-in for react-i18next's `I18nextProvider`.
6
+ * The `i18n` prop is accepted for API compatibility but has no effect —
7
+ * Intlayer uses its own instance. A development warning is emitted when
8
+ * the `i18n` prop is provided so consumers know to remove it.
9
+ */
10
+ declare const I18nextProvider: typeof I18nextProvider$1;
11
+ //#endregion
12
+ export { I18nextProvider };
13
+ //# sourceMappingURL=I18nextProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"I18nextProvider.d.ts","names":[],"sources":["../../src/I18nextProvider.tsx"],"mappings":";;;;;AAiBA;;;;cAAa,eAAA,SAAwB,iBAAA"}
@@ -0,0 +1,22 @@
1
+ import { Trans as Trans$1 } from "react-i18next";
2
+
3
+ //#region src/Trans.d.ts
4
+ /**
5
+ * Drop-in for react-i18next's `<Trans>`.
6
+ *
7
+ * Supports `values` interpolation, `count` plural resolution, `context`,
8
+ * `defaults` fallback, and component interpolation through the `components`
9
+ * prop (object or array form) or numbered tags mapped onto JSX children.
10
+ *
11
+ * @example
12
+ * ```tsx
13
+ * <Trans i18nKey="richText" components={{ bold: <strong /> }} />
14
+ * <Trans i18nKey="hello" count={2} values={{ name: 'John' }}>
15
+ * Hello <b>{'{{name}}'}</b>
16
+ * </Trans>
17
+ * ```
18
+ */
19
+ declare const Trans: typeof Trans$1;
20
+ //#endregion
21
+ export { Trans };
22
+ //# sourceMappingURL=Trans.d.ts.map