Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wordpress : qTranslate X language switcher with language code

I'm trying to make a basic language switcher with qTranslate X, something like :

FR | EN

There's a function to achieve that : qtranxf_generateLanguageSelectCode('text'); but it can only accept 'text', 'image' or 'both', so it doesn't fit to my needs : 'text' is the full name of the language.

How can I just show the language code ? Any idea to make a filter to do that ?

like image 537
enguerranws Avatar asked Dec 10 '22 23:12

enguerranws


1 Answers

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

like image 57
Ash Patel Avatar answered May 26 '23 07:05

Ash Patel