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

Commit 9d6d6f7

Browse files
authored
Merge pull request #16 from panter/fixes/parent-namespace
fix: load parent namespace
2 parents 31635c8 + 3fdf019 commit 9d6d6f7

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

src/install.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ export function install(_Vue) {
8484
this._i18nOptions = { lng, namespaces: namespacesToLoad, keyPrefix };
8585
this.$i18n.i18next.loadNamespaces(namespaces);
8686
} else if (options.parent && options.parent._i18nOptions) {
87-
this._i18nOptions = options.parent._i18nOptions;
87+
this._i18nOptions = { ...options.parent._i18nOptions };
88+
this._i18nOptions.namespaces = [namespace, ...this._i18nOptions.namespaces];
8889
} else if (options.__i18n) {
8990
this._i18nOptions = { namespaces: [namespace] };
9091
}

test/unit/component.test.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,56 @@ describe('Component inline translation', () => {
155155
expect(vm.$refs.yesNoMaybe.textContent).to.equal('Maybe?');
156156
expect(vm.$refs.yesNoNo.textContent).to.equal('No');
157157
});
158+
159+
it('should use the translation in the tag', async () => {
160+
expect(vm.$refs.yesNoYes.textContent).to.equal('Yes');
161+
expect(vm.$refs.yesNoMaybe.textContent).to.equal('Maybe?');
162+
expect(vm.$refs.yesNoNo.textContent).to.equal('No');
163+
});
164+
165+
describe('should work with parents', () => {
166+
beforeEach((done) => {
167+
i18next1.init({
168+
lng: 'en',
169+
resources: {
170+
en: {},
171+
},
172+
});
173+
vueI18Next = new VueI18Next(i18next1);
174+
175+
const el = document.createElement('div');
176+
vm = new Vue({
177+
i18n: vueI18Next,
178+
i18nOptions: {},
179+
name: 'main-comp',
180+
components: {
181+
child: {
182+
name: 'child',
183+
render(h) {
184+
return h('div', {}, [h('p', { ref: 'yesNoYes' }, [this.$t('yesNo.yes')])]);
185+
},
186+
},
187+
},
188+
__i18n: [
189+
JSON.stringify({
190+
en: { yesNo: { yes: 'Yes', maybe: 'Maybe' } },
191+
}),
192+
JSON.stringify({
193+
en: { yesNo: { no: 'No', maybe: 'Maybe?' } },
194+
}),
195+
],
196+
render(h) {
197+
return h('child', { ref: 'subChild' });
198+
},
199+
}).$mount(el);
200+
201+
vm.$nextTick(done);
202+
});
203+
204+
it('should merge namespaces even if parent has none', async () => {
205+
expect(vm.$refs.subChild.$refs.yesNoYes.textContent).to.equal('Yes');
206+
});
207+
});
158208
});
159209

160210
describe('full options', () => {

0 commit comments

Comments
 (0)