Skip to content

Commit

Permalink
Merge pull request #356 from chrismayer/global-app-lang-lookup
Browse files Browse the repository at this point in the history
Introduce global app language lookup
  • Loading branch information
chrismayer authored Apr 18, 2024
2 parents 8cb3059 + 90c4a52 commit 6cde5d3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
16 changes: 12 additions & 4 deletions app-starter/WguAppTemplate.vue
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export default {
}
},
created () {
this.setGlobalAppLang(); // initially set global app language lookup
this.setDocumentTitle();
},
mounted () {
Expand Down Expand Up @@ -189,17 +190,24 @@ export default {
return moduleWins;
},
/**
* Sets the document title from language file.
*/
* Sets the document title from language file.
*/
setDocumentTitle () {
document.title = this.$t('app.browserTitle') || document.title;
},
/**
* Sets the current i18n language to the global app language lookup.
*/
setGlobalAppLang () {
Vue.prototype.$appLanguage = this.$i18n.locale;
}
},
watch: {
/**
* Watch for locale changes.
*/
* Watch for locale changes.
*/
'$i18n.locale': function () {
this.setGlobalAppLang();
this.setDocumentTitle();
}
}
Expand Down
21 changes: 21 additions & 0 deletions tests/unit/specs/WguAppTemplate.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,26 @@ describe('WguAppTpl.vue', () => {
expect(moduleData[0].type).to.equal('wgu-infoclick-win');
expect(moduleData[0].target).to.equal('menu');
});

it('has a method setGlobalAppLang', () => {
expect(vm.setGlobalAppLang).to.be.a('function');
});
});

describe('global app language lookup', () => {
let comp;
let vm;
beforeEach(() => {
comp = shallowMount(WguAppTpl);
vm = comp.vm;
});

it('is set correctly', () => {
expect(vm.$i18n.locale).to.equal(Vue.prototype.$appLanguage);
});

afterEach(() => {
comp.destroy();
});
});
});

0 comments on commit 6cde5d3

Please sign in to comment.