0

I'm working on plugin development and I'd like to localize my plugin name and description, so that these two pieces of information are shown to other WordPress developers in their native languages (if they are supported) on the list of currently installed plugins in WP Admin Dashboard. So far have I managed to accomplish this, but I've noticed that translations are not always shown. At example, if I disable my plugin, then the name and description are shown in original/english language, not in the matching the language of my WordPress instance.

For a second I've assumed that that's probably not even possible, but then I've noticed that the description of the plugin Hello Dolly (which is coming preinstalled and initially disabled) was shown in my language (Croatian to be exact). I've also tried to disable Akismet Anti-Spam plugin, whose description was as well shown in my language while it was enabled, and it remained translated in my language even after disablement.

Therefore my question is how to set-up plugin, so that its name and description are shown translated on the list of currently installed plugins in WP Admin Dashboard even when the plugin is disabled?

2
  • Maybe examine Hello Dolly and see how it does it?
    – vancoder
    Commented Oct 4, 2021 at 17:32
  • Yup, did it, but its script did not contain any localization-related code.
    – zeko868
    Commented Oct 4, 2021 at 17:43

1 Answer 1

0

Hello Dolly is a specific edge case, it does not translate itself. Rather it's considered a part of the WordPress codebase, and has a translated title in the WP core language files.

Instead, to have a plugin name translated, you need a language file that maps to the textdomain specified in your plugin, that contains your plugin name. This needs to be in the wp-content/languages/plugins folder or in the appropriate location inside your plugin. e.g. for mytestplugin it could be mytestplugin/mytextdomain-en_US.mo where mytextdomain is what you specified in your plugins header.

This is done via _get_plugin_data_markup_translate ( which has a special override for hello dolly ), and uses load_plugin_textdomain.

1
  • 1
    Thanks for comprehensive answer! It helped me to realize that the reason why title and description of my disabled plugin were not localized was because plugin's slug wasn't matching the value of textdomain from plugin's header. So when the plugin was installed, WordPress copied localization files from wp-content/plugins/my_plugin/languages to wp-content/languages/plugins, but it renamed them so they had names matching plugin's slug. When I change names of those copied files so that they correspond to the defined textdomain, then name and description were displayed properly.
    – zeko868
    Commented Oct 5, 2021 at 17:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.