Skip to content

Commit

Permalink
Language is not chaged using use if the language is the same as the d…
Browse files Browse the repository at this point in the history
…efault #92 (#93)

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

* Language is not chaged using use if the language is the same as the default #92
Fix codacy issue

Co-authored-by: Carlos Rodriguez Aguado <crodriguez2@werfen.com>
  • Loading branch information
carlosra85 and Carlos Rodriguez Aguado committed Aug 23, 2022
1 parent e092013 commit 69bc1ef
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
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();
});
});
});

0 comments on commit 69bc1ef

Please sign in to comment.