intor-translator 1.0.6 → 1.0.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.
package/dist/index.cjs CHANGED
@@ -249,13 +249,9 @@ var BaseTranslator = class {
249
249
  get locale() {
250
250
  return this.localeRef.current;
251
251
  }
252
- /** Change the active locale if available. */
252
+ /** Change the active locale. */
253
253
  setLocale(newLocale) {
254
- if (this.messagesRef.current && newLocale in this.messagesRef.current) {
255
- this.localeRef.current = newLocale;
256
- return true;
257
- }
258
- return false;
254
+ this.localeRef.current = newLocale;
259
255
  }
260
256
  };
261
257
 
@@ -301,29 +297,29 @@ var getFullKey = (preKey = "", key = "") => {
301
297
  var ScopeTranslator = class extends CoreTranslator {
302
298
  constructor(options) {
303
299
  super(options);
304
- this.scoped = (preKey) => {
305
- return {
306
- hasKey: (key, targetLocale) => {
307
- const fullKey = getFullKey(preKey, key);
308
- return hasKey({
309
- messagesRef: this.messagesRef,
310
- localeRef: this.localeRef,
311
- key: fullKey,
312
- targetLocale
313
- });
314
- },
315
- t: (key, replacements) => {
316
- const fullKey = getFullKey(preKey, key);
317
- return translate({
318
- messagesRef: this.messagesRef,
319
- localeRef: this.localeRef,
320
- isLoadingRef: this.isLoadingRef,
321
- translateConfig: this.options,
322
- key: fullKey,
323
- replacements
324
- });
325
- }
326
- };
300
+ }
301
+ scoped(preKey) {
302
+ return {
303
+ hasKey: (key, targetLocale) => {
304
+ const fullKey = getFullKey(preKey, key);
305
+ return hasKey({
306
+ messagesRef: this.messagesRef,
307
+ localeRef: this.localeRef,
308
+ key: fullKey,
309
+ targetLocale
310
+ });
311
+ },
312
+ t: (key, replacements) => {
313
+ const fullKey = getFullKey(preKey, key);
314
+ return translate({
315
+ messagesRef: this.messagesRef,
316
+ localeRef: this.localeRef,
317
+ isLoadingRef: this.isLoadingRef,
318
+ translateConfig: this.options,
319
+ key: fullKey,
320
+ replacements
321
+ });
322
+ }
327
323
  };
328
324
  }
329
325
  };
package/dist/index.d.cts CHANGED
@@ -364,8 +364,8 @@ declare class BaseTranslator<M extends LocaleNamespaceMessages = never> {
364
364
  setMessages<N extends LocaleNamespaceMessages>(messages: N): void;
365
365
  /** Get the current active locale. */
366
366
  get locale(): LocaleKey<M> | undefined;
367
- /** Change the active locale if available. */
368
- setLocale(newLocale: LocaleKey<M>): boolean;
367
+ /** Change the active locale. */
368
+ setLocale(newLocale: LocaleKey<M>): void;
369
369
  /** Check if a key exists in the specified locale or current locale. */
370
370
  hasKey: (key: InferTranslatorKey<M>, targetLocale?: LocaleKey<M>) => boolean;
371
371
  }
@@ -386,9 +386,13 @@ declare class CoreTranslator<M extends LocaleNamespaceMessages = never> extends
386
386
 
387
387
  declare class ScopeTranslator<M extends LocaleNamespaceMessages = never> extends CoreTranslator<M> {
388
388
  constructor(options?: CoreTranslatorOptions<M>);
389
- scoped: <K extends NodeKeys<UnionLocaleMessages<M>> & string, ScopedKeys extends ScopedLeafKeys<M, K> & string>(preKey: K) => {
390
- hasKey: (key?: ScopedKeys | undefined, targetLocale?: string) => boolean;
391
- t: (key?: ScopedKeys | undefined, replacements?: Replacement | RichReplacement) => string;
389
+ scoped<K extends NodeKeys<UnionLocaleMessages<M>> & string>(preKey: K): {
390
+ hasKey: (key?: ScopedLeafKeys<M, K> & string, targetLocale?: string) => boolean;
391
+ t: (key?: ScopedLeafKeys<M, K> & string, replacements?: Replacement | RichReplacement) => string;
392
+ };
393
+ scoped(): {
394
+ hasKey: (key?: UnionLocaleLeafKeys<M> & string, targetLocale?: string) => boolean;
395
+ t: (key?: UnionLocaleLeafKeys<M> & string, replacements?: Replacement | RichReplacement) => string;
392
396
  };
393
397
  }
394
398
 
package/dist/index.d.ts CHANGED
@@ -364,8 +364,8 @@ declare class BaseTranslator<M extends LocaleNamespaceMessages = never> {
364
364
  setMessages<N extends LocaleNamespaceMessages>(messages: N): void;
365
365
  /** Get the current active locale. */
366
366
  get locale(): LocaleKey<M> | undefined;
367
- /** Change the active locale if available. */
368
- setLocale(newLocale: LocaleKey<M>): boolean;
367
+ /** Change the active locale. */
368
+ setLocale(newLocale: LocaleKey<M>): void;
369
369
  /** Check if a key exists in the specified locale or current locale. */
370
370
  hasKey: (key: InferTranslatorKey<M>, targetLocale?: LocaleKey<M>) => boolean;
371
371
  }
@@ -386,9 +386,13 @@ declare class CoreTranslator<M extends LocaleNamespaceMessages = never> extends
386
386
 
387
387
  declare class ScopeTranslator<M extends LocaleNamespaceMessages = never> extends CoreTranslator<M> {
388
388
  constructor(options?: CoreTranslatorOptions<M>);
389
- scoped: <K extends NodeKeys<UnionLocaleMessages<M>> & string, ScopedKeys extends ScopedLeafKeys<M, K> & string>(preKey: K) => {
390
- hasKey: (key?: ScopedKeys | undefined, targetLocale?: string) => boolean;
391
- t: (key?: ScopedKeys | undefined, replacements?: Replacement | RichReplacement) => string;
389
+ scoped<K extends NodeKeys<UnionLocaleMessages<M>> & string>(preKey: K): {
390
+ hasKey: (key?: ScopedLeafKeys<M, K> & string, targetLocale?: string) => boolean;
391
+ t: (key?: ScopedLeafKeys<M, K> & string, replacements?: Replacement | RichReplacement) => string;
392
+ };
393
+ scoped(): {
394
+ hasKey: (key?: UnionLocaleLeafKeys<M> & string, targetLocale?: string) => boolean;
395
+ t: (key?: UnionLocaleLeafKeys<M> & string, replacements?: Replacement | RichReplacement) => string;
392
396
  };
393
397
  }
394
398
 
package/dist/index.js CHANGED
@@ -247,13 +247,9 @@ var BaseTranslator = class {
247
247
  get locale() {
248
248
  return this.localeRef.current;
249
249
  }
250
- /** Change the active locale if available. */
250
+ /** Change the active locale. */
251
251
  setLocale(newLocale) {
252
- if (this.messagesRef.current && newLocale in this.messagesRef.current) {
253
- this.localeRef.current = newLocale;
254
- return true;
255
- }
256
- return false;
252
+ this.localeRef.current = newLocale;
257
253
  }
258
254
  };
259
255
 
@@ -299,29 +295,29 @@ var getFullKey = (preKey = "", key = "") => {
299
295
  var ScopeTranslator = class extends CoreTranslator {
300
296
  constructor(options) {
301
297
  super(options);
302
- this.scoped = (preKey) => {
303
- return {
304
- hasKey: (key, targetLocale) => {
305
- const fullKey = getFullKey(preKey, key);
306
- return hasKey({
307
- messagesRef: this.messagesRef,
308
- localeRef: this.localeRef,
309
- key: fullKey,
310
- targetLocale
311
- });
312
- },
313
- t: (key, replacements) => {
314
- const fullKey = getFullKey(preKey, key);
315
- return translate({
316
- messagesRef: this.messagesRef,
317
- localeRef: this.localeRef,
318
- isLoadingRef: this.isLoadingRef,
319
- translateConfig: this.options,
320
- key: fullKey,
321
- replacements
322
- });
323
- }
324
- };
298
+ }
299
+ scoped(preKey) {
300
+ return {
301
+ hasKey: (key, targetLocale) => {
302
+ const fullKey = getFullKey(preKey, key);
303
+ return hasKey({
304
+ messagesRef: this.messagesRef,
305
+ localeRef: this.localeRef,
306
+ key: fullKey,
307
+ targetLocale
308
+ });
309
+ },
310
+ t: (key, replacements) => {
311
+ const fullKey = getFullKey(preKey, key);
312
+ return translate({
313
+ messagesRef: this.messagesRef,
314
+ localeRef: this.localeRef,
315
+ isLoadingRef: this.isLoadingRef,
316
+ translateConfig: this.options,
317
+ key: fullKey,
318
+ replacements
319
+ });
320
+ }
325
321
  };
326
322
  }
327
323
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "intor-translator",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
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",