Skip to content

Commit 455a07d

Browse files
committed
fix(I18NextService): context-safe calls of i18next methods
1 parent cfe9ec7 commit 455a07d

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

.vscode/settings.json

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
// Place your settings in this file to overwrite default and user settings.
22
{
3+
"search.exclude": {
4+
"coverage": true,
5+
"dist": true,
6+
"build": true
7+
}
38
}

src/I18NextService.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class I18NextService {
2121
private i18nextPromise: Promise<void>;
2222

2323
public use(plugin: Function) {
24-
i18next.use(plugin);
24+
i18next.use.call(i18next, plugin);
2525
return this;
2626
}
2727

@@ -32,7 +32,7 @@ export class I18NextService {
3232

3333
return this.i18nextPromise =
3434
new Promise<void>((resolve: (thenableOrResult?: void | Promise<void>) => void, reject: (error: any) => void) => {
35-
i18next.init(Object.assign({}, options),
35+
i18next.init.call(i18next, Object.assign({}, options),
3636
(err: any) => {
3737
if (err) {
3838
console.error(err);
@@ -47,14 +47,14 @@ export class I18NextService {
4747

4848
public t(key: string | string[], options?: any): string {
4949
options = options || {};
50-
return i18next.t(<any>key, options);
50+
return i18next.t.call(i18next, <any>key, options);
5151
}
5252

5353
public changeLanguage(lng: string): Promise<i18next.TranslationFunction> {
5454
return new Promise<i18next.TranslationFunction>(
5555
(resolve: (thenableOrResult?: i18next.TranslationFunction) => void,
5656
reject: (error: any) => void) => {
57-
i18next.changeLanguage(lng, (err, t) => {
57+
i18next.changeLanguage.call(i18next, lng, (err, t) => {
5858
if (!err)
5959
resolve(t);
6060
else
@@ -65,14 +65,14 @@ export class I18NextService {
6565
}
6666

6767
private subscribeEvents() {
68-
i18next.on('initialized', e => {
68+
i18next.on.call(i18next, 'initialized', e => {
6969
this.language = i18next.language;
7070
this.languages = i18next.languages;
7171
this.events.initialized.next(!!e);
7272
});
73-
i18next.on('loaded', e => this.events.loaded.next(!!e));
74-
i18next.on('failedLoading', e => this.events.failedLoading.next(e));
75-
i18next.on('languageChanged', e => {
73+
i18next.on.call(i18next, 'loaded', e => this.events.loaded.next(!!e));
74+
i18next.on.call(i18next, 'failedLoading', e => this.events.failedLoading.next(e));
75+
i18next.on.call(i18next, 'languageChanged', e => {
7676
this.language = i18next.language;
7777
this.languages = i18next.languages;
7878
this.events.languageChanged.next(e);

src/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-i18next",
3-
"version": "0.1.1",
3+
"version": "0.2.1",
44
"homepage": "https://github.com/Romanchuk/angular-i18next#readme",
55
"author": {
66
"name": "Sergey Romanchuk"

0 commit comments

Comments
 (0)