-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
this.$forceUpdate does not refresh the whole page when choosing another language #22
Comments
In vue 3. If you want to refresh the app, store an instance of the app, then call const MaticeMixin = {
methods: {
route,
$trans: trans,
$__: __,
$transChoice: transChoice,
$setLocale(locale) {
if (locale !== getLocale()) {
setLocale(locale);
app.$forceUpdate() // Refresh the vue instance after locale change.
}
},
// The current locale
$locale() {
return getLocale()
},
$locales() {
return locales()
},
},
}
const root = document.querySelector('#app');
let app = createApp({
render: () => h(App, {
initialPage: JSON.parse(root.dataset.page),
resolveComponent: (name) => require(`./Pages/${name}`).default,
}),
}).use(plugin)
.mixin(MaticeMixin)
.mount(root) |
Also, I suggest you upgrade to the latest version of matice. There are no breaking changes, but improved performance and more features, |
This solution didn't work for me with this combination:
But I made it work using Inertia:
Using but not on auth pages: Any hint to fix this? |
Can you share the error output if any? Please share with me the code of both pages. Also make sure sure to use the latest version of Matice, v1.6. |
On the links you provided, I connot interact with the local field. So it's impossible to test, |
There's no error output, everything works fine, but the view doesn't reload (only on auth pages). Anyway, this is not so important, I just wanted to help others using Inertia like me. But if you have any suggestion to make my view work, it would be great! You cannot interact with my links because are images, I cannot publish my application at the moment |
UPDATE: |
Share your portion of the code with me, please. |
This one is the same as before:
This is my locale selector (imported inside my layout):
And this is my login page:
That's all |
$setLocale(locale) {
if (locale !== getLocale()) {
setLocale(locale);
this.$inertia.get(route('locale', {'locale': locale}));
this.$inertia.reload();
}
} Matice is a frontend package to handle Laravel's translations. I plan to make a release, to change the code to make the locale update reactive. So it will not be required to reload the page anymore. Just give me a couple of days. |
I tried to put reload function call inside a callback (onSuccess and onFinish), but it causes a modal to appear because of Inertia/Jetstream functionalities. I also tried with a simple setTimeout, but nothing changed. I'll wait for your update! Thanks a lot for your support |
And this is the reason why I make a GET call:
|
Expected behavior
All Vue components on the page are updated when the language is changed.
Current behavior
Only the language selector is updated and the rest of the page remains the same.
this.$forceUpdate()
seems not to work.Versions
Description
The backend package works fine and the translations on the frontend, when I change the language on the Laravel config side, works wonderfully too. The problem here is that when I change the language with a selector I have created on the frontend, the
this.$forceUpdate()
method won't refresh all components on the page, so the translation only applies to the selector itself and nowhere else on the page.I am using Vue3 if that matters. Here is my code on app.js:
and this is the code that calls the
$setLocale(locale)
method on my language selector component:The text was updated successfully, but these errors were encountered: