Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Joob's avatar
Level 1

create a condition

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

0 likes
11 replies
Joob's avatar
Level 1

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

1 like
vincent15000's avatar

@Joob Sorry I can't help you more, I don't know how to do. Perhaps somebody else ?

vincent15000's avatar

@Tray2 I think he tries to use multilingual routes. Is it possible to apply the localization to routes ?

Joeszeto's avatar

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

Joob's avatar
Level 1

@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.

Joeszeto's avatar

@Joob maybe something wrong with those code.

  1. if you using vue router or in nuxt, it should be route.name not router.name
  2. this.$router.name = 'xxx', you are setting the name property to this.$router object, not checking they are equals or not
  3. foo && bar && abc means foo is true and at the same time bar is true and abc is true, so I guest here so use ||
Joob's avatar
Level 1

@Joeszeto thank you for ur reply.

Still doesn't work well.. bbrr with your suggestion

Joob's avatar
Level 1

@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.