Perhaps this will help you.
https://laracasts.com/discuss/channels/laravel/multiple-language-route-name
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello,
Needed help creating a condition. I needed - if the user is on the "/page/terms-and-services" and then click on the language "fr" go to "/page/termes-et-services" ..
I use this to call en / fr etc.. - this.$i18n.locale === 'en'
Thank you
Perhaps this will help you.
https://laracasts.com/discuss/channels/laravel/multiple-language-route-name
no ..
I use like this but doesn't work well It only enters the PT language if you click on another language, it goes to PT
if (this.$router.push('/page/' + this.$route.params.slug + '?lang=' + (this.$i18n.locale ? this.$i18n.locale : 'pt'))) {
this.$router.push('/page/termos-e-servicos')
}
if (this.$router.push('/page/' + this.$route.params.slug + '?lang=' + (this.$i18n.locale ? this.$i18n.locale : 'fr'))) {
this.$router.push('/page/termes-et-services')
}
if (this.$router.push('/page/' + this.$route.params.slug + '?lang=' + (this.$i18n.locale ? this.$i18n.locale : 'en'))) {
this.$router.push('/page/terms-of-services')
}
if (this.$router.push('/page/' + this.$route.params.slug + '?lang=' + (this.$i18n.locale ? this.$i18n.locale : 'es'))) {
this.$router.push('/page/terminos-de-servicios')
}
I want when if I click on the PT flag (PT language), I want it to go to the page - this.$router.push('/page/termos-e-servicos') - but I only want that to happened, when the user is on of those pages (/page/:slug)
ty
@Joob Sorry I can't help you more, I don't know how to do. Perhaps somebody else ?
Have you read the documentation?
@Tray2 I think he tries to use multilingual routes. Is it possible to apply the localization to routes ?
@vincent15000 It looks that way
use Illuminate\Support\Facades\App;
Route::get('/greeting/{locale}', function ($locale) {
if (! in_array($locale, ['en', 'es', 'fr'])) {
abort(400);
}
App::setLocale($locale);
//
});
https://laravel.com/docs/9.x/localization#configuring-the-locale
maybe you can
if (this.$route.name == 'some name') {
this.$router.push('/page/termos-e-servicos')
}
and "some name" is the page /page/:slug name
@Joeszeto thank you.. u understand me .. but check
It works in - changeLanguage(language) { - until I put it like this:
if (this.$i18n.locale === 'pt' && (this.$router.name = '/page/termos-e-servicos') &&
(this.$router.name = '/page/termes-et-services') &&
(this.$router.name = '/page/terms-of-service') &&
(this.$router.name = '/page/terminos-de-servicios')) {
this.$router.push('/page/termos-e-servicos')
}
if (this.$i18n.locale === 'fr' && (this.$router.name = '/page/termos-e-servicos') &&
(this.$router.name = '/page/termes-et-services') &&
(this.$router.name = '/page/terms-of-service') &&
(this.$router.name = '/page/terminos-de-servicios')) {
this.$router.push('/page/termes-et-services')
}
if (this.$i18n.locale === 'en' && (this.$router.name = '/page/termos-e-servicos') &&
(this.$router.name = '/page/termes-et-services') &&
(this.$router.name = '/page/terms-of-service') &&
(this.$router.name = '/page/terminos-de-servicios')) {
this.$router.push('/page/terms-of-service')
}
if (this.$i18n.locale === 'es' && (this.$router.name = '/page/termos-e-servicos') &&
(this.$router.name = '/page/termes-et-services') &&
(this.$router.name = '/page/terms-of-service') &&
(this.$router.name = '/page/terminos-de-servicios')) {
this.$router.push('/page/terminos-de-servicios')
}
because I want it to make just this one call to the page - this.$router.push('/page/terms-of-service') - if I am in one of these links - (this.$router.name = '/page/terms-and-services') && (this.$router.name = '/page/terms-et-services') && (this.$router.name = '/page/terms-of-service') && (this.$router.name = '/page/terms-of-services') -
get it ?
Because I don't want to be on the "homepage" and click on language and have it go to those links, I really only want it when I'm on one of those links.
@Joob maybe something wrong with those code.
this.$router.name = 'xxx', you are setting the name property to this.$router object, not checking they are equals or not@Joeszeto thank you for ur reply.
Still doesn't work well.. bbrr with your suggestion
@Joeszeto I click on the flags when I am on the home page, it changes the language, in the URL you can see the link changing to "/page/terms...." and then back to the home page, but sometimes it happens he page "/page/terms...." then when I am on those, I click on the flags and only at the second click on the flag, the page changes.
it's almost there
Please or to participate in this conversation.