Skip to content

Commit

Permalink
add translateIn filter
Browse files Browse the repository at this point in the history
  • Loading branch information
tikiatua committed Jan 2, 2019
1 parent 783692e commit a2f4e84
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/vuex-i18n-plugin.js
Expand Up @@ -28,13 +28,15 @@ VuexI18nPlugin.install = function install(Vue, store, config) {
identifiers: ['{', '}'],
preserveState: false,
translateFilterName: 'translate',
translateInFilterName: 'translateIn',
onTranslationNotFound: function() {}
}, config);

// define module name and identifiers as constants to prevent any changes
const moduleName = config.moduleName;
const identifiers = config.identifiers;
const translateFilterName = config.translateFilterName;
const translateInFilterName = config.translateInFilterName;

// initialize the onTranslationNotFound function and make sure it is actually
// a function
Expand Down Expand Up @@ -199,6 +201,11 @@ VuexI18nPlugin.install = function install(Vue, store, config) {

};

// add a filter function to translate in a given locale (i.e. {{ 'something' | translateIn('en') }})
let translateInLanguageFilter = function translateInLanguageFilter(key, locale, ...args) {
return translateInLanguage(locale, key, ...args);
};

// check if the given key exists in the current locale
let checkKeyExists = function checkKeyExists(key, scope = 'fallback') {

Expand Down Expand Up @@ -346,6 +353,7 @@ VuexI18nPlugin.install = function install(Vue, store, config) {

// register a filter function for translations
Vue.filter(translateFilterName, translate);
Vue.filter(translateInFilterName, translateInLanguageFilter);

};

Expand Down

0 comments on commit a2f4e84

Please sign in to comment.