@siemens/element-translate-ng 47.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/LICENSE.md +20 -0
  2. package/README.md +68 -0
  3. package/angular-localize/index.d.ts +6 -0
  4. package/angular-localize/package.json +3 -0
  5. package/angular-localize/si-translate-ng-localize-service-builder.service.d.ts +12 -0
  6. package/angular-localize/si-translate-ng-localize.module.d.ts +11 -0
  7. package/angular-localize/si-translate-ng-localize.provider.d.ts +10 -0
  8. package/angular-localize/si-translate-ng-localize.service.d.ts +7 -0
  9. package/bin/update-translatable-keys.js +120 -0
  10. package/fesm2022/siemens-element-translate-ng-angular-localize.mjs +89 -0
  11. package/fesm2022/siemens-element-translate-ng-angular-localize.mjs.map +1 -0
  12. package/fesm2022/siemens-element-translate-ng-localize-types.mjs +4 -0
  13. package/fesm2022/siemens-element-translate-ng-localize-types.mjs.map +1 -0
  14. package/fesm2022/siemens-element-translate-ng-ngx-translate.mjs +157 -0
  15. package/fesm2022/siemens-element-translate-ng-ngx-translate.mjs.map +1 -0
  16. package/fesm2022/siemens-element-translate-ng-translate-types.mjs +9 -0
  17. package/fesm2022/siemens-element-translate-ng-translate-types.mjs.map +1 -0
  18. package/fesm2022/siemens-element-translate-ng-translate.mjs +346 -0
  19. package/fesm2022/siemens-element-translate-ng-translate.mjs.map +1 -0
  20. package/fesm2022/siemens-element-translate-ng.mjs +14 -0
  21. package/fesm2022/siemens-element-translate-ng.mjs.map +1 -0
  22. package/index.d.ts +5 -0
  23. package/localize-types/index.d.ts +11 -0
  24. package/localize-types/package.json +3 -0
  25. package/ngx-translate/index.d.ts +6 -0
  26. package/ngx-translate/package.json +3 -0
  27. package/ngx-translate/si-translate-ngxt.module.d.ts +11 -0
  28. package/ngx-translate/si-translate-ngxt.provider.d.ts +10 -0
  29. package/ngx-translate/si-translate-ngxt.service-builder.d.ts +19 -0
  30. package/ngx-translate/si-translate-ngxt.service.d.ts +28 -0
  31. package/package.json +72 -0
  32. package/public-api.d.ts +8 -0
  33. package/translate/global.scope.d.ts +8 -0
  34. package/translate/index.d.ts +14 -0
  35. package/translate/package.json +3 -0
  36. package/translate/si-localize.d.ts +4 -0
  37. package/translate/si-no-translate.service-builder.d.ts +14 -0
  38. package/translate/si-no-translate.service.d.ts +21 -0
  39. package/translate/si-translatable.model.d.ts +6 -0
  40. package/translate/si-translatable.service.d.ts +11 -0
  41. package/translate/si-translate.module.d.ts +14 -0
  42. package/translate/si-translate.pipe.d.ts +30 -0
  43. package/translate/si-translate.service-builder.d.ts +21 -0
  44. package/translate/si-translate.service.d.ts +96 -0
  45. package/translate/testing/si-translate.mock-service-builder.factory.d.ts +7 -0
  46. package/translate-types/README.md +6 -0
  47. package/translate-types/global.types.d.ts +19 -0
  48. package/translate-types/index.d.ts +5 -0
  49. package/translate-types/package.json +3 -0
