laravel-vue-i18n: Can't seem to get trans to work
I’m using Vue 3 with composition API and while $t and $tChoice both function perfectly, I can’t seem to get trans or transChoice to function properly. It’s as if it’s using a different configuration from $t and $tChoice. Thus no language strings are loaded.
It may just be a case of me doing something very wrong, as I work with Vue 2 daily and this is my first Vue 3 Composition API project.
Just in case it's important, here's the app.js file that I use
require('./bootstrap');
import { createApp, h } from 'vue';
import { createInertiaApp } from '@inertiajs/inertia-vue3';
import { InertiaProgress } from '@inertiajs/progress';
import { i18nVue } from 'laravel-vue-i18n';
const appName = window.document.getElementsByTagName('title')[0]?.innerText || 'Laravel';
createInertiaApp({
title: (title) => `${title} - ${appName}`,
resolve: (name) => require(`./Pages/${name}.vue`),
setup({ el, app, props, plugin }) {
return createApp({ render: () => h(app, props) })
.use(plugin)
.use(i18nVue, {
resolve: lang => import (`../lang/${lang}.json`),
})
.mixin({ methods: { route } })
.mount(el);
},
});
InertiaProgress.init({ color: '#4B5563' });
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 41 (22 by maintainers)
The tl;dr that worked for me after going through this thread is to change your
transfunction calls towTrans:Thanks for the help debugging @A-Ghorab 💪.
ok it won’t work that way
try this way
this should do a ref instead of a simple string to watch for any changes and update it automatically which would fix the issue related to loading the files later on or changing the current language .
don’t forget
@AngelOD you can use
wTrans()now instead oftrans()it should work correctly for you no more need fortrans_ref()fix.care to share your code
basically you need to use wTrans if you are outside the template and you need to be sure to wrap it with computed to handle complex scenario
i’m using it with vuelidate and providing the translations to the validation and it’s working 100% of the times.
This problem appears to be more complicated than it seems. Sometimes
transworks, whilewTransdoes not. And sometimeswTransworks buttransdoes not. In some cases thewTransI have to extend thevaluei.e.wTrans('Hello!').valuefor it to work, while sometimeswTrans('Hello!')is enough. It’s very strange all this and I’ve been dealing with this problem for hours. Ideally,transshould work just like$t()works. So this issue should not be closed.Yes this makes sense. And it works!
Thanks a lot