Releases: dkfbasel/vuex-i18n
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').
Update $i18n.keyExists method
Based on #57 the method $i18n.keyExists()
was slightly modified.
Prior to v1.9.0, the method would check for existence of the key in the current locale and the fallback locale.
Now, the method will check the current locale, the regional parent language locale (i.e. en for en-us) and the fallback locale for the key. This is in line with how the method $t()
will translate a given key.
Additionally a second parameter can be specified to limit the scope that should be checked for the key $i18n.keyExists('key', 'strict')
. Available options are strict
(only current locale), locale
(current locale and regional parent language) and fallback
(current locale, regional parent locale and fallback locale). Details can be found in the readme.
Plugin config options as object and new onTranslationNotFound method
This version has several fixes:
- The minified file version is now actually a minified version of the umd version
- There will be a warning, if the locale is not specified when a translation key is used
- Plugin initialization options can now be set via an object. A depreciation warning is shown for the array initialization method
- There is a new plugin option onTranslationNotFound. This is a method that will be called if the translation key is not found in the current locale. Albeit the translation might still be available in a localized locale or the fallback locale.
Adapt method to add a locale
Previously the method $i18n.add(locale, translations) would replace all existing locale information. With this release, the method will extend existing locale information, making it possible to fill in locale translations from components separately.
Additionally there is a new method $i18n.replace(locale, translations), that will replace all existing locale information (just as $i18n.add() did before).
Support for regional fallback locale
This release adds support for a regional fallback locale. As an example the locale, de-CH
will first fallback to de
, then to the specified fallback locale or the default value if no fallback locale was specified.
See issue #29 for details.
Bugfix for pluralization
This release contains an important bugfix for pluralization. Please make sure to update from 1.5.0
Multiple pluralizations, support for separate key and default values
This release adds two new features:
- Multiple pluralization strings are not supported for languages that have more than one plural form. This is very much inspired from vue-gettext
- It is now possible to keep translation keys and default values separate. This should make it easier for large projects to manage the translation keys even if the default values might change over time. Simply specify the default value after the key to use separate keys and default values
$t('translation.key', 'default text for key')
. Variable substitution and pluralization should still work as expected.
Another bugfix
This version should fix issues when adding a new locale that could occur with older versions of vuex. The plugin uses an internal vuex mechanism to notify watcher when adding a new locale and this might not be present on earlier vuex versions.
if (state.translations.__ob__) {
state.translations.__ob__.dep.notify();
}
Bugfix for version 1.4.0
This is an important bugfix for version 1.4.0 which broke compatibility for nested translation keys.
Phase out of exists method
The exists method will be phased out with this version. The method has been renamed to localeExists and a new method keyExists has been added.
In addition updating of existing translation information and use of custom variable tag identifiers has been added (in comparison to version 1.3.4).