solid-intlayer 9.9.3 → 9.9.4
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/cjs/IntlayerNode.cjs +11 -1
- package/dist/cjs/LoadingBoundary.cjs +26 -1
- package/dist/cjs/analytics/AnalyticsProvider.cjs +12 -1
- package/dist/cjs/analytics/exposureSink.cjs +23 -1
- package/dist/cjs/analytics/index.cjs +9 -1
- package/dist/cjs/analytics/useAnalytics.cjs +59 -1
- package/dist/cjs/analytics/useConversion.cjs +25 -1
- package/dist/cjs/analytics/useExperiment.cjs +59 -1
- package/dist/cjs/client/IntlayerProvider.cjs +91 -1
- package/dist/cjs/client/contentProxy.cjs +32 -1
- package/dist/cjs/client/getBrowserLocale.cjs +115 -1
- package/dist/cjs/client/index.cjs +35 -1
- package/dist/cjs/client/t.cjs +16 -1
- package/dist/cjs/client/useContent.cjs +16 -1
- package/dist/cjs/client/useDictionary.cjs +51 -1
- package/dist/cjs/client/useDictionaryAsync.cjs +19 -1
- package/dist/cjs/client/useDictionaryDynamic.cjs +82 -1
- package/dist/cjs/client/useIntlayer.cjs +50 -1
- package/dist/cjs/client/useLoadDynamic.cjs +140 -1
- package/dist/cjs/client/useLocale.cjs +52 -1
- package/dist/cjs/client/useLocaleBase.cjs +19 -1
- package/dist/cjs/client/useLocaleStorage.cjs +59 -1
- package/dist/cjs/client/usePathname.cjs +41 -1
- package/dist/cjs/client/useRewriteURL.cjs +21 -1
- package/dist/cjs/client/useTraduction.cjs +32 -1
- package/dist/cjs/editor/ContentSelector.cjs +20 -1
- package/dist/cjs/editor/EditorProvider.cjs +8 -1
- package/dist/cjs/editor/createEditedContentSource.cjs +32 -1
- package/dist/cjs/editor/useEditor.cjs +38 -1
- package/dist/cjs/format/index.cjs +19 -1
- package/dist/cjs/format/useCompact.cjs +15 -1
- package/dist/cjs/format/useCurrency.cjs +16 -1
- package/dist/cjs/format/useDate.cjs +25 -1
- package/dist/cjs/format/useIntl.cjs +31 -1
- package/dist/cjs/format/useList.cjs +15 -1
- package/dist/cjs/format/useNumber.cjs +19 -1
- package/dist/cjs/format/usePercentage.cjs +16 -1
- package/dist/cjs/format/useRelativeTime.cjs +16 -1
- package/dist/cjs/format/useUnit.cjs +15 -1
- package/dist/cjs/getDictionary.cjs +17 -1
- package/dist/cjs/getIntlayer.cjs +14 -1
- package/dist/cjs/html/HTMLProvider.cjs +24 -1
- package/dist/cjs/html/HTMLRenderer.cjs +49 -1
- package/dist/cjs/html/index.cjs +8 -1
- package/dist/cjs/html/types.cjs +1 -1
- package/dist/cjs/index.cjs +48 -1
- package/dist/cjs/markdown/MarkdownProvider.cjs +47 -1
- package/dist/cjs/markdown/MarkdownRenderer.cjs +56 -1
- package/dist/cjs/markdown/compiler.cjs +64 -1
- package/dist/cjs/markdown/index.cjs +13 -1
- package/dist/cjs/markdown/runtime.cjs +48 -1
- package/dist/cjs/plugins.cjs +266 -1
- package/dist/cjs/proxyKeys.cjs +14 -1
- package/dist/cjs/server/index.cjs +3 -1
- package/dist/cjs/server/useDictionary.cjs +30 -1
- package/dist/cjs/solidCompat.cjs +167 -1
- package/dist/cjs/solidElement/renderSolidElement.cjs +34 -1
- package/dist/cjs/solidTypes.cjs +1 -1
- package/dist/esm/IntlayerNode.mjs +8 -6
- package/dist/esm/LoadingBoundary.mjs +19 -6
- package/dist/esm/analytics/AnalyticsProvider.mjs +10 -3
- package/dist/esm/analytics/exposureSink.mjs +19 -5
- package/dist/esm/analytics/index.mjs +5 -5
- package/dist/esm/analytics/useAnalytics.mjs +52 -25
- package/dist/esm/analytics/useConversion.mjs +22 -6
- package/dist/esm/analytics/useExperiment.mjs +50 -22
- package/dist/esm/client/IntlayerProvider.mjs +75 -28
- package/dist/esm/client/contentProxy.mjs +26 -12
- package/dist/esm/client/getBrowserLocale.mjs +106 -71
- package/dist/esm/client/index.mjs +14 -14
- package/dist/esm/client/t.mjs +13 -7
- package/dist/esm/client/useContent.mjs +11 -8
- package/dist/esm/client/useDictionary.mjs +47 -25
- package/dist/esm/client/useDictionaryAsync.mjs +16 -9
- package/dist/esm/client/useDictionaryDynamic.mjs +72 -43
- package/dist/esm/client/useIntlayer.mjs +45 -15
- package/dist/esm/client/useLoadDynamic.mjs +128 -49
- package/dist/esm/client/useLocale.mjs +47 -16
- package/dist/esm/client/useLocaleBase.mjs +14 -10
- package/dist/esm/client/useLocaleStorage.mjs +51 -10
- package/dist/esm/client/usePathname.mjs +37 -12
- package/dist/esm/client/useRewriteURL.mjs +17 -11
- package/dist/esm/client/useTraduction.mjs +29 -8
- package/dist/esm/editor/ContentSelector.mjs +18 -15
- package/dist/esm/editor/EditorProvider.mjs +6 -3
- package/dist/esm/editor/createEditedContentSource.mjs +28 -17
- package/dist/esm/editor/useEditor.mjs +32 -22
- package/dist/esm/format/index.mjs +10 -10
- package/dist/esm/format/useCompact.mjs +11 -8
- package/dist/esm/format/useCurrency.mjs +12 -9
- package/dist/esm/format/useDate.mjs +19 -13
- package/dist/esm/format/useIntl.mjs +27 -9
- package/dist/esm/format/useList.mjs +11 -8
- package/dist/esm/format/useNumber.mjs +15 -9
- package/dist/esm/format/usePercentage.mjs +12 -9
- package/dist/esm/format/useRelativeTime.mjs +12 -9
- package/dist/esm/format/useUnit.mjs +11 -8
- package/dist/esm/getDictionary.mjs +14 -6
- package/dist/esm/getIntlayer.mjs +11 -6
- package/dist/esm/html/HTMLProvider.mjs +21 -12
- package/dist/esm/html/HTMLRenderer.mjs +44 -17
- package/dist/esm/html/index.mjs +3 -3
- package/dist/esm/index.mjs +20 -20
- package/dist/esm/markdown/MarkdownProvider.mjs +31 -24
- package/dist/esm/markdown/MarkdownRenderer.mjs +48 -37
- package/dist/esm/markdown/compiler.mjs +59 -23
- package/dist/esm/markdown/index.mjs +4 -4
- package/dist/esm/markdown/runtime.mjs +40 -13
- package/dist/esm/plugins.mjs +205 -156
- package/dist/esm/proxyKeys.mjs +7 -2
- package/dist/esm/server/useDictionary.mjs +25 -7
- package/dist/esm/solidCompat.mjs +146 -39
- package/dist/esm/solidElement/renderSolidElement.mjs +22 -19
- package/dist/rolldown-runtime-CmQyd0Gu.js +27 -0
- package/dist/solid/analytics/useAnalytics.jsx +3 -3
- package/dist/solid/analytics/useConversion.js +2 -2
- package/dist/solid/analytics/useExperiment.js +3 -3
- package/package.json +7 -7
- package/dist/esm-YGODKOLP.js +0 -1
- package/dist/esm-bdKnuomJ.mjs +0 -256
- package/dist/isEnabled-CuTKz0YA.js +0 -1
- package/dist/isEnabled-DVKEZ2He.mjs +0 -18
- package/dist/rolldown-runtime-BocRIvOZ.js +0 -1
- package/dist/solid/esm-1cHk4dPd.js +0 -644
- package/dist/solid/isEnabled-C5NUhdhZ.js +0 -100
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import { useAnalytics
|
|
1
|
+
import { useAnalytics } from "./useAnalytics.mjs";
|
|
2
2
|
// src/analytics/AnalyticsProvider.tsx
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Runs {@link useAnalytics} and renders its children unchanged. Mounted inside
|
|
5
|
+
* {@link IntlayerProvider} alongside `EditorProvider`.
|
|
6
|
+
*/
|
|
7
|
+
var AnalyticsProvider = ({ children }) => {
|
|
8
|
+
useAnalytics();
|
|
9
|
+
return children;
|
|
10
|
+
};
|
|
11
|
+
export { AnalyticsProvider };
|
|
@@ -1,7 +1,21 @@
|
|
|
1
1
|
// src/analytics/exposureSink.ts
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
var sink = null;
|
|
3
|
+
/**
|
|
4
|
+
* Installs (or clears) the exposure sink. `useAnalytics` sets this once the
|
|
5
|
+
* analytics client has loaded, and clears it on unmount.
|
|
6
|
+
*
|
|
7
|
+
* @param next - The sink to install, or `null` to clear.
|
|
8
|
+
*/
|
|
9
|
+
var setExposureSink = (next) => {
|
|
10
|
+
sink = next;
|
|
6
11
|
};
|
|
7
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Forwards a content exposure to the installed sink. A cheap null-check when
|
|
14
|
+
* analytics is not running, so it is safe to call from every node resolution.
|
|
15
|
+
*
|
|
16
|
+
* @param input - The node metadata to report.
|
|
17
|
+
*/
|
|
18
|
+
var reportExposure = (input) => {
|
|
19
|
+
sink?.(input);
|
|
20
|
+
};
|
|
21
|
+
export { reportExposure, setExposureSink };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AnalyticsProvider
|
|
2
|
-
import { useAnalytics
|
|
3
|
-
import { useConversion
|
|
4
|
-
import { useExperiment
|
|
5
|
-
export {
|
|
1
|
+
import { AnalyticsProvider } from "./AnalyticsProvider.mjs";
|
|
2
|
+
import { useAnalytics } from "./useAnalytics.mjs";
|
|
3
|
+
import { useConversion } from "./useConversion.mjs";
|
|
4
|
+
import { useExperiment } from "./useExperiment.mjs";
|
|
5
|
+
export { AnalyticsProvider, useAnalytics, useConversion, useExperiment };
|
|
@@ -1,31 +1,58 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { createSignal
|
|
3
|
-
import { useIntlayerContext
|
|
4
|
-
import { createWatchEffect
|
|
5
|
-
import { setExposureSink
|
|
1
|
+
import { isEnabled } from "@intlayer/analytics/isEnabled";
|
|
2
|
+
import { createSignal, onCleanup } from "solid-js";
|
|
3
|
+
import { useIntlayerContext } from "../client/IntlayerProvider.mjs";
|
|
4
|
+
import { createWatchEffect, onMounted } from "../solidCompat.mjs";
|
|
5
|
+
import { setExposureSink } from "./exposureSink.mjs";
|
|
6
6
|
// src/analytics/useAnalytics.tsx
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Initializes the Intlayer analytics client singleton when analytics is enabled
|
|
9
|
+
* and keeps it aware of the current locale.
|
|
10
|
+
*
|
|
11
|
+
* Mirrors {@link useEditor}: the module is loaded via a dynamic `import()` so it
|
|
12
|
+
* ships as its own async chunk, off the critical rendering path. Apps that
|
|
13
|
+
* don't opt in (`analytics.enabled !== true`) pay nothing — the whole body is
|
|
14
|
+
* guarded by `INTLAYER_ANALYTICS_ENABLED` and dead-code-eliminated at build
|
|
15
|
+
* time.
|
|
16
|
+
*/
|
|
17
|
+
var useAnalytics = () => {
|
|
18
|
+
if (process.env.INTLAYER_ANALYTICS_ENABLED === "false" || !isEnabled) return;
|
|
19
|
+
const { locale } = useIntlayerContext();
|
|
20
|
+
const [client, setClient] = createSignal(null);
|
|
21
|
+
let cancelled = false;
|
|
22
|
+
let initialized = false;
|
|
23
|
+
onMounted(() => {
|
|
24
|
+
import("@intlayer/analytics").then(({ initAnalyticsClient, buildContentExposure }) => {
|
|
25
|
+
if (cancelled) return;
|
|
26
|
+
const clientInstance = initAnalyticsClient();
|
|
27
|
+
initialized = true;
|
|
28
|
+
const currentLocale = locale?.();
|
|
29
|
+
if (currentLocale) clientInstance.setLocale(currentLocale);
|
|
30
|
+
clientInstance.trackPageView({ reason: "initial" });
|
|
31
|
+
setExposureSink((input) => clientInstance.trackContentExposure(buildContentExposure(input)));
|
|
32
|
+
setClient(clientInstance);
|
|
17
33
|
}).catch(() => {});
|
|
18
34
|
});
|
|
19
|
-
let
|
|
20
|
-
|
|
21
|
-
clientInstance:
|
|
22
|
-
currentLocale:
|
|
23
|
-
}), ({ clientInstance
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
35
|
+
let previousLocale;
|
|
36
|
+
createWatchEffect(() => ({
|
|
37
|
+
clientInstance: client(),
|
|
38
|
+
currentLocale: locale?.()
|
|
39
|
+
}), ({ clientInstance, currentLocale }) => {
|
|
40
|
+
if (!clientInstance || !currentLocale) return;
|
|
41
|
+
if (previousLocale === void 0) {
|
|
42
|
+
previousLocale = currentLocale;
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (previousLocale === currentLocale) return;
|
|
46
|
+
previousLocale = currentLocale;
|
|
47
|
+
clientInstance.setLocale(currentLocale);
|
|
48
|
+
clientInstance.trackPageView({ reason: "locale_change" });
|
|
49
|
+
});
|
|
50
|
+
onCleanup(() => {
|
|
51
|
+
cancelled = true;
|
|
52
|
+
setExposureSink(null);
|
|
53
|
+
import("@intlayer/analytics").then(({ stopAnalyticsClient }) => {
|
|
54
|
+
if (initialized) stopAnalyticsClient();
|
|
28
55
|
}).catch(() => {});
|
|
29
56
|
});
|
|
30
57
|
};
|
|
31
|
-
export {
|
|
58
|
+
export { useAnalytics };
|
|
@@ -1,8 +1,24 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isEnabled } from "@intlayer/analytics/isEnabled";
|
|
2
2
|
// src/analytics/useConversion.ts
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Returns a `trackConversion` callback for content A/B testing. Safe to call
|
|
5
|
+
* from any component: it resolves to a no-op when analytics is disabled or the
|
|
6
|
+
* client has not been initialized yet.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* const trackConversion = useConversion();
|
|
11
|
+
* <button onClick={() => trackConversion({
|
|
12
|
+
* experimentKey: 'homepage-hero', variant: 'b', goal: 'cta_click',
|
|
13
|
+
* })}>Get started</button>
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
var useConversion = () => {
|
|
17
|
+
return (params) => {
|
|
18
|
+
if (process.env.INTLAYER_ANALYTICS_ENABLED === "false" || !isEnabled) return;
|
|
19
|
+
import("@intlayer/analytics").then(({ getGlobalAnalyticsClient }) => {
|
|
20
|
+
getGlobalAnalyticsClient()?.trackConversion(params);
|
|
21
|
+
}).catch(() => {});
|
|
22
|
+
};
|
|
7
23
|
};
|
|
8
|
-
export {
|
|
24
|
+
export { useConversion };
|
|
@@ -1,30 +1,58 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { createSignal
|
|
3
|
-
import { onMounted
|
|
1
|
+
import { isEnabled } from "@intlayer/analytics/isEnabled";
|
|
2
|
+
import { createSignal, onCleanup } from "solid-js";
|
|
3
|
+
import { onMounted } from "../solidCompat.mjs";
|
|
4
4
|
// src/analytics/useExperiment.ts
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Assigns this session to a variant of an A/B experiment and records the
|
|
7
|
+
* exposure, scoped to `experimentKey`, so the backend can compute per-variant
|
|
8
|
+
* conversion rates against `useConversion` events.
|
|
9
|
+
*
|
|
10
|
+
* Assignment is deterministic per session (no server round-trip, stable across
|
|
11
|
+
* re-mounts). The exposure is recorded once per mount.
|
|
12
|
+
*
|
|
13
|
+
* @param experimentKey - Unique key identifying the experiment.
|
|
14
|
+
* @param variants - The candidate variant names; the first one is the control.
|
|
15
|
+
* @param weights - Optional relative weights, one per variant (e.g. `[9, 1]`).
|
|
16
|
+
* @returns The {@link ExperimentState} for this session.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```tsx
|
|
20
|
+
* const { variant } = useExperiment('homepage-hero', ['a', 'b']);
|
|
21
|
+
* const content = useIntlayer(variant() === 'b' ? 'hero-b' : 'hero');
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
var useExperiment = (experimentKey, variants, weights) => {
|
|
25
|
+
const [variant, setVariant] = createSignal(variants[0] ?? "");
|
|
26
|
+
const [isAssigned, setIsAssigned] = createSignal(false);
|
|
27
|
+
let cancelled = false;
|
|
28
|
+
let initialized = false;
|
|
29
|
+
onMounted(() => {
|
|
30
|
+
if (process.env.INTLAYER_ANALYTICS_ENABLED === "false" || !isEnabled) return;
|
|
31
|
+
import("@intlayer/analytics").then(({ initAnalyticsClient }) => {
|
|
32
|
+
if (cancelled) return;
|
|
33
|
+
const client = initAnalyticsClient();
|
|
34
|
+
initialized = true;
|
|
35
|
+
const assigned = client.getVariant(experimentKey, variants, weights);
|
|
36
|
+
setVariant(assigned);
|
|
37
|
+
setIsAssigned(true);
|
|
38
|
+
client.trackContentExposure({
|
|
39
|
+
dictionaryKey: experimentKey,
|
|
15
40
|
keyPath: "",
|
|
16
41
|
nodeType: "experiment",
|
|
17
|
-
experimentKey
|
|
18
|
-
variant:
|
|
42
|
+
experimentKey,
|
|
43
|
+
variant: assigned
|
|
19
44
|
});
|
|
20
45
|
}).catch(() => {});
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
|
|
46
|
+
});
|
|
47
|
+
onCleanup(() => {
|
|
48
|
+
cancelled = true;
|
|
49
|
+
import("@intlayer/analytics").then(({ stopAnalyticsClient }) => {
|
|
50
|
+
if (initialized) stopAnalyticsClient();
|
|
24
51
|
}).catch(() => {});
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
|
|
52
|
+
});
|
|
53
|
+
return {
|
|
54
|
+
variant,
|
|
55
|
+
isAssigned
|
|
28
56
|
};
|
|
29
57
|
};
|
|
30
|
-
export {
|
|
58
|
+
export { useExperiment };
|
|
@@ -1,40 +1,87 @@
|
|
|
1
|
-
import { createComponent
|
|
2
|
-
import { internationalization
|
|
3
|
-
import { setIntlayerIdentifier
|
|
4
|
-
import { localeResolver
|
|
5
|
-
import { createContext
|
|
6
|
-
import { LoadingBoundary
|
|
7
|
-
import { createWritableMemo
|
|
8
|
-
import { getLocaleInStorage
|
|
1
|
+
import { createComponent, memo, mergeProps } from "solid-js/web";
|
|
2
|
+
import { internationalization } from "@intlayer/config/built";
|
|
3
|
+
import { setIntlayerIdentifier } from "@intlayer/config/client";
|
|
4
|
+
import { localeResolver } from "@intlayer/core/localization";
|
|
5
|
+
import { createContext, createMemo, untrack, useContext } from "solid-js";
|
|
6
|
+
import { LoadingBoundary } from "../LoadingBoundary.mjs";
|
|
7
|
+
import { createWritableMemo, getContextProvider, lazyComponent, onMounted, runInTransition } from "../solidCompat.mjs";
|
|
8
|
+
import { getLocaleInStorage, setLocaleInStorage } from "./useLocaleStorage.mjs";
|
|
9
9
|
// src/client/IntlayerProvider.tsx
|
|
10
|
-
var
|
|
11
|
-
|
|
10
|
+
var LazyEditorProvider = process.env.INTLAYER_EDITOR_ENABLED !== "false" ? lazyComponent(() => import("../editor/EditorProvider.mjs").then((m) => ({ default: m.EditorProvider }))) : null;
|
|
11
|
+
var LazyAnalyticsProvider = process.env.INTLAYER_ANALYTICS_ENABLED !== "false" ? lazyComponent(() => import("../analytics/AnalyticsProvider.mjs").then((m) => ({ default: m.AnalyticsProvider }))) : null;
|
|
12
|
+
/**
|
|
13
|
+
* Context that store the current locale on the client side
|
|
14
|
+
*/
|
|
15
|
+
var IntlayerClientContext = createContext({
|
|
16
|
+
locale: () => getLocaleInStorage() ?? internationalization?.defaultLocale,
|
|
12
17
|
setLocale: () => null
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
});
|
|
19
|
+
var IntlayerClientContextProvider = getContextProvider(IntlayerClientContext);
|
|
20
|
+
/**
|
|
21
|
+
* Hook that provides the current locale
|
|
22
|
+
*/
|
|
23
|
+
var useIntlayerContext = () => useContext(IntlayerClientContext);
|
|
24
|
+
/**
|
|
25
|
+
* Provider that store the current locale on the client side
|
|
26
|
+
*/
|
|
27
|
+
var IntlayerProviderContent = (props) => {
|
|
28
|
+
const { defaultLocale: defaultLocaleConfig, locales: availableLocales } = internationalization ?? {};
|
|
29
|
+
const defaultLocale = untrack(() => props.locale ?? getLocaleInStorage() ?? props.defaultLocale ?? defaultLocaleConfig);
|
|
30
|
+
const [currentLocale, setCurrentLocale] = createWritableMemo((previousLocale) => props.locale || previousLocale || defaultLocale);
|
|
31
|
+
const setLocaleBase = (newLocale) => {
|
|
32
|
+
if (currentLocale().toString() === newLocale.toString()) return;
|
|
33
|
+
if (!availableLocales?.map(String).includes(newLocale)) {
|
|
34
|
+
console.error(`Locale ${newLocale} is not available`);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
runInTransition(() => setCurrentLocale(newLocale));
|
|
38
|
+
setLocaleInStorage(newLocale, props.isCookieEnabled);
|
|
39
|
+
};
|
|
40
|
+
const setLocale = props.setLocale ?? setLocaleBase;
|
|
41
|
+
const locale = createMemo(() => localeResolver(currentLocale()));
|
|
42
|
+
onMounted(() => {
|
|
43
|
+
setIntlayerIdentifier();
|
|
44
|
+
});
|
|
45
|
+
return createComponent(IntlayerClientContextProvider, {
|
|
20
46
|
value: {
|
|
21
|
-
locale
|
|
22
|
-
setLocale
|
|
23
|
-
variant: () =>
|
|
47
|
+
locale,
|
|
48
|
+
setLocale,
|
|
49
|
+
variant: () => props.variant
|
|
24
50
|
},
|
|
25
51
|
get children() {
|
|
26
|
-
return
|
|
52
|
+
return props.children;
|
|
27
53
|
}
|
|
28
54
|
});
|
|
29
|
-
}
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Main provider for Intlayer in Solid applications.
|
|
58
|
+
*
|
|
59
|
+
* It provides the Intlayer context to your application, allowing the use
|
|
60
|
+
* of hooks like `useIntlayer` and `useLocale`.
|
|
61
|
+
*
|
|
62
|
+
* @param props - The provider props.
|
|
63
|
+
* @returns The provider component.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```tsx
|
|
67
|
+
* import { IntlayerProvider } from 'solid-intlayer';
|
|
68
|
+
*
|
|
69
|
+
* const App = () => (
|
|
70
|
+
* <IntlayerProvider>
|
|
71
|
+
* <MyComponent />
|
|
72
|
+
* </IntlayerProvider>
|
|
73
|
+
* );
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
var IntlayerProvider = (props) => createComponent(IntlayerProviderContent, mergeProps(props, { get children() {
|
|
30
77
|
return [
|
|
31
|
-
|
|
32
|
-
return
|
|
78
|
+
memo(() => memo(() => !!(process.env.INTLAYER_EDITOR_ENABLED !== "false" && LazyEditorProvider))() && createComponent(LoadingBoundary, { get children() {
|
|
79
|
+
return createComponent(LazyEditorProvider, {});
|
|
33
80
|
} })),
|
|
34
|
-
|
|
35
|
-
return
|
|
81
|
+
memo(() => memo(() => !!(process.env.INTLAYER_ANALYTICS_ENABLED !== "false" && LazyAnalyticsProvider))() && createComponent(LoadingBoundary, { get children() {
|
|
82
|
+
return createComponent(LazyAnalyticsProvider, {});
|
|
36
83
|
} })),
|
|
37
|
-
|
|
84
|
+
memo(() => props.children)
|
|
38
85
|
];
|
|
39
86
|
} }));
|
|
40
|
-
export {
|
|
87
|
+
export { IntlayerClientContext, IntlayerProvider, IntlayerProviderContent, useIntlayerContext };
|
|
@@ -1,17 +1,31 @@
|
|
|
1
1
|
// src/client/contentProxy.ts
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Exposes reactive content through a proxy that reads `accessor` on every
|
|
4
|
+
* access, so each field read stays tracked — shared by `useDictionary`,
|
|
5
|
+
* `useIntlayer` and the dynamic collection read.
|
|
6
|
+
*
|
|
7
|
+
* Collections must behave like real arrays: Solid 2's `<For>` copies its list
|
|
8
|
+
* with `list.slice(0)`, which checks every index with `in`. Answering those
|
|
9
|
+
* checks for the function target would yield holes (`undefined` rows), so `in`
|
|
10
|
+
* is answered for the content, and inherited methods (`slice`, `map`…) run
|
|
11
|
+
* against it. Own fields are returned untouched: content nodes carry their
|
|
12
|
+
* own properties (`.value`, `.raw`) that a bound copy would lose.
|
|
13
|
+
*
|
|
14
|
+
* @param accessor - Returns the current content (a memo).
|
|
15
|
+
*/
|
|
16
|
+
var createContentProxy = (accessor) => new Proxy(accessor, {
|
|
17
|
+
get(target, property) {
|
|
18
|
+
const content = target();
|
|
19
|
+
if (content == null) return void 0;
|
|
20
|
+
const value = Reflect.get(Object(content), property);
|
|
21
|
+
return typeof value === "function" && !Object.hasOwn(content, property) ? value.bind(content) : value;
|
|
8
22
|
},
|
|
9
|
-
has(
|
|
10
|
-
|
|
11
|
-
return typeof
|
|
23
|
+
has(target, property) {
|
|
24
|
+
const content = target();
|
|
25
|
+
return content != null && typeof content === "object" && property in content;
|
|
12
26
|
},
|
|
13
|
-
apply(
|
|
14
|
-
return
|
|
27
|
+
apply(target) {
|
|
28
|
+
return target();
|
|
15
29
|
}
|
|
16
30
|
});
|
|
17
|
-
export {
|
|
31
|
+
export { createContentProxy };
|
|
@@ -1,78 +1,113 @@
|
|
|
1
|
-
import { internationalization
|
|
2
|
-
import { DEFAULT_LOCALE
|
|
3
|
-
import { localeDetector
|
|
4
|
-
import { getLocaleFromStorageClient
|
|
1
|
+
import { internationalization } from "@intlayer/config/built";
|
|
2
|
+
import { DEFAULT_LOCALE } from "@intlayer/config/defaultValues";
|
|
3
|
+
import { localeDetector } from "@intlayer/core/localization";
|
|
4
|
+
import { getLocaleFromStorageClient } from "@intlayer/core/utils";
|
|
5
5
|
// src/client/getBrowserLocale.tsx
|
|
6
|
-
var
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
6
|
+
var LanguageDetector = /* @__PURE__ */ function(LanguageDetector) {
|
|
7
|
+
LanguageDetector["Querystring"] = "querystring";
|
|
8
|
+
LanguageDetector["Storage"] = "storage";
|
|
9
|
+
LanguageDetector["Navigator"] = "navigator";
|
|
10
|
+
LanguageDetector["HtmlTag"] = "htmlTag";
|
|
11
|
+
return LanguageDetector;
|
|
12
|
+
}({});
|
|
13
|
+
var getDefaultsOptions = () => {
|
|
14
|
+
return {
|
|
15
|
+
order: [
|
|
16
|
+
"querystring",
|
|
17
|
+
"storage",
|
|
18
|
+
"navigator",
|
|
19
|
+
"htmlTag"
|
|
20
|
+
],
|
|
21
|
+
lookupQuerystring: "locale",
|
|
22
|
+
htmlTag: typeof document !== "undefined" ? document.documentElement : null
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
var detectLanguage = (order, options) => {
|
|
26
|
+
const detected = {};
|
|
27
|
+
const queryStringDetector = () => {
|
|
28
|
+
if (typeof window === "undefined") return;
|
|
29
|
+
const search = window.location.search || "";
|
|
30
|
+
const value = new URLSearchParams(search).get(options.lookupQuerystring ?? "");
|
|
31
|
+
if (value) detected["querystring"] = value;
|
|
32
|
+
};
|
|
33
|
+
const storageDetector = () => {
|
|
34
|
+
if (typeof window === "undefined") return;
|
|
35
|
+
const locale = getLocaleFromStorageClient({
|
|
36
|
+
getCookie: (name) => {
|
|
37
|
+
try {
|
|
38
|
+
const cookies = document.cookie.split(";");
|
|
39
|
+
const cookieName = `${name}=`;
|
|
40
|
+
const cookie = cookies.find((c) => c.trim().startsWith(cookieName));
|
|
41
|
+
if (cookie) return cookie.split("=")[1].trim();
|
|
42
|
+
} catch {}
|
|
43
|
+
},
|
|
44
|
+
getSessionStorage: (name) => {
|
|
45
|
+
try {
|
|
46
|
+
return window.sessionStorage.getItem(name) ?? void 0;
|
|
47
|
+
} catch {}
|
|
48
|
+
},
|
|
49
|
+
getLocaleStorage: (name) => {
|
|
50
|
+
try {
|
|
51
|
+
return window.localStorage.getItem(name) ?? void 0;
|
|
52
|
+
} catch {}
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
if (locale) detected["storage"] = locale;
|
|
56
|
+
};
|
|
57
|
+
const navigatorDetector = () => {
|
|
58
|
+
if (typeof navigator === "undefined") return;
|
|
59
|
+
const languages = navigator.languages ?? [navigator.language];
|
|
60
|
+
const locale = localeDetector({ "accept-language": languages.join(",") }, internationalization.locales, internationalization.defaultLocale);
|
|
61
|
+
if (locale) detected["navigator"] = locale;
|
|
62
|
+
};
|
|
63
|
+
const htmlTagDetector = () => {
|
|
64
|
+
const htmlTag = options.htmlTag;
|
|
65
|
+
if (htmlTag && typeof htmlTag.getAttribute === "function") {
|
|
66
|
+
const lang = htmlTag.getAttribute("lang");
|
|
67
|
+
if (lang) {
|
|
68
|
+
const locale = localeDetector({ "accept-language": lang }, internationalization.locales, internationalization.defaultLocale);
|
|
69
|
+
detected["htmlTag"] = locale;
|
|
59
70
|
}
|
|
60
71
|
}
|
|
61
72
|
};
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
73
|
+
const detectors = {
|
|
74
|
+
["querystring"]: queryStringDetector,
|
|
75
|
+
["storage"]: storageDetector,
|
|
76
|
+
["navigator"]: navigatorDetector,
|
|
77
|
+
["htmlTag"]: htmlTagDetector
|
|
78
|
+
};
|
|
79
|
+
order.forEach((detectorName) => {
|
|
80
|
+
detectors[detectorName]?.();
|
|
81
|
+
});
|
|
82
|
+
return detected;
|
|
83
|
+
};
|
|
84
|
+
var getFirstAvailableLocale = (locales, order) => {
|
|
85
|
+
for (const detector of order) {
|
|
86
|
+
const locale = locales[detector];
|
|
87
|
+
if (locale && internationalization.locales.includes(locale)) return locale;
|
|
69
88
|
}
|
|
70
|
-
return
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
89
|
+
return internationalization?.defaultLocale ?? DEFAULT_LOCALE;
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* Core language detector function for browser environments.
|
|
93
|
+
*
|
|
94
|
+
* Detects the user's preferred locale by checking multiple sources in order:
|
|
95
|
+
* 1. Query string parameter
|
|
96
|
+
* 2. Storage (cookies, localStorage, sessionStorage) - uses getLocaleFromStorage
|
|
97
|
+
* 3. Navigator languages - uses localeDetector
|
|
98
|
+
* 4. HTML lang attribute - uses localeDetector
|
|
99
|
+
*
|
|
100
|
+
* @param userOptions - Optional configuration for detection order and lookup keys
|
|
101
|
+
* @returns The detected locale or the default locale
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* const locale = getBrowserLocale({ order: [LanguageDetector.Storage, LanguageDetector.Navigator] });
|
|
105
|
+
*/
|
|
106
|
+
var getBrowserLocale = (userOptions = {}) => {
|
|
107
|
+
const options = {
|
|
108
|
+
...getDefaultsOptions(),
|
|
109
|
+
...userOptions
|
|
75
110
|
};
|
|
76
|
-
return
|
|
111
|
+
return getFirstAvailableLocale(detectLanguage(options.order ?? [], options), options.order ?? []);
|
|
77
112
|
};
|
|
78
|
-
export {
|
|
113
|
+
export { LanguageDetector, getBrowserLocale };
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { getBrowserLocale
|
|
2
|
-
import { IntlayerClientContext
|
|
3
|
-
import { t
|
|
4
|
-
import { useDictionary
|
|
5
|
-
import { useDictionaryAsync
|
|
6
|
-
import { useDictionaryDynamic
|
|
7
|
-
import { useIntlayer
|
|
8
|
-
import { useLoadDynamic
|
|
9
|
-
import { useLocale
|
|
10
|
-
import { useLocaleBase
|
|
11
|
-
import { localeCookie
|
|
12
|
-
import { usePathname
|
|
13
|
-
import { useRewriteURL
|
|
14
|
-
export {
|
|
1
|
+
import { getBrowserLocale } from "./getBrowserLocale.mjs";
|
|
2
|
+
import { IntlayerClientContext, IntlayerProvider, IntlayerProviderContent, useIntlayerContext } from "./IntlayerProvider.mjs";
|
|
3
|
+
import { t } from "./t.mjs";
|
|
4
|
+
import { useDictionary } from "./useDictionary.mjs";
|
|
5
|
+
import { useDictionaryAsync } from "./useDictionaryAsync.mjs";
|
|
6
|
+
import { useDictionaryDynamic } from "./useDictionaryDynamic.mjs";
|
|
7
|
+
import { useIntlayer } from "./useIntlayer.mjs";
|
|
8
|
+
import { useLoadDynamic } from "./useLoadDynamic.mjs";
|
|
9
|
+
import { useLocale } from "./useLocale.mjs";
|
|
10
|
+
import { useLocaleBase } from "./useLocaleBase.mjs";
|
|
11
|
+
import { localeCookie, localeInStorage, setLocaleCookie, setLocaleInStorage, useLocaleCookie, useLocaleStorage } from "./useLocaleStorage.mjs";
|
|
12
|
+
import { usePathname } from "./usePathname.mjs";
|
|
13
|
+
import { useRewriteURL } from "./useRewriteURL.mjs";
|
|
14
|
+
export { IntlayerClientContext, IntlayerProvider, IntlayerProviderContent, getBrowserLocale, localeCookie, localeInStorage, setLocaleCookie, setLocaleInStorage, t, useDictionary, useDictionaryAsync, useDictionaryDynamic, useIntlayer, useIntlayerContext, useLoadDynamic, useLocale, useLocaleBase, useLocaleCookie, useLocaleStorage, usePathname, useRewriteURL };
|