mondula / ticket-hub

1 stars 0 forks source link

WP_Feedback_Internationalization: Don't use variables or defines as text, context or text domain parameters. #14

Closed JonathanPultz closed 2 months ago

JonathanPultz commented 2 months ago

In order to make a string translatable in your plugin you are using a set of special functions. These functions collectively are known as "gettext".

There is a dedicated team in the WordPress community to translate and help other translating strings of WordPress core, plugins and themes to other languages.

To make them be able to translate this plugin, please do not use variables or function calls for the text, context or text domain parameters of any gettext function, all of them NEED to be strings. Note that the translation parser reads the code without executing it, so it won't be able to read anything that is not a string within these functions.

For example, if your gettext function looks like this... esc_html__( $greetings , 'plugin-slug' ); ...the translator won't be able to see anything to be translated as $greetings is not a string, it is not something that can be translated. You need to give them the string to be translated, so they can see it in the translation system and can translate it, the correct would be as follows... esc_html__( 'Hello, how are you?' , 'plugin-slug' );

This also applies to the translation domain, this is a bad call: esc_html( 'Hello, how are you?' , $plugin_slug ); The fix here would be like this esc_html( 'Hello, how are you?' , 'plugin-slug' ); Also note that the translation domain needs to be the same as your plugin slug.

What if we want to include a dynamic value inside the translation? Easy, you need to add a placeholder which will be part of the string and change it after the gettext function does its magic, you can use printf to do so, like this: printf( / translators: %s: First name of the user / esc_html__( 'Hello %s, how are you?', 'plugin-slug' ), esc_html( $user_firstname ) );

You can read https://developer.wordpress.org/plugins/internationalization/how-to-internationalize-your-plugin/#text-domains for more information.

Example(s) from your plugin:

ticket-hub/ticket-hub.php:55 _n_noop('Archived (%s)', 'Archived (%s)');