admin管理员组

文章数量:1317910

I am following this official guide to internationalise my plugin. But I am confused if the hints are must required incase of variables inside string?

printf(
    /* translators: 1: Name of a city 2: ZIP code */
    __( 'Your zip code is %2$s, and your city is %1$s.', 'my-plugin' ),
    $city,
    $zipcode
);

Also in this documentation, no where it is mentioned to use load_plugin_textdomain to load the text domain. It is only mentioned about the Domain Path. So can I omit load_plugin_textdomain if I use Domain Path?

I am following this official guide to internationalise my plugin. But I am confused if the hints are must required incase of variables inside string?

printf(
    /* translators: 1: Name of a city 2: ZIP code */
    __( 'Your zip code is %2$s, and your city is %1$s.', 'my-plugin' ),
    $city,
    $zipcode
);

Also in this documentation, no where it is mentioned to use load_plugin_textdomain to load the text domain. It is only mentioned about the Domain Path. So can I omit load_plugin_textdomain if I use Domain Path?

Share Improve this question asked Oct 29, 2020 at 14:25 SkyRarSkyRar 2122 silver badges9 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

The notes to translators aren't required, as far as I can tell, but they will definitely help anyone out who's trying to translate your plugin. You might want to think of them as best practices rather than requirements.

As to your second question:

Since WordPress 4.6 translations now take translate.wordpress as priority and so plugins that are translated via translate.wordpress do not necessary require load_plugin_textdomain() anymore. If you don’t want to add a load_plugin_textdomain() call to your plugin you have to set the Requires at least: field in your readme.txt to 4.6.
— from the docs

So I gather that, if you intend your plugin to be translated by the community at translate.wordpress, you don't need to call load_plugin_textdomain(). However, if you're not going to be distributing your plugin through the official WordPress repository (eg, you'll be using GitHub or your personal site to distribute it), you might still need to load_plugin_textdomain().

本文标签: plugin developmentIs hint for translator compulsory while internationalizing a string containing variables