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:
- Set up local wordpress using docker
- Added Text Domain to Plugin-Info
* Text Domain: my-plugin
- Added Domain Path to Plugin-Info
* Domain Path: /languages/
- 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/');
}
I have a
settings.php
which is responsible for rendering my plugin's Settings page and is initialized fromplugin.php
. I added this line there to test my translation:<?php _e( 'Hello, dear user!', 'my-plugin' ); ?>
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 propermy-plugin.pot
inside my plugin'slanguage
directory.I used PoEdit to create translations from that pot file. I made
en_US.po
anden_US.mo
inside thelanguage
directory. I translated my test string in the settings page as well as the plugin description.Set Wordpress language to en_US via general settings. (I also tried
define ('WPLANG', 'en_US');
insidewp_config.php
)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.