Improve onTranslationNotFound method, namespace i18n module
This release improves the onTranslationNotFound method in response to issue #59.
Improvement of i18n method
It is now possible to return a value from the method that will be used as new translation for the given key. The return value can be a string or a promise.
If a return value is specified, the respective locale will be updated in the store. Hence, subsequent requests to the same key will not trigger the onTranslationNotFound method any more.
// with string as return value. this will write the new value as translation into the store
// note: synchronous resolving of keys is not recommended as this functionality
// should be implemented in a different way
Vue.use(vuexI18n.plugin, store, {
moduleName: 'i18n',
onTranslationNotFound (locale, key) {
switch(key) {
case: '200':
return 'Everything went fine';
break;
default:
return 'There was a problem';
}
}}
);
// with promise as return value. this will write the new value into the store,
// after the promise is resolved
Vue.use(vuexI18n.plugin, store, {
moduleName: 'i18n',
onTranslationNotFound (locale, key) {
return new Promise((resolve, reject) => {
axios.get('/api/translations/async', {locale: locale, key:key})
.then((result) => {
resolve(result.data);
}).catch() {
reject();
}
})
}}
);
Namespacing of i18n module
The i18n module is not properly name-spaced. All actions of the module need to be called with the module prefix. ie. store.dispatch('i18n/addLocale').