intor 2.2.6 → 2.2.8

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.
@@ -99,15 +99,13 @@ type TranslatorOptions = {
99
99
  placeholder?: string;
100
100
  };
101
101
 
102
- type WithoutLoader = {
103
- loader?: undefined;
104
- supportedLocales?: readonly Locale[];
105
- };
106
- type WithLoader = {
102
+ type IntorRawConfig = ({
107
103
  loader: LoaderOptions;
108
104
  supportedLocales: readonly Locale[];
109
- };
110
- type IntorRawConfig = (WithLoader | WithoutLoader) & {
105
+ } | {
106
+ loader?: undefined;
107
+ supportedLocales?: readonly Locale[];
108
+ }) & {
111
109
  readonly id?: string;
112
110
  readonly messages?: LocaleMessages;
113
111
  readonly defaultLocale: Locale;
@@ -118,7 +116,13 @@ type IntorRawConfig = (WithLoader | WithoutLoader) & {
118
116
  readonly logger?: LoggerOptions;
119
117
  readonly cache?: CacheRawOptions;
120
118
  };
121
- type IntorResolvedConfig = (WithLoader | WithoutLoader) & {
119
+ type IntorResolvedConfig = ({
120
+ loader: LoaderOptions;
121
+ supportedLocales: readonly Locale[];
122
+ } | {
123
+ loader?: undefined;
124
+ supportedLocales: readonly Locale[];
125
+ }) & {
122
126
  readonly id: string;
123
127
  readonly messages?: LocaleMessages;
124
128
  readonly defaultLocale: Locale;
@@ -99,15 +99,13 @@ type TranslatorOptions = {
99
99
  placeholder?: string;
100
100
  };
101
101
 
102
- type WithoutLoader = {
103
- loader?: undefined;
104
- supportedLocales?: readonly Locale[];
105
- };
106
- type WithLoader = {
102
+ type IntorRawConfig = ({
107
103
  loader: LoaderOptions;
108
104
  supportedLocales: readonly Locale[];
109
- };
110
- type IntorRawConfig = (WithLoader | WithoutLoader) & {
105
+ } | {
106
+ loader?: undefined;
107
+ supportedLocales?: readonly Locale[];
108
+ }) & {
111
109
  readonly id?: string;
112
110
  readonly messages?: LocaleMessages;
113
111
  readonly defaultLocale: Locale;
@@ -118,7 +116,13 @@ type IntorRawConfig = (WithLoader | WithoutLoader) & {
118
116
  readonly logger?: LoggerOptions;
119
117
  readonly cache?: CacheRawOptions;
120
118
  };
121
- type IntorResolvedConfig = (WithLoader | WithoutLoader) & {
119
+ type IntorResolvedConfig = ({
120
+ loader: LoaderOptions;
121
+ supportedLocales: readonly Locale[];
122
+ } | {
123
+ loader?: undefined;
124
+ supportedLocales: readonly Locale[];
125
+ }) & {
122
126
  readonly id: string;
123
127
  readonly messages?: LocaleMessages;
124
128
  readonly defaultLocale: Locale;
package/dist/index.d.cts CHANGED
@@ -111,15 +111,13 @@ type TranslatorOptions = {
111
111
  placeholder?: string;
112
112
  };
113
113
 
114
- type WithoutLoader = {
115
- loader?: undefined;
116
- supportedLocales?: readonly Locale[];
117
- };
118
- type WithLoader = {
114
+ type IntorResolvedConfig = ({
119
115
  loader: LoaderOptions;
120
116
  supportedLocales: readonly Locale[];
121
- };
122
- type IntorResolvedConfig = (WithLoader | WithoutLoader) & {
117
+ } | {
118
+ loader?: undefined;
119
+ supportedLocales: readonly Locale[];
120
+ }) & {
123
121
  readonly id: string;
124
122
  readonly messages?: LocaleMessages;
125
123
  readonly defaultLocale: Locale;
package/dist/index.d.ts CHANGED
@@ -111,15 +111,13 @@ type TranslatorOptions = {
111
111
  placeholder?: string;
112
112
  };
113
113
 
114
- type WithoutLoader = {
115
- loader?: undefined;
116
- supportedLocales?: readonly Locale[];
117
- };
118
- type WithLoader = {
114
+ type IntorResolvedConfig = ({
119
115
  loader: LoaderOptions;
120
116
  supportedLocales: readonly Locale[];
121
- };
122
- type IntorResolvedConfig = (WithLoader | WithoutLoader) & {
117
+ } | {
118
+ loader?: undefined;
119
+ supportedLocales: readonly Locale[];
120
+ }) & {
123
121
  readonly id: string;
124
122
  readonly messages?: LocaleMessages;
125
123
  readonly defaultLocale: Locale;
@@ -185,15 +185,13 @@ type TranslatorOptions = {
185
185
  placeholder?: string;
186
186
  };
187
187
 
188
- type WithoutLoader = {
189
- loader?: undefined;
190
- supportedLocales?: readonly Locale[];
191
- };
192
- type WithLoader = {
188
+ type IntorResolvedConfig = ({
193
189
  loader: LoaderOptions;
194
190
  supportedLocales: readonly Locale[];
195
- };
196
- type IntorResolvedConfig = (WithLoader | WithoutLoader) & {
191
+ } | {
192
+ loader?: undefined;
193
+ supportedLocales: readonly Locale[];
194
+ }) & {
197
195
  readonly id: string;
198
196
  readonly messages?: LocaleMessages;
199
197
  readonly defaultLocale: Locale;
@@ -185,15 +185,13 @@ type TranslatorOptions = {
185
185
  placeholder?: string;
186
186
  };
187
187
 
188
- type WithoutLoader = {
189
- loader?: undefined;
190
- supportedLocales?: readonly Locale[];
191
- };
192
- type WithLoader = {
188
+ type IntorResolvedConfig = ({
193
189
  loader: LoaderOptions;
194
190
  supportedLocales: readonly Locale[];
195
- };
196
- type IntorResolvedConfig = (WithLoader | WithoutLoader) & {
191
+ } | {
192
+ loader?: undefined;
193
+ supportedLocales: readonly Locale[];
194
+ }) & {
197
195
  readonly id: string;
198
196
  readonly messages?: LocaleMessages;
199
197
  readonly defaultLocale: Locale;
@@ -100,15 +100,13 @@ type TranslatorOptions = {
100
100
  placeholder?: string;
101
101
  };
102
102
 
103
- type WithoutLoader = {
104
- loader?: undefined;
105
- supportedLocales?: readonly Locale[];
106
- };
107
- type WithLoader = {
103
+ type IntorResolvedConfig = ({
108
104
  loader: LoaderOptions;
109
105
  supportedLocales: readonly Locale[];
110
- };
111
- type IntorResolvedConfig = (WithLoader | WithoutLoader) & {
106
+ } | {
107
+ loader?: undefined;
108
+ supportedLocales: readonly Locale[];
109
+ }) & {
112
110
  readonly id: string;
113
111
  readonly messages?: LocaleMessages;
114
112
  readonly defaultLocale: Locale;
@@ -100,15 +100,13 @@ type TranslatorOptions = {
100
100
  placeholder?: string;
101
101
  };
102
102
 
103
- type WithoutLoader = {
104
- loader?: undefined;
105
- supportedLocales?: readonly Locale[];
106
- };
107
- type WithLoader = {
103
+ type IntorResolvedConfig = ({
108
104
  loader: LoaderOptions;
109
105
  supportedLocales: readonly Locale[];
110
- };
111
- type IntorResolvedConfig = (WithLoader | WithoutLoader) & {
106
+ } | {
107
+ loader?: undefined;
108
+ supportedLocales: readonly Locale[];
109
+ }) & {
112
110
  readonly id: string;
113
111
  readonly messages?: LocaleMessages;
114
112
  readonly defaultLocale: Locale;
@@ -690,16 +690,21 @@ var loadMessages = async ({
690
690
  };
691
691
 
692
692
  // src/server/translator/get-translator.ts
693
- async function getTranslator(opts) {
694
- const { config, locale, pathname = "", preKey, handlers } = opts;
695
- const messages = await loadMessages({ config, locale, pathname });
693
+ async function getTranslator(options) {
694
+ const { config, locale, pathname = "", preKey } = options;
695
+ const messages = await loadMessages({
696
+ config,
697
+ locale,
698
+ pathname,
699
+ extraOptions: options.extraOptions
700
+ });
696
701
  const translator = new intorTranslator.Translator({
697
702
  locale,
698
703
  messages,
699
704
  fallbackLocales: config.fallbackLocales,
700
705
  loadingMessage: config.translator?.loadingMessage,
701
706
  placeholder: config.translator?.placeholder,
702
- handlers
707
+ handlers: options.handlers
703
708
  });
704
709
  const props = { messages, locale };
705
710
  const scoped = translator.scoped(preKey);
@@ -711,12 +716,15 @@ async function getTranslator(opts) {
711
716
  }
712
717
 
713
718
  // src/adapters/next/server/get-translator.ts
714
- async function getTranslator2(config, preKey) {
719
+ async function getTranslator2(options) {
720
+ const { config, preKey, handlers, extraOptions } = options;
715
721
  const { locale, pathname } = await getI18nContext(config);
716
722
  const translatorInstance = getTranslator({
717
723
  config,
718
724
  locale,
719
725
  pathname,
726
+ handlers,
727
+ extraOptions,
720
728
  preKey
721
729
  });
722
730
  return translatorInstance;
@@ -1,5 +1,7 @@
1
1
  import { Level, NormalizerConfig, FormatterConfig, LoggerPreset } from 'logry/edge';
2
- import { Locale, LocaleMessages, FallbackLocalesMap, ScopedLeafKeys, LocalizedLeafKeys, Replacement, LocalizedNodeKeys } from 'intor-translator';
2
+ import { Locale, LocaleMessages, FallbackLocalesMap, NestedMessage, ScopedLeafKeys, LocalizedLeafKeys, Replacement, TranslateHandlers, LocalizedNodeKeys } from 'intor-translator';
3
+ import Keyv from 'keyv';
4
+ import { Logger } from 'logry';
3
5
 
4
6
  type CookieRawOptions = {
5
7
  /** Completely disable cookie usage (no read, no write, no lookup by name) - default: false */
@@ -99,15 +101,13 @@ type TranslatorOptions = {
99
101
  placeholder?: string;
100
102
  };
101
103
 
102
- type WithoutLoader = {
103
- loader?: undefined;
104
- supportedLocales?: readonly Locale[];
105
- };
106
- type WithLoader = {
104
+ type IntorResolvedConfig = ({
107
105
  loader: LoaderOptions;
108
106
  supportedLocales: readonly Locale[];
109
- };
110
- type IntorResolvedConfig = (WithLoader | WithoutLoader) & {
107
+ } | {
108
+ loader?: undefined;
109
+ supportedLocales: readonly Locale[];
110
+ }) & {
111
111
  readonly id: string;
112
112
  readonly messages?: LocaleMessages;
113
113
  readonly defaultLocale: Locale;
@@ -162,6 +162,53 @@ interface I18nContext {
162
162
  */
163
163
  declare const getI18nContext: <CK extends GenConfigKeys = "__default__">(config: IntorResolvedConfig) => Promise<I18nContext>;
164
164
 
165
+ /**
166
+ * Represents a collection of localized messages.
167
+ *
168
+ * - Each key is a namespace or message identifier, and the value is a
169
+ * `NestedMessage` object that can contain nested message structures.
170
+ *
171
+ * @example
172
+ * ```ts
173
+ * const messages: Messages = {
174
+ * ui: {
175
+ * greeting: "Hello",
176
+ * farewell: "Goodbye"
177
+ * },
178
+ * errors: {
179
+ * network: "Network error occurred"
180
+ * }
181
+ * };
182
+ * ```
183
+ */
184
+ type Messages = Record<string, NestedMessage>;
185
+ /**
186
+ * A function that reads messages from a given file path.
187
+ *
188
+ * - This function is expected to return a `Promise` that resolves to a `Messages` object.
189
+ * - It can be implemented to support different file formats such as JSON, YAML, or others.
190
+ *
191
+ * @param filePath - The path to the message file to read.
192
+ * @returns A Promise that resolves to a `Messages` object.
193
+ *
194
+ * @example
195
+ * ```ts
196
+ * const reader: MessagesReader = async (filePath) => {
197
+ * const content = await fs.promises.readFile(filePath, "utf-8");
198
+ * return JSON.parse(content) as Messages;
199
+ * };
200
+ * ```
201
+ */
202
+ type MessagesReader = (filePath: string) => Promise<Messages>;
203
+
204
+ /**
205
+ * Global messages pool (cross-module + hot-reload safe)
206
+ */
207
+ type MessagesPool = Keyv<LocaleMessages>;
208
+ declare global {
209
+ var __INTOR_MESSAGES_POOL__: MessagesPool | undefined;
210
+ }
211
+
165
212
  /** Base properties shared by all translator instances. */
166
213
  interface TranslatorBaseProps<M = unknown> {
167
214
  /** `messages`: The message object containing all translations. */
@@ -193,16 +240,38 @@ type TranslatorInstance<M, PK extends string | undefined = undefined> = {
193
240
  t: <Result = string>(key?: Key<M, PK>, replacements?: Replacement) => Result;
194
241
  } & TranslatorBaseProps<M> & TranslatorClientProps<M>;
195
242
 
243
+ /**
244
+ * Global logger pool (cross-module + hot-reload safe)
245
+ */
246
+ type LoggerPool = Map<string, Logger>;
247
+ declare global {
248
+ var __INTOR_LOGGER_POOL__: LoggerPool | undefined;
249
+ }
250
+
196
251
  /**
197
252
  * Create a translator instance ready for the current Next.js SSR environment.
198
253
  *
199
- * - Automatically resolves the current locale and pathname using the Next.js adapter.
200
- * - Loads all corresponding messages for the resolved locale and pathname.
201
- * - Returns a translator object containing `t`, `hasKey`, `messages`, and other helpers.
202
- * - Supports optional `preKey` to create a scoped translator for nested translation keys.
203
- * - Allows passing additional `TranslateConfig` options to the underlying translator.
254
+ * - **Automatically resolves the current locale and pathname using the Next.js adapter.**
255
+ * - Loads messages using the provided config, locale, and pathname.
256
+ * - Initializes a translator with `t`, `hasKey`, and optional scoped methods.
257
+ * - Supports optional `preKey` to create a scoped translator for nested keys.
204
258
  */
205
- declare function getTranslator<CK extends GenConfigKeys = "__default__">(config: IntorResolvedConfig): Promise<TranslatorInstance<GenMessages<CK>>>;
206
- declare function getTranslator<CK extends GenConfigKeys = "__default__", PK extends string = LocalizedNodeKeys<GenMessages<CK>>>(config: IntorResolvedConfig, preKey: IfGen<PK, string>): Promise<TranslatorInstance<GenMessages<CK>, PK>>;
259
+ declare function getTranslator<CK extends GenConfigKeys = "__default__">(options: {
260
+ config: IntorResolvedConfig;
261
+ handlers?: TranslateHandlers;
262
+ extraOptions?: {
263
+ exts?: string[];
264
+ messagesReader?: MessagesReader;
265
+ };
266
+ }): Promise<TranslatorInstance<GenMessages<CK>>>;
267
+ declare function getTranslator<CK extends GenConfigKeys = "__default__", PK extends string = LocalizedNodeKeys<GenMessages<CK>>>(options: {
268
+ config: IntorResolvedConfig;
269
+ handlers?: TranslateHandlers;
270
+ extraOptions?: {
271
+ exts?: string[];
272
+ messagesReader?: MessagesReader;
273
+ };
274
+ preKey: IfGen<PK, string>;
275
+ }): Promise<TranslatorInstance<GenMessages<CK>, PK>>;
207
276
 
208
277
  export { getI18nContext, getTranslator };
@@ -1,5 +1,7 @@
1
1
  import { Level, NormalizerConfig, FormatterConfig, LoggerPreset } from 'logry/edge';
2
- import { Locale, LocaleMessages, FallbackLocalesMap, ScopedLeafKeys, LocalizedLeafKeys, Replacement, LocalizedNodeKeys } from 'intor-translator';
2
+ import { Locale, LocaleMessages, FallbackLocalesMap, NestedMessage, ScopedLeafKeys, LocalizedLeafKeys, Replacement, TranslateHandlers, LocalizedNodeKeys } from 'intor-translator';
3
+ import Keyv from 'keyv';
4
+ import { Logger } from 'logry';
3
5
 
4
6
  type CookieRawOptions = {
5
7
  /** Completely disable cookie usage (no read, no write, no lookup by name) - default: false */
@@ -99,15 +101,13 @@ type TranslatorOptions = {
99
101
  placeholder?: string;
100
102
  };
101
103
 
102
- type WithoutLoader = {
103
- loader?: undefined;
104
- supportedLocales?: readonly Locale[];
105
- };
106
- type WithLoader = {
104
+ type IntorResolvedConfig = ({
107
105
  loader: LoaderOptions;
108
106
  supportedLocales: readonly Locale[];
109
- };
110
- type IntorResolvedConfig = (WithLoader | WithoutLoader) & {
107
+ } | {
108
+ loader?: undefined;
109
+ supportedLocales: readonly Locale[];
110
+ }) & {
111
111
  readonly id: string;
112
112
  readonly messages?: LocaleMessages;
113
113
  readonly defaultLocale: Locale;
@@ -162,6 +162,53 @@ interface I18nContext {
162
162
  */
163
163
  declare const getI18nContext: <CK extends GenConfigKeys = "__default__">(config: IntorResolvedConfig) => Promise<I18nContext>;
164
164
 
165
+ /**
166
+ * Represents a collection of localized messages.
167
+ *
168
+ * - Each key is a namespace or message identifier, and the value is a
169
+ * `NestedMessage` object that can contain nested message structures.
170
+ *
171
+ * @example
172
+ * ```ts
173
+ * const messages: Messages = {
174
+ * ui: {
175
+ * greeting: "Hello",
176
+ * farewell: "Goodbye"
177
+ * },
178
+ * errors: {
179
+ * network: "Network error occurred"
180
+ * }
181
+ * };
182
+ * ```
183
+ */
184
+ type Messages = Record<string, NestedMessage>;
185
+ /**
186
+ * A function that reads messages from a given file path.
187
+ *
188
+ * - This function is expected to return a `Promise` that resolves to a `Messages` object.
189
+ * - It can be implemented to support different file formats such as JSON, YAML, or others.
190
+ *
191
+ * @param filePath - The path to the message file to read.
192
+ * @returns A Promise that resolves to a `Messages` object.
193
+ *
194
+ * @example
195
+ * ```ts
196
+ * const reader: MessagesReader = async (filePath) => {
197
+ * const content = await fs.promises.readFile(filePath, "utf-8");
198
+ * return JSON.parse(content) as Messages;
199
+ * };
200
+ * ```
201
+ */
202
+ type MessagesReader = (filePath: string) => Promise<Messages>;
203
+
204
+ /**
205
+ * Global messages pool (cross-module + hot-reload safe)
206
+ */
207
+ type MessagesPool = Keyv<LocaleMessages>;
208
+ declare global {
209
+ var __INTOR_MESSAGES_POOL__: MessagesPool | undefined;
210
+ }
211
+
165
212
  /** Base properties shared by all translator instances. */
166
213
  interface TranslatorBaseProps<M = unknown> {
167
214
  /** `messages`: The message object containing all translations. */
@@ -193,16 +240,38 @@ type TranslatorInstance<M, PK extends string | undefined = undefined> = {
193
240
  t: <Result = string>(key?: Key<M, PK>, replacements?: Replacement) => Result;
194
241
  } & TranslatorBaseProps<M> & TranslatorClientProps<M>;
195
242
 
243
+ /**
244
+ * Global logger pool (cross-module + hot-reload safe)
245
+ */
246
+ type LoggerPool = Map<string, Logger>;
247
+ declare global {
248
+ var __INTOR_LOGGER_POOL__: LoggerPool | undefined;
249
+ }
250
+
196
251
  /**
197
252
  * Create a translator instance ready for the current Next.js SSR environment.
198
253
  *
199
- * - Automatically resolves the current locale and pathname using the Next.js adapter.
200
- * - Loads all corresponding messages for the resolved locale and pathname.
201
- * - Returns a translator object containing `t`, `hasKey`, `messages`, and other helpers.
202
- * - Supports optional `preKey` to create a scoped translator for nested translation keys.
203
- * - Allows passing additional `TranslateConfig` options to the underlying translator.
254
+ * - **Automatically resolves the current locale and pathname using the Next.js adapter.**
255
+ * - Loads messages using the provided config, locale, and pathname.
256
+ * - Initializes a translator with `t`, `hasKey`, and optional scoped methods.
257
+ * - Supports optional `preKey` to create a scoped translator for nested keys.
204
258
  */
205
- declare function getTranslator<CK extends GenConfigKeys = "__default__">(config: IntorResolvedConfig): Promise<TranslatorInstance<GenMessages<CK>>>;
206
- declare function getTranslator<CK extends GenConfigKeys = "__default__", PK extends string = LocalizedNodeKeys<GenMessages<CK>>>(config: IntorResolvedConfig, preKey: IfGen<PK, string>): Promise<TranslatorInstance<GenMessages<CK>, PK>>;
259
+ declare function getTranslator<CK extends GenConfigKeys = "__default__">(options: {
260
+ config: IntorResolvedConfig;
261
+ handlers?: TranslateHandlers;
262
+ extraOptions?: {
263
+ exts?: string[];
264
+ messagesReader?: MessagesReader;
265
+ };
266
+ }): Promise<TranslatorInstance<GenMessages<CK>>>;
267
+ declare function getTranslator<CK extends GenConfigKeys = "__default__", PK extends string = LocalizedNodeKeys<GenMessages<CK>>>(options: {
268
+ config: IntorResolvedConfig;
269
+ handlers?: TranslateHandlers;
270
+ extraOptions?: {
271
+ exts?: string[];
272
+ messagesReader?: MessagesReader;
273
+ };
274
+ preKey: IfGen<PK, string>;
275
+ }): Promise<TranslatorInstance<GenMessages<CK>, PK>>;
207
276
 
208
277
  export { getI18nContext, getTranslator };
@@ -680,16 +680,21 @@ var loadMessages = async ({
680
680
  };
681
681
 
682
682
  // src/server/translator/get-translator.ts
683
- async function getTranslator(opts) {
684
- const { config, locale, pathname = "", preKey, handlers } = opts;
685
- const messages = await loadMessages({ config, locale, pathname });
683
+ async function getTranslator(options) {
684
+ const { config, locale, pathname = "", preKey } = options;
685
+ const messages = await loadMessages({
686
+ config,
687
+ locale,
688
+ pathname,
689
+ extraOptions: options.extraOptions
690
+ });
686
691
  const translator = new Translator({
687
692
  locale,
688
693
  messages,
689
694
  fallbackLocales: config.fallbackLocales,
690
695
  loadingMessage: config.translator?.loadingMessage,
691
696
  placeholder: config.translator?.placeholder,
692
- handlers
697
+ handlers: options.handlers
693
698
  });
694
699
  const props = { messages, locale };
695
700
  const scoped = translator.scoped(preKey);
@@ -701,12 +706,15 @@ async function getTranslator(opts) {
701
706
  }
702
707
 
703
708
  // src/adapters/next/server/get-translator.ts
704
- async function getTranslator2(config, preKey) {
709
+ async function getTranslator2(options) {
710
+ const { config, preKey, handlers, extraOptions } = options;
705
711
  const { locale, pathname } = await getI18nContext(config);
706
712
  const translatorInstance = getTranslator({
707
713
  config,
708
714
  locale,
709
715
  pathname,
716
+ handlers,
717
+ extraOptions,
710
718
  preKey
711
719
  });
712
720
  return translatorInstance;
@@ -101,15 +101,13 @@ type TranslatorOptions = {
101
101
  placeholder?: string;
102
102
  };
103
103
 
104
- type WithoutLoader = {
105
- loader?: undefined;
106
- supportedLocales?: readonly Locale[];
107
- };
108
- type WithLoader = {
104
+ type IntorResolvedConfig = ({
109
105
  loader: LoaderOptions;
110
106
  supportedLocales: readonly Locale[];
111
- };
112
- type IntorResolvedConfig = (WithLoader | WithoutLoader) & {
107
+ } | {
108
+ loader?: undefined;
109
+ supportedLocales: readonly Locale[];
110
+ }) & {
113
111
  readonly id: string;
114
112
  readonly messages?: LocaleMessages;
115
113
  readonly defaultLocale: Locale;
@@ -101,15 +101,13 @@ type TranslatorOptions = {
101
101
  placeholder?: string;
102
102
  };
103
103
 
104
- type WithoutLoader = {
105
- loader?: undefined;
106
- supportedLocales?: readonly Locale[];
107
- };
108
- type WithLoader = {
104
+ type IntorResolvedConfig = ({
109
105
  loader: LoaderOptions;
110
106
  supportedLocales: readonly Locale[];
111
- };
112
- type IntorResolvedConfig = (WithLoader | WithoutLoader) & {
107
+ } | {
108
+ loader?: undefined;
109
+ supportedLocales: readonly Locale[];
110
+ }) & {
113
111
  readonly id: string;
114
112
  readonly messages?: LocaleMessages;
115
113
  readonly defaultLocale: Locale;
@@ -669,16 +669,21 @@ var intor = async (config, i18nContext, loadMessagesOptions = {}) => {
669
669
  messages: mergedMessages
670
670
  };
671
671
  };
672
- async function getTranslator(opts) {
673
- const { config, locale, pathname = "", preKey, handlers } = opts;
674
- const messages = await loadMessages({ config, locale, pathname });
672
+ async function getTranslator(options) {
673
+ const { config, locale, pathname = "", preKey } = options;
674
+ const messages = await loadMessages({
675
+ config,
676
+ locale,
677
+ pathname,
678
+ extraOptions: options.extraOptions
679
+ });
675
680
  const translator = new intorTranslator.Translator({
676
681
  locale,
677
682
  messages,
678
683
  fallbackLocales: config.fallbackLocales,
679
684
  loadingMessage: config.translator?.loadingMessage,
680
685
  placeholder: config.translator?.placeholder,
681
- handlers
686
+ handlers: options.handlers
682
687
  });
683
688
  const props = { messages, locale };
684
689
  const scoped = translator.scoped(preKey);
@@ -101,15 +101,13 @@ type TranslatorOptions = {
101
101
  placeholder?: string;
102
102
  };
103
103
 
104
- type WithoutLoader = {
105
- loader?: undefined;
106
- supportedLocales?: readonly Locale[];
107
- };
108
- type WithLoader = {
104
+ type IntorResolvedConfig = ({
109
105
  loader: LoaderOptions;
110
106
  supportedLocales: readonly Locale[];
111
- };
112
- type IntorResolvedConfig = (WithLoader | WithoutLoader) & {
107
+ } | {
108
+ loader?: undefined;
109
+ supportedLocales: readonly Locale[];
110
+ }) & {
113
111
  readonly id: string;
114
112
  readonly messages?: LocaleMessages;
115
113
  readonly defaultLocale: Locale;
@@ -340,19 +338,26 @@ type TranslatorInstance<M, PK extends string | undefined = undefined> = {
340
338
  * - Loads messages using the provided config, locale, and pathname.
341
339
  * - Initializes a translator with `t`, `hasKey`, and optional scoped methods.
342
340
  * - Supports optional `preKey` to create a scoped translator for nested keys.
343
- * - Passes additional options to the underlying `Translator`.
344
341
  */
345
- declare function getTranslator<CK extends GenConfigKeys = "__default__">(opts: {
342
+ declare function getTranslator<CK extends GenConfigKeys = "__default__">(options: {
346
343
  config: IntorResolvedConfig;
347
344
  locale: GenLocale;
348
345
  pathname?: string;
349
346
  handlers?: TranslateHandlers;
347
+ extraOptions?: {
348
+ exts?: string[];
349
+ messagesReader?: MessagesReader;
350
+ };
350
351
  }): Promise<TranslatorInstance<GenMessages<CK>>>;
351
- declare function getTranslator<CK extends GenConfigKeys = "__default__", PK extends string = LocalizedNodeKeys<GenMessages<CK>>>(opts: {
352
+ declare function getTranslator<CK extends GenConfigKeys = "__default__", PK extends string = LocalizedNodeKeys<GenMessages<CK>>>(options: {
352
353
  config: IntorResolvedConfig;
353
354
  locale: GenLocale;
354
355
  pathname?: string;
355
356
  handlers?: TranslateHandlers;
357
+ extraOptions?: {
358
+ exts?: string[];
359
+ messagesReader?: MessagesReader;
360
+ };
356
361
  preKey?: PK;
357
362
  }): Promise<TranslatorInstance<GenMessages<CK>, PK>>;
358
363
 
@@ -101,15 +101,13 @@ type TranslatorOptions = {
101
101
  placeholder?: string;
102
102
  };
103
103
 
104
- type WithoutLoader = {
105
- loader?: undefined;
106
- supportedLocales?: readonly Locale[];
107
- };
108
- type WithLoader = {
104
+ type IntorResolvedConfig = ({
109
105
  loader: LoaderOptions;
110
106
  supportedLocales: readonly Locale[];
111
- };
112
- type IntorResolvedConfig = (WithLoader | WithoutLoader) & {
107
+ } | {
108
+ loader?: undefined;
109
+ supportedLocales: readonly Locale[];
110
+ }) & {
113
111
  readonly id: string;
114
112
  readonly messages?: LocaleMessages;
115
113
  readonly defaultLocale: Locale;
@@ -340,19 +338,26 @@ type TranslatorInstance<M, PK extends string | undefined = undefined> = {
340
338
  * - Loads messages using the provided config, locale, and pathname.
341
339
  * - Initializes a translator with `t`, `hasKey`, and optional scoped methods.
342
340
  * - Supports optional `preKey` to create a scoped translator for nested keys.
343
- * - Passes additional options to the underlying `Translator`.
344
341
  */
345
- declare function getTranslator<CK extends GenConfigKeys = "__default__">(opts: {
342
+ declare function getTranslator<CK extends GenConfigKeys = "__default__">(options: {
346
343
  config: IntorResolvedConfig;
347
344
  locale: GenLocale;
348
345
  pathname?: string;
349
346
  handlers?: TranslateHandlers;
347
+ extraOptions?: {
348
+ exts?: string[];
349
+ messagesReader?: MessagesReader;
350
+ };
350
351
  }): Promise<TranslatorInstance<GenMessages<CK>>>;
351
- declare function getTranslator<CK extends GenConfigKeys = "__default__", PK extends string = LocalizedNodeKeys<GenMessages<CK>>>(opts: {
352
+ declare function getTranslator<CK extends GenConfigKeys = "__default__", PK extends string = LocalizedNodeKeys<GenMessages<CK>>>(options: {
352
353
  config: IntorResolvedConfig;
353
354
  locale: GenLocale;
354
355
  pathname?: string;
355
356
  handlers?: TranslateHandlers;
357
+ extraOptions?: {
358
+ exts?: string[];
359
+ messagesReader?: MessagesReader;
360
+ };
356
361
  preKey?: PK;
357
362
  }): Promise<TranslatorInstance<GenMessages<CK>, PK>>;
358
363
 
@@ -659,16 +659,21 @@ var intor = async (config, i18nContext, loadMessagesOptions = {}) => {
659
659
  messages: mergedMessages
660
660
  };
661
661
  };
662
- async function getTranslator(opts) {
663
- const { config, locale, pathname = "", preKey, handlers } = opts;
664
- const messages = await loadMessages({ config, locale, pathname });
662
+ async function getTranslator(options) {
663
+ const { config, locale, pathname = "", preKey } = options;
664
+ const messages = await loadMessages({
665
+ config,
666
+ locale,
667
+ pathname,
668
+ extraOptions: options.extraOptions
669
+ });
665
670
  const translator = new Translator({
666
671
  locale,
667
672
  messages,
668
673
  fallbackLocales: config.fallbackLocales,
669
674
  loadingMessage: config.translator?.loadingMessage,
670
675
  placeholder: config.translator?.placeholder,
671
- handlers
676
+ handlers: options.handlers
672
677
  });
673
678
  const props = { messages, locale };
674
679
  const scoped = translator.scoped(preKey);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "intor",
3
- "version": "2.2.6",
3
+ "version": "2.2.8",
4
4
  "description": "A modular and extensible i18n core designed for TypeScript and JavaScript projects. Intor enables custom translation logic with support for both frontend and backend environments, featuring runtime configuration, caching, adapters, and message loaders.",
5
5
  "author": "Yiming Liao",
6
6
  "license": "MIT",
@@ -100,6 +100,7 @@
100
100
  "eslint-plugin-prettier": "^5.5.4",
101
101
  "eslint-plugin-unicorn": "^62.0.0",
102
102
  "eslint-plugin-unused-imports": "^4.1.4",
103
+ "jsdom": "^27.2.0",
103
104
  "knip": "^5.69.1",
104
105
  "next": "^16.0.3",
105
106
  "prettier": "^3.6.2",