Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

String Audit: False-positive for different translator comments #96

Closed
ocean90 opened this issue Oct 27, 2018 · 8 comments
Closed

String Audit: False-positive for different translator comments #96

ocean90 opened this issue Oct 27, 2018 · 8 comments

Comments

@ocean90
Copy link
Contributor

ocean90 commented Oct 27, 2018

There are these warnings:

Warning: The string "Monday" has 3 different translator comments. (wp-includes/class-wp-locale.php:130)
Warning: The string "Tuesday" has 3 different translator comments. (wp-includes/class-wp-locale.php:131)
Warning: The string "Wednesday" has 3 different translator comments. (wp-includes/class-wp-locale.php:132)
Warning: The string "Thursday" has 3 different translator comments. (wp-includes/class-wp-locale.php:133)
Warning: The string "Friday" has 3 different translator comments. (wp-includes/class-wp-locale.php:134)
Warning: The string "Saturday" has 3 different translator comments. (wp-includes/class-wp-locale.php:135)
Warning: The string "February" has 2 different translator comments. (wp-includes/class-wp-locale.php:157)
Warning: The string "March" has 2 different translator comments. (wp-includes/class-wp-locale.php:158)
Warning: The string "April" has 2 different translator comments. (wp-includes/class-wp-locale.php:159)
Warning: The string "May" has 2 different translator comments. (wp-includes/class-wp-locale.php:160)
Warning: The string "June" has 2 different translator comments. (wp-includes/class-wp-locale.php:161)
Warning: The string "July" has 2 different translator comments. (wp-includes/class-wp-locale.php:162)
Warning: The string "August" has 2 different translator comments. (wp-includes/class-wp-locale.php:163)
Warning: The string "September" has 2 different translator comments. (wp-includes/class-wp-locale.php:164)
Warning: The string "October" has 2 different translator comments. (wp-includes/class-wp-locale.php:165)
Warning: The string "November" has 2 different translator comments. (wp-includes/class-wp-locale.php:166)
Warning: The string "December" has 2 different translator comments. (wp-includes/class-wp-locale.php:167)

The string "September" exists here and here. The second one is the comment for _x( 'Sep', 'September abbreviation' ) and not __( 'September' ).

@swissspidy
Copy link
Member

Oh, so it associates the comment with the preceeding __() instead of the following __()? Ugh.

I will try to look into this soon. Sounds like something that might need to be reported upstream at https://github.com/oscarotero/Gettext though.

In the meantime... can you just refactor the code? 😜

@swissspidy
Copy link
Member

Simple test case:

// The Months
$month['01'] = /* translators: month name */ __( 'January' );
$month['02'] = /* translators: month name */ __( 'February' );

// Abbreviations for each month.
$month_abbrev[ __( 'January' ) ]   = /* translators: three-letter abbreviation of the month */ _x( 'Jan', 'January abbreviation' );
$month_abbrev[ __( 'February' ) ]  = /* translators: three-letter abbreviation of the month */ _x( 'Feb', 'February abbreviation' );

No problem with the January string there, but the comments for February are messed up:

#. translators: month name
#: test.php:3
#: test.php:7
msgid "January"
msgstr ""

#. translators: month name
#. translators: three-letter abbreviation of the month
#: test.php:4
#: test.php:8
msgid "February"
msgstr ""

#. translators: three-letter abbreviation of the month
#: test.php:7
msgctxt "January abbreviation"
msgid "Jan"
msgstr ""

#. translators: three-letter abbreviation of the month
#: test.php:8
msgctxt "February abbreviation"
msgid "Feb"
msgstr ""

@swissspidy
Copy link
Member

Reported upstream: php-gettext/Gettext#194

It's been a while since I looked at that library, so if anyone wants to investigate \Gettext\Utils\PhpFunctionsScanner::getFunctions(), feel free 🙂

@swissspidy
Copy link
Member

In the meantime... can you just refactor the code?

Suggested change in https://core.trac.wordpress.org/ticket/45628:

$this->month_abbrev[ /* translators: month name */ __( 'December' ) ] = /* translators: three-letter abbreviation of the month */ _x( 'Dec', 'December abbreviation' );

Haven't tested if that works.

@kkmuffme
Copy link

That will only work if the other string actually also has a translators comment.
But if there is none, it will just apply the first translators comment to the second string too (even if that one doesnt have any placeholders)

@swissspidy
Copy link
Member

See #154 for more examples

@swissspidy
Copy link
Member

This can be revisited now with https://github.com/php-gettext/Gettext/releases/tag/v4.8.5 being released, as it's most likely fixed.

@swissspidy
Copy link
Member

This specific code section win WP_Locale was recently refactored, see WordPress/wordpress-develop@03e95d4

Given that, plus the upstream fix in Gettext, this can be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants