4

I am using qTranslate plugin with my Wordpress site and now I have to detect the active language in the themes functions.php file. The detection function qtrans_getLanguage() is working, however, it always shows the default language (en) as active, even though I have it switched in the page itself. How can I detect the language in function file?

Deez
  • 849
  • 2
  • 9
  • 28

2 Answers2

8

This worked for me:

if (qtrans_getLanguage() == 'en') {
  // english
  print "Hello world!"; 
} elseif (qtrans_getLanguage() == 'es') {
  // spanish
  print "Hola Mundo!"; 
}

Notice that this has changed in qTranslate X (the new version):

if (qtranxf_getLanguage() == 'en') {
  // english
  print "Hello world!"; 
} elseif (qtranxf_getLanguage() == 'es') {
  // spanish
  print "Hola Mundo!";
}

There is also some compatibility functions in the plugin options according to this

To apply this code you need some PHP knowledge, it is used to translate exact parts of your Wordpress Theme

toto_tico
  • 17,977
  • 9
  • 97
  • 116
  • What do you need exactly? It really depends on where you want to apply the translation. You need to put it wherever you want to translate a particular part of your Wordpress Theme (in the php). – toto_tico Nov 27 '15 at 23:48
0

use this :

if ( get_bloginfo('language')=='ar' )  
{  
//load css or js files for Arabic language as example  
}  

replace 'ar' with yours

Bahjat
  • 11
  • 4