A lot of people have been asking me how I deal with loading the correct text translation domain when using qtranslate.
In layman’s terms how to get your plugin to use the correct language on the front end and back end of your website..
So here is how it works for me.
Please remember to backup your functions.php file before this edit
Add this to your themes/child themes functions.php.
Replacing mypluginstextdomain with whatever your plugins textdomain is called
Replacing mypluginsfoldername with whatever your plugins folder is called
Replacing mypluginstextdomainmofile with whatever your plugins translation mo file is called
if ( function_exists('qtrans_getLanguage') ) {
$locale = qtrans_getLanguage();
load_textdomain('mypluginstextdomain', realpath(dirname(__FILE__) . '/../..') . '/plugins/mypluginsfoldername/mypluginstextdomainmofile-' . $locale . '.mo');
}
So for example if I wanted to get the wordpress plugin eshop to work nicely with qtranslate this is what I would add
if ( function_exists('qtrans_getLanguage') ) {
$locale = qtrans_getLanguage();
load_textdomain('eshop', realpath(dirname(__FILE__) . '/../..') . '/plugins/eshop/eshop-' . $locale . '.mo');
}
You may find that the plugin .mo file has a different filename and does not contain a – please edit accordingly….





Hi,
thanks for that article… i was hoping it could help me… but it don’t. I think i don’t see my mistake in this place. Working with woo commerce and on of their templates. All languages files available and can be found under …plugins/woocommerce/lanuages/woothems-xx-xx.mo. I was modifying your code to:
if ( function_exists(‘qtrans_getLanguage’) ) { $locale = qtrans_getLanguage(); load_textdomain(‘woothemes’, realpath(dirname(__FILE__) . ‘/../..’) . ‘/plugins/woocommerce/woothemes-’ . $locale . ‘.mo’); }
But its not working. I’m so frustrated that i have to ask you for help.
Thanks and Regards from the Med.
Alex
Have you tried ?
if ( function_exists(‘qtrans_getLanguage’) ) { $locale = qtrans_getLanguage(); load_textdomain(‘woothemes’, realpath(dirname(__FILE__) . ‘/../..’) . ‘/plugins/woocommerce/languages/woothemes-’ . $locale . ‘.mo’); }
You was missing the / lanuages/
hope it was that simple, if not do ask more help and greetings from the north..
Dont works for me ;/
testet several times on woocomerce, dont work
I have it working now here on my test server. Please check your paths and make sure they are correct. if you still are having problems, please ask over at woothemes support forum..
Nice Clients
For the people having troubles, check the paths, mo files are usually named something as ‘plugin-en_GB.mo’ but &locale will give you back only an ‘en’ flag.
This solution is excellent, but you need to be sure you are pointing to the right thing.
This is how I got it working with Jigoshop for a spanish-english site:
if ( function_exists(‘qtrans_getLanguage’) ) {
$locale = qtrans_getLanguage();
if ($locale == ‘es’){
load_textdomain(‘jigoshop’, realpath(dirname(__FILE__) . ‘/../..’) . ‘/plugins/jigoshop/languages/jigoshop-es_ES.mo’);
}else{
load_textdomain(‘jigoshop’, realpath(dirname(__FILE__) . ‘/../..’) . ‘/plugins/jigoshop/languages/jigoshop-en_GB.mo’);
}
}
Many thanks
Great, thanks for sharing..
Res Ipsa Loquitur -the facts speak for themselves!
Thanks a lot for this… I’ve been scratching my head during a few hours before realizing qTranslate was the culprit. Then I found this page and now everything works fine