angular-intlayer 9.1.1 → 9.1.3
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/client/installIntlayer.cjs +11 -4
- package/dist/cjs/client/installIntlayer.cjs.map +1 -1
- package/dist/cjs/client/intlayerToken.cjs +11 -1
- package/dist/cjs/client/intlayerToken.cjs.map +1 -1
- package/dist/cjs/client/useDictionary.cjs +7 -5
- package/dist/cjs/client/useDictionary.cjs.map +1 -1
- package/dist/cjs/client/useDictionaryDynamic.cjs +7 -2
- package/dist/cjs/client/useDictionaryDynamic.cjs.map +1 -1
- package/dist/cjs/client/useIntlayer.cjs +7 -5
- package/dist/cjs/client/useIntlayer.cjs.map +1 -1
- package/dist/cjs/getDictionary.cjs.map +1 -1
- package/dist/cjs/getIntlayer.cjs.map +1 -1
- package/dist/esm/client/installIntlayer.mjs +11 -4
- package/dist/esm/client/installIntlayer.mjs.map +1 -1
- package/dist/esm/client/intlayerToken.mjs +11 -1
- package/dist/esm/client/intlayerToken.mjs.map +1 -1
- package/dist/esm/client/useDictionary.mjs +7 -5
- package/dist/esm/client/useDictionary.mjs.map +1 -1
- package/dist/esm/client/useDictionaryDynamic.mjs +8 -3
- package/dist/esm/client/useDictionaryDynamic.mjs.map +1 -1
- package/dist/esm/client/useIntlayer.mjs +7 -5
- package/dist/esm/client/useIntlayer.mjs.map +1 -1
- package/dist/esm/getDictionary.mjs.map +1 -1
- package/dist/esm/getIntlayer.mjs.map +1 -1
- package/dist/types/client/installIntlayer.d.ts +10 -3
- package/dist/types/client/installIntlayer.d.ts.map +1 -1
- package/dist/types/client/intlayerToken.d.ts +9 -2
- package/dist/types/client/intlayerToken.d.ts.map +1 -1
- package/dist/types/client/useDictionary.d.ts +2 -2
- package/dist/types/client/useDictionary.d.ts.map +1 -1
- package/dist/types/client/useDictionaryDynamic.d.ts +2 -2
- package/dist/types/client/useDictionaryDynamic.d.ts.map +1 -1
- package/dist/types/client/useIntlayer.d.ts +2 -2
- package/dist/types/client/useIntlayer.d.ts.map +1 -1
- package/dist/types/getDictionary.d.ts +2 -2
- package/dist/types/getDictionary.d.ts.map +1 -1
- package/dist/types/getIntlayer.d.ts +2 -2
- package/dist/types/getIntlayer.d.ts.map +1 -1
- package/package.json +9 -9
|
@@ -14,6 +14,13 @@ const require_editor_useEditor = require('../editor/useEditor.cjs');
|
|
|
14
14
|
*
|
|
15
15
|
* @param locale - Initial locale to use.
|
|
16
16
|
* @param isCookieEnabled - Whether to store the locale in cookies.
|
|
17
|
+
* @param variant - Ambient variant applied to every dictionary read in the app
|
|
18
|
+
* — for a dimension fixed for the whole session (tenant, school type, plan
|
|
19
|
+
* tier…) that no component should have to pass by hand. Accepts a name
|
|
20
|
+
* (`'school1'`), an ordered preference chain (`['school1', 'default']`), or a
|
|
21
|
+
* per-key map (`{ key1: 'school1', default: 'base' }`). A plain object is
|
|
22
|
+
* always the per-key map; nest a structured variant as
|
|
23
|
+
* `{ default: { id: 'prod_abc' } }`. A call-site selector always wins.
|
|
17
24
|
* @returns An array of Angular providers for Intlayer.
|
|
18
25
|
*
|
|
19
26
|
* @example
|
|
@@ -27,8 +34,8 @@ const require_editor_useEditor = require('../editor/useEditor.cjs');
|
|
|
27
34
|
* };
|
|
28
35
|
* ```
|
|
29
36
|
*/
|
|
30
|
-
const provideIntlayer = (locale, isCookieEnabled = true) => {
|
|
31
|
-
const client = installIntlayer(locale, isCookieEnabled);
|
|
37
|
+
const provideIntlayer = (locale, isCookieEnabled = true, variant) => {
|
|
38
|
+
const client = installIntlayer(locale, isCookieEnabled, variant);
|
|
32
39
|
return [
|
|
33
40
|
{
|
|
34
41
|
provide: require_client_intlayerToken.INTLAYER_TOKEN,
|
|
@@ -41,8 +48,8 @@ const provideIntlayer = (locale, isCookieEnabled = true) => {
|
|
|
41
48
|
/**
|
|
42
49
|
* Helper to install the Intlayer provider.
|
|
43
50
|
*/
|
|
44
|
-
const installIntlayer = (locale, isCookieEnabled = true) => {
|
|
45
|
-
return require_client_intlayerToken.createIntlayerClient(locale, isCookieEnabled);
|
|
51
|
+
const installIntlayer = (locale, isCookieEnabled = true, variant) => {
|
|
52
|
+
return require_client_intlayerToken.createIntlayerClient(locale, isCookieEnabled, variant);
|
|
46
53
|
};
|
|
47
54
|
|
|
48
55
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"installIntlayer.cjs","names":["INTLAYER_TOKEN","provideIntlayerEditor","provideIntlayerAnalytics","createIntlayerClient"],"sources":["../../../src/client/installIntlayer.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"installIntlayer.cjs","names":["INTLAYER_TOKEN","provideIntlayerEditor","provideIntlayerAnalytics","createIntlayerClient"],"sources":["../../../src/client/installIntlayer.ts"],"sourcesContent":["import type {\n LocalesValues,\n ProviderVariant,\n} from '@intlayer/types/module_augmentation';\nimport { provideIntlayerAnalytics } from '../analytics/useAnalytics';\nimport { provideIntlayerEditor } from '../editor/useEditor';\nimport {\n createIntlayerClient,\n INTLAYER_TOKEN,\n IntlayerProvider,\n} from './intlayerToken';\n\nexport { createIntlayerClient, INTLAYER_TOKEN, IntlayerProvider };\n\n/**\n * Provides Intlayer to your Angular application.\n *\n * Registers the Intlayer locale token **and** automatically starts the Intlayer\n * editor client (when the editor is enabled) via `provideAppInitializer`.\n *\n * This is the recommended way to set up Intlayer in `app.config.ts`.\n *\n * @param locale - Initial locale to use.\n * @param isCookieEnabled - Whether to store the locale in cookies.\n * @param variant - Ambient variant applied to every dictionary read in the app\n * — for a dimension fixed for the whole session (tenant, school type, plan\n * tier…) that no component should have to pass by hand. Accepts a name\n * (`'school1'`), an ordered preference chain (`['school1', 'default']`), or a\n * per-key map (`{ key1: 'school1', default: 'base' }`). A plain object is\n * always the per-key map; nest a structured variant as\n * `{ default: { id: 'prod_abc' } }`. A call-site selector always wins.\n * @returns An array of Angular providers for Intlayer.\n *\n * @example\n * ```ts\n * // app.config.ts\n * import { ApplicationConfig } from '@angular/core';\n * import { provideIntlayer } from 'angular-intlayer';\n *\n * export const appConfig: ApplicationConfig = {\n * providers: [provideIntlayer()],\n * };\n * ```\n */\nexport const provideIntlayer = (\n locale?: LocalesValues,\n isCookieEnabled = true,\n variant?: ProviderVariant\n) => {\n const client = installIntlayer(locale, isCookieEnabled, variant);\n\n return [\n { provide: INTLAYER_TOKEN, useValue: client },\n provideIntlayerEditor(client),\n provideIntlayerAnalytics(client),\n ];\n};\n\n/**\n * Helper to install the Intlayer provider.\n */\nexport const installIntlayer = (\n locale?: LocalesValues,\n isCookieEnabled = true,\n variant?: ProviderVariant\n) => {\n return createIntlayerClient(locale, isCookieEnabled, variant);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CA,MAAa,mBACX,QACA,kBAAkB,MAClB,YACG;CACH,MAAM,SAAS,gBAAgB,QAAQ,iBAAiB,OAAO;CAE/D,OAAO;EACL;GAAE,SAASA;GAAgB,UAAU;EAAO;EAC5CC,+CAAsB,MAAM;EAC5BC,wDAAyB,MAAM;CACjC;AACF;;;;AAKA,MAAa,mBACX,QACA,kBAAkB,MAClB,YACG;CACH,OAAOC,kDAAqB,QAAQ,iBAAiB,OAAO;AAC9D"}
|
|
@@ -7,13 +7,22 @@ let _intlayer_config_client = require("@intlayer/config/client");
|
|
|
7
7
|
var IntlayerProvider = class {
|
|
8
8
|
isCookieEnabled = (0, _angular_core.signal)(true);
|
|
9
9
|
_locale = (0, _angular_core.signal)(_intlayer_config_built.internationalization.defaultLocale);
|
|
10
|
+
_variant = (0, _angular_core.signal)(void 0);
|
|
10
11
|
locale = this._locale.asReadonly();
|
|
12
|
+
/**
|
|
13
|
+
* Ambient variant applied to every dictionary read in the app, the same way
|
|
14
|
+
* `locale` is. Overridden per call by an explicit selector.
|
|
15
|
+
*/
|
|
16
|
+
variant = this._variant.asReadonly();
|
|
11
17
|
constructor() {
|
|
12
18
|
(0, _intlayer_config_client.setIntlayerIdentifier)();
|
|
13
19
|
}
|
|
14
20
|
setLocale = (locale) => {
|
|
15
21
|
this._locale.set(locale);
|
|
16
22
|
};
|
|
23
|
+
setVariant = (variant) => {
|
|
24
|
+
this._variant.set(variant);
|
|
25
|
+
};
|
|
17
26
|
};
|
|
18
27
|
const INTLAYER_TOKEN = new _angular_core.InjectionToken("intlayer");
|
|
19
28
|
/**
|
|
@@ -23,10 +32,11 @@ let instance = null;
|
|
|
23
32
|
/**
|
|
24
33
|
* Create and return a single IntlayerProvider instance
|
|
25
34
|
*/
|
|
26
|
-
const createIntlayerClient = (locale, isCookieEnabled = true) => {
|
|
35
|
+
const createIntlayerClient = (locale, isCookieEnabled = true, variant) => {
|
|
27
36
|
if (instance) return instance;
|
|
28
37
|
instance = new IntlayerProvider();
|
|
29
38
|
if (locale) instance.setLocale(locale);
|
|
39
|
+
if (variant !== void 0) instance.setVariant(variant);
|
|
30
40
|
instance.isCookieEnabled.set(isCookieEnabled);
|
|
31
41
|
return instance;
|
|
32
42
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intlayerToken.cjs","names":["internationalization","InjectionToken"],"sources":["../../../src/client/intlayerToken.ts"],"sourcesContent":["import { InjectionToken, type Signal, signal } from '@angular/core';\nimport { internationalization } from '@intlayer/config/built';\nimport { setIntlayerIdentifier } from '@intlayer/config/client';\nimport type {
|
|
1
|
+
{"version":3,"file":"intlayerToken.cjs","names":["internationalization","InjectionToken"],"sources":["../../../src/client/intlayerToken.ts"],"sourcesContent":["import { InjectionToken, type Signal, signal } from '@angular/core';\nimport { internationalization } from '@intlayer/config/built';\nimport { setIntlayerIdentifier } from '@intlayer/config/client';\nimport type {\n LocalesValues,\n ProviderVariant,\n} from '@intlayer/types/module_augmentation';\n\nexport class IntlayerProvider {\n isCookieEnabled = signal(true);\n private _locale = signal<LocalesValues>(\n internationalization.defaultLocale as LocalesValues\n );\n\n private _variant = signal<ProviderVariant | undefined>(undefined);\n\n readonly locale: Signal<LocalesValues> = this._locale.asReadonly();\n\n /**\n * Ambient variant applied to every dictionary read in the app, the same way\n * `locale` is. Overridden per call by an explicit selector.\n */\n readonly variant: Signal<ProviderVariant | undefined> =\n this._variant.asReadonly();\n\n constructor() {\n setIntlayerIdentifier();\n }\n\n setLocale = (locale: LocalesValues) => {\n this._locale.set(locale);\n };\n\n setVariant = (variant: ProviderVariant | undefined) => {\n this._variant.set(variant);\n };\n}\n\nexport const INTLAYER_TOKEN = new InjectionToken<IntlayerProvider>('intlayer');\n\n/**\n * Singleton instance\n */\nlet instance: IntlayerProvider | null = null;\n\n/**\n * Create and return a single IntlayerProvider instance\n */\nexport const createIntlayerClient = (\n locale?: LocalesValues,\n isCookieEnabled = true,\n variant?: ProviderVariant\n): IntlayerProvider => {\n if (instance) return instance;\n\n instance = new IntlayerProvider();\n\n if (locale) {\n instance.setLocale(locale);\n }\n if (variant !== undefined) {\n instance.setVariant(variant);\n }\n instance.isCookieEnabled.set(isCookieEnabled);\n\n return instance;\n};\n"],"mappings":";;;;;;AAQA,IAAa,mBAAb,MAA8B;CAC5B,4CAAyB,IAAI;CAC7B,AAAQ,oCACNA,4CAAqB,aACvB;CAEA,AAAQ,qCAA+C,MAAS;CAEhE,AAAS,SAAgC,KAAK,QAAQ,WAAW;;;;;CAMjE,AAAS,UACP,KAAK,SAAS,WAAW;CAE3B,cAAc;EACZ,mDAAsB;CACxB;CAEA,aAAa,WAA0B;EACrC,KAAK,QAAQ,IAAI,MAAM;CACzB;CAEA,cAAc,YAAyC;EACrD,KAAK,SAAS,IAAI,OAAO;CAC3B;AACF;AAEA,MAAa,iBAAiB,IAAIC,6BAAiC,UAAU;;;;AAK7E,IAAI,WAAoC;;;;AAKxC,MAAa,wBACX,QACA,kBAAkB,MAClB,YACqB;CACrB,IAAI,UAAU,OAAO;CAErB,WAAW,IAAI,iBAAiB;CAEhC,IAAI,QACF,SAAS,UAAU,MAAM;CAE3B,IAAI,YAAY,QACd,SAAS,WAAW,OAAO;CAE7B,SAAS,gBAAgB,IAAI,eAAe;CAE5C,OAAO;AACT"}
|
|
@@ -2,6 +2,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2
2
|
const require_getDictionary = require('../getDictionary.cjs');
|
|
3
3
|
const require_client_intlayerToken = require('./intlayerToken.cjs');
|
|
4
4
|
let _angular_core = require("@angular/core");
|
|
5
|
+
let _intlayer_core_dictionaryManipulator = require("@intlayer/core/dictionaryManipulator");
|
|
5
6
|
|
|
6
7
|
//#region src/client/useDictionary.ts
|
|
7
8
|
/**
|
|
@@ -10,13 +11,14 @@ let _angular_core = require("@angular/core");
|
|
|
10
11
|
*/
|
|
11
12
|
const useDictionary = (dictionary, localeOrSelector) => {
|
|
12
13
|
const intlayer = (0, _angular_core.inject)(require_client_intlayerToken.INTLAYER_TOKEN);
|
|
13
|
-
const isSelector = process.env.INTLAYER_DICTIONARY_SELECTOR !== "false" && typeof localeOrSelector === "object" && localeOrSelector !== null;
|
|
14
14
|
return (0, _angular_core.computed)(() => {
|
|
15
15
|
const currentLocale = intlayer?.locale();
|
|
16
|
-
if (
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
if (process.env.INTLAYER_DICTIONARY_SELECTOR !== "false") return require_getDictionary.getDictionary(dictionary, (0, _intlayer_core_dictionaryManipulator.resolveDictionaryArgument)({
|
|
17
|
+
localeOrSelector,
|
|
18
|
+
contextLocale: currentLocale,
|
|
19
|
+
contextVariant: intlayer?.variant?.(),
|
|
20
|
+
dictionaryKey: dictionary.key
|
|
21
|
+
}));
|
|
20
22
|
return require_getDictionary.getDictionary(dictionary, localeOrSelector ?? currentLocale);
|
|
21
23
|
});
|
|
22
24
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionary.cjs","names":["INTLAYER_TOKEN","getDictionary"],"sources":["../../../src/client/useDictionary.ts"],"sourcesContent":["import { computed, inject, type Signal } from '@angular/core';\nimport type {\n Dictionary,\n
|
|
1
|
+
{"version":3,"file":"useDictionary.cjs","names":["INTLAYER_TOKEN","getDictionary"],"sources":["../../../src/client/useDictionary.ts"],"sourcesContent":["import { computed, inject, type Signal } from '@angular/core';\nimport { resolveDictionaryArgument } from '@intlayer/core/dictionaryManipulator';\nimport type {\n Dictionary,\n DictionarySelectorForGroup,\n QualifiedDictionaryGroup,\n ResolveQualifiedDictionaryContent,\n} from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n ExtractSelectorLocale,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { getDictionary } from '../getDictionary';\nimport type { DeepTransformContent } from '../plugins';\nimport { INTLAYER_TOKEN, type IntlayerProvider } from './installIntlayer';\n\n/**\n * Angular hook that transforms a dictionary (or qualified dictionary group)\n * and returns its reactive content for the given locale or selector.\n */\nexport const useDictionary = <\n const T extends Dictionary | QualifiedDictionaryGroup,\n const A extends\n | LocalesValues\n | DictionarySelectorForGroup<T> = DeclaredLocales,\n>(\n dictionary: T,\n localeOrSelector?: A\n): Signal<\n DeepTransformContent<\n ResolveQualifiedDictionaryContent<T, A>,\n ExtractSelectorLocale<A>\n >\n> => {\n const intlayer = inject<IntlayerProvider>(INTLAYER_TOKEN);\n\n /** a *stable* reactive dictionary object */\n const content = computed(() => {\n const currentLocale = intlayer?.locale();\n\n if (process.env.INTLAYER_DICTIONARY_SELECTOR !== 'false') {\n // Layers the provider's locale and variant under the call-site argument.\n // This is also the seam the build-time optimize transform lands on, which\n // rewrites `useIntlayer('key', selector)` into `useDictionary(dict, …)`.\n return getDictionary(\n dictionary,\n resolveDictionaryArgument({\n localeOrSelector,\n contextLocale: currentLocale,\n contextVariant: intlayer?.variant?.(),\n dictionaryKey: dictionary.key,\n }) as A\n ) as any;\n }\n\n return getDictionary(\n dictionary,\n (localeOrSelector ?? currentLocale) as A\n ) as any;\n });\n\n return content; // all consumers keep full reactivity\n};\n"],"mappings":";;;;;;;;;;;AAqBA,MAAa,iBAMX,YACA,qBAMG;CACH,MAAM,qCAAoCA,2CAAc;CA2BxD,yCAxB+B;EAC7B,MAAM,gBAAgB,UAAU,OAAO;EAEvC,IAAI,QAAQ,IAAI,iCAAiC,SAI/C,OAAOC,oCACL,gFAC0B;GACxB;GACA,eAAe;GACf,gBAAgB,UAAU,UAAU;GACpC,eAAe,WAAW;EAC5B,CAAC,CACH;EAGF,OAAOA,oCACL,YACC,oBAAoB,aACvB;CACF,CAEa;AACf"}
|
|
@@ -24,8 +24,13 @@ let _intlayer_core_dictionaryManipulator = require("@intlayer/core/dictionaryMan
|
|
|
24
24
|
const useDictionaryDynamic = (dictionaryPromise, key, localeOrSelector) => {
|
|
25
25
|
const intlayer = (0, _angular_core.inject)(require_client_intlayerToken.INTLAYER_TOKEN);
|
|
26
26
|
if (process.env.INTLAYER_DICTIONARY_SELECTOR !== "false" && (0, _intlayer_core_dictionaryManipulator.isQualifiedDynamicLoaderMap)(dictionaryPromise)) {
|
|
27
|
-
const { locale: selectorLocale, selector } = (0, _intlayer_core_dictionaryManipulator.parseDictionarySelector)(
|
|
28
|
-
|
|
27
|
+
const { locale: selectorLocale, selector } = (0, _intlayer_core_dictionaryManipulator.parseDictionarySelector)((0, _intlayer_core_dictionaryManipulator.resolveDictionaryArgument)({
|
|
28
|
+
localeOrSelector,
|
|
29
|
+
contextLocale: intlayer?.locale(),
|
|
30
|
+
contextVariant: intlayer?.variant?.(),
|
|
31
|
+
dictionaryKey: String(key)
|
|
32
|
+
}));
|
|
33
|
+
const localeTarget = selectorLocale ?? _intlayer_config_built.internationalization.defaultLocale;
|
|
29
34
|
const container = (0, _angular_core.signal)(void 0);
|
|
30
35
|
(0, _intlayer_core_dictionaryManipulator.resolveQualifiedDynamicContentAsync)({
|
|
31
36
|
loaderMap: dictionaryPromise,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionaryDynamic.cjs","names":["INTLAYER_TOKEN","internationalization","getDictionary","useDictionary","useLoadDynamic"],"sources":["../../../src/client/useDictionaryDynamic.ts"],"sourcesContent":["'use client';\n\nimport { computed, inject, signal } from '@angular/core';\nimport { internationalization } from '@intlayer/config/built';\nimport {\n isQualifiedDynamicLoaderMap,\n parseDictionarySelector,\n type QualifiedDynamicLoaderMap,\n resolveQualifiedDynamicContentAsync,\n} from '@intlayer/core/dictionaryManipulator';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n DictionarySelectorForKey,\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { getDictionary } from '../getDictionary';\nimport { INTLAYER_TOKEN, type IntlayerProvider } from './installIntlayer';\nimport { useDictionary } from './useDictionary';\nimport { useLoadDynamic } from './useLoadDynamic';\n\n/**\n * Lazily loads a dictionary (plain or qualified) and returns its reactive\n * content.\n *\n * For a qualified loader map (collection / variant, possibly\n * combined), only the chunk(s) the selector targets are loaded. For a plain\n * loader map, the locale chunk is loaded.\n *\n * If the locale is not provided (directly or through the selector), it will use\n * the locale from the client context.\n */\nexport const useDictionaryDynamic = <\n const T extends Dictionary,\n const K extends DictionaryKeys,\n const A extends
|
|
1
|
+
{"version":3,"file":"useDictionaryDynamic.cjs","names":["INTLAYER_TOKEN","internationalization","getDictionary","useDictionary","useLoadDynamic"],"sources":["../../../src/client/useDictionaryDynamic.ts"],"sourcesContent":["'use client';\n\nimport { computed, inject, signal } from '@angular/core';\nimport { internationalization } from '@intlayer/config/built';\nimport {\n isQualifiedDynamicLoaderMap,\n parseDictionarySelector,\n type QualifiedDynamicLoaderMap,\n resolveDictionaryArgument,\n resolveQualifiedDynamicContentAsync,\n} from '@intlayer/core/dictionaryManipulator';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n DictionarySelectorForKey,\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { getDictionary } from '../getDictionary';\nimport { INTLAYER_TOKEN, type IntlayerProvider } from './installIntlayer';\nimport { useDictionary } from './useDictionary';\nimport { useLoadDynamic } from './useLoadDynamic';\n\n/**\n * Lazily loads a dictionary (plain or qualified) and returns its reactive\n * content.\n *\n * For a qualified loader map (collection / variant, possibly\n * combined), only the chunk(s) the selector targets are loaded. For a plain\n * loader map, the locale chunk is loaded.\n *\n * If the locale is not provided (directly or through the selector), it will use\n * the locale from the client context.\n */\nexport const useDictionaryDynamic = <\n const T extends Dictionary,\n const K extends DictionaryKeys,\n const A extends LocalesValues | DictionarySelectorForKey<K> = DeclaredLocales,\n>(\n dictionaryPromise:\n | StrictModeLocaleMap<() => Promise<T>>\n | QualifiedDynamicLoaderMap,\n key: K,\n localeOrSelector?: A\n) => {\n const intlayer = inject<IntlayerProvider>(INTLAYER_TOKEN);\n\n if (\n process.env.INTLAYER_DICTIONARY_SELECTOR !== 'false' &&\n isQualifiedDynamicLoaderMap(dictionaryPromise)\n ) {\n // Layers the provider's ambient variant under the call-site argument\n // before the chunk walk, so only the targeted chunk is loaded.\n const { locale: selectorLocale, selector } =\n parseDictionarySelector<LocalesValues>(\n resolveDictionaryArgument({\n localeOrSelector,\n contextLocale: intlayer?.locale(),\n contextVariant: intlayer?.variant?.(),\n dictionaryKey: String(key),\n })\n );\n\n const localeTarget = selectorLocale ?? internationalization.defaultLocale;\n\n const container = signal<unknown>(undefined);\n\n resolveQualifiedDynamicContentAsync({\n loaderMap: dictionaryPromise,\n key: String(key),\n locale: localeTarget,\n selector,\n transform: (dictionary) => getDictionary(dictionary, localeTarget),\n }).then((resolved) => container.set(resolved));\n\n return computed(() => container() as any);\n }\n\n const locale =\n typeof localeOrSelector === 'string'\n ? (localeOrSelector as LocalesValues)\n : undefined;\n\n const localeTarget = computed(\n () => locale ?? intlayer?.locale() ?? internationalization.defaultLocale\n );\n\n const dictionary = useLoadDynamic<T>(\n `${String(key)}.${localeTarget()}`,\n (dictionaryPromise as any)[localeTarget()]?.()\n ) as T;\n\n return useDictionary(dictionary, localeTarget() as any);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAmCA,MAAa,wBAKX,mBAGA,KACA,qBACG;CACH,MAAM,qCAAoCA,2CAAc;CAExD,IACE,QAAQ,IAAI,iCAAiC,iFACjB,iBAAiB,GAC7C;EAGA,MAAM,EAAE,QAAQ,gBAAgB,mJAEF;GACxB;GACA,eAAe,UAAU,OAAO;GAChC,gBAAgB,UAAU,UAAU;GACpC,eAAe,OAAO,GAAG;EAC3B,CAAC,CACH;EAEF,MAAM,eAAe,kBAAkBC,4CAAqB;EAE5D,MAAM,sCAA4B,MAAS;EAE3C,8EAAoC;GAClC,WAAW;GACX,KAAK,OAAO,GAAG;GACf,QAAQ;GACR;GACA,YAAY,eAAeC,oCAAc,YAAY,YAAY;EACnE,CAAC,CAAC,CAAC,MAAM,aAAa,UAAU,IAAI,QAAQ,CAAC;EAE7C,yCAAsB,UAAU,CAAQ;CAC1C;CAEA,MAAM,SACJ,OAAO,qBAAqB,WACvB,mBACD;CAEN,MAAM,iDACE,UAAU,UAAU,OAAO,KAAKD,4CAAqB,aAC7D;CAOA,OAAOE,2CALYC,6CACjB,GAAG,OAAO,GAAG,EAAE,GAAG,aAAa,KAC9B,kBAA0B,aAAa,EAAE,GAAG,CAGjB,GAAG,aAAa,CAAQ;AACxD"}
|
|
@@ -2,6 +2,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2
2
|
const require_getIntlayer = require('../getIntlayer.cjs');
|
|
3
3
|
const require_client_intlayerToken = require('./intlayerToken.cjs');
|
|
4
4
|
let _angular_core = require("@angular/core");
|
|
5
|
+
let _intlayer_core_dictionaryManipulator = require("@intlayer/core/dictionaryManipulator");
|
|
5
6
|
|
|
6
7
|
//#region src/client/useIntlayer.ts
|
|
7
8
|
/** guard utility - true only for objects generated by `renderIntlayerNode()` */
|
|
@@ -33,13 +34,14 @@ const isUpdatableNode = (val) => !!val && typeof val === "object" && typeof val.
|
|
|
33
34
|
*/
|
|
34
35
|
const useIntlayer = (key, localeOrSelector) => {
|
|
35
36
|
const intlayer = (0, _angular_core.inject)(require_client_intlayerToken.INTLAYER_TOKEN);
|
|
36
|
-
const isSelector = process.env.INTLAYER_DICTIONARY_SELECTOR !== "false" && typeof localeOrSelector === "object" && localeOrSelector !== null;
|
|
37
37
|
return (0, _angular_core.computed)(() => {
|
|
38
38
|
const currentLocale = intlayer.locale();
|
|
39
|
-
if (
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
if (process.env.INTLAYER_DICTIONARY_SELECTOR !== "false") return require_getIntlayer.getIntlayer(key, (0, _intlayer_core_dictionaryManipulator.resolveDictionaryArgument)({
|
|
40
|
+
localeOrSelector,
|
|
41
|
+
contextLocale: currentLocale,
|
|
42
|
+
contextVariant: intlayer.variant?.(),
|
|
43
|
+
dictionaryKey: key
|
|
44
|
+
}));
|
|
43
45
|
return require_getIntlayer.getIntlayer(key, localeOrSelector ?? currentLocale);
|
|
44
46
|
});
|
|
45
47
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIntlayer.cjs","names":["INTLAYER_TOKEN","getIntlayer"],"sources":["../../../src/client/useIntlayer.ts"],"sourcesContent":["import { computed, inject, type Signal } from '@angular/core';\nimport
|
|
1
|
+
{"version":3,"file":"useIntlayer.cjs","names":["INTLAYER_TOKEN","getIntlayer"],"sources":["../../../src/client/useIntlayer.ts"],"sourcesContent":["import { computed, inject, type Signal } from '@angular/core';\nimport { resolveDictionaryArgument } from '@intlayer/core/dictionaryManipulator';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n DictionaryRegistryResult,\n DictionarySelectorForKey,\n ExtractSelectorLocale,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { getIntlayer } from '../getIntlayer';\nimport type { DeepTransformContent } from '../plugins';\nimport { INTLAYER_TOKEN, type IntlayerProvider } from './installIntlayer';\n\n/** guard utility - true only for objects generated by `renderIntlayerNode()` */\nexport const isUpdatableNode = (\n val: unknown\n): val is { __update: (n: unknown) => void } =>\n !!val &&\n typeof val === 'object' &&\n typeof (val as any).__update === 'function';\n\n/**\n * Angular hook that picks one dictionary by its key and returns its reactive content.\n *\n * It utilizes Angular signals to provide deep reactivity, ensuring your components\n * update automatically when the locale changes.\n *\n * @param key - The unique key of the dictionary to retrieve.\n * @param locale - Optional locale to override the current context locale.\n * @returns The transformed dictionary content.\n *\n * @example\n * ```ts\n * import { Component } from '@angular/core';\n * import { useIntlayer } from 'angular-intlayer';\n *\n * @Component({\n * standalone: true,\n * selector: 'app-my-component',\n * template: `<div>{{ content().myField.value }}</div>`,\n * })\n * export class MyComponent {\n * content = useIntlayer('my-dictionary-key');\n * }\n * ```\n */\nexport const useIntlayer = <\n const T extends DictionaryKeys,\n const A extends LocalesValues | DictionarySelectorForKey<T> = DeclaredLocales,\n>(\n key: T,\n localeOrSelector?: A\n): Signal<\n DeepTransformContent<DictionaryRegistryResult<T, A>, ExtractSelectorLocale<A>>\n> => {\n const intlayer = inject<IntlayerProvider>(INTLAYER_TOKEN)!;\n\n /** a *stable* reactive dictionary object */\n // @ts-ignore Type instantiation is excessively deep and possibly infinite\n const content = computed(() => {\n const currentLocale = intlayer.locale();\n\n if (process.env.INTLAYER_DICTIONARY_SELECTOR !== 'false') {\n // Layers the provider's locale and variant under the call-site argument.\n return getIntlayer(\n key,\n resolveDictionaryArgument({\n localeOrSelector,\n contextLocale: currentLocale,\n contextVariant: intlayer.variant?.(),\n dictionaryKey: key as string,\n }) as A\n ) as any;\n }\n\n return getIntlayer(key, (localeOrSelector ?? currentLocale) as A) as any;\n });\n\n return content; // all consumers keep full reactivity\n};\n"],"mappings":";;;;;;;;AAeA,MAAa,mBACX,QAEA,CAAC,CAAC,OACF,OAAO,QAAQ,YACf,OAAQ,IAAY,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BnC,MAAa,eAIX,KACA,qBAGG;CACH,MAAM,qCAAoCA,2CAAc;CAuBxD,yCAnB+B;EAC7B,MAAM,gBAAgB,SAAS,OAAO;EAEtC,IAAI,QAAQ,IAAI,iCAAiC,SAE/C,OAAOC,gCACL,yEAC0B;GACxB;GACA,eAAe;GACf,gBAAgB,SAAS,UAAU;GACnC,eAAe;EACjB,CAAC,CACH;EAGF,OAAOA,gCAAY,KAAM,oBAAoB,aAAmB;CAClE,CAEa;AACf"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getDictionary.cjs","names":["getPlugins"],"sources":["../../src/getDictionary.ts"],"sourcesContent":["import { getDictionary as getDictionaryCore } from '@intlayer/core/interpreter';\nimport type {\n Dictionary,\n DictionarySelectorForGroup,\n QualifiedDictionaryGroup,\n ResolveQualifiedDictionaryContent,\n} from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n ExtractSelectorLocale,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { type DeepTransformContent, getPlugins } from './plugins';\n\n/**\n * Transforms a dictionary (or qualified dictionary group) and returns its\n * content for the given locale or selector (`{ item }`, `{ variant }`,\n * optionally combined with `locale`).\n */\nexport const getDictionary = <\n const T extends Dictionary | QualifiedDictionaryGroup,\n const A extends\n |
|
|
1
|
+
{"version":3,"file":"getDictionary.cjs","names":["getPlugins"],"sources":["../../src/getDictionary.ts"],"sourcesContent":["import { getDictionary as getDictionaryCore } from '@intlayer/core/interpreter';\nimport type {\n Dictionary,\n DictionarySelectorForGroup,\n QualifiedDictionaryGroup,\n ResolveQualifiedDictionaryContent,\n} from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n ExtractSelectorLocale,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { type DeepTransformContent, getPlugins } from './plugins';\n\n/**\n * Transforms a dictionary (or qualified dictionary group) and returns its\n * content for the given locale or selector (`{ item }`, `{ variant }`,\n * optionally combined with `locale`).\n */\nexport const getDictionary = <\n const T extends Dictionary | QualifiedDictionaryGroup,\n const A extends\n | LocalesValues\n | DictionarySelectorForGroup<T> = DeclaredLocales,\n>(\n dictionary: T,\n localeOrSelector?: A\n): DeepTransformContent<\n ResolveQualifiedDictionaryContent<T, A>,\n ExtractSelectorLocale<A>\n> => {\n const locale = (\n typeof localeOrSelector === 'object' && localeOrSelector !== null\n ? localeOrSelector.locale\n : localeOrSelector\n ) as LocalesValues | undefined;\n\n return getDictionaryCore(\n dictionary,\n localeOrSelector,\n getPlugins(locale)\n ) as any;\n};\n"],"mappings":";;;;;;;;;;AAmBA,MAAa,iBAMX,YACA,qBAIG;CAOH,qDACE,YACA,kBACAA,2BARA,OAAO,qBAAqB,YAAY,qBAAqB,OACzD,iBAAiB,SACjB,gBAMa,CACnB;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getIntlayer.cjs","names":["getPlugins"],"sources":["../../src/getIntlayer.ts"],"sourcesContent":["import { getIntlayer as getIntlayerCore } from '@intlayer/core/interpreter';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n DictionaryRegistryResult,\n DictionarySelectorForKey,\n ExtractSelectorLocale,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { type DeepTransformContent, getPlugins } from './plugins';\n\n/**\n * Picks one dictionary by its key and returns its content for the given\n * locale or selector (`{ item }`, `{ variant }`,\n * optionally combined with `locale`).\n */\nexport const getIntlayer = <\n const T extends DictionaryKeys,\n const A extends
|
|
1
|
+
{"version":3,"file":"getIntlayer.cjs","names":["getPlugins"],"sources":["../../src/getIntlayer.ts"],"sourcesContent":["import { getIntlayer as getIntlayerCore } from '@intlayer/core/interpreter';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n DictionaryRegistryResult,\n DictionarySelectorForKey,\n ExtractSelectorLocale,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { type DeepTransformContent, getPlugins } from './plugins';\n\n/**\n * Picks one dictionary by its key and returns its content for the given\n * locale or selector (`{ item }`, `{ variant }`,\n * optionally combined with `locale`).\n */\nexport const getIntlayer = <\n const T extends DictionaryKeys,\n const A extends LocalesValues | DictionarySelectorForKey<T> = DeclaredLocales,\n>(\n key: T,\n localeOrSelector?: A\n): DeepTransformContent<\n DictionaryRegistryResult<T, A>,\n ExtractSelectorLocale<A>\n> => {\n const locale = (\n typeof localeOrSelector === 'object' && localeOrSelector !== null\n ? localeOrSelector.locale\n : localeOrSelector\n ) as LocalesValues | undefined;\n\n return getIntlayerCore(key, localeOrSelector, getPlugins(locale)) as any;\n};\n"],"mappings":";;;;;;;;;;AAgBA,MAAa,eAIX,KACA,qBAIG;CAOH,mDAAuB,KAAK,kBAAkBA,2BAL5C,OAAO,qBAAqB,YAAY,qBAAqB,OACzD,iBAAiB,SACjB,gBAGyD,CAAC;AAClE"}
|
|
@@ -13,6 +13,13 @@ import { provideIntlayerEditor } from "../editor/useEditor.mjs";
|
|
|
13
13
|
*
|
|
14
14
|
* @param locale - Initial locale to use.
|
|
15
15
|
* @param isCookieEnabled - Whether to store the locale in cookies.
|
|
16
|
+
* @param variant - Ambient variant applied to every dictionary read in the app
|
|
17
|
+
* — for a dimension fixed for the whole session (tenant, school type, plan
|
|
18
|
+
* tier…) that no component should have to pass by hand. Accepts a name
|
|
19
|
+
* (`'school1'`), an ordered preference chain (`['school1', 'default']`), or a
|
|
20
|
+
* per-key map (`{ key1: 'school1', default: 'base' }`). A plain object is
|
|
21
|
+
* always the per-key map; nest a structured variant as
|
|
22
|
+
* `{ default: { id: 'prod_abc' } }`. A call-site selector always wins.
|
|
16
23
|
* @returns An array of Angular providers for Intlayer.
|
|
17
24
|
*
|
|
18
25
|
* @example
|
|
@@ -26,8 +33,8 @@ import { provideIntlayerEditor } from "../editor/useEditor.mjs";
|
|
|
26
33
|
* };
|
|
27
34
|
* ```
|
|
28
35
|
*/
|
|
29
|
-
const provideIntlayer = (locale, isCookieEnabled = true) => {
|
|
30
|
-
const client = installIntlayer(locale, isCookieEnabled);
|
|
36
|
+
const provideIntlayer = (locale, isCookieEnabled = true, variant) => {
|
|
37
|
+
const client = installIntlayer(locale, isCookieEnabled, variant);
|
|
31
38
|
return [
|
|
32
39
|
{
|
|
33
40
|
provide: INTLAYER_TOKEN,
|
|
@@ -40,8 +47,8 @@ const provideIntlayer = (locale, isCookieEnabled = true) => {
|
|
|
40
47
|
/**
|
|
41
48
|
* Helper to install the Intlayer provider.
|
|
42
49
|
*/
|
|
43
|
-
const installIntlayer = (locale, isCookieEnabled = true) => {
|
|
44
|
-
return createIntlayerClient(locale, isCookieEnabled);
|
|
50
|
+
const installIntlayer = (locale, isCookieEnabled = true, variant) => {
|
|
51
|
+
return createIntlayerClient(locale, isCookieEnabled, variant);
|
|
45
52
|
};
|
|
46
53
|
|
|
47
54
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"installIntlayer.mjs","names":[],"sources":["../../../src/client/installIntlayer.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"installIntlayer.mjs","names":[],"sources":["../../../src/client/installIntlayer.ts"],"sourcesContent":["import type {\n LocalesValues,\n ProviderVariant,\n} from '@intlayer/types/module_augmentation';\nimport { provideIntlayerAnalytics } from '../analytics/useAnalytics';\nimport { provideIntlayerEditor } from '../editor/useEditor';\nimport {\n createIntlayerClient,\n INTLAYER_TOKEN,\n IntlayerProvider,\n} from './intlayerToken';\n\nexport { createIntlayerClient, INTLAYER_TOKEN, IntlayerProvider };\n\n/**\n * Provides Intlayer to your Angular application.\n *\n * Registers the Intlayer locale token **and** automatically starts the Intlayer\n * editor client (when the editor is enabled) via `provideAppInitializer`.\n *\n * This is the recommended way to set up Intlayer in `app.config.ts`.\n *\n * @param locale - Initial locale to use.\n * @param isCookieEnabled - Whether to store the locale in cookies.\n * @param variant - Ambient variant applied to every dictionary read in the app\n * — for a dimension fixed for the whole session (tenant, school type, plan\n * tier…) that no component should have to pass by hand. Accepts a name\n * (`'school1'`), an ordered preference chain (`['school1', 'default']`), or a\n * per-key map (`{ key1: 'school1', default: 'base' }`). A plain object is\n * always the per-key map; nest a structured variant as\n * `{ default: { id: 'prod_abc' } }`. A call-site selector always wins.\n * @returns An array of Angular providers for Intlayer.\n *\n * @example\n * ```ts\n * // app.config.ts\n * import { ApplicationConfig } from '@angular/core';\n * import { provideIntlayer } from 'angular-intlayer';\n *\n * export const appConfig: ApplicationConfig = {\n * providers: [provideIntlayer()],\n * };\n * ```\n */\nexport const provideIntlayer = (\n locale?: LocalesValues,\n isCookieEnabled = true,\n variant?: ProviderVariant\n) => {\n const client = installIntlayer(locale, isCookieEnabled, variant);\n\n return [\n { provide: INTLAYER_TOKEN, useValue: client },\n provideIntlayerEditor(client),\n provideIntlayerAnalytics(client),\n ];\n};\n\n/**\n * Helper to install the Intlayer provider.\n */\nexport const installIntlayer = (\n locale?: LocalesValues,\n isCookieEnabled = true,\n variant?: ProviderVariant\n) => {\n return createIntlayerClient(locale, isCookieEnabled, variant);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CA,MAAa,mBACX,QACA,kBAAkB,MAClB,YACG;CACH,MAAM,SAAS,gBAAgB,QAAQ,iBAAiB,OAAO;CAE/D,OAAO;EACL;GAAE,SAAS;GAAgB,UAAU;EAAO;EAC5C,sBAAsB,MAAM;EAC5B,yBAAyB,MAAM;CACjC;AACF;;;;AAKA,MAAa,mBACX,QACA,kBAAkB,MAClB,YACG;CACH,OAAO,qBAAqB,QAAQ,iBAAiB,OAAO;AAC9D"}
|
|
@@ -6,13 +6,22 @@ import { setIntlayerIdentifier } from "@intlayer/config/client";
|
|
|
6
6
|
var IntlayerProvider = class {
|
|
7
7
|
isCookieEnabled = signal(true);
|
|
8
8
|
_locale = signal(internationalization.defaultLocale);
|
|
9
|
+
_variant = signal(void 0);
|
|
9
10
|
locale = this._locale.asReadonly();
|
|
11
|
+
/**
|
|
12
|
+
* Ambient variant applied to every dictionary read in the app, the same way
|
|
13
|
+
* `locale` is. Overridden per call by an explicit selector.
|
|
14
|
+
*/
|
|
15
|
+
variant = this._variant.asReadonly();
|
|
10
16
|
constructor() {
|
|
11
17
|
setIntlayerIdentifier();
|
|
12
18
|
}
|
|
13
19
|
setLocale = (locale) => {
|
|
14
20
|
this._locale.set(locale);
|
|
15
21
|
};
|
|
22
|
+
setVariant = (variant) => {
|
|
23
|
+
this._variant.set(variant);
|
|
24
|
+
};
|
|
16
25
|
};
|
|
17
26
|
const INTLAYER_TOKEN = new InjectionToken("intlayer");
|
|
18
27
|
/**
|
|
@@ -22,10 +31,11 @@ let instance = null;
|
|
|
22
31
|
/**
|
|
23
32
|
* Create and return a single IntlayerProvider instance
|
|
24
33
|
*/
|
|
25
|
-
const createIntlayerClient = (locale, isCookieEnabled = true) => {
|
|
34
|
+
const createIntlayerClient = (locale, isCookieEnabled = true, variant) => {
|
|
26
35
|
if (instance) return instance;
|
|
27
36
|
instance = new IntlayerProvider();
|
|
28
37
|
if (locale) instance.setLocale(locale);
|
|
38
|
+
if (variant !== void 0) instance.setVariant(variant);
|
|
29
39
|
instance.isCookieEnabled.set(isCookieEnabled);
|
|
30
40
|
return instance;
|
|
31
41
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intlayerToken.mjs","names":[],"sources":["../../../src/client/intlayerToken.ts"],"sourcesContent":["import { InjectionToken, type Signal, signal } from '@angular/core';\nimport { internationalization } from '@intlayer/config/built';\nimport { setIntlayerIdentifier } from '@intlayer/config/client';\nimport type {
|
|
1
|
+
{"version":3,"file":"intlayerToken.mjs","names":[],"sources":["../../../src/client/intlayerToken.ts"],"sourcesContent":["import { InjectionToken, type Signal, signal } from '@angular/core';\nimport { internationalization } from '@intlayer/config/built';\nimport { setIntlayerIdentifier } from '@intlayer/config/client';\nimport type {\n LocalesValues,\n ProviderVariant,\n} from '@intlayer/types/module_augmentation';\n\nexport class IntlayerProvider {\n isCookieEnabled = signal(true);\n private _locale = signal<LocalesValues>(\n internationalization.defaultLocale as LocalesValues\n );\n\n private _variant = signal<ProviderVariant | undefined>(undefined);\n\n readonly locale: Signal<LocalesValues> = this._locale.asReadonly();\n\n /**\n * Ambient variant applied to every dictionary read in the app, the same way\n * `locale` is. Overridden per call by an explicit selector.\n */\n readonly variant: Signal<ProviderVariant | undefined> =\n this._variant.asReadonly();\n\n constructor() {\n setIntlayerIdentifier();\n }\n\n setLocale = (locale: LocalesValues) => {\n this._locale.set(locale);\n };\n\n setVariant = (variant: ProviderVariant | undefined) => {\n this._variant.set(variant);\n };\n}\n\nexport const INTLAYER_TOKEN = new InjectionToken<IntlayerProvider>('intlayer');\n\n/**\n * Singleton instance\n */\nlet instance: IntlayerProvider | null = null;\n\n/**\n * Create and return a single IntlayerProvider instance\n */\nexport const createIntlayerClient = (\n locale?: LocalesValues,\n isCookieEnabled = true,\n variant?: ProviderVariant\n): IntlayerProvider => {\n if (instance) return instance;\n\n instance = new IntlayerProvider();\n\n if (locale) {\n instance.setLocale(locale);\n }\n if (variant !== undefined) {\n instance.setVariant(variant);\n }\n instance.isCookieEnabled.set(isCookieEnabled);\n\n return instance;\n};\n"],"mappings":";;;;;AAQA,IAAa,mBAAb,MAA8B;CAC5B,kBAAkB,OAAO,IAAI;CAC7B,AAAQ,UAAU,OAChB,qBAAqB,aACvB;CAEA,AAAQ,WAAW,OAAoC,MAAS;CAEhE,AAAS,SAAgC,KAAK,QAAQ,WAAW;;;;;CAMjE,AAAS,UACP,KAAK,SAAS,WAAW;CAE3B,cAAc;EACZ,sBAAsB;CACxB;CAEA,aAAa,WAA0B;EACrC,KAAK,QAAQ,IAAI,MAAM;CACzB;CAEA,cAAc,YAAyC;EACrD,KAAK,SAAS,IAAI,OAAO;CAC3B;AACF;AAEA,MAAa,iBAAiB,IAAI,eAAiC,UAAU;;;;AAK7E,IAAI,WAAoC;;;;AAKxC,MAAa,wBACX,QACA,kBAAkB,MAClB,YACqB;CACrB,IAAI,UAAU,OAAO;CAErB,WAAW,IAAI,iBAAiB;CAEhC,IAAI,QACF,SAAS,UAAU,MAAM;CAE3B,IAAI,YAAY,QACd,SAAS,WAAW,OAAO;CAE7B,SAAS,gBAAgB,IAAI,eAAe;CAE5C,OAAO;AACT"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getDictionary } from "../getDictionary.mjs";
|
|
2
2
|
import { INTLAYER_TOKEN } from "./intlayerToken.mjs";
|
|
3
3
|
import { computed, inject } from "@angular/core";
|
|
4
|
+
import { resolveDictionaryArgument } from "@intlayer/core/dictionaryManipulator";
|
|
4
5
|
|
|
5
6
|
//#region src/client/useDictionary.ts
|
|
6
7
|
/**
|
|
@@ -9,13 +10,14 @@ import { computed, inject } from "@angular/core";
|
|
|
9
10
|
*/
|
|
10
11
|
const useDictionary = (dictionary, localeOrSelector) => {
|
|
11
12
|
const intlayer = inject(INTLAYER_TOKEN);
|
|
12
|
-
const isSelector = process.env.INTLAYER_DICTIONARY_SELECTOR !== "false" && typeof localeOrSelector === "object" && localeOrSelector !== null;
|
|
13
13
|
return computed(() => {
|
|
14
14
|
const currentLocale = intlayer?.locale();
|
|
15
|
-
if (
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
if (process.env.INTLAYER_DICTIONARY_SELECTOR !== "false") return getDictionary(dictionary, resolveDictionaryArgument({
|
|
16
|
+
localeOrSelector,
|
|
17
|
+
contextLocale: currentLocale,
|
|
18
|
+
contextVariant: intlayer?.variant?.(),
|
|
19
|
+
dictionaryKey: dictionary.key
|
|
20
|
+
}));
|
|
19
21
|
return getDictionary(dictionary, localeOrSelector ?? currentLocale);
|
|
20
22
|
});
|
|
21
23
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionary.mjs","names":[],"sources":["../../../src/client/useDictionary.ts"],"sourcesContent":["import { computed, inject, type Signal } from '@angular/core';\nimport type {\n Dictionary,\n
|
|
1
|
+
{"version":3,"file":"useDictionary.mjs","names":[],"sources":["../../../src/client/useDictionary.ts"],"sourcesContent":["import { computed, inject, type Signal } from '@angular/core';\nimport { resolveDictionaryArgument } from '@intlayer/core/dictionaryManipulator';\nimport type {\n Dictionary,\n DictionarySelectorForGroup,\n QualifiedDictionaryGroup,\n ResolveQualifiedDictionaryContent,\n} from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n ExtractSelectorLocale,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { getDictionary } from '../getDictionary';\nimport type { DeepTransformContent } from '../plugins';\nimport { INTLAYER_TOKEN, type IntlayerProvider } from './installIntlayer';\n\n/**\n * Angular hook that transforms a dictionary (or qualified dictionary group)\n * and returns its reactive content for the given locale or selector.\n */\nexport const useDictionary = <\n const T extends Dictionary | QualifiedDictionaryGroup,\n const A extends\n | LocalesValues\n | DictionarySelectorForGroup<T> = DeclaredLocales,\n>(\n dictionary: T,\n localeOrSelector?: A\n): Signal<\n DeepTransformContent<\n ResolveQualifiedDictionaryContent<T, A>,\n ExtractSelectorLocale<A>\n >\n> => {\n const intlayer = inject<IntlayerProvider>(INTLAYER_TOKEN);\n\n /** a *stable* reactive dictionary object */\n const content = computed(() => {\n const currentLocale = intlayer?.locale();\n\n if (process.env.INTLAYER_DICTIONARY_SELECTOR !== 'false') {\n // Layers the provider's locale and variant under the call-site argument.\n // This is also the seam the build-time optimize transform lands on, which\n // rewrites `useIntlayer('key', selector)` into `useDictionary(dict, …)`.\n return getDictionary(\n dictionary,\n resolveDictionaryArgument({\n localeOrSelector,\n contextLocale: currentLocale,\n contextVariant: intlayer?.variant?.(),\n dictionaryKey: dictionary.key,\n }) as A\n ) as any;\n }\n\n return getDictionary(\n dictionary,\n (localeOrSelector ?? currentLocale) as A\n ) as any;\n });\n\n return content; // all consumers keep full reactivity\n};\n"],"mappings":";;;;;;;;;;AAqBA,MAAa,iBAMX,YACA,qBAMG;CACH,MAAM,WAAW,OAAyB,cAAc;CA2BxD,OAxBgB,eAAe;EAC7B,MAAM,gBAAgB,UAAU,OAAO;EAEvC,IAAI,QAAQ,IAAI,iCAAiC,SAI/C,OAAO,cACL,YACA,0BAA0B;GACxB;GACA,eAAe;GACf,gBAAgB,UAAU,UAAU;GACpC,eAAe,WAAW;EAC5B,CAAC,CACH;EAGF,OAAO,cACL,YACC,oBAAoB,aACvB;CACF,CAEa;AACf"}
|
|
@@ -6,7 +6,7 @@ import { useDictionary } from "./useDictionary.mjs";
|
|
|
6
6
|
import { useLoadDynamic } from "./useLoadDynamic.mjs";
|
|
7
7
|
import { internationalization } from "@intlayer/config/built";
|
|
8
8
|
import { computed, inject, signal } from "@angular/core";
|
|
9
|
-
import { isQualifiedDynamicLoaderMap, parseDictionarySelector, resolveQualifiedDynamicContentAsync } from "@intlayer/core/dictionaryManipulator";
|
|
9
|
+
import { isQualifiedDynamicLoaderMap, parseDictionarySelector, resolveDictionaryArgument, resolveQualifiedDynamicContentAsync } from "@intlayer/core/dictionaryManipulator";
|
|
10
10
|
|
|
11
11
|
//#region src/client/useDictionaryDynamic.ts
|
|
12
12
|
/**
|
|
@@ -23,8 +23,13 @@ import { isQualifiedDynamicLoaderMap, parseDictionarySelector, resolveQualifiedD
|
|
|
23
23
|
const useDictionaryDynamic = (dictionaryPromise, key, localeOrSelector) => {
|
|
24
24
|
const intlayer = inject(INTLAYER_TOKEN);
|
|
25
25
|
if (process.env.INTLAYER_DICTIONARY_SELECTOR !== "false" && isQualifiedDynamicLoaderMap(dictionaryPromise)) {
|
|
26
|
-
const { locale: selectorLocale, selector } = parseDictionarySelector(
|
|
27
|
-
|
|
26
|
+
const { locale: selectorLocale, selector } = parseDictionarySelector(resolveDictionaryArgument({
|
|
27
|
+
localeOrSelector,
|
|
28
|
+
contextLocale: intlayer?.locale(),
|
|
29
|
+
contextVariant: intlayer?.variant?.(),
|
|
30
|
+
dictionaryKey: String(key)
|
|
31
|
+
}));
|
|
32
|
+
const localeTarget = selectorLocale ?? internationalization.defaultLocale;
|
|
28
33
|
const container = signal(void 0);
|
|
29
34
|
resolveQualifiedDynamicContentAsync({
|
|
30
35
|
loaderMap: dictionaryPromise,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionaryDynamic.mjs","names":[],"sources":["../../../src/client/useDictionaryDynamic.ts"],"sourcesContent":["'use client';\n\nimport { computed, inject, signal } from '@angular/core';\nimport { internationalization } from '@intlayer/config/built';\nimport {\n isQualifiedDynamicLoaderMap,\n parseDictionarySelector,\n type QualifiedDynamicLoaderMap,\n resolveQualifiedDynamicContentAsync,\n} from '@intlayer/core/dictionaryManipulator';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n DictionarySelectorForKey,\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { getDictionary } from '../getDictionary';\nimport { INTLAYER_TOKEN, type IntlayerProvider } from './installIntlayer';\nimport { useDictionary } from './useDictionary';\nimport { useLoadDynamic } from './useLoadDynamic';\n\n/**\n * Lazily loads a dictionary (plain or qualified) and returns its reactive\n * content.\n *\n * For a qualified loader map (collection / variant, possibly\n * combined), only the chunk(s) the selector targets are loaded. For a plain\n * loader map, the locale chunk is loaded.\n *\n * If the locale is not provided (directly or through the selector), it will use\n * the locale from the client context.\n */\nexport const useDictionaryDynamic = <\n const T extends Dictionary,\n const K extends DictionaryKeys,\n const A extends
|
|
1
|
+
{"version":3,"file":"useDictionaryDynamic.mjs","names":[],"sources":["../../../src/client/useDictionaryDynamic.ts"],"sourcesContent":["'use client';\n\nimport { computed, inject, signal } from '@angular/core';\nimport { internationalization } from '@intlayer/config/built';\nimport {\n isQualifiedDynamicLoaderMap,\n parseDictionarySelector,\n type QualifiedDynamicLoaderMap,\n resolveDictionaryArgument,\n resolveQualifiedDynamicContentAsync,\n} from '@intlayer/core/dictionaryManipulator';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n DictionarySelectorForKey,\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { getDictionary } from '../getDictionary';\nimport { INTLAYER_TOKEN, type IntlayerProvider } from './installIntlayer';\nimport { useDictionary } from './useDictionary';\nimport { useLoadDynamic } from './useLoadDynamic';\n\n/**\n * Lazily loads a dictionary (plain or qualified) and returns its reactive\n * content.\n *\n * For a qualified loader map (collection / variant, possibly\n * combined), only the chunk(s) the selector targets are loaded. For a plain\n * loader map, the locale chunk is loaded.\n *\n * If the locale is not provided (directly or through the selector), it will use\n * the locale from the client context.\n */\nexport const useDictionaryDynamic = <\n const T extends Dictionary,\n const K extends DictionaryKeys,\n const A extends LocalesValues | DictionarySelectorForKey<K> = DeclaredLocales,\n>(\n dictionaryPromise:\n | StrictModeLocaleMap<() => Promise<T>>\n | QualifiedDynamicLoaderMap,\n key: K,\n localeOrSelector?: A\n) => {\n const intlayer = inject<IntlayerProvider>(INTLAYER_TOKEN);\n\n if (\n process.env.INTLAYER_DICTIONARY_SELECTOR !== 'false' &&\n isQualifiedDynamicLoaderMap(dictionaryPromise)\n ) {\n // Layers the provider's ambient variant under the call-site argument\n // before the chunk walk, so only the targeted chunk is loaded.\n const { locale: selectorLocale, selector } =\n parseDictionarySelector<LocalesValues>(\n resolveDictionaryArgument({\n localeOrSelector,\n contextLocale: intlayer?.locale(),\n contextVariant: intlayer?.variant?.(),\n dictionaryKey: String(key),\n })\n );\n\n const localeTarget = selectorLocale ?? internationalization.defaultLocale;\n\n const container = signal<unknown>(undefined);\n\n resolveQualifiedDynamicContentAsync({\n loaderMap: dictionaryPromise,\n key: String(key),\n locale: localeTarget,\n selector,\n transform: (dictionary) => getDictionary(dictionary, localeTarget),\n }).then((resolved) => container.set(resolved));\n\n return computed(() => container() as any);\n }\n\n const locale =\n typeof localeOrSelector === 'string'\n ? (localeOrSelector as LocalesValues)\n : undefined;\n\n const localeTarget = computed(\n () => locale ?? intlayer?.locale() ?? internationalization.defaultLocale\n );\n\n const dictionary = useLoadDynamic<T>(\n `${String(key)}.${localeTarget()}`,\n (dictionaryPromise as any)[localeTarget()]?.()\n ) as T;\n\n return useDictionary(dictionary, localeTarget() as any);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAmCA,MAAa,wBAKX,mBAGA,KACA,qBACG;CACH,MAAM,WAAW,OAAyB,cAAc;CAExD,IACE,QAAQ,IAAI,iCAAiC,WAC7C,4BAA4B,iBAAiB,GAC7C;EAGA,MAAM,EAAE,QAAQ,gBAAgB,aAC9B,wBACE,0BAA0B;GACxB;GACA,eAAe,UAAU,OAAO;GAChC,gBAAgB,UAAU,UAAU;GACpC,eAAe,OAAO,GAAG;EAC3B,CAAC,CACH;EAEF,MAAM,eAAe,kBAAkB,qBAAqB;EAE5D,MAAM,YAAY,OAAgB,MAAS;EAE3C,oCAAoC;GAClC,WAAW;GACX,KAAK,OAAO,GAAG;GACf,QAAQ;GACR;GACA,YAAY,eAAe,cAAc,YAAY,YAAY;EACnE,CAAC,CAAC,CAAC,MAAM,aAAa,UAAU,IAAI,QAAQ,CAAC;EAE7C,OAAO,eAAe,UAAU,CAAQ;CAC1C;CAEA,MAAM,SACJ,OAAO,qBAAqB,WACvB,mBACD;CAEN,MAAM,eAAe,eACb,UAAU,UAAU,OAAO,KAAK,qBAAqB,aAC7D;CAOA,OAAO,cALY,eACjB,GAAG,OAAO,GAAG,EAAE,GAAG,aAAa,KAC9B,kBAA0B,aAAa,EAAE,GAAG,CAGjB,GAAG,aAAa,CAAQ;AACxD"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getIntlayer } from "../getIntlayer.mjs";
|
|
2
2
|
import { INTLAYER_TOKEN } from "./intlayerToken.mjs";
|
|
3
3
|
import { computed, inject } from "@angular/core";
|
|
4
|
+
import { resolveDictionaryArgument } from "@intlayer/core/dictionaryManipulator";
|
|
4
5
|
|
|
5
6
|
//#region src/client/useIntlayer.ts
|
|
6
7
|
/** guard utility - true only for objects generated by `renderIntlayerNode()` */
|
|
@@ -32,13 +33,14 @@ const isUpdatableNode = (val) => !!val && typeof val === "object" && typeof val.
|
|
|
32
33
|
*/
|
|
33
34
|
const useIntlayer = (key, localeOrSelector) => {
|
|
34
35
|
const intlayer = inject(INTLAYER_TOKEN);
|
|
35
|
-
const isSelector = process.env.INTLAYER_DICTIONARY_SELECTOR !== "false" && typeof localeOrSelector === "object" && localeOrSelector !== null;
|
|
36
36
|
return computed(() => {
|
|
37
37
|
const currentLocale = intlayer.locale();
|
|
38
|
-
if (
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
if (process.env.INTLAYER_DICTIONARY_SELECTOR !== "false") return getIntlayer(key, resolveDictionaryArgument({
|
|
39
|
+
localeOrSelector,
|
|
40
|
+
contextLocale: currentLocale,
|
|
41
|
+
contextVariant: intlayer.variant?.(),
|
|
42
|
+
dictionaryKey: key
|
|
43
|
+
}));
|
|
42
44
|
return getIntlayer(key, localeOrSelector ?? currentLocale);
|
|
43
45
|
});
|
|
44
46
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIntlayer.mjs","names":[],"sources":["../../../src/client/useIntlayer.ts"],"sourcesContent":["import { computed, inject, type Signal } from '@angular/core';\nimport
|
|
1
|
+
{"version":3,"file":"useIntlayer.mjs","names":[],"sources":["../../../src/client/useIntlayer.ts"],"sourcesContent":["import { computed, inject, type Signal } from '@angular/core';\nimport { resolveDictionaryArgument } from '@intlayer/core/dictionaryManipulator';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n DictionaryRegistryResult,\n DictionarySelectorForKey,\n ExtractSelectorLocale,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { getIntlayer } from '../getIntlayer';\nimport type { DeepTransformContent } from '../plugins';\nimport { INTLAYER_TOKEN, type IntlayerProvider } from './installIntlayer';\n\n/** guard utility - true only for objects generated by `renderIntlayerNode()` */\nexport const isUpdatableNode = (\n val: unknown\n): val is { __update: (n: unknown) => void } =>\n !!val &&\n typeof val === 'object' &&\n typeof (val as any).__update === 'function';\n\n/**\n * Angular hook that picks one dictionary by its key and returns its reactive content.\n *\n * It utilizes Angular signals to provide deep reactivity, ensuring your components\n * update automatically when the locale changes.\n *\n * @param key - The unique key of the dictionary to retrieve.\n * @param locale - Optional locale to override the current context locale.\n * @returns The transformed dictionary content.\n *\n * @example\n * ```ts\n * import { Component } from '@angular/core';\n * import { useIntlayer } from 'angular-intlayer';\n *\n * @Component({\n * standalone: true,\n * selector: 'app-my-component',\n * template: `<div>{{ content().myField.value }}</div>`,\n * })\n * export class MyComponent {\n * content = useIntlayer('my-dictionary-key');\n * }\n * ```\n */\nexport const useIntlayer = <\n const T extends DictionaryKeys,\n const A extends LocalesValues | DictionarySelectorForKey<T> = DeclaredLocales,\n>(\n key: T,\n localeOrSelector?: A\n): Signal<\n DeepTransformContent<DictionaryRegistryResult<T, A>, ExtractSelectorLocale<A>>\n> => {\n const intlayer = inject<IntlayerProvider>(INTLAYER_TOKEN)!;\n\n /** a *stable* reactive dictionary object */\n // @ts-ignore Type instantiation is excessively deep and possibly infinite\n const content = computed(() => {\n const currentLocale = intlayer.locale();\n\n if (process.env.INTLAYER_DICTIONARY_SELECTOR !== 'false') {\n // Layers the provider's locale and variant under the call-site argument.\n return getIntlayer(\n key,\n resolveDictionaryArgument({\n localeOrSelector,\n contextLocale: currentLocale,\n contextVariant: intlayer.variant?.(),\n dictionaryKey: key as string,\n }) as A\n ) as any;\n }\n\n return getIntlayer(key, (localeOrSelector ?? currentLocale) as A) as any;\n });\n\n return content; // all consumers keep full reactivity\n};\n"],"mappings":";;;;;;;AAeA,MAAa,mBACX,QAEA,CAAC,CAAC,OACF,OAAO,QAAQ,YACf,OAAQ,IAAY,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BnC,MAAa,eAIX,KACA,qBAGG;CACH,MAAM,WAAW,OAAyB,cAAc;CAuBxD,OAnBgB,eAAe;EAC7B,MAAM,gBAAgB,SAAS,OAAO;EAEtC,IAAI,QAAQ,IAAI,iCAAiC,SAE/C,OAAO,YACL,KACA,0BAA0B;GACxB;GACA,eAAe;GACf,gBAAgB,SAAS,UAAU;GACnC,eAAe;EACjB,CAAC,CACH;EAGF,OAAO,YAAY,KAAM,oBAAoB,aAAmB;CAClE,CAEa;AACf"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getDictionary.mjs","names":["getDictionaryCore"],"sources":["../../src/getDictionary.ts"],"sourcesContent":["import { getDictionary as getDictionaryCore } from '@intlayer/core/interpreter';\nimport type {\n Dictionary,\n DictionarySelectorForGroup,\n QualifiedDictionaryGroup,\n ResolveQualifiedDictionaryContent,\n} from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n ExtractSelectorLocale,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { type DeepTransformContent, getPlugins } from './plugins';\n\n/**\n * Transforms a dictionary (or qualified dictionary group) and returns its\n * content for the given locale or selector (`{ item }`, `{ variant }`,\n * optionally combined with `locale`).\n */\nexport const getDictionary = <\n const T extends Dictionary | QualifiedDictionaryGroup,\n const A extends\n |
|
|
1
|
+
{"version":3,"file":"getDictionary.mjs","names":["getDictionaryCore"],"sources":["../../src/getDictionary.ts"],"sourcesContent":["import { getDictionary as getDictionaryCore } from '@intlayer/core/interpreter';\nimport type {\n Dictionary,\n DictionarySelectorForGroup,\n QualifiedDictionaryGroup,\n ResolveQualifiedDictionaryContent,\n} from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n ExtractSelectorLocale,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { type DeepTransformContent, getPlugins } from './plugins';\n\n/**\n * Transforms a dictionary (or qualified dictionary group) and returns its\n * content for the given locale or selector (`{ item }`, `{ variant }`,\n * optionally combined with `locale`).\n */\nexport const getDictionary = <\n const T extends Dictionary | QualifiedDictionaryGroup,\n const A extends\n | LocalesValues\n | DictionarySelectorForGroup<T> = DeclaredLocales,\n>(\n dictionary: T,\n localeOrSelector?: A\n): DeepTransformContent<\n ResolveQualifiedDictionaryContent<T, A>,\n ExtractSelectorLocale<A>\n> => {\n const locale = (\n typeof localeOrSelector === 'object' && localeOrSelector !== null\n ? localeOrSelector.locale\n : localeOrSelector\n ) as LocalesValues | undefined;\n\n return getDictionaryCore(\n dictionary,\n localeOrSelector,\n getPlugins(locale)\n ) as any;\n};\n"],"mappings":";;;;;;;;;AAmBA,MAAa,iBAMX,YACA,qBAIG;CAOH,OAAOA,gBACL,YACA,kBACA,WARA,OAAO,qBAAqB,YAAY,qBAAqB,OACzD,iBAAiB,SACjB,gBAMa,CACnB;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getIntlayer.mjs","names":["getIntlayerCore"],"sources":["../../src/getIntlayer.ts"],"sourcesContent":["import { getIntlayer as getIntlayerCore } from '@intlayer/core/interpreter';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n DictionaryRegistryResult,\n DictionarySelectorForKey,\n ExtractSelectorLocale,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { type DeepTransformContent, getPlugins } from './plugins';\n\n/**\n * Picks one dictionary by its key and returns its content for the given\n * locale or selector (`{ item }`, `{ variant }`,\n * optionally combined with `locale`).\n */\nexport const getIntlayer = <\n const T extends DictionaryKeys,\n const A extends
|
|
1
|
+
{"version":3,"file":"getIntlayer.mjs","names":["getIntlayerCore"],"sources":["../../src/getIntlayer.ts"],"sourcesContent":["import { getIntlayer as getIntlayerCore } from '@intlayer/core/interpreter';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n DictionaryRegistryResult,\n DictionarySelectorForKey,\n ExtractSelectorLocale,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { type DeepTransformContent, getPlugins } from './plugins';\n\n/**\n * Picks one dictionary by its key and returns its content for the given\n * locale or selector (`{ item }`, `{ variant }`,\n * optionally combined with `locale`).\n */\nexport const getIntlayer = <\n const T extends DictionaryKeys,\n const A extends LocalesValues | DictionarySelectorForKey<T> = DeclaredLocales,\n>(\n key: T,\n localeOrSelector?: A\n): DeepTransformContent<\n DictionaryRegistryResult<T, A>,\n ExtractSelectorLocale<A>\n> => {\n const locale = (\n typeof localeOrSelector === 'object' && localeOrSelector !== null\n ? localeOrSelector.locale\n : localeOrSelector\n ) as LocalesValues | undefined;\n\n return getIntlayerCore(key, localeOrSelector, getPlugins(locale)) as any;\n};\n"],"mappings":";;;;;;;;;AAgBA,MAAa,eAIX,KACA,qBAIG;CAOH,OAAOA,cAAgB,KAAK,kBAAkB,WAL5C,OAAO,qBAAqB,YAAY,qBAAqB,OACzD,iBAAiB,SACjB,gBAGyD,CAAC;AAClE"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { INTLAYER_TOKEN, IntlayerProvider, createIntlayerClient } from "./intlayerToken.js";
|
|
2
|
-
import { LocalesValues } from "@intlayer/types/module_augmentation";
|
|
2
|
+
import { LocalesValues, ProviderVariant } from "@intlayer/types/module_augmentation";
|
|
3
3
|
//#region src/client/installIntlayer.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* Provides Intlayer to your Angular application.
|
|
@@ -11,6 +11,13 @@ import { LocalesValues } from "@intlayer/types/module_augmentation";
|
|
|
11
11
|
*
|
|
12
12
|
* @param locale - Initial locale to use.
|
|
13
13
|
* @param isCookieEnabled - Whether to store the locale in cookies.
|
|
14
|
+
* @param variant - Ambient variant applied to every dictionary read in the app
|
|
15
|
+
* — for a dimension fixed for the whole session (tenant, school type, plan
|
|
16
|
+
* 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 array of Angular providers for Intlayer.
|
|
15
22
|
*
|
|
16
23
|
* @example
|
|
@@ -24,14 +31,14 @@ import { LocalesValues } from "@intlayer/types/module_augmentation";
|
|
|
24
31
|
* };
|
|
25
32
|
* ```
|
|
26
33
|
*/
|
|
27
|
-
declare const provideIntlayer: (locale?: LocalesValues, isCookieEnabled?: boolean) => (import("@angular/core").EnvironmentProviders | {
|
|
34
|
+
declare const provideIntlayer: (locale?: LocalesValues, isCookieEnabled?: boolean, variant?: ProviderVariant) => (import("@angular/core").EnvironmentProviders | {
|
|
28
35
|
provide: import("@angular/core").InjectionToken<IntlayerProvider>;
|
|
29
36
|
useValue: IntlayerProvider;
|
|
30
37
|
})[];
|
|
31
38
|
/**
|
|
32
39
|
* Helper to install the Intlayer provider.
|
|
33
40
|
*/
|
|
34
|
-
declare const installIntlayer: (locale?: LocalesValues, isCookieEnabled?: boolean) => IntlayerProvider;
|
|
41
|
+
declare const installIntlayer: (locale?: LocalesValues, isCookieEnabled?: boolean, variant?: ProviderVariant) => IntlayerProvider;
|
|
35
42
|
//#endregion
|
|
36
43
|
export { INTLAYER_TOKEN, IntlayerProvider, createIntlayerClient, installIntlayer, provideIntlayer };
|
|
37
44
|
//# sourceMappingURL=installIntlayer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"installIntlayer.d.ts","names":[],"sources":["../../../src/client/installIntlayer.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"installIntlayer.d.ts","names":[],"sources":["../../../src/client/installIntlayer.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA4Ca,kBAAe,SACjB,eAAa,2BAAA,UAEZ,6CAAe;;;;;;;cAcd,kBAAe,SACjB,eAAa,2BAAA,UAEZ,oBAAe"}
|
|
@@ -1,18 +1,25 @@
|
|
|
1
1
|
import { InjectionToken, Signal } from "@angular/core";
|
|
2
|
-
import { LocalesValues } from "@intlayer/types/module_augmentation";
|
|
2
|
+
import { LocalesValues, ProviderVariant } from "@intlayer/types/module_augmentation";
|
|
3
3
|
//#region src/client/intlayerToken.d.ts
|
|
4
4
|
declare class IntlayerProvider {
|
|
5
5
|
isCookieEnabled: import("@angular/core").WritableSignal<boolean>;
|
|
6
6
|
private _locale;
|
|
7
|
+
private _variant;
|
|
7
8
|
readonly locale: Signal<LocalesValues>;
|
|
9
|
+
/**
|
|
10
|
+
* Ambient variant applied to every dictionary read in the app, the same way
|
|
11
|
+
* `locale` is. Overridden per call by an explicit selector.
|
|
12
|
+
*/
|
|
13
|
+
readonly variant: Signal<ProviderVariant | undefined>;
|
|
8
14
|
constructor();
|
|
9
15
|
setLocale: (locale: LocalesValues) => void;
|
|
16
|
+
setVariant: (variant: ProviderVariant | undefined) => void;
|
|
10
17
|
}
|
|
11
18
|
declare const INTLAYER_TOKEN: InjectionToken<IntlayerProvider>;
|
|
12
19
|
/**
|
|
13
20
|
* Create and return a single IntlayerProvider instance
|
|
14
21
|
*/
|
|
15
|
-
declare const createIntlayerClient: (locale?: LocalesValues, isCookieEnabled?: boolean) => IntlayerProvider;
|
|
22
|
+
declare const createIntlayerClient: (locale?: LocalesValues, isCookieEnabled?: boolean, variant?: ProviderVariant) => IntlayerProvider;
|
|
16
23
|
//#endregion
|
|
17
24
|
export { INTLAYER_TOKEN, IntlayerProvider, createIntlayerClient };
|
|
18
25
|
//# sourceMappingURL=intlayerToken.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intlayerToken.d.ts","names":[],"sources":["../../../src/client/intlayerToken.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"intlayerToken.d.ts","names":[],"sources":["../../../src/client/intlayerToken.ts"],"mappings":";;;cAQa;EACX,yCAAe;UACP;UAIA;WAEC,QAAQ,OAAO;;;;;WAMf,SAAS,OAAO;EAGzB;EAIA,YAAS,QAAY;EAIrB,aAAU,SAAa;;cAKZ,gBAAc,eAAA;;;;cAUd,uBAAoB,SACtB,eAAa,2BAAA,UAEZ,oBACT"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { DeepTransformContent } from "../plugins.js";
|
|
2
2
|
import { Signal } from "@angular/core";
|
|
3
|
-
import { DeclaredLocales, ExtractSelectorLocale } from "@intlayer/types/module_augmentation";
|
|
3
|
+
import { DeclaredLocales, ExtractSelectorLocale, LocalesValues } from "@intlayer/types/module_augmentation";
|
|
4
4
|
import { Dictionary, DictionarySelectorForGroup, QualifiedDictionaryGroup, ResolveQualifiedDictionaryContent } from "@intlayer/types/dictionary";
|
|
5
5
|
//#region src/client/useDictionary.d.ts
|
|
6
6
|
/**
|
|
7
7
|
* Angular hook that transforms a dictionary (or qualified dictionary group)
|
|
8
8
|
* and returns its reactive content for the given locale or selector.
|
|
9
9
|
*/
|
|
10
|
-
declare const useDictionary: <const T extends Dictionary | QualifiedDictionaryGroup, const A extends
|
|
10
|
+
declare const useDictionary: <const T extends Dictionary | QualifiedDictionaryGroup, const A extends LocalesValues | DictionarySelectorForGroup<T> = DeclaredLocales>(dictionary: T, localeOrSelector?: A) => Signal<DeepTransformContent<ResolveQualifiedDictionaryContent<T, A>, ExtractSelectorLocale<A>>>;
|
|
11
11
|
//#endregion
|
|
12
12
|
export { useDictionary };
|
|
13
13
|
//# sourceMappingURL=useDictionary.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionary.d.ts","names":[],"sources":["../../../src/client/useDictionary.ts"],"mappings":";;;;;;;;;
|
|
1
|
+
{"version":3,"file":"useDictionary.d.ts","names":[],"sources":["../../../src/client/useDictionary.ts"],"mappings":";;;;;;;;;cAqBa,sBACL,UAAU,aAAa,gCACvB,UACF,gBACA,2BAA2B,KAAK,iBAAe,YAEvC,GAAC,mBACM,MAClB,OACD,qBACE,kCAAkC,GAAG,IACrC,sBAAsB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DeclaredLocales, DictionaryKeys, DictionarySelectorForKey, StrictModeLocaleMap } from "@intlayer/types/module_augmentation";
|
|
1
|
+
import { DeclaredLocales, DictionaryKeys, DictionarySelectorForKey, LocalesValues, StrictModeLocaleMap } from "@intlayer/types/module_augmentation";
|
|
2
2
|
import { Dictionary } from "@intlayer/types/dictionary";
|
|
3
3
|
import { QualifiedDynamicLoaderMap } from "@intlayer/core/dictionaryManipulator";
|
|
4
4
|
//#region src/client/useDictionaryDynamic.d.ts
|
|
@@ -13,7 +13,7 @@ import { QualifiedDynamicLoaderMap } from "@intlayer/core/dictionaryManipulator"
|
|
|
13
13
|
* If the locale is not provided (directly or through the selector), it will use
|
|
14
14
|
* the locale from the client context.
|
|
15
15
|
*/
|
|
16
|
-
declare const useDictionaryDynamic: <const T extends Dictionary, const K extends DictionaryKeys, const A extends
|
|
16
|
+
declare const useDictionaryDynamic: <const T extends Dictionary, const K extends DictionaryKeys, const A extends LocalesValues | DictionarySelectorForKey<K> = DeclaredLocales>(dictionaryPromise: StrictModeLocaleMap<() => Promise<T>> | QualifiedDynamicLoaderMap, key: K, localeOrSelector?: A) => import("@angular/core").Signal<any>;
|
|
17
17
|
//#endregion
|
|
18
18
|
export { useDictionaryDynamic };
|
|
19
19
|
//# sourceMappingURL=useDictionaryDynamic.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionaryDynamic.d.ts","names":[],"sources":["../../../src/client/useDictionaryDynamic.ts"],"mappings":";;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"useDictionaryDynamic.d.ts","names":[],"sources":["../../../src/client/useDictionaryDynamic.ts"],"mappings":";;;;;;;;;;;;;;;cAmCa,6BACL,UAAU,kBACV,UAAU,sBACV,UAAU,gBAAgB,yBAAyB,KAAK,iBAAe,mBAGzE,0BAA0B,QAAQ,MAClC,2BAAyB,KACxB,GAAC,mBACa,8BAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DeepTransformContent } from "../plugins.js";
|
|
2
2
|
import { Signal } from "@angular/core";
|
|
3
|
-
import { DeclaredLocales, DictionaryKeys, DictionaryRegistryResult, DictionarySelectorForKey, ExtractSelectorLocale } from "@intlayer/types/module_augmentation";
|
|
3
|
+
import { DeclaredLocales, DictionaryKeys, DictionaryRegistryResult, DictionarySelectorForKey, ExtractSelectorLocale, LocalesValues } from "@intlayer/types/module_augmentation";
|
|
4
4
|
//#region src/client/useIntlayer.d.ts
|
|
5
5
|
/** guard utility - true only for objects generated by `renderIntlayerNode()` */
|
|
6
6
|
declare const isUpdatableNode: (val: unknown) => val is {
|
|
@@ -31,7 +31,7 @@ declare const isUpdatableNode: (val: unknown) => val is {
|
|
|
31
31
|
* }
|
|
32
32
|
* ```
|
|
33
33
|
*/
|
|
34
|
-
declare const useIntlayer: <const T extends DictionaryKeys, const A extends
|
|
34
|
+
declare const useIntlayer: <const T extends DictionaryKeys, const A extends LocalesValues | DictionarySelectorForKey<T> = DeclaredLocales>(key: T, localeOrSelector?: A) => Signal<DeepTransformContent<DictionaryRegistryResult<T, A>, ExtractSelectorLocale<A>>>;
|
|
35
35
|
//#endregion
|
|
36
36
|
export { isUpdatableNode, useIntlayer };
|
|
37
37
|
//# sourceMappingURL=useIntlayer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIntlayer.d.ts","names":[],"sources":["../../../src/client/useIntlayer.ts"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"useIntlayer.d.ts","names":[],"sources":["../../../src/client/useIntlayer.ts"],"mappings":";;;;;cAea,kBAAe,iBAEzB;EAAS,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;cA8BV,oBACL,UAAU,sBACV,UAAU,gBAAgB,yBAAyB,KAAK,iBAAe,KAExE,GAAC,mBACa,MAClB,OACD,qBAAqB,yBAAyB,GAAG,IAAI,sBAAsB"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DeepTransformContent } from "./plugins.js";
|
|
2
|
-
import { DeclaredLocales, ExtractSelectorLocale } from "@intlayer/types/module_augmentation";
|
|
2
|
+
import { DeclaredLocales, ExtractSelectorLocale, LocalesValues } from "@intlayer/types/module_augmentation";
|
|
3
3
|
import { Dictionary, DictionarySelectorForGroup, QualifiedDictionaryGroup, ResolveQualifiedDictionaryContent } from "@intlayer/types/dictionary";
|
|
4
4
|
//#region src/getDictionary.d.ts
|
|
5
5
|
/**
|
|
@@ -7,7 +7,7 @@ import { Dictionary, DictionarySelectorForGroup, QualifiedDictionaryGroup, Resol
|
|
|
7
7
|
* content for the given locale or selector (`{ item }`, `{ variant }`,
|
|
8
8
|
* optionally combined with `locale`).
|
|
9
9
|
*/
|
|
10
|
-
declare const getDictionary: <const T extends Dictionary | QualifiedDictionaryGroup, const A extends
|
|
10
|
+
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>>;
|
|
11
11
|
//#endregion
|
|
12
12
|
export { getDictionary };
|
|
13
13
|
//# sourceMappingURL=getDictionary.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getDictionary.d.ts","names":[],"sources":["../../src/getDictionary.ts"],"mappings":";;;;;;;;;cAmBa,sBACL,UAAU,aAAa,gCACvB,UACF,
|
|
1
|
+
{"version":3,"file":"getDictionary.d.ts","names":[],"sources":["../../src/getDictionary.ts"],"mappings":";;;;;;;;;cAmBa,sBACL,UAAU,aAAa,gCACvB,UACF,gBACA,2BAA2B,KAAK,iBAAe,YAEvC,GAAC,mBACM,MAClB,qBACD,kCAAkC,GAAG,IACrC,sBAAsB"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { DeepTransformContent } from "./plugins.js";
|
|
2
|
-
import { DeclaredLocales, DictionaryKeys, DictionaryRegistryResult, DictionarySelectorForKey, ExtractSelectorLocale } from "@intlayer/types/module_augmentation";
|
|
2
|
+
import { DeclaredLocales, DictionaryKeys, DictionaryRegistryResult, DictionarySelectorForKey, ExtractSelectorLocale, LocalesValues } from "@intlayer/types/module_augmentation";
|
|
3
3
|
//#region src/getIntlayer.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* Picks one dictionary by its key and returns its content for the given
|
|
6
6
|
* locale or selector (`{ item }`, `{ variant }`,
|
|
7
7
|
* optionally combined with `locale`).
|
|
8
8
|
*/
|
|
9
|
-
declare const getIntlayer: <const T extends DictionaryKeys, const A extends
|
|
9
|
+
declare const getIntlayer: <const T extends DictionaryKeys, const A extends LocalesValues | DictionarySelectorForKey<T> = DeclaredLocales>(key: T, localeOrSelector?: A) => DeepTransformContent<DictionaryRegistryResult<T, A>, ExtractSelectorLocale<A>>;
|
|
10
10
|
//#endregion
|
|
11
11
|
export { getIntlayer };
|
|
12
12
|
//# sourceMappingURL=getIntlayer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getIntlayer.d.ts","names":[],"sources":["../../src/getIntlayer.ts"],"mappings":";;;;;;;;cAgBa,oBACL,UAAU,sBACV,
|
|
1
|
+
{"version":3,"file":"getIntlayer.d.ts","names":[],"sources":["../../src/getIntlayer.ts"],"mappings":";;;;;;;;cAgBa,oBACL,UAAU,sBACV,UAAU,gBAAgB,yBAAyB,KAAK,iBAAe,KAExE,GAAC,mBACa,MAClB,qBACD,yBAAyB,GAAG,IAC5B,sBAAsB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "angular-intlayer",
|
|
3
|
-
"version": "9.1.
|
|
3
|
+
"version": "9.1.3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Easily internationalize i18n your Angular applications with type-safe multilingual content management.",
|
|
6
6
|
"keywords": [
|
|
@@ -119,13 +119,13 @@
|
|
|
119
119
|
"@babel/core": "^7.26.9",
|
|
120
120
|
"@babel/plugin-syntax-import-attributes": "7.28.6",
|
|
121
121
|
"@babel/preset-env": "7.29.2",
|
|
122
|
-
"@intlayer/config": "9.1.
|
|
123
|
-
"@intlayer/core": "9.1.
|
|
124
|
-
"@intlayer/dictionaries-entry": "9.1.
|
|
125
|
-
"@intlayer/editor": "9.1.
|
|
126
|
-
"@intlayer/engine": "9.1.
|
|
127
|
-
"@intlayer/types": "9.1.
|
|
128
|
-
"@intlayer/webpack": "9.1.
|
|
122
|
+
"@intlayer/config": "9.1.3",
|
|
123
|
+
"@intlayer/core": "9.1.3",
|
|
124
|
+
"@intlayer/dictionaries-entry": "9.1.3",
|
|
125
|
+
"@intlayer/editor": "9.1.3",
|
|
126
|
+
"@intlayer/engine": "9.1.3",
|
|
127
|
+
"@intlayer/types": "9.1.3",
|
|
128
|
+
"@intlayer/webpack": "9.1.3",
|
|
129
129
|
"babel-loader": "10.1.1",
|
|
130
130
|
"defu": "6.1.7"
|
|
131
131
|
},
|
|
@@ -155,7 +155,7 @@
|
|
|
155
155
|
}
|
|
156
156
|
},
|
|
157
157
|
"optionalDependencies": {
|
|
158
|
-
"@intlayer/analytics": "9.1.
|
|
158
|
+
"@intlayer/analytics": "9.1.3"
|
|
159
159
|
},
|
|
160
160
|
"engines": {
|
|
161
161
|
"node": ">=14.18"
|