wordpresspluginswpml

Wordpress Plugin translation - load_plugin_textdomain


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?


Solution

  • In case someone having the same problem. I had

    get_plugin_data( __FILE__ );
    

    in 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

    I 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.