@intlayer/react-i18next 8.12.5-canary.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +330 -0
- package/dist/cjs/I18nextProvider.cjs +25 -0
- package/dist/cjs/I18nextProvider.cjs.map +1 -0
- package/dist/cjs/Trans.cjs +64 -0
- package/dist/cjs/Trans.cjs.map +1 -0
- package/dist/cjs/_virtual/_rolldown/runtime.cjs +29 -0
- package/dist/cjs/helpers.cjs +67 -0
- package/dist/cjs/helpers.cjs.map +1 -0
- package/dist/cjs/index.cjs +49 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/initReactI18next.cjs +24 -0
- package/dist/cjs/initReactI18next.cjs.map +1 -0
- package/dist/cjs/plugin/index.cjs +62 -0
- package/dist/cjs/plugin/index.cjs.map +1 -0
- package/dist/cjs/useDictionary.cjs +64 -0
- package/dist/cjs/useDictionary.cjs.map +1 -0
- package/dist/cjs/useDictionaryDynamic.cjs +49 -0
- package/dist/cjs/useDictionaryDynamic.cjs.map +1 -0
- package/dist/cjs/useTranslation.cjs +109 -0
- package/dist/cjs/useTranslation.cjs.map +1 -0
- package/dist/cjs/useTranslationDictionary.cjs +57 -0
- package/dist/cjs/useTranslationDictionary.cjs.map +1 -0
- package/dist/cjs/useTranslationDictionaryDynamic.cjs +49 -0
- package/dist/cjs/useTranslationDictionaryDynamic.cjs.map +1 -0
- package/dist/cjs/withTranslation.cjs +28 -0
- package/dist/cjs/withTranslation.cjs.map +1 -0
- package/dist/esm/I18nextProvider.mjs +23 -0
- package/dist/esm/I18nextProvider.mjs.map +1 -0
- package/dist/esm/Trans.mjs +62 -0
- package/dist/esm/Trans.mjs.map +1 -0
- package/dist/esm/helpers.mjs +54 -0
- package/dist/esm/helpers.mjs.map +1 -0
- package/dist/esm/index.mjs +28 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/initReactI18next.mjs +23 -0
- package/dist/esm/initReactI18next.mjs.map +1 -0
- package/dist/esm/plugin/index.mjs +58 -0
- package/dist/esm/plugin/index.mjs.map +1 -0
- package/dist/esm/useDictionary.mjs +62 -0
- package/dist/esm/useDictionary.mjs.map +1 -0
- package/dist/esm/useDictionaryDynamic.mjs +47 -0
- package/dist/esm/useDictionaryDynamic.mjs.map +1 -0
- package/dist/esm/useTranslation.mjs +107 -0
- package/dist/esm/useTranslation.mjs.map +1 -0
- package/dist/esm/useTranslationDictionary.mjs +55 -0
- package/dist/esm/useTranslationDictionary.mjs.map +1 -0
- package/dist/esm/useTranslationDictionaryDynamic.mjs +47 -0
- package/dist/esm/useTranslationDictionaryDynamic.mjs.map +1 -0
- package/dist/esm/withTranslation.mjs +26 -0
- package/dist/esm/withTranslation.mjs.map +1 -0
- package/dist/types/I18nextProvider.d.ts +13 -0
- package/dist/types/I18nextProvider.d.ts.map +1 -0
- package/dist/types/Trans.d.ts +22 -0
- package/dist/types/Trans.d.ts.map +1 -0
- package/dist/types/helpers.d.ts +35 -0
- package/dist/types/helpers.d.ts.map +1 -0
- package/dist/types/index.d.ts +27 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/initReactI18next.d.ts +16 -0
- package/dist/types/initReactI18next.d.ts.map +1 -0
- package/dist/types/plugin/index.d.ts +12 -0
- package/dist/types/plugin/index.d.ts.map +1 -0
- package/dist/types/useDictionary.d.ts +32 -0
- package/dist/types/useDictionary.d.ts.map +1 -0
- package/dist/types/useDictionaryDynamic.d.ts +22 -0
- package/dist/types/useDictionaryDynamic.d.ts.map +1 -0
- package/dist/types/useTranslation.d.ts +43 -0
- package/dist/types/useTranslation.d.ts.map +1 -0
- package/dist/types/useTranslationDictionary.d.ts +29 -0
- package/dist/types/useTranslationDictionary.d.ts.map +1 -0
- package/dist/types/useTranslationDictionaryDynamic.d.ts +22 -0
- package/dist/types/useTranslationDictionaryDynamic.d.ts.map +1 -0
- package/dist/types/withTranslation.d.ts +10 -0
- package/dist/types/withTranslation.d.ts.map +1 -0
- package/package.json +118 -0
package/README.md
ADDED
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://intlayer.org" rel="">
|
|
3
|
+
<img src="https://raw.githubusercontent.com/aymericzip/intlayer/main/docs/assets/cover.png" width="60%" alt="Intlayer Logo" />
|
|
4
|
+
</a>
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<h1 align="center">
|
|
8
|
+
<strong>Per-component i18n</strong>
|
|
9
|
+
</h1>
|
|
10
|
+
|
|
11
|
+
<h2 align="center">
|
|
12
|
+
<strong>AI-powered translation. Visual Editor. Multilingual CMS.</strong>
|
|
13
|
+
</h2>
|
|
14
|
+
|
|
15
|
+
<br />
|
|
16
|
+
|
|
17
|
+
<p align="center">
|
|
18
|
+
<a href="https://intlayer.org/doc/concept/content" rel="">Docs</a> •
|
|
19
|
+
<a href="https://intlayer.org/doc/environment/nextjs" rel="">Next.js</a> •
|
|
20
|
+
<a href="https://intlayer.org/doc/environment/vite-and-react" rel="">React + Vite</a> •
|
|
21
|
+
<a href="https://intlayer.org/doc/concept/cms" rel="">CMS</a> •
|
|
22
|
+
<a href="https://discord.gg/7uxamYVeCk" rel="noopener noreferrer nofollow">Discord</a>
|
|
23
|
+
</p>
|
|
24
|
+
<p align="center" style="margin-top:15px;">
|
|
25
|
+
<a href="https://www.npmjs.com/package/intlayer" target="_blank" rel="noopener noreferrer nofollow"><img src="https://img.shields.io/npm/v/intlayer?style=for-the-badge&labelColor=FFFFFF&color=000000&logoColor=FFFFFF" alt="npm version" height="24"/></a>
|
|
26
|
+
<a href="https://github.com/aymericzip/intlayer/stargazers" target="_blank" rel="noopener noreferrer nofollow"><img src="https://img.shields.io/github/stars/aymericzip/intlayer?style=for-the-badge&labelColor=000000&color=FFFFFF&logo=github&logoColor=FFD700" alt="GitHub Stars" height="24"/></a>
|
|
27
|
+
<a href="https://www.npmjs.org/package/intlayer" target="_blank" rel="noopener noreferrer nofollow"><img src="https://img.shields.io/npm/dm/intlayer?style=for-the-badge&labelColor=000000&color=FFFFFF&logoColor=000000&cacheSeconds=86400" alt="monthly downloads" height="24"/></a>
|
|
28
|
+
<a href="https://github.com/aymericzip/intlayer/blob/main/LICENSE" target="_blank" rel="noopener noreferrer nofollow"><img src="https://img.shields.io/github/license/aymericzip/intlayer?style=for-the-badge&labelColor=000000&color=FFFFFF&logoColor=000000&cacheSeconds=86400" alt="license"/></a>
|
|
29
|
+
<a href="https://github.com/aymericzip/intlayer/commits/main" target="_blank" rel="noopener noreferrer nofollow"><img src="https://img.shields.io/github/last-commit/aymericzip/intlayer?style=for-the-badge&labelColor=000000&color=FFFFFF&logoColor=000000&cacheSeconds=86400" alt="last commit"/>
|
|
30
|
+
</a>
|
|
31
|
+
</p>
|
|
32
|
+
|
|
33
|
+

