Frage

This code never works:

function i18n_load_plugin_textdomain() {
    $path = '[DIR]/wp-content/plugins/my-plugin/languages/my-plugin-de_DE.mo';     
    load_plugin_textdomain( 'my-plugin', false, $path);
}
add_action('plugins_loaded', 'i18n_load_plugin_textdomain');

I also tried 'init' instead of 'plugins_loaded' hook.

I tested $path with this different values (strings!) - no one worked. load_plugin_textdomain() returned always false.

$path = '[URL]/wp-content/plugins/my-plugin/languages/my-plugin-de_DE.mo';
$path = '[DIR]\wp-content\plugins\my-plugin/languages/my-plugin-de_DE.mo';
$path = 'languages/my-plugin-de_DE.mo';
$path = '/languages/my-plugin-de_DE.mo';
$path = '/languages/';
$path = '/languages';
$path = 'languages';
$path = '/';
$path = '';

But this works:

function i18n_load_textdomain() {
    $mofile = '[DIR]/wp-content/plugins/my-plugin/languages/my-plugin-de_DE.mo';
    load_textdomain( 'my-plugin', $mofile);
}
add_action('plugins_loaded', 'i18n_load_textdomain');

Can anyone tell me WHY?

War es hilfreich?

Lösung

why did u write $path: and not $path= in your first function code?

Wait forget it, you have to privde the relative path, you're providing the full path.. When using load_plugin_textdomain, you gotta use your plugin folder + your language files folder only; so if your language files are inside wp-content/plugins/your-plugin/languages, use

load_plugin_textdomain( 'your-plugin', false, 'your-plugin/languages' );

When I do it like this with my plugins translations always work. And I remember that whenever translations of my plugins didn't work, the wrong path was the problem in most of the cases.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit wordpress.stackexchange
scroll top