3

I am trying to translate my custom plugin.

I can translate my plugin if I place the fr_CA.po/.mo into my wp-content\languages\plugins manually.

But I would like to be able to put my .po/.mo into my plugins folder in "myplugin/languages"

Well, in the main file, I have this:

 * Text Domain: myplugin
 * Domain Path: /languages/

my text

    add_action( 'init', 'myplugin_load_textdomain' );

function myplugin_load_textdomain() {
    load_plugin_textdomain( 'myplugin', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
}

all my .po / .mo is in that folder myplugin/languages/

My Wordpress is in fr_CA ( WordPress 4.7.2–fr_CA)

I have a fr_FR.po /fr_CA.po (and their .mo).


Like I said previously, my plugin change the language if I put my .po/.mo into the wp-content\languages\plugins and I change the fr_FR(.mo/.po) to myplugin-fr_FR(.mo/.po)

but I would like to keep my .po/.mo into my plugins folder.

Anyone know what is the problem?

2

From the source code of load_plugin_textdomain it becomes appararent that the function will first look for $domain . '-' . $locale . '.mo' (so, that's myplugin-fr_FR.mo) in WP_LANG_DIR . '/plugins/' . $mofile.

Only when the file is not there, it will start looking at the specified path and if it is not there in the main plugin directory. So, if you don't get the mo-file in the specified directory, either it isn't there or you are supplying the wrong path.

I cannot see whether you have made any typos, but instead of combining dirname and plugin_basename you might want to stick to plugin_dir_path to supply the correct directory.

| improve this answer | |

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.