@tolgee/ngx 2.3.2 → 2.8.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.
@@ -1,6 +1,6 @@
1
1
  import * as i0 from '@angular/core';
2
2
  import { EventEmitter, Injectable, Pipe, Component, Input, APP_INITIALIZER, NgModule } from '@angular/core';
3
- import { from } from 'rxjs';
3
+ import { Observable } from 'rxjs';
4
4
  import { Tolgee, TolgeeConfig, TOLGEE_WRAPPED_ONLY_DATA_ATTRIBUTE } from '@tolgee/core';
5
5
  export { TolgeeConfig } from '@tolgee/core';
6
6
 
@@ -13,10 +13,14 @@ class TranslateService {
13
13
  get tolgee() {
14
14
  return this._tolgee;
15
15
  }
16
+ /**
17
+ * Starts Tolgee if not started and subscribes for languageChange and translationChange events
18
+ */
16
19
  async start(config) {
17
20
  if (!this.runPromise) {
18
21
  this._tolgee = new Tolgee(config);
19
22
  this.runPromise = this.tolgee.run();
23
+ // unsubscribe first, if it is subscribed for some reason
20
24
  this.unsubscribeCoreListeners();
21
25
  this.onTranslationChangeCoreSubscription =
22
26
  this._tolgee.onTranslationChange.subscribe((data) => {
@@ -29,40 +33,119 @@ class TranslateService {
29
33
  await this.runPromise;
30
34
  }
31
35
  ngOnDestroy() {
36
+ // stop it!
32
37
  this.tolgee.stop();
38
+ // unsubscribe listeners
33
39
  this.unsubscribeCoreListeners();
34
40
  }
41
+ /**
42
+ * Changes the current language
43
+ * @param lang The new current language (e.g. en, en-US)
44
+ */
35
45
  setLang(lang) {
36
46
  this.tolgee.lang = lang;
37
47
  }
38
- get(input, params = {}, defaultValue) {
39
- return from(this.translate(input, params, false, defaultValue));
48
+ /**
49
+ * Returns the current language
50
+ */
51
+ getCurrentLang() {
52
+ return this.tolgee.lang;
53
+ }
54
+ /**
55
+ * Returns Observable providing current translated value
56
+ * Tne observable is subscribed to translation change and language change events of Tolgee
57
+ *
58
+ * In development mode, it returns string wrapped with configured
59
+ * prefix and suffix to be handled in browser by MutationObserver.
60
+ *
61
+ * You should use unsubscribe method when you are done!
62
+ *
63
+ * in onInit: this.subscription = translateService.get('aa')
64
+ * in onDestroy: this.subscription.unsubscribe()
65
+ *
66
+ * @param key The key to translate (e.g. what-a-key)
67
+ * @param params The parameters to interpolate (e.g. {name: "John"})
68
+ * @param defaultValue Value, which will be rendered, when no translated value is provided
69
+ */
70
+ get(key, params = {}, defaultValue) {
71
+ return this.translate(key, params, false, defaultValue);
40
72
  }
41
- getSafe(input, params = {}, defaultValue) {
42
- return from(this.translate(input, params, true, defaultValue));
73
+ /**
74
+ * Returns Observable providing current translated value
75
+ * Tne observable is subscribed to translation change and language change events of Tolgee
76
+ *
77
+ * In development mode, it returns the translated string,
78
+ * so in-context localization is not going to work.
79
+ *
80
+ * You should use unsubscribe method when you are done!
81
+ *
82
+ * in onInit: this.subscription = translateService.get('aa')
83
+ * in onDestroy: this.subscription.unsubscribe()
84
+ *
85
+ * @param key The key to translate (e.g. what-a-key)
86
+ * @param params The parameters to interpolate (e.g. {name: "John"})
87
+ * @param defaultValue Value, which will be rendered, when no translated value is provided
88
+ */
89
+ getSafe(key, params = {}, defaultValue) {
90
+ return this.translate(key, params, true, defaultValue);
43
91
  }
44
- instant(input, params = {}, defaultValue) {
45
- return this.tolgee.instant(input, params, undefined, undefined, defaultValue);
92
+ /**
93
+ * Returns the translation value synchronously
94
+ *
95
+ * In development mode, it returns string wrapped with configured
96
+ * prefix and suffix to be handled in browser by MutationObserver.
97
+ *
98
+ * @param key The key to translate (e.g. what-a-key)
99
+ * @param params The parameters to interpolate (e.g. {name: "John"})
100
+ * @param defaultValue Value, which will be rendered, when no translated value is provided
101
+ */
102
+ instant(key, params = {}, defaultValue) {
103
+ return this.tolgee.instant(key, params, undefined, undefined, defaultValue);
46
104
  }
105
+ /**
106
+ * Returns the translation value synchronously
107
+ *
108
+ * In development mode, it returns the translated string,
109
+ * so in-context localization is not going to work.
110
+ *
111
+ * @param key The key to translate (e.g. what-a-key)
112
+ * @param params The parameters to interpolate (e.g. {name: "John"})
113
+ * @param defaultValue Value, which will be rendered, when no translated value is provided
114
+ */
47
115
  instantSafe(input, params = {}, defaultValue) {
48
116
  return this.tolgee.instant(input, params, true, undefined, defaultValue);
49
117
  }
50
- getCurrentLang() {
51
- return this.tolgee.lang;
52
- }
53
118
  unsubscribeCoreListeners() {
54
119
  this.onTranslationChangeCoreSubscription?.unsubscribe();
55
120
  this.onLangChangeCoreSubscription?.unsubscribe();
56
121
  }
57
- async translate(input, params = {}, noWrap = false, defaultValue) {
58
- //wait for start before translating
59
- await this.start(this.config);
60
- return await this.tolgee.translate(input, params, noWrap, defaultValue);
122
+ translate(key, params = {}, noWrap = false, defaultValue) {
123
+ return new Observable((subscriber) => {
124
+ const translate = async () => {
125
+ // start if not started
126
+ await this.start(this.config);
127
+ const translated = await this.tolgee.translate(key, params, noWrap, defaultValue);
128
+ subscriber.next(translated);
129
+ };
130
+ translate();
131
+ const onTranslationChangeSubscription = this.tolgee.onTranslationChange.subscribe((data) => {
132
+ if (data.key === key) {
133
+ translate();
134
+ }
135
+ });
136
+ const onLanguageChangeSubscription = this.tolgee.onLangChange.subscribe(() => {
137
+ translate();
138
+ });
139
+ return () => {
140
+ onTranslationChangeSubscription.unsubscribe();
141
+ onLanguageChangeSubscription.unsubscribe();
142
+ };
143
+ });
61
144
  }
62
145
  }
63
- TranslateService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: TranslateService, deps: [{ token: TolgeeConfig }], target: i0.ɵɵFactoryTarget.Injectable });
64
- TranslateService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: TranslateService });
65
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: TranslateService, decorators: [{
146
+ TranslateService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.3", ngImport: i0, type: TranslateService, deps: [{ token: TolgeeConfig }], target: i0.ɵɵFactoryTarget.Injectable });
147
+ TranslateService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.0.3", ngImport: i0, type: TranslateService });
148
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.3", ngImport: i0, type: TranslateService, decorators: [{
66
149
  type: Injectable
67
150
  }], ctorParameters: function () { return [{ type: TolgeeConfig }]; } });
68
151
 
@@ -72,14 +155,14 @@ class TranslatePipe {
72
155
  this.value = '';
73
156
  }
74
157
  get resultProvider() {
75
- return (input, params, defaultValue) => this.translateService.get(input, params, defaultValue);
158
+ return (key, params, defaultValue) => this.translateService.get(key, params, defaultValue);
76
159
  }
77
160
  ngOnDestroy() {
78
- this.langChangeSubscription.unsubscribe();
161
+ this.unsubscribe();
79
162
  }
80
- transform(input, paramsOrDefaultValue, params) {
81
- if (!input || input.length === 0) {
82
- return input;
163
+ transform(key, paramsOrDefaultValue, params) {
164
+ if (!key || key.length === 0) {
165
+ return key;
83
166
  }
84
167
  const defaultValue = typeof paramsOrDefaultValue !== 'object'
85
168
  ? paramsOrDefaultValue
@@ -87,30 +170,34 @@ class TranslatePipe {
87
170
  if (typeof paramsOrDefaultValue === 'object') {
88
171
  params = paramsOrDefaultValue;
89
172
  }
90
- const newHash = this.getHash(input, params, this.translateService.getCurrentLang());
91
- if (newHash === this.lastHash) {
173
+ if (this.key === key &&
174
+ JSON.stringify(this.params) === JSON.stringify(params) &&
175
+ this.defaultValue === defaultValue) {
92
176
  return this.value;
93
177
  }
94
- this.langChangeSubscription?.unsubscribe();
95
- this.langChangeSubscription = this.translateService.onLangChange.subscribe(() => {
96
- this.onLangChange(input, params, defaultValue);
97
- });
98
- this.onLangChange(input, params, defaultValue);
99
- this.lastHash = newHash;
178
+ this.key = key;
179
+ this.params = params;
180
+ this.defaultValue = defaultValue;
181
+ // unsubscribe first
182
+ this.unsubscribe();
183
+ // asynchronously translate and assign subscription
184
+ this.subscription = this.translate(key, params, defaultValue);
100
185
  return this.value;
101
186
  }
102
- getHash(input, params, language) {
103
- return JSON.stringify({ input, params, language });
187
+ unsubscribe() {
188
+ if (this.subscription) {
189
+ this.subscription.unsubscribe();
190
+ }
104
191
  }
105
- onLangChange(input, params, defaultValue) {
106
- this.resultProvider(input, params, defaultValue).subscribe((r) => {
192
+ translate(key, params, defaultValue) {
193
+ return this.resultProvider(key, params, defaultValue).subscribe((r) => {
107
194
  this.value = r;
108
195
  });
109
196
  }
110
197
  }
111
- TranslatePipe.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: TranslatePipe, deps: [{ token: TranslateService }], target: i0.ɵɵFactoryTarget.Pipe });
112
- TranslatePipe.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: TranslatePipe, name: "translate", pure: false });
113
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: TranslatePipe, decorators: [{
198
+ TranslatePipe.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.3", ngImport: i0, type: TranslatePipe, deps: [{ token: TranslateService }], target: i0.ɵɵFactoryTarget.Pipe });
199
+ TranslatePipe.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "12.0.0", version: "13.0.3", ngImport: i0, type: TranslatePipe, name: "translate", pure: false });
200
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.3", ngImport: i0, type: TranslatePipe, decorators: [{
114
201
  type: Pipe,
115
202
  args: [{
116
203
  name: 'translate',
@@ -126,9 +213,9 @@ class STranslatePipe extends TranslatePipe {
126
213
  return (input, params, defaultValue) => this.translateService.getSafe(input, params, defaultValue);
127
214
  }
128
215
  }
129
- STranslatePipe.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: STranslatePipe, deps: [{ token: TranslateService }], target: i0.ɵɵFactoryTarget.Pipe });
130
- STranslatePipe.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: STranslatePipe, name: "stranslate", pure: false });
131
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: STranslatePipe, decorators: [{
216
+ STranslatePipe.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.3", ngImport: i0, type: STranslatePipe, deps: [{ token: TranslateService }], target: i0.ɵɵFactoryTarget.Pipe });
217
+ STranslatePipe.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "12.0.0", version: "13.0.3", ngImport: i0, type: STranslatePipe, name: "stranslate", pure: false });
218
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.3", ngImport: i0, type: STranslatePipe, decorators: [{
132
219
  type: Pipe,
133
220
  args: [{
134
221
  name: 'stranslate',
@@ -141,39 +228,27 @@ class TComponent {
141
228
  this.ref = ref;
142
229
  this.translateService = translateService;
143
230
  }
144
- get resultProvider() {
145
- return (key, params, defaultValue) => this.translateService.getSafe(key, params, defaultValue);
146
- }
147
231
  ngOnInit() {
148
232
  const element = this.ref.nativeElement;
149
233
  element.setAttribute(TOLGEE_WRAPPED_ONLY_DATA_ATTRIBUTE, this.key);
150
- //update value when language changed
151
- this.onLangChangeSubscription =
152
- this.translateService.onLangChange.subscribe(() => {
153
- this.translate(this.key, this.params, this.default);
154
- });
155
- //update value when translation changed
156
- this.onTranslationChangeSubscription =
157
- this.translateService.onTranslationChange.subscribe((data) => {
158
- if (data.key == this.key) {
159
- this.translate(this.key, this.params, this.default);
160
- }
161
- });
162
- this.translate(this.key, this.params, this.default);
234
+ // set safe at first
235
+ element.textContent = this.translateService.instantSafe(this.key, this.params, this.default);
236
+ // then do the async translation
237
+ this.subscription = this.translateService
238
+ .getSafe(this.key, this.params, this.default)
239
+ .subscribe((translated) => {
240
+ return (element.textContent = translated);
241
+ });
163
242
  }
164
243
  ngOnDestroy() {
165
- this.onLangChangeSubscription?.unsubscribe();
166
- this.onTranslationChangeSubscription?.unsubscribe();
167
- }
168
- translate(key, params, defaultValue) {
169
- this.resultProvider(key, params, defaultValue).subscribe((r) => {
170
- this.ref.nativeElement.textContent = r;
171
- });
244
+ if (this.subscription) {
245
+ this.subscription.unsubscribe();
246
+ }
172
247
  }
173
248
  }
174
- TComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: TComponent, deps: [{ token: i0.ElementRef }, { token: TranslateService }], target: i0.ɵɵFactoryTarget.Component });
175
- TComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.0.0", type: TComponent, selector: "[t]", inputs: { params: "params", key: "key", default: "default" }, ngImport: i0, template: ``, isInline: true });
176
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: TComponent, decorators: [{
249
+ TComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.3", ngImport: i0, type: TComponent, deps: [{ token: i0.ElementRef }, { token: TranslateService }], target: i0.ɵɵFactoryTarget.Component });
250
+ TComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.0.3", type: TComponent, selector: "[t]", inputs: { params: "params", key: "key", default: "default" }, ngImport: i0, template: ``, isInline: true });
251
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.3", ngImport: i0, type: TComponent, decorators: [{
177
252
  type: Component,
178
253
  args: [{
179
254
  selector: '[t]',
@@ -195,9 +270,9 @@ class TranslationsProvider {
195
270
  return await this.translateService.start(options);
196
271
  }
197
272
  }
198
- TranslationsProvider.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: TranslationsProvider, deps: [{ token: TranslateService }], target: i0.ɵɵFactoryTarget.Injectable });
199
- TranslationsProvider.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: TranslationsProvider });
200
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: TranslationsProvider, decorators: [{
273
+ TranslationsProvider.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.3", ngImport: i0, type: TranslationsProvider, deps: [{ token: TranslateService }], target: i0.ɵɵFactoryTarget.Injectable });
274
+ TranslationsProvider.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.0.3", ngImport: i0, type: TranslationsProvider });
275
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.3", ngImport: i0, type: TranslationsProvider, decorators: [{
201
276
  type: Injectable
202
277
  }], ctorParameters: function () { return [{ type: TranslateService }]; } });
