intor-translator 1.0.12 → 1.0.14

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.cjs CHANGED
@@ -194,11 +194,11 @@ var translate = ({
194
194
  return loadingMessage;
195
195
  }
196
196
  }
197
- if (!message) {
197
+ if (message === void 0 || message === null) {
198
198
  if (onMissing) {
199
199
  return onMissing({ key, locale, replacements });
200
200
  }
201
- if (placeholder) {
201
+ if (placeholder !== void 0 && placeholder !== null) {
202
202
  return placeholder;
203
203
  }
204
204
  return key;
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,8 @@ 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
421
  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 };
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,8 @@ 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
421
  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 };
package/dist/index.js CHANGED
@@ -192,11 +192,11 @@ var translate = ({
192
192
  return loadingMessage;
193
193
  }
194
194
  }
195
- if (!message) {
195
+ if (message === void 0 || message === null) {
196
196
  if (onMissing) {
197
197
  return onMissing({ key, locale, replacements });
198
198
  }
199
- if (placeholder) {
199
+ if (placeholder !== void 0 && placeholder !== null) {
200
200
  return placeholder;
201
201
  }
202
202
  return key;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "intor-translator",
3
- "version": "1.0.12",
3
+ "version": "1.0.14",
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",