intor 2.4.15 → 2.4.16

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 { 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.16",
4
4
  "description": "The i18n library for modern JavaScript",
5
5
  "author": "Yiming Liao",
6
6
  "homepage": "https://intor.dev",