hono-intlayer 8.0.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 +292 -0
- package/dist/cjs/index.cjs +131 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/esm/index.mjs +127 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/types/index.d.ts +54 -0
- package/package.json +104 -0
package/README.md
ADDED
|
@@ -0,0 +1,292 @@
|
|
|
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
|
+
<h2 align="center">
|
|
11
|
+
<strong>AI-powered translation. Visual Editor. Multilingual CMS.</strong>
|
|
12
|
+
</h2>
|
|
13
|
+
|
|
14
|
+
<br />
|
|
15
|
+
|
|
16
|
+
<p align="center">
|
|
17
|
+
<a href="https://intlayer.org/doc/concept/content" rel="">Docs</a> •
|
|
18
|
+
<a href="https://intlayer.org/doc/environment/nextjs" rel="">Next.js</a> •
|
|
19
|
+
<a href="https://intlayer.org/doc/environment/vite-and-react" rel="">React + Vite</a> •
|
|
20
|
+
<a href="https://intlayer.org/doc/concept/cms" rel="">CMS</a> •
|
|
21
|
+
<a href="https://discord.gg/7uxamYVeCk" rel="noopener noreferrer nofollow">Discord</a>
|
|
22
|
+
</p>
|
|
23
|
+
<p align="center" style="margin-top:15px;">
|
|
24
|
+
<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>
|
|
25
|
+
<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>
|
|
26
|
+
<a href="https://www.npmjs.com/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>
|
|
27
|
+
<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>
|
|
28
|
+
<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"/>
|
|
29
|
+
</a>
|
|
30
|
+
</p>
|
|
31
|
+
|
|
32
|
+

