@argos-js/i18n 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +221 -2
- package/dist/formatters.d.ts +19 -0
- package/dist/formatters.d.ts.map +1 -0
- package/dist/formatters.js +34 -0
- package/dist/formatters.js.map +1 -0
- package/dist/i18n-manager.d.ts +75 -0
- package/dist/i18n-manager.d.ts.map +1 -0
- package/dist/i18n-manager.js +271 -0
- package/dist/i18n-manager.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/locales/en-US.d.ts +37 -0
- package/dist/locales/en-US.d.ts.map +1 -0
- package/dist/locales/en-US.js +40 -0
- package/dist/locales/en-US.js.map +1 -0
- package/dist/locales/es-ES.d.ts +37 -0
- package/dist/locales/es-ES.d.ts.map +1 -0
- package/dist/locales/es-ES.js +40 -0
- package/dist/locales/es-ES.js.map +1 -0
- package/dist/locales/index.d.ts +4 -0
- package/dist/locales/index.d.ts.map +1 -0
- package/dist/locales/index.js +10 -0
- package/dist/locales/index.js.map +1 -0
- package/dist/locales/pt-BR.d.ts +37 -0
- package/dist/locales/pt-BR.d.ts.map +1 -0
- package/dist/locales/pt-BR.js +40 -0
- package/dist/locales/pt-BR.js.map +1 -0
- package/dist/plugin.d.ts +12 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +145 -0
- package/dist/plugin.js.map +1 -0
- package/dist/types.d.ts +83 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +30 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Argos-JS Team
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,222 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @argos-js/i18n
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Transparent, high-performance, and request-scoped internationalization (i18n) for Argos-JS.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## ⚡ Overview
|
|
8
|
+
|
|
9
|
+
`@argos-js/i18n` provides seamless multi-language support built for asynchronous, high-throughput Node.js microservices and REST APIs:
|
|
10
|
+
|
|
11
|
+
- **Isolated Request Context (`AsyncLocalStorage`)**: Concurrent requests in different languages run concurrently without race conditions or cross-request pollution.
|
|
12
|
+
- **Fast Token Interpolation**: Fast template engine substituting `{param}` tokens.
|
|
13
|
+
- **Developer Ergonomics**: Canonical `translate()` along with concise aliases `trans()` and `t()`, available both on `ctx` and as standalone functions anywhere in your service layers.
|
|
14
|
+
- **Automatic Validation Localization**: Intercepts `ctx.validate()` failures and transforms schema `v` errors into localized 422 JSON payloads based on the requester's language.
|
|
15
|
+
- **Smart Locale Detection**: Resolves language preference from `Accept-Language` headers (with `q` weight parsing), URL query parameters (`?lang=es-ES`), or cookies.
|
|
16
|
+
- **Built-in Community Locales**: Ships with complete base translations for `pt-BR`, `en-US`, and `es-ES`.
|
|
17
|
+
- **Regional Formatting**: Built-in `formatCurrency()` and `formatDate()` utilities utilizing native `Intl`.
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## 📦 Installation
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
pnpm add @argos-js/i18n
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## 🚀 Quick Start
|
|
30
|
+
|
|
31
|
+
### 1. Register the Plugin
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
import { ArgosApp } from '@argos-js/core';
|
|
35
|
+
import { i18nPlugin, ptBR, enUS, esES } from '@argos-js/i18n';
|
|
36
|
+
|
|
37
|
+
const app = new ArgosApp();
|
|
38
|
+
|
|
39
|
+
await app.register(
|
|
40
|
+
i18nPlugin({
|
|
41
|
+
defaultLocale: 'pt-BR',
|
|
42
|
+
supportedLocales: ['pt-BR', 'en-US', 'es-ES'],
|
|
43
|
+
locales: {
|
|
44
|
+
'pt-BR': ptBR,
|
|
45
|
+
'en-US': enUS,
|
|
46
|
+
'es-ES': esES,
|
|
47
|
+
},
|
|
48
|
+
detection: {
|
|
49
|
+
header: 'accept-language',
|
|
50
|
+
query: 'lang', // e.g. ?lang=en-US
|
|
51
|
+
},
|
|
52
|
+
autoLocalizeValidation: true,
|
|
53
|
+
})
|
|
54
|
+
);
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### 2. Using in Controllers
|
|
58
|
+
|
|
59
|
+
Use `ctx.translate`, `ctx.trans`, or `ctx.t` directly:
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
app.get('/dashboard', (ctx) => {
|
|
63
|
+
const userName = 'Alice';
|
|
64
|
+
|
|
65
|
+
return ctx.json({
|
|
66
|
+
locale: ctx.locale, // e.g. 'pt-BR'
|
|
67
|
+
greeting: ctx.trans('common.welcome', { name: userName }),
|
|
68
|
+
balance: ctx.formatCurrency(1450.9, 'BRL'),
|
|
69
|
+
lastLogin: ctx.formatDate(new Date(), { dateStyle: 'medium' }),
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### 3. Standalone Usage in Services
|
|
75
|
+
|
|
76
|
+
Because `@argos-js/i18n` leverages `AsyncLocalStorage`, you can call `translate` or its aliases anywhere inside your business logic without passing `ctx`:
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
import { trans, t, translate } from '@argos-js/i18n';
|
|
80
|
+
|
|
81
|
+
export class OrderService {
|
|
82
|
+
async notifyCustomer(orderId: number) {
|
|
83
|
+
// Automatically uses the active request's language
|
|
84
|
+
const msg = trans('orders.paid_success', { id: orderId });
|
|
85
|
+
await emailClient.send(msg);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
---
|
|
91
|
+
|
|
92
|
+
## 🛡️ Automatic Validation Localization (422)
|
|
93
|
+
|
|
94
|
+
When validating schemas with `ctx.validate(schema)`, `@argos-js/i18n` automatically translates the validation errors into the requester's language:
|
|
95
|
+
|
|
96
|
+
```typescript
|
|
97
|
+
import { v } from '@argos-js/core';
|
|
98
|
+
|
|
99
|
+
app.post('/users', async (ctx) => {
|
|
100
|
+
const payload = await ctx.validate({
|
|
101
|
+
email: v.string().email(),
|
|
102
|
+
name: v.string().min(3),
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
return ctx.json({ success: true, data: payload });
|
|
106
|
+
});
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Response for Portuguese Requester (`Accept-Language: pt-BR`):
|
|
110
|
+
```json
|
|
111
|
+
{
|
|
112
|
+
"success": false,
|
|
113
|
+
"error": "Falha na validação",
|
|
114
|
+
"fields": {
|
|
115
|
+
"email": "O campo deve ser um endereço de e-mail válido",
|
|
116
|
+
"name": "O campo deve conter no mínimo 3 caracteres"
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Response for Spanish Requester (`Accept-Language: es-ES`):
|
|
122
|
+
```json
|
|
123
|
+
{
|
|
124
|
+
"success": false,
|
|
125
|
+
"error": "Validación fallida",
|
|
126
|
+
"fields": {
|
|
127
|
+
"email": "El campo debe ser una dirección de correo válida",
|
|
128
|
+
"name": "El campo debe contener al menos 3 caracteres"
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### Response for English Requester (`Accept-Language: en-US`):
|
|
134
|
+
```json
|
|
135
|
+
{
|
|
136
|
+
"success": false,
|
|
137
|
+
"error": "Validation failed",
|
|
138
|
+
"fields": {
|
|
139
|
+
"email": "The field must be a valid email address",
|
|
140
|
+
"name": "The field must contain at least 3 characters"
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
## 🌐 Community Translations & Adding New Locales
|
|
148
|
+
|
|
149
|
+
Adding a new language is straightforward. Create a dictionary object matching the required keys and pass it to `locales`:
|
|
150
|
+
|
|
151
|
+
```typescript
|
|
152
|
+
// src/locales/fr-FR.ts
|
|
153
|
+
export const frFR = {
|
|
154
|
+
validation: {
|
|
155
|
+
required: 'Le champ est obligatoire',
|
|
156
|
+
string: 'Le champ doit être une chaîne',
|
|
157
|
+
number: 'Le champ doit être un nombre',
|
|
158
|
+
email: 'Le champ doit être une adresse e-mail valide',
|
|
159
|
+
min_length: 'Le champ doit contenir au moins {min} caractères',
|
|
160
|
+
failed: 'Échec de la validation',
|
|
161
|
+
},
|
|
162
|
+
common: {
|
|
163
|
+
welcome: 'Bienvenue, {name} !',
|
|
164
|
+
},
|
|
165
|
+
};
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
Register it in your app:
|
|
169
|
+
|
|
170
|
+
```typescript
|
|
171
|
+
import { frFR } from './locales/fr-FR';
|
|
172
|
+
|
|
173
|
+
await app.register(
|
|
174
|
+
i18nPlugin({
|
|
175
|
+
defaultLocale: 'pt-BR',
|
|
176
|
+
locales: {
|
|
177
|
+
'fr-FR': frFR,
|
|
178
|
+
},
|
|
179
|
+
})
|
|
180
|
+
);
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
---
|
|
184
|
+
|
|
185
|
+
## 🧰 Regional Formatting
|
|
186
|
+
|
|
187
|
+
```typescript
|
|
188
|
+
import { formatCurrency, formatDate } from '@argos-js/i18n';
|
|
189
|
+
|
|
190
|
+
// Automatically uses the active request locale, or pass explicitly:
|
|
191
|
+
formatCurrency(1234.56, 'USD', 'en-US'); // "$1,234.56"
|
|
192
|
+
formatCurrency(1234.56, 'BRL', 'pt-BR'); // "R$ 1.234,56"
|
|
193
|
+
formatCurrency(1234.56, 'EUR', 'es-ES'); // "1.234,56 €"
|
|
194
|
+
|
|
195
|
+
formatDate(new Date(), { dateStyle: 'short' }); // "02/10/2026"
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
---
|
|
199
|
+
|
|
200
|
+
## 📚 API Reference
|
|
201
|
+
|
|
202
|
+
### Functions & Aliases
|
|
203
|
+
- `translate(key, params?, options?)`: Canonical translation function.
|
|
204
|
+
- `trans(key, params?, options?)`: Shorter alias for `translate`.
|
|
205
|
+
- `t(key, params?, options?)`: Ultra-short alias for `translate`.
|
|
206
|
+
- `formatCurrency(value, currency, locale?)`: Localized currency formatter.
|
|
207
|
+
- `formatDate(date, options?, locale?)`: Localized date and time formatter.
|
|
208
|
+
- `getActiveLocale()`: Retrieves the current request's locale tag.
|
|
209
|
+
|
|
210
|
+
### Plugin
|
|
211
|
+
- `i18nPlugin(options: I18nOptions)`: Plugin factory for ArgosApp.
|
|
212
|
+
|
|
213
|
+
### Base Locales
|
|
214
|
+
- `ptBR`: Brazilian Portuguese dictionary.
|
|
215
|
+
- `enUS`: English dictionary.
|
|
216
|
+
- `esES`: Spanish dictionary.
|
|
217
|
+
|
|
218
|
+
---
|
|
219
|
+
|
|
220
|
+
## 📄 License
|
|
221
|
+
|
|
222
|
+
MIT © Argos-JS
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Formats a numeric value into a localized currency string.
|
|
3
|
+
*
|
|
4
|
+
* @param value The monetary value to format
|
|
5
|
+
* @param currency The ISO 4217 currency code (e.g. 'BRL', 'USD', 'EUR')
|
|
6
|
+
* @param locale Optional locale tag; defaults to the active request-scoped locale
|
|
7
|
+
* @returns Localized currency string
|
|
8
|
+
*/
|
|
9
|
+
export declare function formatCurrency(value: number, currency: string, locale?: string): string;
|
|
10
|
+
/**
|
|
11
|
+
* Formats a Date, timestamp, or date string into a localized date string.
|
|
12
|
+
*
|
|
13
|
+
* @param date The Date object, ISO timestamp, or milliseconds number
|
|
14
|
+
* @param options Intl.DateTimeFormatOptions (e.g. { dateStyle: 'short' })
|
|
15
|
+
* @param locale Optional locale tag; defaults to the active request-scoped locale
|
|
16
|
+
* @returns Localized date string
|
|
17
|
+
*/
|
|
18
|
+
export declare function formatDate(date: Date | string | number, options?: Intl.DateTimeFormatOptions, locale?: string): string;
|
|
19
|
+
//# sourceMappingURL=formatters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatters.d.ts","sourceRoot":"","sources":["../src/formatters.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAMvF;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CACxB,IAAI,EAAE,IAAI,GAAG,MAAM,GAAG,MAAM,EAC5B,OAAO,CAAC,EAAE,IAAI,CAAC,qBAAqB,EACpC,MAAM,CAAC,EAAE,MAAM,GACd,MAAM,CAIR"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatCurrency = formatCurrency;
|
|
4
|
+
exports.formatDate = formatDate;
|
|
5
|
+
const i18n_manager_js_1 = require("./i18n-manager.js");
|
|
6
|
+
/**
|
|
7
|
+
* Formats a numeric value into a localized currency string.
|
|
8
|
+
*
|
|
9
|
+
* @param value The monetary value to format
|
|
10
|
+
* @param currency The ISO 4217 currency code (e.g. 'BRL', 'USD', 'EUR')
|
|
11
|
+
* @param locale Optional locale tag; defaults to the active request-scoped locale
|
|
12
|
+
* @returns Localized currency string
|
|
13
|
+
*/
|
|
14
|
+
function formatCurrency(value, currency, locale) {
|
|
15
|
+
const targetLocale = locale || (0, i18n_manager_js_1.getActiveLocale)() || 'en-US';
|
|
16
|
+
return new Intl.NumberFormat(targetLocale, {
|
|
17
|
+
style: 'currency',
|
|
18
|
+
currency,
|
|
19
|
+
}).format(value);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Formats a Date, timestamp, or date string into a localized date string.
|
|
23
|
+
*
|
|
24
|
+
* @param date The Date object, ISO timestamp, or milliseconds number
|
|
25
|
+
* @param options Intl.DateTimeFormatOptions (e.g. { dateStyle: 'short' })
|
|
26
|
+
* @param locale Optional locale tag; defaults to the active request-scoped locale
|
|
27
|
+
* @returns Localized date string
|
|
28
|
+
*/
|
|
29
|
+
function formatDate(date, options, locale) {
|
|
30
|
+
const targetLocale = locale || (0, i18n_manager_js_1.getActiveLocale)() || 'en-US';
|
|
31
|
+
const dateObj = date instanceof Date ? date : new Date(date);
|
|
32
|
+
return new Intl.DateTimeFormat(targetLocale, options).format(dateObj);
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=formatters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatters.js","sourceRoot":"","sources":["../src/formatters.ts"],"names":[],"mappings":";;AAUA,wCAMC;AAUD,gCAQC;AAlCD,uDAAoD;AAEpD;;;;;;;GAOG;AACH,SAAgB,cAAc,CAAC,KAAa,EAAE,QAAgB,EAAE,MAAe;IAC7E,MAAM,YAAY,GAAG,MAAM,IAAI,IAAA,iCAAe,GAAE,IAAI,OAAO,CAAC;IAC5D,OAAO,IAAI,IAAI,CAAC,YAAY,CAAC,YAAY,EAAE;QACzC,KAAK,EAAE,UAAU;QACjB,QAAQ;KACT,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACnB,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,UAAU,CACxB,IAA4B,EAC5B,OAAoC,EACpC,MAAe;IAEf,MAAM,YAAY,GAAG,MAAM,IAAI,IAAA,iCAAe,GAAE,IAAI,OAAO,CAAC;IAC5D,MAAM,OAAO,GAAG,IAAI,YAAY,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC;IAC7D,OAAO,IAAI,IAAI,CAAC,cAAc,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;AACxE,CAAC"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { I18nDictionary, I18nLocales, I18nOptions } from './types.js';
|
|
2
|
+
export declare class I18nManager {
|
|
3
|
+
private defaultLocale;
|
|
4
|
+
private supportedLocales;
|
|
5
|
+
private dictionaries;
|
|
6
|
+
private detection;
|
|
7
|
+
private fallbackToDefault;
|
|
8
|
+
private asyncLocalStorage;
|
|
9
|
+
constructor(options?: I18nOptions);
|
|
10
|
+
configure(options: I18nOptions): void;
|
|
11
|
+
/**
|
|
12
|
+
* Registers or deep merges a locale dictionary.
|
|
13
|
+
*/
|
|
14
|
+
registerLocale(locale: string, dict: I18nDictionary): void;
|
|
15
|
+
/**
|
|
16
|
+
* Registers multiple locale dictionaries at once.
|
|
17
|
+
*/
|
|
18
|
+
registerLocales(locales: I18nLocales): void;
|
|
19
|
+
/**
|
|
20
|
+
* Retrieves the currently active locale for the async execution context.
|
|
21
|
+
*/
|
|
22
|
+
getActiveLocale(): string;
|
|
23
|
+
/**
|
|
24
|
+
* Executes a callback within an isolated request-scoped locale context.
|
|
25
|
+
*/
|
|
26
|
+
runInContext<R>(locale: string, callback: () => R): R;
|
|
27
|
+
/**
|
|
28
|
+
* Transitions current async context to the given locale using enterWith.
|
|
29
|
+
*/
|
|
30
|
+
enterContext(locale: string): void;
|
|
31
|
+
/**
|
|
32
|
+
* Detects the preferred locale from request query, headers, or cookies.
|
|
33
|
+
*/
|
|
34
|
+
detectLocale(request: {
|
|
35
|
+
headers?: Record<string, string | string[] | undefined>;
|
|
36
|
+
query?: Record<string, any>;
|
|
37
|
+
cookies?: string;
|
|
38
|
+
}): string;
|
|
39
|
+
/**
|
|
40
|
+
* Fast template interpolation substituting {param} tokens.
|
|
41
|
+
*/
|
|
42
|
+
interpolate(template: string, params?: Record<string, any>): string;
|
|
43
|
+
/**
|
|
44
|
+
* Resolves a key from dictionary supporting dot notation ('validation.required').
|
|
45
|
+
*/
|
|
46
|
+
private resolveKey;
|
|
47
|
+
/**
|
|
48
|
+
* Translates a message key into the active or requested locale.
|
|
49
|
+
*/
|
|
50
|
+
translate(key: string, params?: Record<string, any>, options?: {
|
|
51
|
+
locale?: string;
|
|
52
|
+
}): string;
|
|
53
|
+
private parseAcceptLanguage;
|
|
54
|
+
private matchSupportedLocale;
|
|
55
|
+
private extractCookie;
|
|
56
|
+
private deepMerge;
|
|
57
|
+
}
|
|
58
|
+
export declare function getI18nManager(): I18nManager;
|
|
59
|
+
export declare function setI18nManager(manager: I18nManager): void;
|
|
60
|
+
export declare function getActiveLocale(): string;
|
|
61
|
+
/**
|
|
62
|
+
* Translates a key using the request-scoped active locale or explicit override.
|
|
63
|
+
*/
|
|
64
|
+
export declare function translate(key: string, params?: Record<string, any>, options?: {
|
|
65
|
+
locale?: string;
|
|
66
|
+
}): string;
|
|
67
|
+
/**
|
|
68
|
+
* Direct alias for `translate`.
|
|
69
|
+
*/
|
|
70
|
+
export declare const trans: typeof translate;
|
|
71
|
+
/**
|
|
72
|
+
* Ultra-short alias for `translate`.
|
|
73
|
+
*/
|
|
74
|
+
export declare const t: typeof translate;
|
|
75
|
+
//# sourceMappingURL=i18n-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"i18n-manager.d.ts","sourceRoot":"","sources":["../src/i18n-manager.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAEV,cAAc,EACd,WAAW,EACX,WAAW,EACZ,MAAM,YAAY,CAAC;AAOpB,qBAAa,WAAW;IACtB,OAAO,CAAC,aAAa,CAAmB;IACxC,OAAO,CAAC,gBAAgB,CAAyC;IACjE,OAAO,CAAC,YAAY,CAA0C;IAC9D,OAAO,CAAC,SAAS,CAIf;IACF,OAAO,CAAC,iBAAiB,CAAiB;IAC1C,OAAO,CAAC,iBAAiB,CAAgD;gBAE7D,OAAO,CAAC,EAAE,WAAW;IAW1B,SAAS,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI;IAkB5C;;OAEG;IACI,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,cAAc,GAAG,IAAI;IAQjE;;OAEG;IACI,eAAe,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI;IAMlD;;OAEG;IACI,eAAe,IAAI,MAAM;IAKhC;;OAEG;IACI,YAAY,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,GAAG,CAAC;IAI5D;;OAEG;IACI,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAIzC;;OAEG;IACI,YAAY,CAAC,OAAO,EAAE;QAC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= exports.I18nManager = void 0;
|
|
4
|
+
exports.getI18nManager = getI18nManager;
|
|
5
|
+
exports.setI18nManager = setI18nManager;
|
|
6
|
+
exports.getActiveLocale = getActiveLocale;
|
|
7
|
+
exports.translate = translate;
|
|
8
|
+
const node_async_hooks_1 = require("node:async_hooks");
|
|
9
|
+
const index_js_1 = require("./locales/index.js");
|
|
10
|
+
class I18nManager {
|
|
11
|
+
defaultLocale = 'pt-BR';
|
|
12
|
+
supportedLocales = ['pt-BR', 'en-US', 'es-ES'];
|
|
13
|
+
dictionaries = new Map();
|
|
14
|
+
detection = {
|
|
15
|
+
header: 'accept-language',
|
|
16
|
+
query: 'lang',
|
|
17
|
+
cookie: 'lang',
|
|
18
|
+
};
|
|
19
|
+
fallbackToDefault = true;
|
|
20
|
+
asyncLocalStorage = new node_async_hooks_1.AsyncLocalStorage();
|
|
21
|
+
constructor(options) {
|
|
22
|
+
// Seed default community dictionaries
|
|
23
|
+
this.registerLocale('pt-BR', index_js_1.ptBR);
|
|
24
|
+
this.registerLocale('en-US', index_js_1.enUS);
|
|
25
|
+
this.registerLocale('es-ES', index_js_1.esES);
|
|
26
|
+
if (options) {
|
|
27
|
+
this.configure(options);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
configure(options) {
|
|
31
|
+
if (options.defaultLocale) {
|
|
32
|
+
this.defaultLocale = options.defaultLocale;
|
|
33
|
+
}
|
|
34
|
+
if (options.supportedLocales && options.supportedLocales.length > 0) {
|
|
35
|
+
this.supportedLocales = options.supportedLocales;
|
|
36
|
+
}
|
|
37
|
+
if (options.locales) {
|
|
38
|
+
this.registerLocales(options.locales);
|
|
39
|
+
}
|
|
40
|
+
if (options.detection) {
|
|
41
|
+
this.detection = { ...this.detection, ...options.detection };
|
|
42
|
+
}
|
|
43
|
+
if (options.fallbackToDefault !== undefined) {
|
|
44
|
+
this.fallbackToDefault = options.fallbackToDefault;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Registers or deep merges a locale dictionary.
|
|
49
|
+
*/
|
|
50
|
+
registerLocale(locale, dict) {
|
|
51
|
+
const existing = this.dictionaries.get(locale) || {};
|
|
52
|
+
this.dictionaries.set(locale, this.deepMerge(existing, dict));
|
|
53
|
+
if (!this.supportedLocales.includes(locale)) {
|
|
54
|
+
this.supportedLocales.push(locale);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Registers multiple locale dictionaries at once.
|
|
59
|
+
*/
|
|
60
|
+
registerLocales(locales) {
|
|
61
|
+
for (const [locale, dict] of Object.entries(locales)) {
|
|
62
|
+
this.registerLocale(locale, dict);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Retrieves the currently active locale for the async execution context.
|
|
67
|
+
*/
|
|
68
|
+
getActiveLocale() {
|
|
69
|
+
const store = this.asyncLocalStorage.getStore();
|
|
70
|
+
return store?.locale || this.defaultLocale;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Executes a callback within an isolated request-scoped locale context.
|
|
74
|
+
*/
|
|
75
|
+
runInContext(locale, callback) {
|
|
76
|
+
return this.asyncLocalStorage.run({ locale }, callback);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Transitions current async context to the given locale using enterWith.
|
|
80
|
+
*/
|
|
81
|
+
enterContext(locale) {
|
|
82
|
+
this.asyncLocalStorage.enterWith({ locale });
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Detects the preferred locale from request query, headers, or cookies.
|
|
86
|
+
*/
|
|
87
|
+
detectLocale(request) {
|
|
88
|
+
const queryKey = this.detection.query || 'lang';
|
|
89
|
+
const altQueryKey = queryKey === 'lang' ? 'locale' : 'lang';
|
|
90
|
+
// 1. URL Query parameter check (e.g. ?lang=en-US or ?locale=pt-BR)
|
|
91
|
+
if (request.query) {
|
|
92
|
+
const qVal = request.query[queryKey] || request.query[altQueryKey];
|
|
93
|
+
if (typeof qVal === 'string' && qVal.trim()) {
|
|
94
|
+
const matched = this.matchSupportedLocale(qVal.trim());
|
|
95
|
+
if (matched)
|
|
96
|
+
return matched;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
// 2. Cookie check
|
|
100
|
+
const cookieKey = this.detection.cookie || 'lang';
|
|
101
|
+
if (request.cookies) {
|
|
102
|
+
const cookieMatch = this.extractCookie(request.cookies, cookieKey);
|
|
103
|
+
if (cookieMatch) {
|
|
104
|
+
const matched = this.matchSupportedLocale(cookieMatch);
|
|
105
|
+
if (matched)
|
|
106
|
+
return matched;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
// 3. HTTP Header check (e.g. Accept-Language)
|
|
110
|
+
const headerKey = (this.detection.header || 'accept-language').toLowerCase();
|
|
111
|
+
const rawHeader = request.headers?.[headerKey];
|
|
112
|
+
const headerVal = Array.isArray(rawHeader) ? rawHeader[0] : rawHeader;
|
|
113
|
+
if (typeof headerVal === 'string' && headerVal.trim()) {
|
|
114
|
+
const matched = this.parseAcceptLanguage(headerVal);
|
|
115
|
+
if (matched)
|
|
116
|
+
return matched;
|
|
117
|
+
}
|
|
118
|
+
return this.defaultLocale;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Fast template interpolation substituting {param} tokens.
|
|
122
|
+
*/
|
|
123
|
+
interpolate(template, params) {
|
|
124
|
+
if (!params || Object.keys(params).length === 0) {
|
|
125
|
+
return template;
|
|
126
|
+
}
|
|
127
|
+
return template.replace(/\{([a-zA-Z0-9_]+)\}/g, (match, token) => {
|
|
128
|
+
if (token in params && params[token] !== undefined && params[token] !== null) {
|
|
129
|
+
return String(params[token]);
|
|
130
|
+
}
|
|
131
|
+
return match;
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Resolves a key from dictionary supporting dot notation ('validation.required').
|
|
136
|
+
*/
|
|
137
|
+
resolveKey(dict, key) {
|
|
138
|
+
if (key in dict && typeof dict[key] === 'string') {
|
|
139
|
+
return dict[key];
|
|
140
|
+
}
|
|
141
|
+
const parts = key.split('.');
|
|
142
|
+
let current = dict;
|
|
143
|
+
for (const part of parts) {
|
|
144
|
+
if (current && typeof current === 'object' && part in current) {
|
|
145
|
+
current = current[part];
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
return undefined;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return typeof current === 'string' ? current : undefined;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Translates a message key into the active or requested locale.
|
|
155
|
+
*/
|
|
156
|
+
translate(key, params, options) {
|
|
157
|
+
const targetLocale = options?.locale || this.getActiveLocale();
|
|
158
|
+
const targetDict = this.dictionaries.get(targetLocale);
|
|
159
|
+
let template;
|
|
160
|
+
if (targetDict) {
|
|
161
|
+
template = this.resolveKey(targetDict, key);
|
|
162
|
+
}
|
|
163
|
+
// Fallback to defaultLocale if missing
|
|
164
|
+
if (template === undefined && targetLocale !== this.defaultLocale && this.fallbackToDefault) {
|
|
165
|
+
const defaultDict = this.dictionaries.get(this.defaultLocale);
|
|
166
|
+
if (defaultDict) {
|
|
167
|
+
template = this.resolveKey(defaultDict, key);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
// If key not found anywhere, return the key as fallback
|
|
171
|
+
if (template === undefined) {
|
|
172
|
+
return this.interpolate(key, params);
|
|
173
|
+
}
|
|
174
|
+
return this.interpolate(template, params);
|
|
175
|
+
}
|
|
176
|
+
parseAcceptLanguage(header) {
|
|
177
|
+
const candidates = header
|
|
178
|
+
.split(',')
|
|
179
|
+
.map((part) => {
|
|
180
|
+
const [lang, qPart] = part.trim().split(';');
|
|
181
|
+
let q = 1.0;
|
|
182
|
+
if (qPart) {
|
|
183
|
+
const match = qPart.match(/q=([0-9.]+)/);
|
|
184
|
+
if (match)
|
|
185
|
+
q = parseFloat(match[1]);
|
|
186
|
+
}
|
|
187
|
+
return { lang: lang.trim(), q };
|
|
188
|
+
})
|
|
189
|
+
.filter((c) => c.lang && !isNaN(c.q))
|
|
190
|
+
.sort((a, b) => b.q - a.q);
|
|
191
|
+
for (const candidate of candidates) {
|
|
192
|
+
const matched = this.matchSupportedLocale(candidate.lang);
|
|
193
|
+
if (matched)
|
|
194
|
+
return matched;
|
|
195
|
+
}
|
|
196
|
+
return null;
|
|
197
|
+
}
|
|
198
|
+
matchSupportedLocale(lang) {
|
|
199
|
+
const cleanLang = lang.trim();
|
|
200
|
+
if (!cleanLang || cleanLang === '*')
|
|
201
|
+
return null;
|
|
202
|
+
// 1. Exact match (case insensitive)
|
|
203
|
+
for (const supported of this.supportedLocales) {
|
|
204
|
+
if (supported.toLowerCase() === cleanLang.toLowerCase()) {
|
|
205
|
+
return supported;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
// 2. Base language prefix match (e.g. 'pt' matches 'pt-BR', 'es' matches 'es-ES')
|
|
209
|
+
const primaryTag = cleanLang.split(/[-_]/)[0].toLowerCase();
|
|
210
|
+
for (const supported of this.supportedLocales) {
|
|
211
|
+
const supportedPrimary = supported.split(/[-_]/)[0].toLowerCase();
|
|
212
|
+
if (supportedPrimary === primaryTag) {
|
|
213
|
+
return supported;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
return null;
|
|
217
|
+
}
|
|
218
|
+
extractCookie(cookieHeader, name) {
|
|
219
|
+
const pairs = cookieHeader.split(';');
|
|
220
|
+
for (const pair of pairs) {
|
|
221
|
+
const [key, value] = pair.trim().split('=');
|
|
222
|
+
if (key && key.trim() === name && value) {
|
|
223
|
+
return decodeURIComponent(value.trim());
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
return null;
|
|
227
|
+
}
|
|
228
|
+
deepMerge(target, source) {
|
|
229
|
+
const output = { ...target };
|
|
230
|
+
for (const key of Object.keys(source)) {
|
|
231
|
+
if (source[key] &&
|
|
232
|
+
typeof source[key] === 'object' &&
|
|
233
|
+
!Array.isArray(source[key]) &&
|
|
234
|
+
key in target &&
|
|
235
|
+
typeof target[key] === 'object') {
|
|
236
|
+
output[key] = this.deepMerge(target[key], source[key]);
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
output[key] = source[key];
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
return output;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
exports.I18nManager = I18nManager;
|
|
246
|
+
// Global default manager instance
|
|
247
|
+
let globalManager = new I18nManager();
|
|
248
|
+
function getI18nManager() {
|
|
249
|
+
return globalManager;
|
|
250
|
+
}
|
|
251
|
+
function setI18nManager(manager) {
|
|
252
|
+
globalManager = manager;
|
|
253
|
+
}
|
|
254
|
+
function getActiveLocale() {
|
|
255
|
+
return globalManager.getActiveLocale();
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Translates a key using the request-scoped active locale or explicit override.
|
|
259
|
+
*/
|
|
260
|
+
function translate(key, params, options) {
|
|
261
|
+
return globalManager.translate(key, params, options);
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Direct alias for `translate`.
|
|
265
|
+
*/
|
|
266
|
+
exports.trans = translate;
|
|
267
|
+
/**
|
|
268
|
+
* Ultra-short alias for `translate`.
|
|
269
|
+
*/
|
|
270
|
+
exports.t = translate;
|
|
271
|
+
//# sourceMappingURL=i18n-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"i18n-manager.js","sourceRoot":"","sources":["../src/i18n-manager.ts"],"names":[],"mappings":";;;AA4RA,wCAEC;AAED,wCAEC;AAED,0CAEC;AAKD,8BAMC;AAjTD,uDAAqD;AAOrD,iDAAsD;AAMtD,MAAa,WAAW;IACd,aAAa,GAAW,OAAO,CAAC;IAChC,gBAAgB,GAAa,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IACzD,YAAY,GAAgC,IAAI,GAAG,EAAE,CAAC;IACtD,SAAS,GAAqB;QACpC,MAAM,EAAE,iBAAiB;QACzB,KAAK,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