Sha
Sha

Reputation: 1181

Vue I18n doesn't work on pure javascript files

I implemented https://kazupon.github.io/vue-i18n/ i18n localization in my project. And it works very well on vue components/pages. But it doesn't work on pure javascript classes and mixins. Is there a way to handle it?

In example.vue component:

<template>
<p>{{ $t("message.hello") }}</p>
...
</template>
<script>
data:(){
...
},
methods:...
i18n: require('path of localization messages.')
</script>

But it is not work on example.js(pure javascript) or example.mjs(mixins) files.

Upvotes: 0

Views: 3552

Answers (1)

Sha
Sha

Reputation: 1181

I found my answer from here: https://github.com/kazupon/vue-i18n/issues/287

You can import VueI18n instance.

e.g. app generated with vue-cli:

src/i18n.js:

import VueI18n from 'vue-i18n'
import Vue from 'vue'

Vue.use(VueI18n)

export default new VueI18n({
  // ...
})

src/foo.js:

import i18n from './i18n'

console.log(i18n.t('foo.bar')

Upvotes: 2

Related Questions