|
|
33
|
+
|
|
34
|
+
<a href="https://intlayer.org/doc/concept/content" rel="">
|
|
35
|
+
<img src="https://img.shields.io/badge/Get_Started-FFFFFF?style=for-the-badge&logo=rocket&logoColor=black" />
|
|
36
|
+
</a>
|
|
37
|
+
|
|
38
|
+
## What is Intlayer?
|
|
39
|
+
|
|
40
|
+
Most i18n libraries are either too complex, too rigid, or not built for modern frameworks.
|
|
41
|
+
|
|
42
|
+
Intlayer is a **modern i18n solution** for web and mobile apps.
|
|
43
|
+
It’s framework-agnostic, **AI-powered**, and includes a free **CMS & visual editor**.
|
|
44
|
+
|
|
45
|
+
With **per-locale content files**, **TypeScript autocompletion**, **tree-shakable dictionaries**, and **CI/CD integration**, Intlayer makes internationalization **faster, cleaner, and smarter**.
|
|
46
|
+
|
|
47
|
+
## Keys benefits of Intlayer:
|
|
48
|
+
|
|
49
|
+
| Feature | Description |
|
|
50
|
+
| --------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
51
|
+
| <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, Hono, and more. |
|
|
52
|
+
| <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) |
|
|
53
|
+
| <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) |
|
|
54
|
+
| <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) |
|
|
55
|
+
| <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) |
|
|
56
|
+
| <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) |
|
|
57
|
+
| <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) |
|
|
58
|
+
| <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) |
|
|
59
|
+
| <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) |
|
|
60
|
+
| <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) |
|
|
61
|
+
| <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) |
|
|
62
|
+
| <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) |
|
|
63
|
+
| <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) |
|
|
64
|
+
| <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) |
|
|
65
|
+
| <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) |
|
|
66
|
+
| <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) |
|
|
67
|
+
| <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, and react-intl. <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) |
|
|
68
|
+
|
|
69
|
+
---
|
|
70
|
+
|
|
71
|
+
## 📦 Installation
|
|
72
|
+
|
|
73
|
+
Start your journey with Intlayer today and experience a smoother, more powerful approach to internationalization.
|
|
74
|
+
|
|
75
|
+
<a href="https://intlayer.org/doc/concept/content" rel="">
|
|
76
|
+
<img src="https://img.shields.io/badge/Get_Started-FFFFFF?style=for-the-badge&logo=rocket&logoColor=black" />
|
|
77
|
+
</a>
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
npm install intlayer hono-intlayer
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
⚡ Quick Start (Hono)
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
// intlayer.config.ts
|
|
87
|
+
import { Locales, type IntlayerConfig } from "intlayer";
|
|
88
|
+
|
|
89
|
+
const config: IntlayerConfig = {
|
|
90
|
+
internationalization: {
|
|
91
|
+
locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH],
|
|
92
|
+
defaultLocale: Locales.ENGLISH,
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
export default config;
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
```ts
|
|
100
|
+
// app/home.content.ts
|
|
101
|
+
import { t, type Dictionary } from "intlayer";
|
|
102
|
+
|
|
103
|
+
const content = {
|
|
104
|
+
key: "home",
|
|
105
|
+
content: {
|
|
106
|
+
title: t({
|
|
107
|
+
en: "Home",
|
|
108
|
+
fr: "Accueil",
|
|
109
|
+
es: "Inicio",
|
|
110
|
+
}),
|
|
111
|
+
},
|
|
112
|
+
} satisfies Dictionary;
|
|
113
|
+
|
|
114
|
+
export default content;
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
```tsx
|
|
118
|
+
// app/page.ts
|
|
119
|
+
import { Hono } from "hono";
|
|
120
|
+
import { intlayer, t } from "hono-intlayer";
|
|
121
|
+
|
|
122
|
+
const app = new Hono();
|
|
123
|
+
|
|
124
|
+
app.use("*", intlayer());
|
|
125
|
+
|
|
126
|
+
app.get("/", (c) => {
|
|
127
|
+
return c.text(
|
|
128
|
+
t({
|
|
129
|
+
en: "Home",
|
|
130
|
+
fr: "Accueil",
|
|
131
|
+
es: "Inicio",
|
|
132
|
+
})
|
|
133
|
+
);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
export default app;
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
<a href="https://intlayer.org/doc/environment/hono"> Get the full guide → </a>
|
|
140
|
+
|
|
141
|
+
## 🎥 Live tutorial on YouTube
|
|
142
|
+
|
|
143
|
+
[](https://youtu.be/e_PPG7PTqGU?si=GyU_KpVhr61razRw)
|
|
144
|
+
|
|
145
|
+
<a href="https://intlayer.org/doc/concept/content" rel="">
|
|
146
|
+
<img src="https://img.shields.io/badge/Get_Started-FFFFFF?style=for-the-badge&logo=rocket&logoColor=black" />
|
|
147
|
+
</a>
|
|
148
|
+
|
|
149
|
+
## Table of Contents
|
|
150
|
+
|
|
151
|
+
Explore our comprehensive documentation to get started with Intlayer and learn how to integrate it into your projects.
|
|
152
|
+
|
|
153
|
+
<details open>
|
|
154
|
+
<summary style="font-size:16px; font-weight:bold;">📘 Get Started</summary>
|
|
155
|
+
<ul>
|
|
156
|
+
<li><a href="https://intlayer.org/doc/why" rel=''>Why Intlayer?</a></li>
|
|
157
|
+
<li><a href="https://intlayer.org/doc" rel=''>Introduction</a></li>
|
|
158
|
+
</ul>
|
|
159
|
+
</details>
|
|
160
|
+
|
|
161
|
+
<details>
|
|
162
|
+
<summary style="font-size:16px; font-weight:bold;">⚙️ Concept</summary>
|
|
163
|
+
<ul>
|
|
164
|
+
<li><a href="https://intlayer.org/doc/concept/how-works-intlayer" rel=''>How Intlayer Works</a></li>
|
|
165
|
+
<li><a href="https://intlayer.org/doc/concept/configuration" rel=''>Configuration</a></li>
|
|
166
|
+
<li><a href="https://intlayer.org/doc/concept/cli" rel=''>Intlayer CLI</a></li>
|
|
167
|
+
<li><a href="https://intlayer.org/doc/concept/editor" rel=''>Intlayer Editor</a></li>
|
|
168
|
+
<li><a href="https://intlayer.org/doc/concept/cms" rel=''>Intlayer CMS</a></li>
|
|
169
|
+
<li><a href="https://intlayer.org/doc/concept/content" rel=''>Dictionary</a>
|
|
170
|
+
<ul>
|
|
171
|
+
<li><a href="https://intlayer.org/doc/concept/content/per-locale-file" rel=''>Per-Locale Content Declaration File</a></li>
|
|
172
|
+
<li><a href="https://intlayer.org/doc/concept/content/translation" rel=''>Translation</a></li>
|
|
173
|
+
<li><a href="https://intlayer.org/doc/concept/content/enumeration" rel=''>Enumeration</a></li>
|
|
174
|
+
<li><a href="https://intlayer.org/doc/concept/content/condition" rel=''>Condition</a></li>
|
|
175
|
+
<li><a href="https://intlayer.org/doc/concept/content/nesting" rel=''>Nesting</a></li>
|
|
176
|
+
<li><a href="https://intlayer.org/doc/concept/content/markdown" rel=''>Markdown</a></li>
|
|
177
|
+
<li><a href="https://intlayer.org/doc/concept/content/function-fetching" rel=''>Function Fetching</a></li>
|
|
178
|
+
<li><a href="https://intlayer.org/doc/concept/content/insertion" rel=''>Insertion</a></li>
|
|
179
|
+
<li><a href="https://intlayer.org/doc/concept/content/file" rel=''>File</a></li>
|
|
180
|
+
</ul>
|
|
181
|
+
</li>
|
|
182
|
+
</ul>
|
|
183
|
+
</details>
|
|
184
|
+
|
|
185
|
+
<details open>
|
|
186
|
+
<summary style="font-size:16px; font-weight:bold;">🌐 Environment</summary>
|
|
187
|
+
<ul>
|
|
188
|
+
<li><a href="https://intlayer.org/doc/environment/nextjs" rel=''>Intlayer with Next.js 16</a>
|
|
189
|
+
<ul>
|
|
190
|
+
<li><a href="https://intlayer.org/doc/environment/nextjs/15" rel=''>Next.js 15</a></li>
|
|
191
|
+
<li><a href="https://intlayer.org/doc/environment/nextjs/14" rel=''>Next.js 14 (App Router)</a></li>
|
|
192
|
+
<li><a href="https://intlayer.org/doc/environment/nextjs/next-with-Page-Router" rel=''>Next.js Page Router</a></li>
|
|
193
|
+
</ul>
|
|
194
|
+
</li>
|
|
195
|
+
<li><a href="https://intlayer.org/doc/environment/create-react-app" rel=''>React CRA</a></li>
|
|
196
|
+
<li><a href="https://intlayer.org/doc/environment/vite-and-react" rel=''>Vite + React</a>
|
|
197
|
+
<ul>
|
|
198
|
+
<li><a href="https://intlayer.org/doc/environment/vite-and-react/react-router-v7" rel=''>React-router-v7</a></li>
|
|
199
|
+
<li><a href="https://intlayer.org/doc/environment/vite-and-react/tanstack-start" rel=''>Tanstack start</a></li>
|
|
200
|
+
</ul>
|
|
201
|
+
</li>
|
|
202
|
+
<li><a href="https://intlayer.org/doc/environment/react-native-and-expo" rel=''>React Native</a></li>
|
|
203
|
+
<li><a href="https://intlayer.org/doc/environment/lynx-and-react" rel=''>Lynx + React</a></li>
|
|
204
|
+
<li><a href="https://intlayer.org/doc/environment/vite-and-svelte" rel=''>Vite + Svelte</a></li>
|
|
205
|
+
<li><a href="https://intlayer.org/doc/environment/sveltekit" rel=''>SvelteKit</a></li>
|
|
206
|
+
<li><a href="https://intlayer.org/doc/environment/vite-and-preact" rel=''>Vite + Preact</a></li>
|
|
207
|
+
<li><a href="https://intlayer.org/doc/environment/vite-and-vue" rel=''>Vite + Vue</a></li>
|
|
208
|
+
<li><a href="https://intlayer.org/doc/environment/vite-and-nuxt" rel=''>Vite + Nuxt</a></li>
|
|
209
|
+
<li><a href="https://intlayer.org/doc/environment/vite-and-solid" rel=''>Vite + Solid</a></li>
|
|
210
|
+
<li><a href="https://intlayer.org/doc/environment/angular" rel=''>Angular</a></li>
|
|
211
|
+
<li><a href="https://intlayer.org/doc/environment/express" rel=''>Express</a></li>
|
|
212
|
+
<li><a href="https://intlayer.org/doc/environment/hono" rel=''>Hono</a></li>
|
|
213
|
+
<li><a href="https://intlayer.org/doc/environment/nest" rel=''>NestJS</a></li>
|
|
214
|
+
</ul>
|
|
215
|
+
</details>
|
|
216
|
+
|
|
217
|
+
<details>
|
|
218
|
+
<summary style="font-size:16px; font-weight:bold;">📰 Blog</summary>
|
|
219
|
+
<ul>
|
|
220
|
+
<li><a href="https://github.com/aymericzip/intlayer/blob/main/docs/blog/en/what_is_internationalization.md" rel=''>What is i18n</a></li>
|
|
221
|
+
<li><a href="https://intlayer.org/blog/SEO-and-i18n" rel=''>i18n and SEO</a></li>
|
|
222
|
+
<li><a href="https://intlayer.org/blog/intlayer-with-next-i18next" rel=''>Intlayer and i18next</a></li>
|
|
223
|
+
<li><a href="https://intlayer.org/blog/intlayer-with-react-i18next" rel=''>Intlayer and react-intl</a></li>
|
|
224
|
+
<li><a href="https://intlayer.org/blog/intlayer-with-next-intl" rel=''>Intlayer and next-intl</a></li>
|
|
225
|
+
</ul>
|
|
226
|
+
</details>
|
|
227
|
+
|
|
228
|
+
## 🌐 Readme in other languages
|
|
229
|
+
|
|
230
|
+
<p align="center">
|
|
231
|
+
<a href="https://github.com/aymericzip/intlayer/blob/main/readme.md">English</a> •
|
|
232
|
+
<a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/zh/readme.md">简体中文</a> •
|
|
233
|
+
<a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/ru/readme.md">Русский</a> •
|
|
234
|
+
<a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/ja/readme.md">日本語</a> •
|
|
235
|
+
<a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/fr/readme.md">Français</a> •
|
|
236
|
+
<a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/ko/readme.md">한국어</a> •
|
|
237
|
+
<a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/es/readme.md">Español</a> •
|
|
238
|
+
<a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/de/readme.md">Deutsch</a> •
|
|
239
|
+
<a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/ar/readme.md">العربية</a> •
|
|
240
|
+
<a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/it/readme.md">Italiano</a> •
|
|
241
|
+
<a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/en-GB/readme.md">English (UK)</a> •
|
|
242
|
+
<a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/pt/readme.md">Português</a> •
|
|
243
|
+
<a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/hi/readme.md">हिन्दी</a> •
|
|
244
|
+
<a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/tr/readme.md">Türkçe</a>
|
|
245
|
+
</p>
|
|
246
|
+
|
|
247
|
+
## 🤝 Community
|
|
248
|
+
|
|
249
|
+
Intlayer is built with and for the community and we’d love your input!
|
|
250
|
+
|
|
251
|
+
- Have a suggestion? [Open an issue](https://github.com/aymericzip/intlayer/issues)
|
|
252
|
+
- Found a bug or improvement? [Submit a PR](https://github.com/aymericzip/intlayer/pulls)
|
|
253
|
+
- Need help or want to connect? [Join our Discord](https://discord.gg/7uxamYVeCk)
|
|
254
|
+
|
|
255
|
+
You can also follow us on :
|
|
256
|
+
|
|
257
|
+
<div>
|
|
258
|
+
<br/>
|
|
259
|
+
<p align="center">
|
|
260
|
+
<a href="https://discord.gg/528mBV4N" target="blank" rel='noopener noreferrer nofollow'><img align="center"
|
|
261
|
+
src="https://img.shields.io/badge/discord-5865F2.svg?style=for-the-badge&logo=discord&logoColor=white"
|
|
262
|
+
alt="Intlayer Discord" height="30"/></a>
|
|
263
|
+
<a href="https://www.linkedin.com/company/intlayerorg" target="blank" rel='noopener noreferrer nofollow'><img align="center"
|
|
264
|
+
src="https://img.shields.io/badge/linkedin-%231DA1F2.svg?style=for-the-badge&logo=linkedin&logoColor=white"
|
|
265
|
+
alt="Intlayer LinkedIn" height="30"/></a>
|
|
266
|
+
<a href="https://www.instagram.com/intlayer/" target="blank" rel='noopener noreferrer nofollow'><img align="center"
|
|
267
|
+
src="https://img.shields.io/badge/instagram-%23E4405F.svg?style=for-the-badge&logo=Instagram&logoColor=white"
|
|
268
|
+
alt="Intlayer Instagram" height="30"/></a>
|
|
269
|
+
<a href="https://x.com/Intlayer183096" target="blank" rel='noopener noreferrer nofollow'><img align="center"
|
|
270
|
+
src="https://img.shields.io/badge/x-1DA1F2.svg?style=for-the-badge&logo=x&logoColor=white"
|
|
271
|
+
alt="Intlayer X" height="30"/></a>
|
|
272
|
+
<a href="https://www.youtube.com/@intlayer" target="blank" rel='noopener noreferrer nofollow'><img align="center"
|
|
273
|
+
src="https://img.shields.io/badge/youtube-FF0000.svg?style=for-the-badge&logo=youtube&logoColor=white"
|
|
274
|
+
alt="Intlayer YouTube" height="30"/></a>
|
|
275
|
+
<a href="https://www.tiktok.com/@intlayer" target="blank" rel='noopener noreferrer nofollow'><img align="center"
|
|
276
|
+
src="https://img.shields.io/badge/tiktok-000000.svg?style=for-the-badge&logo=tiktok&logoColor=white"
|
|
277
|
+
alt="Intlayer TikTok" height="30"/></a>
|
|
278
|
+
<br>
|
|
279
|
+
</p>
|
|
280
|
+
</div>
|
|
281
|
+
|
|
282
|
+
### Contribution
|
|
283
|
+
|
|
284
|
+
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!
|
|
285
|
+
|
|
286
|
+
Contribute on [GitHub](https://github.com/aymericzip/intlayer), [GitLab](https://gitlab.com/ay.pineau/intlayer), or [Bitbucket](https://bitbucket.org/intlayer/intlayer/).
|
|
287
|
+
|
|
288
|
+
### Thank You for the Support
|
|
289
|
+
|
|
290
|
+
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-).
|
|
291
|
+
|
|
292
|
+
[](https://star-history.com/#aymericzip/intlayer&Date)
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
let _intlayer_chokidar = require("@intlayer/chokidar");
|
|
2
|
+
let _intlayer_config = require("@intlayer/config");
|
|
3
|
+
let _intlayer_core = require("@intlayer/core");
|
|
4
|
+
let cls_hooked = require("cls-hooked");
|
|
5
|
+
let hono_cookie = require("hono/cookie");
|
|
6
|
+
|
|
7
|
+
//#region src/index.ts
|
|
8
|
+
const configuration = (0, _intlayer_config.getConfiguration)();
|
|
9
|
+
const { internationalization } = configuration;
|
|
10
|
+
/**
|
|
11
|
+
* Retrieves the locale from storage (cookies, headers).
|
|
12
|
+
*/
|
|
13
|
+
const getStorageLocale = (context) => (0, _intlayer_core.getLocaleFromStorage)({
|
|
14
|
+
getCookie: (name) => (0, hono_cookie.getCookie)(context, name),
|
|
15
|
+
getHeader: (name) => context.req.header(name)
|
|
16
|
+
});
|
|
17
|
+
const appNamespace = (0, cls_hooked.createNamespace)("app");
|
|
18
|
+
(0, _intlayer_chokidar.prepareIntlayer)(configuration);
|
|
19
|
+
const translateFunction = (context) => (content, locale) => {
|
|
20
|
+
const currentLocale = context.get("locale");
|
|
21
|
+
const defaultLocale = context.get("defaultLocale");
|
|
22
|
+
const targetLocale = locale ?? currentLocale;
|
|
23
|
+
if (typeof content === "undefined") return "";
|
|
24
|
+
if (typeof content === "string") return content;
|
|
25
|
+
if (typeof content?.[targetLocale] === "undefined") if (typeof content?.[defaultLocale] === "undefined") return content;
|
|
26
|
+
else return (0, _intlayer_core.getTranslation)(content, defaultLocale);
|
|
27
|
+
return (0, _intlayer_core.getTranslation)(content, targetLocale);
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Hono middleware that detects the user's locale and populates context with Intlayer data.
|
|
31
|
+
*
|
|
32
|
+
* It performs:
|
|
33
|
+
* 1. Locale detection from cookies, headers, or default settings.
|
|
34
|
+
* 2. Injects `t`, `getIntlayer`, and `getDictionary` functions into the context.
|
|
35
|
+
* 3. Sets up a `cls-hooked` namespace for accessing these functions anywhere in the request lifecycle.
|
|
36
|
+
*
|
|
37
|
+
* @returns A Hono middleware function.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* import { Hono } from 'hono';
|
|
42
|
+
* import { intlayer } from 'hono-intlayer';
|
|
43
|
+
*
|
|
44
|
+
* const app = new Hono();
|
|
45
|
+
* app.use('*', intlayer());
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
const intlayer = () => async (c, next) => {
|
|
49
|
+
const localeFromStorage = getStorageLocale(c);
|
|
50
|
+
const localeDetected = (0, _intlayer_core.localeDetector)(c.req.header(), internationalization.locales, internationalization.defaultLocale);
|
|
51
|
+
const locale = localeFromStorage ?? localeDetected;
|
|
52
|
+
c.set("locale_storage", localeFromStorage);
|
|
53
|
+
c.set("locale_detected", localeDetected);
|
|
54
|
+
c.set("locale", locale);
|
|
55
|
+
c.set("defaultLocale", internationalization.defaultLocale);
|
|
56
|
+
const t = translateFunction(c);
|
|
57
|
+
const getIntlayer = (key, localeArg = locale, ...props) => (0, _intlayer_core.getIntlayer)(key, localeArg, ...props);
|
|
58
|
+
const getDictionary = (key, localeArg = locale, ...props) => (0, _intlayer_core.getDictionary)(key, localeArg, ...props);
|
|
59
|
+
c.set("t", t);
|
|
60
|
+
c.set("getIntlayer", getIntlayer);
|
|
61
|
+
c.set("getDictionary", getDictionary);
|
|
62
|
+
return new Promise((resolve) => {
|
|
63
|
+
appNamespace.run(async () => {
|
|
64
|
+
appNamespace.set("t", t);
|
|
65
|
+
appNamespace.set("getIntlayer", getIntlayer);
|
|
66
|
+
appNamespace.set("getDictionary", getDictionary);
|
|
67
|
+
await next();
|
|
68
|
+
resolve();
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Translation function to retrieve content for the current locale.
|
|
74
|
+
*
|
|
75
|
+
* This function works within the request lifecycle managed by the `intlayer` middleware.
|
|
76
|
+
*
|
|
77
|
+
* @param content - A map of locales to content.
|
|
78
|
+
* @param locale - Optional locale override.
|
|
79
|
+
* @returns The translated content.
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```ts
|
|
83
|
+
* import { t } from 'hono-intlayer';
|
|
84
|
+
*
|
|
85
|
+
* app.get('/', (c) => {
|
|
86
|
+
* const greeting = t({
|
|
87
|
+
* en: 'Hello',
|
|
88
|
+
* fr: 'Bonjour',
|
|
89
|
+
* });
|
|
90
|
+
* return c.text(greeting);
|
|
91
|
+
* });
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
const t = (content, locale) => {
|
|
95
|
+
try {
|
|
96
|
+
if (typeof appNamespace === "undefined") throw new Error("Intlayer is not initialized. Add the `app.use(\"*\", intlayer());` middleware before using this function.");
|
|
97
|
+
if (typeof appNamespace.get("t") !== "function") throw new Error("Using the import { t } from \"hono-intlayer\" is not supported in your environment. Use the context instead.");
|
|
98
|
+
return appNamespace.get("t")(content, locale);
|
|
99
|
+
} catch (error) {
|
|
100
|
+
if (process.env.NODE_ENV === "development") console.error(error.message);
|
|
101
|
+
return (0, _intlayer_core.getTranslation)(content, locale ?? internationalization.defaultLocale);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
const getIntlayer = (...args) => {
|
|
105
|
+
try {
|
|
106
|
+
if (typeof appNamespace === "undefined") throw new Error("Intlayer is not initialized. Add the `app.use(\"*\", intlayer());` middleware before using this function.");
|
|
107
|
+
if (typeof appNamespace.get("getIntlayer") !== "function") throw new Error("Using the import { getIntlayer } from \"hono-intlayer\" is not supported in your environment. Use the context instead.");
|
|
108
|
+
return appNamespace.get("getIntlayer")(...args);
|
|
109
|
+
} catch (error) {
|
|
110
|
+
if (process.env.NODE_ENV === "development") console.error(error.message);
|
|
111
|
+
return (0, _intlayer_core.getIntlayer)(...args);
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
const getDictionary = (...args) => {
|
|
115
|
+
try {
|
|
116
|
+
if (typeof appNamespace === "undefined") throw new Error("Intlayer is not initialized. Add the `app.use(\"*\", intlayer());` middleware before using this function.");
|
|
117
|
+
if (typeof appNamespace.get("getDictionary") !== "function") throw new Error("Using the import { getDictionary } from \"hono-intlayer\" is not supported in your environment. Use the context instead.");
|
|
118
|
+
return appNamespace.get("getDictionary")(...args);
|
|
119
|
+
} catch (error) {
|
|
120
|
+
if (process.env.NODE_ENV === "development") console.error(error.message);
|
|
121
|
+
return (0, _intlayer_core.getDictionary)(...args);
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
//#endregion
|
|
126
|
+
exports.getDictionary = getDictionary;
|
|
127
|
+
exports.getIntlayer = getIntlayer;
|
|
128
|
+
exports.intlayer = intlayer;
|
|
129
|
+
exports.t = t;
|
|
130
|
+
exports.translateFunction = translateFunction;
|
|
131
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","names":[],"sources":["../../src/index.ts"],"sourcesContent":["import { prepareIntlayer } from '@intlayer/chokidar';\nimport { getConfiguration } from '@intlayer/config';\nimport {\n getDictionary as getDictionaryFunction,\n getIntlayer as getIntlayerFunction,\n getLocaleFromStorage,\n getTranslation,\n localeDetector,\n} from '@intlayer/core';\nimport type { Locale, StrictModeLocaleMap } from '@intlayer/types';\nimport { createNamespace } from 'cls-hooked';\nimport type { Context, MiddlewareHandler } from 'hono';\nimport { getCookie } from 'hono/cookie';\n\nconst configuration = getConfiguration();\nconst { internationalization } = configuration;\n\n/**\n * Retrieves the locale from storage (cookies, headers).\n */\nconst getStorageLocale = (context: Context): Locale | undefined =>\n getLocaleFromStorage({\n getCookie: (name: string) => getCookie(context, name),\n getHeader: (name: string) => context.req.header(name),\n });\n\nconst appNamespace = createNamespace('app');\n\nprepareIntlayer(configuration);\n\nexport const translateFunction =\n (context: Context) =>\n <T extends string>(\n content: StrictModeLocaleMap<T> | string,\n locale?: Locale\n ): T => {\n const currentLocale = context.get('locale') as Locale;\n const defaultLocale = context.get('defaultLocale') as Locale;\n\n const targetLocale = locale ?? currentLocale;\n\n if (typeof content === 'undefined') {\n return '' as unknown as T;\n }\n\n if (typeof content === 'string') {\n return content as unknown as T;\n }\n\n if (\n typeof content?.[\n targetLocale as unknown as keyof StrictModeLocaleMap<T>\n ] === 'undefined'\n ) {\n if (\n typeof content?.[\n defaultLocale as unknown as keyof StrictModeLocaleMap<T>\n ] === 'undefined'\n ) {\n return content as unknown as T;\n } else {\n return getTranslation(content, defaultLocale);\n }\n }\n\n return getTranslation(content, targetLocale);\n };\n\n/**\n * Hono middleware that detects the user's locale and populates context with Intlayer data.\n *\n * It performs:\n * 1. Locale detection from cookies, headers, or default settings.\n * 2. Injects `t`, `getIntlayer`, and `getDictionary` functions into the context.\n * 3. Sets up a `cls-hooked` namespace for accessing these functions anywhere in the request lifecycle.\n *\n * @returns A Hono middleware function.\n *\n * @example\n * ```ts\n * import { Hono } from 'hono';\n * import { intlayer } from 'hono-intlayer';\n *\n * const app = new Hono();\n * app.use('*', intlayer());\n * ```\n */\nexport const intlayer =\n (): MiddlewareHandler => async (c: Context, next: () => Promise<void>) => {\n // Detect if locale is set by intlayer frontend lib in the headers\n const localeFromStorage = getStorageLocale(c);\n\n const negotiatorHeaders: Record<string, string> = c.req.header();\n\n const localeDetected = localeDetector(\n negotiatorHeaders,\n internationalization.locales,\n internationalization.defaultLocale\n );\n\n const locale = localeFromStorage ?? localeDetected;\n\n c.set('locale_storage', localeFromStorage);\n c.set('locale_detected', localeDetected);\n c.set('locale', locale);\n c.set('defaultLocale', internationalization.defaultLocale);\n\n const t = translateFunction(c);\n\n const getIntlayer: typeof getIntlayerFunction = (\n key: Parameters<typeof getIntlayerFunction>[0],\n localeArg = locale as Parameters<typeof getIntlayerFunction>[1],\n ...props: any[]\n ) => getIntlayerFunction(key, localeArg, ...props);\n\n const getDictionary: typeof getDictionaryFunction = (\n key: Parameters<typeof getDictionaryFunction>[0],\n localeArg = locale as Parameters<typeof getDictionaryFunction>[1],\n ...props: any[]\n ) => getDictionaryFunction(key, localeArg, ...props);\n\n c.set('t', t);\n c.set('getIntlayer', getIntlayer);\n c.set('getDictionary', getDictionary);\n\n return new Promise<void>((resolve) => {\n appNamespace.run(async () => {\n appNamespace.set('t', t);\n appNamespace.set('getIntlayer', getIntlayer);\n appNamespace.set('getDictionary', getDictionary);\n\n await next();\n resolve();\n });\n });\n };\n\n/**\n * Translation function to retrieve content for the current locale.\n *\n * This function works within the request lifecycle managed by the `intlayer` middleware.\n *\n * @param content - A map of locales to content.\n * @param locale - Optional locale override.\n * @returns The translated content.\n *\n * @example\n * ```ts\n * import { t } from 'hono-intlayer';\n *\n * app.get('/', (c) => {\n * const greeting = t({\n * en: 'Hello',\n * fr: 'Bonjour',\n * });\n * return c.text(greeting);\n * });\n * ```\n */\nexport const t = <Content = string>(\n content: StrictModeLocaleMap<Content>,\n locale?: Locale\n): Content => {\n try {\n if (typeof appNamespace === 'undefined') {\n throw new Error(\n 'Intlayer is not initialized. Add the `app.use(\"*\", intlayer());` middleware before using this function.'\n );\n }\n\n if (typeof appNamespace.get('t') !== 'function') {\n throw new Error(\n 'Using the import { t } from \"hono-intlayer\" is not supported in your environment. Use the context instead.'\n );\n }\n\n return appNamespace.get('t')(content, locale);\n } catch (error) {\n if (process.env.NODE_ENV === 'development') {\n console.error((error as Error).message);\n }\n\n return getTranslation(\n content,\n locale ?? internationalization.defaultLocale\n );\n }\n};\n\nexport const getIntlayer: typeof getIntlayerFunction = (\n ...args: Parameters<typeof getIntlayerFunction>\n) => {\n try {\n if (typeof appNamespace === 'undefined') {\n throw new Error(\n 'Intlayer is not initialized. Add the `app.use(\"*\", intlayer());` middleware before using this function.'\n );\n }\n\n if (typeof appNamespace.get('getIntlayer') !== 'function') {\n throw new Error(\n 'Using the import { getIntlayer } from \"hono-intlayer\" is not supported in your environment. Use the context instead.'\n );\n }\n\n return appNamespace.get('getIntlayer')(...args);\n } catch (error) {\n if (process.env.NODE_ENV === 'development') {\n console.error((error as Error).message);\n }\n return getIntlayerFunction(...args);\n }\n};\n\nexport const getDictionary: typeof getDictionaryFunction = (\n ...args: Parameters<typeof getDictionaryFunction>\n) => {\n try {\n if (typeof appNamespace === 'undefined') {\n throw new Error(\n 'Intlayer is not initialized. Add the `app.use(\"*\", intlayer());` middleware before using this function.'\n );\n }\n\n if (typeof appNamespace.get('getDictionary') !== 'function') {\n throw new Error(\n 'Using the import { getDictionary } from \"hono-intlayer\" is not supported in your environment. Use the context instead.'\n );\n }\n\n return appNamespace.get('getDictionary')(...args);\n } catch (error) {\n if (process.env.NODE_ENV === 'development') {\n console.error((error as Error).message);\n }\n return getDictionaryFunction(...args);\n }\n};\n"],"mappings":";;;;;;;AAcA,MAAM,wDAAkC;AACxC,MAAM,EAAE,yBAAyB;;;;AAKjC,MAAM,oBAAoB,qDACH;CACnB,YAAY,oCAA2B,SAAS,KAAK;CACrD,YAAY,SAAiB,QAAQ,IAAI,OAAO,KAAK;CACtD,CAAC;AAEJ,MAAM,+CAA+B,MAAM;wCAE3B,cAAc;AAE9B,MAAa,qBACV,aAEC,SACA,WACM;CACN,MAAM,gBAAgB,QAAQ,IAAI,SAAS;CAC3C,MAAM,gBAAgB,QAAQ,IAAI,gBAAgB;CAElD,MAAM,eAAe,UAAU;AAE/B,KAAI,OAAO,YAAY,YACrB,QAAO;AAGT,KAAI,OAAO,YAAY,SACrB,QAAO;AAGT,KACE,OAAO,UACL,kBACI,YAEN,KACE,OAAO,UACL,mBACI,YAEN,QAAO;KAEP,2CAAsB,SAAS,cAAc;AAIjD,2CAAsB,SAAS,aAAa;;;;;;;;;;;;;;;;;;;;;AAsBhD,MAAa,iBACc,OAAO,GAAY,SAA8B;CAExE,MAAM,oBAAoB,iBAAiB,EAAE;CAI7C,MAAM,oDAF4C,EAAE,IAAI,QAAQ,EAI9D,qBAAqB,SACrB,qBAAqB,cACtB;CAED,MAAM,SAAS,qBAAqB;AAEpC,GAAE,IAAI,kBAAkB,kBAAkB;AAC1C,GAAE,IAAI,mBAAmB,eAAe;AACxC,GAAE,IAAI,UAAU,OAAO;AACvB,GAAE,IAAI,iBAAiB,qBAAqB,cAAc;CAE1D,MAAM,IAAI,kBAAkB,EAAE;CAE9B,MAAM,eACJ,KACA,YAAY,QACZ,GAAG,0CACoB,KAAK,WAAW,GAAG,MAAM;CAElD,MAAM,iBACJ,KACA,YAAY,QACZ,GAAG,4CACsB,KAAK,WAAW,GAAG,MAAM;AAEpD,GAAE,IAAI,KAAK,EAAE;AACb,GAAE,IAAI,eAAe,YAAY;AACjC,GAAE,IAAI,iBAAiB,cAAc;AAErC,QAAO,IAAI,SAAe,YAAY;AACpC,eAAa,IAAI,YAAY;AAC3B,gBAAa,IAAI,KAAK,EAAE;AACxB,gBAAa,IAAI,eAAe,YAAY;AAC5C,gBAAa,IAAI,iBAAiB,cAAc;AAEhD,SAAM,MAAM;AACZ,YAAS;IACT;GACF;;;;;;;;;;;;;;;;;;;;;;;;AAyBN,MAAa,KACX,SACA,WACY;AACZ,KAAI;AACF,MAAI,OAAO,iBAAiB,YAC1B,OAAM,IAAI,MACR,4GACD;AAGH,MAAI,OAAO,aAAa,IAAI,IAAI,KAAK,WACnC,OAAM,IAAI,MACR,+GACD;AAGH,SAAO,aAAa,IAAI,IAAI,CAAC,SAAS,OAAO;UACtC,OAAO;AACd,MAAI,QAAQ,IAAI,aAAa,cAC3B,SAAQ,MAAO,MAAgB,QAAQ;AAGzC,4CACE,SACA,UAAU,qBAAqB,cAChC;;;AAIL,MAAa,eACX,GAAG,SACA;AACH,KAAI;AACF,MAAI,OAAO,iBAAiB,YAC1B,OAAM,IAAI,MACR,4GACD;AAGH,MAAI,OAAO,aAAa,IAAI,cAAc,KAAK,WAC7C,OAAM,IAAI,MACR,yHACD;AAGH,SAAO,aAAa,IAAI,cAAc,CAAC,GAAG,KAAK;UACxC,OAAO;AACd,MAAI,QAAQ,IAAI,aAAa,cAC3B,SAAQ,MAAO,MAAgB,QAAQ;AAEzC,yCAA2B,GAAG,KAAK;;;AAIvC,MAAa,iBACX,GAAG,SACA;AACH,KAAI;AACF,MAAI,OAAO,iBAAiB,YAC1B,OAAM,IAAI,MACR,4GACD;AAGH,MAAI,OAAO,aAAa,IAAI,gBAAgB,KAAK,WAC/C,OAAM,IAAI,MACR,2HACD;AAGH,SAAO,aAAa,IAAI,gBAAgB,CAAC,GAAG,KAAK;UAC1C,OAAO;AACd,MAAI,QAAQ,IAAI,aAAa,cAC3B,SAAQ,MAAO,MAAgB,QAAQ;AAEzC,2CAA6B,GAAG,KAAK"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { prepareIntlayer } from "@intlayer/chokidar";
|
|
2
|
+
import { getConfiguration } from "@intlayer/config";
|
|
3
|
+
import { getDictionary as getDictionary$1, getIntlayer as getIntlayer$1, getLocaleFromStorage, getTranslation, localeDetector } from "@intlayer/core";
|
|
4
|
+
import { createNamespace } from "cls-hooked";
|
|
5
|
+
import { getCookie } from "hono/cookie";
|
|
6
|
+
|
|
7
|
+
//#region src/index.ts
|
|
8
|
+
const configuration = getConfiguration();
|
|
9
|
+
const { internationalization } = configuration;
|
|
10
|
+
/**
|
|
11
|
+
* Retrieves the locale from storage (cookies, headers).
|
|
12
|
+
*/
|
|
13
|
+
const getStorageLocale = (context) => getLocaleFromStorage({
|
|
14
|
+
getCookie: (name) => getCookie(context, name),
|
|
15
|
+
getHeader: (name) => context.req.header(name)
|
|
16
|
+
});
|
|
17
|
+
const appNamespace = createNamespace("app");
|
|
18
|
+
prepareIntlayer(configuration);
|
|
19
|
+
const translateFunction = (context) => (content, locale) => {
|
|
20
|
+
const currentLocale = context.get("locale");
|
|
21
|
+
const defaultLocale = context.get("defaultLocale");
|
|
22
|
+
const targetLocale = locale ?? currentLocale;
|
|
23
|
+
if (typeof content === "undefined") return "";
|
|
24
|
+
if (typeof content === "string") return content;
|
|
25
|
+
if (typeof content?.[targetLocale] === "undefined") if (typeof content?.[defaultLocale] === "undefined") return content;
|
|
26
|
+
else return getTranslation(content, defaultLocale);
|
|
27
|
+
return getTranslation(content, targetLocale);
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Hono middleware that detects the user's locale and populates context with Intlayer data.
|
|
31
|
+
*
|
|
32
|
+
* It performs:
|
|
33
|
+
* 1. Locale detection from cookies, headers, or default settings.
|
|
34
|
+
* 2. Injects `t`, `getIntlayer`, and `getDictionary` functions into the context.
|
|
35
|
+
* 3. Sets up a `cls-hooked` namespace for accessing these functions anywhere in the request lifecycle.
|
|
36
|
+
*
|
|
37
|
+
* @returns A Hono middleware function.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* import { Hono } from 'hono';
|
|
42
|
+
* import { intlayer } from 'hono-intlayer';
|
|
43
|
+
*
|
|
44
|
+
* const app = new Hono();
|
|
45
|
+
* app.use('*', intlayer());
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
const intlayer = () => async (c, next) => {
|
|
49
|
+
const localeFromStorage = getStorageLocale(c);
|
|
50
|
+
const localeDetected = localeDetector(c.req.header(), internationalization.locales, internationalization.defaultLocale);
|
|
51
|
+
const locale = localeFromStorage ?? localeDetected;
|
|
52
|
+
c.set("locale_storage", localeFromStorage);
|
|
53
|
+
c.set("locale_detected", localeDetected);
|
|
54
|
+
c.set("locale", locale);
|
|
55
|
+
c.set("defaultLocale", internationalization.defaultLocale);
|
|
56
|
+
const t = translateFunction(c);
|
|
57
|
+
const getIntlayer = (key, localeArg = locale, ...props) => getIntlayer$1(key, localeArg, ...props);
|
|
58
|
+
const getDictionary = (key, localeArg = locale, ...props) => getDictionary$1(key, localeArg, ...props);
|
|
59
|
+
c.set("t", t);
|
|
60
|
+
c.set("getIntlayer", getIntlayer);
|
|
61
|
+
c.set("getDictionary", getDictionary);
|
|
62
|
+
return new Promise((resolve) => {
|
|
63
|
+
appNamespace.run(async () => {
|
|
64
|
+
appNamespace.set("t", t);
|
|
65
|
+
appNamespace.set("getIntlayer", getIntlayer);
|
|
66
|
+
appNamespace.set("getDictionary", getDictionary);
|
|
67
|
+
await next();
|
|
68
|
+
resolve();
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Translation function to retrieve content for the current locale.
|
|
74
|
+
*
|
|
75
|
+
* This function works within the request lifecycle managed by the `intlayer` middleware.
|
|
76
|
+
*
|
|
77
|
+
* @param content - A map of locales to content.
|
|
78
|
+
* @param locale - Optional locale override.
|
|
79
|
+
* @returns The translated content.
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```ts
|
|
83
|
+
* import { t } from 'hono-intlayer';
|
|
84
|
+
*
|
|
85
|
+
* app.get('/', (c) => {
|
|
86
|
+
* const greeting = t({
|
|
87
|
+
* en: 'Hello',
|
|
88
|
+
* fr: 'Bonjour',
|
|
89
|
+
* });
|
|
90
|
+
* return c.text(greeting);
|
|
91
|
+
* });
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
const t = (content, locale) => {
|
|
95
|
+
try {
|
|
96
|
+
if (typeof appNamespace === "undefined") throw new Error("Intlayer is not initialized. Add the `app.use(\"*\", intlayer());` middleware before using this function.");
|
|
97
|
+
if (typeof appNamespace.get("t") !== "function") throw new Error("Using the import { t } from \"hono-intlayer\" is not supported in your environment. Use the context instead.");
|
|
98
|
+
return appNamespace.get("t")(content, locale);
|
|
99
|
+
} catch (error) {
|
|
100
|
+
console.error(error.message);
|
|
101
|
+
return getTranslation(content, locale ?? internationalization.defaultLocale);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
const getIntlayer = (...args) => {
|
|
105
|
+
try {
|
|
106
|
+
if (typeof appNamespace === "undefined") throw new Error("Intlayer is not initialized. Add the `app.use(\"*\", intlayer());` middleware before using this function.");
|
|
107
|
+
if (typeof appNamespace.get("getIntlayer") !== "function") throw new Error("Using the import { getIntlayer } from \"hono-intlayer\" is not supported in your environment. Use the context instead.");
|
|
108
|
+
return appNamespace.get("getIntlayer")(...args);
|
|
109
|
+
} catch (error) {
|
|
110
|
+
console.error(error.message);
|
|
111
|
+
return getIntlayer$1(...args);
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
const getDictionary = (...args) => {
|
|
115
|
+
try {
|
|
116
|
+
if (typeof appNamespace === "undefined") throw new Error("Intlayer is not initialized. Add the `app.use(\"*\", intlayer());` middleware before using this function.");
|
|
117
|
+
if (typeof appNamespace.get("getDictionary") !== "function") throw new Error("Using the import { getDictionary } from \"hono-intlayer\" is not supported in your environment. Use the context instead.");
|
|
118
|
+
return appNamespace.get("getDictionary")(...args);
|
|
119
|
+
} catch (error) {
|
|
120
|
+
console.error(error.message);
|
|
121
|
+
return getDictionary$1(...args);
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
//#endregion
|
|
126
|
+
export { getDictionary, getIntlayer, intlayer, t, translateFunction };
|
|
127
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["getIntlayerFunction","getDictionaryFunction"],"sources":["../../src/index.ts"],"sourcesContent":["import { prepareIntlayer } from '@intlayer/chokidar';\nimport { getConfiguration } from '@intlayer/config';\nimport {\n getDictionary as getDictionaryFunction,\n getIntlayer as getIntlayerFunction,\n getLocaleFromStorage,\n getTranslation,\n localeDetector,\n} from '@intlayer/core';\nimport type { Locale, StrictModeLocaleMap } from '@intlayer/types';\nimport { createNamespace } from 'cls-hooked';\nimport type { Context, MiddlewareHandler } from 'hono';\nimport { getCookie } from 'hono/cookie';\n\nconst configuration = getConfiguration();\nconst { internationalization } = configuration;\n\n/**\n * Retrieves the locale from storage (cookies, headers).\n */\nconst getStorageLocale = (context: Context): Locale | undefined =>\n getLocaleFromStorage({\n getCookie: (name: string) => getCookie(context, name),\n getHeader: (name: string) => context.req.header(name),\n });\n\nconst appNamespace = createNamespace('app');\n\nprepareIntlayer(configuration);\n\nexport const translateFunction =\n (context: Context) =>\n <T extends string>(\n content: StrictModeLocaleMap<T> | string,\n locale?: Locale\n ): T => {\n const currentLocale = context.get('locale') as Locale;\n const defaultLocale = context.get('defaultLocale') as Locale;\n\n const targetLocale = locale ?? currentLocale;\n\n if (typeof content === 'undefined') {\n return '' as unknown as T;\n }\n\n if (typeof content === 'string') {\n return content as unknown as T;\n }\n\n if (\n typeof content?.[\n targetLocale as unknown as keyof StrictModeLocaleMap<T>\n ] === 'undefined'\n ) {\n if (\n typeof content?.[\n defaultLocale as unknown as keyof StrictModeLocaleMap<T>\n ] === 'undefined'\n ) {\n return content as unknown as T;\n } else {\n return getTranslation(content, defaultLocale);\n }\n }\n\n return getTranslation(content, targetLocale);\n };\n\n/**\n * Hono middleware that detects the user's locale and populates context with Intlayer data.\n *\n * It performs:\n * 1. Locale detection from cookies, headers, or default settings.\n * 2. Injects `t`, `getIntlayer`, and `getDictionary` functions into the context.\n * 3. Sets up a `cls-hooked` namespace for accessing these functions anywhere in the request lifecycle.\n *\n * @returns A Hono middleware function.\n *\n * @example\n * ```ts\n * import { Hono } from 'hono';\n * import { intlayer } from 'hono-intlayer';\n *\n * const app = new Hono();\n * app.use('*', intlayer());\n * ```\n */\nexport const intlayer =\n (): MiddlewareHandler => async (c: Context, next: () => Promise<void>) => {\n // Detect if locale is set by intlayer frontend lib in the headers\n const localeFromStorage = getStorageLocale(c);\n\n const negotiatorHeaders: Record<string, string> = c.req.header();\n\n const localeDetected = localeDetector(\n negotiatorHeaders,\n internationalization.locales,\n internationalization.defaultLocale\n );\n\n const locale = localeFromStorage ?? localeDetected;\n\n c.set('locale_storage', localeFromStorage);\n c.set('locale_detected', localeDetected);\n c.set('locale', locale);\n c.set('defaultLocale', internationalization.defaultLocale);\n\n const t = translateFunction(c);\n\n const getIntlayer: typeof getIntlayerFunction = (\n key: Parameters<typeof getIntlayerFunction>[0],\n localeArg = locale as Parameters<typeof getIntlayerFunction>[1],\n ...props: any[]\n ) => getIntlayerFunction(key, localeArg, ...props);\n\n const getDictionary: typeof getDictionaryFunction = (\n key: Parameters<typeof getDictionaryFunction>[0],\n localeArg = locale as Parameters<typeof getDictionaryFunction>[1],\n ...props: any[]\n ) => getDictionaryFunction(key, localeArg, ...props);\n\n c.set('t', t);\n c.set('getIntlayer', getIntlayer);\n c.set('getDictionary', getDictionary);\n\n return new Promise<void>((resolve) => {\n appNamespace.run(async () => {\n appNamespace.set('t', t);\n appNamespace.set('getIntlayer', getIntlayer);\n appNamespace.set('getDictionary', getDictionary);\n\n await next();\n resolve();\n });\n });\n };\n\n/**\n * Translation function to retrieve content for the current locale.\n *\n * This function works within the request lifecycle managed by the `intlayer` middleware.\n *\n * @param content - A map of locales to content.\n * @param locale - Optional locale override.\n * @returns The translated content.\n *\n * @example\n * ```ts\n * import { t } from 'hono-intlayer';\n *\n * app.get('/', (c) => {\n * const greeting = t({\n * en: 'Hello',\n * fr: 'Bonjour',\n * });\n * return c.text(greeting);\n * });\n * ```\n */\nexport const t = <Content = string>(\n content: StrictModeLocaleMap<Content>,\n locale?: Locale\n): Content => {\n try {\n if (typeof appNamespace === 'undefined') {\n throw new Error(\n 'Intlayer is not initialized. Add the `app.use(\"*\", intlayer());` middleware before using this function.'\n );\n }\n\n if (typeof appNamespace.get('t') !== 'function') {\n throw new Error(\n 'Using the import { t } from \"hono-intlayer\" is not supported in your environment. Use the context instead.'\n );\n }\n\n return appNamespace.get('t')(content, locale);\n } catch (error) {\n if (process.env.NODE_ENV === 'development') {\n console.error((error as Error).message);\n }\n\n return getTranslation(\n content,\n locale ?? internationalization.defaultLocale\n );\n }\n};\n\nexport const getIntlayer: typeof getIntlayerFunction = (\n ...args: Parameters<typeof getIntlayerFunction>\n) => {\n try {\n if (typeof appNamespace === 'undefined') {\n throw new Error(\n 'Intlayer is not initialized. Add the `app.use(\"*\", intlayer());` middleware before using this function.'\n );\n }\n\n if (typeof appNamespace.get('getIntlayer') !== 'function') {\n throw new Error(\n 'Using the import { getIntlayer } from \"hono-intlayer\" is not supported in your environment. Use the context instead.'\n );\n }\n\n return appNamespace.get('getIntlayer')(...args);\n } catch (error) {\n if (process.env.NODE_ENV === 'development') {\n console.error((error as Error).message);\n }\n return getIntlayerFunction(...args);\n }\n};\n\nexport const getDictionary: typeof getDictionaryFunction = (\n ...args: Parameters<typeof getDictionaryFunction>\n) => {\n try {\n if (typeof appNamespace === 'undefined') {\n throw new Error(\n 'Intlayer is not initialized. Add the `app.use(\"*\", intlayer());` middleware before using this function.'\n );\n }\n\n if (typeof appNamespace.get('getDictionary') !== 'function') {\n throw new Error(\n 'Using the import { getDictionary } from \"hono-intlayer\" is not supported in your environment. Use the context instead.'\n );\n }\n\n return appNamespace.get('getDictionary')(...args);\n } catch (error) {\n if (process.env.NODE_ENV === 'development') {\n console.error((error as Error).message);\n }\n return getDictionaryFunction(...args);\n }\n};\n"],"mappings":"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"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { getDictionary as getDictionary$1, getIntlayer as getIntlayer$1 } from "@intlayer/core";
|
|
2
|
+
import { Locale, StrictModeLocaleMap } from "@intlayer/types";
|
|
3
|
+
import { Context, MiddlewareHandler } from "hono";
|
|
4
|
+
|
|
5
|
+
//#region src/index.d.ts
|
|
6
|
+
declare const translateFunction: (context: Context) => <T extends string>(content: StrictModeLocaleMap<T> | string, locale?: Locale) => T;
|
|
7
|
+
/**
|
|
8
|
+
* Hono middleware that detects the user's locale and populates context with Intlayer data.
|
|
9
|
+
*
|
|
10
|
+
* It performs:
|
|
11
|
+
* 1. Locale detection from cookies, headers, or default settings.
|
|
12
|
+
* 2. Injects `t`, `getIntlayer`, and `getDictionary` functions into the context.
|
|
13
|
+
* 3. Sets up a `cls-hooked` namespace for accessing these functions anywhere in the request lifecycle.
|
|
14
|
+
*
|
|
15
|
+
* @returns A Hono middleware function.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* import { Hono } from 'hono';
|
|
20
|
+
* import { intlayer } from 'hono-intlayer';
|
|
21
|
+
*
|
|
22
|
+
* const app = new Hono();
|
|
23
|
+
* app.use('*', intlayer());
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
declare const intlayer: () => MiddlewareHandler;
|
|
27
|
+
/**
|
|
28
|
+
* Translation function to retrieve content for the current locale.
|
|
29
|
+
*
|
|
30
|
+
* This function works within the request lifecycle managed by the `intlayer` middleware.
|
|
31
|
+
*
|
|
32
|
+
* @param content - A map of locales to content.
|
|
33
|
+
* @param locale - Optional locale override.
|
|
34
|
+
* @returns The translated content.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* import { t } from 'hono-intlayer';
|
|
39
|
+
*
|
|
40
|
+
* app.get('/', (c) => {
|
|
41
|
+
* const greeting = t({
|
|
42
|
+
* en: 'Hello',
|
|
43
|
+
* fr: 'Bonjour',
|
|
44
|
+
* });
|
|
45
|
+
* return c.text(greeting);
|
|
46
|
+
* });
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
declare const t: <Content = string>(content: StrictModeLocaleMap<Content>, locale?: Locale) => Content;
|
|
50
|
+
declare const getIntlayer: typeof getIntlayer$1;
|
|
51
|
+
declare const getDictionary: typeof getDictionary$1;
|
|
52
|
+
//#endregion
|
|
53
|
+
export { getDictionary, getIntlayer, intlayer, t, translateFunction };
|
|
54
|
+
//# sourceMappingURL=index.d.ts.map
|
package/package.json
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "hono-intlayer",
|
|
3
|
+
"version": "8.0.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "Manage internationalization i18n in a simple way for hono application.",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"intlayer",
|
|
8
|
+
"hono",
|
|
9
|
+
"backend",
|
|
10
|
+
"error",
|
|
11
|
+
"api",
|
|
12
|
+
"application",
|
|
13
|
+
"typescript",
|
|
14
|
+
"javascript",
|
|
15
|
+
"middleware"
|
|
16
|
+
],
|
|
17
|
+
"homepage": "https://intlayer.org",
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/aymericzip/intlayer/issues"
|
|
20
|
+
},
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/aymericzip/intlayer.git"
|
|
24
|
+
},
|
|
25
|
+
"license": "Apache-2.0",
|
|
26
|
+
"author": {
|
|
27
|
+
"name": "Aymeric PINEAU",
|
|
28
|
+
"url": "https://github.com/aymericzip"
|
|
29
|
+
},
|
|
30
|
+
"contributors": [
|
|
31
|
+
{
|
|
32
|
+
"name": "Aymeric Pineau",
|
|
33
|
+
"email": "ay.pineau@gmail.com",
|
|
34
|
+
"url": "https://github.com/aymericzip"
|
|
35
|
+
}
|
|
36
|
+
],
|
|
37
|
+
"sideEffects": false,
|
|
38
|
+
"exports": {
|
|
39
|
+
".": {
|
|
40
|
+
"types": "./dist/types/index.d.ts",
|
|
41
|
+
"require": "./dist/cjs/index.cjs",
|
|
42
|
+
"import": "./dist/esm/index.mjs"
|
|
43
|
+
},
|
|
44
|
+
"./package.json": "./package.json"
|
|
45
|
+
},
|
|
46
|
+
"main": "dist/cjs/index.cjs",
|
|
47
|
+
"module": "dist/esm/index.mjs",
|
|
48
|
+
"types": "dist/types/index.d.ts",
|
|
49
|
+
"typesVersions": {
|
|
50
|
+
"*": {
|
|
51
|
+
"package.json": [
|
|
52
|
+
"./package.json"
|
|
53
|
+
]
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
"files": [
|
|
57
|
+
"./dist",
|
|
58
|
+
"./package.json"
|
|
59
|
+
],
|
|
60
|
+
"scripts": {
|
|
61
|
+
"_prepublish": "cp -f ../../README.md ./README.md",
|
|
62
|
+
"build": "tsdown --config tsdown.config.ts",
|
|
63
|
+
"build:ci": "tsdown --config tsdown.config.ts",
|
|
64
|
+
"clean": "rimraf ./dist .turbo",
|
|
65
|
+
"dev": "tsdown --config tsdown.config.ts --watch",
|
|
66
|
+
"format": "biome format . --check",
|
|
67
|
+
"format:fix": "biome format --write .",
|
|
68
|
+
"lint": "biome lint .",
|
|
69
|
+
"lint:fix": "biome lint --write .",
|
|
70
|
+
"prepublish": "echo prepublish temporally disabled to avoid rewrite readme",
|
|
71
|
+
"publish": "bun publish || true",
|
|
72
|
+
"publish:canary": "bun publish --access public --tag canary || true",
|
|
73
|
+
"publish:latest": "bun publish --access public --tag latest || true",
|
|
74
|
+
"test": "vitest run",
|
|
75
|
+
"test:watch": "vitest",
|
|
76
|
+
"typecheck": "tsc --noEmit --project tsconfig.types.json"
|
|
77
|
+
},
|
|
78
|
+
"dependencies": {
|
|
79
|
+
"@intlayer/chokidar": "8.0.0",
|
|
80
|
+
"@intlayer/config": "8.0.0",
|
|
81
|
+
"@intlayer/core": "8.0.0",
|
|
82
|
+
"@intlayer/types": "8.0.0",
|
|
83
|
+
"cls-hooked": "4.2.2",
|
|
84
|
+
"intlayer": "8.0.0"
|
|
85
|
+
},
|
|
86
|
+
"devDependencies": {
|
|
87
|
+
"@types/cls-hooked": "4.3.9",
|
|
88
|
+
"@types/node": "25.0.10",
|
|
89
|
+
"@utils/ts-config": "1.0.4",
|
|
90
|
+
"@utils/ts-config-types": "1.0.4",
|
|
91
|
+
"@utils/tsdown-config": "1.0.4",
|
|
92
|
+
"hono": "4.7.4",
|
|
93
|
+
"rimraf": "6.1.2",
|
|
94
|
+
"tsdown": "0.20.1",
|
|
95
|
+
"typescript": "5.9.3",
|
|
96
|
+
"vitest": "4.0.18"
|
|
97
|
+
},
|
|
98
|
+
"engines": {
|
|
99
|
+
"node": ">=14.18"
|
|
100
|
+
},
|
|
101
|
+
"bug": {
|
|
102
|
+
"url": "https://github.com/aymericzip/intlayer/issues"
|
|
103
|
+
}
|
|
104
|
+
}
|