0

I'm pulling my hair out with this one:

I want to provide translations for my plugin, but they're not showing up. I followed the documentation and took the following steps:

  1. Set up local wordpress using docker
  2. Added Text Domain to Plugin-Info * Text Domain: my-plugin
  3. Added Domain Path to Plugin-Info * Domain Path: /languages/
  4. Added translation loading to plugin.php:
add_action( 'plugins_loaded', 'load_i18n' );
function load_i18n() {
  load_plugin_textdomain("my-plugin", false, dirname( plugin_basename( __FILE__ ) ) . '/languages/');
}
  1. I have a settings.php which is responsible for rendering my plugin's Settings page and is initialized from plugin.php. I added this line there to test my translation: <?php _e( 'Hello, dear user!', 'my-plugin' ); ?>

  2. I used wp i18n make-pot to create the pot file. It successfully detects the line in settings and the plugin info stuff and creates what looks like a proper my-plugin.pot inside my plugin's language directory.

  3. I used PoEdit to create translations from that pot file. I made en_US.po and en_US.mo inside the language directory. I translated my test string in the settings page as well as the plugin description.

  4. Set Wordpress language to en_US via general settings. (I also tried define ('WPLANG', 'en_US'); inside wp_config.php)

  5. Installed my plugin.

Translations don't show up (original text is displayed), neither in the plugin description nor the settings page. I also tried other hooks for loading the text domain and other languages. The plugin is not going to be uploaded to the plugin repository, so the translations need to come with the plugin directly.

1 Answer 1

1

So i found my own mistake:

I did not properly read https://developer.wordpress.org/plugins/internationalization/localization/#translate-the-po-file

My .mo files were just called like en-US.mo. But they should be called my-plugin-en-US.mo.

Solved!

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.