@agorapulse/ui-components 22.5.3 → 22.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,176 @@
1
+ import * as i0 from '@angular/core';
2
+ import { InjectionToken, isDevMode, Pipe, inject, computed } from '@angular/core';
3
+
4
+ const DEFAULT_TEXTS = Object.freeze({});
5
+ /**
6
+ * Holds the fallback table read by `injectTranslate`; provide another table to override it, for instance in a test.
7
+ *
8
+ * @example
9
+ * TestBed.configureTestingModule({ providers: [{ provide: UI_COMPONENTS_DEFAULT_TEXTS, useValue: { 'ui-components.ok': 'OK' } }] });
10
+ */
11
+ const UI_COMPONENTS_DEFAULT_TEXTS = new InjectionToken('UI_COMPONENTS_DEFAULT_TEXTS', {
12
+ providedIn: 'root',
13
+ factory: () => DEFAULT_TEXTS,
14
+ });
15
+ function fallbackText(key, params, table = DEFAULT_TEXTS) {
16
+ if (!Object.prototype.hasOwnProperty.call(table, key))
17
+ return undefined;
18
+ return table[key].replace(/\{\{\s*([^{}\s]+)\s*\}\}/g, (placeholder, name) => params?.[name] !== undefined && params[name] !== null && Object.prototype.hasOwnProperty.call(params, name)
19
+ ? String(params[name])
20
+ : placeholder);
21
+ }
22
+
23
+ /**
24
+ * The default `isKey`: dotted segments, so dotted data such as `example.com` passes too.
25
+ *
26
+ * @example
27
+ * DEFAULT_IS_KEY('report.filter.apply'); // true
28
+ * DEFAULT_IS_KEY('Black Friday 2026'); // false
29
+ */
30
+ const DEFAULT_IS_KEY = (text) => /^[\w-]+(\.[\w-]+)+$/.test(text);
31
+ const warnedValues = new Set();
32
+ function warnIfNotKey(text, isKey, devMode = isDevMode()) {
33
+ if (!devMode || isKey(text) || warnedValues.has(text))
34
+ return;
35
+ warnedValues.add(text);
36
+ console.warn(`[ui-components/i18n] "${text}" is not a translation key. Wrap displayed data with raw() (or | apRaw).`);
37
+ }
38
+
39
+ /**
40
+ * Turns a text into a {@link RawText} so a component displays it as is. `null` and `undefined` give an empty text.
41
+ *
42
+ * @example
43
+ * <ap-button [i18n]="{ label: user.name | apRaw }" />
44
+ */
45
+ class RawPipe {
46
+ transform(text) {
47
+ return { raw: text ?? '' };
48
+ }
49
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.5", ngImport: i0, type: RawPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
50
+ static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "22.0.5", ngImport: i0, type: RawPipe, isStandalone: true, name: "apRaw" });
51
+ }
52
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.5", ngImport: i0, type: RawPipe, decorators: [{
53
+ type: Pipe,
54
+ args: [{ name: 'apRaw' }]
55
+ }] });
56
+
57
+ /**
58
+ * Marks a text to display as is: it never reaches the app's `translate`.
59
+ *
60
+ * @example
61
+ * raw('jordan.amar'); // { raw: 'jordan.amar' }
62
+ */
63
+ function raw(text) {
64
+ return { raw: text };
65
+ }
66
+ /**
67
+ * Checks the shape only: an object with a string `raw`, whatever other keys it carries.
68
+ *
69
+ * @example
70
+ * isRawText({ raw: 'x' }); // true
71
+ * isRawText('a.b'); // false
72
+ */
73
+ function isRawText(value) {
74
+ return typeof value === 'object' && value !== null && 'raw' in value && typeof value.raw === 'string';
75
+ }
76
+ /**
77
+ * Checks the shape only: an object with a string `key`; `params` is not validated.
78
+ *
79
+ * @example
80
+ * isKeyRequest({ key: 'a.b' }); // true
81
+ * isKeyRequest({ label: 'x' }); // false
82
+ */
83
+ function isKeyRequest(value) {
84
+ return typeof value === 'object' && value !== null && 'key' in value && typeof value.key === 'string';
85
+ }
86
+
87
+ /**
88
+ * Holds the app's translation; absent when the app provides none.
89
+ *
90
+ * @example
91
+ * const translation = inject(UI_COMPONENTS_TRANSLATION, { optional: true });
92
+ */
93
+ const UI_COMPONENTS_TRANSLATION = new InjectionToken('UI_COMPONENTS_TRANSLATION');
94
+ /**
95
+ * Plugs the app's translation into the DS components.
96
+ *
97
+ * @param config the translation, or a factory run in an injection context when it needs `inject()`.
98
+ *
99
+ * @example
100
+ * provideUiComponentsTranslation(() => {
101
+ * const translateService = inject(TranslateService);
102
+ * return { translate: (key, params) => translateService.instant(key, params) };
103
+ * });
104
+ */
105
+ function provideUiComponentsTranslation(config) {
106
+ return typeof config === 'function'
107
+ ? { provide: UI_COMPONENTS_TRANSLATION, useFactory: config }
108
+ : { provide: UI_COMPONENTS_TRANSLATION, useValue: config };
109
+ }
110
+ /**
111
+ * Call in an injection context; the returned function renders a {@link TranslationRequest} and, read inside a
112
+ * `computed`, follows language changes. Resolution rules: `design-specs/patterns/translation.md`.
113
+ *
114
+ * @example
115
+ * const t = injectTranslate();
116
+ * const title = computed(() => t(this.i18n().title, { count: this.count() }));
117
+ */
118
+ function injectTranslate() {
119
+ const translation = inject(UI_COMPONENTS_TRANSLATION, { optional: true });
120
+ const defaultTexts = inject(UI_COMPONENTS_DEFAULT_TEXTS);
121
+ const isKey = translation?.isKey ?? DEFAULT_IS_KEY;
122
+ function resolve(request, dsParams) {
123
+ translation?.language?.();
124
+ if (request === null || request === undefined || request === '')
125
+ return '';
126
+ if (typeof request === 'string') {
127
+ warnIfNotKey(request, isKey);
128
+ return translateKey(request, dsParams);
129
+ }
130
+ if (isRawText(request))
131
+ return request.raw;
132
+ if (isKeyRequest(request)) {
133
+ if (request.key === '')
134
+ return '';
135
+ return translateKey(request.key, request.params || dsParams ? { ...request.params, ...definedEntries(dsParams) } : undefined);
136
+ }
137
+ if (isDevMode()) {
138
+ console.warn('[ui-components/i18n] Unsupported translation request, expected a key string, { key, params } or { raw }:', request);
139
+ }
140
+ return '';
141
+ }
142
+ function translateKey(key, params) {
143
+ const resolvedParams = resolveParams(params);
144
+ if (!translation)
145
+ return fallbackText(key, resolvedParams, defaultTexts) ?? key;
146
+ const translated = translation.translate(key, resolvedParams);
147
+ return translated === key ? (fallbackText(key, resolvedParams, defaultTexts) ?? translated) : translated;
148
+ }
149
+ function definedEntries(params) {
150
+ return Object.fromEntries(Object.entries(params ?? {}).filter(([, value]) => value !== undefined));
151
+ }
152
+ function resolveParams(params) {
153
+ if (!params)
154
+ return undefined;
155
+ return Object.fromEntries(Object.entries(params).map(([name, value]) => [name, isRawText(value) || isKeyRequest(value) ? resolve(value) : value]));
156
+ }
157
+ return resolve;
158
+ }
159
+ /**
160
+ * The app's current language, `undefined` when the app gives none.
161
+ *
162
+ * @example
163
+ * const language = injectLanguage();
164
+ * const locale = computed(() => language() ?? 'en');
165
+ */
166
+ function injectLanguage() {
167
+ const translation = inject(UI_COMPONENTS_TRANSLATION, { optional: true });
168
+ return computed(() => translation?.language?.());
169
+ }
170
+
171
+ /**
172
+ * Generated bundle index. Do not edit.
173
+ */
174
+
175
+ export { DEFAULT_IS_KEY, RawPipe, UI_COMPONENTS_DEFAULT_TEXTS, UI_COMPONENTS_TRANSLATION, injectLanguage, injectTranslate, isKeyRequest, isRawText, provideUiComponentsTranslation, raw };
176
+ //# sourceMappingURL=agorapulse-ui-components-i18n.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agorapulse-ui-components-i18n.mjs","sources":["../../../libs/ui-components/i18n/src/default-texts.ts","../../../libs/ui-components/i18n/src/key-guard.ts","../../../libs/ui-components/i18n/src/raw.pipe.ts","../../../libs/ui-components/i18n/src/translation.model.ts","../../../libs/ui-components/i18n/src/translation.provider.ts","../../../libs/ui-components/i18n/src/agorapulse-ui-components-i18n.ts"],"sourcesContent":["import { InjectionToken } from '@angular/core';\n\nexport const DEFAULT_TEXTS: Readonly<Record<string, string>> = Object.freeze({});\n\n/**\n * Holds the fallback table read by `injectTranslate`; provide another table to override it, for instance in a test.\n *\n * @example\n * TestBed.configureTestingModule({ providers: [{ provide: UI_COMPONENTS_DEFAULT_TEXTS, useValue: { 'ui-components.ok': 'OK' } }] });\n */\nexport const UI_COMPONENTS_DEFAULT_TEXTS = new InjectionToken<Readonly<Record<string, string>>>('UI_COMPONENTS_DEFAULT_TEXTS', {\n providedIn: 'root',\n factory: () => DEFAULT_TEXTS,\n});\n\nexport function fallbackText(\n key: string,\n params?: Record<string, unknown>,\n table: Readonly<Record<string, string>> = DEFAULT_TEXTS\n): string | undefined {\n if (!Object.prototype.hasOwnProperty.call(table, key)) return undefined;\n\n return table[key].replace(/\\{\\{\\s*([^{}\\s]+)\\s*\\}\\}/g, (placeholder, name: string) =>\n params?.[name] !== undefined && params[name] !== null && Object.prototype.hasOwnProperty.call(params, name)\n ? String(params[name])\n : placeholder\n );\n}\n","import { isDevMode } from '@angular/core';\n\n/**\n * The default `isKey`: dotted segments, so dotted data such as `example.com` passes too.\n *\n * @example\n * DEFAULT_IS_KEY('report.filter.apply'); // true\n * DEFAULT_IS_KEY('Black Friday 2026'); // false\n */\nexport const DEFAULT_IS_KEY = (text: string): boolean => /^[\\w-]+(\\.[\\w-]+)+$/.test(text);\n\nconst warnedValues = new Set<string>();\n\nexport function warnIfNotKey(text: string, isKey: (text: string) => boolean, devMode: boolean = isDevMode()): void {\n if (!devMode || isKey(text) || warnedValues.has(text)) return;\n\n warnedValues.add(text);\n console.warn(`[ui-components/i18n] \"${text}\" is not a translation key. Wrap displayed data with raw() (or | apRaw).`);\n}\n","import { Pipe, PipeTransform } from '@angular/core';\nimport { RawText } from './translation.model';\n\n/**\n * Turns a text into a {@link RawText} so a component displays it as is. `null` and `undefined` give an empty text.\n *\n * @example\n * <ap-button [i18n]=\"{ label: user.name | apRaw }\" />\n */\n@Pipe({ name: 'apRaw' })\nexport class RawPipe implements PipeTransform {\n transform(text: string | null | undefined): RawText {\n return { raw: text ?? '' };\n }\n}\n","/**\n * A translation key with optional interpolation parameters.\n *\n * @example\n * const request: TranslationKeyRequest = { key: 'inbox.unread', params: { count: 3 } };\n */\nexport type TranslationKeyRequest = { key: string; params?: Record<string, unknown> };\n\n/**\n * A text displayed as is, never looked up in a catalogue (user content, names, handles).\n *\n * @example\n * const text: RawText = { raw: 'jordan.amar' };\n */\nexport type RawText = { raw: string };\n\n/**\n * What a component accepts for a displayed text: a string is a translation key,\n * `{ key, params }` a key with parameters, `{ raw }` a text displayed as is.\n *\n * @example\n * const label: TranslationRequest = 'common.save';\n */\nexport type TranslationRequest = string | TranslationKeyRequest | RawText;\n\n/**\n * Declares the translatable inputs of a component: `Req` are required, `Opt` optional.\n *\n * @example\n * type ButtonI18n = I18nOf<'label', 'caption'>;\n * const i18n: ButtonI18n = { label: 'common.save' };\n */\nexport type I18nOf<Req extends string, Opt extends string = never> = Record<Req, TranslationRequest> &\n Partial<Record<Opt, TranslationRequest>>;\n\n/**\n * Marks a text to display as is: it never reaches the app's `translate`.\n *\n * @example\n * raw('jordan.amar'); // { raw: 'jordan.amar' }\n */\nexport function raw(text: string): RawText {\n return { raw: text };\n}\n\n/**\n * Checks the shape only: an object with a string `raw`, whatever other keys it carries.\n *\n * @example\n * isRawText({ raw: 'x' }); // true\n * isRawText('a.b'); // false\n */\nexport function isRawText(value: unknown): value is RawText {\n return typeof value === 'object' && value !== null && 'raw' in value && typeof value.raw === 'string';\n}\n\n/**\n * Checks the shape only: an object with a string `key`; `params` is not validated.\n *\n * @example\n * isKeyRequest({ key: 'a.b' }); // true\n * isKeyRequest({ label: 'x' }); // false\n */\nexport function isKeyRequest(value: unknown): value is TranslationKeyRequest {\n return typeof value === 'object' && value !== null && 'key' in value && typeof value.key === 'string';\n}\n","import { computed, inject, InjectionToken, isDevMode, Provider, Signal } from '@angular/core';\nimport { fallbackText, UI_COMPONENTS_DEFAULT_TEXTS } from './default-texts';\nimport { DEFAULT_IS_KEY, warnIfNotKey } from './key-guard';\nimport { isKeyRequest, isRawText, TranslationRequest } from './translation.model';\n\n/**\n * How the DS translates the texts it renders, provided by the consuming app.\n *\n * @example\n * const config: UiComponentsTranslation = { translate: (key, params) => catalogue.instant(key, params), language: currentLanguage };\n */\nexport interface UiComponentsTranslation {\n /** Turns a key and its simple params into the text to render. */\n translate: (key: string, params?: Record<string, unknown>) => string;\n /** The app's current language, such as `fr`; texts are recomputed when it changes. */\n language?: Signal<string>;\n /** Used by the dev guard only, never for rendering; defaults to `DEFAULT_IS_KEY`. */\n isKey?: (text: string) => boolean;\n}\n\n/**\n * Holds the app's translation; absent when the app provides none.\n *\n * @example\n * const translation = inject(UI_COMPONENTS_TRANSLATION, { optional: true });\n */\nexport const UI_COMPONENTS_TRANSLATION = new InjectionToken<UiComponentsTranslation>('UI_COMPONENTS_TRANSLATION');\n\n/**\n * Plugs the app's translation into the DS components.\n *\n * @param config the translation, or a factory run in an injection context when it needs `inject()`.\n *\n * @example\n * provideUiComponentsTranslation(() => {\n * const translateService = inject(TranslateService);\n * return { translate: (key, params) => translateService.instant(key, params) };\n * });\n */\nexport function provideUiComponentsTranslation(config: UiComponentsTranslation | (() => UiComponentsTranslation)): Provider {\n return typeof config === 'function'\n ? { provide: UI_COMPONENTS_TRANSLATION, useFactory: config }\n : { provide: UI_COMPONENTS_TRANSLATION, useValue: config };\n}\n\n/**\n * Call in an injection context; the returned function renders a {@link TranslationRequest} and, read inside a\n * `computed`, follows language changes. Resolution rules: `design-specs/patterns/translation.md`.\n *\n * @example\n * const t = injectTranslate();\n * const title = computed(() => t(this.i18n().title, { count: this.count() }));\n */\nexport function injectTranslate(): (request: TranslationRequest | null | undefined, params?: Record<string, unknown>) => string {\n const translation = inject(UI_COMPONENTS_TRANSLATION, { optional: true });\n const defaultTexts = inject(UI_COMPONENTS_DEFAULT_TEXTS);\n const isKey = translation?.isKey ?? DEFAULT_IS_KEY;\n\n function resolve(request: unknown, dsParams?: Record<string, unknown>): string {\n translation?.language?.();\n\n if (request === null || request === undefined || request === '') return '';\n if (typeof request === 'string') {\n warnIfNotKey(request, isKey);\n return translateKey(request, dsParams);\n }\n if (isRawText(request)) return request.raw;\n if (isKeyRequest(request)) {\n if (request.key === '') return '';\n return translateKey(request.key, request.params || dsParams ? { ...request.params, ...definedEntries(dsParams) } : undefined);\n }\n\n if (isDevMode()) {\n console.warn(\n '[ui-components/i18n] Unsupported translation request, expected a key string, { key, params } or { raw }:',\n request\n );\n }\n return '';\n }\n\n function translateKey(key: string, params: Record<string, unknown> | undefined): string {\n const resolvedParams = resolveParams(params);\n if (!translation) return fallbackText(key, resolvedParams, defaultTexts) ?? key;\n\n const translated = translation.translate(key, resolvedParams);\n return translated === key ? (fallbackText(key, resolvedParams, defaultTexts) ?? translated) : translated;\n }\n\n function definedEntries(params: Record<string, unknown> | undefined): Record<string, unknown> {\n return Object.fromEntries(Object.entries(params ?? {}).filter(([, value]) => value !== undefined));\n }\n\n function resolveParams(params: Record<string, unknown> | undefined): Record<string, unknown> | undefined {\n if (!params) return undefined;\n return Object.fromEntries(\n Object.entries(params).map(([name, value]) => [name, isRawText(value) || isKeyRequest(value) ? resolve(value) : value])\n );\n }\n\n return resolve;\n}\n\n/**\n * The app's current language, `undefined` when the app gives none.\n *\n * @example\n * const language = injectLanguage();\n * const locale = computed(() => language() ?? 'en');\n */\nexport function injectLanguage(): Signal<string | undefined> {\n const translation = inject(UI_COMPONENTS_TRANSLATION, { optional: true });\n\n return computed(() => translation?.language?.());\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public_api';\n"],"names":[],"mappings":";;;AAEO,MAAM,aAAa,GAAqC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;AAEhF;;;;;AAKG;MACU,2BAA2B,GAAG,IAAI,cAAc,CAAmC,6BAA6B,EAAE;AAC3H,IAAA,UAAU,EAAE,MAAM;AAClB,IAAA,OAAO,EAAE,MAAM,aAAa;AAC/B,CAAA;AAEK,SAAU,YAAY,CACxB,GAAW,EACX,MAAgC,EAChC,QAA0C,aAAa,EAAA;AAEvD,IAAA,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,CAAC;AAAE,QAAA,OAAO,SAAS;AAEvE,IAAA,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,2BAA2B,EAAE,CAAC,WAAW,EAA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AS;QAC7B,OAAO,MAAM,CAAC,WAAW,CACrB,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,SAAS,CAAC,KAAK,CAAC,IAAI,YAAY,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC,CAAC,CAC1H;IACL;AAEA,IAAA,OAAO,OAAO;AAClB;AAEA;;;;;;AAMG;SACa,cAAc,GAAA;AAC1B,IAAA,MAAM,WAAW,GAAG,MAAM,CAAC,yBAAyB,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IAEzE,OAAO,QAAQ,CAAC,MAAM,WAAW,EAAE,QAAQ,IAAI,CAAC;AACpD;;AClHA;;AAEG;;;;"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@agorapulse/ui-components",
3
3
  "description": "Agorapulse UI Components Library",
