How to localize a custom mu-plugin

I’m using Bedrock 1.6.3 with WP 4.5.2 and I am trying to translate my wordpress plugin bud I can’t get it work.

The plugin is stored in web/app/mu-plugins/my-plug-in/my-plug-in.php and is working. The strings to translate are wrapped in the __('str', 'text-domain') and _e('str', 'text-domain') function. The necessary .mo and .po files are created, named like my-plug-in-de_DE.po and stored in web/app/mu-plugins/my-plug-in/languages.

The textdomain is added like:

load_plugin_textdomain( 'my-plug-in', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' );

The function is hooked to ‘muplugins_loaded’.

What am I missing?

Thanks!

Samething here…

I check the ACF plugin and found this solution

function load_plugin_textdomain() {
    load_textdomain( 'my-plug-in', $this->plugin_absolute_path . 'lang/my-plug-in-' . get_locale() . '.mo' );
}
add_action('init', [$this, 'load_plugin_textdomain'], 5);

Anyone has a better solution ?

1 Like

Thank you!

Unfortunately I don’t have a better solution but I slightly modified your code and the mo-files are loaded.

function load_plugin_textdomain() { load_textdomain('my-plug-in', WPMU_PLUGIN_DIR . '/' .plugin_basename( dirname( __FILE__ ) ) . '/languages/my-plug-in-' . get_locale() . '.mo'); } add_action('muplugins_loaded', 'load_plugin_textdomain');

Which is the correct action (init or muplugins_loaded) to hook the load_plugin_textdomain-function? The translation works with both actions.

1 Like

Have you tried localizing your plugin with the localization app POEditor?
I found it makes translating strings from .po files easier, especially if used with its translation management plugin (to be found on WordPress here).