Vue-i18n: can I use $t() in javascript?

Created on 2 Feb 2016  路  5Comments  路  Source: kazupon/vue-i18n

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. :)

Most helpful comment

You can use the $t as method of Vue instance.

e.g.

new Vue({
  methods: {
    getMessage: function (key) {
      return this.$t(key)
    }
  }
})

All 5 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

abou7mied picture abou7mied  路  3Comments

JakubKoralewski picture JakubKoralewski  路  5Comments

forddyce picture forddyce  路  5Comments

Rosadojonathan picture Rosadojonathan  路  4Comments

koslo picture koslo  路  5Comments