Skip Navigation

This thread is resolved. Here is a description of the problem and solution.

Problem:
The client is working on a site under development and is trying to use translation hints in their code. However, they do not see the hint in the translation dialog when using the following PHP code:

printf(esc_html(// translators: %s is a year __( 'Active since %s', 'cnmd' ),), esc_html( $year ));

Solution:
The solution in this case would be using the _x() Function which will allow you to add a context to a sting. WPML String Translation does have a column to display this context.
Source: https://developer.wordpress.org/reference/functions/_x/

We further explained that the comment

/* translators: %s: %s is a year */

is intended to provide context to translators who are translating the theme or plugin into different languages. It helps in understanding what the string represents, especially when creating .po language files that accompany the theme or plugin. However, PHP comments, whether single-line (//) or multi-line (/* */), are ignored by the PHP interpreter during script execution. They are meant only for documentation and do not appear on the website or affect the program's execution. For more details on PHP comments, you can visit https://www.w3schools.com/php/php_comments.asp.

If this solution does not resolve your issue or seems irrelevant due to being outdated or not applicable to your case, we highly recommend checking related known issues at https://wpml.org/known-issues/, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. Should you need further assistance, please open a new support ticket with us.

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This topic contains 2 replies, has 2 voices.

Last updated by mikeD-5 4 months, 3 weeks ago.

Assisted by: Andreas W..

Author Posts
July 12, 2024 at 3:06 am #15939015

mikeD-5

Background of the issue:
I am working on a site under development and trying to use translation hints in my code. Given this code:

printf(
esc_html(
// translators: %s is a year
__( 'Active since %s', 'cnmd' ),
),
esc_html( $year )
);

I do not see the hint in the translation dialog.

Symptoms:
Translation hint is not visible in the translation dialog.

Questions:
Where are translation hints?

July 12, 2024 at 4:16 am #15939398

Andreas W.
Supporter

Languages: English (English ) Spanish (Español ) German (Deutsch )

Timezone: America/Lima (GMT-05:00)

Hello,

Purpose of the Translator Comment:

The comment

/* translators: %s: %s is a year */

is meant for translators who work on translating your theme or plugin into different languages. It provides context about the string that needs translation, specifically explaining what it represents.

In your example, the comment serves translators who work on the theme files and create .po language files that are shipped together with the theme or plugin.

Comments in PHP (denoted by // for single-line comments or /* */ for multi-line comments) are primarily used to document code and explain its purpose or functionality. This helps developers (including yourself in the future) understand why certain code was written in a particular way.
Comments are also used to provide context, describe algorithms, or clarify complex sections of code.

Non-Execution:

PHP interpreter ignores comments completely during the execution of the script. They do not generate any output, nor do they affect how the program runs.
This means comments are purely for human readers and do not contribute to the logic, calculations, or output of the PHP script.

This means, that it is technically impossible to display a comment on the website.

More details:
hidden link

Best regards
Andreas

July 12, 2024 at 8:25 am #15940907

mikeD-5

This response is factually correct while missing the entire point of the question.

Given that you have correctly identified the purpose of the translation hint comment, please read my question again.

Also can you please enable a private response?

July 12, 2024 at 4:48 pm #15943572

mikeD-5

The solution seems to be to use the _x() versions of the translations functions, and duplicate the translation hint there. Seems unfortunately redundant but at least there is a solution.

Thanks.