Is it possible to use vue, vue-i18n only with javascript (as an object), not in the template ?
I want to use it in something like window.confirm, is that possible ?
Thanks.
The vue-i18n plugin provides components with access to the i18n instance through the $i18n variable. Simply set $i18n. locale to switch to a new locale. Now, after an app reload, you'll see a <select> element that allows us to change the current locale.
Vue I18n is internationalization plugin of Vue. js. It easily integrates some localization features to your Vue. js Application.
Single-file components and readability A Vue application/web page is built of components that represent encapsulated elements of your interface. Components can be written in HTML, CSS, and JavaScript without dividing them into separate files.
yes it's possible, i never used the plugin, but it looks pretty straightforward:
first you create the instance:
// Ready translated locale messages
const messages = {
en: {
message: {
greeting: 'hi {name}'
}
},
es: {
message: {
greeting: 'hola {name}'
}
}
}
// Create VueI18n instance with options
const i18n = new VueI18n({
locale: 'es', // set locale
messages, // set locale messages
})
(be aware 'const' is es6)
Then you can use it in any js where i18n var exists:
i18n.t('greeting', { name: 'kazupon' }) // -> hola kazupon
Doc:
http://kazupon.github.io/vue-i18n/en/started.html
http://kazupon.github.io/vue-i18n/en/migrations.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With