@intlayer/react-i18next 9.5.2 → 9.5.4-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.
- package/README.md +9 -9
- package/dist/esm/index.mjs +3 -3
- package/package.json +11 -10
- package/dist/cjs/I18nextProvider.cjs +0 -25
- package/dist/cjs/I18nextProvider.cjs.map +0 -1
- package/dist/cjs/Trans.cjs +0 -64
- package/dist/cjs/Trans.cjs.map +0 -1
- package/dist/cjs/_virtual/_rolldown/runtime.cjs +0 -29
- package/dist/cjs/helpers.cjs +0 -67
- package/dist/cjs/helpers.cjs.map +0 -1
- package/dist/cjs/index.cjs +0 -49
- package/dist/cjs/index.cjs.map +0 -1
- package/dist/cjs/initReactI18next.cjs +0 -24
- package/dist/cjs/initReactI18next.cjs.map +0 -1
- package/dist/cjs/plugin/index.cjs +0 -62
- package/dist/cjs/plugin/index.cjs.map +0 -1
- package/dist/cjs/useDictionary.cjs +0 -64
- package/dist/cjs/useDictionary.cjs.map +0 -1
- package/dist/cjs/useDictionaryDynamic.cjs +0 -49
- package/dist/cjs/useDictionaryDynamic.cjs.map +0 -1
- package/dist/cjs/useTranslation.cjs +0 -109
- package/dist/cjs/useTranslation.cjs.map +0 -1
- package/dist/cjs/useTranslationDictionary.cjs +0 -57
- package/dist/cjs/useTranslationDictionary.cjs.map +0 -1
- package/dist/cjs/useTranslationDictionaryDynamic.cjs +0 -49
- package/dist/cjs/useTranslationDictionaryDynamic.cjs.map +0 -1
- package/dist/cjs/withTranslation.cjs +0 -28
- package/dist/cjs/withTranslation.cjs.map +0 -1
- package/dist/esm/useTranslationDictionary.mjs +0 -55
- package/dist/esm/useTranslationDictionary.mjs.map +0 -1
- package/dist/esm/useTranslationDictionaryDynamic.mjs +0 -47
- package/dist/esm/useTranslationDictionaryDynamic.mjs.map +0 -1
- package/dist/types/useTranslationDictionary.d.ts +0 -29
- package/dist/types/useTranslationDictionary.d.ts.map +0 -1
- package/dist/types/useTranslationDictionaryDynamic.d.ts +0 -22
- package/dist/types/useTranslationDictionaryDynamic.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<p align="center">
|
|
2
2
|
<a href="https://intlayer.org" rel="">
|
|
3
|
-
<img src="https://raw.githubusercontent.com/aymericzip/intlayer/main/docs/assets/cover.
|
|
3
|
+
<img src="https://raw.githubusercontent.com/aymericzip/intlayer/main/docs/assets/cover.webp" width="60%" alt="Intlayer Logo" />
|
|
4
4
|
</a>
|
|
5
5
|
</p>
|
|
6
6
|
|
|
@@ -49,10 +49,10 @@ With **per-locale content files**, **TypeScript autocompletion**, **tree-shakabl
|
|
|
49
49
|
|
|
50
50
|
| Feature | Description |
|
|
51
51
|
| --------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
52
|
-
| <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/frameworks.
|
|
52
|
+
| <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/frameworks.webp?raw=true" alt="Feature" width="700"> | **Cross-Frameworks Support**<br><br>Intlayer is compatible with all major frameworks and libraries, including Next.js, React, Vite, Vue.js, Nuxt, Preact, Express, and more. |
|
|
53
53
|
| <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/javascript_content_management.jpg?raw=true" alt="Feature" width="700"> | **JavaScript-Powered Content Management**<br><br>Harness the flexibility of JavaScript to define and manage your content efficiently. <br><br> - [Content declaration](https://intlayer.org/doc/concept/content) |
|
|
54
54
|
| <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/per_locale_content_declaration_file.png?raw=true" alt="Feature" width="700"> | **Per-Locale Content Declaration File**<br><br>Speed up your development by declaring your content once, before auto generation.<br><br> - [Per-Locale Content Declaration File](https://intlayer.org/doc/concept/per-locale-file) |
|
|
55
|
-
| <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/compiler.
|
|
55
|
+
| <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/compiler.webp?raw=true" alt="Feature" width="700"> | **Compiler**<br><br>The Intlayer Compiler extract automatically the content from the components and generate the dictionary files.<br><br> - [Compiler](https://intlayer.org/doc/compiler) |
|
|
56
56
|
| <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/autocompletion.png?raw=true" alt="Feature" width="700"> | **Type-Safe Environment**<br><br>Leverage TypeScript to ensure your content definitions and code are error-free, while also benefiting from IDE autocompletion.<br><br> - [TypeScript configuration](https://intlayer.org/doc/environment/vite-and-react#configure-typescript) |
|
|
57
57
|
| <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/config_file.png?raw=true" alt="Feature" width="700"> | **Simplified Setup**<br><br>Get up and running quickly with minimal configuration. Adjust settings for internationalization, routing, AI, build, and content handling with ease. <br><br> - [Explore Next.js integration](https://intlayer.org/doc/environment/nextjs) |
|
|
58
58
|
| <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/content_retrieval.png?raw=true" alt="Feature" width="700"> | **Simplified Content Retrieval**<br><br>No need to call your `t` function for each piece of content. Retrieve all your content directly using a single hook.<br><br> - [React integration](https://intlayer.org/doc/environment/create-react-app) |
|
|
@@ -60,12 +60,12 @@ With **per-locale content files**, **TypeScript autocompletion**, **tree-shakabl
|
|
|
60
60
|
| <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/file_tree.png?raw=true" alt="Feature" width="700"> | **Organized Codebase**<br><br>Keep your codebase more organized: 1 component = 1 dictionary in the same folder. Translations close to their respective components, enhance maintainability and clarity. <br><br> - [How Intlayer works](https://intlayer.org/doc/concept/how-works-intlayer) |
|
|
61
61
|
| <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/url_routing.png?raw=true" alt="Feature" width="700"> | **Enhanced Routing**<br><br>Full support of app routing, adapting seamlessly to complex application structures, for Next.js, React, Vite, Vue.js, etc.<br><br> - [Explore Next.js integration](https://intlayer.org/doc/environment/nextjs) |
|
|
62
62
|
| <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/markdown.png?raw=true" alt="Feature" width="700"> | **Markdown Support**<br><br>Import and interpret, locale files and remote Markdown for multilingual content like privacy policies, documentation, etc. Interpret and make Markdown metadata accessible in your code.<br><br> - [Content files](https://intlayer.org/doc/concept/content/file) |
|
|
63
|
-
| <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/visual_editor.
|
|
64
|
-
| <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/bundle.
|
|
65
|
-
| <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/static_rendering.
|
|
63
|
+
| <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/visual_editor.webp?raw=true" alt="Feature" width="700"> | **Free Visual Editor & CMS**<br><br>A free visual editor and CMS are available for content writers, removing the need for a localization platform. Keep your content synchronized using Git, or externalize it totally or partially with the CMS.<br><br> - [Intlayer Editor](https://intlayer.org/doc/concept/editor) <br> - [Intlayer CMS](https://intlayer.org/doc/concept/cms) |
|
|
64
|
+
| <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/bundle.webp?raw=true" alt="Feature" width="700"> | **Tree-shakable Content**<br><br>Tree-shakable content, reducing the size of the final bundle. Loads content per component, excluding any unused content from your bundle. Supports lazy loading to enhance app loading efficiency. <br><br> - [App build optimization](https://intlayer.org/doc/concept/how-works-intlayer#app-build-optimization) |
|
|
65
|
+
| <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/static_rendering.webp?raw=true" alt="Feature" width="700"> | **Static Rendering**<br><br>Doesn't block Static Rendering. <br><br> - [Next.js integration](https://intlayer.org/doc/environment/nextjs) |
|
|
66
66
|
| <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/AI_translation.png?raw=true" alt="Feature" width="700"> | **AI-Powered Translation**<br><br>Transform your website into 231 languages with just one click using Intlayer's advanced AI-powered translation tools using your own AI provider / API key. <br><br> - [CI/CD integration](https://intlayer.org/doc/concept/ci-cd) <br> - [Intlayer CLI](https://intlayer.org/doc/concept/cli) <br> - [Auto fill](https://intlayer.org/doc/concept/auto-fill) |
|
|
67
67
|
| <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/mcp.png?raw=true" alt="Feature" width="700"> | **MCP Server Integration**<br><br>Provides an MCP (Model Context Protocol) server for IDE automation, enabling seamless content management and i18n workflows directly within your development environment. <br><br> - [MCP Server](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/mcp_server.md) |
|
|
68
|
-
| <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/vscode_extension.
|
|
68
|
+
| <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/vscode_extension.webp?raw=true" alt="Feature" width="700"> | **VSCode Extension**<br><br>Intlayer provides a VSCode extension to help you manage your content and translations, building your dictionaries, translating your content, and more. <br><br> - [VSCode Extension](https://intlayer.org/doc/vs-code-extension) |
|
|
69
69
|
| <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/interoperability.png?raw=true" alt="Feature" width="700"> | **Interoperability**<br><br>Allow interoperability with react-i18next, next-i18next, next-intl, react-intl, vue-i18n. <br><br> - [Intlayer and react-intl](https://intlayer.org/blog/intlayer-with-react-intl) <br> - [Intlayer and next-intl](https://intlayer.org/blog/intlayer-with-next-intl) <br> - [Intlayer and next-i18next](https://intlayer.org/blog/intlayer-with-next-i18next) <br> - [Intlayer and vue-i18n](https://intlayer.org/blog/intlayer-with-vue-i18n) <br> - [Intlayer compat adapters](https://intlayer.org/doc/compatibility) |
|
|
70
70
|
| <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/benchmark.png?raw=true" alt="Feature" width="700"> | **Performances & Benchmark**<br><br>Uses advanced tree-shaking and dynamic loading to boost performances and keep the solution as light as possible. <br><br> - [Performances & Benchmark](https://intlayer.org/doc/benchmark) |
|
|
71
71
|
|
|
@@ -262,7 +262,7 @@ Intlayer connects **developers**, **copywriters**, and **AI agents** in one work
|
|
|
262
262
|
- Feature flags
|
|
263
263
|
- Headless CMSs (e.g. Contentful, Strapi, Sanity)
|
|
264
264
|
|
|
265
|
-

