Commit c4e9ad276101c957bdc046b37efa21be192d5ac6
1 parent
024d6059
Exists in
master
and in
31 other branches
Config available languages when the current language changes
Showing
2 changed files
with
13 additions
and
5 deletions
Show diff stats
src/app/components/translator/translator.service.spec.ts
| ... | ... | @@ -31,8 +31,8 @@ describe("Services", () => { |
| 31 | 31 | let component: TranslatorService = createComponent(); |
| 32 | 32 | component.availableLanguages = null; |
| 33 | 33 | expect(component.availableLanguages).toBeNull(); |
| 34 | - component.changeLanguage('en'); | |
| 35 | - expect(component.availableLanguages).toBeDefined(); | |
| 34 | + $rootScope.$emit("$translateChangeSuccess"); | |
| 35 | + expect(component.availableLanguages).not.toBeNull(); | |
| 36 | 36 | done(); |
| 37 | 37 | }); |
| 38 | 38 | |
| ... | ... | @@ -55,6 +55,14 @@ describe("Services", () => { |
| 55 | 55 | done(); |
| 56 | 56 | }); |
| 57 | 57 | |
| 58 | + it("do not load moment locale when change the language to english", (done) => { | |
| 59 | + let component: TranslatorService = createComponent(); | |
| 60 | + component["angularLoad"].loadScript = jasmine.createSpy("loadScript").and.returnValue($q.defer().promise); | |
| 61 | + component.changeLanguage('en'); | |
| 62 | + expect(component["angularLoad"].loadScript).not.toHaveBeenCalledWith("/bower_components/moment/locale/pt.js"); | |
| 63 | + done(); | |
| 64 | + }); | |
| 65 | + | |
| 58 | 66 | it("do nothing when call change language with null", (done) => { |
| 59 | 67 | let component: TranslatorService = createComponent(); |
| 60 | 68 | component["angularLoad"].loadScript = jasmine.createSpy("loadScript"); | ... | ... |
src/app/components/translator/translator.service.ts
| ... | ... | @@ -12,10 +12,12 @@ export class TranslatorService { |
| 12 | 12 | private angularLoad: any, |
| 13 | 13 | private $rootScope: any) { |
| 14 | 14 | |
| 15 | - this.configAvailableLanguages(); | |
| 16 | 15 | this.$rootScope.$on("$localeChangeSuccess", () => { |
| 17 | 16 | this.changeLanguage(tmhDynamicLocale.get() || $translate.use()); |
| 18 | 17 | }); |
| 18 | + this.$rootScope.$on("$translateChangeSuccess", () => { | |
| 19 | + this.configAvailableLanguages(); | |
| 20 | + }); | |
| 19 | 21 | } |
| 20 | 22 | |
| 21 | 23 | currentLanguage() { |
| ... | ... | @@ -31,8 +33,6 @@ export class TranslatorService { |
| 31 | 33 | this.tmhDynamicLocale.set(language); |
| 32 | 34 | this.angularLoad.loadScript(`/bower_components/messageformat/locale/${language}.js`).then(() => { |
| 33 | 35 | return this.$translate.use(language); |
| 34 | - }).then(() => { | |
| 35 | - this.configAvailableLanguages(); | |
| 36 | 36 | }); |
| 37 | 37 | } |
| 38 | 38 | ... | ... |