vue-i18n icon indicating copy to clipboard operation
vue-i18n copied to clipboard

VIte + Vue2 example

Open montella1507 opened this issue 2 years ago • 2 comments

Clear and concise description of the problem

Please provide example of Vite + Vue2 solution, there is no way how to make this work :-/

Suggested solution

Small example with vite.config.js, tsconfig.base.json and 2 types of messages:

  • global
  • local in blocks

Alternative

No response

Additional context

No response

Validations

montella1507 avatar Nov 30 '22 20:11 montella1507

Simply switch Webpack's module.hot() to Vite's import.meta.hot(). I wish they should provide it in the docs too. Here is a simple snippet for you :)

import Vue from 'vue'
import VueI18n from 'vue-i18n'
import en from "@/locales/en.json";
import zhHans from "@/locales/zhHans.json";
import zhHant from "@/locales/zhHant.json";

Vue.use(VueI18n);

const messages = {
  en,
  zhHans,
  zhHant
}

const i18n = new VueI18n({
  locale: 'en',
  messages
})

// Hot updates
if (import.meta.hot) {
  import.meta.hot.on("locales-update", (data) => {
    i18n.setLocaleMessage('en', en.default)
    i18n.setLocaleMessage('zhHans', zhHans.default)
    i18n.setLocaleMessage('zhHant', zhHant.default)
  })
}
export default i18n;

LDY681 avatar Dec 26 '22 03:12 LDY681

how to use Lazy loading translations in vite + vue2 . 8.x not provide an example

meiliujun avatar Mar 10 '23 14:03 meiliujun