@@ -0,0 +1,14 @@
1
+ import { SiTranslateService } from './si-translate.service';
2
+ import { SiTranslateServiceBuilder } from './si-translate.service-builder';
3
+ import * as i0 from "@angular/core";
4
+ /**
5
+ * Always returns the same instance of {@link SiNoTranslateService}
6
+ *
7
+ * @internal
8
+ */
9
+ export declare class SiNoTranslateServiceBuilder extends SiTranslateServiceBuilder {
10
+ private siNoTranslateService;
11
+ buildService(): SiTranslateService;
12
+ static ɵfac: i0.ɵɵFactoryDeclaration<SiNoTranslateServiceBuilder, never>;
13
+ static ɵprov: i0.ɵɵInjectableDeclaration<SiNoTranslateServiceBuilder>;
14
+ }
@@ -0,0 +1,21 @@
1
+ import { Observable } from 'rxjs';
2
+ import { SiTranslateService, TranslationResult } from './si-translate.service';
3
+ import * as i0 from "@angular/core";
4
+ /**
5
+ * Pass through implementation of the {@link SiTranslateService} which is used as a default.
6
+ *
7
+ * @internal
8
+ */
9
+ export declare class SiNoTranslateService extends SiTranslateService {
10
+ get currentLanguage(): string;
11
+ get availableLanguages(): string[];
12
+ set availableLanguages(lang: string[]);
13
+ setCurrentLanguage(lang: string): Observable<void>;
14
+ getDefaultLanguage(): string;
15
+ setDefaultLanguage(lang: string): void;
16
+ translate<T extends string | string[]>(keys: T, _params?: Record<string, unknown>): TranslationResult<T>;
17
+ translateSync<T extends string | string[]>(keys: T, params?: Record<string, unknown>): TranslationResult<T>;
18
+ translateAsync<T extends string | string[]>(keys: T, params?: Record<string, unknown>): Observable<TranslationResult<T>>;
19
+ static ɵfac: i0.ɵɵFactoryDeclaration<SiNoTranslateService, never>;
20
+ static ɵprov: i0.ɵɵInjectableDeclaration<SiNoTranslateService>;
21
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Copyright Siemens 2016 - 2025.
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+ import { InjectionToken } from '@angular/core';
6
+ export declare const SI_TRANSLATABLE_VALUES: InjectionToken<Record<string, string>[]>;
@@ -0,0 +1,11 @@
1
+ import { TranslatableString } from '@siemens/element-translate-ng/translate-types';
2
+ import * as i0 from "@angular/core";
3
+ export declare class SiTranslatableService {
4
+ private readonly translatableValues;
5
+ private readonly isNoTranslate;
6
+ private readonly siTranslateService;
7
+ constructor();
8
+ resolveText(key: string, originalText: string): TranslatableString;
9
+ static ɵfac: i0.ɵɵFactoryDeclaration<SiTranslatableService, never>;
10
+ static ɵprov: i0.ɵɵInjectableDeclaration<SiTranslatableService>;
11
+ }
@@ -0,0 +1,14 @@
1
+ import * as i0 from "@angular/core";
2
+ import * as i1 from "./si-translate.pipe";
3
+ /**
4
+ * This provides declares SiTranslatePipe and provides a respective SiTranslateService.
5
+ * It should be used internally of Element but NOT by any application
6
+ *
7
+ * @internal
8
+ */
9
+ export declare class SiTranslateModule {
10
+ constructor();
11
+ static ɵfac: i0.ɵɵFactoryDeclaration<SiTranslateModule, never>;
12
+ static ɵmod: i0.ɵɵNgModuleDeclaration<SiTranslateModule, [typeof i1.SiTranslatePipe], never, [typeof i1.SiTranslatePipe]>;
13
+ static ɵinj: i0.ɵɵInjectorDeclaration<SiTranslateModule>;
14
+ }
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Copyright Siemens 2016 - 2025.
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+ import { OnDestroy, PipeTransform } from '@angular/core';
6
+ import * as i0 from "@angular/core";
7
+ /**
8
+ * Translates keys by using the {@link SiTranslateService}.
9
+ * Within Element this pipe should be used instead of ngx-translates `translate` pipe.
10
+ * Outside Element, this pipe should NOT be used.
11
+ *
12
+ * @internal
13
+ */
14
+ export declare class SiTranslatePipe implements PipeTransform, OnDestroy {
15
+ private lastKeyParams?;
16
+ private value;
17
+ private subscription?;
18
+ private siTranslateService;
19
+ private cdRef;
20
+ /**
21
+ * Method which is called on any data passed to the pipe.
22
+ * Called by Angular, should not be called directly.
23
+ */
24
+ transform(key: string, params?: any): string;
25
+ transform(key: string | null | undefined, params?: any): string | null | undefined;
26
+ ngOnDestroy(): void;
27
+ private updateValue;
28
+ static ɵfac: i0.ɵɵFactoryDeclaration<SiTranslatePipe, never>;
29
+ static ɵpipe: i0.ɵɵPipeDeclaration<SiTranslatePipe, "translate", false>;
30
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Copyright Siemens 2016 - 2025.
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+ import { Injector } from '@angular/core';
6
+ import { SiTranslateService } from './si-translate.service';
7
+ import * as i0 from "@angular/core";
8
+ /**
9
+ * Provide this class to build a custom translation service.
10
+ *
11
+ * @internal
12
+ */
13
+ export declare abstract class SiTranslateServiceBuilder {
14
+ /**
15
+ * Returns a translation service instance.
16
+ * @param injector - Is used to retrieve dependencies needed to create the translation service.
17
+ */
18
+ abstract buildService(injector: Injector): SiTranslateService;
19
+ static ɵfac: i0.ɵɵFactoryDeclaration<SiTranslateServiceBuilder, never>;
20
+ static ɵprov: i0.ɵɵInjectableDeclaration<SiTranslateServiceBuilder>;
21
+ }
@@ -0,0 +1,96 @@
1
+ import { Observable } from 'rxjs';
2
+ import * as i0 from "@angular/core";
3
+ export type TranslationResult<T> = T extends string ? string : Record<string, string>;
4
+ /**
5
+ * @returns The culture language code of the browser, e.g. "en-US".
6
+ */
7
+ export declare const getBrowserCultureLanguage: () => string | undefined;
8
+ /**
9
+ * @returns The language code of the browser, e.g. "en".
10
+ */
11
+ export declare const getBrowserLanguage: () => string | undefined;
12
+ /**
13
+ * Wrapper around an actual translation framework which is meant to be used internally by Element.
14
+ * Applications must not use this service.
15
+ *
16
+ * @internal
17
+ */
18
+ export declare abstract class SiTranslateService {
19
+ protected translationChange$: Observable<void>;
20
+ private documentRef;
21
+ prevent$LocalizeInit?: boolean;
22
+ /**
23
+ * The currently used language.
24
+ */
25
+ abstract get currentLanguage(): string;
26
+ /**
27
+ * Sets a new language to be used. If needed, loads the language file.
28
+ * @param lang - The language to be used.
29
+ * @returns An observable that emits when the new language is loaded and activated.
30
+ */
31
+ abstract setCurrentLanguage(lang: string): Observable<void>;
32
+ /**
33
+ * The language to be used as default.
34
+ * @param lang - The language code.
35
+ */
36
+ abstract setDefaultLanguage(lang: string): void;
37
+ /**
38
+ * The language to be used as default.
39
+ * @returns The code of the default language.
40
+ */
41
+ abstract getDefaultLanguage(): string;
42
+ /**
43
+ * The available languages.
44
+ */
45
+ abstract get availableLanguages(): string[];
46
+ abstract set availableLanguages(languages: string[]);
47
+ /**
48
+ * If the underlying translation library supports switching the language
49
+ * and/or updating the translation texts, this observable will emit.
50
+ * There is no initial emit.
51
+ */
52
+ get translationChange(): Observable<void>;
53
+ /**
54
+ * Translates the key(s) by using the underlying translation library.
55
+ *
56
+ * @param keys - A single translation key or an array of keys.
57
+ * @param params - Parameters to be replaced within the translation text.
58
+ *
59
+ * @returns Returns the translated key or an object with the translated keys.
60
+ * Depending on the underlying translation library (sync/async) the result will
61
+ * be wrapped in an Observable.
62
+ */
63
+ abstract translate<T extends string | string[]>(keys: T, params?: Record<string, unknown>): Observable<TranslationResult<T>> | TranslationResult<T>;
64
+ /**
65
+ * Translates the key(s) by using the underlying translation library in an asynchronous manner.
66
+ * It will emit each time the active language is changed.
67
+ *
68
+ * @param keys - A single translation key or an array of keys.
69
+ * @param params - Parameters to be replaced within the translation text.
70
+ *
71
+ * @returns Returns the translated key or an object with the translated keys wrapped in an Observable.
72
+ */
73
+ abstract translateAsync<T extends string | string[]>(keys: T, params?: Record<string, unknown>): Observable<TranslationResult<T>>;
74
+ /**
75
+ * Translates the key(s) by using the underlying translation library in a synchronous manner.
76
+ *
77
+ * Warning: The caller of this function needs to make sure the translation file(s) are already loaded.
78
+ * It is generally not recommended to use this function unless you know exactly what you are doing.
79
+ *
80
+ * @param keys - A single translation key or an array of keys.
81
+ * @param params - Parameters to be replaced within the translation text.
82
+ *
83
+ * @returns Returns the translated key or an object with the translated keys.
84
+ */
85
+ abstract translateSync<T extends string | string[]>(keys: T, params?: Record<string, unknown>): TranslationResult<T>;
86
+ /**
87
+ * If supported by the underlying translation library, this method can be used to add a translation for a specific key.
88
+ * It is intended to be used for adding the english default value.
89
+ * It will be called whenever a key within element is resolved.
90
+ * An implementation of this method must check that it does not override an existing translation.
91
+ */
92
+ setTranslation?(key: string, value: string): void;
93
+ setDocumentLanguage(lang: string): void;
94
+ static ɵfac: i0.ɵɵFactoryDeclaration<SiTranslateService, never>;
95
+ static ɵprov: i0.ɵɵInjectableDeclaration<SiTranslateService>;
96
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Copyright Siemens 2016 - 2025.
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+ import { Injector, Provider } from '@angular/core';
6
+ import { SiTranslateService } from '../si-translate.service';
7
+ export declare const provideMockTranslateServiceBuilder: (buildService: (injector: Injector) => SiTranslateService) => Provider;
@@ -0,0 +1,6 @@
1
+ # Entry point for @siemens/element development only
2
+
3
+ `TranslatableString` must be in its own entry point as it is reused in `@siemens/element-localize-types` which itself is
4
+ used as a types-package.
5
+ Having `TranslatableString` in `@siemens/element-translate-ng/translation` causes the compiler to fail.
6
+ Therefore, it is only reexported in `@siemens/element-translate-ng/translation`.
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Copyright Siemens 2016 - 2025.
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+ /**
6
+ * Empty interface to represent translatable strings before they are translated.
7
+ * Needed so the TypeScript compiler doesn't strip away the {@link TranslatableString} type.
8
+ * Ignored by the documentation.
9
+ * @internal
10
+ */
11
+ interface Translatable {
12
+ }
13
+ /**
14
+ * Represents a translatable string. This can either be a translation key, e.g. `ACTIONS.EDIT` that
15
+ * will be automatically translated when displayed on the UI or a pre-translated string, e.g. `Edit`.
16
+ * Equivalent to a normal string in usage and functionality.
17
+ */
18
+ export type TranslatableString = string & Translatable;
19
+ export {};
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Copyright Siemens 2016 - 2025.
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+ export * from './global.types';
@@ -0,0 +1,3 @@
1
+ {
2
+ "module": "../fesm2022/siemens-element-translate-ng-translate-types.mjs"
3
+ }