intor 2.2.1 → 2.2.3
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/dist/config/index.d.cts +9 -9
- package/dist/config/index.d.ts +9 -9
- package/dist/index.cjs +307 -453
- package/dist/index.d.cts +109 -51
- package/dist/index.d.ts +109 -51
- package/dist/index.js +309 -456
- package/dist/next/index.cjs +141 -148
- package/dist/next/index.d.cts +9 -9
- package/dist/next/index.d.ts +9 -9
- package/dist/next/index.js +139 -147
- package/dist/next/middleware/index.d.cts +9 -9
- package/dist/next/middleware/index.d.ts +9 -9
- package/dist/next/server/index.cjs +287 -430
- package/dist/next/server/index.d.cts +9 -9
- package/dist/next/server/index.d.ts +9 -9
- package/dist/next/server/index.js +289 -433
- package/package.json +6 -12
package/dist/index.d.cts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Level, NormalizerConfig, FormatterConfig, LoggerPreset } from 'logry/edge';
|
|
2
|
-
import { Locale, LocaleMessages, FallbackLocalesMap, ScopedLeafKeys, LocalizedLeafKeys, Replacement, TranslateHandlers, LocalizedNodeKeys } from 'intor-translator';
|
|
2
|
+
import { Locale, LocaleMessages, FallbackLocalesMap, NestedMessage, ScopedLeafKeys, LocalizedLeafKeys, Replacement, TranslateHandlers, LocalizedNodeKeys } from 'intor-translator';
|
|
3
3
|
export { FallbackLocalesMap, FormatHandler, LeafKeys, LoadingHandler, Locale, LocaleMessages, LocalizedLeafKeys, LocalizedMessagesUnion, MissingHandler, NestedMessage, NodeKeys, Replacement, ScopedLeafKeys, TranslateHandlerContext, TranslateHandlers, Translator } from 'intor-translator';
|
|
4
|
-
import { Logger } from 'logry';
|
|
5
4
|
import Keyv from 'keyv';
|
|
5
|
+
import { Logger } from 'logry';
|
|
6
6
|
|
|
7
7
|
type CookieRawOptions = {
|
|
8
8
|
/** Completely disable cookie usage (no read, no write, no lookup by name) - default: false */
|
|
@@ -44,28 +44,28 @@ type RouteNamespaces = {
|
|
|
44
44
|
[key: string]: string[];
|
|
45
45
|
default: string[];
|
|
46
46
|
};
|
|
47
|
-
interface
|
|
47
|
+
interface RemoteHeaders {
|
|
48
48
|
authorization?: string;
|
|
49
49
|
"x-api-key"?: string;
|
|
50
50
|
[key: string]: string | undefined;
|
|
51
51
|
}
|
|
52
52
|
type BaseLoaderOptions = {
|
|
53
|
-
|
|
53
|
+
rootDir?: string;
|
|
54
54
|
namespaces?: string[];
|
|
55
55
|
routeNamespaces?: RouteNamespaces;
|
|
56
56
|
concurrency?: number;
|
|
57
57
|
lazyLoad?: boolean;
|
|
58
58
|
};
|
|
59
|
-
type
|
|
60
|
-
type: "
|
|
59
|
+
type LocalLoader = BaseLoaderOptions & {
|
|
60
|
+
type: "local";
|
|
61
61
|
};
|
|
62
|
-
type
|
|
63
|
-
type: "
|
|
64
|
-
|
|
65
|
-
|
|
62
|
+
type RemoteLoader = BaseLoaderOptions & {
|
|
63
|
+
type: "remote";
|
|
64
|
+
remoteUrl: string;
|
|
65
|
+
remoteHeaders?: RemoteHeaders;
|
|
66
66
|
fullReload?: boolean;
|
|
67
67
|
};
|
|
68
|
-
type LoaderOptions =
|
|
68
|
+
type LoaderOptions = LocalLoader | RemoteLoader;
|
|
69
69
|
|
|
70
70
|
type LoggerOptions = {
|
|
71
71
|
level?: Level;
|
|
@@ -166,40 +166,92 @@ interface IntorResult {
|
|
|
166
166
|
}
|
|
167
167
|
|
|
168
168
|
/**
|
|
169
|
-
*
|
|
169
|
+
* Represents a collection of localized messages.
|
|
170
170
|
*
|
|
171
|
-
*
|
|
172
|
-
*
|
|
173
|
-
*
|
|
171
|
+
* - Each key is a namespace or message identifier, and the value is a
|
|
172
|
+
* `NestedMessage` object that can contain nested message structures.
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```ts
|
|
176
|
+
* const messages: Messages = {
|
|
177
|
+
* ui: {
|
|
178
|
+
* greeting: "Hello",
|
|
179
|
+
* farewell: "Goodbye"
|
|
180
|
+
* },
|
|
181
|
+
* errors: {
|
|
182
|
+
* network: "Network error occurred"
|
|
183
|
+
* }
|
|
184
|
+
* };
|
|
185
|
+
* ```
|
|
174
186
|
*/
|
|
175
|
-
|
|
187
|
+
type Messages = Record<string, NestedMessage>;
|
|
188
|
+
/**
|
|
189
|
+
* A function that reads messages from a given file path.
|
|
190
|
+
*
|
|
191
|
+
* - This function is expected to return a `Promise` that resolves to a `Messages` object.
|
|
192
|
+
* - It can be implemented to support different file formats such as JSON, YAML, or others.
|
|
193
|
+
*
|
|
194
|
+
* @param filePath - The path to the message file to read.
|
|
195
|
+
* @returns A Promise that resolves to a `Messages` object.
|
|
196
|
+
*
|
|
197
|
+
* @example
|
|
198
|
+
* ```ts
|
|
199
|
+
* const reader: MessagesReader = async (filePath) => {
|
|
200
|
+
* const content = await fs.promises.readFile(filePath, "utf-8");
|
|
201
|
+
* return JSON.parse(content) as Messages;
|
|
202
|
+
* };
|
|
203
|
+
* ```
|
|
204
|
+
*/
|
|
205
|
+
type MessagesReader = (filePath: string) => Promise<Messages>;
|
|
176
206
|
|
|
177
|
-
type
|
|
207
|
+
type LoadMessagesOptions = {
|
|
178
208
|
config: IntorResolvedConfig;
|
|
179
209
|
locale: Locale;
|
|
180
|
-
pathname
|
|
210
|
+
pathname?: string;
|
|
211
|
+
extraOptions?: {
|
|
212
|
+
exts?: string[];
|
|
213
|
+
messagesReader?: MessagesReader;
|
|
214
|
+
};
|
|
181
215
|
};
|
|
182
|
-
type
|
|
216
|
+
type LoadMessagesResult<C extends GenConfigKeys = "__default__"> = Promise<GenMessages<C> | undefined>;
|
|
183
217
|
|
|
184
218
|
/**
|
|
185
219
|
* Load messages for a given locale and pathname.
|
|
186
220
|
*
|
|
187
221
|
* - Resolve namespaces based on config and pathname.
|
|
188
|
-
* - Support both **local
|
|
222
|
+
* - Support both **local local** and **remote API** loaders.
|
|
189
223
|
* - Apply fallback locales if needed.
|
|
190
224
|
* - Cache messages if enabled (handled by underlying loader, not this function directly).
|
|
191
225
|
*/
|
|
192
|
-
declare const loadMessages: <C extends GenConfigKeys = "__default__">({ config, locale, pathname, }:
|
|
226
|
+
declare const loadMessages: <C extends GenConfigKeys = "__default__">({ config, locale, pathname, extraOptions: { exts, messagesReader }, }: LoadMessagesOptions) => LoadMessagesResult<C>;
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Global messages pool (cross-module + hot-reload safe)
|
|
230
|
+
*/
|
|
231
|
+
type MessagesPool = Keyv<LocaleMessages>;
|
|
232
|
+
declare global {
|
|
233
|
+
var __INTOR_MESSAGES_POOL__: MessagesPool | undefined;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Optional: clear all cache
|
|
237
|
+
* Useful in tests or dynamic reloads.
|
|
238
|
+
*/
|
|
239
|
+
declare function clearMessagesPool(): void;
|
|
193
240
|
|
|
194
241
|
interface LoadLocalMessagesOptions {
|
|
195
|
-
|
|
196
|
-
|
|
242
|
+
pool?: MessagesPool;
|
|
243
|
+
rootDir?: string;
|
|
244
|
+
locale: string;
|
|
197
245
|
fallbackLocales?: string[];
|
|
198
246
|
namespaces?: string[];
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
247
|
+
extraOptions?: {
|
|
248
|
+
concurrency?: number;
|
|
249
|
+
cacheOptions?: CacheResolvedOptions;
|
|
250
|
+
loggerOptions?: LoggerOptions & {
|
|
251
|
+
id?: string;
|
|
252
|
+
};
|
|
253
|
+
exts?: string[];
|
|
254
|
+
messagesReader?: MessagesReader;
|
|
203
255
|
};
|
|
204
256
|
}
|
|
205
257
|
|
|
@@ -211,14 +263,21 @@ interface LoadLocalMessagesOptions {
|
|
|
211
263
|
* - Cache messages if enabled.
|
|
212
264
|
* - Limit concurrent file reads for performance.
|
|
213
265
|
*/
|
|
214
|
-
declare const loadLocalMessages: ({
|
|
266
|
+
declare const loadLocalMessages: ({ pool, rootDir, locale, fallbackLocales, namespaces, extraOptions: { concurrency, cacheOptions, loggerOptions, exts, messagesReader, }, }: LoadLocalMessagesOptions) => Promise<LocaleMessages | undefined>;
|
|
215
267
|
|
|
216
|
-
interface
|
|
268
|
+
interface LoadRemoteMessagesOptions {
|
|
269
|
+
pool?: MessagesPool;
|
|
270
|
+
rootDir?: string;
|
|
217
271
|
locale: string;
|
|
218
272
|
fallbackLocales: string[];
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
273
|
+
namespaces?: string[];
|
|
274
|
+
remoteUrl: string;
|
|
275
|
+
remoteHeaders?: RemoteHeaders;
|
|
276
|
+
extraOptions?: {
|
|
277
|
+
cacheOptions?: CacheResolvedOptions;
|
|
278
|
+
loggerOptions?: LoggerOptions & {
|
|
279
|
+
id?: string;
|
|
280
|
+
};
|
|
222
281
|
};
|
|
223
282
|
}
|
|
224
283
|
|
|
@@ -228,7 +287,19 @@ interface LoadApiMessagesOptions extends Omit<ApiLoader, "type"> {
|
|
|
228
287
|
* - Fetch messages for a target locale with optional fallback locales.
|
|
229
288
|
* - Cache messages if enabled.
|
|
230
289
|
*/
|
|
231
|
-
declare const
|
|
290
|
+
declare const loadRemoteMessages: ({ pool, rootDir, remoteUrl, remoteHeaders, locale, fallbackLocales, namespaces, extraOptions: { cacheOptions, loggerOptions, }, }: LoadRemoteMessagesOptions) => Promise<LocaleMessages | undefined>;
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Entry point for initializing Intor.
|
|
294
|
+
*
|
|
295
|
+
* 1. Resolve context via adapter or fallback values.
|
|
296
|
+
* 2. Load messages if loader is enabled.
|
|
297
|
+
* 3. Merge static messages with loaded messages.
|
|
298
|
+
*/
|
|
299
|
+
declare const intor: (config: IntorResolvedConfig, i18nContext: GetI18nContext | Partial<I18nContext>, loadMessagesOptions?: {
|
|
300
|
+
exts?: string[];
|
|
301
|
+
messagesReader?: MessagesReader;
|
|
302
|
+
}) => Promise<IntorResult>;
|
|
232
303
|
|
|
233
304
|
/** Base properties shared by all translator instances. */
|
|
234
305
|
interface TranslatorBaseProps<M = unknown> {
|
|
@@ -284,10 +355,10 @@ declare function getTranslator<CK extends GenConfigKeys = "__default__", PK exte
|
|
|
284
355
|
}): Promise<TranslatorInstance<GenMessages<CK>, PK>>;
|
|
285
356
|
|
|
286
357
|
/**
|
|
287
|
-
*
|
|
288
|
-
* Loaded messages override static ones on conflict.
|
|
358
|
+
* Deeply merges loaded messages into static messages by locale.
|
|
359
|
+
* - Loaded messages override static ones on conflict.
|
|
289
360
|
*/
|
|
290
|
-
declare const mergeMessages: (staticMessages?: LocaleMessages, loadedMessages?: LocaleMessages |
|
|
361
|
+
declare const mergeMessages: (staticMessages?: LocaleMessages, loadedMessages?: LocaleMessages | undefined) => LocaleMessages;
|
|
291
362
|
|
|
292
363
|
type RawCacheKey = string | boolean | Array<string | number | boolean | undefined | null>;
|
|
293
364
|
declare const normalizeCacheKey: (key?: RawCacheKey, delimiter?: string) => string | null;
|
|
@@ -299,7 +370,7 @@ interface ResolveNamespacesOptions {
|
|
|
299
370
|
/**
|
|
300
371
|
* Resolves namespaces based on pathname.
|
|
301
372
|
*/
|
|
302
|
-
declare const resolveNamespaces: ({ config, pathname, }: ResolveNamespacesOptions) => string[];
|
|
373
|
+
declare const resolveNamespaces: ({ config, pathname, }: ResolveNamespacesOptions) => string[] | undefined;
|
|
303
374
|
|
|
304
375
|
/**
|
|
305
376
|
* Normalizes and finds the best matching locale from the supported locales list.
|
|
@@ -381,17 +452,4 @@ declare global {
|
|
|
381
452
|
*/
|
|
382
453
|
declare function clearLoggerPool(): void;
|
|
383
454
|
|
|
384
|
-
|
|
385
|
-
* Global messages pool (cross-module + hot-reload safe)
|
|
386
|
-
*/
|
|
387
|
-
type MessagesPool = Keyv<LocaleMessages>;
|
|
388
|
-
declare global {
|
|
389
|
-
var __INTOR_MESSAGES_POOL__: MessagesPool | undefined;
|
|
390
|
-
}
|
|
391
|
-
/**
|
|
392
|
-
* Optional: clear all cache
|
|
393
|
-
* Useful in tests or dynamic reloads.
|
|
394
|
-
*/
|
|
395
|
-
declare function clearMessagesPool(): void;
|
|
396
|
-
|
|
397
|
-
export { type I18nContext, type IntorResult, type LoadApiMessagesOptions, type LoadLocalMessagesOptions, PREFIX_PLACEHOLDER, clearLoggerPool, clearMessagesPool, extractPathname, getTranslator, intor, loadApiMessages, loadLocalMessages, loadMessages, mergeMessages, normalizeCacheKey, normalizeLocale, normalizePathname, resolveNamespaces, resolvePreferredLocale, standardizePathname };
|
|
455
|
+
export { type I18nContext, type IntorResult, type LoadLocalMessagesOptions, type LoadRemoteMessagesOptions, type Messages, type MessagesReader, PREFIX_PLACEHOLDER, clearLoggerPool, clearMessagesPool, extractPathname, getTranslator, intor, loadLocalMessages, loadMessages, loadRemoteMessages, mergeMessages, normalizeCacheKey, normalizeLocale, normalizePathname, resolveNamespaces, resolvePreferredLocale, standardizePathname };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Level, NormalizerConfig, FormatterConfig, LoggerPreset } from 'logry/edge';
|
|
2
|
-
import { Locale, LocaleMessages, FallbackLocalesMap, ScopedLeafKeys, LocalizedLeafKeys, Replacement, TranslateHandlers, LocalizedNodeKeys } from 'intor-translator';
|
|
2
|
+
import { Locale, LocaleMessages, FallbackLocalesMap, NestedMessage, ScopedLeafKeys, LocalizedLeafKeys, Replacement, TranslateHandlers, LocalizedNodeKeys } from 'intor-translator';
|
|
3
3
|
export { FallbackLocalesMap, FormatHandler, LeafKeys, LoadingHandler, Locale, LocaleMessages, LocalizedLeafKeys, LocalizedMessagesUnion, MissingHandler, NestedMessage, NodeKeys, Replacement, ScopedLeafKeys, TranslateHandlerContext, TranslateHandlers, Translator } from 'intor-translator';
|
|
4
|
-
import { Logger } from 'logry';
|
|
5
4
|
import Keyv from 'keyv';
|
|
5
|
+
import { Logger } from 'logry';
|
|
6
6
|
|
|
7
7
|
type CookieRawOptions = {
|
|
8
8
|
/** Completely disable cookie usage (no read, no write, no lookup by name) - default: false */
|
|
@@ -44,28 +44,28 @@ type RouteNamespaces = {
|
|
|
44
44
|
[key: string]: string[];
|
|
45
45
|
default: string[];
|
|
46
46
|
};
|
|
47
|
-
interface
|
|
47
|
+
interface RemoteHeaders {
|
|
48
48
|
authorization?: string;
|
|
49
49
|
"x-api-key"?: string;
|
|
50
50
|
[key: string]: string | undefined;
|
|
51
51
|
}
|
|
52
52
|
type BaseLoaderOptions = {
|
|
53
|
-
|
|
53
|
+
rootDir?: string;
|
|
54
54
|
namespaces?: string[];
|
|
55
55
|
routeNamespaces?: RouteNamespaces;
|
|
56
56
|
concurrency?: number;
|
|
57
57
|
lazyLoad?: boolean;
|
|
58
58
|
};
|
|
59
|
-
type
|
|
60
|
-
type: "
|
|
59
|
+
type LocalLoader = BaseLoaderOptions & {
|
|
60
|
+
type: "local";
|
|
61
61
|
};
|
|
62
|
-
type
|
|
63
|
-
type: "
|
|
64
|
-
|
|
65
|
-
|
|
62
|
+
type RemoteLoader = BaseLoaderOptions & {
|
|
63
|
+
type: "remote";
|
|
64
|
+
remoteUrl: string;
|
|
65
|
+
remoteHeaders?: RemoteHeaders;
|
|
66
66
|
fullReload?: boolean;
|
|
67
67
|
};
|
|
68
|
-
type LoaderOptions =
|
|
68
|
+
type LoaderOptions = LocalLoader | RemoteLoader;
|
|
69
69
|
|
|
70
70
|
type LoggerOptions = {
|
|
71
71
|
level?: Level;
|
|
@@ -166,40 +166,92 @@ interface IntorResult {
|
|
|
166
166
|
}
|
|
167
167
|
|
|
168
168
|
/**
|
|
169
|
-
*
|
|
169
|
+
* Represents a collection of localized messages.
|
|
170
170
|
*
|
|
171
|
-
*
|
|
172
|
-
*
|
|
173
|
-
*
|
|
171
|
+
* - Each key is a namespace or message identifier, and the value is a
|
|
172
|
+
* `NestedMessage` object that can contain nested message structures.
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```ts
|
|
176
|
+
* const messages: Messages = {
|
|
177
|
+
* ui: {
|
|
178
|
+
* greeting: "Hello",
|
|
179
|
+
* farewell: "Goodbye"
|
|
180
|
+
* },
|
|
181
|
+
* errors: {
|
|
182
|
+
* network: "Network error occurred"
|
|
183
|
+
* }
|
|
184
|
+
* };
|
|
185
|
+
* ```
|
|
174
186
|
*/
|
|
175
|
-
|
|
187
|
+
type Messages = Record<string, NestedMessage>;
|
|
188
|
+
/**
|
|
189
|
+
* A function that reads messages from a given file path.
|
|
190
|
+
*
|
|
191
|
+
* - This function is expected to return a `Promise` that resolves to a `Messages` object.
|
|
192
|
+
* - It can be implemented to support different file formats such as JSON, YAML, or others.
|
|
193
|
+
*
|
|
194
|
+
* @param filePath - The path to the message file to read.
|
|
195
|
+
* @returns A Promise that resolves to a `Messages` object.
|
|
196
|
+
*
|
|
197
|
+
* @example
|
|
198
|
+
* ```ts
|
|
199
|
+
* const reader: MessagesReader = async (filePath) => {
|
|
200
|
+
* const content = await fs.promises.readFile(filePath, "utf-8");
|
|
201
|
+
* return JSON.parse(content) as Messages;
|
|
202
|
+
* };
|
|
203
|
+
* ```
|
|
204
|
+
*/
|
|
205
|
+
type MessagesReader = (filePath: string) => Promise<Messages>;
|
|
176
206
|
|
|
177
|
-
type
|
|
207
|
+
type LoadMessagesOptions = {
|
|
178
208
|
config: IntorResolvedConfig;
|
|
179
209
|
locale: Locale;
|
|
180
|
-
pathname
|
|
210
|
+
pathname?: string;
|
|
211
|
+
extraOptions?: {
|
|
212
|
+
exts?: string[];
|
|
213
|
+
messagesReader?: MessagesReader;
|
|
214
|
+
};
|
|
181
215
|
};
|
|
182
|
-
type
|
|
216
|
+
type LoadMessagesResult<C extends GenConfigKeys = "__default__"> = Promise<GenMessages<C> | undefined>;
|
|
183
217
|
|
|
184
218
|
/**
|
|
185
219
|
* Load messages for a given locale and pathname.
|
|
186
220
|
*
|
|
187
221
|
* - Resolve namespaces based on config and pathname.
|
|
188
|
-
* - Support both **local
|
|
222
|
+
* - Support both **local local** and **remote API** loaders.
|
|
189
223
|
* - Apply fallback locales if needed.
|
|
190
224
|
* - Cache messages if enabled (handled by underlying loader, not this function directly).
|
|
191
225
|
*/
|
|
192
|
-
declare const loadMessages: <C extends GenConfigKeys = "__default__">({ config, locale, pathname, }:
|
|
226
|
+
declare const loadMessages: <C extends GenConfigKeys = "__default__">({ config, locale, pathname, extraOptions: { exts, messagesReader }, }: LoadMessagesOptions) => LoadMessagesResult<C>;
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Global messages pool (cross-module + hot-reload safe)
|
|
230
|
+
*/
|
|
231
|
+
type MessagesPool = Keyv<LocaleMessages>;
|
|
232
|
+
declare global {
|
|
233
|
+
var __INTOR_MESSAGES_POOL__: MessagesPool | undefined;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Optional: clear all cache
|
|
237
|
+
* Useful in tests or dynamic reloads.
|
|
238
|
+
*/
|
|
239
|
+
declare function clearMessagesPool(): void;
|
|
193
240
|
|
|
194
241
|
interface LoadLocalMessagesOptions {
|
|
195
|
-
|
|
196
|
-
|
|
242
|
+
pool?: MessagesPool;
|
|
243
|
+
rootDir?: string;
|
|
244
|
+
locale: string;
|
|
197
245
|
fallbackLocales?: string[];
|
|
198
246
|
namespaces?: string[];
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
247
|
+
extraOptions?: {
|
|
248
|
+
concurrency?: number;
|
|
249
|
+
cacheOptions?: CacheResolvedOptions;
|
|
250
|
+
loggerOptions?: LoggerOptions & {
|
|
251
|
+
id?: string;
|
|
252
|
+
};
|
|
253
|
+
exts?: string[];
|
|
254
|
+
messagesReader?: MessagesReader;
|
|
203
255
|
};
|
|
204
256
|
}
|
|
205
257
|
|
|
@@ -211,14 +263,21 @@ interface LoadLocalMessagesOptions {
|
|
|
211
263
|
* - Cache messages if enabled.
|
|
212
264
|
* - Limit concurrent file reads for performance.
|
|
213
265
|
*/
|
|
214
|
-
declare const loadLocalMessages: ({
|
|
266
|
+
declare const loadLocalMessages: ({ pool, rootDir, locale, fallbackLocales, namespaces, extraOptions: { concurrency, cacheOptions, loggerOptions, exts, messagesReader, }, }: LoadLocalMessagesOptions) => Promise<LocaleMessages | undefined>;
|
|
215
267
|
|
|
216
|
-
interface
|
|
268
|
+
interface LoadRemoteMessagesOptions {
|
|
269
|
+
pool?: MessagesPool;
|
|
270
|
+
rootDir?: string;
|
|
217
271
|
locale: string;
|
|
218
272
|
fallbackLocales: string[];
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
273
|
+
namespaces?: string[];
|
|
274
|
+
remoteUrl: string;
|
|
275
|
+
remoteHeaders?: RemoteHeaders;
|
|
276
|
+
extraOptions?: {
|
|
277
|
+
cacheOptions?: CacheResolvedOptions;
|
|
278
|
+
loggerOptions?: LoggerOptions & {
|
|
279
|
+
id?: string;
|
|
280
|
+
};
|
|
222
281
|
};
|
|
223
282
|
}
|
|
224
283
|
|
|
@@ -228,7 +287,19 @@ interface LoadApiMessagesOptions extends Omit<ApiLoader, "type"> {
|
|
|
228
287
|
* - Fetch messages for a target locale with optional fallback locales.
|
|
229
288
|
* - Cache messages if enabled.
|
|
230
289
|
*/
|
|
231
|
-
declare const
|
|
290
|
+
declare const loadRemoteMessages: ({ pool, rootDir, remoteUrl, remoteHeaders, locale, fallbackLocales, namespaces, extraOptions: { cacheOptions, loggerOptions, }, }: LoadRemoteMessagesOptions) => Promise<LocaleMessages | undefined>;
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Entry point for initializing Intor.
|
|
294
|
+
*
|
|
295
|
+
* 1. Resolve context via adapter or fallback values.
|
|
296
|
+
* 2. Load messages if loader is enabled.
|
|
297
|
+
* 3. Merge static messages with loaded messages.
|
|
298
|
+
*/
|
|
299
|
+
declare const intor: (config: IntorResolvedConfig, i18nContext: GetI18nContext | Partial<I18nContext>, loadMessagesOptions?: {
|
|
300
|
+
exts?: string[];
|
|
301
|
+
messagesReader?: MessagesReader;
|
|
302
|
+
}) => Promise<IntorResult>;
|
|
232
303
|
|
|
233
304
|
/** Base properties shared by all translator instances. */
|
|
234
305
|
interface TranslatorBaseProps<M = unknown> {
|
|
@@ -284,10 +355,10 @@ declare function getTranslator<CK extends GenConfigKeys = "__default__", PK exte
|
|
|
284
355
|
}): Promise<TranslatorInstance<GenMessages<CK>, PK>>;
|
|
285
356
|
|
|
286
357
|
/**
|
|
287
|
-
*
|
|
288
|
-
* Loaded messages override static ones on conflict.
|
|
358
|
+
* Deeply merges loaded messages into static messages by locale.
|
|
359
|
+
* - Loaded messages override static ones on conflict.
|
|
289
360
|
*/
|
|
290
|
-
declare const mergeMessages: (staticMessages?: LocaleMessages, loadedMessages?: LocaleMessages |
|
|
361
|
+
declare const mergeMessages: (staticMessages?: LocaleMessages, loadedMessages?: LocaleMessages | undefined) => LocaleMessages;
|
|
291
362
|
|
|
292
363
|
type RawCacheKey = string | boolean | Array<string | number | boolean | undefined | null>;
|
|
293
364
|
declare const normalizeCacheKey: (key?: RawCacheKey, delimiter?: string) => string | null;
|
|
@@ -299,7 +370,7 @@ interface ResolveNamespacesOptions {
|
|
|
299
370
|
/**
|
|
300
371
|
* Resolves namespaces based on pathname.
|
|
301
372
|
*/
|
|
302
|
-
declare const resolveNamespaces: ({ config, pathname, }: ResolveNamespacesOptions) => string[];
|
|
373
|
+
declare const resolveNamespaces: ({ config, pathname, }: ResolveNamespacesOptions) => string[] | undefined;
|
|
303
374
|
|
|
304
375
|
/**
|
|
305
376
|
* Normalizes and finds the best matching locale from the supported locales list.
|
|
@@ -381,17 +452,4 @@ declare global {
|
|
|
381
452
|
*/
|
|
382
453
|
declare function clearLoggerPool(): void;
|
|
383
454
|
|
|
384
|
-
|
|
385
|
-
* Global messages pool (cross-module + hot-reload safe)
|
|
386
|
-
*/
|
|
387
|
-
type MessagesPool = Keyv<LocaleMessages>;
|
|
388
|
-
declare global {
|
|
389
|
-
var __INTOR_MESSAGES_POOL__: MessagesPool | undefined;
|
|
390
|
-
}
|
|
391
|
-
/**
|
|
392
|
-
* Optional: clear all cache
|
|
393
|
-
* Useful in tests or dynamic reloads.
|
|
394
|
-
*/
|
|
395
|
-
declare function clearMessagesPool(): void;
|
|
396
|
-
|
|
397
|
-
export { type I18nContext, type IntorResult, type LoadApiMessagesOptions, type LoadLocalMessagesOptions, PREFIX_PLACEHOLDER, clearLoggerPool, clearMessagesPool, extractPathname, getTranslator, intor, loadApiMessages, loadLocalMessages, loadMessages, mergeMessages, normalizeCacheKey, normalizeLocale, normalizePathname, resolveNamespaces, resolvePreferredLocale, standardizePathname };
|
|
455
|
+
export { type I18nContext, type IntorResult, type LoadLocalMessagesOptions, type LoadRemoteMessagesOptions, type Messages, type MessagesReader, PREFIX_PLACEHOLDER, clearLoggerPool, clearMessagesPool, extractPathname, getTranslator, intor, loadLocalMessages, loadMessages, loadRemoteMessages, mergeMessages, normalizeCacheKey, normalizeLocale, normalizePathname, resolveNamespaces, resolvePreferredLocale, standardizePathname };
|