Adding full i18n to Quasar

Scott Molinari
Dec 30, 2018 · 4 min read
Image for post
Image for post
Reusable code for any platform!
$ yarn add vue-i18nor $ npm install vue-i18n --save
Image for post
Image for post
A successful install of vue-i18n
$ quasar new boot i18n
import VueI18n from 'vue-i18n'

import messages from 'src/i18n'

export default ({ app, Vue }) => {
Vue.use(VueI18n)

app.i18n = new VueI18n({
locale: 'en',
fallbackLocale: 'en',
messages
})
}
Image for post
Image for post
Image for post
Image for post
The location for your translations
Image for post
Image for post
A translation file added for German.
export default {
failed: 'Aktion fehlgeschlagen',
success: 'Aktion erfolgreich',
}
Image for post
Image for post
The German language added to the index.js file.
{{ $t('translation.path') }} // in your template codeor this.$t('translation.path') // in your script code

Example Code

Pro Tip! — Change the app language dynamically!

<q-select 
label="Select Language"
v-model="lang"
map-options
:options="langs"
/>
return {
langs: [
{
label: 'German',
value: 'de'
},
{
label: 'US English',
value: 'en-us'
}
],
lang: this.$i18n.locale
watch: {
lang(lang) {
this.$i18n.locale = lang.value
// set quasar's language too!!
import(`quasar/lang/${lang.value}`).then(language =>
{this.$q.lang.set(language.default)
})
}
}

Pro Tip #2! — Translations outside of components

import VueI18n from 'vue-i18n'
import { messages } from 'src/i18n'
let i18nexport default ({ app, Vue }) => {
Vue.use(VueI18n)
app.i18n = new VueI18n({
locale: 'en-us',
fallbackLocale: 'en-us',
messages
})
i18n = app.i18n
}
export { i18n }
import i18n from 'boot/i18n.js'i18n.t('translation.path')

Quasar Framework

Build high-performance cross-device VueJS user interfaces…

Thanks to Daniel Thompson-Yvetot

Scott Molinari

Written by

Clapping is great. Buying me a coffee or a beer is even better! https://www.patreon.com/user?u=16255660

Quasar Framework

Build high-performance cross-device VueJS user interfaces in record time

Scott Molinari

Written by

Clapping is great. Buying me a coffee or a beer is even better! https://www.patreon.com/user?u=16255660

Quasar Framework

Build high-performance cross-device VueJS user interfaces in record time

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store