203
278
 
@@ -223,10 +298,10 @@ class NgxTolgeeModule {
223
298
  };
224
299
  }
225
300
  }
226
- NgxTolgeeModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: NgxTolgeeModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
227
- NgxTolgeeModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: NgxTolgeeModule, declarations: [TranslatePipe, STranslatePipe, TComponent], exports: [TranslatePipe, STranslatePipe, TComponent] });
228
- NgxTolgeeModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: NgxTolgeeModule, providers: [] });
229
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: NgxTolgeeModule, decorators: [{
301
+ NgxTolgeeModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.3", ngImport: i0, type: NgxTolgeeModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
302
+ NgxTolgeeModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.0.3", ngImport: i0, type: NgxTolgeeModule, declarations: [TranslatePipe, STranslatePipe, TComponent], exports: [TranslatePipe, STranslatePipe, TComponent] });
303
+ NgxTolgeeModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.0.3", ngImport: i0, type: NgxTolgeeModule, providers: [] });
304
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.3", ngImport: i0, type: NgxTolgeeModule, decorators: [{
230
305
  type: NgModule,
231
306
  args: [{
232
307
  declarations: [TranslatePipe, STranslatePipe, TComponent],
@@ -1 +1 @@
1
- {"version":3,"file":"tolgee-ngx.mjs","sources":["../../../projects/ngx-tolgee/src/lib/translate.service.ts","../../../projects/ngx-tolgee/src/lib/translate.pipe.ts","../../../projects/ngx-tolgee/src/lib/stranslate.pipe.ts","../../../projects/ngx-tolgee/src/lib/t.component.ts","../../../projects/ngx-tolgee/src/lib/translations-provider.ts","../../../projects/ngx-tolgee/src/lib/ngx-tolgee.module.ts","../../../projects/ngx-tolgee/src/public-api.ts","../../../projects/ngx-tolgee/src/tolgee-ngx.ts"],"sourcesContent":["import { EventEmitter, Injectable, OnDestroy } from '@angular/core';\nimport { from, Observable } from 'rxjs';\nimport { Tolgee, TranslationData } from '@tolgee/core';\nimport { TolgeeConfig } from './tolgeeConfig';\n\n@Injectable()\nexport class TranslateService implements OnDestroy {\n public readonly onLangChange: EventEmitter<never> = new EventEmitter<never>();\n public readonly onTranslationChange: EventEmitter<TranslationData> =\n new EventEmitter<TranslationData>();\n\n private runPromise: Promise<void>;\n private onTranslationChangeCoreSubscription: any;\n private onLangChangeCoreSubscription: any;\n\n constructor(private config: TolgeeConfig) {}\n\n private _tolgee: Tolgee;\n\n public get tolgee(): Tolgee {\n return this._tolgee;\n }\n\n public async start(config: TolgeeConfig): Promise<void> {\n if (!this.runPromise) {\n this._tolgee = new Tolgee(config);\n this.runPromise = this.tolgee.run();\n this.unsubscribeCoreListeners();\n this.onTranslationChangeCoreSubscription =\n this._tolgee.onTranslationChange.subscribe((data) => {\n this.onTranslationChange.emit(data);\n });\n this.onLangChangeCoreSubscription = this._tolgee.onLangChange.subscribe(\n () => {\n this.onLangChange.emit();\n }\n );\n }\n await this.runPromise;\n }\n\n ngOnDestroy(): void {\n this.tolgee.stop();\n this.unsubscribeCoreListeners();\n }\n\n public setLang(lang: string) {\n this.tolgee.lang = lang;\n }\n\n public get(\n input: string,\n params = {},\n defaultValue?: string\n ): Observable<string> {\n return from(this.translate(input, params, false, defaultValue));\n }\n\n public getSafe(\n input: string,\n params = {},\n defaultValue?: string\n ): Observable<string> {\n return from(this.translate(input, params, true, defaultValue));\n }\n\n public instant(input: string, params = {}, defaultValue?: string): string {\n return this.tolgee.instant(\n input,\n params,\n undefined,\n undefined,\n defaultValue\n );\n }\n\n public instantSafe(\n input: string,\n params = {},\n defaultValue?: string\n ): string {\n return this.tolgee.instant(input, params, true, undefined, defaultValue);\n }\n\n public getCurrentLang(): string {\n return this.tolgee.lang;\n }\n\n private unsubscribeCoreListeners() {\n this.onTranslationChangeCoreSubscription?.unsubscribe();\n this.onLangChangeCoreSubscription?.unsubscribe();\n }\n\n private async translate(\n input: string,\n params = {},\n noWrap = false,\n defaultValue: string\n ): Promise<string> {\n //wait for start before translating\n await this.start(this.config);\n return await this.tolgee.translate(input, params, noWrap, defaultValue);\n }\n}\n","import { OnDestroy, Pipe, PipeTransform } from '@angular/core';\nimport { TranslateService } from './translate.service';\nimport { Observable, Subscription } from 'rxjs';\n\n@Pipe({\n name: 'translate',\n pure: false,\n})\nexport class TranslatePipe implements PipeTransform, OnDestroy {\n value = '';\n lastHash: string;\n private langChangeSubscription: Subscription;\n\n constructor(protected translateService: TranslateService) {}\n\n protected get resultProvider(): (\n key,\n params,\n defaultValue: string\n ) => Observable<string> {\n return (input, params, defaultValue) =>\n this.translateService.get(input, params, defaultValue);\n }\n\n ngOnDestroy(): void {\n this.langChangeSubscription.unsubscribe();\n }\n\n transform(input: any, params?: Record<string, any>): string;\n transform(\n input: any,\n defaultValue?: string,\n params?: Record<string, any>\n ): string;\n\n transform(\n input: any,\n paramsOrDefaultValue?: Record<string, any> | string,\n params?: Record<string, any>\n ): string {\n if (!input || input.length === 0) {\n return input;\n }\n\n const defaultValue =\n typeof paramsOrDefaultValue !== 'object'\n ? paramsOrDefaultValue\n : undefined;\n\n if (typeof paramsOrDefaultValue === 'object') {\n params = paramsOrDefaultValue;\n }\n\n const newHash = this.getHash(\n input,\n params,\n this.translateService.getCurrentLang()\n );\n\n if (newHash === this.lastHash) {\n return this.value;\n }\n\n this.langChangeSubscription?.unsubscribe();\n this.langChangeSubscription = this.translateService.onLangChange.subscribe(\n () => {\n this.onLangChange(input, params, defaultValue);\n }\n );\n\n this.onLangChange(input, params, defaultValue);\n\n this.lastHash = newHash;\n\n return this.value;\n }\n\n private getHash(input: string, params: object, language: string): string {\n return JSON.stringify({ input, params, language });\n }\n\n private onLangChange(input, params, defaultValue) {\n this.resultProvider(input, params, defaultValue).subscribe((r) => {\n this.value = r;\n });\n }\n}\n","import { Pipe } from '@angular/core';\nimport { TranslateService } from './translate.service';\nimport { TranslatePipe } from './translate.pipe';\nimport { Observable } from 'rxjs';\n\n@Pipe({\n name: 'stranslate',\n pure: false,\n})\nexport class STranslatePipe extends TranslatePipe {\n constructor(translateService: TranslateService) {\n super(translateService);\n }\n\n protected get resultProvider(): (\n input,\n params,\n defaultValue\n ) => Observable<string> {\n return (input, params, defaultValue) =>\n this.translateService.getSafe(input, params, defaultValue);\n }\n}\n","import { Component, ElementRef, Input, OnDestroy, OnInit } from '@angular/core';\nimport { Observable, Subscription } from 'rxjs';\nimport { TranslateService } from './translate.service';\nimport { TOLGEE_WRAPPED_ONLY_DATA_ATTRIBUTE } from '@tolgee/core';\n\n@Component({\n selector: '[t]',\n template: ``,\n})\nexport class TComponent implements OnInit, OnDestroy {\n value: string;\n @Input() params?: Record<string, any>;\n @Input() key: string;\n @Input() default?: string;\n onLangChangeSubscription: Subscription;\n onTranslationChangeSubscription: Subscription;\n\n constructor(\n private ref: ElementRef,\n private translateService: TranslateService\n ) {}\n\n protected get resultProvider(): (\n key,\n params,\n defaultValue: string\n ) => Observable<string> {\n return (key, params, defaultValue) =>\n this.translateService.getSafe(key, params, defaultValue);\n }\n\n ngOnInit(): void {\n const element = this.ref.nativeElement as HTMLElement;\n\n element.setAttribute(TOLGEE_WRAPPED_ONLY_DATA_ATTRIBUTE, this.key);\n\n //update value when language changed\n this.onLangChangeSubscription =\n this.translateService.onLangChange.subscribe(() => {\n this.translate(this.key, this.params, this.default);\n });\n\n //update value when translation changed\n this.onTranslationChangeSubscription =\n this.translateService.onTranslationChange.subscribe((data) => {\n if (data.key == this.key) {\n this.translate(this.key, this.params, this.default);\n }\n });\n this.translate(this.key, this.params, this.default);\n }\n\n ngOnDestroy(): void {\n this.onLangChangeSubscription?.unsubscribe();\n this.onTranslationChangeSubscription?.unsubscribe();\n }\n\n private translate(key, params, defaultValue: string) {\n this.resultProvider(key, params, defaultValue).subscribe((r) => {\n this.ref.nativeElement.textContent = r;\n });\n }\n}\n","import {Injectable} from '@angular/core';\nimport {TranslateService} from \"./translate.service\";\nimport {TolgeeConfig} from \"@tolgee/core\";\n\n@Injectable()\nexport class TranslationsProvider {\n\n constructor(private translateService: TranslateService) {\n }\n\n async load(options: TolgeeConfig) {\n return await this.translateService.start(options);\n }\n}\n\n\n","import { APP_INITIALIZER, ModuleWithProviders, NgModule } from '@angular/core';\nimport { TranslatePipe } from './translate.pipe';\nimport { TranslationsProvider } from './translations-provider';\nimport { TranslateService } from './translate.service';\nimport { STranslatePipe } from './stranslate.pipe';\nimport { TolgeeConfig } from './tolgeeConfig';\nimport { TComponent } from './t.component';\n\n@NgModule({\n declarations: [TranslatePipe, STranslatePipe, TComponent],\n exports: [TranslatePipe, STranslatePipe, TComponent],\n providers: [],\n})\nexport class NgxTolgeeModule {\n // @dynamic\n static forRoot(options: TolgeeConfig): ModuleWithProviders<NgxTolgeeModule> {\n options = { filesUrlPrefix: '/assets/i18n/', ...options };\n return {\n ngModule: NgxTolgeeModule,\n providers: [\n TranslateService,\n TranslationsProvider,\n {\n provide: APP_INITIALIZER,\n useFactory: (provider: TranslationsProvider) => {\n return async () => await provider.load(options);\n },\n deps: [TranslationsProvider, TranslateService],\n multi: true,\n },\n { provide: TolgeeConfig, useValue: options },\n ],\n };\n }\n}\n","/*\n * Public API Surface of ngx-tolgee\n */\nimport { TranslateService } from './lib/translate.service';\nimport { TranslatePipe } from './lib/translate.pipe';\nimport { STranslatePipe } from './lib/stranslate.pipe';\nimport { TolgeeConfig } from './lib/tolgeeConfig';\nimport { TComponent } from './lib/t.component';\n\nexport * from './lib/ngx-tolgee.module';\nexport { TolgeeConfig };\nexport { TranslateService };\nexport { TranslatePipe };\nexport { STranslatePipe };\nexport { TComponent };\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;MAMa,gBAAgB;IAS3B,YAAoB,MAAoB;QAApB,WAAM,GAAN,MAAM,CAAc;QARxB,iBAAY,GAAwB,IAAI,YAAY,EAAS,CAAC;QAC9D,wBAAmB,GACjC,IAAI,YAAY,EAAmB,CAAC;KAMM;IAI5C,IAAW,MAAM;QACf,OAAO,IAAI,CAAC,OAAO,CAAC;KACrB;IAEM,MAAM,KAAK,CAAC,MAAoB;QACrC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE;YACpB,IAAI,CAAC,OAAO,GAAG,IAAI,MAAM,CAAC,MAAM,CAAC,CAAC;YAClC,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC;YACpC,IAAI,CAAC,wBAAwB,EAAE,CAAC;YAChC,IAAI,CAAC,mCAAmC;gBACtC,IAAI,CAAC,OAAO,CAAC,mBAAmB,CAAC,SAAS,CAAC,CAAC,IAAI;oBAC9C,IAAI,CAAC,mB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;KACH;;4GApBU,eAAe;6GAAf,eAAe,iBAJX,aAAa,EAAE,cAAc,EAAE,UAAU,aAC9C,aAAa,EAAE,cAAc,EAAE,UAAU;6GAGxC,eAAe,aAFf,EAAE;2FAEF,eAAe;kBAL3B,QAAQ;mBAAC;oBACR,YAAY,EAAE,CAAC,aAAa,EAAE,cAAc,EAAE,UAAU,CAAC;oBACzD,OAAO,EAAE,CAAC,aAAa,EAAE,cAAc,EAAE,UAAU,CAAC;oBACpD,SAAS,EAAE,EAAE;iBACd;;;ACZD;;;;ACAA;;;;;;"}
1
+ {"version":3,"file":"tolgee-ngx.mjs","sources":["../../../projects/ngx-tolgee/src/lib/translate.service.ts","../../../projects/ngx-tolgee/src/lib/translate.pipe.ts","../../../projects/ngx-tolgee/src/lib/stranslate.pipe.ts","../../../projects/ngx-tolgee/src/lib/t.component.ts","../../../projects/ngx-tolgee/src/lib/translations-provider.ts","../../../projects/ngx-tolgee/src/lib/ngx-tolgee.module.ts","../../../projects/ngx-tolgee/src/public-api.ts","../../../projects/ngx-tolgee/src/tolgee-ngx.ts"],"sourcesContent":["import { EventEmitter, Injectable, OnDestroy } from '@angular/core';\nimport { Observable } from 'rxjs';\nimport { Tolgee, TranslationData } from '@tolgee/core';\nimport { TolgeeConfig } from './tolgeeConfig';\n\n@Injectable()\nexport class TranslateService implements OnDestroy {\n public readonly onLangChange: EventEmitter<never> = new EventEmitter<never>();\n public readonly onTranslationChange: EventEmitter<TranslationData> =\n new EventEmitter<TranslationData>();\n\n private runPromise: Promise<void>;\n private onTranslationChangeCoreSubscription: any;\n private onLangChangeCoreSubscription: any;\n\n constructor(private config: TolgeeConfig) {}\n\n private _tolgee: Tolgee;\n\n public get tolgee(): Tolgee {\n return this._tolgee;\n }\n\n /**\n * Starts Tolgee if not started and subscribes for languageChange and translationChange events\n */\n public async start(config: TolgeeConfig): Promise<void> {\n if (!this.runPromise) {\n this._tolgee = new Tolgee(config);\n this.runPromise = this.tolgee.run();\n // unsubscribe first, if it is subscribed for some reason\n this.unsubscribeCoreListeners();\n this.onTranslationChangeCoreSubscription =\n this._tolgee.onTranslationChange.subscribe((data) => {\n this.onTranslationChange.emit(data);\n });\n this.onLangChangeCoreSubscription = this._tolgee.onLangChange.subscribe(\n () => {\n this.onLangChange.emit();\n }\n );\n }\n await this.runPromise;\n }\n\n ngOnDestroy(): void {\n // stop it!\n this.tolgee.stop();\n // unsubscribe listeners\n this.unsubscribeCoreListeners();\n }\n\n /**\n * Changes the current language\n * @param lang The new current language (e.g. en, en-US)\n */\n public setLang(lang: string) {\n this.tolgee.lang = lang;\n }\n\n /**\n * Returns the current language\n */\n public getCurrentLang(): string {\n return this.tolgee.lang;\n }\n\n /**\n * Returns Observable providing current translated value\n * Tne observable is subscribed to translation change and language change events of Tolgee\n *\n * In development mode, it returns string wrapped with configured\n * prefix and suffix to be handled in browser by MutationObserver.\n *\n * You should use unsubscribe method when you are done!\n *\n * in onInit: this.subscription = translateService.get('aa')\n * in onDestroy: this.subscription.unsubscribe()\n *\n * @param key The key to translate (e.g. what-a-key)\n * @param params The parameters to interpolate (e.g. {name: \"John\"})\n * @param defaultValue Value, which will be rendered, when no translated value is provided\n */\n public get(\n key: string,\n params = {},\n defaultValue?: string\n ): Observable<string> {\n return this.translate(key, params, false, defaultValue);\n }\n\n /**\n * Returns Observable providing current translated value\n * Tne observable is subscribed to translation change and language change events of Tolgee\n *\n * In development mode, it returns the translated string,\n * so in-context localization is not going to work.\n *\n * You should use unsubscribe method when you are done!\n *\n * in onInit: this.subscription = translateService.get('aa')\n * in onDestroy: this.subscription.unsubscribe()\n *\n * @param key The key to translate (e.g. what-a-key)\n * @param params The parameters to interpolate (e.g. {name: \"John\"})\n * @param defaultValue Value, which will be rendered, when no translated value is provided\n */\n public getSafe(\n key: string,\n params = {},\n defaultValue?: string\n ): Observable<string> {\n return this.translate(key, params, true, defaultValue);\n }\n\n /**\n * Returns the translation value synchronously\n *\n * In development mode, it returns string wrapped with configured\n * prefix and suffix to be handled in browser by MutationObserver.\n *\n * @param key The key to translate (e.g. what-a-key)\n * @param params The parameters to interpolate (e.g. {name: \"John\"})\n * @param defaultValue Value, which will be rendered, when no translated value is provided\n */\n public instant(key: string, params = {}, defaultValue?: string): string {\n return this.tolgee.instant(key, params, undefined, undefined, defaultValue);\n }\n\n /**\n * Returns the translation value synchronously\n *\n * In development mode, it returns the translated string,\n * so in-context localization is not going to work.\n *\n * @param key The key to translate (e.g. what-a-key)\n * @param params The parameters to interpolate (e.g. {name: \"John\"})\n * @param defaultValue Value, which will be rendered, when no translated value is provided\n */\n public instantSafe(\n input: string,\n params = {},\n defaultValue?: string\n ): string {\n return this.tolgee.instant(input, params, true, undefined, defaultValue);\n }\n\n private unsubscribeCoreListeners() {\n this.onTranslationChangeCoreSubscription?.unsubscribe();\n this.onLangChangeCoreSubscription?.unsubscribe();\n }\n\n private translate(\n key: string,\n params = {},\n noWrap = false,\n defaultValue: string\n ): Observable<string> {\n return new Observable((subscriber) => {\n const translate = async () => {\n // start if not started\n await this.start(this.config);\n const translated = await this.tolgee.translate(\n key,\n params,\n noWrap,\n defaultValue\n );\n\n subscriber.next(translated);\n };\n\n translate();\n\n const onTranslationChangeSubscription =\n this.tolgee.onTranslationChange.subscribe((data) => {\n if (data.key === key) {\n translate();\n }\n });\n\n const onLanguageChangeSubscription = this.tolgee.onLangChange.subscribe(\n () => {\n translate();\n }\n );\n\n return () => {\n onTranslationChangeSubscription.unsubscribe();\n onLanguageChangeSubscription.unsubscribe();\n };\n });\n }\n}\n","import { OnDestroy, Pipe, PipeTransform } from '@angular/core';\nimport { TranslateService } from './translate.service';\nimport { Observable, Subscription } from 'rxjs';\n\n@Pipe({\n name: 'translate',\n pure: false,\n})\nexport class TranslatePipe implements PipeTransform, OnDestroy {\n value = '';\n key: string;\n params: Record<string, any>;\n defaultValue: string;\n private;\n private subscription: Subscription;\n\n constructor(protected translateService: TranslateService) {}\n\n protected get resultProvider(): (\n key,\n params,\n defaultValue: string\n ) => Observable<string> {\n return (key, params, defaultValue) =>\n this.translateService.get(key, params, defaultValue);\n }\n\n ngOnDestroy(): void {\n this.unsubscribe();\n }\n\n transform(key: any, params?: Record<string, any>): string;\n\n transform(\n key: any,\n defaultValue?: string,\n params?: Record<string, any>\n ): string;\n\n transform(\n key: any,\n paramsOrDefaultValue?: Record<string, any> | string,\n params?: Record<string, any>\n ): string {\n if (!key || key.length === 0) {\n return key;\n }\n\n const defaultValue =\n typeof paramsOrDefaultValue !== 'object'\n ? paramsOrDefaultValue\n : undefined;\n\n if (typeof paramsOrDefaultValue === 'object') {\n params = paramsOrDefaultValue;\n }\n\n if (\n this.key === key &&\n JSON.stringify(this.params) === JSON.stringify(params) &&\n this.defaultValue === defaultValue\n ) {\n return this.value;\n }\n\n this.key = key;\n this.params = params;\n this.defaultValue = defaultValue;\n\n // unsubscribe first\n this.unsubscribe();\n\n // asynchronously translate and assign subscription\n this.subscription = this.translate(key, params, defaultValue);\n\n return this.value;\n }\n\n private unsubscribe() {\n if (this.subscription) {\n this.subscription.unsubscribe();\n }\n }\n\n private translate(key, params, defaultValue) {\n return this.resultProvider(key, params, defaultValue).subscribe((r) => {\n this.value = r;\n });\n }\n}\n","import { Pipe } from '@angular/core';\nimport { TranslateService } from './translate.service';\nimport { TranslatePipe } from './translate.pipe';\nimport { Observable } from 'rxjs';\n\n@Pipe({\n name: 'stranslate',\n pure: false,\n})\nexport class STranslatePipe extends TranslatePipe {\n constructor(translateService: TranslateService) {\n super(translateService);\n }\n\n protected get resultProvider(): (\n input,\n params,\n defaultValue\n ) => Observable<string> {\n return (input, params, defaultValue) =>\n this.translateService.getSafe(input, params, defaultValue);\n }\n}\n","import { Component, ElementRef, Input, OnDestroy, OnInit } from '@angular/core';\nimport { Subscription } from 'rxjs';\nimport { TranslateService } from './translate.service';\nimport { TOLGEE_WRAPPED_ONLY_DATA_ATTRIBUTE } from '@tolgee/core';\n\n@Component({\n selector: '[t]',\n template: ``,\n})\nexport class TComponent implements OnInit, OnDestroy {\n @Input() params?: Record<string, any>;\n @Input() key: string;\n @Input() default?: string;\n subscription: Subscription;\n\n constructor(\n private ref: ElementRef,\n private translateService: TranslateService\n ) {}\n\n ngOnInit(): void {\n const element = this.ref.nativeElement as HTMLElement;\n element.setAttribute(TOLGEE_WRAPPED_ONLY_DATA_ATTRIBUTE, this.key);\n\n // set safe at first\n element.textContent = this.translateService.instantSafe(\n this.key,\n this.params,\n this.default\n );\n\n // then do the async translation\n this.subscription = this.translateService\n .getSafe(this.key, this.params, this.default)\n .subscribe((translated) => {\n return (element.textContent = translated);\n });\n }\n\n ngOnDestroy(): void {\n if (this.subscription) {\n this.subscription.unsubscribe();\n }\n }\n}\n","import {Injectable} from '@angular/core';\nimport {TranslateService} from \"./translate.service\";\nimport {TolgeeConfig} from \"@tolgee/core\";\n\n@Injectable()\nexport class TranslationsProvider {\n\n constructor(private translateService: TranslateService) {\n }\n\n async load(options: TolgeeConfig) {\n return await this.translateService.start(options);\n }\n}\n\n\n","import { APP_INITIALIZER, ModuleWithProviders, NgModule } from '@angular/core';\nimport { TranslatePipe } from './translate.pipe';\nimport { TranslationsProvider } from './translations-provider';\nimport { TranslateService } from './translate.service';\nimport { STranslatePipe } from './stranslate.pipe';\nimport { TolgeeConfig } from './tolgeeConfig';\nimport { TComponent } from './t.component';\n\n@NgModule({\n declarations: [TranslatePipe, STranslatePipe, TComponent],\n exports: [TranslatePipe, STranslatePipe, TComponent],\n providers: [],\n})\nexport class NgxTolgeeModule {\n // @dynamic\n static forRoot(options: TolgeeConfig): ModuleWithProviders<NgxTolgeeModule> {\n options = { filesUrlPrefix: '/assets/i18n/', ...options };\n return {\n ngModule: NgxTolgeeModule,\n providers: [\n TranslateService,\n TranslationsProvider,\n {\n provide: APP_INITIALIZER,\n useFactory: (provider: TranslationsProvider) => {\n return async () => await provider.load(options);\n },\n deps: [TranslationsProvider, TranslateService],\n multi: true,\n },\n { provide: TolgeeConfig, useValue: options },\n ],\n };\n }\n}\n","/*\n * Public API Surface of ngx-tolgee\n */\nimport { TranslateService } from './lib/translate.service';\nimport { TranslatePipe } from './lib/translate.pipe';\nimport { STranslatePipe } from './lib/stranslate.pipe';\nimport { TolgeeConfig } from './lib/tolgeeConfig';\nimport { TComponent } from './lib/t.component';\n\nexport * from './lib/ngx-tolgee.module';\nexport { TolgeeConfig };\nexport { TranslateService };\nexport { TranslatePipe };\nexport { STranslatePipe };\nexport { TComponent };\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;MAMa,gBAAgB;IAS3B,YAAoB,MAAoB;QAApB,WAAM,GAAN,MAAM,CAAc;QARxB,iBAAY,GAAwB,IAAI,YAAY,EAAS,CAAC;QAC9D,wBAAmB,GACjC,IAAI,YAAY,EAAmB,CAAC;KAMM;IAI5C,IAAW,MAAM;QACf,OAAO,IAAI,CAAC,OAAO,CAAC;KACrB;;;;IAKM,MAAM,KAAK,CAAC,MAAoB;QACrC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE;YACpB,IAAI,CAAC,OAAO,GAAG,IAAI,MAAM,CAAC,MAAM,CAAC,CAAC;YAClC,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC;;YAEpC,IAAI,CAAC,wBAAwB,EAAE,CAAC;YAChC,IAAI,CAAC,mCAAmC;gBACtC,IAAI,CAAC,OAAO,CAAC,mBAAmB,CAAC,SAAS,CAAC,CAAC,IAAI;oBAC9C,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;iBACrC,CAAC,CAAC;YACL,IAAI,CAAC,4BAA4B,GAAG,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,SAAS,CACrE;gBACE,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC;aAC1B,CACF,CAAC;SACH;QACD,MAAM,IAAI,CAAC,UAAU,CAAC;KACvB;IAED,WAAW;;QAET,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC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s';
2
+ import { Subscription } from 'rxjs';
3
3
  import { TranslateService } from './translate.service';
4
4
  import * as i0 from "@angular/core";
5
5
  export declare class TComponent implements OnInit, OnDestroy {
6
6
  private ref;
7
7
  private translateService;
8
- value: string;
9
8
  params?: Record<string, any>;
10
9
  key: string;
11
10
  default?: string;
12
- onLangChangeSubscription: Subscription;
13
- onTranslationChangeSubscription: Subscription;
11
+ subscription: Subscription;
14
12
  constructor(ref: ElementRef, translateService: TranslateService);
15
- protected get resultProvider(): (key: any, params: any, defaultValue: string) => Observable<string>;
16
13
  ngOnInit(): void;
17
14
  ngOnDestroy(): void;
18
- private translate;
19
15
  static ɵfac: i0.ɵɵFactoryDeclaration<TComponent, never>;
20
16
  static ɵcmp: i0.ɵɵComponentDeclaration<TComponent, "[t]", never, { "params": "params"; "key": "key"; "default": "default"; }, {}, never, never>;
21
17
  }
@@ -5,15 +5,18 @@ import * as i0 from "@angular/core";
5
5
  export declare class TranslatePipe implements PipeTransform, OnDestroy {
6
6
  protected translateService: TranslateService;
7
7
  value: string;
8
- lastHash: string;
9
- private langChangeSubscription;
8
+ key: string;
9
+ params: Record<string, any>;
10
+ defaultValue: string;
11
+ private: any;
12
+ private subscription;
10
13
  constructor(translateService: TranslateService);
11
14
  protected get resultProvider(): (key: any, params: any, defaultValue: string) => Observable<string>;
12
15
  ngOnDestroy(): void;
13
- transform(input: any, params?: Record<string, any>): string;
14
- transform(input: any, defaultValue?: string, params?: Record<string, any>): string;
15
- private getHash;
16
- private onLangChange;
16
+ transform(key: any, params?: Record<string, any>): string;
17
+ transform(key: any, defaultValue?: string, params?: Record<string, any>): string;
18
+ private unsubscribe;
19
+ private translate;
17
20
  static ɵfac: i0.ɵɵFactoryDeclaration<TranslatePipe, never>;
18
21
  static ɵpipe: i0.ɵɵPipeDeclaration<TranslatePipe, "translate">;
19
22
  }
@@ -13,14 +13,76 @@ export declare class TranslateService implements OnDestroy {
13
13
  constructor(config: TolgeeConfig);
14
14
  private _tolgee;
15
15
  get tolgee(): Tolgee;
16
+ /**
17
+ * Starts Tolgee if not started and subscribes for languageChange and translationChange events
18
+ */
16
19
  start(config: TolgeeConfig): Promise<void>;
17
20
  ngOnDestroy(): void;
21
+ /**
22
+ * Changes the current language
23
+ * @param lang The new current language (e.g. en, en-US)
24
+ */
18
25
  setLang(lang: string): void;
19
- get(input: string, params?: {}, defaultValue?: string): Observable<string>;
20
- getSafe(input: string, params?: {}, defaultValue?: string): Observable<string>;
21
- instant(input: string, params?: {}, defaultValue?: string): string;
22
- instantSafe(input: string, params?: {}, defaultValue?: string): string;
26
+ /**
27
+ * Returns the current language
28
+ */
23
29
  getCurrentLang(): string;
30
+ /**
31
+ * Returns Observable providing current translated value
32
+ * Tne observable is subscribed to translation change and language change events of Tolgee
33
+ *
34
+ * In development mode, it returns string wrapped with configured
35
+ * prefix and suffix to be handled in browser by MutationObserver.
36
+ *
37
+ * You should use unsubscribe method when you are done!
38
+ *
39
+ * in onInit: this.subscription = translateService.get('aa')
40
+ * in onDestroy: this.subscription.unsubscribe()
41
+ *
42
+ * @param key The key to translate (e.g. what-a-key)
43
+ * @param params The parameters to interpolate (e.g. {name: "John"})
44
+ * @param defaultValue Value, which will be rendered, when no translated value is provided
45
+ */
46
+ get(key: string, params?: {}, defaultValue?: string): Observable<string>;
47
+ /**
48
+ * Returns Observable providing current translated value
49
+ * Tne observable is subscribed to translation change and language change events of Tolgee
50
+ *
51
+ * In development mode, it returns the translated string,
52
+ * so in-context localization is not going to work.
53
+ *
54
+ * You should use unsubscribe method when you are done!
55
+ *
56
+ * in onInit: this.subscription = translateService.get('aa')
57
+ * in onDestroy: this.subscription.unsubscribe()
58
+ *
59
+ * @param key The key to translate (e.g. what-a-key)
60
+ * @param params The parameters to interpolate (e.g. {name: "John"})
61
+ * @param defaultValue Value, which will be rendered, when no translated value is provided
62
+ */
63
+ getSafe(key: string, params?: {}, defaultValue?: string): Observable<string>;
64
+ /**
65
+ * Returns the translation value synchronously
66
+ *
67
+ * In development mode, it returns string wrapped with configured
68
+ * prefix and suffix to be handled in browser by MutationObserver.
69
+ *
70
+ * @param key The key to translate (e.g. what-a-key)
71
+ * @param params The parameters to interpolate (e.g. {name: "John"})
72
+ * @param defaultValue Value, which will be rendered, when no translated value is provided
73
+ */
74
+ instant(key: string, params?: {}, defaultValue?: string): string;
75
+ /**
76
+ * Returns the translation value synchronously
77
+ *
78
+ * In development mode, it returns the translated string,
79
+ * so in-context localization is not going to work.
80
+ *
81
+ * @param key The key to translate (e.g. what-a-key)
82
+ * @param params The parameters to interpolate (e.g. {name: "John"})
83
+ * @param defaultValue Value, which will be rendered, when no translated value is provided
84
+ */
85
+ instantSafe(input: string, params?: {}, defaultValue?: string): string;
24
86
  private unsubscribeCoreListeners;
25
87
  private translate;
26
88
  static ɵfac: i0.ɵɵFactoryDeclaration<TranslateService, never>;
package/package.json CHANGED
@@ -5,7 +5,11 @@
5
5
  "type": "git",
6
6
  "url": "https://github.com/tolgee/tolgee-js"
7
7
  },
8
- "version": "2.3.2",
8
+ "dependencies": {
9
+ "@tolgee/core": "^2.8.1",
10
+ "tslib": "^2.3.0"
11
+ },
12
+ "version": "2.8.1",
9
13
  "publishConfig": {
10
14
  "directory": "../../dist/ngx-tolgee",
11
15
  "access": "public"
@@ -29,8 +33,5 @@
29
33
  "default": "./fesm2020/tolgee-ngx.mjs"
30
34
  }
31
35
  },
32
- "sideEffects": false,
33
- "dependencies": {
34
- "tslib": "^2.3.0"
35
- }
36
+ "sideEffects": false
36
37
  }