|
|
34
|
+
|
|
35
|
+
<a href="https://intlayer.org/doc/concept/content" rel="">
|
|
36
|
+
<img src="https://img.shields.io/badge/Get_Started-FFFFFF?style=for-the-badge&logo=rocket&logoColor=black" />
|
|
37
|
+
</a>
|
|
38
|
+
|
|
39
|
+
## What is Intlayer?
|
|
40
|
+
|
|
41
|
+
Most i18n libraries are either too complex, too rigid, or not built for modern frameworks.
|
|
42
|
+
|
|
43
|
+
Intlayer is a **modern i18n solution** for web and mobile apps.
|
|
44
|
+
It’s framework-agnostic, **AI-powered**, and includes a free **CMS & visual editor**.
|
|
45
|
+
|
|
46
|
+
With **per-locale content files**, **TypeScript autocompletion**, **tree-shakable dictionaries**, and **CI/CD integration**, Intlayer makes internationalization **faster, cleaner, and smarter**.
|
|
47
|
+
|
|
48
|
+
## Keys benefits of Intlayer:
|
|
49
|
+
|
|
50
|
+
| Feature | Description |
|
|
51
|
+
| --------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
52
|
+
| <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/frameworks.png?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
|
+
| <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
|
+
| <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.jpg?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
|
+
| <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
|
+
| <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
|
+
| <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) |
|
|
59
|
+
| <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/server_component.png?raw=true" alt="Feature" width="700"> | **Consistent Server Component Implementation**<br><br>Perfectly suited for Next.js server components, use the same implementation for both client and server components, no need to pass your `t` function across each server component. <br><br> - [Server Components](https://intlayer.org/doc/environment/nextjs#step-7-utilize-content-in-your-code) |
|
|
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
|
+
| <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
|
+
| <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.png?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.png?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.png?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
|
+
| <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
|
+
| <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.png?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
|
+
| <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) |
|
|
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
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## 📦 Installation
|
|
75
|
+
|
|
76
|
+
Start your journey with Intlayer today and experience a smoother, more powerful approach to internationalization.
|
|
77
|
+
|
|
78
|
+
<a href="https://intlayer.org/doc/concept/content" rel="">
|
|
79
|
+
<img src="https://img.shields.io/badge/Get_Started-FFFFFF?style=for-the-badge&logo=rocket&logoColor=black" />
|
|
80
|
+
</a>
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
npm install intlayer react-intlayer
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
⚡ Quick Start (Next.js)
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
// intlayer.config.ts
|
|
90
|
+
import { Locales, type IntlayerConfig } from "intlayer";
|
|
91
|
+
|
|
92
|
+
const config: IntlayerConfig = {
|
|
93
|
+
internationalization: {
|
|
94
|
+
locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH],
|
|
95
|
+
defaultLocale: Locales.ENGLISH,
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
export default config;
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
```ts
|
|
103
|
+
// app/home.content.ts
|
|
104
|
+
import { t, type Dictionary } from "intlayer";
|
|
105
|
+
|
|
106
|
+
const content = {
|
|
107
|
+
key: "home",
|
|
108
|
+
content: {
|
|
109
|
+
title: t({
|
|
110
|
+
en: "Home",
|
|
111
|
+
fr: "Accueil",
|
|
112
|
+
es: "Inicio",
|
|
113
|
+
}),
|
|
114
|
+
},
|
|
115
|
+
} satisfies Dictionary;
|
|
116
|
+
|
|
117
|
+
export default content;
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
```tsx
|
|
121
|
+
// app/page.tsx
|
|
122
|
+
import { useIntlayer } from "react-intlayer";
|
|
123
|
+
|
|
124
|
+
const HomePage = () => {
|
|
125
|
+
const { title } = useIntlayer("home");
|
|
126
|
+
|
|
127
|
+
return <h1>{title}</h1>;
|
|
128
|
+
};
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
<a href="https://intlayer.org/doc/environment/nextjs"> Get the full guide → </a>
|
|
132
|
+
|
|
133
|
+
## 🎥 Live tutorial on YouTube
|
|
134
|
+
|
|
135
|
+
[](https://youtu.be/e_PPG7PTqGU?si=GyU_KpVhr61razRw)
|
|
136
|
+
|
|
137
|
+
<a href="https://intlayer.org/doc/concept/content" rel="">
|
|
138
|
+
<img src="https://img.shields.io/badge/Get_Started-FFFFFF?style=for-the-badge&logo=rocket&logoColor=black" />
|
|
139
|
+
</a>
|
|
140
|
+
|
|
141
|
+
## Table of Contents
|
|
142
|
+
|
|
143
|
+
Explore our comprehensive documentation to get started with Intlayer and learn how to integrate it into your projects.
|
|
144
|
+
|
|
145
|
+
<details open>
|
|
146
|
+
<summary style="font-size:16px; font-weight:bold;">📘 Get Started</summary>
|
|
147
|
+
<ul>
|
|
148
|
+
<li><a href="https://intlayer.org/doc/why" rel=''>Why Intlayer?</a></li>
|
|
149
|
+
<li><a href="https://intlayer.org/doc" rel=''>Introduction</a></li>
|
|
150
|
+
</ul>
|
|
151
|
+
</details>
|
|
152
|
+
|
|
153
|
+
<details>
|
|
154
|
+
<summary style="font-size:16px; font-weight:bold;">⚙️ Concept</summary>
|
|
155
|
+
<ul>
|
|
156
|
+
<li><a href="https://intlayer.org/doc/concept/how-works-intlayer" rel=''>How Intlayer Works</a></li>
|
|
157
|
+
<li><a href="https://intlayer.org/doc/concept/configuration" rel=''>Configuration</a></li>
|
|
158
|
+
<li><a href="https://intlayer.org/doc/concept/cli" rel=''>Intlayer CLI</a></li>
|
|
159
|
+
<li><a href="https://intlayer.org/doc/compiler" rel=''>Compiler</a></li>
|
|
160
|
+
|
|
161
|
+
<li><a href="https://intlayer.org/doc/concept/editor" rel=''>Intlayer Editor</a></li>
|
|
162
|
+
<li><a href="https://intlayer.org/doc/concept/cms" rel=''>Intlayer CMS</a></li>
|
|
163
|
+
<li><a href="https://intlayer.org/doc/concept/content" rel=''>Dictionary</a>
|
|
164
|
+
<ul>
|
|
165
|
+
<li><a href="https://intlayer.org/doc/concept/content/per-locale-file" rel=''>Per-Locale Content Declaration File</a></li>
|
|
166
|
+
<li><a href="https://intlayer.org/doc/concept/content/translation" rel=''>Translation</a></li>
|
|
167
|
+
<li><a href="https://intlayer.org/doc/concept/content/enumeration" rel=''>Enumeration</a></li>
|
|
168
|
+
<li><a href="https://intlayer.org/doc/concept/content/condition" rel=''>Condition</a></li>
|
|
169
|
+
<li><a href="https://intlayer.org/doc/concept/content/nesting" rel=''>Nesting</a></li>
|
|
170
|
+
<li><a href="https://intlayer.org/doc/concept/content/markdown" rel=''>Markdown</a></li>
|
|
171
|
+
<li><a href="https://intlayer.org/doc/concept/content/function-fetching" rel=''>Function Fetching</a></li>
|
|
172
|
+
<li><a href="https://intlayer.org/doc/concept/content/insertion" rel=''>Insertion</a></li>
|
|
173
|
+
<li><a href="https://intlayer.org/doc/concept/content/file" rel=''>File</a></li>
|
|
174
|
+
</ul>
|
|
175
|
+
</li>
|
|
176
|
+
</ul>
|
|
177
|
+
</details>
|
|
178
|
+
|
|
179
|
+
<details open>
|
|
180
|
+
<summary style="font-size:16px; font-weight:bold;">🌐 Environment</summary>
|
|
181
|
+
<ul>
|
|
182
|
+
<li><a href="https://intlayer.org/doc/environment/nextjs" rel=''>Intlayer with Next.js 16</a>
|
|
183
|
+
<ul>
|
|
184
|
+
<li><a href="https://intlayer.org/doc/environment/nextjs/15" rel=''>Next.js 15</a></li>
|
|
185
|
+
<li><a href="https://intlayer.org/doc/environment/nextjs/14" rel=''>Next.js 14 (App Router)</a></li>
|
|
186
|
+
<li><a href="https://intlayer.org/doc/environment/nextjs/next-with-Page-Router" rel=''>Next.js Page Router</a></li>
|
|
187
|
+
<li><a href="https://intlayer.org/doc/environment/nextjs/compiler" rel=''>Next.js using Compiler</a></li>
|
|
188
|
+
</ul>
|
|
189
|
+
</li>
|
|
190
|
+
<li><a href="https://intlayer.org/doc/environment/create-react-app" rel=''>React CRA</a></li>
|
|
191
|
+
<li><a href="https://intlayer.org/doc/environment/vite-and-react" rel=''>Vite + React</a></li>
|
|
192
|
+
<li><a href="https://intlayer.org/doc/environment/vite-and-react" rel=''>Vite + React using Compiler</a></li>
|
|
193
|
+
<li><a href="https://intlayer.org/doc/environment/vite-and-react/compiler" rel=''>React-router-v7</a></li>
|
|
194
|
+
<li><a href="https://intlayer.org/doc/environment/tanstack-start" rel=''>Tanstack start</a>
|
|
195
|
+
<ul>
|
|
196
|
+
<li><a href="https://intlayer.org/doc/environment/tanstack-start/solid" rel=''>Solid</a></li>
|
|
197
|
+
</ul>
|
|
198
|
+
</li>
|
|
199
|
+
<li><a href="https://intlayer.org/doc/environment/astro" rel=''>Astro</a>
|
|
200
|
+
<ul>
|
|
201
|
+
<li><a href="https://intlayer.org/doc/environment/astro/react" rel=''>React</a></li>
|
|
202
|
+
<li><a href="https://intlayer.org/doc/environment/astro/vue" rel=''>Vue</a></li>
|
|
203
|
+
<li><a href="https://intlayer.org/doc/environment/astro/svelte" rel=''>Svelte</a></li>
|
|
204
|
+
<li><a href="https://intlayer.org/doc/environment/astro/solid" rel=''>Solid</a></li>
|
|
205
|
+
<li><a href="https://intlayer.org/doc/environment/astro/vanilla" rel=''>Vanilla JS</a></li>
|
|
206
|
+
<li><a href="https://intlayer.org/doc/environment/astro/lit" rel=''>Lit</a></li>
|
|
207
|
+
</ul>
|
|
208
|
+
</li>
|
|
209
|
+
|
|
210
|
+
<li><a href="https://intlayer.org/doc/environment/react-native-and-expo" rel=''>React Native</a></li>
|
|
211
|
+
<li><a href="https://intlayer.org/doc/environment/vite-and-svelte" rel=''>Vite + Svelte</a></li>
|
|
212
|
+
<li><a href="https://intlayer.org/doc/environment/sveltekit" rel=''>SvelteKit</a></li>
|
|
213
|
+
<li><a href="https://intlayer.org/doc/environment/vite-and-preact" rel=''>Vite + Preact</a></li>
|
|
214
|
+
<li><a href="https://intlayer.org/doc/environment/vite-and-vue" rel=''>Vite + Vue</a></li>
|
|
215
|
+
<li><a href="https://intlayer.org/doc/environment/vite-and-nuxt" rel=''>Vite + Nuxt</a></li>
|
|
216
|
+
<li><a href="https://intlayer.org/doc/environment/vite-and-solid" rel=''>Vite + Solid</a></li>
|
|
217
|
+
<li><a href="https://intlayer.org/doc/environment/angular" rel=''>Angular</a></li>
|
|
218
|
+
<li>
|
|
219
|
+
<a href="https://intlayer.org/doc/environment/express" rel=''>Backend</a>
|
|
220
|
+
<ul>
|
|
221
|
+
<li><a href="https://intlayer.org/doc/environment/express" rel=''>Express</a></li>
|
|
222
|
+
<li><a href="https://intlayer.org/doc/environment/nest" rel=''>NestJS</a></li>
|
|
223
|
+
<li><a href="https://intlayer.org/doc/environment/fastify" rel=''>Fastify</a></li>
|
|
224
|
+
<li><a href="https://intlayer.org/doc/environment/adonisjs" rel=''>AdonisJS</a></li>
|
|
225
|
+
<li><a href="https://intlayer.org/doc/environment/hono" rel=''>Hono</a></li>
|
|
226
|
+
</ul>
|
|
227
|
+
</li>
|
|
228
|
+
</ul>
|
|
229
|
+
</details>
|
|
230
|
+
|
|
231
|
+
<details>
|
|
232
|
+
<summary style="font-size:16px; font-weight:bold;">📊 Benchmark</summary>
|
|
233
|
+
<ul>
|
|
234
|
+
<li><a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/benchmark/nextjs.md" rel=''>Next.js</a></li>
|
|
235
|
+
<li><a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/benchmark/tanstack.md" rel=''>TanStack Start</a></li>
|
|
236
|
+
<li><a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/benchmark/vue.md" rel=''>Vue</a></li>
|
|
237
|
+
<li><a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/benchmark/solid.md" rel=''>Solid</a></li>
|
|
238
|
+
<li><a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/benchmark/svelte.md" rel=''>Svelte</a></li>
|
|
239
|
+
</ul>
|
|
240
|
+
</details>
|
|
241
|
+
|
|
242
|
+
<details>
|
|
243
|
+
<summary style="font-size:16px; font-weight:bold;">📰 Blog</summary>
|
|
244
|
+
<ul>
|
|
245
|
+
<li><a href="https://github.com/aymericzip/intlayer/blob/main/docs/blog/en/what_is_internationalization.md" rel=''>What is i18n</a></li>
|
|
246
|
+
<li><a href="https://intlayer.org/blog/SEO-and-i18n" rel=''>i18n and SEO</a></li>
|
|
247
|
+
<li><a href="https://intlayer.org/blog/intlayer-with-next-i18next" rel=''>Intlayer and i18next</a></li>
|
|
248
|
+
<li><a href="https://intlayer.org/blog/intlayer-with-react-i18next" rel=''>Intlayer and react-intl</a></li>
|
|
249
|
+
<li><a href="https://intlayer.org/blog/intlayer-with-next-intl" rel=''>Intlayer and next-intl</a></li>
|
|
250
|
+
</ul>
|
|
251
|
+
</details>
|
|
252
|
+
|
|
253
|
+
## Multilingual content management system
|
|
254
|
+
|
|
255
|
+
More than an i18n library, Intlayer is a complete **multilingual content management system**. A full CMS is available for free at [app.intlayer.org](https://app.intlayer.org).
|
|
256
|
+
|
|
257
|
+
Intlayer connects **developers**, **copywriters**, and **AI agents** in one workflow for creating and maintaining multilingual websites effortlessly.Intlayer replaces the following stack in a single solution:
|
|
258
|
+
|
|
259
|
+
- i18n solutions (e.g. `i18next`, `next-intl`, `vue-i18n`)
|
|
260
|
+
- TMSs (Translation Management Systems) (e.g. Crowdin, Phrase, Lokalise)
|
|
261
|
+
- Feature flags
|
|
262
|
+
- Headless CMSs (e.g. Contentful, Strapi, Sanity)
|
|
263
|
+
|
|
264
|
+

|
|
265
|
+
|
|
266
|
+
## 🌐 Readme in other languages
|
|
267
|
+
|
|
268
|
+
<p align="center">
|
|
269
|
+
<a href="https://github.com/aymericzip/intlayer/blob/main/readme.md">English</a> •
|
|
270
|
+
<a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/zh/readme.md">简体中文</a> •
|
|
271
|
+
<a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/ru/readme.md">Русский</a> •
|
|
272
|
+
<a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/ja/readme.md">日本語</a> •
|
|
273
|
+
<a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/fr/readme.md">Français</a> •
|
|
274
|
+
<a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/ko/readme.md">한국어</a> •
|
|
275
|
+
<a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/es/readme.md">Español</a> •
|
|
276
|
+
<a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/de/readme.md">Deutsch</a> •
|
|
277
|
+
<a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/ar/readme.md">العربية</a> •
|
|
278
|
+
<a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/it/readme.md">Italiano</a> •
|
|
279
|
+
<a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/en-GB/readme.md">English (UK)</a> •
|
|
280
|
+
<a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/pt/readme.md">Português</a> •
|
|
281
|
+
<a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/hi/readme.md">हिन्दी</a> •
|
|
282
|
+
<a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/tr/readme.md">Türkçe</a>
|
|
283
|
+
</p>
|
|
284
|
+
|
|
285
|
+
## 🤝 Community
|
|
286
|
+
|
|
287
|
+
Intlayer is built with and for the community and we’d love your input!
|
|
288
|
+
|
|
289
|
+
- Have a suggestion? [Open an issue](https://github.com/aymericzip/intlayer/issues)
|
|
290
|
+
- Found a bug or improvement? [Submit a PR](https://github.com/aymericzip/intlayer/pulls)
|
|
291
|
+
- Need help or want to connect? [Join our Discord](https://discord.gg/7uxamYVeCk)
|
|
292
|
+
|
|
293
|
+
You can also follow us on :
|
|
294
|
+
|
|
295
|
+
<div>
|
|
296
|
+
<br/>
|
|
297
|
+
<p align="center">
|
|
298
|
+
<a href="https://discord.gg/528mBV4N" target="blank" rel='noopener noreferrer nofollow'><img align="center"
|
|
299
|
+
src="https://img.shields.io/badge/discord-5865F2.svg?style=for-the-badge&logo=discord&logoColor=white"
|
|
300
|
+
alt="Intlayer Discord" height="30"/></a>
|
|
301
|
+
<a href="https://www.linkedin.com/company/intlayerorg" target="blank" rel='noopener noreferrer nofollow'><img align="center"
|
|
302
|
+
src="https://img.shields.io/badge/linkedin-%231DA1F2.svg?style=for-the-badge&logo=linkedin&logoColor=white"
|
|
303
|
+
alt="Intlayer LinkedIn" height="30"/></a>
|
|
304
|
+
<a href="https://www.instagram.com/intlayer/" target="blank" rel='noopener noreferrer nofollow'><img align="center"
|
|
305
|
+
src="https://img.shields.io/badge/instagram-%23E4405F.svg?style=for-the-badge&logo=Instagram&logoColor=white"
|
|
306
|
+
alt="Intlayer Instagram" height="30"/></a>
|
|
307
|
+
<a href="https://x.com/Intlayer183096" target="blank" rel='noopener noreferrer nofollow'><img align="center"
|
|
308
|
+
src="https://img.shields.io/badge/x-1DA1F2.svg?style=for-the-badge&logo=x&logoColor=white"
|
|
309
|
+
alt="Intlayer X" height="30"/></a>
|
|
310
|
+
<a href="https://www.youtube.com/@intlayer" target="blank" rel='noopener noreferrer nofollow'><img align="center"
|
|
311
|
+
src="https://img.shields.io/badge/youtube-FF0000.svg?style=for-the-badge&logo=youtube&logoColor=white"
|
|
312
|
+
alt="Intlayer YouTube" height="30"/></a>
|
|
313
|
+
<a href="https://www.tiktok.com/@intlayer" target="blank" rel='noopener noreferrer nofollow'><img align="center"
|
|
314
|
+
src="https://img.shields.io/badge/tiktok-000000.svg?style=for-the-badge&logo=tiktok&logoColor=white"
|
|
315
|
+
alt="Intlayer TikTok" height="30"/></a>
|
|
316
|
+
<br>
|
|
317
|
+
</p>
|
|
318
|
+
</div>
|
|
319
|
+
|
|
320
|
+
### Contribution
|
|
321
|
+
|
|
322
|
+
For more detailed guidelines on contributing to this project, please refer to the [`CONTRIBUTING.md`](https://github.com/aymericzip/intlayer/blob/main/CONTRIBUTING.md) file. It contains essential information on our development process, commit message conventions, and release procedures. Your contributions are valuable to us, and we appreciate your efforts in making this project better!
|
|
323
|
+
|
|
324
|
+
Contribute on [GitHub](https://github.com/aymericzip/intlayer), [GitLab](https://gitlab.com/ay.pineau/intlayer), or [Bitbucket](https://bitbucket.org/intlayer/intlayer/).
|
|
325
|
+
|
|
326
|
+
### Thank You for the Support
|
|
327
|
+
|
|
328
|
+
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-).
|
|
329
|
+
|
|
330
|
+
[](https://star-history.com/#aymericzip/intlayer&Date)
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,64 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,29 @@
|
|
|
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;
|
|
@@ -0,0 +1,67 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,49 @@
|
|
|
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
|