@intlayer/docs 8.0.0 → 8.0.1-canary.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (172) hide show
  1. package/dist/cjs/generated/docs.entry.cjs +160 -0
  2. package/dist/cjs/generated/docs.entry.cjs.map +1 -1
  3. package/dist/esm/generated/docs.entry.mjs +160 -0
  4. package/dist/esm/generated/docs.entry.mjs.map +1 -1
  5. package/dist/types/generated/docs.entry.d.ts +8 -0
  6. package/dist/types/generated/docs.entry.d.ts.map +1 -1
  7. package/docs/ar/intlayer_with_adonisjs.md +394 -0
  8. package/docs/ar/intlayer_with_hono.md +223 -0
  9. package/docs/ar/intlayer_with_vite+preact.md +317 -675
  10. package/docs/ar/packages/adonis-intlayer/exports.md +50 -0
  11. package/docs/ar/packages/adonis-intlayer/intlayer.md +54 -0
  12. package/docs/ar/packages/adonis-intlayer/t.md +149 -0
  13. package/docs/ar/packages/hono-intlayer/exports.md +59 -0
  14. package/docs/ar/packages/hono-intlayer/intlayer.md +60 -0
  15. package/docs/ar/packages/hono-intlayer/t.md +268 -0
  16. package/docs/de/intlayer_with_adonisjs.md +392 -0
  17. package/docs/de/intlayer_with_hono.md +418 -0
  18. package/docs/de/intlayer_with_vite+preact.md +272 -632
  19. package/docs/de/packages/adonis-intlayer/exports.md +50 -0
  20. package/docs/de/packages/adonis-intlayer/intlayer.md +54 -0
  21. package/docs/de/packages/adonis-intlayer/t.md +149 -0
  22. package/docs/de/packages/hono-intlayer/exports.md +59 -0
  23. package/docs/de/packages/hono-intlayer/intlayer.md +59 -0
  24. package/docs/de/packages/hono-intlayer/t.md +316 -0
  25. package/docs/en/index.md +8 -0
  26. package/docs/en/intlayer_with_adonisjs.md +388 -0
  27. package/docs/en/intlayer_with_hono.md +418 -0
  28. package/docs/en/intlayer_with_vite+preact.md +171 -556
  29. package/docs/en/introduction.md +1 -0
  30. package/docs/en/packages/adonis-intlayer/exports.md +50 -0
  31. package/docs/en/packages/adonis-intlayer/intlayer.md +54 -0
  32. package/docs/en/packages/adonis-intlayer/t.md +149 -0
  33. package/docs/en/packages/hono-intlayer/exports.md +59 -0
  34. package/docs/en/packages/hono-intlayer/intlayer.md +59 -0
  35. package/docs/en/packages/hono-intlayer/t.md +316 -0
  36. package/docs/en-GB/intlayer_with_adonisjs.md +394 -0
  37. package/docs/en-GB/intlayer_with_hono.md +418 -0
  38. package/docs/en-GB/intlayer_with_vite+preact.md +236 -583
  39. package/docs/en-GB/packages/adonis-intlayer/exports.md +50 -0
  40. package/docs/en-GB/packages/adonis-intlayer/intlayer.md +54 -0
  41. package/docs/en-GB/packages/adonis-intlayer/t.md +149 -0
  42. package/docs/en-GB/packages/hono-intlayer/exports.md +59 -0
  43. package/docs/en-GB/packages/hono-intlayer/intlayer.md +59 -0
  44. package/docs/en-GB/packages/hono-intlayer/t.md +316 -0
  45. package/docs/es/intlayer_with_adonisjs.md +388 -0
  46. package/docs/es/intlayer_with_hono.md +418 -0
  47. package/docs/es/intlayer_with_vite+preact.md +286 -650
  48. package/docs/es/packages/adonis-intlayer/exports.md +50 -0
  49. package/docs/es/packages/adonis-intlayer/intlayer.md +54 -0
  50. package/docs/es/packages/adonis-intlayer/t.md +149 -0
  51. package/docs/es/packages/hono-intlayer/exports.md +59 -0
  52. package/docs/es/packages/hono-intlayer/intlayer.md +59 -0
  53. package/docs/es/packages/hono-intlayer/t.md +316 -0
  54. package/docs/fr/intlayer_with_adonisjs.md +388 -0
  55. package/docs/fr/intlayer_with_hono.md +418 -0
  56. package/docs/fr/intlayer_with_vite+preact.md +274 -614
  57. package/docs/fr/packages/adonis-intlayer/exports.md +50 -0
  58. package/docs/fr/packages/adonis-intlayer/intlayer.md +54 -0
  59. package/docs/fr/packages/adonis-intlayer/t.md +149 -0
  60. package/docs/fr/packages/hono-intlayer/exports.md +59 -0
  61. package/docs/fr/packages/hono-intlayer/intlayer.md +59 -0
  62. package/docs/fr/packages/hono-intlayer/t.md +316 -0
  63. package/docs/hi/intlayer_with_adonisjs.md +394 -0
  64. package/docs/hi/intlayer_with_hono.md +227 -0
  65. package/docs/hi/intlayer_with_vite+preact.md +304 -680
  66. package/docs/hi/packages/adonis-intlayer/exports.md +50 -0
  67. package/docs/hi/packages/adonis-intlayer/intlayer.md +54 -0
  68. package/docs/hi/packages/adonis-intlayer/t.md +149 -0
  69. package/docs/hi/packages/hono-intlayer/exports.md +59 -0
  70. package/docs/hi/packages/hono-intlayer/intlayer.md +60 -0
  71. package/docs/hi/packages/hono-intlayer/t.md +268 -0
  72. package/docs/id/intlayer_with_adonisjs.md +394 -0
  73. package/docs/id/intlayer_with_hono.md +227 -0
  74. package/docs/id/intlayer_with_vite+preact.md +297 -697
  75. package/docs/id/packages/adonis-intlayer/exports.md +50 -0
  76. package/docs/id/packages/adonis-intlayer/intlayer.md +54 -0
  77. package/docs/id/packages/adonis-intlayer/t.md +149 -0
  78. package/docs/id/packages/hono-intlayer/exports.md +59 -0
  79. package/docs/id/packages/hono-intlayer/intlayer.md +60 -0
  80. package/docs/id/packages/hono-intlayer/t.md +268 -0
  81. package/docs/it/intlayer_with_adonisjs.md +394 -0
  82. package/docs/it/intlayer_with_hono.md +227 -0
  83. package/docs/it/intlayer_with_vite+preact.md +290 -659
  84. package/docs/it/packages/adonis-intlayer/exports.md +50 -0
  85. package/docs/it/packages/adonis-intlayer/intlayer.md +54 -0
  86. package/docs/it/packages/adonis-intlayer/t.md +149 -0
  87. package/docs/it/packages/hono-intlayer/exports.md +59 -0
  88. package/docs/it/packages/hono-intlayer/intlayer.md +60 -0
  89. package/docs/it/packages/hono-intlayer/t.md +268 -0
  90. package/docs/ja/intlayer_with_adonisjs.md +394 -0
  91. package/docs/ja/intlayer_with_hono.md +227 -0
  92. package/docs/ja/intlayer_with_vite+preact.md +307 -662
  93. package/docs/ja/packages/adonis-intlayer/exports.md +50 -0
  94. package/docs/ja/packages/adonis-intlayer/intlayer.md +54 -0
  95. package/docs/ja/packages/adonis-intlayer/t.md +149 -0
  96. package/docs/ja/packages/hono-intlayer/exports.md +59 -0
  97. package/docs/ja/packages/hono-intlayer/intlayer.md +60 -0
  98. package/docs/ja/packages/hono-intlayer/t.md +268 -0
  99. package/docs/ko/intlayer_with_adonisjs.md +394 -0
  100. package/docs/ko/intlayer_with_hono.md +227 -0
  101. package/docs/ko/intlayer_with_vite+preact.md +303 -703
  102. package/docs/ko/packages/adonis-intlayer/exports.md +50 -0
  103. package/docs/ko/packages/adonis-intlayer/intlayer.md +54 -0
  104. package/docs/ko/packages/adonis-intlayer/t.md +149 -0
  105. package/docs/ko/packages/hono-intlayer/exports.md +59 -0
  106. package/docs/ko/packages/hono-intlayer/intlayer.md +60 -0
  107. package/docs/ko/packages/hono-intlayer/t.md +268 -0
  108. package/docs/pl/intlayer_with_adonisjs.md +394 -0
  109. package/docs/pl/intlayer_with_hono.md +227 -0
  110. package/docs/pl/intlayer_with_vite+preact.md +289 -690
  111. package/docs/pl/packages/adonis-intlayer/exports.md +50 -0
  112. package/docs/pl/packages/adonis-intlayer/intlayer.md +54 -0
  113. package/docs/pl/packages/adonis-intlayer/t.md +149 -0
  114. package/docs/pl/packages/hono-intlayer/exports.md +59 -0
  115. package/docs/pl/packages/hono-intlayer/intlayer.md +60 -0
  116. package/docs/pl/packages/hono-intlayer/t.md +268 -0
  117. package/docs/pt/intlayer_with_adonisjs.md +394 -0
  118. package/docs/pt/intlayer_with_hono.md +227 -0
  119. package/docs/pt/intlayer_with_vite+preact.md +275 -637
  120. package/docs/pt/packages/adonis-intlayer/exports.md +50 -0
  121. package/docs/pt/packages/adonis-intlayer/intlayer.md +54 -0
  122. package/docs/pt/packages/adonis-intlayer/t.md +149 -0
  123. package/docs/pt/packages/hono-intlayer/exports.md +59 -0
  124. package/docs/pt/packages/hono-intlayer/intlayer.md +60 -0
  125. package/docs/pt/packages/hono-intlayer/t.md +268 -0
  126. package/docs/ru/intlayer_with_adonisjs.md +393 -0
  127. package/docs/ru/intlayer_with_hono.md +223 -0
  128. package/docs/ru/intlayer_with_vite+preact.md +319 -683
  129. package/docs/ru/packages/adonis-intlayer/exports.md +50 -0
  130. package/docs/ru/packages/adonis-intlayer/intlayer.md +54 -0
  131. package/docs/ru/packages/adonis-intlayer/t.md +149 -0
  132. package/docs/ru/packages/hono-intlayer/exports.md +59 -0
  133. package/docs/ru/packages/hono-intlayer/intlayer.md +60 -0
  134. package/docs/ru/packages/hono-intlayer/t.md +268 -0
  135. package/docs/tr/intlayer_with_adonisjs.md +394 -0
  136. package/docs/tr/intlayer_with_hono.md +227 -0
  137. package/docs/tr/intlayer_with_vite+preact.md +332 -665
  138. package/docs/tr/packages/adonis-intlayer/exports.md +50 -0
  139. package/docs/tr/packages/adonis-intlayer/intlayer.md +54 -0
  140. package/docs/tr/packages/adonis-intlayer/t.md +149 -0
  141. package/docs/tr/packages/hono-intlayer/exports.md +59 -0
  142. package/docs/tr/packages/hono-intlayer/intlayer.md +60 -0
  143. package/docs/tr/packages/hono-intlayer/t.md +268 -0
  144. package/docs/uk/intlayer_with_adonisjs.md +394 -0
  145. package/docs/uk/intlayer_with_hono.md +227 -0
  146. package/docs/uk/intlayer_with_vite+preact.md +228 -626
  147. package/docs/uk/packages/adonis-intlayer/exports.md +50 -0
  148. package/docs/uk/packages/adonis-intlayer/intlayer.md +54 -0
  149. package/docs/uk/packages/adonis-intlayer/t.md +149 -0
  150. package/docs/uk/packages/hono-intlayer/exports.md +59 -0
  151. package/docs/uk/packages/hono-intlayer/intlayer.md +60 -0
  152. package/docs/uk/packages/hono-intlayer/t.md +268 -0
  153. package/docs/vi/intlayer_with_adonisjs.md +394 -0
  154. package/docs/vi/intlayer_with_hono.md +227 -0
  155. package/docs/vi/intlayer_with_vite+preact.md +294 -679
  156. package/docs/vi/packages/adonis-intlayer/exports.md +50 -0
  157. package/docs/vi/packages/adonis-intlayer/intlayer.md +54 -0
  158. package/docs/vi/packages/adonis-intlayer/t.md +149 -0
  159. package/docs/vi/packages/hono-intlayer/exports.md +59 -0
  160. package/docs/vi/packages/hono-intlayer/intlayer.md +60 -0
  161. package/docs/vi/packages/hono-intlayer/t.md +268 -0
  162. package/docs/zh/intlayer_with_adonisjs.md +393 -0
  163. package/docs/zh/intlayer_with_hono.md +418 -0
  164. package/docs/zh/intlayer_with_vite+preact.md +338 -743
  165. package/docs/zh/packages/adonis-intlayer/exports.md +50 -0
  166. package/docs/zh/packages/adonis-intlayer/intlayer.md +54 -0
  167. package/docs/zh/packages/adonis-intlayer/t.md +149 -0
  168. package/docs/zh/packages/hono-intlayer/exports.md +59 -0
  169. package/docs/zh/packages/hono-intlayer/intlayer.md +60 -0
  170. package/docs/zh/packages/hono-intlayer/t.md +294 -0
  171. package/package.json +6 -6
  172. package/src/generated/docs.entry.ts +160 -0
