Пример:
Файл index.html:
Код:
<!DOCTYPE html>
<html>
<head>
<title>Урок 2 - перевод в vue js</title>
</head>
<body>
<div id="app">
<div>{{ $t('message.hello') }}</div>
</div>
<script src="https://unpkg.com/vue@3"></script>
<script src="https://unpkg.com/vue-i18n@9"></script>
<script src="App.js"></script>
</body>
</html>
Файл App.js:
Код:
const messages = {
en: {
message: {
hello: 'hello world'
}
},
ru: {
message: {
hello: 'Привет мир'
}
}
}
const i18n_settings = {
locale:'ru',
fallbackLocale:'en',
messages
}
const App = {
data() {
return { }
}
}
const i18n = VueI18n.createI18n(i18n_settings)
Vue.createApp(App).use(i18n).mount('#app')Результат:
Привет мир