svelte-intlayer 9.1.0 → 9.1.2
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/client/intlayerContext.d.ts +12 -1
- package/dist/client/setupIntlayer.svelte.d.ts +13 -2
- package/dist/client/setupIntlayer.svelte.js +17 -1
- package/dist/client/useDictionary.d.ts +2 -2
- package/dist/client/useDictionary.js +11 -8
- package/dist/client/useDictionaryDynamic.d.ts +2 -2
- package/dist/client/useDictionaryDynamic.js +8 -2
- package/dist/client/useIntlayer.d.ts +2 -2
- package/dist/client/useIntlayer.js +9 -8
- package/dist/getDictionary.d.ts +2 -2
- package/dist/getIntlayer.d.ts +2 -2
- package/package.json +7 -7
|
@@ -1,7 +1,18 @@
|
|
|
1
|
-
import type { LocalesValues } from '@intlayer/types/module_augmentation';
|
|
1
|
+
import type { LocalesValues, ProviderVariant } from '@intlayer/types/module_augmentation';
|
|
2
2
|
export interface IntlayerContextType {
|
|
3
3
|
locale: LocalesValues;
|
|
4
4
|
setLocale: (locale: LocalesValues) => void;
|
|
5
|
+
/**
|
|
6
|
+
* Ambient variant applied to every dictionary read below the provider, the
|
|
7
|
+
* same way `locale` is. Overridden per call by an explicit selector.
|
|
8
|
+
*
|
|
9
|
+
* Accepts a name (`'school1'`), an ordered preference chain
|
|
10
|
+
* (`['school1', 'default']`), or a per-key map
|
|
11
|
+
* (`{ key1: 'school1', default: 'base' }`). A plain object is always the
|
|
12
|
+
* per-key map; nest a structured variant as `{ default: { id: 'prod_abc' } }`.
|
|
13
|
+
*/
|
|
14
|
+
variant?: ProviderVariant;
|
|
15
|
+
setVariant?: (variant: ProviderVariant | undefined) => void;
|
|
5
16
|
isCookieEnabled?: boolean;
|
|
6
17
|
}
|
|
7
18
|
export declare const setIntlayerContext: (context: IntlayerContextType) => void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { LocalesValues } from '@intlayer/types/module_augmentation';
|
|
1
|
+
import type { LocalesValues, ProviderVariant } from '@intlayer/types/module_augmentation';
|
|
2
2
|
/**
|
|
3
3
|
* Setups Intlayer in your Svelte application.
|
|
4
4
|
*
|
|
@@ -6,6 +6,13 @@ import type { LocalesValues } from '@intlayer/types/module_augmentation';
|
|
|
6
6
|
* It should be called at the root of your application (e.g., in a top-level layout).
|
|
7
7
|
*
|
|
8
8
|
* @param initialLocale - The initial locale to use.
|
|
9
|
+
* @param variant - Ambient variant applied to every dictionary read below this
|
|
10
|
+
* setup — for a dimension fixed for the whole session (tenant, school type,
|
|
11
|
+
* plan tier…) that no component should have to pass by hand. Accepts a name
|
|
12
|
+
* (`'school1'`), an ordered preference chain (`['school1', 'default']`), or a
|
|
13
|
+
* per-key map (`{ key1: 'school1', default: 'base' }`). A plain object is
|
|
14
|
+
* always the per-key map; nest a structured variant as
|
|
15
|
+
* `{ default: { id: 'prod_abc' } }`. A call-site selector always wins.
|
|
9
16
|
* @returns An object containing the reactive locale and a setter function.
|
|
10
17
|
*
|
|
11
18
|
* @example
|
|
@@ -13,10 +20,14 @@ import type { LocalesValues } from '@intlayer/types/module_augmentation';
|
|
|
13
20
|
* <script>
|
|
14
21
|
* import { setupIntlayer } from 'svelte-intlayer';
|
|
15
22
|
* const { locale } = setupIntlayer('en');
|
|
23
|
+
* // ambient variant for the whole app
|
|
24
|
+
* setupIntlayer('en', 'school1');
|
|
16
25
|
* </script>
|
|
17
26
|
* ```
|
|
18
27
|
*/
|
|
19
|
-
export declare const setupIntlayer: (initialLocale?: LocalesValues) => {
|
|
28
|
+
export declare const setupIntlayer: (initialLocale?: LocalesValues, initialVariant?: ProviderVariant) => {
|
|
20
29
|
readonly locale: any;
|
|
21
30
|
setLocale: (newLocale: LocalesValues) => void;
|
|
31
|
+
readonly variant: ProviderVariant | undefined;
|
|
32
|
+
setVariant: (newVariant: ProviderVariant | undefined) => void;
|
|
22
33
|
};
|
|
@@ -11,6 +11,13 @@ import { intlayerStore } from './intlayerStore';
|
|
|
11
11
|
* It should be called at the root of your application (e.g., in a top-level layout).
|
|
12
12
|
*
|
|
13
13
|
* @param initialLocale - The initial locale to use.
|
|
14
|
+
* @param variant - Ambient variant applied to every dictionary read below this
|
|
15
|
+
* setup — for a dimension fixed for the whole session (tenant, school type,
|
|
16
|
+
* plan tier…) that no component should have to pass by hand. Accepts a name
|
|
17
|
+
* (`'school1'`), an ordered preference chain (`['school1', 'default']`), or a
|
|
18
|
+
* per-key map (`{ key1: 'school1', default: 'base' }`). A plain object is
|
|
19
|
+
* always the per-key map; nest a structured variant as
|
|
20
|
+
* `{ default: { id: 'prod_abc' } }`. A call-site selector always wins.
|
|
14
21
|
* @returns An object containing the reactive locale and a setter function.
|
|
15
22
|
*
|
|
16
23
|
* @example
|
|
@@ -18,16 +25,19 @@ import { intlayerStore } from './intlayerStore';
|
|
|
18
25
|
* <script>
|
|
19
26
|
* import { setupIntlayer } from 'svelte-intlayer';
|
|
20
27
|
* const { locale } = setupIntlayer('en');
|
|
28
|
+
* // ambient variant for the whole app
|
|
29
|
+
* setupIntlayer('en', 'school1');
|
|
21
30
|
* </script>
|
|
22
31
|
* ```
|
|
23
32
|
*/
|
|
24
|
-
export const setupIntlayer = (initialLocale) => {
|
|
33
|
+
export const setupIntlayer = (initialLocale, initialVariant) => {
|
|
25
34
|
setIntlayerIdentifier();
|
|
26
35
|
useEditor();
|
|
27
36
|
useAnalytics();
|
|
28
37
|
// Create Reactive State (Svelte 5)
|
|
29
38
|
// We make the locale a "rune" so updates propagate
|
|
30
39
|
let locale = $state(initialLocale);
|
|
40
|
+
let variant = $state(initialVariant);
|
|
31
41
|
// Keep intlayerStore in sync so useEditor can subscribe to it
|
|
32
42
|
if (initialLocale) {
|
|
33
43
|
intlayerStore.setLocale(initialLocale);
|
|
@@ -41,6 +51,12 @@ export const setupIntlayer = (initialLocale) => {
|
|
|
41
51
|
locale = newLocale;
|
|
42
52
|
intlayerStore.setLocale(newLocale);
|
|
43
53
|
},
|
|
54
|
+
get variant() {
|
|
55
|
+
return variant;
|
|
56
|
+
},
|
|
57
|
+
setVariant: (newVariant) => {
|
|
58
|
+
variant = newVariant;
|
|
59
|
+
},
|
|
44
60
|
};
|
|
45
61
|
// Set the Context
|
|
46
62
|
setIntlayerContext(contextValue);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Dictionary, DictionarySelectorForGroup, QualifiedDictionaryGroup, ResolveQualifiedDictionaryContent } from '@intlayer/types/dictionary';
|
|
2
|
-
import type { DeclaredLocales, ExtractSelectorLocale
|
|
2
|
+
import type { DeclaredLocales, ExtractSelectorLocale } from '@intlayer/types/module_augmentation';
|
|
3
3
|
import { type Readable } from 'svelte/store';
|
|
4
4
|
import type { DeepTransformContent } from '../plugins';
|
|
5
5
|
/**
|
|
@@ -10,4 +10,4 @@ import type { DeepTransformContent } from '../plugins';
|
|
|
10
10
|
* @param localeOrSelector The target locale or selector (optional)
|
|
11
11
|
* @returns Reactive store with transformed dictionary content
|
|
12
12
|
*/
|
|
13
|
-
export declare const useDictionary: <const T extends Dictionary | QualifiedDictionaryGroup, const A extends
|
|
13
|
+
export declare const useDictionary: <const T extends Dictionary | QualifiedDictionaryGroup, const A extends DeclaredLocales | DictionarySelectorForGroup<T> = DeclaredLocales>(dictionary: T, localeOrSelector?: A) => Readable<DeepTransformContent<ResolveQualifiedDictionaryContent<T, A>, ExtractSelectorLocale<A>>>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { resolveDictionaryArgument } from '@intlayer/core/dictionaryManipulator';
|
|
1
2
|
import { derived } from 'svelte/store';
|
|
2
3
|
import { getDictionary } from '../getDictionary';
|
|
3
4
|
import { getIntlayerContext } from './intlayerContext';
|
|
@@ -12,17 +13,19 @@ import { intlayerStore } from './intlayerStore';
|
|
|
12
13
|
*/
|
|
13
14
|
export const useDictionary = (dictionary, localeOrSelector) => {
|
|
14
15
|
const context = getIntlayerContext();
|
|
15
|
-
const isSelector = process.env.INTLAYER_DICTIONARY_SELECTOR !== 'false' &&
|
|
16
|
-
typeof localeOrSelector === 'object' &&
|
|
17
|
-
localeOrSelector !== null;
|
|
18
16
|
// Create a derived store that reactively updates when locale changes
|
|
19
17
|
return derived([intlayerStore], ([$store]) => {
|
|
20
18
|
const contextLocale = context?.locale ?? $store.locale;
|
|
21
|
-
if (
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
if (process.env.INTLAYER_DICTIONARY_SELECTOR !== 'false') {
|
|
20
|
+
// Layers the provider's locale and variant under the call-site argument.
|
|
21
|
+
// This is also the seam the build-time optimize transform lands on, which
|
|
22
|
+
// rewrites `useIntlayer('key', selector)` into `useDictionary(dict, …)`.
|
|
23
|
+
return getDictionary(dictionary, resolveDictionaryArgument({
|
|
24
|
+
localeOrSelector,
|
|
25
|
+
contextLocale,
|
|
26
|
+
contextVariant: context?.variant,
|
|
27
|
+
dictionaryKey: dictionary.key,
|
|
28
|
+
}));
|
|
26
29
|
}
|
|
27
30
|
return getDictionary(dictionary, (localeOrSelector ?? contextLocale));
|
|
28
31
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type QualifiedDynamicLoaderMap } from '@intlayer/core/dictionaryManipulator';
|
|
2
2
|
import type { Dictionary } from '@intlayer/types/dictionary';
|
|
3
|
-
import type { DictionaryKeys, DictionarySelectorForKey,
|
|
3
|
+
import type { DeclaredLocales, DictionaryKeys, DictionarySelectorForKey, StrictModeLocaleMap } from '@intlayer/types/module_augmentation';
|
|
4
4
|
import { type Readable } from 'svelte/store';
|
|
5
5
|
import type { DeepTransformContent } from '../plugins';
|
|
6
6
|
/**
|
|
@@ -15,7 +15,7 @@ import type { DeepTransformContent } from '../plugins';
|
|
|
15
15
|
* @param localeOrSelector - Optional fixed locale or selector.
|
|
16
16
|
* @returns Readable store with the loaded dictionary content.
|
|
17
17
|
*/
|
|
18
|
-
export declare function useDictionaryDynamic<const T extends Dictionary, const K extends DictionaryKeys, const A extends
|
|
18
|
+
export declare function useDictionaryDynamic<const T extends Dictionary, const K extends DictionaryKeys, const A extends DeclaredLocales | DictionarySelectorForKey<K> = DeclaredLocales>(dictionaryPromise: StrictModeLocaleMap<() => Promise<T>> | QualifiedDynamicLoaderMap, key: K, localeOrSelector?: A): Readable<DeepTransformContent<T['content']> & {
|
|
19
19
|
isLoading: boolean;
|
|
20
20
|
error: Error | null;
|
|
21
21
|
}>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isQualifiedDynamicLoaderMap, resolveQualifiedDynamicContentAsync, } from '@intlayer/core/dictionaryManipulator';
|
|
1
|
+
import { isQualifiedDynamicLoaderMap, resolveProviderVariant, resolveQualifiedDynamicContentAsync, } from '@intlayer/core/dictionaryManipulator';
|
|
2
2
|
import { derived } from 'svelte/store';
|
|
3
3
|
import { getDictionary } from '../getDictionary';
|
|
4
4
|
import { getIntlayerContext } from './intlayerContext';
|
|
@@ -57,9 +57,15 @@ export function useDictionaryDynamic(dictionaryPromise, key, localeOrSelector) {
|
|
|
57
57
|
const isSelector = process.env.INTLAYER_DICTIONARY_SELECTOR !== 'false' &&
|
|
58
58
|
typeof localeOrSelector === 'object' &&
|
|
59
59
|
localeOrSelector !== null;
|
|
60
|
-
const
|
|
60
|
+
const callSelector = isSelector
|
|
61
61
|
? localeOrSelector
|
|
62
62
|
: undefined;
|
|
63
|
+
// Layers the provider's ambient variant under the call-site selector, so only
|
|
64
|
+
// the targeted chunk is loaded. A call-site variant always wins.
|
|
65
|
+
const variant = callSelector?.variant ?? resolveProviderVariant(context?.variant, key);
|
|
66
|
+
const selector = variant !== undefined
|
|
67
|
+
? { ...callSelector, variant }
|
|
68
|
+
: callSelector;
|
|
63
69
|
const explicitLocale = isSelector
|
|
64
70
|
? localeOrSelector.locale
|
|
65
71
|
: localeOrSelector;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DeclaredLocales, DictionaryKeys, DictionaryRegistryResult, DictionarySelectorForKey, ExtractSelectorLocale
|
|
1
|
+
import type { DeclaredLocales, DictionaryKeys, DictionaryRegistryResult, DictionarySelectorForKey, ExtractSelectorLocale } from '@intlayer/types/module_augmentation';
|
|
2
2
|
import { type Readable } from 'svelte/store';
|
|
3
3
|
import type { DeepTransformContent } from '../plugins';
|
|
4
4
|
/**
|
|
@@ -26,4 +26,4 @@ import type { DeepTransformContent } from '../plugins';
|
|
|
26
26
|
* <div>{$content.myField.value}</div>
|
|
27
27
|
* ```
|
|
28
28
|
*/
|
|
29
|
-
export declare const useIntlayer: <const T extends DictionaryKeys, const A extends
|
|
29
|
+
export declare const useIntlayer: <const T extends DictionaryKeys, const A extends DeclaredLocales | DictionarySelectorForKey<T> = DeclaredLocales>(key: T, localeOrSelector?: A) => Readable<DeepTransformContent<DictionaryRegistryResult<T, A>, ExtractSelectorLocale<A>>>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { resolveDictionaryArgument } from '@intlayer/core/dictionaryManipulator';
|
|
1
2
|
import { derived } from 'svelte/store';
|
|
2
3
|
import { getIntlayer } from '../getIntlayer';
|
|
3
4
|
import { getIntlayerContext } from './intlayerContext';
|
|
@@ -29,17 +30,17 @@ import { intlayerStore } from './intlayerStore';
|
|
|
29
30
|
*/
|
|
30
31
|
export const useIntlayer = (key, localeOrSelector) => {
|
|
31
32
|
const context = getIntlayerContext();
|
|
32
|
-
const isSelector = process.env.INTLAYER_DICTIONARY_SELECTOR !== 'false' &&
|
|
33
|
-
typeof localeOrSelector === 'object' &&
|
|
34
|
-
localeOrSelector !== null;
|
|
35
33
|
// Create a derived store that reactively updates when locale changes
|
|
36
34
|
return derived([intlayerStore], ([$store]) => {
|
|
37
35
|
const contextLocale = context?.locale ?? $store.locale;
|
|
38
|
-
if (
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
36
|
+
if (process.env.INTLAYER_DICTIONARY_SELECTOR !== 'false') {
|
|
37
|
+
// Layers the provider's locale and variant under the call-site argument.
|
|
38
|
+
return getIntlayer(key, resolveDictionaryArgument({
|
|
39
|
+
localeOrSelector,
|
|
40
|
+
contextLocale,
|
|
41
|
+
contextVariant: context?.variant,
|
|
42
|
+
dictionaryKey: key,
|
|
43
|
+
}));
|
|
43
44
|
}
|
|
44
45
|
return getIntlayer(key, (localeOrSelector ?? contextLocale));
|
|
45
46
|
});
|
package/dist/getDictionary.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Dictionary, DictionarySelectorForGroup, QualifiedDictionaryGroup, ResolveQualifiedDictionaryContent } from '@intlayer/types/dictionary';
|
|
2
|
-
import type { DeclaredLocales, ExtractSelectorLocale
|
|
2
|
+
import type { DeclaredLocales, ExtractSelectorLocale } from '@intlayer/types/module_augmentation';
|
|
3
3
|
import { type DeepTransformContent } from './plugins';
|
|
4
4
|
/**
|
|
5
5
|
* Get content for a dictionary (or qualified dictionary group) in Svelte
|
|
@@ -10,4 +10,4 @@ import { type DeepTransformContent } from './plugins';
|
|
|
10
10
|
* @param localeOrSelector The target locale or selector (optional)
|
|
11
11
|
* @returns Transformed dictionary content optimized for Svelte
|
|
12
12
|
*/
|
|
13
|
-
export declare const getDictionary: <const T extends Dictionary | QualifiedDictionaryGroup, const A extends
|
|
13
|
+
export declare const getDictionary: <const T extends Dictionary | QualifiedDictionaryGroup, const A extends DeclaredLocales | DictionarySelectorForGroup<T> = DeclaredLocales>(dictionary: T, localeOrSelector?: A) => DeepTransformContent<ResolveQualifiedDictionaryContent<T, A>, ExtractSelectorLocale<A>>;
|
package/dist/getIntlayer.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DeclaredLocales, DictionaryKeys, DictionaryRegistryResult, DictionarySelectorForKey, ExtractSelectorLocale
|
|
1
|
+
import type { DeclaredLocales, DictionaryKeys, DictionaryRegistryResult, DictionarySelectorForKey, ExtractSelectorLocale } from '@intlayer/types/module_augmentation';
|
|
2
2
|
import { type DeepTransformContent } from './plugins';
|
|
3
3
|
/**
|
|
4
4
|
* Get dictionary content by key for Svelte applications.
|
|
@@ -10,4 +10,4 @@ import { type DeepTransformContent } from './plugins';
|
|
|
10
10
|
* @param localeOrSelector The target locale or selector (optional)
|
|
11
11
|
* @returns Transformed dictionary content optimized for Svelte
|
|
12
12
|
*/
|
|
13
|
-
export declare const getIntlayer: <const T extends DictionaryKeys, const A extends
|
|
13
|
+
export declare const getIntlayer: <const T extends DictionaryKeys, const A extends DeclaredLocales | DictionarySelectorForKey<T> = DeclaredLocales>(key: T, localeOrSelector?: A) => DeepTransformContent<DictionaryRegistryResult<T, A>, ExtractSelectorLocale<A>>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "svelte-intlayer",
|
|
3
|
-
"version": "9.1.
|
|
3
|
+
"version": "9.1.2",
|
|
4
4
|
"description": "Easily internationalize i18n your Svelte applications with type-safe multilingual content management.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"intlayer",
|
|
@@ -82,11 +82,11 @@
|
|
|
82
82
|
"typecheck": "tsc --noEmit --project tsconfig.types.json"
|
|
83
83
|
},
|
|
84
84
|
"dependencies": {
|
|
85
|
-
"@intlayer/api": "9.1.
|
|
86
|
-
"@intlayer/config": "9.1.
|
|
87
|
-
"@intlayer/core": "9.1.
|
|
88
|
-
"@intlayer/editor": "9.1.
|
|
89
|
-
"@intlayer/types": "9.1.
|
|
85
|
+
"@intlayer/api": "9.1.2",
|
|
86
|
+
"@intlayer/config": "9.1.2",
|
|
87
|
+
"@intlayer/core": "9.1.2",
|
|
88
|
+
"@intlayer/editor": "9.1.2",
|
|
89
|
+
"@intlayer/types": "9.1.2"
|
|
90
90
|
},
|
|
91
91
|
"devDependencies": {
|
|
92
92
|
"@sveltejs/adapter-auto": "7.0.1",
|
|
@@ -108,7 +108,7 @@
|
|
|
108
108
|
"svelte": ">=5.0.0"
|
|
109
109
|
},
|
|
110
110
|
"optionalDependencies": {
|
|
111
|
-
"@intlayer/analytics": "9.1.
|
|
111
|
+
"@intlayer/analytics": "9.1.2"
|
|
112
112
|
},
|
|
113
113
|
"engines": {
|
|
114
114
|
"node": ">=14.18"
|