Wordpress : qTranslate X language switcher with language code Wordpress : qTranslate X language switcher with language code wordpress wordpress

Wordpress : qTranslate X language switcher with language code


Try to add following script below translate code.

echo qtranxf_generateLanguageSelectCode('text');<script>jQuery(document).ready(function(){ jQuery('.lang-en a span').html('EN'); jQuery('.lang-fr a span').html('FR'); })</script>

Serverside Solution:

Please find below Code which modify language name to language code without change in plugin code and you can do it by word press filter.

Paste below code into function.php file.

add_filter('template_include','start_buffer_EN',1);function start_buffer_EN($template) {  ob_start('end_buffer_EN');    return $template;}function end_buffer_EN($buffer) {  return str_replace('<span>English</span>','<span>EN</span>',$buffer);  }add_filter('template_include','start_buffer_FR',1);function start_buffer_FR($template) {  ob_start('end_buffer_FR');  return $template;}function end_buffer_FR($buffer) {    return str_replace('<span>Français</span>','<span>FR</span>',$buffer);}

You can change language name from wp-admin by edit language name directly..

Q-translate-x-change-image-name-from-admin


Inspecting the plugin I found that generateLanguageSelectCode have more types than documented. So to use language codes you can simply just use the type 'short', like this:

qtranxf_generateLanguageSelectCode('short');

This might be a feature added since last answer.

Here is a overview of all the switcher types:'text', 'image', 'both', 'short', 'css_only', 'custom', and 'dropdown'. I havn't looked into how the different types works, but you'll find them in qtranslate_widget.php in the plugin folder.


A friend helped me with that and it's based on Ash Patel answer but in a cleaner way (IMHO) :

function my_qtranxf_generateLanguageSelectCode($style='', $id='') {    ob_start();      qtranxf_generateLanguageSelectCode($style, $id);    $o = ob_get_contents();    ob_end_clean();    return str_replace(array('English', 'Français'),array('EN', 'FR'), $o); }