How to access translations in static .js file?
-
This post is deleted! -
@mYnDstrEAm export the instance of your i18n boot.
something like this:
//src/boot/i18n.js ... let i18n = null export default ({ app }) => { // Set i18n instance on app; // We inject it into root component by doing so; // new Vue({..., i18n: ... }).$mount(...) i18n = new VueI18n({ locale: 'en', fallbackLocale: 'en', messages }) app.i18n = i18n } export { i18n } // some js file import { i18n } from 'src/boot/i18n.js' ... i18n.t('translation.path')
-
@mYnDstrEAm you didn’t need to delete your post, just marked the title as [Solved] *if it was solved, for others who might stumble upon the same issue :).
-
Hey @metalsadman How can I do this in quasar 2?
-
For Quasar v2 the default src/boot/i18n.js is:
import { createI18n } from 'vue-i18n' import messages from 'src/i18n' export default ({ app }) => { const i18n = createI18n({ locale: 'en-US', messages }) app.use(i18n) }
Modified version:
import { createI18n } from 'vue-i18n' import messages from 'src/i18n' let i18n export default ({ app }) => { i18n = createI18n({ locale: 'en-US', messages }) app.use(i18n) } export { i18n }
But really you should rather use
this.$t(...)
whenever you can. -
I was talking about using it in single js file, I found a solution:
import { i18n } from 'src/boot/i18n' const { t } = i18n.global . . . export const eStatusList = [ { code: '0', label: t('documents.inProgress') }, { code: '1', label: t('documents.sent') }, { code: '2', label: t('documents.accepted') }, { code: '3', label: t('documents.rejected') }, { code: '4', label: t('documents.voiding') }, { code: '5', label: t('documents.voided') } ]