admin管理员组

文章数量:1279008

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?

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?

Share Improve this question asked Oct 4, 2021 at 17:28 zeko868zeko868 32 bronze badges 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
Add a comment  | 

1 Answer 1

Reset to default 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.

本文标签: Use localized plugin name and description even when the plugin is disabled