Skip to content

ContainerAwareTrans should not add empty strings to the SourceCollection #130

@nicwortel

Description

@nicwortel

Might be somewhat related to #125.

The ContainerAwareTrans visitor unconditionally creates a source location, even if the result of getStringArgument is null.

//If $this->get('translator')->trans('foobar')
if ('trans' === $name) {
$label = $this->getStringArgument($node, 0);
$domain = $this->getStringArgument($node, 2);
$this->addLocation($label, $node->getAttribute('startLine'), $node, ['domain' => $domain]);
}

In my particular case this happens because I concatenate a string with a variable:

$this->translator->trans('message.audit_log.' . $eventType);

Which results in the following translation unit being added to my messages.en.xlf:

    <unit id="47DEQpj" name="">
      <segment>
        <source></source>
        <target></target>
      </segment>
    </unit>

I believe the $this->addLocation call should be wrapped in an if (null !== $label = $this->getStringArgument($node, 1)), similar to what happens in the FlashMessage visitor:

if (null !== $label = $this->getStringArgument($node, 1)) {
$this->addLocation($label, $node->getAttribute('startLine'), $node);
}

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