Good Day,

I'm trying to translate my plugin but it doesn't seems to work.

I read that I should check the return value of "load_plugin_textdomain" to see if it's false (meaning it doesn't find my translation file), but I cannot find how to find this value.

Can someone point me in the right direction?


EDIT As requested here is the lines to load it

function ap_action_init() {
    load_plugin_textdomain('my_plugin', false, WP_PLUGIN_DIR . '/languages' );

// Localization

// Add Actions
add_action('init', 'ap_action_init');
  • Can you post the code your are using? – cybmeta May 26 '15 at 8:20
  • As Requested - The Line has been added – pSyToR May 26 '15 at 8:24
  • What if you change WP_PLUGIN_DIR . '/languages' to WP_PLUGIN_DIR . '/my-plugin/languages/'? Check the path, it seems wrong in your code. – cybmeta May 26 '15 at 8:26
  • 1
    Oh, sorry, checking the value returned by a function is a very basic PHP task I supposed you alreay know. Note that this site is for questions specific to WordPress, general questions about PHP are better asked in StackOverflow where there are PHP expert coders ready to help. – cybmeta May 26 '15 at 10:23
  • 1
    Try Debug Translations. – fuxia May 26 '15 at 11:08
global $langOK;
add_action( 'plugins_loaded', 'myplugin_load_textdomain' );
function myplugin_load_textdomain() {
    global $langOK;
    $langOK = load_plugin_textdomain( 'my-plugin', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );

Later you can check the value of $langOK ( TRUE = success, FALSE = failure ).

| improve this answer | |
  • Thanks a lot Frank that's exactly what I was looking for! – pSyToR May 26 '15 at 10:06
  • 2
    You could do simply $langOK = load_plugin_textdomain( 'my-plugin', false, dirname( plugin_basename( __FILE__ ) ) ); as load_plugin_textdomain() already returns true or false. I also would return the true or false in myplugin_load_textdomain instead of, or in addition to, using a global variable. – cybmeta May 26 '15 at 10:25
  • First part is 100% true. Second - returning value from action callback is pointless as you cannot access it elswhere. You could react to success or failure within the callback by displaying a message or doing something else. – Frank P. Walentynowicz May 26 '15 at 12:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.