Change qTranslate text – qtrans_generateLanguageSelectCode(”)

qTranslate allows you to insert a Language Selector on your theme by using this line of code:

<?php echo qtrans_generateLanguageSelectCode($type); ?>

If you define $type as ‘image’ you will get flags, if you define it as ‘text’ you will get language words.  And there are some other options also, let’s quickly review them:

  • ‘image’
  • ‘text’
  • ‘both’
  • ‘dropdown

So you select ‘text’ and the words ‘english’, ‘french’, ‘spanish’, ‘other’, etc, start appearing in your theme and you would like to change them to something like ‘EN’, ‘FR’, ‘ES’, etc.

How do you change those words

So, you’re searching on internet looking a way to change the qTranslate text generated by that line of code, but the true is: there’s no easy way of changing these words yet (may be in future releases).  We will tell you how to quickly change it.  Just insert the following on your theme where you want the language selector to appear:
<?php echo qtrans_generateLanguageSelectCode('text'); ?>
<script>jQuery(document).ready(function(){ jQuery('.lang-en a span').html('EN'); jQuery('.lang-fr a span').html('FR'); })</script>

Quick, easy, and you don’t have to spend 2 hours on internet searching how to do it.   Let them update the plugin in the future and integrate this funcionality, meanwhile just go and do whatever other thing you have to do on your theme…

10 Comments Add yours

  1. Alex Leonard says:

    Nice one – quick, simple and I really should have thought of it myself! Much appreciated.

  2. Radu says:

    Isn’t it simpler to just rename the language in Settings/languages? Click edit and change the name field.

  3. Toni Michel says:

    Hi there!

    Wouldn’t be easy to re-do this function? than finding with javascript the elements?

  4. emilie says:

    hi,

    thank you very much for the tip, but it seems not working on the website i m working on :
    http://emilierolland.com/preprod/blog/

    when i swith in english, cliking on “UK”, the text ” français english” appears instead of “FR | UK”,

    if you have any suggestion,

    thanks for your help,

    emilie

  5. I’ve been looking for this for ages! I assumed that there would be an option to either display EN or English, but was surprised to find that this was not the case.
    Thank you for your solution!

  6. I rewrote it a bit, now you don’t have to change code if you add extra languages.
    This will display the two letters for your language. In my case:
    EN NL ES

    [code]

    jQuery(document).ready(function(){
    jQuery(‘#qtranslate-chooser li’).each(function() {
    var liClass = jQuery(this).attr(‘class’).replace(/^(\S*).*/, ‘$1’);
    var liShort = liClass.substr(liClass.length – 2);
    jQuery(this).children(‘a’).html(liShort);
    });
    })

    [/code]

    Good luck 🙂

  7. johnny says:

    Terrible tip.

  8. rasheed24291 says:

    Hi Every One , I Install the plugin works fine , Now the plugin display only text in the drop box , I need to get Both text and img in drop box , any one help me quick.

  9. I am using the AVADA theme and want to add the language selector into the header area @ http://wenxin.trinitytranslation.com/

    I added this code into the Banner field in Header (Theme Options);

    jQuery(document).ready(function(){
    jQuery(‘#qtranslate-chooser li’).each(function() {
    var liClass = jQuery(this).attr(‘class’).replace(/^(\S*).*/, ‘$1’);
    var liShort = liClass.substr(liClass.length – 2);
    jQuery(this).children(‘a’).html(liShort);
    });
    })

    … but this did not work!!

    I am using the ‘mqtranslate’ plugin so I changed the code above as follows;

    jQuery(document).ready(function(){
    jQuery(‘#mqtranslate-chooser li’).each(function() {
    var liClass = jQuery(this).attr(‘class’).replace(/^(\S*).*/, ‘$1’);
    var liShort = liClass.substr(liClass.length – 2);
    jQuery(this).children(‘a’).html(liShort);
    });
    })

    Still not working…

    Any help would be useful…

  10. oscar says:

    Funked bitch code kiss my ass mayor a add_filter PUTOS

Leave a Reply