4
- "version": "22.5.3",
4
+ "version": "22.5.4",
5
5
  "author": "Benoit Hediard",
6
6
  "repository": {
7
7
  "type": "git",
@@ -121,6 +121,10 @@
121
121
  "types": "./types/agorapulse-ui-components-form-message.d.ts",
122
122
  "default": "./fesm2022/agorapulse-ui-components-form-message.mjs"
123
123
  },
124
+ "./i18n": {
125
+ "types": "./types/agorapulse-ui-components-i18n.d.ts",
126
+ "default": "./fesm2022/agorapulse-ui-components-i18n.mjs"
127
+ },
124
128
  "./icon-button": {
125
129
  "types": "./types/agorapulse-ui-components-icon-button.d.ts",
126
130
  "default": "./fesm2022/agorapulse-ui-components-icon-button.mjs"
@@ -0,0 +1,144 @@
1
+ import * as i0 from '@angular/core';
2
+ import { InjectionToken, PipeTransform, Signal, Provider } from '@angular/core';
3
+
4
+ /**
5
+ * Holds the fallback table read by `injectTranslate`; provide another table to override it, for instance in a test.
6
+ *
7
+ * @example
8
+ * TestBed.configureTestingModule({ providers: [{ provide: UI_COMPONENTS_DEFAULT_TEXTS, useValue: { 'ui-components.ok': 'OK' } }] });
9
+ */
10
+ declare const UI_COMPONENTS_DEFAULT_TEXTS: InjectionToken<Readonly<Record<string, string>>>;
11
+
12
+ /**
13
+ * The default `isKey`: dotted segments, so dotted data such as `example.com` passes too.
14
+ *
15
+ * @example
16
+ * DEFAULT_IS_KEY('report.filter.apply'); // true
17
+ * DEFAULT_IS_KEY('Black Friday 2026'); // false
18
+ */
19
+ declare const DEFAULT_IS_KEY: (text: string) => boolean;
20
+
21
+ /**
22
+ * A translation key with optional interpolation parameters.
23
+ *
24
+ * @example
25
+ * const request: TranslationKeyRequest = { key: 'inbox.unread', params: { count: 3 } };
26
+ */
27
+ type TranslationKeyRequest = {
28
+ key: string;
29
+ params?: Record<string, unknown>;
30
+ };
31
+ /**
32
+ * A text displayed as is, never looked up in a catalogue (user content, names, handles).
33
+ *
34
+ * @example
35
+ * const text: RawText = { raw: 'jordan.amar' };
36
+ */
37
+ type RawText = {
38
+ raw: string;
39
+ };
40
+ /**
41
+ * What a component accepts for a displayed text: a string is a translation key,
42
+ * `{ key, params }` a key with parameters, `{ raw }` a text displayed as is.
43
+ *
44
+ * @example
45
+ * const label: TranslationRequest = 'common.save';
46
+ */
47
+ type TranslationRequest = string | TranslationKeyRequest | RawText;
48
+ /**
49
+ * Declares the translatable inputs of a component: `Req` are required, `Opt` optional.
50
+ *
51
+ * @example
52
+ * type ButtonI18n = I18nOf<'label', 'caption'>;
53
+ * const i18n: ButtonI18n = { label: 'common.save' };
54
+ */
55
+ type I18nOf<Req extends string, Opt extends string = never> = Record<Req, TranslationRequest> & Partial<Record<Opt, TranslationRequest>>;
56
+ /**
57
+ * Marks a text to display as is: it never reaches the app's `translate`.
58
+ *
59
+ * @example
60
+ * raw('jordan.amar'); // { raw: 'jordan.amar' }
61
+ */
62
+ declare function raw(text: string): RawText;
63
+ /**
64
+ * Checks the shape only: an object with a string `raw`, whatever other keys it carries.
65
+ *
66
+ * @example
67
+ * isRawText({ raw: 'x' }); // true
68
+ * isRawText('a.b'); // false
69
+ */
70
+ declare function isRawText(value: unknown): value is RawText;
71
+ /**
72
+ * Checks the shape only: an object with a string `key`; `params` is not validated.
73
+ *
74
+ * @example
75
+ * isKeyRequest({ key: 'a.b' }); // true
76
+ * isKeyRequest({ label: 'x' }); // false
77
+ */
78
+ declare function isKeyRequest(value: unknown): value is TranslationKeyRequest;
79
+
80
+ /**
81
+ * Turns a text into a {@link RawText} so a component displays it as is. `null` and `undefined` give an empty text.
82
+ *
83
+ * @example
84
+ * <ap-button [i18n]="{ label: user.name | apRaw }" />
85
+ */
86
+ declare class RawPipe implements PipeTransform {
87
+ transform(text: string | null | undefined): RawText;
88
+ static ɵfac: i0.ɵɵFactoryDeclaration<RawPipe, never>;
89
+ static ɵpipe: i0.ɵɵPipeDeclaration<RawPipe, "apRaw", true>;
90
+ }
91
+
92
+ /**
93
+ * How the DS translates the texts it renders, provided by the consuming app.
94
+ *
95
+ * @example
96
+ * const config: UiComponentsTranslation = { translate: (key, params) => catalogue.instant(key, params), language: currentLanguage };
97
+ */
98
+ interface UiComponentsTranslation {
99
+ /** Turns a key and its simple params into the text to render. */
100
+ translate: (key: string, params?: Record<string, unknown>) => string;
101
+ /** The app's current language, such as `fr`; texts are recomputed when it changes. */
102
+ language?: Signal<string>;
103
+ /** Used by the dev guard only, never for rendering; defaults to `DEFAULT_IS_KEY`. */
104
+ isKey?: (text: string) => boolean;
105
+ }
106
+ /**
107
+ * Holds the app's translation; absent when the app provides none.
108
+ *
109
+ * @example
110
+ * const translation = inject(UI_COMPONENTS_TRANSLATION, { optional: true });
111
+ */
112
+ declare const UI_COMPONENTS_TRANSLATION: InjectionToken<UiComponentsTranslation>;
113
+ /**
114
+ * Plugs the app's translation into the DS components.
115
+ *
116
+ * @param config the translation, or a factory run in an injection context when it needs `inject()`.
117
+ *
118
+ * @example
119
+ * provideUiComponentsTranslation(() => {
120
+ * const translateService = inject(TranslateService);
121
+ * return { translate: (key, params) => translateService.instant(key, params) };
122
+ * });
123
+ */
124
+ declare function provideUiComponentsTranslation(config: UiComponentsTranslation | (() => UiComponentsTranslation)): Provider;
125
+ /**
126
+ * Call in an injection context; the returned function renders a {@link TranslationRequest} and, read inside a
127
+ * `computed`, follows language changes. Resolution rules: `design-specs/patterns/translation.md`.
128
+ *
129
+ * @example
130
+ * const t = injectTranslate();
131
+ * const title = computed(() => t(this.i18n().title, { count: this.count() }));
132
+ */
133
+ declare function injectTranslate(): (request: TranslationRequest | null | undefined, params?: Record<string, unknown>) => string;
134
+ /**
135
+ * The app's current language, `undefined` when the app gives none.
136
+ *
137
+ * @example
138
+ * const language = injectLanguage();
139
+ * const locale = computed(() => language() ?? 'en');
140
+ */
141
+ declare function injectLanguage(): Signal<string | undefined>;
142
+
143
+ export { DEFAULT_IS_KEY, RawPipe, UI_COMPONENTS_DEFAULT_TEXTS, UI_COMPONENTS_TRANSLATION, injectLanguage, injectTranslate, isKeyRequest, isRawText, provideUiComponentsTranslation, raw };
144
+ export type { I18nOf, RawText, TranslationKeyRequest, TranslationRequest, UiComponentsTranslation };
Binary file