BeginnerSoul's avatar

Change language and change the link

Hi I don't know how to do that when I will change language on the website then remaining in the same page and using the specific slug for the specific language.

For example: English: localhost.net/en/knowledgebase

Hungarian localhost.net/hu/tudastar

English localhost.net/en/knowledgebase/info/something

Hungarian localhost.net/hu/tudastar/info/valami

Last version I tried this to change the first part of the link which has the language "en" and "hu":

$('.langswitch').on('select2:select', function (e) {
    var lang = e.params.data;
    var url = window.location.href;
    var parts = url.split('/');
    parts[3] = lang.id;
    location = parts.join('/');
});

However I thought to change the whole link path so it will be more friendly with SEO. I did thinking about to get somehow the current page route name and then get the translation through laravel but no idea how to get + no idea how to recognize the dynamic urls such as localhost.net/en/knowledgebase/info/something . After the info path would be from the database.

Or does someone have better solution how to change the url to the specific language? Thanks in advance for the answers.

0 likes
0 replies

Please or to participate in this conversation.