Search code examples
wordpresspluginstranslatepo

Can't add language translation support to Wordpress plugin


I am trying to add language/translation support for my Wordpress plugin using POEdit software to create .po files, but the code isn't working and there are no screen error printing out.

My plugin is located in /plugins/site-status/ and the languages directory is located as /plugins/site-status/languages/. In /languages/ directory all .po files have names such as site-status-en_US.po (the unique identifier is called site-status) Here is the language support code:

function    status_language_init() {
          load_plugin_textdomain( 'site-status', false, 'site-status/languages/' ); 
        }
        add_action('init', 'status_language_init');

Here is the test code for outputing the default/translated text:

echo _x( 'test', 'site-status' );

I very much look forward for your help!

Thanks in advance and with best wishes, WHOAMi


Solution

  • To debug this, check the return value of load_plugin_textdomain(). And don’t rely on a directory name of your plugin. The user can change it.

    $path        = basename( dirname( __FILE__ ) ) . '/languages';
    $lang_loaded = load_plugin_textdomain( 'site-status', FALSE, $path );
    // die harder!
    ! $lang_loaded and die( $path . ' not found' );