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-contentpluginsmy-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?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0