I'm currently trying to internationalize my vue 3 vite project with "@intlify/vite-plugin-vue-i18n". The problem I am facing here, is that i currently have to import and setup the t variable for every component to use it.
example component:
<template>
t('translation')
</template>
<script>
import { useI18n } from 'vue-i18n'
export default {
setup(){
const {t} = useI18n();
return {t}
},
};
</script>
My question is, if its possible, what is the best way to make the variable "t" global? I cant find any examples/help on this, since they all import it into every compoenent. All help would be apreciated! :) For reference, here are the relevant files.
export default defineConfig({
plugins: [
vue(),
vueI18n({
include: path.resolve(__dirname, './src/locales/**')
})
]
})
main.ts:
import i18n from './i18n';
const app = createApp(App);
app.use(i18n);
app.mount("#app");
i18n.js:
import { createI18n } from 'vue-i18n'
import messages from '@intlify/vite-plugin-vue-i18n/messages'
export default createI18n({
legacy: false,
locale: 'no',
messages
})