Qtranslate custom URL for the language switcher

5.3k views Asked by At

My current project is Multilingual in :

  1. Arabic
  2. English

I'm working one making custom language switcher with Qtranslate plugin.And this is what I want to do:

  1. At English Content, user want to press on language URL for the Arabic language only, so that he switch to the Arabic version.
  2. At Arabic Content, user want to press on language URL for the English language only, so that he switch to the English version.

What I did, I appended to the header.php after wordpress call the menu this code:

<?php 
    $current_lang=qtranxf_getLanguage();
    if($current_lang=="ar"){
    echo "<li class='menu-item menu-item-type-custom'>". " <a class ='qtranxs_flag_en qtranxs_flag_and_text' href='http://127.0.0.1/idevlab.com/comtec.com/idevtra/'>Englsih</a>"."</li>";
    }else{
    echo "<li class='menu-item menu-item-type-custom'>". " <a class                 ='qtranxs_flag_ar qtranxs_flag_and_text' href='http://127.0.0.1/idevlab.com/comtec.com/idevtra/ar'>العربية</a>"."</li>";        
    }
    ?>

But, the URL appears well, but unfortunately it reloads the website to the current content not to the other synchronized content.

I tried to inspect the element of the widgets and I could only figure that they use this class in the URL for the language switcher ,

<a class ='qtranxs_flag_en qtranxs_flag_and_text

But, it do nothing with my and it seems that it calls the last cashed language from the browser or the DB and I don't know how ?

So, I'd be highly appreciated if you could guide/help me to make this costume language switcher.

2

There are 2 answers

0
b_machuel On
  • In the admin dashboard, go to Appearance > Menus;
  • Add a custom link menu item with the following code as url:

    #qtransLangSwLM?flags=none&title=current&current=hidden
    

Leave the other fields empty.

1
nodws On

Here is the solution for: Just text, hide current lang, hide menu title, inline items

#qtransLangSwLM?flags=none&title=none&current=hidden&type=AL

Here is a reference of the available options

type = [LM|AL]
title = [none|Language|Current]
current = [shown|hidden]
flags = [none|all|items]
lang_names = [shown|hidden]
colon = [shown|hidden]