svelte-intlayer 8.12.4 → 9.0.0-canary.0
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/useDictionary.d.ts +8 -6
- package/dist/client/useDictionary.js +15 -6
- package/dist/client/useDictionaryDynamic.d.ts +12 -7
- package/dist/client/useDictionaryDynamic.js +59 -39
- package/dist/client/useIntlayer.d.ts +10 -3
- package/dist/client/useIntlayer.js +18 -4
- package/dist/client/useLocaleStorage.d.ts +2 -2
- package/dist/format/useCompact.d.ts +1 -1
- package/dist/format/useCurrency.d.ts +1 -1
- package/dist/format/useDate.d.ts +1 -1
- package/dist/format/useList.d.ts +1 -1
- package/dist/format/useNumber.d.ts +1 -1
- package/dist/format/usePercentage.d.ts +1 -1
- package/dist/format/useRelativeTime.d.ts +1 -1
- package/dist/format/useUnit.d.ts +1 -1
- package/dist/getDictionary.d.ts +9 -6
- package/dist/getDictionary.js +12 -4
- package/dist/getIntlayer.d.ts +8 -4
- package/dist/getIntlayer.js +12 -3
- package/dist/markdown/MarkdownRenderer.svelte +1 -2
- package/dist/markdown/MarkdownWithSelector.svelte +1 -2
- package/package.json +7 -7
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import type { Dictionary } from '@intlayer/types/dictionary';
|
|
2
|
-
import type { LocalesValues } from '@intlayer/types/module_augmentation';
|
|
1
|
+
import type { Dictionary, DictionarySelectorForGroup, QualifiedDictionaryGroup, ResolveQualifiedDictionaryContent } from '@intlayer/types/dictionary';
|
|
2
|
+
import type { DeclaredLocales, ExtractSelectorLocale, LocalesValues } from '@intlayer/types/module_augmentation';
|
|
3
3
|
import { type Readable } from 'svelte/store';
|
|
4
4
|
import type { DeepTransformContent } from '../plugins';
|
|
5
5
|
/**
|
|
6
|
-
* Svelte hook that transforms a dictionary
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* Svelte hook that transforms a dictionary (or qualified dictionary group) and
|
|
7
|
+
* returns reactive content.
|
|
8
|
+
*
|
|
9
|
+
* @param dictionary The dictionary (or qualified group) to transform
|
|
10
|
+
* @param localeOrSelector The target locale or selector (optional)
|
|
9
11
|
* @returns Reactive store with transformed dictionary content
|
|
10
12
|
*/
|
|
11
|
-
export declare const useDictionary: <const T extends Dictionary>(dictionary: T,
|
|
13
|
+
export declare const useDictionary: <const T extends Dictionary | QualifiedDictionaryGroup, const A extends LocalesValues | DictionarySelectorForGroup<T> = DeclaredLocales>(dictionary: T, localeOrSelector?: A) => Readable<DeepTransformContent<ResolveQualifiedDictionaryContent<T, A>, ExtractSelectorLocale<A>>>;
|
|
@@ -3,16 +3,25 @@ import { getDictionary } from '../getDictionary';
|
|
|
3
3
|
import { getIntlayerContext } from './intlayerContext';
|
|
4
4
|
import { intlayerStore } from './intlayerStore';
|
|
5
5
|
/**
|
|
6
|
-
* Svelte hook that transforms a dictionary
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* Svelte hook that transforms a dictionary (or qualified dictionary group) and
|
|
7
|
+
* returns reactive content.
|
|
8
|
+
*
|
|
9
|
+
* @param dictionary The dictionary (or qualified group) to transform
|
|
10
|
+
* @param localeOrSelector The target locale or selector (optional)
|
|
9
11
|
* @returns Reactive store with transformed dictionary content
|
|
10
12
|
*/
|
|
11
|
-
export const useDictionary = (dictionary,
|
|
13
|
+
export const useDictionary = (dictionary, localeOrSelector) => {
|
|
12
14
|
const context = getIntlayerContext();
|
|
15
|
+
const isSelector = typeof localeOrSelector === 'object' && localeOrSelector !== null;
|
|
13
16
|
// Create a derived store that reactively updates when locale changes
|
|
14
17
|
return derived([intlayerStore], ([$store]) => {
|
|
15
|
-
const
|
|
16
|
-
|
|
18
|
+
const contextLocale = context?.locale ?? $store.locale;
|
|
19
|
+
if (isSelector) {
|
|
20
|
+
return getDictionary(dictionary, {
|
|
21
|
+
...localeOrSelector,
|
|
22
|
+
locale: localeOrSelector.locale ?? contextLocale,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
return getDictionary(dictionary, (localeOrSelector ?? contextLocale));
|
|
17
26
|
});
|
|
18
27
|
};
|
|
@@ -1,16 +1,21 @@
|
|
|
1
|
+
import { type QualifiedDynamicLoaderMap } from '@intlayer/core/dictionaryManipulator';
|
|
1
2
|
import type { Dictionary } from '@intlayer/types/dictionary';
|
|
2
|
-
import type { DictionaryKeys, LocalesValues, StrictModeLocaleMap } from '@intlayer/types/module_augmentation';
|
|
3
|
+
import type { DictionaryKeys, DictionarySelectorForKey, LocalesValues, StrictModeLocaleMap } from '@intlayer/types/module_augmentation';
|
|
3
4
|
import { type Readable } from 'svelte/store';
|
|
4
5
|
import type { DeepTransformContent } from '../plugins';
|
|
5
6
|
/**
|
|
6
|
-
* Svelte hook for dynamic dictionary loading
|
|
7
|
-
* Loads dictionary content asynchronously and returns a reactive store.
|
|
7
|
+
* Svelte hook for dynamic dictionary loading.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
9
|
+
* For a qualified loader map (collection / variant / meta record, possibly
|
|
10
|
+
* combined), only the chunk(s) the selector targets are loaded. For a plain
|
|
11
|
+
* loader map, the locale chunk is loaded.
|
|
12
|
+
*
|
|
13
|
+
* @param dictionaryPromise - Locale-keyed loader map, or a qualified loader map.
|
|
14
|
+
* @param key - The dictionary key (used for cache namespacing).
|
|
15
|
+
* @param localeOrSelector - Optional fixed locale or selector.
|
|
16
|
+
* @returns Readable store with the loaded dictionary content.
|
|
12
17
|
*/
|
|
13
|
-
export declare function useDictionaryDynamic<const T extends Dictionary>(dictionaryPromise: StrictModeLocaleMap<() => Promise<T
|
|
18
|
+
export declare function useDictionaryDynamic<const T extends Dictionary, const K extends DictionaryKeys, const A extends LocalesValues | DictionarySelectorForKey<K> = LocalesValues>(dictionaryPromise: StrictModeLocaleMap<() => Promise<T>> | QualifiedDynamicLoaderMap, key: K, localeOrSelector?: A): Readable<DeepTransformContent<T['content']> & {
|
|
14
19
|
isLoading: boolean;
|
|
15
20
|
error: Error | null;
|
|
16
21
|
}>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isQualifiedDynamicLoaderMap, resolveQualifiedDynamicContentAsync, } from '@intlayer/core/dictionaryManipulator';
|
|
1
2
|
import { derived } from 'svelte/store';
|
|
2
3
|
import { getDictionary } from '../getDictionary';
|
|
3
4
|
import { getIntlayerContext } from './intlayerContext';
|
|
@@ -18,48 +19,75 @@ const recursiveProxy = new Proxy(() => { }, {
|
|
|
18
19
|
},
|
|
19
20
|
apply: () => recursiveProxy,
|
|
20
21
|
});
|
|
22
|
+
const loadingProxy = () => new Proxy({ isLoading: true, error: null }, {
|
|
23
|
+
get: (_target, prop) => {
|
|
24
|
+
if (prop === 'isLoading')
|
|
25
|
+
return true;
|
|
26
|
+
if (prop === 'error')
|
|
27
|
+
return null;
|
|
28
|
+
// For any other property, return the recursive proxy
|
|
29
|
+
// to allow nested access without errors
|
|
30
|
+
return recursiveProxy;
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
/** Merges the resolved content with the loading/error state. */
|
|
34
|
+
const withState = (value) => {
|
|
35
|
+
if (Array.isArray(value)) {
|
|
36
|
+
return Object.assign(value.slice(), { isLoading: false, error: null });
|
|
37
|
+
}
|
|
38
|
+
if (value && typeof value === 'object') {
|
|
39
|
+
return { ...value, isLoading: false, error: null };
|
|
40
|
+
}
|
|
41
|
+
return { isLoading: false, error: null };
|
|
42
|
+
};
|
|
21
43
|
/**
|
|
22
|
-
* Svelte hook for dynamic dictionary loading
|
|
23
|
-
*
|
|
44
|
+
* Svelte hook for dynamic dictionary loading.
|
|
45
|
+
*
|
|
46
|
+
* For a qualified loader map (collection / variant / meta record, possibly
|
|
47
|
+
* combined), only the chunk(s) the selector targets are loaded. For a plain
|
|
48
|
+
* loader map, the locale chunk is loaded.
|
|
24
49
|
*
|
|
25
|
-
* @param dictionaryPromise -
|
|
26
|
-
* @param
|
|
27
|
-
* @
|
|
50
|
+
* @param dictionaryPromise - Locale-keyed loader map, or a qualified loader map.
|
|
51
|
+
* @param key - The dictionary key (used for cache namespacing).
|
|
52
|
+
* @param localeOrSelector - Optional fixed locale or selector.
|
|
53
|
+
* @returns Readable store with the loaded dictionary content.
|
|
28
54
|
*/
|
|
29
|
-
export function useDictionaryDynamic(dictionaryPromise,
|
|
55
|
+
export function useDictionaryDynamic(dictionaryPromise, key, localeOrSelector) {
|
|
30
56
|
const context = getIntlayerContext();
|
|
31
|
-
const
|
|
57
|
+
const isSelector = typeof localeOrSelector === 'object' && localeOrSelector !== null;
|
|
58
|
+
const selector = isSelector
|
|
59
|
+
? localeOrSelector
|
|
60
|
+
: undefined;
|
|
61
|
+
const explicitLocale = isSelector
|
|
62
|
+
? localeOrSelector.locale
|
|
63
|
+
: localeOrSelector;
|
|
64
|
+
const localeStore = derived(intlayerStore, ($store) => explicitLocale ?? context?.locale ?? $store.locale);
|
|
32
65
|
return derived(localeStore, ($locale, set) => {
|
|
33
66
|
// Set loading state immediately with proxy
|
|
34
|
-
set(
|
|
35
|
-
get: (_target, prop) => {
|
|
36
|
-
if (prop === 'isLoading')
|
|
37
|
-
return true;
|
|
38
|
-
if (prop === 'error')
|
|
39
|
-
return null;
|
|
40
|
-
// For any other property, return the recursive proxy
|
|
41
|
-
// to allow nested access without errors
|
|
42
|
-
return recursiveProxy;
|
|
43
|
-
},
|
|
44
|
-
}));
|
|
67
|
+
set(loadingProxy());
|
|
45
68
|
let isCancelled = false;
|
|
46
69
|
const load = async () => {
|
|
47
70
|
try {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
71
|
+
let resolved;
|
|
72
|
+
if (isQualifiedDynamicLoaderMap(dictionaryPromise)) {
|
|
73
|
+
resolved = await resolveQualifiedDynamicContentAsync({
|
|
74
|
+
loaderMap: dictionaryPromise,
|
|
75
|
+
key: String(key),
|
|
76
|
+
locale: $locale,
|
|
77
|
+
selector,
|
|
78
|
+
transform: (dictionary) => getDictionary(dictionary, $locale),
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
const loader = dictionaryPromise[$locale];
|
|
83
|
+
if (!loader)
|
|
84
|
+
return;
|
|
85
|
+
const dict = await loader();
|
|
86
|
+
resolved = getDictionary(dict, $locale);
|
|
53
87
|
}
|
|
54
|
-
const dict = await loader();
|
|
55
88
|
if (isCancelled)
|
|
56
89
|
return;
|
|
57
|
-
|
|
58
|
-
set({
|
|
59
|
-
...content,
|
|
60
|
-
isLoading: false,
|
|
61
|
-
error: null,
|
|
62
|
-
});
|
|
90
|
+
set(withState(resolved));
|
|
63
91
|
}
|
|
64
92
|
catch (error) {
|
|
65
93
|
if (isCancelled)
|
|
@@ -77,13 +105,5 @@ export function useDictionaryDynamic(dictionaryPromise, _key, locale) {
|
|
|
77
105
|
};
|
|
78
106
|
},
|
|
79
107
|
// Initial value
|
|
80
|
-
|
|
81
|
-
get: (_target, prop) => {
|
|
82
|
-
if (prop === 'isLoading')
|
|
83
|
-
return true;
|
|
84
|
-
if (prop === 'error')
|
|
85
|
-
return null;
|
|
86
|
-
return recursiveProxy;
|
|
87
|
-
},
|
|
88
|
-
}));
|
|
108
|
+
loadingProxy());
|
|
89
109
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DictionaryKeys,
|
|
1
|
+
import type { DeclaredLocales, DictionaryKeys, DictionaryRegistryResult, DictionarySelectorForKey, ExtractSelectorLocale, LocalesValues } from '@intlayer/types/module_augmentation';
|
|
2
2
|
import { type Readable } from 'svelte/store';
|
|
3
3
|
import type { DeepTransformContent } from '../plugins';
|
|
4
4
|
/**
|
|
@@ -6,8 +6,14 @@ import type { DeepTransformContent } from '../plugins';
|
|
|
6
6
|
*
|
|
7
7
|
* It returns a readable store that reactively updates whenever the locale changes.
|
|
8
8
|
*
|
|
9
|
+
* The second argument is either a locale or a selector object:
|
|
10
|
+
* - `{ item: 2 }` — collection item (omit `item` to get every item as array)
|
|
11
|
+
* - `{ variant: 'black-friday' }` — named variant (omit for the `default` one)
|
|
12
|
+
* - `{ id: 'prod_abc', ...metaFields }` — meta record
|
|
13
|
+
* - `locale` composes with any selector and overrides the context locale
|
|
14
|
+
*
|
|
9
15
|
* @param key - The unique key of the dictionary to retrieve.
|
|
10
|
-
* @param
|
|
16
|
+
* @param localeOrSelector - Optional locale or selector.
|
|
11
17
|
* @returns A readable store with the transformed dictionary content.
|
|
12
18
|
*
|
|
13
19
|
* @example
|
|
@@ -15,9 +21,10 @@ import type { DeepTransformContent } from '../plugins';
|
|
|
15
21
|
* <script>
|
|
16
22
|
* import { useIntlayer } from 'svelte-intlayer';
|
|
17
23
|
* const content = useIntlayer('my-dictionary-key');
|
|
24
|
+
* const faq2 = useIntlayer('faq', { item: 2 });
|
|
18
25
|
* </script>
|
|
19
26
|
*
|
|
20
27
|
* <div>{$content.myField.value}</div>
|
|
21
28
|
* ```
|
|
22
29
|
*/
|
|
23
|
-
export declare const useIntlayer: <const T extends DictionaryKeys>(key: T,
|
|
30
|
+
export declare const useIntlayer: <const T extends DictionaryKeys, const A extends LocalesValues | DictionarySelectorForKey<T> = DeclaredLocales>(key: T, localeOrSelector?: A) => Readable<DeepTransformContent<DictionaryRegistryResult<T, A>, ExtractSelectorLocale<A>>>;
|
|
@@ -7,8 +7,14 @@ import { intlayerStore } from './intlayerStore';
|
|
|
7
7
|
*
|
|
8
8
|
* It returns a readable store that reactively updates whenever the locale changes.
|
|
9
9
|
*
|
|
10
|
+
* The second argument is either a locale or a selector object:
|
|
11
|
+
* - `{ item: 2 }` — collection item (omit `item` to get every item as array)
|
|
12
|
+
* - `{ variant: 'black-friday' }` — named variant (omit for the `default` one)
|
|
13
|
+
* - `{ id: 'prod_abc', ...metaFields }` — meta record
|
|
14
|
+
* - `locale` composes with any selector and overrides the context locale
|
|
15
|
+
*
|
|
10
16
|
* @param key - The unique key of the dictionary to retrieve.
|
|
11
|
-
* @param
|
|
17
|
+
* @param localeOrSelector - Optional locale or selector.
|
|
12
18
|
* @returns A readable store with the transformed dictionary content.
|
|
13
19
|
*
|
|
14
20
|
* @example
|
|
@@ -16,16 +22,24 @@ import { intlayerStore } from './intlayerStore';
|
|
|
16
22
|
* <script>
|
|
17
23
|
* import { useIntlayer } from 'svelte-intlayer';
|
|
18
24
|
* const content = useIntlayer('my-dictionary-key');
|
|
25
|
+
* const faq2 = useIntlayer('faq', { item: 2 });
|
|
19
26
|
* </script>
|
|
20
27
|
*
|
|
21
28
|
* <div>{$content.myField.value}</div>
|
|
22
29
|
* ```
|
|
23
30
|
*/
|
|
24
|
-
export const useIntlayer = (key,
|
|
31
|
+
export const useIntlayer = (key, localeOrSelector) => {
|
|
25
32
|
const context = getIntlayerContext();
|
|
33
|
+
const isSelector = typeof localeOrSelector === 'object' && localeOrSelector !== null;
|
|
26
34
|
// Create a derived store that reactively updates when locale changes
|
|
27
35
|
return derived([intlayerStore], ([$store]) => {
|
|
28
|
-
const
|
|
29
|
-
|
|
36
|
+
const contextLocale = context?.locale ?? $store.locale;
|
|
37
|
+
if (isSelector) {
|
|
38
|
+
return getIntlayer(key, {
|
|
39
|
+
...localeOrSelector,
|
|
40
|
+
locale: localeOrSelector.locale ?? contextLocale,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
return getIntlayer(key, (localeOrSelector ?? contextLocale));
|
|
30
44
|
});
|
|
31
45
|
};
|
|
@@ -2,13 +2,13 @@ import type { LocalesValues } from '@intlayer/types/module_augmentation';
|
|
|
2
2
|
/**
|
|
3
3
|
* Get the locale cookie
|
|
4
4
|
*/
|
|
5
|
-
export declare const localeInStorage: import("
|
|
5
|
+
export declare const localeInStorage: import("intlayer").Locale | undefined;
|
|
6
6
|
/**
|
|
7
7
|
* @deprecated Use localeInStorage instead
|
|
8
8
|
*
|
|
9
9
|
* Get the locale cookie
|
|
10
10
|
*/
|
|
11
|
-
export declare const localeCookie: import("
|
|
11
|
+
export declare const localeCookie: import("intlayer").Locale | undefined;
|
|
12
12
|
/**
|
|
13
13
|
* Set the locale cookie
|
|
14
14
|
*/
|
package/dist/format/useDate.d.ts
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* A store containing a date/time formatting function bound to the active locale.
|
|
6
6
|
*/
|
|
7
7
|
export declare const useDate: () => import("svelte/store").Readable<(date: string | number | Date, options?: import("@intlayer/core/formatters").DateTimePreset | (Intl.DateTimeFormatOptions & {
|
|
8
|
-
locale?: import("
|
|
8
|
+
locale?: import("intlayer").LocalesValues;
|
|
9
9
|
}) | undefined) => string>;
|
package/dist/format/useList.d.ts
CHANGED
|
@@ -3,5 +3,5 @@ export declare const useList: () => import("svelte/store").Readable<(values: (st
|
|
|
3
3
|
type?: "conjunction" | "disjunction" | "unit";
|
|
4
4
|
style?: "long" | "short" | "narrow";
|
|
5
5
|
} & {
|
|
6
|
-
locale?: import("
|
|
6
|
+
locale?: import("intlayer").LocalesValues;
|
|
7
7
|
}) | undefined) => string>;
|
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* A store containing a number formatting function bound to the active locale.
|
|
6
6
|
*/
|
|
7
7
|
export declare const useNumber: () => import("svelte/store").Readable<(value: string | number, args_1?: (Intl.NumberFormatOptions & {
|
|
8
|
-
locale?: import("
|
|
8
|
+
locale?: import("intlayer").LocalesValues;
|
|
9
9
|
}) | undefined) => string>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export declare const useRelativeTime: () => import("svelte/store").Readable<(from: string | number | Date, to?: string | number | Date | undefined, options?: (Intl.RelativeTimeFormatOptions & {
|
|
2
|
-
locale?: import("
|
|
2
|
+
locale?: import("intlayer").LocalesValues;
|
|
3
3
|
unit?: Intl.RelativeTimeFormatUnit;
|
|
4
4
|
}) | undefined) => string>;
|
package/dist/format/useUnit.d.ts
CHANGED
package/dist/getDictionary.d.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import type { Dictionary } from '@intlayer/types/dictionary';
|
|
2
|
-
import type { DeclaredLocales, LocalesValues } from '@intlayer/types/module_augmentation';
|
|
1
|
+
import type { Dictionary, DictionarySelectorForGroup, QualifiedDictionaryGroup, ResolveQualifiedDictionaryContent } from '@intlayer/types/dictionary';
|
|
2
|
+
import type { DeclaredLocales, ExtractSelectorLocale, LocalesValues } from '@intlayer/types/module_augmentation';
|
|
3
3
|
import { type DeepTransformContent } from './plugins';
|
|
4
4
|
/**
|
|
5
|
-
* Get
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* Get content for a dictionary (or qualified dictionary group) in Svelte
|
|
6
|
+
* applications, for the given locale or selector (`{ item }`, `{ variant }`,
|
|
7
|
+
* `{ id, ...meta }`, optionally combined with `locale`).
|
|
8
|
+
*
|
|
9
|
+
* @param dictionary The dictionary (or qualified group) to transform
|
|
10
|
+
* @param localeOrSelector The target locale or selector (optional)
|
|
8
11
|
* @returns Transformed dictionary content optimized for Svelte
|
|
9
12
|
*/
|
|
10
|
-
export declare const getDictionary: <const T extends Dictionary, const
|
|
13
|
+
export declare const getDictionary: <const T extends Dictionary | QualifiedDictionaryGroup, const A extends LocalesValues | DictionarySelectorForGroup<T> = DeclaredLocales>(dictionary: T, localeOrSelector?: A) => DeepTransformContent<ResolveQualifiedDictionaryContent<T, A>, ExtractSelectorLocale<A>>;
|
package/dist/getDictionary.js
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
import { getDictionary as getDictionaryCore } from '@intlayer/core/interpreter';
|
|
2
2
|
import { getPlugins } from './plugins';
|
|
3
3
|
/**
|
|
4
|
-
* Get
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* Get content for a dictionary (or qualified dictionary group) in Svelte
|
|
5
|
+
* applications, for the given locale or selector (`{ item }`, `{ variant }`,
|
|
6
|
+
* `{ id, ...meta }`, optionally combined with `locale`).
|
|
7
|
+
*
|
|
8
|
+
* @param dictionary The dictionary (or qualified group) to transform
|
|
9
|
+
* @param localeOrSelector The target locale or selector (optional)
|
|
7
10
|
* @returns Transformed dictionary content optimized for Svelte
|
|
8
11
|
*/
|
|
9
|
-
export const getDictionary = (dictionary,
|
|
12
|
+
export const getDictionary = (dictionary, localeOrSelector) => {
|
|
13
|
+
const locale = (typeof localeOrSelector === 'object' && localeOrSelector !== null
|
|
14
|
+
? localeOrSelector.locale
|
|
15
|
+
: localeOrSelector);
|
|
16
|
+
return getDictionaryCore(dictionary, localeOrSelector, getPlugins(locale));
|
|
17
|
+
};
|
package/dist/getIntlayer.d.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import type { DeclaredLocales, DictionaryKeys,
|
|
1
|
+
import type { DeclaredLocales, DictionaryKeys, DictionaryRegistryResult, DictionarySelectorForKey, ExtractSelectorLocale, LocalesValues } from '@intlayer/types/module_augmentation';
|
|
2
2
|
import { type DeepTransformContent } from './plugins';
|
|
3
3
|
/**
|
|
4
|
-
* Get dictionary content by key for Svelte applications
|
|
4
|
+
* Get dictionary content by key for Svelte applications.
|
|
5
|
+
*
|
|
6
|
+
* The second argument is either a locale or a selector object (`{ item }`,
|
|
7
|
+
* `{ variant }`, `{ id, ...meta }`, optionally combined with `locale`).
|
|
8
|
+
*
|
|
5
9
|
* @param key The dictionary key to retrieve
|
|
6
|
-
* @param
|
|
10
|
+
* @param localeOrSelector The target locale or selector (optional)
|
|
7
11
|
* @returns Transformed dictionary content optimized for Svelte
|
|
8
12
|
*/
|
|
9
|
-
export declare const getIntlayer: <const T extends DictionaryKeys, const
|
|
13
|
+
export declare const getIntlayer: <const T extends DictionaryKeys, const A extends LocalesValues | DictionarySelectorForKey<T> = DeclaredLocales>(key: T, localeOrSelector?: A) => DeepTransformContent<DictionaryRegistryResult<T, A>, ExtractSelectorLocale<A>>;
|
package/dist/getIntlayer.js
CHANGED
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
import { getIntlayer as getIntlayerCore } from '@intlayer/core/interpreter';
|
|
2
2
|
import { getPlugins } from './plugins';
|
|
3
3
|
/**
|
|
4
|
-
* Get dictionary content by key for Svelte applications
|
|
4
|
+
* Get dictionary content by key for Svelte applications.
|
|
5
|
+
*
|
|
6
|
+
* The second argument is either a locale or a selector object (`{ item }`,
|
|
7
|
+
* `{ variant }`, `{ id, ...meta }`, optionally combined with `locale`).
|
|
8
|
+
*
|
|
5
9
|
* @param key The dictionary key to retrieve
|
|
6
|
-
* @param
|
|
10
|
+
* @param localeOrSelector The target locale or selector (optional)
|
|
7
11
|
* @returns Transformed dictionary content optimized for Svelte
|
|
8
12
|
*/
|
|
9
|
-
export const getIntlayer = (key,
|
|
13
|
+
export const getIntlayer = (key, localeOrSelector) => {
|
|
14
|
+
const locale = (typeof localeOrSelector === 'object' && localeOrSelector !== null
|
|
15
|
+
? localeOrSelector.locale
|
|
16
|
+
: localeOrSelector);
|
|
17
|
+
return getIntlayerCore(key, localeOrSelector, getPlugins(locale));
|
|
18
|
+
};
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { HTMLComponents } from '../html/types';
|
|
3
|
-
import { getMarkdownContext } from './context';
|
|
4
|
-
|
|
5
3
|
import type { ParsedMarkdown } from './compiler';
|
|
4
|
+
import { getMarkdownContext } from './context';
|
|
6
5
|
|
|
7
6
|
export let value: string | ParsedMarkdown;
|
|
8
7
|
export const components: HTMLComponents<'permissive', {}> | undefined =
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { KeyPath } from '@intlayer/types/keyPath';
|
|
3
3
|
import ContentSelector from '../editor/ContentSelector.svelte';
|
|
4
|
-
import MarkdownRenderer from './MarkdownRenderer.svelte';
|
|
5
|
-
|
|
6
4
|
import type { ParsedMarkdown } from './compiler';
|
|
5
|
+
import MarkdownRenderer from './MarkdownRenderer.svelte';
|
|
7
6
|
|
|
8
7
|
export let dictionaryKey: string;
|
|
9
8
|
export let keyPath: KeyPath[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "svelte-intlayer",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "9.0.0-canary.0",
|
|
4
4
|
"description": "Easily internationalize i18n your Svelte applications with type-safe multilingual content management.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"intlayer",
|
|
@@ -82,17 +82,17 @@
|
|
|
82
82
|
"typecheck": "tsc --noEmit --project tsconfig.types.json"
|
|
83
83
|
},
|
|
84
84
|
"dependencies": {
|
|
85
|
-
"@intlayer/api": "
|
|
86
|
-
"@intlayer/config": "
|
|
87
|
-
"@intlayer/core": "
|
|
88
|
-
"@intlayer/editor": "
|
|
89
|
-
"@intlayer/types": "
|
|
85
|
+
"@intlayer/api": "9.0.0-canary.0",
|
|
86
|
+
"@intlayer/config": "9.0.0-canary.0",
|
|
87
|
+
"@intlayer/core": "9.0.0-canary.0",
|
|
88
|
+
"@intlayer/editor": "9.0.0-canary.0",
|
|
89
|
+
"@intlayer/types": "9.0.0-canary.0"
|
|
90
90
|
},
|
|
91
91
|
"devDependencies": {
|
|
92
92
|
"@sveltejs/adapter-auto": "7.0.1",
|
|
93
93
|
"@sveltejs/package": "2.5.7",
|
|
94
94
|
"@sveltejs/vite-plugin-svelte": "7.1.2",
|
|
95
|
-
"@types/node": "25.9.
|
|
95
|
+
"@types/node": "25.9.3",
|
|
96
96
|
"@utils/ts-config": "1.0.4",
|
|
97
97
|
"@utils/ts-config-types": "1.0.4",
|
|
98
98
|
"@utils/tsdown-config": "1.0.4",
|