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

Joob's avatar
Level 1

change language and url slug

I wanted help to change the corresponding link with the language. Imagine.

I am in the FR language and I am on the page (.../page/terms-et-services), and if I am on the same page and change the language to EN, it doesn't change to the page (.../page/terms-and-services), it only changes if I go to the footer menu and click on the terms and then it goes to the page (.../page/terms-and-services).

I wanted, for example, if it was in the FR language with the link (/page/terms-et-services) and changed the language to EN it would go to the page (/page/terms-of-service), but this would only happen if the user was on the link (/page)

In the footer menu I use it this way.

<li v-if="legal.visibility" v-for="(legal, index) in config.legal.filter(legal => legal.lang === getLocale())" :key="index">
  <router-link :to="{name: 'DynamicPage', params: {slug: legal.slug }}" class="hover-text-theme">
  {{ legal.title }}
  </router-link>
</li>

And I user in the languagepage

    export default {
    name: 'LanguageSwitcher',
    components: { CountryFlag, ChevronDownIcon },
    data() {
        return {
            language: this.$store.getters.currentLanguage,
            isOpen: false,
        }
    },
    computed: {
        selected: function () {
            return this.$store.getters.languages.find(language => language.code === this.language);
        },
    },
    
    beforeMount() {
        if (! this.selected) {
            this.language = this.$store.getters.languages[0].code;
        }
    },
    watch: {
        locale() {
            this.$router.replace({ params: { lang: this.language } }).catch(() => {})
        }
    },
    methods: {
        changeLanguage(language) {
            // Emit selected
            this.$emit('input', language.value)
            // Get selected
            this.language = language.code
            // Close menu
            this.isOpen = false
            this.$store.dispatch('setLanguage', language.code);

            setTimeout(() => location.reload(), 10)
        },
        toggleSwitch() {
            this.isOpen = !this.isOpen
        },
        hideSwitch() {
            this.isOpen = false
        },
    },
}

I use these 5 links - Terms of Service | Privacy | Cookie | Policy | About Us

Thank you

0 likes
4 replies
johnDoe220's avatar

write like this

https://example.com/fr/page

you shold write complete url

johnDoe220's avatar

Will the page reload after changing the language? Will it actually refresh?

Joob's avatar
Level 1

yes, works well. I only have the problem on these pages, because it is a dynamicpage. Because I had to create a page for each link and each language has its own link. The site itself, the language works with the cache, but in dynamicpage it works with the pages/links ...

Like

https://example.com/page/terms-of-services

https://example.com/page/termes-et-services

https://example.com/page/politique-de-cookies

https://example.com/page/cookie-policy

etc...

Please or to participate in this conversation.