intor-translator 1.0.12 → 1.0.13

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/index.d.cts CHANGED
@@ -327,6 +327,15 @@ type IsLoadingRef = {
327
327
  current: boolean;
328
328
  };
329
329
 
330
+ type ScopedTranslatorMethods<M, K extends string> = {
331
+ hasKey: (key?: ScopedLeafKeys<M, K> & string, targetLocale?: LocaleKey<M>) => boolean;
332
+ t: (key?: ScopedLeafKeys<M, K> & string, replacements?: Replacement | RichReplacement) => string;
333
+ };
334
+ type TranslatorMethods<M> = {
335
+ hasKey: (key?: InferTranslatorKey<M> & string, targetLocale?: LocaleKey<M>) => boolean;
336
+ t: (key?: InferTranslatorKey<M> & string, replacements?: Replacement | RichReplacement) => string;
337
+ };
338
+
330
339
  /** Config options for translation behavior. */
331
340
  type TranslateConfig<M> = {
332
341
  fallbackLocales?: FallbackLocalesMap<LocaleKey<M>>;
@@ -405,14 +414,28 @@ declare class CoreTranslator<M = unknown> extends BaseTranslator<M> {
405
414
 
406
415
  declare class ScopeTranslator<M = unknown> extends CoreTranslator<M> {
407
416
  constructor(options?: CoreTranslatorOptions<M>);
408
- scoped<K extends NodeKeys<UnionLocaleMessages<M>> & string>(preKey: K): {
409
- hasKey: (key?: ScopedLeafKeys<M, K> & string, targetLocale?: LocaleKey<M>) => boolean;
410
- t: (key?: ScopedLeafKeys<M, K> & string, replacements?: Replacement | RichReplacement) => string;
411
- };
412
- scoped(): {
413
- hasKey: (key?: InferTranslatorKey<M> & string, targetLocale?: LocaleKey<M>) => boolean;
414
- t: (key?: InferTranslatorKey<M> & string, replacements?: Replacement | RichReplacement) => string;
415
- };
417
+ scoped<K extends NodeKeys<UnionLocaleMessages<M>> & string>(preKey: K): ScopedTranslatorMethods<M, K>;
418
+ scoped(): TranslatorMethods<M>;
416
419
  }
417
420
 
418
- export { type FallbackLocalesMap, type FormatMessage, type InferTranslatorKey, type IsLoadingRef, type LeafKeys, type Locale, type LocaleKey, type LocaleNamespaceMessages, type LocaleRef, type Message, type MessageRecord, type MessagesRef, type Namespace, type NamespaceMessages, type NestedMessage, type NodeKeys, type OnLoading, type OnMissing, type Replacement, type RichReplacement, type ScopedLeafKeys, type StrictLocaleKey, type TranslateConfig, type TranslateContext, type TranslateHandlers, ScopeTranslator as Translator, type UnionLocaleLeafKeys, type UnionLocaleMessages };
421
+ /**
422
+ * Generic translate function type.
423
+ *
424
+ * Represents the shape of a `t()` function that supports typed keys and optional replacements.
425
+ *
426
+ * @template M - The shape of the messages object (e.g., typeof messages)
427
+ * @template Result - The expected return type (usually string, but can be JSX or others)
428
+ */
429
+ type TranslateFunction = <M, Result = string>(key: InferTranslatorKey<M>, replacements?: Replacement | RichReplacement) => Result;
430
+ /**
431
+ * Generic hasKey function type.
432
+ *
433
+ * Represents a function that checks if a given key exists in a message set,
434
+ * optionally for a specific locale.
435
+ *
436
+ * @template M - The shape of the messages object
437
+ * @template Result - The return value (default is boolean, override if needed)
438
+ */
439
+ type HasKeyFunction = <M, Result = boolean>(key: InferTranslatorKey<M>, targetLocale?: LocaleKey<M>) => Result;
440
+
441
+ export { type FallbackLocalesMap, type FormatMessage, type HasKeyFunction, type InferTranslatorKey, type IsLoadingRef, type LeafKeys, type Locale, type LocaleKey, type LocaleNamespaceMessages, type LocaleRef, type Message, type MessageRecord, type MessagesRef, type Namespace, type NamespaceMessages, type NestedMessage, type NodeKeys, type OnLoading, type OnMissing, type Replacement, type RichReplacement, type ScopedLeafKeys, type StrictLocaleKey, type TranslateConfig, type TranslateContext, type TranslateFunction, type TranslateHandlers, ScopeTranslator as Translator, type UnionLocaleLeafKeys, type UnionLocaleMessages };
package/dist/index.d.ts CHANGED
@@ -327,6 +327,15 @@ type IsLoadingRef = {
327
327
  current: boolean;
328
328
  };
329
329
 
330
+ type ScopedTranslatorMethods<M, K extends string> = {
331
+ hasKey: (key?: ScopedLeafKeys<M, K> & string, targetLocale?: LocaleKey<M>) => boolean;
332
+ t: (key?: ScopedLeafKeys<M, K> & string, replacements?: Replacement | RichReplacement) => string;
333
+ };
334
+ type TranslatorMethods<M> = {
335
+ hasKey: (key?: InferTranslatorKey<M> & string, targetLocale?: LocaleKey<M>) => boolean;
336
+ t: (key?: InferTranslatorKey<M> & string, replacements?: Replacement | RichReplacement) => string;
337
+ };
338
+
330
339
  /** Config options for translation behavior. */
331
340
  type TranslateConfig<M> = {
332
341
  fallbackLocales?: FallbackLocalesMap<LocaleKey<M>>;
@@ -405,14 +414,28 @@ declare class CoreTranslator<M = unknown> extends BaseTranslator<M> {
405
414
 
406
415
  declare class ScopeTranslator<M = unknown> extends CoreTranslator<M> {
407
416
  constructor(options?: CoreTranslatorOptions<M>);
408
- scoped<K extends NodeKeys<UnionLocaleMessages<M>> & string>(preKey: K): {
409
- hasKey: (key?: ScopedLeafKeys<M, K> & string, targetLocale?: LocaleKey<M>) => boolean;
410
- t: (key?: ScopedLeafKeys<M, K> & string, replacements?: Replacement | RichReplacement) => string;
411
- };
412
- scoped(): {
413
- hasKey: (key?: InferTranslatorKey<M> & string, targetLocale?: LocaleKey<M>) => boolean;
414
- t: (key?: InferTranslatorKey<M> & string, replacements?: Replacement | RichReplacement) => string;
415
- };
417
+ scoped<K extends NodeKeys<UnionLocaleMessages<M>> & string>(preKey: K): ScopedTranslatorMethods<M, K>;
418
+ scoped(): TranslatorMethods<M>;
416
419
  }
417
420
 
418
- export { type FallbackLocalesMap, type FormatMessage, type InferTranslatorKey, type IsLoadingRef, type LeafKeys, type Locale, type LocaleKey, type LocaleNamespaceMessages, type LocaleRef, type Message, type MessageRecord, type MessagesRef, type Namespace, type NamespaceMessages, type NestedMessage, type NodeKeys, type OnLoading, type OnMissing, type Replacement, type RichReplacement, type ScopedLeafKeys, type StrictLocaleKey, type TranslateConfig, type TranslateContext, type TranslateHandlers, ScopeTranslator as Translator, type UnionLocaleLeafKeys, type UnionLocaleMessages };
421
+ /**
422
+ * Generic translate function type.
423
+ *
424
+ * Represents the shape of a `t()` function that supports typed keys and optional replacements.
425
+ *
426
+ * @template M - The shape of the messages object (e.g., typeof messages)
427
+ * @template Result - The expected return type (usually string, but can be JSX or others)
428
+ */
429
+ type TranslateFunction = <M, Result = string>(key: InferTranslatorKey<M>, replacements?: Replacement | RichReplacement) => Result;
430
+ /**
431
+ * Generic hasKey function type.
432
+ *
433
+ * Represents a function that checks if a given key exists in a message set,
434
+ * optionally for a specific locale.
435
+ *
436
+ * @template M - The shape of the messages object
437
+ * @template Result - The return value (default is boolean, override if needed)
438
+ */
439
+ type HasKeyFunction = <M, Result = boolean>(key: InferTranslatorKey<M>, targetLocale?: LocaleKey<M>) => Result;
440
+
441
+ export { type FallbackLocalesMap, type FormatMessage, type HasKeyFunction, type InferTranslatorKey, type IsLoadingRef, type LeafKeys, type Locale, type LocaleKey, type LocaleNamespaceMessages, type LocaleRef, type Message, type MessageRecord, type MessagesRef, type Namespace, type NamespaceMessages, type NestedMessage, type NodeKeys, type OnLoading, type OnMissing, type Replacement, type RichReplacement, type ScopedLeafKeys, type StrictLocaleKey, type TranslateConfig, type TranslateContext, type TranslateFunction, type TranslateHandlers, ScopeTranslator as Translator, type UnionLocaleLeafKeys, type UnionLocaleMessages };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "intor-translator",
3
- "version": "1.0.12",
3
+ "version": "1.0.13",
4
4
  "description": "A type safe translator that knows what to say and how to handle the rest. Supports custom messages, rich replacements, and async loading.",
5
5
  "author": "Yiming Liao",
6
6
  "license": "MIT",