I'm working with installing the qTranslate multi-language plugin on a WordPress site. The site has a custom plugin from before which complicates things. This question concerns some cases where qTranslate fails to translate Gettext marked strings (_e, etc). In these cases, I can verify the qTranslate language and WordPress locale correctly, as near as the line before the Gettext calls, like so:

<pre>lang: <?php echo qtrans_getLanguage(); ?></pre>
<p class="message"><?php _e('Cart is empty.', 'myplugin'); ?></p>

The string will be output in the language set to default in qTranslate, regardless of the current language. So here's a typical output where Swedish is the default language:

lang: en

Varukorgen är tom.

I understand that you can't see from this summary exactly what is wrong. But can you help me by suggesting what could be possible causes for this behaviour?

Hint: Ajax might be involved, but honestly I'm a bit confused to see if that's really true.

有帮助吗?

解决方案

The load_plugin_textdomain call should be inside an init function, so instead of

load_plugin_textdomain('myplugin', false, dirname(plugin_basename(__FILE__))
    . '/languages/');

I did

function myplugin_init() {
    load_plugin_textdomain('myplugin', false, dirname(plugin_basename(__FILE__))
        . '/languages/');
}
add_action( 'init', 'myplugin_init' );

and it worked.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top