Skip to content
This repository has been archived by the owner on May 19, 2022. It is now read-only.

Commit

Permalink
fix: load parent namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiocro committed Nov 28, 2017
1 parent ed9e7dc commit 3fdf019
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ export function install(_Vue) {
this._i18nOptions = { lng, namespaces: namespacesToLoad, keyPrefix };
this.$i18n.i18next.loadNamespaces(namespaces);
} else if (options.parent && options.parent._i18nOptions) {
this._i18nOptions = options.parent._i18nOptions;
this._i18nOptions = { ...options.parent._i18nOptions };
this._i18nOptions.namespaces = [namespace, ...this._i18nOptions.namespaces];
} else if (options.__i18n) {
this._i18nOptions = { namespaces: [namespace] };
}
Expand Down
50 changes: 50 additions & 0 deletions test/unit/component.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,56 @@ describe('Component inline translation', () => {
expect(vm.$refs.yesNoMaybe.textContent).to.equal('Maybe?');
expect(vm.$refs.yesNoNo.textContent).to.equal('No');
});

it('should use the translation in the tag', async () => {
expect(vm.$refs.yesNoYes.textContent).to.equal('Yes');
expect(vm.$refs.yesNoMaybe.textContent).to.equal('Maybe?');
expect(vm.$refs.yesNoNo.textContent).to.equal('No');
});

describe('should work with parents', () => {
beforeEach((done) => {
i18next1.init({
lng: 'en',
resources: {
en: {},
},
});
vueI18Next = new VueI18Next(i18next1);

const el = document.createElement('div');
vm = new Vue({
i18n: vueI18Next,
i18nOptions: {},
name: 'main-comp',
components: {
child: {
name: 'child',
render(h) {
return h('div', {}, [h('p', { ref: 'yesNoYes' }, [this.$t('yesNo.yes')])]);
},
},
},
__i18n: [
JSON.stringify({
en: { yesNo: { yes: 'Yes', maybe: 'Maybe' } },
}),
JSON.stringify({
en: { yesNo: { no: 'No', maybe: 'Maybe?' } },
}),
],
render(h) {
return h('child', { ref: 'subChild' });
},
}).$mount(el);

vm.$nextTick(done);
});

it('should merge namespaces even if parent has none', async () => {
expect(vm.$refs.subChild.$refs.yesNoYes.textContent).to.equal('Yes');
});
});
});

describe('full options', () => {
Expand Down

0 comments on commit 3fdf019

Please sign in to comment.