WordPress.org

Make WordPress Core

Opened 2 years ago

Closed 18 months ago

Last modified 18 months ago

#43864 closed defect (bug) (worksforme)

A comment inside an i18n function will cause makepot/extract.php to miss the string

Reported by: julesaus Owned by:
Milestone: Priority: normal
Severity: normal Version: 5.1
Component: I18N Keywords: has-patch has-unit-tests
Focuses: Cc:

Description

If you put a comment inside a translation function, makepot misses the entire string. For example, none of these strings will appear in a generated pot file:

<?php
__( /* */ 'missing' );

__(
  //
  'multiline missing'
);

__(
  // translators: This seems like a reasonable place to put a comment
  'A reasonable looking example'
);

You might pop the attached test-file.php into test-dir/ and run php ../makepot.php generic $PWD /dev/stdout; echo; if you'd like to see it yourself.

This is valid PHP and gettext handles this syntax fine, so it can be quite tricky to recognize the problem when it occurs.

Attachments (2)

extract-inline-translator-comments.patch (2.4 KB) - added by julesaus 2 years ago.
Patch
test-file.php (238 bytes) - added by julesaus 2 years ago.
Some example problematic strings

Download all attachments as: .zip

Change History (6)

@julesaus
2 years ago

Some example problematic strings

#1 @julesaus
2 years ago

  • Version set to trunk

Props @akirk for test_find_function_calls_with_inline_c_style_comment()

#2 @julesaus
20 months ago

This would certainly be a lower priority if we're using the wp i18n command (see https://meta.trac.wordpress.org/ticket/3748), but it still seems worth fixing this behaviour to me as long as makepot/extract.php is in the codebase.

Even with a better alternative, It seems like that many users will continue to use the old tool for some time before they update their existing processes.

#3 @swissspidy
18 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from new to closed

Closing as we now use https://github.com/wp-cli/i18n-command on WordPress.org for core, plugins, and themes, and recommend using that instead of makepot.php.

That WP-CLI command should work very well with these cases.

#4 @swissspidy
18 months ago

See #45287 for reference.

Note: See TracTickets for help on using tickets.