|
|
266
266
|
|
|
267
267
|
## 🌐 Readme in other languages
|
|
268
268
|
|
|
@@ -328,4 +328,4 @@ Contribute on [GitHub](https://github.com/aymericzip/intlayer), [GitLab](https:/
|
|
|
328
328
|
|
|
329
329
|
If you like Intlayer, give us a ⭐ on GitHub. It helps others discover the project! [See why GitHub Stars matter](https://github.com/aymericzip/intlayer/blob/main/CONTRIBUTING.md#why-github-stars-matter-).
|
|
330
330
|
|
|
331
|
-
[](https://
|
|
331
|
+
[](https://star-history.com/#aymericzip/intlayer&Date)
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { useTranslation } from "./useTranslation.mjs";
|
|
2
|
-
import {
|
|
2
|
+
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";
|
|
3
3
|
import { Trans } from "./Trans.mjs";
|
|
4
|
-
import { useDictionaryDynamic } from "./useDictionaryDynamic.mjs";
|
|
5
4
|
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
5
|
import { initReactI18next } from "./initReactI18next.mjs";
|
|
8
6
|
import { useDictionary } from "./useDictionary.mjs";
|
|
7
|
+
import { useDictionaryDynamic } from "./useDictionaryDynamic.mjs";
|
|
8
|
+
import { withTranslation } from "./withTranslation.mjs";
|
|
9
9
|
|
|
10
10
|
//#region src/index.ts
|
|
11
11
|
const nodesToString = nodesToString$1;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intlayer/react-i18next",
|
|
3
|
-
"version": "9.5.
|
|
3
|
+
"version": "9.5.4-canary.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "react-i18next API adapter for intlayer — useTranslation, Trans, withTranslation, I18nextProvider backed by react-intlayer",
|
|
6
6
|
"keywords": [
|
|
@@ -70,19 +70,20 @@
|
|
|
70
70
|
"prepublish": "cp -f ../../README.md ./README.md",
|
|
71
71
|
"publish": "bun publish || true",
|
|
72
72
|
"publish:canary": "bun publish --access public --tag canary || true",
|
|
73
|
+
"publish:ci": "bun ../../scripts/publish-package.mjs",
|
|
73
74
|
"publish:latest": "bun publish --access public --tag latest || true",
|
|
74
75
|
"test": "bun --bun vitest run",
|
|
75
76
|
"test:watch": "bun --bun vitest",
|
|
76
77
|
"typecheck": "tsc --noEmit --project tsconfig.types.json"
|
|
77
78
|
},
|
|
78
79
|
"dependencies": {
|
|
79
|
-
"@intlayer/config": "9.5.
|
|
80
|
-
"@intlayer/core": "9.5.
|
|
81
|
-
"@intlayer/engine": "9.5.
|
|
82
|
-
"@intlayer/i18next": "9.5.
|
|
83
|
-
"@intlayer/types": "9.5.
|
|
84
|
-
"react-intlayer": "9.5.
|
|
85
|
-
"vite-intlayer": "9.5.
|
|
80
|
+
"@intlayer/config": "9.5.4-canary.0",
|
|
81
|
+
"@intlayer/core": "9.5.4-canary.0",
|
|
82
|
+
"@intlayer/engine": "9.5.4-canary.0",
|
|
83
|
+
"@intlayer/i18next": "9.5.4-canary.0",
|
|
84
|
+
"@intlayer/types": "9.5.4-canary.0",
|
|
85
|
+
"react-intlayer": "9.5.4-canary.0",
|
|
86
|
+
"vite-intlayer": "9.5.4-canary.0"
|
|
86
87
|
},
|
|
87
88
|
"devDependencies": {
|
|
88
89
|
"@types/node": "^22",
|
|
@@ -91,12 +92,12 @@
|
|
|
91
92
|
"@utils/ts-config-types": "1.0.4",
|
|
92
93
|
"@utils/tsdown-config": "1.0.4",
|
|
93
94
|
"i18next": "26.4.2",
|
|
94
|
-
"react-i18next": "17.0.
|
|
95
|
+
"react-i18next": "17.0.14",
|
|
95
96
|
"rimraf": "6.1.3",
|
|
96
97
|
"tsdown": "0.23.0",
|
|
97
98
|
"typescript": "7.0.2",
|
|
98
99
|
"vite": "8.3.0",
|
|
99
|
-
"vitest": "5.0.
|
|
100
|
+
"vitest": "5.0.1"
|
|
100
101
|
},
|
|
101
102
|
"peerDependencies": {
|
|
102
103
|
"i18next": ">=20.0.0",
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
5
|
-
let react_intlayer = require("react-intlayer");
|
|
6
|
-
let react_jsx_runtime = require("react/jsx-runtime");
|
|
7
|
-
let _intlayer_config_built = require("@intlayer/config/built");
|
|
8
|
-
let _intlayer_config_colors = require("@intlayer/config/colors");
|
|
9
|
-
let _intlayer_config_logger = require("@intlayer/config/logger");
|
|
10
|
-
|
|
11
|
-
//#region src/I18nextProvider.tsx
|
|
12
|
-
/**
|
|
13
|
-
* Drop-in for react-i18next's `I18nextProvider`.
|
|
14
|
-
* The `i18n` prop is accepted for API compatibility but has no effect —
|
|
15
|
-
* Intlayer uses its own instance. A development warning is emitted when
|
|
16
|
-
* the `i18n` prop is provided so consumers know to remove it.
|
|
17
|
-
*/
|
|
18
|
-
const I18nextProvider = ({ children, i18n: _i18n }) => {
|
|
19
|
-
if (process.env.NODE_ENV === "development" && _i18n !== void 0) (0, _intlayer_config_logger.getAppLogger)({ log: _intlayer_config_built.log })(`${(0, _intlayer_config_logger.colorize)("I18nextProvider", _intlayer_config_colors.CYAN)}: the \`i18n\` prop has no effect with intlayer. Intlayer manages its own i18n instance — you can safely remove the prop.`);
|
|
20
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_intlayer.IntlayerProvider, { children });
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
//#endregion
|
|
24
|
-
exports.I18nextProvider = I18nextProvider;
|
|
25
|
-
//# sourceMappingURL=I18nextProvider.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"I18nextProvider.cjs","names":["CYAN","IntlayerProvider"],"sources":["../../src/I18nextProvider.tsx"],"sourcesContent":["'use client';\n\nimport { log } from '@intlayer/config/built';\nimport { CYAN } from '@intlayer/config/colors';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport type {\n I18nextProvider as _I18nextProvider,\n I18nextProviderProps,\n} from 'react-i18next';\nimport { IntlayerProvider } from 'react-intlayer';\n\n/**\n * Drop-in for react-i18next's `I18nextProvider`.\n * The `i18n` prop is accepted for API compatibility but has no effect —\n * Intlayer uses its own instance. A development warning is emitted when\n * the `i18n` prop is provided so consumers know to remove it.\n */\nexport const I18nextProvider: typeof _I18nextProvider = ({\n children,\n i18n: _i18n,\n}: I18nextProviderProps) => {\n if (process.env.NODE_ENV === 'development' && _i18n !== undefined) {\n const appLogger = getAppLogger({ log });\n appLogger(\n `${colorize('I18nextProvider', CYAN)}: the \\`i18n\\` prop has no effect with intlayer. Intlayer manages its own i18n instance — you can safely remove the prop.`\n );\n }\n\n return <IntlayerProvider>{children}</IntlayerProvider>;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;AAiBA,MAAa,mBAA4C,EACvD,UACA,MAAM,YACoB;AAC1B,KAAI,QAAQ,IAAI,aAAa,iBAAiB,UAAU,OAEtD,2CAD+B,EAAE,iCAAK,CAC7B,CACP,yCAAY,mBAAmBA,6BAAK,CAAC,2HACtC;AAGH,QAAO,2CAACC,iCAAD,EAAmB,UAA4B"}
|
package/dist/cjs/Trans.cjs
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
5
|
-
const require_useTranslation = require('./useTranslation.cjs');
|
|
6
|
-
let _intlayer_core_messageFormat = require("@intlayer/core/messageFormat");
|
|
7
|
-
let react = require("react");
|
|
8
|
-
let react_jsx_runtime = require("react/jsx-runtime");
|
|
9
|
-
|
|
10
|
-
//#region src/Trans.tsx
|
|
11
|
-
/**
|
|
12
|
-
* Renders parsed message tokens to React nodes, mapping tags to the
|
|
13
|
-
* `components` prop (object or array form) or to the JSX children
|
|
14
|
-
* (numbered tags `<1>…</1>` index into the children, react-i18next style).
|
|
15
|
-
*/
|
|
16
|
-
const renderTokens = (tokens, components, childrenArray) => tokens.map((token, tokenIndex) => {
|
|
17
|
-
if (typeof token === "string") return token;
|
|
18
|
-
const renderedChildren = renderTokens(token.children, components, childrenArray);
|
|
19
|
-
const mappedComponent = Array.isArray(components) ? components[Number(token.tag)] : components[token.tag];
|
|
20
|
-
const fallbackChild = /^\d+$/.test(token.tag) ? childrenArray[Number(token.tag)] : void 0;
|
|
21
|
-
const elementToClone = mappedComponent ?? fallbackChild;
|
|
22
|
-
if ((0, react.isValidElement)(elementToClone)) return (0, react.cloneElement)(elementToClone, { key: tokenIndex }, ...renderedChildren.length ? renderedChildren : [elementToClone.props.children]);
|
|
23
|
-
if (/^[a-z][\w-]*$/.test(token.tag)) {
|
|
24
|
-
const NativeTag = token.tag;
|
|
25
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(NativeTag, { children: renderedChildren }, tokenIndex);
|
|
26
|
-
}
|
|
27
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.Fragment, { children: renderedChildren }, tokenIndex);
|
|
28
|
-
});
|
|
29
|
-
/**
|
|
30
|
-
* Drop-in for react-i18next's `<Trans>`.
|
|
31
|
-
*
|
|
32
|
-
* Supports `values` interpolation, `count` plural resolution, `context`,
|
|
33
|
-
* `defaults` fallback, and component interpolation through the `components`
|
|
34
|
-
* prop (object or array form) or numbered tags mapped onto JSX children.
|
|
35
|
-
*
|
|
36
|
-
* @example
|
|
37
|
-
* ```tsx
|
|
38
|
-
* <Trans i18nKey="richText" components={{ bold: <strong /> }} />
|
|
39
|
-
* <Trans i18nKey="hello" count={2} values={{ name: 'John' }}>
|
|
40
|
-
* Hello <b>{'{{name}}'}</b>
|
|
41
|
-
* </Trans>
|
|
42
|
-
* ```
|
|
43
|
-
*/
|
|
44
|
-
const Trans = function Trans({ i18nKey, ns, values, count, context, defaults, components, tOptions, children }) {
|
|
45
|
-
const { t } = require_useTranslation.useTranslation(Array.isArray(ns) ? ns[0] : ns);
|
|
46
|
-
const translateOptions = {
|
|
47
|
-
...tOptions ?? {},
|
|
48
|
-
...values ?? {}
|
|
49
|
-
};
|
|
50
|
-
if (count !== void 0) translateOptions.count = count;
|
|
51
|
-
if (context !== void 0) translateOptions.context = context;
|
|
52
|
-
if (typeof defaults === "string") translateOptions.defaultValue = defaults;
|
|
53
|
-
const message = i18nKey ? t(i18nKey, translateOptions) : defaults ?? "";
|
|
54
|
-
const resolvedMessage = typeof message === "string" && message !== i18nKey ? message : defaults ?? message;
|
|
55
|
-
if (typeof resolvedMessage !== "string") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: children ?? resolvedMessage });
|
|
56
|
-
const childrenArray = react.Children.toArray(children);
|
|
57
|
-
const tokens = (0, _intlayer_core_messageFormat.parseTaggedMessage)(resolvedMessage);
|
|
58
|
-
if (!tokens.some((token) => typeof token !== "string") && !components) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: resolvedMessage });
|
|
59
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: renderTokens(tokens, components ?? {}, childrenArray) });
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
//#endregion
|
|
63
|
-
exports.Trans = Trans;
|
|
64
|
-
//# sourceMappingURL=Trans.cjs.map
|
package/dist/cjs/Trans.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Trans.cjs","names":["Fragment","useTranslation","translateFunction","Children"],"sources":["../../src/Trans.tsx"],"sourcesContent":["'use client';\n\nimport {\n parseTaggedMessage,\n type TaggedMessageToken,\n} from '@intlayer/core/messageFormat';\nimport type { DictionaryKeys } from '@intlayer/types/module_augmentation';\nimport type { Namespace, TOptions } from 'i18next';\nimport {\n Children,\n cloneElement,\n Fragment,\n isValidElement,\n type ReactElement,\n type ReactNode,\n} from 'react';\nimport type { Trans as _Trans, TransProps } from 'react-i18next';\nimport { useTranslation } from './useTranslation';\n\n/**\n * Renders parsed message tokens to React nodes, mapping tags to the\n * `components` prop (object or array form) or to the JSX children\n * (numbered tags `<1>…</1>` index into the children, react-i18next style).\n */\nconst renderTokens = (\n tokens: TaggedMessageToken[],\n components: Record<string, ReactElement> | readonly ReactElement[],\n childrenArray: ReactNode[]\n): ReactNode[] =>\n tokens.map((token, tokenIndex) => {\n if (typeof token === 'string') return token;\n\n const renderedChildren = renderTokens(\n token.children,\n components,\n childrenArray\n );\n\n const mappedComponent = Array.isArray(components)\n ? components[Number(token.tag)]\n : (components as Record<string, ReactElement>)[token.tag];\n\n const fallbackChild = /^\\d+$/.test(token.tag)\n ? childrenArray[Number(token.tag)]\n : undefined;\n\n const elementToClone = mappedComponent ?? fallbackChild;\n\n if (isValidElement(elementToClone)) {\n return cloneElement(\n elementToClone as ReactElement<{ children?: ReactNode }>,\n { key: tokenIndex },\n ...(renderedChildren.length\n ? renderedChildren\n : [\n (elementToClone as ReactElement<{ children?: ReactNode }>).props\n .children,\n ])\n );\n }\n\n // Native HTML tag in the message without a mapping — render it as-is\n if (/^[a-z][\\w-]*$/.test(token.tag)) {\n const NativeTag = token.tag as keyof React.JSX.IntrinsicElements;\n return <NativeTag key={tokenIndex}>{renderedChildren}</NativeTag>;\n }\n\n // Unknown numbered tag — render its children unwrapped\n return <Fragment key={tokenIndex}>{renderedChildren}</Fragment>;\n });\n\n/**\n * Drop-in for react-i18next's `<Trans>`.\n *\n * Supports `values` interpolation, `count` plural resolution, `context`,\n * `defaults` fallback, and component interpolation through the `components`\n * prop (object or array form) or numbered tags mapped onto JSX children.\n *\n * @example\n * ```tsx\n * <Trans i18nKey=\"richText\" components={{ bold: <strong /> }} />\n * <Trans i18nKey=\"hello\" count={2} values={{ name: 'John' }}>\n * Hello <b>{'{{name}}'}</b>\n * </Trans>\n * ```\n */\nexport const Trans: typeof _Trans = function Trans<\n Key extends string = string,\n Ns extends Namespace = Namespace,\n>({\n i18nKey,\n ns,\n values,\n count,\n context,\n defaults,\n components,\n tOptions,\n children,\n}: TransProps<Key, Ns>): React.ReactElement {\n const { t } = useTranslation(\n (Array.isArray(ns) ? ns[0] : ns) as DictionaryKeys\n );\n\n const translateOptions: TOptions = {\n ...((tOptions ?? {}) as TOptions),\n ...((values ?? {}) as Record<string, unknown>),\n };\n if (count !== undefined) translateOptions.count = count;\n if (context !== undefined) translateOptions.context = context;\n if (typeof defaults === 'string') translateOptions.defaultValue = defaults;\n\n const translateFunction = t as unknown as (\n key: string,\n options?: TOptions\n ) => string;\n\n const message = i18nKey\n ? translateFunction(i18nKey as string, translateOptions)\n : (defaults ?? '');\n\n const resolvedMessage =\n typeof message === 'string' && message !== i18nKey\n ? message\n : (defaults ?? message);\n\n if (typeof resolvedMessage !== 'string') {\n return <>{children ?? resolvedMessage}</>;\n }\n\n const childrenArray = Children.toArray(children);\n\n const tokens = parseTaggedMessage(resolvedMessage);\n const hasTags = tokens.some((token) => typeof token !== 'string');\n\n if (!hasTags && !components) {\n return <>{resolvedMessage}</>;\n }\n\n return (\n <>\n {renderTokens(\n tokens,\n (components ?? {}) as Record<string, ReactElement>,\n childrenArray\n )}\n </>\n );\n} as typeof _Trans;\n"],"mappings":";;;;;;;;;;;;;;;AAwBA,MAAM,gBACJ,QACA,YACA,kBAEA,OAAO,KAAK,OAAO,eAAe;AAChC,KAAI,OAAO,UAAU,SAAU,QAAO;CAEtC,MAAM,mBAAmB,aACvB,MAAM,UACN,YACA,cACD;CAED,MAAM,kBAAkB,MAAM,QAAQ,WAAW,GAC7C,WAAW,OAAO,MAAM,IAAI,IAC3B,WAA4C,MAAM;CAEvD,MAAM,gBAAgB,QAAQ,KAAK,MAAM,IAAI,GACzC,cAAc,OAAO,MAAM,IAAI,IAC/B;CAEJ,MAAM,iBAAiB,mBAAmB;AAE1C,+BAAmB,eAAe,CAChC,gCACE,gBACA,EAAE,KAAK,YAAY,EACnB,GAAI,iBAAiB,SACjB,mBACA,CACG,eAA0D,MACxD,SACJ,CACN;AAIH,KAAI,gBAAgB,KAAK,MAAM,IAAI,EAAE;EACnC,MAAM,YAAY,MAAM;AACxB,SAAO,2CAAC,WAAD,YAA6B,kBAA6B,EAA1C,WAA0C;;AAInE,QAAO,2CAACA,gBAAD,YAA4B,kBAA4B,EAAzC,WAAyC;EAC/D;;;;;;;;;;;;;;;;AAiBJ,MAAa,QAAuB,SAAS,MAG3C,EACA,SACA,IACA,QACA,OACA,SACA,UACA,YACA,UACA,YAC0C;CAC1C,MAAM,EAAE,MAAMC,sCACX,MAAM,QAAQ,GAAG,GAAG,GAAG,KAAK,GAC9B;CAED,MAAM,mBAA6B;EACjC,GAAK,YAAY,EAAE;EACnB,GAAK,UAAU,EAAE;EAClB;AACD,KAAI,UAAU,OAAW,kBAAiB,QAAQ;AAClD,KAAI,YAAY,OAAW,kBAAiB,UAAU;AACtD,KAAI,OAAO,aAAa,SAAU,kBAAiB,eAAe;CAOlE,MAAM,UAAU,UACZC,EAAkB,SAAmB,iBAAiB,GACrD,YAAY;CAEjB,MAAM,kBACJ,OAAO,YAAY,YAAY,YAAY,UACvC,UACC,YAAY;AAEnB,KAAI,OAAO,oBAAoB,SAC7B,QAAO,mFAAG,YAAY,iBAAmB;CAG3C,MAAM,gBAAgBC,eAAS,QAAQ,SAAS;CAEhD,MAAM,8DAA4B,gBAAgB;AAGlD,KAAI,CAFY,OAAO,MAAM,UAAU,OAAO,UAAU,SAE5C,IAAI,CAAC,WACf,QAAO,mFAAG,iBAAmB;AAG/B,QACE,mFACG,aACC,QACC,cAAc,EAAE,EACjB,cACD,EACA"}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
//#region \0rolldown/runtime.js
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
-
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
-
key = keys[i];
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
13
|
-
__defProp(to, key, {
|
|
14
|
-
get: ((k) => from[k]).bind(null, key),
|
|
15
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return to;
|
|
21
|
-
};
|
|
22
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
23
|
-
value: mod,
|
|
24
|
-
enumerable: true
|
|
25
|
-
}) : target, mod));
|
|
26
|
-
|
|
27
|
-
//#endregion
|
|
28
|
-
|
|
29
|
-
exports.__toESM = __toESM;
|
package/dist/cjs/helpers.cjs
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
3
|
-
const require_useTranslation = require('./useTranslation.cjs');
|
|
4
|
-
let react = require("react");
|
|
5
|
-
react = require_runtime.__toESM(react);
|
|
6
|
-
let react_jsx_runtime = require("react/jsx-runtime");
|
|
7
|
-
|
|
8
|
-
//#region src/helpers.tsx
|
|
9
|
-
const I18nContext = react.createContext({ i18n: null });
|
|
10
|
-
const Translation = ({ children, ns, keyPrefix }) => {
|
|
11
|
-
const { t, i18n } = require_useTranslation.useTranslation(ns, { keyPrefix });
|
|
12
|
-
return children(t, {
|
|
13
|
-
i18n,
|
|
14
|
-
lng: i18n.language
|
|
15
|
-
}, true);
|
|
16
|
-
};
|
|
17
|
-
const nodesToString = (children, _i18nOptions, _i18n, _i18nKey) => {
|
|
18
|
-
if (typeof children === "string" || typeof children === "number") return String(children);
|
|
19
|
-
if (!children) return "";
|
|
20
|
-
if (Array.isArray(children)) return children.map((c) => nodesToString(c)).join("");
|
|
21
|
-
const childElement = children;
|
|
22
|
-
if (childElement.props?.children) return nodesToString(childElement.props.children);
|
|
23
|
-
return "";
|
|
24
|
-
};
|
|
25
|
-
let globalI18n = null;
|
|
26
|
-
let globalDefaults = {};
|
|
27
|
-
const setI18n = (instance) => {
|
|
28
|
-
globalI18n = instance;
|
|
29
|
-
};
|
|
30
|
-
const getI18n = () => {
|
|
31
|
-
return globalI18n;
|
|
32
|
-
};
|
|
33
|
-
const setDefaults = (options) => {
|
|
34
|
-
globalDefaults = options;
|
|
35
|
-
};
|
|
36
|
-
const getDefaults = () => {
|
|
37
|
-
return globalDefaults;
|
|
38
|
-
};
|
|
39
|
-
const useSSR = (_initialI18nStore, _initialLanguage) => {};
|
|
40
|
-
const withSSR = () => {
|
|
41
|
-
const Hoc = (WrappedComponent) => {
|
|
42
|
-
const Component = (props) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(WrappedComponent, { ...props });
|
|
43
|
-
const ExtendedComponent = Component;
|
|
44
|
-
ExtendedComponent.getInitialProps = async (_ctx) => ({});
|
|
45
|
-
return ExtendedComponent;
|
|
46
|
-
};
|
|
47
|
-
return Hoc;
|
|
48
|
-
};
|
|
49
|
-
const composeInitialProps = (_ForComponent) => async (_ctx) => ({});
|
|
50
|
-
const getInitialProps = () => ({
|
|
51
|
-
initialI18nStore: {},
|
|
52
|
-
initialLanguage: "en"
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
//#endregion
|
|
56
|
-
exports.I18nContext = I18nContext;
|
|
57
|
-
exports.Translation = Translation;
|
|
58
|
-
exports.composeInitialProps = composeInitialProps;
|
|
59
|
-
exports.getDefaults = getDefaults;
|
|
60
|
-
exports.getI18n = getI18n;
|
|
61
|
-
exports.getInitialProps = getInitialProps;
|
|
62
|
-
exports.nodesToString = nodesToString;
|
|
63
|
-
exports.setDefaults = setDefaults;
|
|
64
|
-
exports.setI18n = setI18n;
|
|
65
|
-
exports.useSSR = useSSR;
|
|
66
|
-
exports.withSSR = withSSR;
|
|
67
|
-
//# sourceMappingURL=helpers.cjs.map
|
package/dist/cjs/helpers.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.cjs","names":["React","useTranslation"],"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,cAAcA,MAAM,cAA8B,EAC7D,MAAM,MACP,CAAC;AAaF,MAAa,eAAe,EAC1B,UACA,IACA,gBAC0C;CAC1C,MAAM,EAAE,GAAG,SAASC,sCAAe,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,2CAAC,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"}
|
package/dist/cjs/index.cjs
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_useTranslation = require('./useTranslation.cjs');
|
|
3
|
-
const require_withTranslation = require('./withTranslation.cjs');
|
|
4
|
-
const require_Trans = require('./Trans.cjs');
|
|
5
|
-
const require_useDictionaryDynamic = require('./useDictionaryDynamic.cjs');
|
|
6
|
-
const require_I18nextProvider = require('./I18nextProvider.cjs');
|
|
7
|
-
const require_helpers = require('./helpers.cjs');
|
|
8
|
-
const require_initReactI18next = require('./initReactI18next.cjs');
|
|
9
|
-
const require_useDictionary = require('./useDictionary.cjs');
|
|
10
|
-
|
|
11
|
-
//#region src/index.ts
|
|
12
|
-
const nodesToString = require_helpers.nodesToString;
|
|
13
|
-
const setDefaults = require_helpers.setDefaults;
|
|
14
|
-
const getDefaults = require_helpers.getDefaults;
|
|
15
|
-
const setI18n = require_helpers.setI18n;
|
|
16
|
-
const getI18n = require_helpers.getI18n;
|
|
17
|
-
const composeInitialProps = require_helpers.composeInitialProps;
|
|
18
|
-
const getInitialProps = require_helpers.getInitialProps;
|
|
19
|
-
const useSSR = require_helpers.useSSR;
|
|
20
|
-
const withSSR = require_helpers.withSSR;
|
|
21
|
-
const Translation = require_helpers.Translation;
|
|
22
|
-
const I18nContext = require_helpers.I18nContext;
|
|
23
|
-
const TransWithoutContext = require_Trans.Trans;
|
|
24
|
-
const IcuTrans = require_Trans.Trans;
|
|
25
|
-
const IcuTransWithoutContext = require_Trans.Trans;
|
|
26
|
-
|
|
27
|
-
//#endregion
|
|
28
|
-
exports.I18nContext = I18nContext;
|
|
29
|
-
exports.I18nextProvider = require_I18nextProvider.I18nextProvider;
|
|
30
|
-
exports.IcuTrans = IcuTrans;
|
|
31
|
-
exports.IcuTransWithoutContext = IcuTransWithoutContext;
|
|
32
|
-
exports.Trans = require_Trans.Trans;
|
|
33
|
-
exports.TransWithoutContext = TransWithoutContext;
|
|
34
|
-
exports.Translation = Translation;
|
|
35
|
-
exports.composeInitialProps = composeInitialProps;
|
|
36
|
-
exports.getDefaults = getDefaults;
|
|
37
|
-
exports.getI18n = getI18n;
|
|
38
|
-
exports.getInitialProps = getInitialProps;
|
|
39
|
-
exports.initReactI18next = require_initReactI18next.initReactI18next;
|
|
40
|
-
exports.nodesToString = nodesToString;
|
|
41
|
-
exports.setDefaults = setDefaults;
|
|
42
|
-
exports.setI18n = setI18n;
|
|
43
|
-
exports.useDictionary = require_useDictionary.useDictionary;
|
|
44
|
-
exports.useDictionaryDynamic = require_useDictionaryDynamic.useDictionaryDynamic;
|
|
45
|
-
exports.useSSR = useSSR;
|
|
46
|
-
exports.useTranslation = require_useTranslation.useTranslation;
|
|
47
|
-
exports.withSSR = withSSR;
|
|
48
|
-
exports.withTranslation = require_withTranslation.withTranslation;
|
|
49
|
-
//# sourceMappingURL=index.cjs.map
|
package/dist/cjs/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["nodesToStringImpl","setDefaultsImpl","getDefaultsImpl","setI18nImpl","getI18nImpl","composeInitialPropsImpl","getInitialPropsImpl","useSSRImpl","withSSRImpl","TranslationImpl","I18nContextImpl","Trans"],"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,sBAAsBC;AAMnC,MAAa,WAAWA;AACxB,MAAa,yBAAyBA"}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_helpers = require('./helpers.cjs');
|
|
3
|
-
|
|
4
|
-
//#region src/initReactI18next.ts
|
|
5
|
-
/**
|
|
6
|
-
* Drop-in for react-i18next's `initReactI18next` plugin.
|
|
7
|
-
*
|
|
8
|
-
* Implemented locally rather than re-exported from `react-i18next`: when the
|
|
9
|
-
* compat alias plugin is enabled, `react-i18next` resolves back to this package,
|
|
10
|
-
* so a re-export would be self-referential (resolving to `undefined`). The
|
|
11
|
-
* plugin records the i18n instance via the compat `setI18n`/`setDefaults`
|
|
12
|
-
* helpers; actual translation is served by Intlayer.
|
|
13
|
-
*/
|
|
14
|
-
const initReactI18next = {
|
|
15
|
-
type: "3rdParty",
|
|
16
|
-
init: (instance) => {
|
|
17
|
-
require_helpers.setI18n(instance);
|
|
18
|
-
require_helpers.setDefaults({});
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
//#endregion
|
|
23
|
-
exports.initReactI18next = initReactI18next;
|
|
24
|
-
//# sourceMappingURL=initReactI18next.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"initReactI18next.cjs","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,0BAAQ,SAAkB;AAC1B,8BAAY,EAAE,CAAC;;CAElB"}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
2
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
|
-
let _intlayer_config_colors = require("@intlayer/config/colors");
|
|
4
|
-
_intlayer_config_colors = require_runtime.__toESM(_intlayer_config_colors);
|
|
5
|
-
let _intlayer_config_logger = require("@intlayer/config/logger");
|
|
6
|
-
let node_path = require("node:path");
|
|
7
|
-
let _intlayer_chokidar_utils = require("@intlayer/chokidar/utils");
|
|
8
|
-
let _intlayer_config_node = require("@intlayer/config/node");
|
|
9
|
-
let vite_intlayer = require("vite-intlayer");
|
|
10
|
-
|
|
11
|
-
//#region src/plugin/index.ts
|
|
12
|
-
/**
|
|
13
|
-
* Caller configurations for `react-i18next`'s `useTranslation` hook.
|
|
14
|
-
*
|
|
15
|
-
* Tells the intlayer field-usage analyser how to extract the dictionary key
|
|
16
|
-
* (namespace) and consumed fields from `useTranslation` call sites, enabling
|
|
17
|
-
* accurate dictionary pruning for projects using `@intlayer/react-i18next`.
|
|
18
|
-
*/
|
|
19
|
-
const REACT_I18NEXT_COMPAT_CALLERS = [{
|
|
20
|
-
callerName: "useTranslation",
|
|
21
|
-
importSources: ["react-i18next", "@intlayer/react-i18next"],
|
|
22
|
-
namespace: {
|
|
23
|
-
from: "argument",
|
|
24
|
-
index: 0
|
|
25
|
-
},
|
|
26
|
-
keyPrefix: {
|
|
27
|
-
from: "option",
|
|
28
|
-
argumentIndex: 1,
|
|
29
|
-
property: "keyPrefix"
|
|
30
|
-
},
|
|
31
|
-
translationFunction: "destructured-t"
|
|
32
|
-
}];
|
|
33
|
-
/**
|
|
34
|
-
* A Vite plugin for react-i18next compat that wraps vite-intlayer
|
|
35
|
-
* and configures resolve aliases for react-i18next and i18next.
|
|
36
|
-
*/
|
|
37
|
-
const reactI18nextVitePlugin = (options) => {
|
|
38
|
-
const intlayerConfig = (0, _intlayer_config_node.getConfiguration)();
|
|
39
|
-
const appLogger = (0, _intlayer_config_logger.getAppLogger)(intlayerConfig);
|
|
40
|
-
(0, _intlayer_chokidar_utils.runOnce)((0, node_path.join)(intlayerConfig.system.baseDir, ".intlayer", "cache", "intlayer-issues-invitation.lock"), () => {
|
|
41
|
-
appLogger([(0, _intlayer_config_logger.colorize)("Please report any issues you met on GitHub:", _intlayer_config_colors.GREY), (0, _intlayer_config_logger.colorize)("https://github.com/aymericzip/intlayer/issues", _intlayer_config_colors.GREY_LIGHT)]);
|
|
42
|
-
}, { cacheTimeoutMs: 1e3 * 60 * 60 });
|
|
43
|
-
const basePlugins = (0, vite_intlayer.intlayer)({
|
|
44
|
-
...options,
|
|
45
|
-
compatCallers: [...options?.compatCallers ?? [], ...REACT_I18NEXT_COMPAT_CALLERS]
|
|
46
|
-
});
|
|
47
|
-
const compatPlugin = {
|
|
48
|
-
name: "vite-react-i18next-compat-plugin",
|
|
49
|
-
config: () => {
|
|
50
|
-
return { resolve: { alias: {
|
|
51
|
-
"react-i18next": "@intlayer/react-i18next",
|
|
52
|
-
i18next: "@intlayer/i18next"
|
|
53
|
-
} } };
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
return [...Array.isArray(basePlugins) ? basePlugins : [basePlugins], compatPlugin];
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
//#endregion
|
|
60
|
-
exports.default = reactI18nextVitePlugin;
|
|
61
|
-
exports.reactI18nextVitePlugin = reactI18nextVitePlugin;
|
|
62
|
-
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["ANSIColors"],"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,8DAAmC;CACzC,MAAM,sDAAyB,eAAe;AAE9C,2DAEI,eAAe,OAAO,SACtB,aACA,SACA,kCACD,QACK;AACJ,YAAU,uCAEN,+CACAA,wBAAW,KACZ,wCAEC,iDACAA,wBAAW,WACZ,CACF,CAAC;IAEJ,EACE,gBAAgB,MAAO,KAAK,IAC7B,CACF;CAED,MAAM,0CAAuB;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"}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
5
|
-
let react = require("react");
|
|
6
|
-
let react_intlayer = require("react-intlayer");
|
|
7
|
-
|
|
8
|
-
//#region src/useDictionary.ts
|
|
9
|
-
const navigatePath = (objectValue, path) => {
|
|
10
|
-
if (!path) return objectValue;
|
|
11
|
-
let current = objectValue;
|
|
12
|
-
for (const part of path.split(".")) {
|
|
13
|
-
if (current === null || current === void 0 || typeof current !== "object") return;
|
|
14
|
-
current = current[part];
|
|
15
|
-
}
|
|
16
|
-
return current;
|
|
17
|
-
};
|
|
18
|
-
/**
|
|
19
|
-
* Dictionary-accepting variant of `useTranslation`.
|
|
20
|
-
*
|
|
21
|
-
* Used internally by the SWC optimization: instead of looking up the dictionary
|
|
22
|
-
* at runtime by key, the SWC plugin pre-imports the dictionary JSON at build time
|
|
23
|
-
* and passes it directly here. This enables tree-shaking of unused locale content.
|
|
24
|
-
*
|
|
25
|
-
* For a nested namespace (`useTranslation('about.counter')`), the SWC passes the
|
|
26
|
-
* key prefix (`'counter'`) as the second argument.
|
|
27
|
-
*
|
|
28
|
-
* @example (generated by SWC, not written manually)
|
|
29
|
-
* import _abc from '.intlayer/dictionaries/about.json' with { type: 'json' };
|
|
30
|
-
* const { t } = useDictionary(_abc);
|
|
31
|
-
*/
|
|
32
|
-
const useDictionary = (dictionary, keyPrefix, options) => {
|
|
33
|
-
const content = (0, react_intlayer.useDictionary)(dictionary);
|
|
34
|
-
const { locale, setLocale, availableLocales } = (0, react_intlayer.useLocale)();
|
|
35
|
-
const i18n = (0, react.useMemo)(() => ({
|
|
36
|
-
language: locale,
|
|
37
|
-
languages: availableLocales ?? [],
|
|
38
|
-
changeLanguage: async (lng) => {
|
|
39
|
-
setLocale(lng);
|
|
40
|
-
},
|
|
41
|
-
isInitialized: true
|
|
42
|
-
}), [
|
|
43
|
-
locale,
|
|
44
|
-
availableLocales,
|
|
45
|
-
setLocale
|
|
46
|
-
]);
|
|
47
|
-
const prefix = (typeof keyPrefix === "object" ? keyPrefix : options)?.keyPrefix ?? (typeof keyPrefix === "string" ? keyPrefix : void 0);
|
|
48
|
-
const t = (key, params) => {
|
|
49
|
-
const lookupKey = prefix ? `${prefix}.${String(key)}` : String(key);
|
|
50
|
-
const rawValue = navigatePath(content, lookupKey);
|
|
51
|
-
const str = String(rawValue ?? lookupKey);
|
|
52
|
-
if (!params) return str;
|
|
53
|
-
return str.replace(/\{\{(\w+)\}\}/g, (_, name) => params[name] != null ? String(params[name]) : `{{${name}}}`);
|
|
54
|
-
};
|
|
55
|
-
return {
|
|
56
|
-
t,
|
|
57
|
-
i18n,
|
|
58
|
-
ready: true
|
|
59
|
-
};
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
//#endregion
|
|
63
|
-
exports.useDictionary = useDictionary;
|
|
64
|
-
//# sourceMappingURL=useDictionary.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionary.cjs","names":[],"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,4CAA4B,WAAW;CAC7C,MAAM,EAAE,QAAQ,WAAW,oDAAgC;CAE3D,MAAM,iCACG;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"}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
5
|
-
let react = require("react");
|
|
6
|
-
let react_intlayer = require("react-intlayer");
|
|
7
|
-
|
|
8
|
-
//#region src/useDictionaryDynamic.ts
|
|
9
|
-
/**
|
|
10
|
-
* Dynamic dictionary-accepting variant of `useTranslation`.
|
|
11
|
-
*/
|
|
12
|
-
const useDictionaryDynamic = (dictionaryPromise, key, options) => {
|
|
13
|
-
const content = (0, react_intlayer.useDictionaryDynamic)(dictionaryPromise, key);
|
|
14
|
-
const { locale, setLocale, availableLocales } = (0, react_intlayer.useLocale)();
|
|
15
|
-
const i18n = (0, react.useMemo)(() => ({
|
|
16
|
-
language: locale,
|
|
17
|
-
languages: availableLocales ?? [],
|
|
18
|
-
changeLanguage: async (lng) => {
|
|
19
|
-
setLocale(lng);
|
|
20
|
-
},
|
|
21
|
-
isInitialized: true
|
|
22
|
-
}), [
|
|
23
|
-
locale,
|
|
24
|
-
availableLocales,
|
|
25
|
-
setLocale
|
|
26
|
-
]);
|
|
27
|
-
const prefix = options?.keyPrefix;
|
|
28
|
-
const t = (lookup, params) => {
|
|
29
|
-
const lookupKey = prefix ? `${prefix}.${String(lookup)}` : String(lookup);
|
|
30
|
-
const parts = lookupKey.split(".");
|
|
31
|
-
let current = content;
|
|
32
|
-
for (const part of parts) {
|
|
33
|
-
if (current == null) break;
|
|
34
|
-
current = current[part];
|
|
35
|
-
}
|
|
36
|
-
const str = String(current ?? lookupKey);
|
|
37
|
-
if (!params) return str;
|
|
38
|
-
return str.replace(/\{\{(\w+)\}\}/g, (_, k) => params[k] != null ? String(params[k]) : `{{${k}}}`);
|
|
39
|
-
};
|
|
40
|
-
return {
|
|
41
|
-
t,
|
|
42
|
-
i18n,
|
|
43
|
-
ready: true
|
|
44
|
-
};
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
//#endregion
|
|
48
|
-
exports.useDictionaryDynamic = useDictionaryDynamic;
|
|
49
|
-
//# sourceMappingURL=useDictionaryDynamic.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionaryDynamic.cjs","names":[],"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,mDACJ,mBACA,IACD;CACD,MAAM,EAAE,QAAQ,WAAW,oDAAgC;CAE3D,MAAM,iCACG;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"}
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
5
|
-
let _intlayer_core_localization = require("@intlayer/core/localization");
|
|
6
|
-
let _intlayer_core_messageFormat = require("@intlayer/core/messageFormat");
|
|
7
|
-
let _intlayer_i18next = require("@intlayer/i18next");
|
|
8
|
-
let react = require("react");
|
|
9
|
-
let react_intlayer = require("react-intlayer");
|
|
10
|
-
|
|
11
|
-
//#region src/useTranslation.ts
|
|
12
|
-
/**
|
|
13
|
-
* Drop-in for react-i18next's `useTranslation`.
|
|
14
|
-
*
|
|
15
|
-
* Translation lookup goes through the shared i18next-dialect resolver:
|
|
16
|
-
* namespace prefixes (`ns:key`), the `ns` option, plural suffixes
|
|
17
|
-
* (`key_one`/`key_other` via `Intl.PluralRules`), context suffixes
|
|
18
|
-
* (`key_male`), `$t()` nesting, `defaultValue` and `{{var}}` interpolation
|
|
19
|
-
* are all supported.
|
|
20
|
-
*
|
|
21
|
-
* The returned `t()` is typed against the intlayer dictionary for namespace N:
|
|
22
|
-
* keys are autocompleted and dot-paths are validated at compile time.
|
|
23
|
-
*
|
|
24
|
-
* @example
|
|
25
|
-
* ```tsx
|
|
26
|
-
* const { t } = useTranslation('about');
|
|
27
|
-
* t('counter.label'); // ✓ typed; compile error if key doesn't exist
|
|
28
|
-
* t('items', { count: 3 }); // plural suffix resolution
|
|
29
|
-
* ```
|
|
30
|
-
*/
|
|
31
|
-
const useTranslation = (ns, options) => {
|
|
32
|
-
const namespace = Array.isArray(ns) ? ns[0] ?? "translation" : ns ?? "translation";
|
|
33
|
-
const { locale, setLocale, availableLocales } = (0, react_intlayer.useLocale)();
|
|
34
|
-
const keyPrefix = options?.keyPrefix;
|
|
35
|
-
/**
|
|
36
|
-
* @param key - A valid dot-notation path within the namespace N dictionary.
|
|
37
|
-
* @param optionsOrDefaultValue - i18next `t()` options (interpolation
|
|
38
|
-
* values, `count`, `context`, `ns`, `defaultValue`, …) or a default
|
|
39
|
-
* value string.
|
|
40
|
-
*/
|
|
41
|
-
const translate = (0, react.useMemo)(() => {
|
|
42
|
-
const resolveSingleKey = (key, translateOptions) => (0, _intlayer_i18next.resolveTranslation)({
|
|
43
|
-
locale,
|
|
44
|
-
namespace,
|
|
45
|
-
key: keyPrefix ? `${keyPrefix}.${key}` : key,
|
|
46
|
-
options: translateOptions
|
|
47
|
-
});
|
|
48
|
-
return (key, optionsOrDefaultValue, extraOptions) => {
|
|
49
|
-
const translateOptions = typeof optionsOrDefaultValue === "string" ? {
|
|
50
|
-
defaultValue: optionsOrDefaultValue,
|
|
51
|
-
...extraOptions
|
|
52
|
-
} : optionsOrDefaultValue ?? {};
|
|
53
|
-
const keys = Array.isArray(key) ? key : [key];
|
|
54
|
-
for (const candidateKey of keys) {
|
|
55
|
-
const resolved = resolveSingleKey(candidateKey, translateOptions);
|
|
56
|
-
if (resolved !== void 0) return resolved;
|
|
57
|
-
}
|
|
58
|
-
const defaultValue = translateOptions.defaultValue;
|
|
59
|
-
if (typeof defaultValue === "string") return (0, _intlayer_core_messageFormat.resolveMessage)(defaultValue, (0, _intlayer_i18next.getInterpolationValues)(translateOptions), locale, "i18next");
|
|
60
|
-
return keys[keys.length - 1];
|
|
61
|
-
};
|
|
62
|
-
}, [
|
|
63
|
-
locale,
|
|
64
|
-
namespace,
|
|
65
|
-
keyPrefix
|
|
66
|
-
]);
|
|
67
|
-
return {
|
|
68
|
-
t: translate,
|
|
69
|
-
i18n: (0, react.useMemo)(() => ({
|
|
70
|
-
language: locale,
|
|
71
|
-
languages: availableLocales ?? [],
|
|
72
|
-
resolvedLanguage: locale,
|
|
73
|
-
isInitialized: true,
|
|
74
|
-
changeLanguage: async (newLanguage) => {
|
|
75
|
-
setLocale(newLanguage);
|
|
76
|
-
},
|
|
77
|
-
dir: (language) => {
|
|
78
|
-
return (0, _intlayer_core_localization.getHTMLTextDir)(language ?? locale) === "rtl" ? "rtl" : "ltr";
|
|
79
|
-
},
|
|
80
|
-
exists: (key, existsOptions) => (0, _intlayer_i18next.resolveTranslation)({
|
|
81
|
-
locale,
|
|
82
|
-
namespace,
|
|
83
|
-
key,
|
|
84
|
-
options: existsOptions
|
|
85
|
-
}) !== void 0,
|
|
86
|
-
t: translate,
|
|
87
|
-
getFixedT: (language, fixedNamespace) => (key, fixedOptions) => {
|
|
88
|
-
const resolved = (0, _intlayer_i18next.resolveTranslation)({
|
|
89
|
-
locale: language ?? locale,
|
|
90
|
-
namespace: fixedNamespace ?? namespace,
|
|
91
|
-
key,
|
|
92
|
-
options: fixedOptions
|
|
93
|
-
});
|
|
94
|
-
return resolved !== void 0 ? resolved : key;
|
|
95
|
-
}
|
|
96
|
-
}), [
|
|
97
|
-
locale,
|
|
98
|
-
availableLocales,
|
|
99
|
-
setLocale,
|
|
100
|
-
namespace,
|
|
101
|
-
translate
|
|
102
|
-
]),
|
|
103
|
-
ready: true
|
|
104
|
-
};
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
//#endregion
|
|
108
|
-
exports.useTranslation = useTranslation;
|
|
109
|
-
//# sourceMappingURL=useTranslation.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useTranslation.cjs","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,oDAAgC;CAE3D,MAAM,YAAY,SAAS;;;;;;;CAQ3B,MAAM,qCAA0B;EAC9B,MAAM,oBACJ,KACA,+DAEmB;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,yDACE,4DACuB,iBAAiB,EACxC,QACA,UACD;AAGH,UAAO,KAAK,KAAK,SAAS;;IAE3B;EAAC;EAAQ;EAAW;EAAU,CAAC;AA6ClC,QAAO;EAAE;EAAG,gCA1CH;GACL,UAAU;GACV,WAAY,oBAAoB,EAAE;GAClC,kBAAkB;GAClB,eAAe;GACf,gBAAgB,OAAO,gBAAwB;AAC7C,cAAU,YAA6B;;GAEzC,MAAM,aAAqC;AAEzC,2DADkC,YAAY,OAC9B,KAAK,QAAQ,QAAQ;;GAEvC,SAAS,KAAa,4DACD;IACT;IACR;IACA;IACA,SAAS;IACV,CAAC,KAAK;GACT,GAAG;GACH,YACG,UAA0B,oBAC1B,KAAa,iBAAoC;IAChD,MAAM,qDAA8B;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"}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
5
|
-
let react = require("react");
|
|
6
|
-
let react_intlayer = require("react-intlayer");
|
|
7
|
-
|
|
8
|
-
//#region src/useTranslationDictionary.ts
|
|
9
|
-
/**
|
|
10
|
-
* Dictionary-accepting variant of `useTranslation`.
|
|
11
|
-
*
|
|
12
|
-
* Used internally by the SWC optimization: instead of looking up the dictionary
|
|
13
|
-
* at runtime by key, the SWC plugin pre-imports the dictionary JSON at build time
|
|
14
|
-
* and passes it directly here. This enables tree-shaking of unused locale content.
|
|
15
|
-
*
|
|
16
|
-
* @example (generated by SWC, not written manually)
|
|
17
|
-
* import _abc from '.intlayer/dictionaries/about.json' with { type: 'json' };
|
|
18
|
-
* const { t } = useTranslationDictionary(_abc);
|
|
19
|
-
*/
|
|
20
|
-
const useTranslationDictionary = (dictionary, keyPrefix, options) => {
|
|
21
|
-
const content = (0, react_intlayer.useDictionary)(dictionary);
|
|
22
|
-
const { locale, setLocale, availableLocales } = (0, react_intlayer.useLocale)();
|
|
23
|
-
const i18n = (0, react.useMemo)(() => ({
|
|
24
|
-
language: locale,
|
|
25
|
-
languages: availableLocales ?? [],
|
|
26
|
-
changeLanguage: async (lng) => {
|
|
27
|
-
setLocale(lng);
|
|
28
|
-
},
|
|
29
|
-
isInitialized: true
|
|
30
|
-
}), [
|
|
31
|
-
locale,
|
|
32
|
-
availableLocales,
|
|
33
|
-
setLocale
|
|
34
|
-
]);
|
|
35
|
-
const prefix = options?.keyPrefix ?? keyPrefix;
|
|
36
|
-
const t = (key, params) => {
|
|
37
|
-
const lookupKey = prefix ? `${prefix}.${String(key)}` : String(key);
|
|
38
|
-
const parts = lookupKey.split(".");
|
|
39
|
-
let current = content;
|
|
40
|
-
for (const part of parts) {
|
|
41
|
-
if (current == null) break;
|
|
42
|
-
current = current[part];
|
|
43
|
-
}
|
|
44
|
-
const str = String(current ?? lookupKey);
|
|
45
|
-
if (!params) return str;
|
|
46
|
-
return str.replace(/\{\{(\w+)\}\}/g, (_, k) => params[k] != null ? String(params[k]) : `{{${k}}}`);
|
|
47
|
-
};
|
|
48
|
-
return {
|
|
49
|
-
t,
|
|
50
|
-
i18n,
|
|
51
|
-
ready: true
|
|
52
|
-
};
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
//#endregion
|
|
56
|
-
exports.useTranslationDictionary = useTranslationDictionary;
|
|
57
|
-
//# sourceMappingURL=useTranslationDictionary.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useTranslationDictionary.cjs","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,4CAAwB,WAAW;CACzC,MAAM,EAAE,QAAQ,WAAW,oDAAgC;CAE3D,MAAM,iCACG;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"}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
5
|
-
let react = require("react");
|
|
6
|
-
let react_intlayer = require("react-intlayer");
|
|
7
|
-
|
|
8
|
-
//#region src/useTranslationDictionaryDynamic.ts
|
|
9
|
-
/**
|
|
10
|
-
* Dynamic dictionary-accepting variant of `useTranslation`.
|
|
11
|
-
*/
|
|
12
|
-
const useTranslationDictionaryDynamic = (dictionaryPromise, key, keyPrefix, options) => {
|
|
13
|
-
const content = (0, react_intlayer.useDictionaryDynamic)(dictionaryPromise, key);
|
|
14
|
-
const { locale, setLocale, availableLocales } = (0, react_intlayer.useLocale)();
|
|
15
|
-
const i18n = (0, react.useMemo)(() => ({
|
|
16
|
-
language: locale,
|
|
17
|
-
languages: availableLocales ?? [],
|
|
18
|
-
changeLanguage: async (lng) => {
|
|
19
|
-
setLocale(lng);
|
|
20
|
-
},
|
|
21
|
-
isInitialized: true
|
|
22
|
-
}), [
|
|
23
|
-
locale,
|
|
24
|
-
availableLocales,
|
|
25
|
-
setLocale
|
|
26
|
-
]);
|
|
27
|
-
const prefix = options?.keyPrefix ?? keyPrefix;
|
|
28
|
-
const t = (lookup, params) => {
|
|
29
|
-
const lookupKey = prefix ? `${prefix}.${String(lookup)}` : String(lookup);
|
|
30
|
-
const parts = lookupKey.split(".");
|
|
31
|
-
let current = content;
|
|
32
|
-
for (const part of parts) {
|
|
33
|
-
if (current == null) break;
|
|
34
|
-
current = current[part];
|
|
35
|
-
}
|
|
36
|
-
const str = String(current ?? lookupKey);
|
|
37
|
-
if (!params) return str;
|
|
38
|
-
return str.replace(/\{\{(\w+)\}\}/g, (_, k) => params[k] != null ? String(params[k]) : `{{${k}}}`);
|
|
39
|
-
};
|
|
40
|
-
return {
|
|
41
|
-
t,
|
|
42
|
-
i18n,
|
|
43
|
-
ready: true
|
|
44
|
-
};
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
//#endregion
|
|
48
|
-
exports.useTranslationDictionaryDynamic = useTranslationDictionaryDynamic;
|
|
49
|
-
//# sourceMappingURL=useTranslationDictionaryDynamic.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useTranslationDictionaryDynamic.cjs","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,mDAAuC,mBAAmB,IAAW;CAC3E,MAAM,EAAE,QAAQ,WAAW,oDAAgC;CAE3D,MAAM,iCACG;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"}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
5
|
-
const require_useTranslation = require('./useTranslation.cjs');
|
|
6
|
-
let react_jsx_runtime = require("react/jsx-runtime");
|
|
7
|
-
|
|
8
|
-
//#region src/withTranslation.tsx
|
|
9
|
-
/**
|
|
10
|
-
* Drop-in for react-i18next's `withTranslation` HOC.
|
|
11
|
-
*/
|
|
12
|
-
const withTranslation = ((ns, options) => (WrappedComponent) => {
|
|
13
|
-
const WithTranslation = (props) => {
|
|
14
|
-
const { t, i18n } = require_useTranslation.useTranslation(ns, options);
|
|
15
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(WrappedComponent, {
|
|
16
|
-
...props,
|
|
17
|
-
t,
|
|
18
|
-
i18n,
|
|
19
|
-
tReady: true
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
WithTranslation.displayName = `withTranslation(${WrappedComponent.displayName ?? WrappedComponent.name ?? "Component"})`;
|
|
23
|
-
return WithTranslation;
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
//#endregion
|
|
27
|
-
exports.withTranslation = withTranslation;
|
|
28
|
-
//# sourceMappingURL=withTranslation.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"withTranslation.cjs","names":["useTranslation"],"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,SAASA,sCAAe,IAAI,QAAQ;AAC/C,SACE,2CAAC,kBAAD;GACE,GAAK;GACF;GACG;GACN;GACA;;AAGN,iBAAgB,cAAc,mBAC5B,iBAAiB,eAAe,iBAAiB,QAAQ,YAC1D;AACD,QAAO"}
|
|
@@ -1,55 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,47 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { UseTranslationOptions } from "i18next";
|
|
2
|
-
import { ValidDotPathsFor } from "@intlayer/core/transpiler";
|
|
3
|
-
import { Dictionary } from "@intlayer/types/dictionary";
|
|
4
|
-
|
|
5
|
-
//#region src/useTranslationDictionary.d.ts
|
|
6
|
-
/**
|
|
7
|
-
* Dictionary-accepting variant of `useTranslation`.
|
|
8
|
-
*
|
|
9
|
-
* Used internally by the SWC optimization: instead of looking up the dictionary
|
|
10
|
-
* at runtime by key, the SWC plugin pre-imports the dictionary JSON at build time
|
|
11
|
-
* and passes it directly here. This enables tree-shaking of unused locale content.
|
|
12
|
-
*
|
|
13
|
-
* @example (generated by SWC, not written manually)
|
|
14
|
-
* import _abc from '.intlayer/dictionaries/about.json' with { type: 'json' };
|
|
15
|
-
* const { t } = useTranslationDictionary(_abc);
|
|
16
|
-
*/
|
|
17
|
-
declare const useTranslationDictionary: <T extends Dictionary>(dictionary: T, keyPrefix?: string, options?: UseTranslationOptions<string>) => {
|
|
18
|
-
t: <P extends ValidDotPathsFor<any>>(key: P, params?: Record<string, unknown>) => string;
|
|
19
|
-
i18n: {
|
|
20
|
-
language: string;
|
|
21
|
-
languages: string[];
|
|
22
|
-
changeLanguage: (lng: string) => Promise<void>;
|
|
23
|
-
isInitialized: boolean;
|
|
24
|
-
};
|
|
25
|
-
ready: boolean;
|
|
26
|
-
};
|
|
27
|
-
//#endregion
|
|
28
|
-
export { useTranslationDictionary };
|
|
29
|
-
//# sourceMappingURL=useTranslationDictionary.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useTranslationDictionary.d.ts","names":[],"sources":["../../src/useTranslationDictionary.ts"],"mappings":";;;;;;;AAmBA;;;;;;;;;cAAa,wBAAA,aAAsC,UAAA,EACjD,UAAA,EAAY,CAAA,EACZ,SAAA,WACA,OAAA,GAAU,qBAAA;gBAoBW,gBAAA,OAAqB,GAAA,EACnC,CAAA,EAAC,MAAA,GACG,MAAA;;;;qCAZ2B,OAAA"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { UseTranslationOptions } from "i18next";
|
|
2
|
-
import { ValidDotPathsFor } from "@intlayer/core/transpiler";
|
|
3
|
-
import { StrictModeLocaleMap } from "@intlayer/types/module_augmentation";
|
|
4
|
-
import { Dictionary } from "@intlayer/types/dictionary";
|
|
5
|
-
|
|
6
|
-
//#region src/useTranslationDictionaryDynamic.d.ts
|
|
7
|
-
/**
|
|
8
|
-
* Dynamic dictionary-accepting variant of `useTranslation`.
|
|
9
|
-
*/
|
|
10
|
-
declare const useTranslationDictionaryDynamic: <const T extends Dictionary, const K extends string>(dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>, key: K, keyPrefix?: string, options?: UseTranslationOptions<string>) => {
|
|
11
|
-
t: <P extends ValidDotPathsFor<any>>(lookup: P, params?: Record<string, unknown>) => string;
|
|
12
|
-
i18n: {
|
|
13
|
-
language: string;
|
|
14
|
-
languages: string[];
|
|
15
|
-
changeLanguage: (lng: string) => Promise<void>;
|
|
16
|
-
isInitialized: boolean;
|
|
17
|
-
};
|
|
18
|
-
ready: boolean;
|
|
19
|
-
};
|
|
20
|
-
//#endregion
|
|
21
|
-
export { useTranslationDictionaryDynamic };
|
|
22
|
-
//# sourceMappingURL=useTranslationDictionaryDynamic.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useTranslationDictionaryDynamic.d.ts","names":[],"sources":["../../src/useTranslationDictionaryDynamic.ts"],"mappings":";;;;;;;;AAYA;cAAa,+BAAA,mBACK,UAAA,0BAGhB,iBAAA,EAAmB,mBAAA,OAA0B,OAAA,CAAQ,CAAA,IACrD,GAAA,EAAK,CAAA,EACL,SAAA,WACA,OAAA,GAAU,qBAAA;gBAmBW,gBAAA,OAAqB,MAAA,EAChC,CAAA,EAAC,MAAA,GACA,MAAA;;;;qCAZ2B,OAAA"}
|