intor 2.4.15 → 2.4.17

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.
@@ -5,7 +5,7 @@ import 'logry';
5
5
  export { clearLoggerPool } from '../src/core/logger/global-logger-pool.js';
6
6
  import 'p-limit';
7
7
  export { mergeMessages } from '../src/core/messages/merge-messages.js';
8
- import 'intor-translator';
8
+ export { Translator } from 'intor-translator';
9
9
  export { defineIntorConfig } from '../src/config/define-intor-config.js';
10
10
  import '../src/config/constants/cookie.js';
11
11
  export { localizePathname } from '../src/routing/pathname/localize-pathname.js';
@@ -57,6 +57,12 @@ function IntorProvider({ value: { config, locale: initialLocale, messages, handl
57
57
  // ---------------------------------------------------------------------------
58
58
  useLocaleEffects(config, locale);
59
59
  useMessagesEffects(config, locale, setRuntimeMessages, setInternalIsLoading);
60
+ // Sync internal locale with external prop
61
+ React.useEffect(() => {
62
+ if (initialLocale !== locale)
63
+ setLocaleState(initialLocale);
64
+ // eslint-disable-next-line react-hooks/exhaustive-deps
65
+ }, [initialLocale]);
60
66
  return (jsx(IntorContext.Provider, { value: { config, locale, setLocale, translator }, children: children }));
61
67
  }
62
68
 
@@ -26,7 +26,9 @@ function createIntorStore({ config, locale: initialLocale, messages, handlers, p
26
26
  // ---------------------------------------------------------------------------
27
27
  // Effective state
28
28
  // ---------------------------------------------------------------------------
29
- const externalIsLoadingStore = readable(!!externalIsLoading);
29
+ const externalIsLoadingStore = typeof externalIsLoading === "object" && "subscribe" in externalIsLoading
30
+ ? externalIsLoading
31
+ : readable(!!externalIsLoading);
30
32
  // external > internal
31
33
  const effectiveIsLoading = derived([externalIsLoadingStore, internalIsLoading], ([$external, $internal]) => $external || $internal);
32
34
  // runtime (client refetch) > initial > config (static)
@@ -1,3 +1,4 @@
1
1
  export { LOCALE_PLACEHOLDER, IntorError, IntorErrorCode, matchLocale, clearLoggerPool, mergeMessages, type MessagesReader, type MessagesReaders, type GenLocale as Locale, } from "../src/core";
2
2
  export { defineIntorConfig, type IntorRawConfig, type IntorResolvedConfig, } from "../src/config";
3
3
  export { localizePathname, type InboundContext } from "../src/routing";
4
+ export { Translator, type TranslatorPlugin, type TranslateContext, type TranslateHook, type TranslateHandlers, type HandlerContext, type FormatHandler, type LoadingHandler, type MissingHandler, type LocaleMessages, type MessageObject, type MessageValue, } from "intor-translator";
@@ -1,5 +1,5 @@
1
1
  import type { ReactTagRenderers } from "../render";
2
- import { type Replacement, type TranslatorMethods } from "intor-translator";
2
+ import { type LocaleMessages, type Replacement, type TranslatorMethods } from "intor-translator";
3
3
  /**
4
4
  * Create a React-specific rich translation function.
5
5
  *
@@ -12,4 +12,4 @@ import { type Replacement, type TranslatorMethods } from "intor-translator";
12
12
  *
13
13
  * Intended for React client usage only.
14
14
  */
15
- export declare const createTRich: (t: TranslatorMethods["t"]) => (key: string, tagRenderers?: ReactTagRenderers, replacements?: Replacement) => import("react/jsx-runtime").JSX.Element[];
15
+ export declare const createTRich: (t: TranslatorMethods<LocaleMessages>["t"]) => (key: string, tagRenderers?: ReactTagRenderers, replacements?: Replacement) => import("react/jsx-runtime").JSX.Element[];
@@ -1,12 +1,12 @@
1
1
  import type { ReactTagRenderers } from "../render";
2
2
  import type { TranslatorInstance } from "../../../core";
3
3
  import type { JSX } from "react/jsx-runtime";
4
- import { type Locale, type LocaleMessages, type LocalizedKey, type LocalizedReplacement, type LocalizedRich, type Replacement, type Rich, type ScopedKey } from "intor-translator";
4
+ import { type Locale, type LocaleMessages, type LocalizedKey, type LocalizedReplacement, type LocalizedRich, type Replacement, type Rich, type ScopedKey, type ScopedReplacement, type ScopedRich } from "intor-translator";
5
5
  export type TranslatorInstanceReact<M extends LocaleMessages, ReplacementSchema = Replacement, RichSchema = Rich, PK extends string | undefined = undefined> = Omit<TranslatorInstance<M, ReplacementSchema, RichSchema, PK>, "tRich"> & {
6
6
  /** Indicates whether translations are currently loading. */
7
7
  isLoading: boolean;
8
8
  /** Update the active locale. */
9
9
  setLocale: (locale: Locale<M>) => void;
10
10
  /** Translate a key into React nodes using semantic tags */
11
- tRich: <K extends string = PK extends string ? ScopedKey<M, PK> : LocalizedKey<M>, RI = LocalizedRich<RichSchema, K>, RE = LocalizedReplacement<ReplacementSchema, K>>(key?: K | (string & {}), tagRenderers?: ReactTagRenderers<RI> | ReactTagRenderers, replacements?: RE | Replacement) => JSX.Element[];
11
+ tRich: <K extends string = PK extends string ? ScopedKey<M, PK> : LocalizedKey<M>, RI = PK extends string ? ScopedRich<RichSchema, PK, K> : LocalizedRich<RichSchema, K>, RE = PK extends string ? ScopedReplacement<ReplacementSchema, PK, K> : LocalizedReplacement<ReplacementSchema, K>>(key?: K | (string & {}), tagRenderers?: ReactTagRenderers<RI> | ReactTagRenderers, replacements?: RE | Replacement) => JSX.Element[];
12
12
  };
@@ -1,5 +1,5 @@
1
1
  import type { VueTagRenderers } from "../../../client/vue/render";
2
- import { type Replacement, type TranslatorMethods } from "intor-translator";
2
+ import { type LocaleMessages, type Replacement, type TranslatorMethods } from "intor-translator";
3
3
  /**
4
4
  * Create a Vue-specific rich translation function.
5
5
  *
@@ -12,4 +12,4 @@ import { type Replacement, type TranslatorMethods } from "intor-translator";
12
12
  *
13
13
  * Intended for Vue client usage only.
14
14
  */
15
- export declare const createTRich: (t: TranslatorMethods["t"]) => (key: string, tagRenderers?: VueTagRenderers, replacements?: Replacement) => import("vue").VNodeChild[];
15
+ export declare const createTRich: (t: TranslatorMethods<LocaleMessages>["t"]) => (key: string, tagRenderers?: VueTagRenderers, replacements?: Replacement) => import("vue").VNodeChild[];
@@ -1,7 +1,7 @@
1
1
  import type { VueTagRenderers } from "../../../client/vue/render";
2
2
  import type { TranslatorInstance } from "../../../core";
3
3
  import type { ComputedRef, VNodeChild } from "vue";
4
- import { type Locale, type LocaleMessages, type LocalizedKey, type LocalizedReplacement, type LocalizedRich, type Replacement, type Rich, type ScopedKey } from "intor-translator";
4
+ import { type Locale, type LocaleMessages, type LocalizedKey, type LocalizedReplacement, type LocalizedRich, type Replacement, type Rich, type ScopedKey, type ScopedReplacement, type ScopedRich } from "intor-translator";
5
5
  export type TranslatorInstanceVue<M extends LocaleMessages, ReplacementSchema = Replacement, RichSchema = Rich, PK extends string | undefined = undefined> = Omit<TranslatorInstance<M, ReplacementSchema, RichSchema, PK>, "tRich" | "messages" | "locale"> & {
6
6
  /** `messages`: The message object containing all translations. */
7
7
  messages: ComputedRef<M>;
@@ -12,5 +12,5 @@ export type TranslatorInstanceVue<M extends LocaleMessages, ReplacementSchema =
12
12
  /** Update the active locale. */
13
13
  setLocale: (locale: Locale<M>) => void;
14
14
  /** Translate a key into VNodes using semantic tags */
15
- tRich: <K extends string = PK extends string ? ScopedKey<M, PK> : LocalizedKey<M>, RI = LocalizedRich<RichSchema, K>, RE = LocalizedReplacement<ReplacementSchema, K>>(key?: K | (string & {}), tagRenderers?: VueTagRenderers<RI> | VueTagRenderers, replacements?: RE | Replacement) => VNodeChild[];
15
+ tRich: <K extends string = PK extends string ? ScopedKey<M, PK> : LocalizedKey<M>, RI = PK extends string ? ScopedRich<RichSchema, PK, K> : LocalizedRich<RichSchema, K>, RE = PK extends string ? ScopedReplacement<ReplacementSchema, PK, K> : LocalizedReplacement<ReplacementSchema, K>>(key?: K | (string & {}), tagRenderers?: VueTagRenderers<RI> | VueTagRenderers, replacements?: RE | Replacement) => VNodeChild[];
16
16
  };
@@ -1,4 +1,4 @@
1
- import { type Replacement, type TranslatorMethods } from "intor-translator";
1
+ import { type LocaleMessages, type Replacement, type TranslatorMethods } from "intor-translator";
2
2
  import { type TagRenderers } from "../render";
3
3
  /**
4
4
  * Create an HTML-string rich translation function.
@@ -9,4 +9,4 @@ import { type TagRenderers } from "../render";
9
9
  *
10
10
  * Can be used in any HTML-based environment (Astro, Svelte, SSR, etc.).
11
11
  */
12
- export declare const createTRich: (t: TranslatorMethods["t"]) => (key: string, tagRenderers?: TagRenderers, replacements?: Replacement) => string;
12
+ export declare const createTRich: (t: TranslatorMethods<LocaleMessages>["t"]) => (key: string, tagRenderers?: TagRenderers, replacements?: Replacement) => string;
@@ -1,5 +1,5 @@
1
1
  import type { HtmlTagRenderers } from "../render";
2
- import { type Locale, type LocaleMessages, type LocalizedKey, type ScopedKey, type LocalizedValue, type ScopedValue, type Replacement, type LocalizedReplacement, type LocalizedRich, type Rich } from "intor-translator";
2
+ import { type Locale, type LocaleMessages, type LocalizedKey, type ScopedKey, type LocalizedValue, type ScopedValue, type Replacement, type LocalizedReplacement, type LocalizedRich, type Rich, type ScopedRich, type ScopedReplacement } from "intor-translator";
3
3
  type FallbackIfNever<T, Fallback> = [T] extends [never] ? Fallback : T;
4
4
  /**
5
5
  * Core translator instance interface.
@@ -16,6 +16,6 @@ export type TranslatorInstance<M extends LocaleMessages, ReplacementSchema = Rep
16
16
  /** Translate a given key into its string representation. */
17
17
  t: <K extends string = PK extends string ? ScopedKey<M, PK> : LocalizedKey<M>, R extends Replacement = LocalizedReplacement<ReplacementSchema, K>>(key?: K | (string & {}), replacements?: R | Replacement) => FallbackIfNever<PK extends string ? ScopedValue<M, PK, K> : LocalizedValue<M, K>, string>;
18
18
  /** Translate a key into an HTML string using semantic rich tags. */
19
- tRich: <K extends string = PK extends string ? ScopedKey<M, PK> : LocalizedKey<M>, RI = LocalizedRich<RichSchema, K>, RE = LocalizedReplacement<ReplacementSchema, K>>(key?: K | (string & {}), tagRenderers?: HtmlTagRenderers<RI> | HtmlTagRenderers, replacements?: RE | Replacement) => string;
19
+ tRich: <K extends string = PK extends string ? ScopedKey<M, PK> : LocalizedKey<M>, RI = PK extends string ? ScopedRich<RichSchema, PK, K> : LocalizedRich<RichSchema, K>, RE = PK extends string ? ScopedReplacement<ReplacementSchema, PK, K> : LocalizedReplacement<ReplacementSchema, K>>(key?: K | (string & {}), tagRenderers?: HtmlTagRenderers<RI> | HtmlTagRenderers, replacements?: RE | Replacement) => string;
20
20
  };
21
21
  export {};
@@ -1,5 +1,5 @@
1
1
  import { Translator } from 'intor-translator';
2
- import { defineComponent, ref, computed, provide } from 'vue';
2
+ import { defineComponent, ref, computed, watch, provide } from 'vue';
3
3
  import { useLocaleEffects } from './effects/use-locale-effects.js';
4
4
  import { useMessagesEffects } from './effects/use-messages-effects.js';
5
5
 
@@ -8,11 +8,10 @@ const IntorProvider = defineComponent({
8
8
  name: "IntorProvider",
9
9
  props: { value: { type: Object, required: true } },
10
10
  setup(props, { slots }) {
11
- const { config, locale: initialLocale, messages, handlers, plugins, onLocaleChange, isLoading: externalIsLoading, } = props.value;
12
11
  // ---------------------------------------------------------------------------
13
12
  // Internal state
14
13
  // ---------------------------------------------------------------------------
15
- const locale = ref(initialLocale);
14
+ const locale = ref(props.value.locale);
16
15
  const runtimeMessages = ref(null);
17
16
  const internalIsLoading = ref(false);
18
17
  // ---------------------------------------------------------------------------
@@ -23,15 +22,18 @@ const IntorProvider = defineComponent({
23
22
  if (newLocale === locale.value)
24
23
  return;
25
24
  locale.value = newLocale;
26
- onLocaleChange?.(newLocale); // Notify external listener (fire-and-forget)
25
+ props.value.onLocaleChange?.(newLocale); // Notify external listener (fire-and-forget)
27
26
  };
28
27
  // ---------------------------------------------------------------------------
29
28
  // Effective state
30
29
  // ---------------------------------------------------------------------------
31
30
  // external > internal
32
- const effectiveIsLoading = computed(() => !!externalIsLoading?.value || internalIsLoading.value);
31
+ const effectiveIsLoading = computed(() => !!props.value.isLoading?.value || internalIsLoading.value);
33
32
  // runtime (client refetch) > initial > config (static)
34
- const effectiveMessages = computed(() => runtimeMessages.value || messages?.value || config.messages || {});
33
+ const effectiveMessages = computed(() => runtimeMessages.value ||
34
+ props.value.messages?.value ||
35
+ props.value.config.messages ||
36
+ {});
35
37
  // ---------------------------------------------------------------------------
36
38
  // Translator
37
39
  // ---------------------------------------------------------------------------
@@ -40,20 +42,25 @@ const IntorProvider = defineComponent({
40
42
  messages: effectiveMessages.value,
41
43
  locale: locale.value,
42
44
  isLoading: effectiveIsLoading.value,
43
- fallbackLocales: config.fallbackLocales,
44
- loadingMessage: config.translator?.loadingMessage,
45
- missingMessage: config.translator?.missingMessage,
46
- handlers: handlers,
47
- plugins: plugins,
45
+ fallbackLocales: props.value.config.fallbackLocales,
46
+ loadingMessage: props.value.config.translator?.loadingMessage,
47
+ missingMessage: props.value.config.translator?.missingMessage,
48
+ handlers: props.value.handlers,
49
+ plugins: props.value.plugins,
48
50
  });
49
51
  });
50
52
  // -------------------------------------------------------------------------
51
53
  // Side effects
52
54
  // -------------------------------------------------------------------------
53
- useLocaleEffects(config, locale);
54
- useMessagesEffects(config, locale, runtimeMessages, internalIsLoading);
55
+ useLocaleEffects(props.value.config, locale);
56
+ useMessagesEffects(props.value.config, locale, runtimeMessages, internalIsLoading);
57
+ // Sync internal locale with external prop
58
+ watch(() => props.value.locale, (newLocale) => {
59
+ if (newLocale !== locale.value)
60
+ locale.value = newLocale;
61
+ });
55
62
  const contextValue = computed(() => ({
56
- config,
63
+ config: props.value.config,
57
64
  locale,
58
65
  setLocale,
59
66
  translator,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "intor",
3
- "version": "2.4.15",
3
+ "version": "2.4.17",
4
4
  "description": "The i18n library for modern JavaScript",
5
5
  "author": "Yiming Liao",
6
6
  "homepage": "https://intor.dev",
@@ -107,7 +107,7 @@
107
107
  "prepublishOnly": "yarn build"
108
108
  },
109
109
  "dependencies": {
110
- "intor-translator": "^1.4.14",
110
+ "intor-translator": "^1.4.15",
111
111
  "logry": "2.1.6",
112
112
  "p-limit": "7.2.0"
113
113
  },