I am trying to add a translation to a plugin I wrote from scratch but after experimenting a while I'm not sure how to make Wordpress aware that there's a translation available for my plugin.
I'm not sure what else to try so I thought that someone more experienced could point out things I might need to change.
What I did so far:
- Added either
_e()
or__()
to the sentences I want to be translated in my plugin files. - Used Loco Translate plugin to generate a
.pot
file. - Opened
.pot
file in Poedit, (it displayed a list of all the strings I wanted to translate) translated plugin and generated.po
and.mo
files from it. - Moved
.pot
,.po
and.mo
tomy-plugin/languages/
. - Renamed files to
my-plugin-pt.po
andmy-plugin-pt.mo
. - Changed Wordpress site language to translated language. Language changed everywhere else but the plugin still renders in english.
Not really sure what to do next.
I've created a method that runs load_plugin_textdomain()
while following these instructions from Wordpress and have added it as an action to my-plugin
__construct()
:
my-plugin.php
public function __construct() {
// Other filters and actions...
add_action( 'plugins_loaded', array( $this, 'translation_init' ) );
} // __construct
function translation_init() {
load_plugin_textdomain( 'my-plugin', FALSE, basename( dirname( __FILE__ ) ) . '/languages/' );
}