Home:ALL Converter>Wordpress Plugin translation - load_plugin_textdomain

Wordpress Plugin translation - load_plugin_textdomain

Ask Time:2017-08-06T02:56:00         Author:jekey123

Json Formatter

I'm working on a custom Wordpress plugin but I cannot get it multi-lang ready.

It does load the .mo file of the main language properly, but when switching languages (using WPML), it always shows the translation of the main language (in this case German). So when I am on English, it still shows the German translations.

Here's my code:

in the header:

/*
Plugin Name: MM Jobs
Plugin URI: http://example.com/
Description: Custom Jobs Plugin to create new Jobs
Version: 1.3.84
Author: Jekey
Author URI: http://example.com/
Text Domain: mm-jobs
Domain Path: /languages
*/

then:

function mm_jobs_plugins_loaded() {
        load_plugin_textdomain( 'mm-jobs', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
    }
    add_action( 'plugins_loaded', 'mm_jobs_plugins_loaded', 0 );

.mo files are correct, as it already loads the German translation. Named: mm-jobs-en_US.mo or mm-jobs-de_DE.mo under /plugins/mm-jobs/languages/

You have any idea what's causing the problem?

Author:jekey123,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/45525390/wordpress-plugin-translation-load-plugin-textdomain
jekey123 :

In case someone having the same problem. I had\n\nget_plugin_data( __FILE__ );\n\n\nin my code. This caused to run a wp_core function where it loads the textdomain, so my en_US.mo was overriden by de_DE.mo\n\nI don't know why get_plugin_data() took the wrong lang-file. It seems to have picked the right one for different plugins that use the function.",
2017-08-25T14:04:31
yy