Importing vue-i18n in vuex module using quasar framework

Viewed 464

My i18n boot file

import { boot } from 'quasar/wrappers';
import { LocalStorage } from 'quasar';
import messages from 'src/i18n';
import { createI18n } from 'vue-i18n';
    
const storedLang = LocalStorage.getItem('anty-locale');
    
const i18n = createI18n({
  locale: storedLang && storedLang === 'en' ? 'en-US' : 'ru-RU',
  messages,
});
    
export default boot(({ app }) => {
  app.use(i18n);
});
    
export { i18n };

when I am trying to import in vuex js file like this

import { useI18n } from 'vue-i18n';

const { t } = useI18n({ useScope: 'global' });

I occur an error SyntaxError: Must be called at the top of a setup function

import i18n from 'boot/i18n';
i18n.t('common.user') //also doesn't work

Is there any correct way to import i18n in .js/.ts file?

1 Answers

I fixed like this and it worked.

import { i18n } from 'boot/i18n';

i18n.global.t('common.user'); // it works
Related