@mmstack/translate 19.2.5 → 19.2.7
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/README.md
CHANGED
|
@@ -61,33 +61,57 @@ import { provideIntlConfig } from '@mmstack/translate';
|
|
|
61
61
|
|
|
62
62
|
const appConfig: Providers = [
|
|
63
63
|
provideIntlConfig({
|
|
64
|
-
defaultLocale: '
|
|
64
|
+
defaultLocale: 'en-US', // defaults to 'en-US' if nothing is provided
|
|
65
65
|
}),
|
|
66
66
|
];
|
|
67
67
|
```
|
|
68
68
|
|
|
69
69
|
```typescript
|
|
70
|
-
|
|
71
|
-
import { ActivatedRoute } from '@angular/router';
|
|
70
|
+
// DEMO impl, how you actually provide LOCALE_ID & what it's based on is up to you, it just has to be available when the resolvers are called
|
|
72
71
|
|
|
73
|
-
|
|
72
|
+
import { Component, LOCALE_ID } from '@angular/core';
|
|
74
73
|
|
|
75
74
|
@Component({
|
|
76
75
|
selector: 'app-locale-shell',
|
|
77
|
-
|
|
78
|
-
{
|
|
79
|
-
provide: LOCALE_ID,
|
|
80
|
-
useFactory: (route: ActivatedRoute) => {
|
|
81
|
-
const locale = route.snapshot.paramMap.get('locale') || 'en-US';
|
|
82
|
-
if (KNOWN_LOCALES.includes(locale)) return locale;
|
|
83
|
-
return 'en-US';
|
|
84
|
-
},
|
|
85
|
-
deps: [ActivatedRoute],
|
|
86
|
-
},
|
|
87
|
-
],
|
|
88
|
-
template: `<ng-content />`,
|
|
76
|
+
template: `<router-outlet />`,
|
|
89
77
|
})
|
|
90
78
|
export class LocaleShellComponent {}
|
|
79
|
+
|
|
80
|
+
// app.routes.ts
|
|
81
|
+
import { Routes, ActivatedRouteSnapshot } from '@angular/router';
|
|
82
|
+
import { Injectable, LOCALE_ID } from '@angular/core';
|
|
83
|
+
import { QuoteComponent } from './quote.component';
|
|
84
|
+
|
|
85
|
+
@Injectable({
|
|
86
|
+
providedIn: 'root',
|
|
87
|
+
})
|
|
88
|
+
export class LocaleStore {
|
|
89
|
+
locale = 'en-US';
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export const routes: Routes = [
|
|
93
|
+
{
|
|
94
|
+
path: ':locale',
|
|
95
|
+
component: LocaleShellComponent,
|
|
96
|
+
resolve: {
|
|
97
|
+
localeId: (route: ActivatedRouteSnapshot) => {
|
|
98
|
+
const locale = route.params['locale'] || 'en-US';
|
|
99
|
+
|
|
100
|
+
return route.params['locale'] || 'en-US';
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
providers: [
|
|
104
|
+
{
|
|
105
|
+
provide: LOCALE_ID,
|
|
106
|
+
useFactory: (store: LocaleStore) => {
|
|
107
|
+
return store.locale;
|
|
108
|
+
},
|
|
109
|
+
deps: [LocaleStore],
|
|
110
|
+
},
|
|
111
|
+
],
|
|
112
|
+
loadChildren: () => import('./quote.routes').then((m) => m.QUOTE_ROUTES),
|
|
113
|
+
},
|
|
114
|
+
];
|
|
91
115
|
```
|
|
92
116
|
|
|
93
117
|
_Note:_ `@mmstack/translate` relies on Angular's `LOCALE_ID` provider. You must provide a value for it. How you determine this value (e.g., hardcoded, from server config, from URL segment via a factory provider) is up to your application's architecture. The library assumes this `LOCALE_ID` is static for the duration of the application session and requires a page refresh to change.
|
|
@@ -129,7 +153,7 @@ export const createQuoteTranslation = ns.createTranslation;
|
|
|
129
153
|
import { createQuoteTranslation } from './quote.namespace';
|
|
130
154
|
|
|
131
155
|
// shape is typesafe (errors if you have missing or additional keys)
|
|
132
|
-
export default createQuoteTranslation({
|
|
156
|
+
export default createQuoteTranslation('sl-SI', {
|
|
133
157
|
pageTitle: 'Znani Citati',
|
|
134
158
|
greeting: 'Zdravo {name}!',
|
|
135
159
|
detail: {
|
|
@@ -152,10 +176,10 @@ import q from './quote.namespace';
|
|
|
152
176
|
// Register the namespace
|
|
153
177
|
// Example: packages/quote/src/lib/quote.t.ts
|
|
154
178
|
const r = registerNamespace(
|
|
155
|
-
() => import('./quote.namespace
|
|
179
|
+
() => import('./quote.namespace').then((m) => m.default), // Default locale's compiled translation (functions as fallback if no locale of type provided)
|
|
156
180
|
{
|
|
157
181
|
// Map other locales to promise factories (dynamic imports)
|
|
158
|
-
'sl-SI': () => import('./quote-sl.translation
|
|
182
|
+
'sl-SI': () => import('./quote-sl.translation').then((m) => m.default),
|
|
159
183
|
},
|
|
160
184
|
);
|
|
161
185
|
|
|
@@ -167,10 +191,10 @@ export const resolveQuoteTranslations = r.resolveNamespaceTranslation;
|
|
|
167
191
|
import { type Routes } from '@angular/router';
|
|
168
192
|
import { resolveQuoteTranslations } from './quote.t';
|
|
169
193
|
|
|
170
|
-
|
|
171
|
-
|
|
194
|
+
// quote.routes.ts
|
|
195
|
+
export const QUOTE_ROUTES: Routes = [
|
|
172
196
|
{
|
|
173
|
-
// ...
|
|
197
|
+
// ... component at or above where the translations need to be available
|
|
174
198
|
resolve: {
|
|
175
199
|
resolveQuoteTranslations,
|
|
176
200
|
},
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { InjectionToken, inject,
|
|
2
|
+
import { InjectionToken, inject, signal, LOCALE_ID, computed, Injectable, isSignal, isDevMode, input, Renderer2, ElementRef, effect, Directive } from '@angular/core';
|
|
3
3
|
import { createIntlCache, createIntl } from '@formatjs/intl';
|
|
4
4
|
|
|
5
5
|
const KEY_DELIM = '::MMT_DELIM::';
|
|
@@ -69,16 +69,16 @@ function injectDefaultLocale() {
|
|
|
69
69
|
class TranslationStore {
|
|
70
70
|
cache = createIntlCache();
|
|
71
71
|
config = injectIntlConfig();
|
|
72
|
-
locale = inject(LOCALE_ID);
|
|
72
|
+
locale = signal(inject(LOCALE_ID));
|
|
73
73
|
defaultLocale = injectDefaultLocale();
|
|
74
74
|
translations = signal({
|
|
75
75
|
[this.defaultLocale]: {},
|
|
76
76
|
});
|
|
77
77
|
nonMessageConfig = computed(() => ({
|
|
78
78
|
...this.config,
|
|
79
|
-
locale: this.locale,
|
|
79
|
+
locale: this.locale(),
|
|
80
80
|
}));
|
|
81
|
-
messages = computed(() => this.translations()[this.locale] ??
|
|
81
|
+
messages = computed(() => this.translations()[this.locale()] ??
|
|
82
82
|
this.translations()[this.defaultLocale] ??
|
|
83
83
|
{});
|
|
84
84
|
intl = computed(() => createIntl({
|
|
@@ -86,12 +86,14 @@ class TranslationStore {
|
|
|
86
86
|
messages: this.messages(),
|
|
87
87
|
}, this.cache));
|
|
88
88
|
formatMessage(key, values) {
|
|
89
|
-
const message = this.translations()[this.locale]?.[key] ?? '';
|
|
89
|
+
const message = this.translations()[this.locale()]?.[key] ?? '';
|
|
90
90
|
if (!message)
|
|
91
91
|
return '';
|
|
92
92
|
return this.intl().formatMessage({ id: key, defaultMessage: message }, values);
|
|
93
93
|
}
|
|
94
|
-
register(namespace, flat) {
|
|
94
|
+
register(namespace, flat, locale) {
|
|
95
|
+
console.log(locale);
|
|
96
|
+
this.locale.set(locale);
|
|
95
97
|
this.translations.update((cur) => {
|
|
96
98
|
return Object.entries(flat).reduce((acc, [locale, translation]) => {
|
|
97
99
|
const localeTranslation = acc[locale] ?? {};
|
|
@@ -187,11 +189,12 @@ function registerNamespace(defaultTranslation, other) {
|
|
|
187
189
|
if (promise !== defaultTranslation &&
|
|
188
190
|
translation.locale !== locale &&
|
|
189
191
|
isDevMode()) {
|
|
192
|
+
console.log('hre');
|
|
190
193
|
return console.warn(`Expected locale to be ${locale} but got ${translation.locale}`);
|
|
191
194
|
}
|
|
192
195
|
store.register(translation.namespace, {
|
|
193
196
|
[locale]: translation.flat,
|
|
194
|
-
});
|
|
197
|
+
}, locale);
|
|
195
198
|
if (promise === defaultTranslation) {
|
|
196
199
|
defaultTranslationLoaded = true;
|
|
197
200
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mmstack-translate.mjs","sources":["../../../../packages/translate/src/lib/delim.ts","../../../../packages/translate/src/lib/compile.ts","../../../../packages/translate/src/lib/create-namespace.ts","../../../../packages/translate/src/lib/translation.store.ts","../../../../packages/translate/src/lib/register-namespace.ts","../../../../packages/translate/src/lib/translate.directive.ts","../../../../packages/translate/src/lib/translate.pipe.ts","../../../../packages/translate/src/mmstack-translate.ts"],"sourcesContent":["const KEY_DELIM = '::MMT_DELIM::';\r\n\r\nexport function prependDelim(prefix: string, key: string): string {\r\n return `${prefix}${KEY_DELIM}${key}`;\r\n}\r\n\r\nexport function replaceWithDelim(str: string, repl = '.'): string {\r\n return str.replaceAll(repl, KEY_DELIM);\r\n}\r\n","import { prependDelim } from './delim';\r\nimport type {\r\n inferTranslationParamMap,\r\n inferTranslationShape,\r\n} from './parameterize.type';\r\nimport type { UnknownStringKeyObject } from './string-key-object.type';\r\n\r\nconst INTERNAL_SYMBOL = Symbol.for('mmstack-translate-internal');\r\n\r\ntype InternalSymbol = typeof INTERNAL_SYMBOL;\r\n\r\nexport type CompiledTranslation<\r\n T extends UnknownStringKeyObject,\r\n TNS extends string,\r\n TLocale extends string = string,\r\n> = {\r\n flat: Record<string, string>;\r\n locale?: TLocale;\r\n namespace: TNS;\r\n [INTERNAL_SYMBOL]: {\r\n shape: inferTranslationShape<T>;\r\n map: inferTranslationParamMap<TNS, T>;\r\n };\r\n};\r\n\r\nexport type mergeTranslationMaps<\r\n TMain extends CompiledTranslation<UnknownStringKeyObject, string>,\r\n TOther extends CompiledTranslation<UnknownStringKeyObject, string>,\r\n> = Omit<TMain, InternalSymbol> & {\r\n [INTERNAL_SYMBOL]: {\r\n shape: inferCompiledTranslationShape<TMain>;\r\n map: inferCompiledTranslationMap<TOther> &\r\n inferCompiledTranslationMap<TMain>;\r\n };\r\n};\r\n\r\nexport type inferCompiledTranslationNamespace<\r\n T extends CompiledTranslation<UnknownStringKeyObject, string>,\r\n> = T['namespace'];\r\n\r\nexport type inferCompiledTranslationShape<\r\n T extends CompiledTranslation<UnknownStringKeyObject, string>,\r\n> = T[InternalSymbol]['shape'];\r\n\r\nexport type inferCompiledTranslationMap<\r\n T extends CompiledTranslation<UnknownStringKeyObject, string>,\r\n> = T[InternalSymbol]['map'];\r\n\r\nfunction isTranslationObject(t: unknown): t is UnknownStringKeyObject {\r\n return typeof t === 'object' && t !== null;\r\n}\r\n\r\nfunction flattenTranslation<T extends UnknownStringKeyObject>(obj: T) {\r\n return Object.entries(obj).reduce(\r\n (acc, [key, value]) => {\r\n if (typeof value === 'string') {\r\n acc[key] = value;\r\n } else if (isTranslationObject(value)) {\r\n Object.entries(flattenTranslation(value)).forEach(\r\n ([nestedKey, nestedValue]) => {\r\n acc[prependDelim(key, nestedKey)] = nestedValue;\r\n },\r\n );\r\n }\r\n\r\n return acc;\r\n },\r\n {} as Record<string, string>,\r\n );\r\n}\r\n\r\nexport function compileTranslation<\r\n T extends UnknownStringKeyObject,\r\n TNS extends string,\r\n TLocale extends string = string,\r\n>(\r\n translation: T,\r\n ns: TNS,\r\n locale?: TLocale,\r\n): CompiledTranslation<T, TNS, TLocale> {\r\n type $Shape = inferTranslationShape<T>;\r\n type $Map = inferTranslationParamMap<TNS, T>;\r\n\r\n return {\r\n locale,\r\n flat: flattenTranslation(translation),\r\n namespace: ns,\r\n [INTERNAL_SYMBOL]: {\r\n shape: {} as $Shape,\r\n map: {} as $Map,\r\n },\r\n };\r\n}\r\n","import {\r\n CompiledTranslation,\r\n compileTranslation,\r\n inferCompiledTranslationShape,\r\n mergeTranslationMaps,\r\n} from './compile';\r\nimport { UnknownStringKeyObject } from './string-key-object.type';\r\n\r\ntype TranslationNamespace<\r\n TNS extends string,\r\n T extends CompiledTranslation<UnknownStringKeyObject, TNS>,\r\n TShape extends UnknownStringKeyObject,\r\n> = {\r\n translation: T;\r\n createTranslation: <TLocale extends string>(\r\n locale: TLocale,\r\n translation: TShape,\r\n ) => CompiledTranslation<TShape, TNS, TLocale>;\r\n createMergedNamespace: <\r\n TOtherNS extends string,\r\n const TOther extends UnknownStringKeyObject,\r\n TOtherCompiled extends CompiledTranslation<TOther, TOtherNS>,\r\n >(\r\n ns: TOtherNS,\r\n translation: TOther,\r\n ) => TranslationNamespace<\r\n TOtherNS,\r\n mergeTranslationMaps<TOtherCompiled, T>,\r\n inferCompiledTranslationShape<TOtherCompiled>\r\n >;\r\n};\r\n\r\nexport function createNamespace<\r\n const T extends UnknownStringKeyObject,\r\n TNS extends string,\r\n>(ns: TNS, translation: T) {\r\n const compiled = compileTranslation<T, TNS>(translation, ns);\r\n\r\n type TCompiled = typeof compiled;\r\n type TShape = inferCompiledTranslationShape<typeof compiled>;\r\n\r\n const namespace: TranslationNamespace<TNS, TCompiled, TShape> = {\r\n translation: compileTranslation(translation, ns),\r\n createTranslation: <TLocale extends string>(\r\n locale: TLocale,\r\n translation: TShape,\r\n ) => {\r\n return compileTranslation(translation, ns, locale);\r\n },\r\n createMergedNamespace: <\r\n TOther extends UnknownStringKeyObject,\r\n TOtherNS extends string,\r\n TOtherCompiled extends CompiledTranslation<\r\n TOther,\r\n TOtherNS\r\n > = CompiledTranslation<TOther, TOtherNS>,\r\n >(\r\n otherNs: TOtherNS,\r\n otherTranslation: TOther,\r\n ) => {\r\n return createNamespace(otherNs, otherTranslation) as TranslationNamespace<\r\n TOtherNS,\r\n mergeTranslationMaps<TOtherCompiled, TCompiled>,\r\n inferCompiledTranslationShape<TOtherCompiled>\r\n > as unknown as any;\r\n },\r\n };\r\n\r\n return namespace;\r\n}\r\n","import {\r\n computed,\r\n inject,\r\n Injectable,\r\n InjectionToken,\r\n LOCALE_ID,\r\n Provider,\r\n signal,\r\n} from '@angular/core';\r\nimport { createIntl, createIntlCache, IntlConfig } from '@formatjs/intl';\r\nimport { prependDelim } from './delim';\r\n\r\nconst CONFIG_TOKEN = new InjectionToken<\r\n Omit<IntlConfig, 'locale' | 'messages'>\r\n>('mmstack-intl-config');\r\n\r\nexport function provideIntlConfig(\r\n config: Omit<IntlConfig, 'locale' | 'messages'>,\r\n): Provider {\r\n return {\r\n useValue: config,\r\n provide: CONFIG_TOKEN,\r\n };\r\n}\r\n\r\nexport function injectIntlConfig() {\r\n return inject(CONFIG_TOKEN, { optional: true }) ?? undefined;\r\n}\r\n\r\nexport function injectDefaultLocale() {\r\n return injectIntlConfig()?.defaultLocale ?? 'en-US';\r\n}\r\n\r\n@Injectable({\r\n providedIn: 'root',\r\n})\r\nexport class TranslationStore {\r\n private readonly cache = createIntlCache();\r\n private readonly config = injectIntlConfig();\r\n private readonly locale = inject(LOCALE_ID);\r\n private readonly defaultLocale = injectDefaultLocale();\r\n private readonly translations = signal<\r\n Record<string, Record<string, string>>\r\n >({\r\n [this.defaultLocale]: {},\r\n });\r\n\r\n private readonly nonMessageConfig = computed(() => ({\r\n ...this.config,\r\n locale: this.locale,\r\n }));\r\n\r\n private readonly messages = computed(\r\n () =>\r\n this.translations()[this.locale] ??\r\n this.translations()[this.defaultLocale] ??\r\n {},\r\n );\r\n\r\n readonly intl = computed(() =>\r\n createIntl(\r\n {\r\n ...this.nonMessageConfig(),\r\n messages: this.messages(),\r\n },\r\n this.cache,\r\n ),\r\n );\r\n\r\n formatMessage(key: string, values?: Record<string, string | number>) {\r\n const message = this.translations()[this.locale]?.[key] ?? '';\r\n\r\n if (!message) return '';\r\n\r\n return this.intl().formatMessage(\r\n { id: key, defaultMessage: message },\r\n values,\r\n );\r\n }\r\n\r\n register(\r\n namespace: string,\r\n flat: Partial<Record<string, Record<string, string>>>,\r\n ) {\r\n this.translations.update((cur) => {\r\n return Object.entries(flat).reduce(\r\n (acc, [locale, translation]) => {\r\n const localeTranslation = acc[locale] ?? {};\r\n\r\n const withNS = Object.entries(translation ?? {}).reduce(\r\n (acc, [key, value]) => {\r\n acc[prependDelim(namespace, key)] = value;\r\n return acc;\r\n },\r\n {} as Record<string, string>,\r\n );\r\n\r\n acc[locale] = {\r\n ...localeTranslation,\r\n ...withNS,\r\n };\r\n\r\n return acc;\r\n },\r\n { ...cur },\r\n );\r\n });\r\n }\r\n}\r\n\r\nexport function injectIntl() {\r\n return inject(TranslationStore).intl;\r\n}\r\n","import {\r\n computed,\r\n inject,\r\n isDevMode,\r\n isSignal,\r\n LOCALE_ID,\r\n Signal,\r\n} from '@angular/core';\r\nimport { CompiledTranslation, inferCompiledTranslationMap } from './compile';\r\nimport { replaceWithDelim } from './delim';\r\nimport { UnknownStringKeyObject } from './string-key-object.type';\r\nimport { TranslationStore } from './translation.store';\r\n\r\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\r\ntype AnyStringRecord = Record<string, any>;\r\n\r\nfunction createEqualsRecord<T extends AnyStringRecord>(keys: (keyof T)[] = []) {\r\n let keyMatcher: (a: T, b: T) => boolean;\r\n\r\n if (keys.length === 0) {\r\n keyMatcher = () => true;\r\n } else if (keys.length === 1) {\r\n const key = keys[0];\r\n keyMatcher = (a, b) => a[key] === b[key];\r\n } else {\r\n keyMatcher = (a, b) => {\r\n return keys.every((k) => a[k] === b[k]);\r\n };\r\n }\r\n\r\n return (a?: T, b?: T): boolean => {\r\n if (!a && !b) return true;\r\n if (!a || !b) return false;\r\n return keyMatcher(a, b);\r\n };\r\n}\r\n\r\ntype TFunction<TMap extends AnyStringRecord> = <\r\n TKey extends keyof TMap & string,\r\n>(\r\n key: TKey,\r\n ...args: TMap[TKey] extends void ? [] : [TMap[TKey]]\r\n) => string;\r\n\r\ntype SignalTFunction<TMap extends AnyStringRecord> = <\r\n TKey extends keyof TMap & string,\r\n>(\r\n key: TKey,\r\n ...args: TMap[TKey] extends void ? [] : [() => TMap[TKey]]\r\n) => Signal<string>;\r\n\r\ntype TFunctionWithSignalConstructor<\r\n TMap extends AnyStringRecord,\r\n TFN extends TFunction<TMap>,\r\n> = TFN & {\r\n asSignal: SignalTFunction<TMap>;\r\n};\r\n\r\nfunction addSignalFn<TMap extends AnyStringRecord, TFn extends TFunction<TMap>>(\r\n fn: TFn,\r\n store: TranslationStore,\r\n): TFunctionWithSignalConstructor<TMap, TFn> {\r\n const withSig = fn as TFunctionWithSignalConstructor<TMap, TFn>;\r\n\r\n const asSignal = <TKey extends keyof TMap & string>(\r\n key: TKey,\r\n ...args: TMap[TKey] extends void ? [] : [() => TMap[TKey]]\r\n ): Signal<string> => {\r\n const variables = args[0] as () => AnyStringRecord | undefined;\r\n const stringKey = key as string;\r\n\r\n const flatPath = replaceWithDelim(stringKey);\r\n\r\n const varsFn = variables === undefined ? () => undefined : variables;\r\n const varsSignal = isSignal(varsFn)\r\n ? varsFn\r\n : computed(varsFn, {\r\n equal: createEqualsRecord(Object.keys(varsFn() ?? {})),\r\n });\r\n\r\n return computed(() => store.formatMessage(flatPath, varsSignal()));\r\n };\r\n\r\n withSig.asSignal = asSignal;\r\n\r\n return withSig;\r\n}\r\n\r\nexport function createT<TMap extends AnyStringRecord>(\r\n store: TranslationStore,\r\n): TFunction<TMap> {\r\n return <TKey extends keyof TMap & string>(\r\n key: TKey,\r\n ...args: TMap[TKey] extends void ? [] : [TMap[TKey]]\r\n ): string => {\r\n const variables = args[0] as AnyStringRecord | undefined;\r\n const stringKey = key as string;\r\n\r\n return store.formatMessage(replaceWithDelim(stringKey), variables);\r\n };\r\n}\r\n\r\nexport function registerNamespace<\r\n TDefault extends CompiledTranslation<UnknownStringKeyObject, string>,\r\n TOther extends CompiledTranslation<UnknownStringKeyObject, string>,\r\n>(\r\n defaultTranslation: () => Promise<TDefault>,\r\n other: Record<string, () => Promise<TOther>>,\r\n) {\r\n type $Map = inferCompiledTranslationMap<TDefault>;\r\n type $BaseTFN = TFunction<$Map>;\r\n type $TFN = TFunctionWithSignalConstructor<$Map, $BaseTFN>;\r\n\r\n const injectT = (): $TFN => {\r\n const store = inject(TranslationStore);\r\n\r\n return addSignalFn(createT(store), store);\r\n };\r\n\r\n let defaultTranslationLoaded = false;\r\n const resolver = async () => {\r\n const locale = inject(LOCALE_ID);\r\n const store = inject(TranslationStore);\r\n\r\n const tPromise = other[locale] as (() => Promise<TOther>) | undefined;\r\n\r\n const promise = tPromise ?? defaultTranslation;\r\n if (!promise && isDevMode()) {\r\n return console.warn(`No translation found for locale: ${locale}`);\r\n }\r\n\r\n if (promise === defaultTranslation && defaultTranslationLoaded) return;\r\n\r\n try {\r\n const translation = await promise();\r\n\r\n if (\r\n promise !== defaultTranslation &&\r\n translation.locale !== locale &&\r\n isDevMode()\r\n ) {\r\n return console.warn(\r\n `Expected locale to be ${locale} but got ${translation.locale}`,\r\n );\r\n }\r\n\r\n store.register(translation.namespace, {\r\n [locale]: translation.flat,\r\n });\r\n if (promise === defaultTranslation) {\r\n defaultTranslationLoaded = true;\r\n }\r\n } catch {\r\n if (isDevMode()) {\r\n console.warn(`Failed to load translation for locale: ${locale}`);\r\n }\r\n }\r\n };\r\n\r\n return {\r\n injectNamespaceT: injectT,\r\n resolveNamespaceTranslation: resolver,\r\n };\r\n}\r\n","import {\r\n computed,\r\n Directive,\r\n effect,\r\n ElementRef,\r\n inject,\r\n input,\r\n Renderer2,\r\n} from '@angular/core';\r\nimport { CompiledTranslation, inferCompiledTranslationMap } from './compile';\r\nimport { createT } from './register-namespace';\r\nimport { UnknownStringKeyObject } from './string-key-object.type';\r\nimport { TranslationStore } from './translation.store';\r\n\r\n@Directive()\r\nexport abstract class BaseTranslateDirective<\r\n TInput extends string,\r\n T extends CompiledTranslation<UnknownStringKeyObject, string>,\r\n TMap extends inferCompiledTranslationMap<T> = inferCompiledTranslationMap<T>,\r\n TKey extends TInput & keyof TMap & string = TInput & keyof TMap & string,\r\n> {\r\n private readonly t = createT(inject(TranslationStore));\r\n\r\n readonly translate =\r\n input.required<\r\n TMap[TKey] extends void\r\n ? TKey | [key: TKey]\r\n : [key: TKey, vars: TMap[TKey]]\r\n >();\r\n\r\n constructor() {\r\n const key = computed(() => {\r\n const vars = this.translate();\r\n return (Array.isArray(vars) ? vars[0] : vars) as TKey;\r\n });\r\n\r\n const args = computed(\r\n () => {\r\n const vars = this.translate();\r\n return (Array.isArray(vars) ? vars[1] : undefined) as TMap[TKey];\r\n },\r\n {\r\n equal: (a, b) => {\r\n if (a === undefined && b === undefined) return true;\r\n if (a === undefined || b === undefined) return false;\r\n\r\n const aObj = a as Record<string, string>;\r\n const keys = Object.keys(aObj);\r\n const bObj = b as Record<string, string>;\r\n\r\n if (!keys.length) return !Object.keys(bObj).length;\r\n\r\n return keys.every((key) => aObj[key] === bObj[key]);\r\n },\r\n },\r\n );\r\n\r\n const translation = computed(() => this.t(key(), args()));\r\n\r\n const renderer = inject(Renderer2);\r\n const el = inject<ElementRef<HTMLElement>>(ElementRef);\r\n\r\n effect(() =>\r\n renderer.setProperty(el.nativeElement, 'textContent', translation()),\r\n );\r\n }\r\n}\r\n","import { inject } from '@angular/core';\r\nimport { CompiledTranslation, inferCompiledTranslationMap } from './compile';\r\nimport { createT } from './register-namespace';\r\nimport { UnknownStringKeyObject } from './string-key-object.type';\r\nimport { TranslationStore } from './translation.store';\r\n\r\nexport abstract class BaseTranslatePipe<\r\n T extends CompiledTranslation<UnknownStringKeyObject, string>,\r\n TMap extends inferCompiledTranslationMap<T> = inferCompiledTranslationMap<T>,\r\n> {\r\n private readonly t = createT<TMap>(inject(TranslationStore));\r\n\r\n transform<K extends keyof TMap & string>(\r\n key: K,\r\n ...args: TMap[K] extends void ? [] : [TMap[K]]\r\n ): string {\r\n return this.t(key, ...args);\r\n }\r\n}\r\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;AAAA,MAAM,SAAS,GAAG,eAAe;AAEjB,SAAA,YAAY,CAAC,MAAc,EAAE,GAAW,EAAA;AACtD,IAAA,OAAO,GAAG,MAAM,CAAA,EAAG,SAAS,CAAG,EAAA,GAAG,EAAE;AACtC;SAEgB,gBAAgB,CAAC,GAAW,EAAE,IAAI,GAAG,GAAG,EAAA;IACtD,OAAO,GAAG,CAAC,UAAU,CAAC,IAAI,EAAE,SAAS,CAAC;AACxC;;ACDA,MAAM,eAAe,GAAG,MAAM,CAAC,GAAG,CAAC,4BAA4B,CAAC;AAyChE,SAAS,mBAAmB,CAAC,CAAU,EAAA;IACrC,OAAO,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KA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ACF;AAED,QAAA,MAAM,WAAW,GAAG,QAAQ,CAAC,MAAM,IAAI,CAAC,CAAC,CAAC,GAAG,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;AAEzD,QAAA,MAAM,QAAQ,GAAG,MAAM,CAAC,SAAS,CAAC;AAClC,QAAA,MAAM,EAAE,GAAG,MAAM,CAA0B,UAAU,CAAC;AAEtD,QAAA,MAAM,CAAC,MACL,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC,aAAa,EAAE,aAAa,EAAE,WAAW,EAAE,CAAC,CACrE;;uGAjDiB,sBAAsB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,SAAA,EAAA,CAAA;2FAAtB,sBAAsB,EAAA,YAAA,EAAA,IAAA,EAAA,MAAA,EAAA,EAAA,SAAA,EAAA,EAAA,iBAAA,EAAA,WAAA,EAAA,UAAA,EAAA,WAAA,EAAA,QAAA,EAAA,IAAA,EAAA,UAAA,EAAA,IAAA,EAAA,iBAAA,EAAA,IAAA,EAAA,EAAA,EAAA,QAAA,EAAA,EAAA,EAAA,CAAA;;2FAAtB,sBAAsB,EAAA,UAAA,EAAA,CAAA;kBAD3C;;;MCRqB,iBAAiB,CAAA;IAIpB,CAAC,GAAG,OAAO,CAAO,MAAM,CAAC,gBAAgB,CAAC,CAAC;AAE5D,IAAA,SAAS,CACP,GAAM,EACN,GAAG,IAA2C,EAAA;QAE9C,OAAO,IAAI,CAAC,CAAC,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;;AAE9B;;AClBD;;AAEG;;;;"}
|
|
1
|
+
{"version":3,"file":"mmstack-translate.mjs","sources":["../../../../packages/translate/src/lib/delim.ts","../../../../packages/translate/src/lib/compile.ts","../../../../packages/translate/src/lib/create-namespace.ts","../../../../packages/translate/src/lib/translation.store.ts","../../../../packages/translate/src/lib/register-namespace.ts","../../../../packages/translate/src/lib/translate.directive.ts","../../../../packages/translate/src/lib/translate.pipe.ts","../../../../packages/translate/src/mmstack-translate.ts"],"sourcesContent":["const KEY_DELIM = '::MMT_DELIM::';\r\n\r\nexport function prependDelim(prefix: string, key: string): string {\r\n return `${prefix}${KEY_DELIM}${key}`;\r\n}\r\n\r\nexport function replaceWithDelim(str: string, repl = '.'): string {\r\n return str.replaceAll(repl, KEY_DELIM);\r\n}\r\n","import { prependDelim } from './delim';\r\nimport type {\r\n inferTranslationParamMap,\r\n inferTranslationShape,\r\n} from './parameterize.type';\r\nimport type { UnknownStringKeyObject } from './string-key-object.type';\r\n\r\nconst INTERNAL_SYMBOL = Symbol.for('mmstack-translate-internal');\r\n\r\ntype InternalSymbol = typeof INTERNAL_SYMBOL;\r\n\r\nexport type CompiledTranslation<\r\n T extends UnknownStringKeyObject,\r\n TNS extends string,\r\n TLocale extends string = string,\r\n> = {\r\n flat: Record<string, string>;\r\n locale?: TLocale;\r\n namespace: TNS;\r\n [INTERNAL_SYMBOL]: {\r\n shape: inferTranslationShape<T>;\r\n map: inferTranslationParamMap<TNS, T>;\r\n };\r\n};\r\n\r\nexport type mergeTranslationMaps<\r\n TMain extends CompiledTranslation<UnknownStringKeyObject, string>,\r\n TOther extends CompiledTranslation<UnknownStringKeyObject, string>,\r\n> = Omit<TMain, InternalSymbol> & {\r\n [INTERNAL_SYMBOL]: {\r\n shape: inferCompiledTranslationShape<TMain>;\r\n map: inferCompiledTranslationMap<TOther> &\r\n inferCompiledTranslationMap<TMain>;\r\n };\r\n};\r\n\r\nexport type inferCompiledTranslationNamespace<\r\n T extends CompiledTranslation<UnknownStringKeyObject, string>,\r\n> = T['namespace'];\r\n\r\nexport type inferCompiledTranslationShape<\r\n T extends CompiledTranslation<UnknownStringKeyObject, string>,\r\n> = T[InternalSymbol]['shape'];\r\n\r\nexport type inferCompiledTranslationMap<\r\n T extends CompiledTranslation<UnknownStringKeyObject, string>,\r\n> = T[InternalSymbol]['map'];\r\n\r\nfunction isTranslationObject(t: unknown): t is UnknownStringKeyObject {\r\n return typeof t === 'object' && t !== null;\r\n}\r\n\r\nfunction flattenTranslation<T extends UnknownStringKeyObject>(obj: T) {\r\n return Object.entries(obj).reduce(\r\n (acc, [key, value]) => {\r\n if (typeof value === 'string') {\r\n acc[key] = value;\r\n } else if (isTranslationObject(value)) {\r\n Object.entries(flattenTranslation(value)).forEach(\r\n ([nestedKey, nestedValue]) => {\r\n acc[prependDelim(key, nestedKey)] = nestedValue;\r\n },\r\n );\r\n }\r\n\r\n return acc;\r\n },\r\n {} as Record<string, string>,\r\n );\r\n}\r\n\r\nexport function compileTranslation<\r\n T extends UnknownStringKeyObject,\r\n TNS extends string,\r\n TLocale extends string = string,\r\n>(\r\n translation: T,\r\n ns: TNS,\r\n locale?: TLocale,\r\n): CompiledTranslation<T, TNS, TLocale> {\r\n type $Shape = inferTranslationShape<T>;\r\n type $Map = inferTranslationParamMap<TNS, T>;\r\n\r\n return {\r\n locale,\r\n flat: flattenTranslation(translation),\r\n namespace: ns,\r\n [INTERNAL_SYMBOL]: {\r\n shape: {} as $Shape,\r\n map: {} as $Map,\r\n },\r\n };\r\n}\r\n","import {\r\n CompiledTranslation,\r\n compileTranslation,\r\n inferCompiledTranslationShape,\r\n mergeTranslationMaps,\r\n} from './compile';\r\nimport { UnknownStringKeyObject } from './string-key-object.type';\r\n\r\ntype TranslationNamespace<\r\n TNS extends string,\r\n T extends CompiledTranslation<UnknownStringKeyObject, TNS>,\r\n TShape extends UnknownStringKeyObject,\r\n> = {\r\n translation: T;\r\n createTranslation: <TLocale extends string>(\r\n locale: TLocale,\r\n translation: TShape,\r\n ) => CompiledTranslation<TShape, TNS, TLocale>;\r\n createMergedNamespace: <\r\n TOtherNS extends string,\r\n const TOther extends UnknownStringKeyObject,\r\n TOtherCompiled extends CompiledTranslation<TOther, TOtherNS>,\r\n >(\r\n ns: TOtherNS,\r\n translation: TOther,\r\n ) => TranslationNamespace<\r\n TOtherNS,\r\n mergeTranslationMaps<TOtherCompiled, T>,\r\n inferCompiledTranslationShape<TOtherCompiled>\r\n >;\r\n};\r\n\r\nexport function createNamespace<\r\n const T extends UnknownStringKeyObject,\r\n TNS extends string,\r\n>(ns: TNS, translation: T) {\r\n const compiled = compileTranslation<T, TNS>(translation, ns);\r\n\r\n type TCompiled = typeof compiled;\r\n type TShape = inferCompiledTranslationShape<typeof compiled>;\r\n\r\n const namespace: TranslationNamespace<TNS, TCompiled, TShape> = {\r\n translation: compileTranslation(translation, ns),\r\n createTranslation: <TLocale extends string>(\r\n locale: TLocale,\r\n translation: TShape,\r\n ) => {\r\n return compileTranslation(translation, ns, locale);\r\n },\r\n createMergedNamespace: <\r\n TOther extends UnknownStringKeyObject,\r\n TOtherNS extends string,\r\n TOtherCompiled extends CompiledTranslation<\r\n TOther,\r\n TOtherNS\r\n > = CompiledTranslation<TOther, TOtherNS>,\r\n >(\r\n otherNs: TOtherNS,\r\n otherTranslation: TOther,\r\n ) => {\r\n return createNamespace(otherNs, otherTranslation) as TranslationNamespace<\r\n TOtherNS,\r\n mergeTranslationMaps<TOtherCompiled, TCompiled>,\r\n inferCompiledTranslationShape<TOtherCompiled>\r\n > as unknown as any;\r\n },\r\n };\r\n\r\n return namespace;\r\n}\r\n","import {\r\n computed,\r\n inject,\r\n Injectable,\r\n InjectionToken,\r\n LOCALE_ID,\r\n Provider,\r\n signal,\r\n} from '@angular/core';\r\nimport { createIntl, createIntlCache, IntlConfig } from '@formatjs/intl';\r\nimport { prependDelim } from './delim';\r\n\r\nconst CONFIG_TOKEN = new InjectionToken<\r\n Omit<IntlConfig, 'locale' | 'messages'>\r\n>('mmstack-intl-config');\r\n\r\nexport function provideIntlConfig(\r\n config: Omit<IntlConfig, 'locale' | 'messages'>,\r\n): Provider {\r\n return {\r\n useValue: config,\r\n provide: CONFIG_TOKEN,\r\n };\r\n}\r\n\r\nexport function injectIntlConfig() {\r\n return inject(CONFIG_TOKEN, { optional: true }) ?? undefined;\r\n}\r\n\r\nexport function injectDefaultLocale() {\r\n return injectIntlConfig()?.defaultLocale ?? 'en-US';\r\n}\r\n\r\n@Injectable({\r\n providedIn: 'root',\r\n})\r\nexport class TranslationStore {\r\n private readonly cache = createIntlCache();\r\n private readonly config = injectIntlConfig();\r\n private readonly locale = signal(inject(LOCALE_ID));\r\n private readonly defaultLocale = injectDefaultLocale();\r\n private readonly translations = signal<\r\n Record<string, Record<string, string>>\r\n >({\r\n [this.defaultLocale]: {},\r\n });\r\n\r\n private readonly nonMessageConfig = computed(() => ({\r\n ...this.config,\r\n locale: this.locale(),\r\n }));\r\n\r\n private readonly messages = computed(\r\n () =>\r\n this.translations()[this.locale()] ??\r\n this.translations()[this.defaultLocale] ??\r\n {},\r\n );\r\n\r\n readonly intl = computed(() =>\r\n createIntl(\r\n {\r\n ...this.nonMessageConfig(),\r\n messages: this.messages(),\r\n },\r\n this.cache,\r\n ),\r\n );\r\n\r\n formatMessage(key: string, values?: Record<string, string | number>) {\r\n const message = this.translations()[this.locale()]?.[key] ?? '';\r\n\r\n if (!message) return '';\r\n\r\n return this.intl().formatMessage(\r\n { id: key, defaultMessage: message },\r\n values,\r\n );\r\n }\r\n\r\n register(\r\n namespace: string,\r\n flat: Partial<Record<string, Record<string, string>>>,\r\n locale: string,\r\n ) {\r\n console.log(locale);\r\n this.locale.set(locale);\r\n this.translations.update((cur) => {\r\n return Object.entries(flat).reduce(\r\n (acc, [locale, translation]) => {\r\n const localeTranslation = acc[locale] ?? {};\r\n\r\n const withNS = Object.entries(translation ?? {}).reduce(\r\n (acc, [key, value]) => {\r\n acc[prependDelim(namespace, key)] = value;\r\n return acc;\r\n },\r\n {} as Record<string, string>,\r\n );\r\n\r\n acc[locale] = {\r\n ...localeTranslation,\r\n ...withNS,\r\n };\r\n\r\n return acc;\r\n },\r\n { ...cur },\r\n );\r\n });\r\n }\r\n}\r\n\r\nexport function injectIntl() {\r\n return inject(TranslationStore).intl;\r\n}\r\n","import {\r\n computed,\r\n inject,\r\n isDevMode,\r\n isSignal,\r\n LOCALE_ID,\r\n Signal,\r\n} from '@angular/core';\r\nimport { CompiledTranslation, inferCompiledTranslationMap } from './compile';\r\nimport { replaceWithDelim } from './delim';\r\nimport { UnknownStringKeyObject } from './string-key-object.type';\r\nimport { TranslationStore } from './translation.store';\r\n\r\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\r\ntype AnyStringRecord = Record<string, any>;\r\n\r\nfunction createEqualsRecord<T extends AnyStringRecord>(keys: (keyof T)[] = []) {\r\n let keyMatcher: (a: T, b: T) => boolean;\r\n\r\n if (keys.length === 0) {\r\n keyMatcher = () => true;\r\n } else if (keys.length === 1) {\r\n const key = keys[0];\r\n keyMatcher = (a, b) => a[key] === b[key];\r\n } else {\r\n keyMatcher = (a, b) => {\r\n return keys.every((k) => a[k] === b[k]);\r\n };\r\n }\r\n\r\n return (a?: T, b?: T): boolean => {\r\n if (!a && !b) return true;\r\n if (!a || !b) return false;\r\n return keyMatcher(a, b);\r\n };\r\n}\r\n\r\ntype TFunction<TMap extends AnyStringRecord> = <\r\n TKey extends keyof TMap & string,\r\n>(\r\n key: TKey,\r\n ...args: TMap[TKey] extends void ? [] : [TMap[TKey]]\r\n) => string;\r\n\r\ntype SignalTFunction<TMap extends AnyStringRecord> = <\r\n TKey extends keyof TMap & string,\r\n>(\r\n key: TKey,\r\n ...args: TMap[TKey] extends void ? [] : [() => TMap[TKey]]\r\n) => Signal<string>;\r\n\r\ntype TFunctionWithSignalConstructor<\r\n TMap extends AnyStringRecord,\r\n TFN extends TFunction<TMap>,\r\n> = TFN & {\r\n asSignal: SignalTFunction<TMap>;\r\n};\r\n\r\nfunction addSignalFn<TMap extends AnyStringRecord, TFn extends TFunction<TMap>>(\r\n fn: TFn,\r\n store: TranslationStore,\r\n): TFunctionWithSignalConstructor<TMap, TFn> {\r\n const withSig = fn as TFunctionWithSignalConstructor<TMap, TFn>;\r\n\r\n const asSignal = <TKey extends keyof TMap & string>(\r\n key: TKey,\r\n ...args: TMap[TKey] extends void ? [] : [() => TMap[TKey]]\r\n ): Signal<string> => {\r\n const variables = args[0] as () => AnyStringRecord | undefined;\r\n const stringKey = key as string;\r\n\r\n const flatPath = replaceWithDelim(stringKey);\r\n\r\n const varsFn = variables === undefined ? () => undefined : variables;\r\n const varsSignal = isSignal(varsFn)\r\n ? varsFn\r\n : computed(varsFn, {\r\n equal: createEqualsRecord(Object.keys(varsFn() ?? {})),\r\n });\r\n\r\n return computed(() => store.formatMessage(flatPath, varsSignal()));\r\n };\r\n\r\n withSig.asSignal = asSignal;\r\n\r\n return withSig;\r\n}\r\n\r\nexport function createT<TMap extends AnyStringRecord>(\r\n store: TranslationStore,\r\n): TFunction<TMap> {\r\n return <TKey extends keyof TMap & string>(\r\n key: TKey,\r\n ...args: TMap[TKey] extends void ? [] : [TMap[TKey]]\r\n ): string => {\r\n const variables = args[0] as AnyStringRecord | undefined;\r\n const stringKey = key as string;\r\n\r\n return store.formatMessage(replaceWithDelim(stringKey), variables);\r\n };\r\n}\r\n\r\nexport function registerNamespace<\r\n TDefault extends CompiledTranslation<UnknownStringKeyObject, string>,\r\n TOther extends CompiledTranslation<UnknownStringKeyObject, string>,\r\n>(\r\n defaultTranslation: () => Promise<TDefault>,\r\n other: Record<string, () => Promise<TOther>>,\r\n) {\r\n type $Map = inferCompiledTranslationMap<TDefault>;\r\n type $BaseTFN = TFunction<$Map>;\r\n type $TFN = TFunctionWithSignalConstructor<$Map, $BaseTFN>;\r\n\r\n const injectT = (): $TFN => {\r\n const store = inject(TranslationStore);\r\n\r\n return addSignalFn(createT(store), store);\r\n };\r\n\r\n let defaultTranslationLoaded = false;\r\n const resolver = async () => {\r\n const locale = inject(LOCALE_ID);\r\n const store = inject(TranslationStore);\r\n\r\n const tPromise = other[locale] as (() => Promise<TOther>) | undefined;\r\n\r\n const promise = tPromise ?? defaultTranslation;\r\n if (!promise && isDevMode()) {\r\n return console.warn(`No translation found for locale: ${locale}`);\r\n }\r\n\r\n if (promise === defaultTranslation && defaultTranslationLoaded) return;\r\n\r\n try {\r\n const translation = await promise();\r\n\r\n if (\r\n promise !== defaultTranslation &&\r\n translation.locale !== locale &&\r\n isDevMode()\r\n ) {\r\n console.log('hre');\r\n return console.warn(\r\n `Expected locale to be ${locale} but got ${translation.locale}`,\r\n );\r\n }\r\n\r\n store.register(\r\n translation.namespace,\r\n {\r\n [locale]: translation.flat,\r\n },\r\n locale,\r\n );\r\n if (promise === defaultTranslation) {\r\n defaultTranslationLoaded = true;\r\n }\r\n } catch {\r\n if (isDevMode()) {\r\n console.warn(`Failed to load translation for locale: ${locale}`);\r\n }\r\n }\r\n };\r\n\r\n return {\r\n injectNamespaceT: injectT,\r\n resolveNamespaceTranslation: resolver,\r\n };\r\n}\r\n","import {\r\n computed,\r\n Directive,\r\n effect,\r\n ElementRef,\r\n inject,\r\n input,\r\n Renderer2,\r\n} from '@angular/core';\r\nimport { CompiledTranslation, inferCompiledTranslationMap } from './compile';\r\nimport { createT } from './register-namespace';\r\nimport { UnknownStringKeyObject } from './string-key-object.type';\r\nimport { TranslationStore } from './translation.store';\r\n\r\n@Directive()\r\nexport abstract class BaseTranslateDirective<\r\n TInput extends string,\r\n T extends CompiledTranslation<UnknownStringKeyObject, string>,\r\n TMap extends inferCompiledTranslationMap<T> = inferCompiledTranslationMap<T>,\r\n TKey extends TInput & keyof TMap & string = TInput & keyof TMap & string,\r\n> {\r\n private readonly t = createT(inject(TranslationStore));\r\n\r\n readonly translate =\r\n input.required<\r\n TMap[TKey] extends void\r\n ? TKey | [key: TKey]\r\n : [key: TKey, vars: TMap[TKey]]\r\n >();\r\n\r\n constructor() {\r\n const key = computed(() => {\r\n const vars = this.translate();\r\n return (Array.isArray(vars) ? vars[0] : vars) as TKey;\r\n });\r\n\r\n const args = computed(\r\n () => {\r\n const vars = this.translate();\r\n return (Array.isArray(vars) ? vars[1] : undefined) as TMap[TKey];\r\n },\r\n {\r\n equal: (a, b) => {\r\n if (a === undefined && b === undefined) return true;\r\n if (a === undefined || b === undefined) return false;\r\n\r\n const aObj = a as Record<string, string>;\r\n const keys = Object.keys(aObj);\r\n const bObj = b as Record<string, string>;\r\n\r\n if (!keys.length) return !Object.keys(bObj).length;\r\n\r\n return keys.every((key) => aObj[key] === bObj[key]);\r\n },\r\n },\r\n );\r\n\r\n const translation = computed(() => this.t(key(), args()));\r\n\r\n const renderer = inject(Renderer2);\r\n const el = inject<ElementRef<HTMLElement>>(ElementRef);\r\n\r\n effect(() =>\r\n renderer.setProperty(el.nativeElement, 'textContent', translation()),\r\n );\r\n }\r\n}\r\n","import { inject } from '@angular/core';\r\nimport { CompiledTranslation, inferCompiledTranslationMap } from './compile';\r\nimport { createT } from './register-namespace';\r\nimport { UnknownStringKeyObject } from './string-key-object.type';\r\nimport { TranslationStore } from './translation.store';\r\n\r\nexport abstract class BaseTranslatePipe<\r\n T extends CompiledTranslation<UnknownStringKeyObject, string>,\r\n TMap extends inferCompiledTranslationMap<T> = inferCompiledTranslationMap<T>,\r\n> {\r\n private readonly t = createT<TMap>(inject(TranslationStore));\r\n\r\n transform<K extends keyof TMap & string>(\r\n key: K,\r\n ...args: TMap[K] extends void ? [] : [TMap[K]]\r\n ): string {\r\n return this.t(key, ...args);\r\n }\r\n}\r\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;AAAA,MAAM,SAAS,GAAG,eAAe;AAEjB,SAAA,YAAY,CAAC,MAAc,EAAE,GAAW,EAAA;AACtD,IAAA,OAAO,GAAG,MAAM,CAAA,EAAG,SAAS,CAAG,EAAA,GAAG,EAAE;AACtC;SAEgB,gBAAgB,CAAC,GAAW,EAAE,IAAI,GAAG,GAAG,EAAA;IACtD,OAAO,GAAG,CAAC,UAAU,CAAC,IAAI,EAAE,SAAS,CAAC;AACxC;;ACDA,MAAM,eAAe,GAAG,MAAM,CAAC,GAAG,CAAC,4BAA4B,CAAC;AAyChE,SAAS,mBAAmB,CAAC,CAAU,EAAA;IACrC,OAAO,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,IAAI;AAC5C;AAEA,SAAS,kBAA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|
15
15
|
readonly intl: import("@angular/core").Signal<import("@formatjs/intl").IntlShape<string>>;
|
|
16
16
|
formatMessage(key: string, values?: Record<string, string | number>): string;
|
|
17
|
-
register(namespace: string, flat: Partial<Record<string, Record<string, string
|
|
17
|
+
register(namespace: string, flat: Partial<Record<string, Record<string, string>>>, locale: string): void;
|
|
18
18
|
static ɵfac: i0.ɵɵFactoryDeclaration<TranslationStore, never>;
|
|
19
19
|
static ɵprov: i0.ɵɵInjectableDeclaration<TranslationStore>;
|
|
20
20
|
}
|