@@ -0,0 +1,50 @@
1
+ ---
2
+ createdAt: 2026-01-30
3
+ updatedAt: 2026-01-30
4
+ title: adonis-intlayer Package Documentation
5
+ description: AdonisJS middleware for Intlayer, providing translation functions and locale detection.
6
+ keywords:
7
+ - adonis-intlayer
8
+ - adonisjs
9
+ - middleware
10
+ - internationalisation
11
+ - i18n
12
+ slugs:
13
+ - doc
14
+ - packages
15
+ - adonis-intlayer
16
+ - exports
17
+ history:
18
+ - version: 8.0.0
19
+ date: 2026-01-30
20
+ changes: Initial documentation
21
+ ---
22
+
23
+ # adonis-intlayer Package
24
+
25
+ The `adonis-intlayer` package provides a middleware for AdonisJS applications to handle internationalisation. It detects the user's locale and provides translation functions.
26
+
27
+ ## Installation
28
+
29
+ ```bash
30
+ npm install adonis-intlayer
31
+ ```
32
+
33
+ ## Exports
34
+
35
+ ### Middleware
36
+
37
+ The package provides an AdonisJS middleware to handle internationalisation.
38
+
39
+ | Function | Description | Related Doc |
40
+ | -------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------- |
41
+ | `IntlayerMiddleware` | AdonisJS middleware that detects the user's locale and populates the request context with Intlayer data. It also sets up a CLS (Async Local Storage) namespace for request lifecycle access, enabling the use of global functions like `t`, `getIntlayer`, etc. | [intlayer](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en-GB/packages/adonis-intlayer/intlayer.md) |
42
+
43
+ ### Functions
44
+
45
+ | Function | Description | Related Doc |
46
+ | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------- |
47
+ | `t` | Translation function that retrieves content for the current locale. Works within the request lifecycle managed by the `intlayer` middleware. Uses CLS (Async Local Storage) to access request context. | [translation](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en-GB/dictionary/translation.md) |
48
+ | `getIntlayer` | Retrieves a dictionary by its key from the generated declaration and returns its content for the specified locale. Optimised version of `getDictionary`. Uses CLS to access request context. | - |
49
+ | `getDictionary` | Processes dictionary objects and returns content for the specified locale. Processes `t()` translations, enumerations, markdown, HTML, etc. Uses CLS to access request context. | - |
50
+ | `getLocale` | Retrieves the current locale from the request context using CLS. | - |
@@ -0,0 +1,54 @@
1
+ ---
2
+ createdAt: 2026-01-30
3
+ updatedAt: 2026-01-30
4
+ title: intlayer AdonisJS Middleware Documentation | adonis-intlayer
5
+ description: See how to use the intlayer middleware for adonis-intlayer package
6
+ keywords:
7
+ - intlayer
8
+ - adonisjs
9
+ - middleware
10
+ - Intlayer
11
+ - Internationalisation
12
+ - Documentation
13
+ slugs:
14
+ - doc
15
+ - packages
16
+ - adonis-intlayer
17
+ - intlayer
18
+ history:
19
+ - version: 8.0.0
20
+ date: 2026-01-30
21
+ changes: Initial documentation
22
+ ---
23
+
24
+ # intlayer AdonisJS Middleware Documentation
25
+
26
+ The `intlayer` middleware for AdonisJS detects the user's locale and provides translation functions through the request context. It also enables the use of global translation functions within the request flow.
27
+
28
+ ## Usage
29
+
30
+ ```ts fileName="start/kernel.ts"
31
+ router.use([() => import("adonis-intlayer/middleware")]);
32
+ ```
33
+
34
+ ```ts fileName="start/routes.ts"
35
+ import router from "@adonisjs/core/services/router";
36
+ import { t } from "adonis-intlayer";
37
+
38
+ router.get("/", async () => {
39
+ return t({
40
+ en: "Hello",
41
+ fr: "Bonjour",
42
+ });
43
+ });
44
+ ```
45
+
46
+ ## Description
47
+
48
+ The middleware performs the following tasks:
49
+
50
+ 1. **Locale Detection**: It analyses the request (headers, cookies, etc.) to determine the user's preferred locale.
51
+ 2. **Context Setup**: It populates the request context with locale information.
52
+ 3. **Async Local Storage**: It uses `cls-hooked` to manage an asynchronous context, allowing global Intlayer functions like `t`, `getIntlayer`, and `getDictionary` to access the request-specific locale without passing it manually.
53
+
54
+ > Note: To use cookies for locale detection, ensure `@adonisjs/cookie` is configured and used in your application.
@@ -0,0 +1,149 @@
1
+ ---
2
+ createdAt: 2026-01-30
3
+ updatedAt: 2026-01-30
4
+ title: t Function Documentation | adonis-intlayer
5
+ description: See how to use the t function for adonis-intlayer package
6
+ keywords:
7
+ - t
8
+ - translation
9
+ - Intlayer
10
+ - Internationalisation
11
+ - Documentation
12
+ - AdonisJS
13
+ - JavaScript
14
+ slugs:
15
+ - doc
16
+ - packages
17
+ - adonis-intlayer
18
+ - t
19
+ history:
20
+ - version: 8.0.0
21
+ date: 2026-01-30
22
+ changes: Initial documentation
23
+ ---
24
+
25
+ # Documentation: `t` Function in `adonis-intlayer`
26
+
27
+ The `t` function in the `adonis-intlayer` package is the core utility for providing localised responses in your AdonisJS application. It simplifies internationalisation (i18n) by dynamically selecting content based on the user's preferred language.
28
+
29
+ ---
30
+
31
+ ## Overview
32
+
33
+ The `t` function is used to define and retrieve translations for a given set of languages. It automatically determines the appropriate language to return based on the client's request settings, such as the `Accept-Language` header. If the preferred language is unavailable, it gracefully falls back to the default locale specified in your configuration.
34
+
35
+ ---
36
+
37
+ ## Key Features
38
+
39
+ - **Dynamic Localisation**: Automatically selects the most appropriate translation for the client.
40
+ - **Fallback to Default Locale**: Falls back to a default locale if the client's preferred language isn't available, ensuring continuity in user experience.
41
+ - **Asynchronous Context**: Works seamlessly within the AdonisJS request lifecycle using Async Local Storage.
42
+ - **TypeScript Support**: Enforce type safety for your translations.
43
+
44
+ ---
45
+
46
+ ## Function Signature
47
+
48
+ ```typescript
49
+ t(translations: Record<string, any>): any;
50
+ ```
51
+
52
+ ### Parameters
53
+
54
+ - `translations`: An object where the keys are locale codes (e.g., `en`, `fr`, `es`) and the values are the corresponding translated content.
55
+
56
+ ### Returns
57
+
58
+ - The content representing the client's preferred language.
59
+
60
+ ---
61
+
62
+ ## Loading the Middleware
63
+
64
+ To ensure that the `t` function works correctly, you **must** register the `intlayer` middleware in your AdonisJS application.
65
+
66
+ ```typescript fileName="start/kernel.ts"
67
+ router.use([() => import("adonis-intlayer/middleware")]);
68
+ ```
69
+
70
+ ---
71
+
72
+ ## Usage Examples
73
+
74
+ ### Basic Example
75
+
76
+ ```typescript fileName="start/routes.ts"
77
+ import router from "@adonisjs/core/services/router";
78
+ import { t } from "adonis-intlayer";
79
+
80
+ router.get("/", async () => {
81
+ return t({
82
+ en: "Welcome!",
83
+ fr: "Bienvenue!",
84
+ es: "¡Bienvenido!",
85
+ });
86
+ });
87
+ ```
88
+
89
+ ### Usage in Controllers
90
+
91
+ ```typescript fileName="app/controllers/example_controller.ts"
92
+ import type { HttpContext } from "@adonisjs/core/http";
93
+ import { t } from "adonis-intlayer";
94
+
95
+ export default class ExampleController {
96
+ async index({ response }: HttpContext) {
97
+ return response.send(
98
+ t({
99
+ en: "Hello from controller",
100
+ fr: "Bonjour depuis le contrôleur",
101
+ })
102
+ );
103
+ }
104
+ }
105
+ ```
106
+
107
+ ---
108
+
109
+ ## Advanced Topics
110
+
111
+ ### Fallback Mechanism
112
+
113
+ If a preferred locale is unavailable, the `t` function will fallback to the default locale defined in your `intlayer.config.ts`.
114
+
115
+ ```typescript
116
+ import { Locales, type IntlayerConfig } from "intlayer";
117
+
118
+ const config: IntlayerConfig = {
119
+ internationalization: {
120
+ locales: [
121
+ Locales.ENGLISH,
122
+ Locales.RUSSIAN,
123
+ Locales.JAPANESE,
124
+ Locales.FRENCH,
125
+ Locales.KOREAN,
126
+ Locales.CHINESE,
127
+ Locales.SPANISH,
128
+ Locales.GERMAN,
129
+ Locales.ARABIC,
130
+ Locales.ITALIAN,
131
+ Locales.ENGLISH_UNITED_KINGDOM,
132
+ Locales.PORTUGUESE,
133
+ Locales.HINDI,
134
+ Locales.TURKISH,
135
+ Locales.POLISH,
136
+ Locales.INDONESIAN,
137
+ Locales.VIETNAMESE,
138
+ Locales.UKRAINIAN,
139
+ ],
140
+ defaultLocale: Locales.ENGLISH,
141
+ },
142
+ };
143
+
144
+ export default config;
145
+ ```
146
+
147
+ ### TypeScript Integration
148
+
149
+ The `t` function is type-safe when used with defined dictionaries. For more details, refer to the [TypeScript documentation](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en-GB/configuration.md).
@@ -0,0 +1,59 @@
1
+ ---
2
+ createdAt: 2026-01-29
3
+ updatedAt: 2026-01-29
4
+ title: hono-intlayer Package Documentation
5
+ description: Hono middleware for Intlayer, providing translation functions and locale detection.
6
+ keywords:
7
+ - hono-intlayer
8
+ - hono
9
+ - middleware
10
+ - internationalization
11
+ - i18n
12
+ slugs:
13
+ - doc
14
+ - packages
15
+ - hono-intlayer
16
+ - exports
17
+ history:
18
+ - version: 8.0.0
19
+ date: 2026-01-29
20
+ changes: Unified documentation for all exports
21
+ ---
22
+
23
+ # hono-intlayer Package
24
+
25
+ The `hono-intlayer` package provides a middleware for Hono applications to handle internationalization. It detects the user's locale and populates the context object.
26
+
27
+ ## Installation
28
+
29
+ ```bash
30
+ npm install hono-intlayer
31
+ ```
32
+
33
+ ## Exports
34
+
35
+ ### Middleware
36
+
37
+ Import:
38
+
39
+ ```tsx
40
+ import { intlayer } from "hono-intlayer";
41
+ ```
42
+
43
+ | Function | Description | Related Doc |
44
+ | ---------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ |
45
+ | `intlayer` | Hono middleware that integrates Intlayer into your Hono application. Handles locale detection from storage (cookies, headers), populates the context with `t`, `getIntlayer`, and `getDictionary`, and sets up CLS namespace for programmatic access during the request lifecycle. | [intlayer](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/packages/hono-intlayer/intlayer.md) |
46
+
47
+ ### Functions
48
+
49
+ Import:
50
+
51
+ ```tsx
52
+ import { t, getIntlayer, getDictionary } from "hono-intlayer";
53
+ ```
54
+
55
+ | Function | Description | Related Doc |
56
+ | --------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------ |
57
+ | `t` | Global translation function that retrieves content for the current locale in Hono. Utilizes CLS (Async Local Storage) and must be used within a request context managed by the `intlayer` middleware. Can also be accessed via context. | [translation](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/dictionary/translation.md) |
58
+ | `getIntlayer` | Retrieves a dictionary by its key from the generated declaration and returns its content for the specified locale. Optimized version of `getDictionary`. Uses CLS to access request context. Can also be accessed via context. | - |
59
+ | `getDictionary` | Processes dictionary objects and returns content for the specified locale. Processes `t()` translations, enumerations, markdown, HTML, etc. Uses CLS to access request context. Can also be accessed via context. | - |
@@ -0,0 +1,59 @@
1
+ ---
2
+ createdAt: 2026-01-29
3
+ updatedAt: 2026-01-29
4
+ title: intlayer Hono Middleware Documentation | hono-intlayer
5
+ description: See how to use the intlayer middleware for hono-intlayer package
6
+ keywords:
7
+ - intlayer
8
+ - hono
9
+ - middleware
10
+ - Intlayer
11
+ - Internationalization
12
+ - Documentation
13
+ slugs:
14
+ - doc
15
+ - packages
16
+ - hono-intlayer
17
+ - intlayer
18
+ history:
19
+ - version: 8.0.0
20
+ date: 2026-01-29
21
+ changes: Init doc
22
+ ---
23
+
24
+ # intlayer Hono Middleware Documentation
25
+
26
+ The `intlayer` middleware for Hono detects the user's locale and populates the context object with Intlayer functions. It also enables the use of global translation functions within the request context.
27
+
28
+ ## Usage
29
+
30
+ ```ts
31
+ import { Hono } from "hono";
32
+ import { intlayer } from "hono-intlayer";
33
+
34
+ const app = new Hono();
35
+
36
+ app.use("*", intlayer());
37
+
38
+ app.get("/", async (c) => {
39
+ const t = c.get("t");
40
+ const content = t({
41
+ en: "Hello",
42
+ fr: "Bonjour",
43
+ });
44
+
45
+ return c.text(content);
46
+ });
47
+ ```
48
+
49
+ ## Description
50
+
51
+ The middleware performs the following tasks:
52
+
53
+ 1. **Locale Detection**: It analyzes the request (headers, cookies, etc.) to determine the user's preferred locale.
54
+ 2. **Context Population**: It adds Intlayer data to the Hono context, accessible via `c.get()`. This includes:
55
+ - `locale`: The detected locale.
56
+ - `t`: A translation function.
57
+ - `getIntlayer`: A function to retrieve dictionaries.
58
+ - `getDictionary`: A function to process dictionary objects.
59
+ 3. **Context Management**: It uses `cls-hooked` to manage an asynchronous context, allowing global Intlayer functions (`t`, `getIntlayer`, `getDictionary`) to access the request-specific locale without passing the context object.
@@ -0,0 +1,316 @@
1
+ ---
2
+ createdAt: 2024-12-02
3
+ updatedAt: 2025-06-29
4
+ title: t Function Documentation | hono-intlayer
5
+ description: See how to use the t function for hono-intlayer package
6
+ keywords:
7
+ - t
8
+ - translation
9
+ - Intlayer
10
+ - Internationalization
11
+ - Documentation
12
+ - Hono
13
+ - JavaScript
14
+ slugs:
15
+ - doc
16
+ - packages
17
+ - hono-intlayer
18
+ - t
19
+ history:
20
+ - version: 5.5.10
21
+ date: 2025-06-29
22
+ changes: Init history
23
+ ---
24
+
25
+ # Documentation: `t` Function in `hono-intlayer`
26
+
27
+ The `t` function in the `hono-intlayer` package is the core utility for providing localized responses in your Hono application. It simplifies internationalization (i18n) by dynamically selecting content based on the user's preferred language.
28
+
29
+ ---
30
+
31
+ ## Overview
32
+
33
+ The `t` function is used to define and retrieve translations for a given set of languages. It automatically determines the appropriate language to return based on the client's request settings, such as the `Accept-Language` header. If the preferred language is unavailable, it gracefully falls back to the default locale specified in your configuration.
34
+
35
+ ---
36
+
37
+ ## Key Features
38
+
39
+ - **Dynamic Localization**: Automatically selects the most appropriate translation for the client.
40
+ - **Fallback to Default Locale**: Falls back to a default locale if the client's preferred language isn't available, ensuring continuity in user experience.
41
+ - **Lightweight and Fast**: Designed for high-performance applications, ensuring minimal overhead.
42
+ - **Strict Mode Support**: Enforce strict adherence to declared locales for reliable behavior.
43
+
44
+ ---
45
+
46
+ ## Function Signature
47
+
48
+ ```typescript
49
+ t(translations: Record<string, string>): string;
50
+ ```
51
+
52
+ ### Parameters
53
+
54
+ - `translations`: An object where the keys are locale codes (e.g., `en`, `fr`, `es-MX`) and the values are the corresponding translated strings.
55
+
56
+ ### Returns
57
+
58
+ - A string representing the content in the client's preferred language.
59
+
60
+ ---
61
+
62
+ ## Loading the Internationalization Request Handler
63
+
64
+ To ensure that the internationalization functionality provided by `hono-intlayer` works correctly, you **must** load the internationalization middleware at the beginning of your Hono application. This enables the `t` function and ensures proper handling of locale detection and translation.
65
+
66
+ Place the `app.use("*", intlayer())` middleware **before any routes** in your application to ensure that all routes benefit from internationalization:
67
+
68
+ ```typescript {6} fileName="src/index.ts" codeFormat="typescript"
69
+ import { Hono } from "hono";
70
+ import { intlayer } from "hono-intlayer";
71
+
72
+ const app = new Hono();
73
+
74
+ // Load internationalization request handler
75
+ app.use("*", intlayer());
76
+
77
+ // Define your routes after loading the middleware
78
+ app.get("/", (c) => {
79
+ return c.text(
80
+ t({
81
+ en: "Hello, World!",
82
+ fr: "Bonjour le monde!",
83
+ es: "¡Hola, Mundo!",
84
+ })
85
+ );
86
+ });
87
+ ```
88
+
89
+ ```javascript {6} fileName="src/index.mjs" codeFormat="esm"
90
+ import { Hono } from "hono";
91
+ import { intlayer } from "hono-intlayer";
92
+
93
+ const app = new Hono();
94
+
95
+ // Load internationalization request handler
96
+ app.use("*", intlayer());
97
+
98
+ // Define your routes after loading the middleware
99
+ app.get("/", (c) => {
100
+ return c.text(
101
+ t({
102
+ en: "Hello, World!",
103
+ fr: "Bonjour le monde!",
104
+ es: "¡Hola, Mundo!",
105
+ })
106
+ );
107
+ });
108
+ ```
109
+
110
+ ```javascript {6} fileName="src/index.cjs" codeFormat="commonjs"
111
+ const { Hono } = require("hono");
112
+ const { intlayer, t } = require("hono-intlayer");
113
+
114
+ const app = new Hono();
115
+
116
+ // Load internationalization request handler
117
+ app.use("*", intlayer());
118
+
119
+ // Define your routes after loading the middleware
120
+ app.get("/", (c) => {
121
+ return c.text(
122
+ t({
123
+ en: "Hello, World!",
124
+ fr: "Bonjour le monde!",
125
+ es: "¡Hola, Mundo!",
126
+ })
127
+ );
128
+ });
129
+ ```
130
+
131
+ ### Why This is Required
132
+
133
+ - **Locale Detection**: The `intlayer` middleware processes incoming requests to detect the user's preferred locale based on headers, cookies, or other configured methods.
134
+ - **Translation Context**: Sets up the necessary context for the `t` function to operate correctly, ensuring that translations are returned in the correct language.
135
+ - **Error Prevention**: Without this middleware, using the `t` function will result in runtime errors because the necessary locale information won't be available.
136
+
137
+ ---
138
+
139
+ ## Usage Examples
140
+
141
+ ### Basic Example
142
+
143
+ Serve localized content in different languages:
144
+
145
+ ```typescript fileName="src/index.ts" codeFormat="typescript"
146
+ app.get("/", (c) => {
147
+ return c.text(
148
+ t({
149
+ en: "Welcome!",
150
+ fr: "Bienvenue!",
151
+ es: "¡Bienvenido!",
152
+ })
153
+ );
154
+ });
155
+ ```
156
+
157
+ ```javascript fileName="src/index.mjs" codeFormat="esm"
158
+ app.get("/", (c) => {
159
+ return c.text(
160
+ t({
161
+ en: "Welcome!",
162
+ fr: "Bienvenue!",
163
+ es: "¡Bienvenido!",
164
+ })
165
+ );
166
+ });
167
+ ```
168
+
169
+ ```javascript fileName="src/index.cjs" codeFormat="commonjs"
170
+ app.get("/", (c) => {
171
+ return c.text(
172
+ t({
173
+ en: "Welcome!",
174
+ fr: "Bienvenue!",
175
+ es: "¡Bienvenido!",
176
+ })
177
+ );
178
+ });
179
+ ```
180
+
181
+ **Client Requests:**
182
+
183
+ - A client with `Accept-Language: fr` will receive `Bienvenue!`.
184
+ - A client with `Accept-Language: es` will receive `¡Bienvenido!`.
185
+ - A client with `Accept-Language: de` will receive `Welcome!` (default locale).
186
+
187
+ ### Handling Errors
188
+
189
+ Provide error messages in multiple languages:
190
+
191
+ ```typescript fileName="src/index.ts" codeFormat="typescript"
192
+ app.get("/error", (c) => {
193
+ return c.text(
194
+ t({
195
+ en: "An unexpected error occurred.",
196
+ fr: "Une erreur inattendue s'est produite.",
197
+ es: "Ocurrió un error inesperado.",
198
+ }),
199
+ 500
200
+ );
201
+ });
202
+ ```
203
+
204
+ ```javascript fileName="src/index.mjs" codeFormat="esm"
205
+ app.get("/error", (c) => {
206
+ return c.text(
207
+ t({
208
+ en: "An unexpected error occurred.",
209
+ fr: "Une erreur inattendue s'est produite.",
210
+ es: "Ocurrió un error inesperado.",
211
+ }),
212
+ 500
213
+ );
214
+ });
215
+ ```
216
+
217
+ ```javascript fileName="src/index.cjs" codeFormat="commonjs"
218
+ app.get("/error", (c) => {
219
+ return c.text(
220
+ t({
221
+ en: "An unexpected error occurred.",
222
+ fr: "Une erreur inattendue s'est produite.",
223
+ es: "Ocurrió un error inesperado.",
224
+ }),
225
+ 500
226
+ );
227
+ });
228
+ ```
229
+
230
+ ---
231
+
232
+ ### Using Locale Variants
233
+
234
+ Specify translations for locale-specific variants:
235
+
236
+ ```typescript fileName="src/index.ts" codeFormat="typescript"
237
+ app.get("/greet", (c) => {
238
+ return c.text(
239
+ t({
240
+ en: "Hello!",
241
+ "en-GB": "Hello, mate!",
242
+ fr: "Bonjour!",
243
+ "es-MX": "¡Hola, amigo!",
244
+ "es-ES": "¡Hola!",
245
+ })
246
+ );
247
+ });
248
+ ```
249
+
250
+ ---
251
+
252
+ ## Advanced Topics
253
+
254
+ ### Fallback Mechanism
255
+
256
+ If a preferred locale is unavailable, the `t` function will fallback to the default locale defined in the configuration:
257
+
258
+ ```typescript {5-6} fileName="intlayer.config.ts" codeFormat="typescript"
259
+ import { Locales, type IntlayerConfig } from "intlayer";
260
+
261
+ const config = {
262
+ internationalization: {
263
+ locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH],
264
+ defaultLocale: Locales.ENGLISH,
265
+ },
266
+ } satisfies IntlayerConfig;
267
+
268
+ export default config;
269
+ ```
270
+
271
+ ---
272
+
273
+ ### Strict Mode Enforcement
274
+
275
+ Configure the `t` function to enforce strict adherence to declared locales:
276
+
277
+ | Mode | Behavior |
278
+ | ----------- | ------------------------------------------------------------------------------------------- |
279
+ | `strict` | All declared locales must have translations provided. Missing locales will throw errors. |
280
+ | `inclusive` | Declared locales must have translations. Missing locales trigger warnings but are accepted. |
281
+ | `loose` | Any existing locale is accepted, even if not declared. |
282
+
283
+ ---
284
+
285
+ ### TypeScript Integration
286
+
287
+ The `t` function is type-safe when used with TypeScript. Define a type-safe translations object:
288
+
289
+ ```typescript fileName="src/index.ts" codeFormat="typescript"
290
+ import { type LanguageContent } from "hono-intlayer";
291
+
292
+ const translations: LanguageContent<string> = {
293
+ en: "Good morning!",
294
+ fr: "Bonjour!",
295
+ es: "¡Buenos días!",
296
+ };
297
+
298
+ app.get("/morning", (c) => {
299
+ return c.text(t(translations));
300
+ });
301
+ ```
302
+
303
+ ---
304
+
305
+ ### Common Errors and Troubleshooting
306
+
307
+ | Issue | Cause | Solution |
308
+ | -------------------------- | --------------------------------------- | --------------------------------------------------------- |
309
+ | `t` function not working | Middleware not loaded | Ensure `app.use("*", intlayer())` is added before routes. |
310
+ | Missing translations error | Strict mode enabled without all locales | Provide all required translations. |
311
+
312
+ ---
313
+
314
+ ## Conclusion
315
+
316
+ The `t` function is a powerful tool for backend internationalization. By using it effectively, you can create a more inclusive and user-friendly application for a global audience. For advanced usage and detailed configuration options, refer to the [documentation](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/configuration.md).