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

Translator comments are not extracted if they are not directly followed by a gettext function #4

Closed
ocean90 opened this issue Dec 13, 2017 · 4 comments
Labels
Milestone

Comments

@ocean90
Copy link
Contributor

ocean90 commented Dec 13, 2017

Example plugin file:

<?php
/**
 * Plugin Name: Plugin name
 */

/* translators: TRANSLATORS!! */
_e( 'hello world', 'test-plugin' );

/* translators: TRANSLATORS!! */
$foo = __( 'foo', 'test-plugin' );

Running the makpot command creates this POT file:

# Copyright (C) 2017 Plugin name
# This file is distributed under the same license as the Plugin name package.
msgid ""
msgstr ""
"Project-Id-Version: Plugin name\n"
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/test-plugin\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"POT-Creation-Date: 2017-12-13T17:11:07+00:00\n"
"PO-Revision-Date: 2017-12-13T17:11:07+00:00\n"
"X-Domain: test-plugin\n"

#. translators: TRANSLATORS!!
#: test-plugin.php:7
msgid "hello world"
msgstr ""

#: test-plugin.php:10
msgid "foo"
msgstr ""

#. Plugin Name of the plugin/theme
msgid "Plugin name"
msgstr ""

Note the missing comment for "foo".

@swissspidy
Copy link
Member

I'll try to investigate this a bit.

Perhaps this needs to be reported upstream?

See php-gettext/Gettext#100 and php-gettext/Gettext#102.

@swissspidy
Copy link
Member

Here's the gettext spec, for reference: https://www.gnu.org/savannah-checkouts/gnu/gettext/manual/html_node/xgettext-Invocation.html#Operation-mode

It mentions a case like

/* translators: this comment is ignored */
__(
    'foo',
    'test-plugin'
);

but not

/* translators: TRANSLATORS!! */
$foo = __( 'foo', 'test-plugin' );

@swissspidy
Copy link
Member

swissspidy commented Dec 14, 2017

Okay so xgettext --add-comments=translators --keyword=__:1 --add-location test.php extracts that comment, but that library doesn't.

@swissspidy
Copy link
Member

This specific case is now addressed. php-gettext/Gettext#166 now aims to improve support for multi-line comments and comments on the same line as the function.

I'll continue to address this in #23.

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

No branches or pull requests

3 participants