This an easy and short one, but the documentation on WP.org for the load_plugin_textdomain function might lead you into the wrong direction, if you start thinking about how to define the 2nd and 3rd parameter.
For a simple plugin, it is best to use the translate.wordpress.org repository for translations. This way the different strings can be translated individually directly online and you do not need to worry about having the right .po
and .mo
files updated within your plugins repository.
Additionally, usage of the online repository will also simplify the load_plugin_textdomain call, as you can basically leave out the 2nd and 3rd parameter. For the first parameter use the slug of your plugin name – here the example for my th23 User Management plugin:
load_plugin_textdomain('th23-user-management');
Make sure NOT to use a variable as the slug, e.g. do NOT use the following:
$plugin_slug = 'th23-user-management'; load_plugin_textdomain($plugin_slug);
And ensure to declare the plugin text domain in the header of your main plugin file – again my th23 User Management example, where the main file is named th23-user-management.php
:
<?php /* ... Text Domain: th23-user-management ... */
Easy!
- Don’t try to be smart!
- Don’t make up something sophisticated!