@mmstack/translate 19.2.8 → 19.3.1

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,69 @@
1
+ import { type Provider, type Signal, type WritableSignal } from '@angular/core';
2
+ import { type IntlConfig } from '@formatjs/intl';
3
+ import * as i0 from "@angular/core";
4
+ export declare function provideIntlConfig(config: Omit<IntlConfig, 'locale' | 'messages'> & {
5
+ /** Checks next locale is in provided array before switching locales */
6
+ supportedLocales?: string[];
7
+ /** Preloads the default locale ensuring sync fallback, not necessary for most cases as it will lazily load automatically when needed */
8
+ preloadDefaultLocale?: boolean;
9
+ /** Auto-resolution when using a locale parameter via angular router */
10
+ localeParamName?: string;
11
+ }): Provider[];
12
+ export declare function injectIntlConfig(): (Omit<IntlConfig, "messages" | "locale"> & {
13
+ supportedLocales?: string[];
14
+ preloadDefaultLocale?: boolean;
15
+ localeParamName?: string;
16
+ }) | undefined;
17
+ export declare function injectDefaultLocale(): string;
18
+ export declare function injectSupportedLocales(): string[];
19
+ export declare function injectLocaleInternal(): WritableSignal<string>;
20
+ export declare class TranslationStore {
21
+ private readonly cache;
22
+ private readonly config;
23
+ readonly loadQueue: WritableSignal<string[]>;
24
+ readonly locale: WritableSignal<string>;
25
+ private readonly defaultLocale;
26
+ private readonly translations;
27
+ private attemptedFallbackLoad;
28
+ private readonly onDemandLoaders;
29
+ private readonly nonMessageConfig;
30
+ private readonly messages;
31
+ readonly dynamicLocaleLoader: import("@angular/core").ResourceRef<{
32
+ locales: {
33
+ namespace: string;
34
+ flat: Record<string, string>;
35
+ }[];
36
+ locale: string;
37
+ } | undefined>;
38
+ readonly intl: Signal<import("@formatjs/intl").IntlShape<string>>;
39
+ constructor();
40
+ formatMessage(key: string, values?: Record<string, string | number>): string;
41
+ register(namespace: string, flat: Partial<Record<string, Record<string, string>>>): void;
42
+ registerOnDemandLoaders(namespace: string, loaders: Record<string, () => Promise<any>>): void;
43
+ hasLocaleLoaders(locale: string): boolean;
44
+ static ɵfac: i0.ɵɵFactoryDeclaration<TranslationStore, never>;
45
+ static ɵprov: i0.ɵɵInjectableDeclaration<TranslationStore>;
46
+ }
47
+ export declare function injectIntl(): Signal<import("@formatjs/intl").IntlShape<string>>;
48
+ /**
49
+ * Inject a dynamic locale signal that supports runtime language switching.
50
+ *
51
+ * @returns A writable signal with the current locale and loading state.
52
+ * Only allows switching to locales that have registered loaders.
53
+ *
54
+ * @example
55
+ * ```typescript
56
+ * const locale = injectDynamicLocale();
57
+ *
58
+ * // Switch language (triggers automatic translation loading)
59
+ * locale.set('sl-SI');
60
+ *
61
+ * // Check loading state
62
+ * if (locale.isLoading()) {
63
+ * // Show spinner
64
+ * }
65
+ * ```
66
+ */
67
+ export declare function injectDynamicLocale(): WritableSignal<string> & {
68
+ isLoading: Signal<boolean>;
69
+ };
@@ -0,0 +1,8 @@
1
+ import { CompiledTranslation, inferCompiledTranslationMap } from './compile';
2
+ import { UnknownStringKeyObject } from './string-key-object.type';
3
+ export declare abstract class Translator<T extends CompiledTranslation<UnknownStringKeyObject, string>, TMap extends inferCompiledTranslationMap<T> = inferCompiledTranslationMap<T>> {
4
+ private readonly store;
5
+ private readonly t;
6
+ constructor();
7
+ transform<K extends keyof TMap & string>(key: K, ...args: TMap[K] extends void ? [locale?: string] : [TMap[K], locale?: string]): string;
8
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mmstack/translate",
3
- "version": "19.2.8",
3
+ "version": "19.3.1",
4
4
  "keywords": [
5
5
  "angular",
6
6
  "localize",
@@ -14,8 +14,9 @@
14
14
  "url": "https://github.com/mihajm/mmstack"
15
15
  },
16
16
  "peerDependencies": {
17
- "@angular/core": "~19.2.3",
18
- "@formatjs/intl": "~3.1.6"
17
+ "@angular/core": ">=19 <20",
18
+ "@angular/router": ">=19 <20",
19
+ "@formatjs/intl": "~3.1.8 || ^4.0.0"
19
20
  },
20
21
  "homepage": "https://github.com/mihajm/mmstack/blob/master/packages/translate",
21
22
  "sideEffects": false,
@@ -1,10 +0,0 @@
1
- import { CompiledTranslation, inferCompiledTranslationMap } from './compile';
2
- import { UnknownStringKeyObject } from './string-key-object.type';
3
- import * as i0 from "@angular/core";
4
- export declare abstract class BaseTranslateDirective<TInput extends string, T extends CompiledTranslation<UnknownStringKeyObject, string>, TMap extends inferCompiledTranslationMap<T> = inferCompiledTranslationMap<T>, TKey extends TInput & keyof TMap & string = TInput & keyof TMap & string> {
5
- private readonly t;
6
- readonly translate: import("@angular/core").InputSignal<TMap[TKey] extends void ? TKey | [key: TKey] : [key: TKey, vars: TMap[TKey]]>;
7
- constructor();
8
- static ɵfac: i0.ɵɵFactoryDeclaration<BaseTranslateDirective<any, any, any, any>, never>;
9
- static ɵdir: i0.ɵɵDirectiveDeclaration<BaseTranslateDirective<any, any, any, any>, never, never, { "translate": { "alias": "translate"; "required": true; "isSignal": true; }; }, {}, never, never, true, never>;
10
- }
@@ -1,6 +0,0 @@
1
- import { CompiledTranslation, inferCompiledTranslationMap } from './compile';
2
- import { UnknownStringKeyObject } from './string-key-object.type';
3
- export declare abstract class BaseTranslatePipe<T extends CompiledTranslation<UnknownStringKeyObject, string>, TMap extends inferCompiledTranslationMap<T> = inferCompiledTranslationMap<T>> {
4
- private readonly t;
5
- transform<K extends keyof TMap & string>(key: K, ...args: TMap[K] extends void ? [] : [TMap[K]]): string;
6
- }
@@ -1,21 +0,0 @@
1
- import { Provider } from '@angular/core';
2
- import { IntlConfig } from '@formatjs/intl';
3
- import * as i0 from "@angular/core";
4
- export declare function provideIntlConfig(config: Omit<IntlConfig, 'locale' | 'messages'>): Provider;
5
- export declare function injectIntlConfig(): Omit<IntlConfig, "messages" | "locale"> | undefined;
6
- export declare function injectDefaultLocale(): string;
7
- export declare class TranslationStore {
8
- private readonly cache;
9
- private readonly config;
10
- private readonly locale;
11
- private readonly defaultLocale;
12
- private readonly translations;
13
- private readonly nonMessageConfig;
14
- private readonly messages;
15
- readonly intl: import("@angular/core").Signal<import("@formatjs/intl").IntlShape<string>>;
16
- formatMessage(key: string, values?: Record<string, string | number>): string;
17
- register(namespace: string, flat: Partial<Record<string, Record<string, string>>>, locale: string): void;
18
- static ɵfac: i0.ɵɵFactoryDeclaration<TranslationStore, never>;
19
- static ɵprov: i0.ɵɵInjectableDeclaration<TranslationStore>;
20
- }
21
- export declare function injectIntl(): import("@angular/core").Signal<import("@formatjs/intl").IntlShape<string>>;