Hey, is there any possibility to use the $t() function inside a javscript file? Like I have a method in my vue script that returns a string and I want it to be internationalized. :)
You can use the $t as method of Vue instance.
e.g.
new Vue({
methods: {
getMessage: function (key) {
return this.$t(key)
}
}
})
Thanks a lot! :)
Would be nice to see that in README.md
How can i call this method getMessage from another component, which is in separated .vue file ?
@donaldinos If you added i18n instance in root vue instance (like Vue.use(i18n)), you can just call this.$t('something') anywhere you want.
Most helpful comment
You can use the
$tas method of Vue instance.e.g.