-
-
Notifications
You must be signed in to change notification settings - Fork 135
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
Comments extraction from PHP code #102
Comments extraction from PHP code #102
Conversation
* Constructor. | ||
* | ||
* @param string $code The php code to scan | ||
*/ | ||
public function __construct($code) | ||
{ | ||
$this->tokens = token_get_all($code); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's filter out white spaces, so that parsing tokens is faster
It looks fine. I think is better to extract always the comments. If the user don't want them, they can be removed later. The rest of the extractors are not configurable. What do you think? |
One may want only comments that start with a specific text (like xgettext), otherwise we risk to extract comments that are not related to the strings to be translated. // Initialize some variables
$hi = __('Hello');
$x = 1;
$y = 2; So, I think we should keep the same approach as xgettext: only extract comments if requested, and optionally allow to specify a "tag" to filter comments to be extracted. |
ah, so comments can be before the function, not neccesary inside? |
Its fine to me |
I forgot to answer this:
Yes, xgettext can extract comments that are imediately before the function, provided that "comment blocks supposed to be extracted must be adjacent to keyword lines" (from gettext manual) That means that with this code <?php
echo __(/* i18n: Test comment 1 */'test 1');
/* i18n: Test comment 2 */
echo __('test 2');
/* i18n: Test comment 3 */
echo __('test 3');
/* i18n: Test comment 4 */
echo __(
'test 4'
);
#. i18n: Test comment 1
#: test.php:3
msgid "test 1"
msgstr ""
#. i18n: Test comment 2
#: test.php:6
msgid "test 2"
msgstr ""
#. i18n: Test comment 3
#: test.php:10
msgid "test 3"
msgstr ""
#: test.php:14
msgid "test 4"
msgstr "" The current implementation of this pull request is a bit different: it will extracts also |
Ok, I'll add a few tests and everything is ready to be merged 😉 |
Done. |
After this has been merged I'll stop boring you and I'll be looking forward to a new release 😉 |
Comments extraction from PHP code
Thanks for your hard work. I'm going to release the new 3.5.9 version soon. |
Thanks to you!
Great! |
The wait is over: https://github.com/oscarotero/Gettext/releases/tag/v3.5.9 |
Super fast! Thank you!! |
Follow-up of #100: what about a code like this?