Created
March 11, 2021 12:38
-
-
Save defaye/04e9eb0ad59a978f2e5a9ccf9a01e9a0 to your computer and use it in GitHub Desktop.
Translation helper to be used with messages in a Vue store
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { at } from 'lodash' | |
Vue.prototype.$t = function (translationKey, options) { | |
const rawTranslation = at(this.$store.state.translations.translations, translationKey) | |
let translation = rawTranslation[0] | |
for (let key in options) { | |
translation = translation.replace(`%{${key}}`, options[key]) | |
} | |
return translation | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment