vue-i18n
vue-i18n copied to clipboard
VIte + Vue2 example
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
- [X] Read the Contributing Guidelines
- [X] Read the Documentation
- [X] Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
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;
how to use Lazy loading translations in vite + vue2 . 8.x not provide an example