Skip to content

Commit

Permalink
fix(I18NextService): context-safe calls of i18next methods
Browse files Browse the repository at this point in the history
  • Loading branch information
fshchudlo committed Jun 29, 2017
1 parent cfe9ec7 commit 455a07d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// Place your settings in this file to overwrite default and user settings.
{
"search.exclude": {
"coverage": true,
"dist": true,
"build": true
}
}
16 changes: 8 additions & 8 deletions src/I18NextService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class I18NextService {
private i18nextPromise: Promise<void>;

public use(plugin: Function) {
i18next.use(plugin);
i18next.use.call(i18next, plugin);
return this;
}

Expand All @@ -32,7 +32,7 @@ export class I18NextService {

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

public t(key: string | string[], options?: any): string {
options = options || {};
return i18next.t(<any>key, options);
return i18next.t.call(i18next, <any>key, options);
}

public changeLanguage(lng: string): Promise<i18next.TranslationFunction> {
return new Promise<i18next.TranslationFunction>(
(resolve: (thenableOrResult?: i18next.TranslationFunction) => void,
reject: (error: any) => void) => {
i18next.changeLanguage(lng, (err, t) => {
i18next.changeLanguage.call(i18next, lng, (err, t) => {
if (!err)
resolve(t);
else
Expand All @@ -65,14 +65,14 @@ export class I18NextService {
}

private subscribeEvents() {
i18next.on('initialized', e => {
i18next.on.call(i18next, 'initialized', e => {
this.language = i18next.language;
this.languages = i18next.languages;
this.events.initialized.next(!!e);
});
i18next.on('loaded', e => this.events.loaded.next(!!e));
i18next.on('failedLoading', e => this.events.failedLoading.next(e));
i18next.on('languageChanged', e => {
i18next.on.call(i18next, 'loaded', e => this.events.loaded.next(!!e));
i18next.on.call(i18next, 'failedLoading', e => this.events.failedLoading.next(e));
i18next.on.call(i18next, 'languageChanged', e => {
this.language = i18next.language;
this.languages = i18next.languages;
this.events.languageChanged.next(e);
Expand Down
2 changes: 1 addition & 1 deletion src/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-i18next",
"version": "0.1.1",
"version": "0.2.1",
"homepage": "https://github.com/Romanchuk/angular-i18next#readme",
"author": {
"name": "Sergey Romanchuk"
Expand Down

0 comments on commit 455a07d

Please sign in to comment.