Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Language is not chaged using use if the language is the same as the default #92 #93

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions projects/systelab-translate/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ If you want to get the browser language, call the method:
this.i18nService.getBrowserLang()
```

If you want to force reloading a language

```javascript
this.i18nService.reloadLanguage('en-US').subscribe(() => console.log('Translations for American English reloaded.'));
```

### Translate

There are two convenient methods to set or append new keys to an specific locale:
Expand Down
2 changes: 1 addition & 1 deletion projects/systelab-translate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"Translate",
"i18n"
],
"version": "11.1.0",
"version": "11.1.1",
"license": "MIT",
"homepage": "https://github.com/systelab/systelab-translate.git",
"repository": {
Expand Down
4 changes: 4 additions & 0 deletions projects/systelab-translate/src/lib/i18n.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ export class I18nService {
return this.translateService.getBrowserLang();
}

public reloadLanguage(lang: string): Observable<any> {
return this.translateService.reloadLang(lang);
}

public setTranslation(locale: string, translations: Object): void {
this.translateService.setTranslation(locale, translations, false);
}
Expand Down
26 changes: 26 additions & 0 deletions projects/systelab-translate/src/test/i18n.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { httpLoaderFactory, I18nService } from '../public-api';
import { TestBed } from '@angular/core/testing';
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
import { HttpClient, HttpClientModule } from '@angular/common/http';
import { switchMap } from 'rxjs/operators';

describe('Translate Service', () => {
let service: I18nService;
Expand Down Expand Up @@ -318,4 +319,29 @@ describe('Translate Service', () => {
});
});

it('Check using reloadLanguage the translation of a key in english', (done) => {
service.use('en-US')
.pipe(
switchMap(()=>service.reloadLanguage('en-US'))
)
.subscribe(() => {
expect(service.instant('COMMON_DAY'))
.toBe('Day');
done();
},
(error) => {
});
});

it('Check using reloadLanguage the translation of a key in spanish', (done) => {
service.use('es-ES')
.pipe(
switchMap(()=>service.reloadLanguage('es-ES'))
)
.subscribe(() => {
expect(service.instant('COMMON_DAY'))
.toBe('Día');
done();
});
});
});