Skip to content

Comment extraction does not work when placed on the line above within array (or what) #19

@jasomdotnet

Description

@jasomdotnet

Hi Oscar,

this is the case, comment extraction does not work:

<?php
require 'vendor/autoload.php';

use Gettext\Scanner\PhpScanner;
use Gettext\Translations;

$phpScanner = new PhpScanner(
        Translations::create('default'),
        Translations::create('admin'),
);

$phpScanner->setFunctions([
    '__' => 'gettext',
    'd__' => 'dgettext',
]);

$phpScanner->ignoreInvalidFunctions(true);
$phpScanner->setDefaultDomain('default');
$phpScanner->extractCommentsStartingWith('PREV:', 'Prev:', 'prev:');
$phpScanner->scanFile('class.php');

echo '<pre>' . PHP_EOL;
print_r($phpScanner->getTranslations());

And this is the class.php

<?php
/* PREV: Extracted comment 1 */
$arg = [__('String with extracted comment 1')];

$args = [];

$args = array_merge($args, [
    'title' => /* PREV: Extracted comment 2 */ __('Contact'),
    'noscript' => [
        /* PREV: Omitted commnet above 1  */
        Flash::INFO => [__('String with no comment extracted despite it has one.')]
    ],
    'breadcrumb' => [
        ['text' => /* PREV: Extracted comment 3 */ d__('admin', 'String with extracted comment 3'), 'link' => get_homepage_url()],
    ],
    'metatags' => new Meta([
        /* PREV: Omitted commnet above 2 */
        'description' => __('Another string with no comment extracted despite it has one.'),
            ]),
        ]
);

Is this a bug or am I doing something wrong?

NOTE: PREV in this case means "previous original"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions