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?

1 Answer
1

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.

Leave a Reply

Your email address will not be published. Required fields are marked *