src/Xml/XliffFile.php
public function createTranslationUnit(string $identifier, string $sourceValue = null): XmlElement
    {
        if (null === $body = $this->getXPathFirstItem('/xlf:xliff/xlf:file/xlf:body')) {
            throw new \InvalidArgumentException('Could not find the xliff body element');
        }

        /** @var XmlElement $transUnit */
        $transUnit = $this->createElementNS(self::XLIFF_NS, 'trans-unit');

        $body->appendChild($transUnit);

        $transUnit->setAttributeNS(self::XLIFF_NS, 'id', $identifier);
        $source = $transUnit->appendChild($this->createElementNS(self::XLIFF_NS, 'source'));
        if (null !== $sourceValue) {
            $source->appendChild($this->createTextNode($sourceValue));
        }

        return $transUnit;
    }
public function createTranslationUnit(string $identifier, string $sourceValue = null): XmlElement
    {
        if (null === $body = $this->getXPathFirstItem('/xlf:xliff/xlf:file/xlf:body')) {
            throw new \InvalidArgumentException('Could not find the xliff body element');
        }

        /** @var XmlElement $transUnit */
        $transUnit = $this->createElementNS(self::XLIFF_NS, 'trans-unit');

        $body->appendChild($transUnit);

        $transUnit->setAttributeNS(self::XLIFF_NS, 'id', $identifier);
        $source = $transUnit->appendChild($this->createElementNS(self::XLIFF_NS, 'source'));
        if (null !== $sourceValue) {
            $source->appendChild($this->createTextNode($sourceValue));
        }

        return $transUnit;
    }
public function createTranslationUnit ( string $ identifier , string $ sourceValue = null ) : XmlElement { if ( null === $ body = $ this -> getXPathFirstItem ( '/xlf:xliff/xlf:file/xlf:body' ) ) { throw new \ InvalidArgumentException ( 'Could not find the xliff body element' ) ; } /** @var XmlElement $transUnit */ $ transUnit = $ this -> createElementNS ( self :: XLIFF_NS , 'trans-unit' ) ; $ body -> appendChild ( $ transUnit ) ; $ transUnit -> setAttributeNS ( self :: XLIFF_NS , 'id' , $ identifier ) ; $ source = $ transUnit -> appendChild ( $ this -> createElementNS ( self :: XLIFF_NS , 'source' ) ) ; if ( null !== $ sourceValue ) { $ source -> appendChild ( $ this -> createTextNode ( $ sourceValue ) ) ; } return $ transUnit ; }
Append a translation unit.

@param string $identifier  The identifier to set.
@param string $sourceValue The content for the source value to set.

@return XmlElement

@throws \InvalidArgumentException When the body element can not be found.
Append a translation unit .