src/Viserio/Component/Parser/Dumper/XliffDumper.php
private static function dumpXliffVersion1(array $data): string
    {
        $sourceLanguage = $data['source-language'];
        $targetLanguage = $data['target-language'];
        $encoding       = 'UTF-8';

        if (isset($data['encoding'])) {
            $encoding = $data['encoding'];

            unset($data['encoding']);
        }

        unset($data['source-language'], $data['target-language']);

        $dom               = new DOMDocument('1.0', $encoding);
        $dom->formatOutput = true;

        $xliff = $dom->appendChild($dom->createElement('xliff'));
        $xliff->setAttribute('version', '1.2');
        $xliff->setAttribute('xmlns', 'urn:oasis:names:tc:xliff:document:1.2');

        $xliffFile = $xliff->appendChild($dom->createElement('file'));
        $xliffFile->setAttribute('source-language', \str_replace('_', '-', $sourceLanguage));

        if ($targetLanguage !== '') {
            $xliffFile->setAttribute('target-language', \str_replace('_', '-', $targetLanguage));
        }

        $xliffFile->setAttribute('datatype', 'plaintext');
        $xliffFile->setAttribute('original', 'file.ext');

        $xliffBody = $xliffFile->appendChild($dom->createElement('body'));

        foreach ($data as $resname => $translation) {
            $unit = $dom->createElement('trans-unit');
            $unit->setAttribute('id', $translation['id'] ?? \md5($resname));
            $unit->setAttribute('resname', $resname);

            $source = $unit->appendChild($dom->createElement('source'));
            $source->appendChild($dom->createTextNode($translation['source']));

            $targetElement = $dom->createElement('target');

            if (isset($translation['target-attributes'])) {
                foreach ($translation['target-attributes'] as $key => $value) {
                    $targetElement->setAttribute($key, $value);
                }
            }

            $target = $unit->appendChild($targetElement);

            // Does the target contain characters requiring a CDATA section?
            if (\preg_match('/[&<>]/', $translation['target']) === 1) {
                $target->appendChild($dom->createCDATASection($translation['target']));
            } else {
                $target->appendChild($dom->createTextNode($translation['target']));
            }

            if (isset($translation['notes'])) {
                foreach ($translation['notes'] as $note) {
                    $noteElement = $dom->createElement('note');
                    $noteElement->appendChild($dom->createTextNode($note['content'] ?? ''));

                    unset($note['content']);

                    foreach ((array) $note as $name => $value) {
                        $noteElement->setAttribute($name, $value);
                    }

                    $unit->appendChild($noteElement);
                }
            }

            $xliffBody->appendChild($unit);
        }

        return $dom->saveXML();
    }
private static function dumpXliffVersion1(array $data): string
    {
        $sourceLanguage = $data['source-language'];
        $targetLanguage = $data['target-language'];
        $encoding       = 'UTF-8';

        if (isset($data['encoding'])) {
            $encoding = $data['encoding'];

            unset($data['encoding']);
        }

        unset($data['source-language'], $data['target-language']);

        $dom               = new DOMDocument('1.0', $encoding);
        $dom->formatOutput = true;

        $xliff = $dom->appendChild($dom->createElement('xliff'));
        $xliff->setAttribute('version', '1.2');
        $xliff->setAttribute('xmlns', 'urn:oasis:names:tc:xliff:document:1.2');

        $xliffFile = $xliff->appendChild($dom->createElement('file'));
        $xliffFile->setAttribute('source-language', \str_replace('_', '-', $sourceLanguage));

        if ($targetLanguage !== '') {
            $xliffFile->setAttribute('target-language', \str_replace('_', '-', $targetLanguage));
        }

        $xliffFile->setAttribute('datatype', 'plaintext');
        $xliffFile->setAttribute('original', 'file.ext');

        $xliffBody = $xliffFile->appendChild($dom->createElement('body'));

        foreach ($data as $resname => $translation) {
            $unit = $dom->createElement('trans-unit');
            $unit->setAttribute('id', $translation['id'] ?? \md5($resname));
            $unit->setAttribute('resname', $resname);

            $source = $unit->appendChild($dom->createElement('source'));
            $source->appendChild($dom->createTextNode($translation['source']));

            $targetElement = $dom->createElement('target');

            if (isset($translation['target-attributes'])) {
                foreach ($translation['target-attributes'] as $key => $value) {
                    $targetElement->setAttribute($key, $value);
                }
            }

            $target = $unit->appendChild($targetElement);

            // Does the target contain characters requiring a CDATA section?
            if (\preg_match('/[&<>]/', $translation['target']) === 1) {
                $target->appendChild($dom->createCDATASection($translation['target']));
            } else {
                $target->appendChild($dom->createTextNode($translation['target']));
            }

            if (isset($translation['notes'])) {
                foreach ($translation['notes'] as $note) {
                    $noteElement = $dom->createElement('note');
                    $noteElement->appendChild($dom->createTextNode($note['content'] ?? ''));

                    unset($note['content']);

                    foreach ((array) $note as $name => $value) {
                        $noteElement->setAttribute($name, $value);
                    }

                    $unit->appendChild($noteElement);
                }
            }

            $xliffBody->appendChild($unit);
        }

        return $dom->saveXML();
    }
Dump xliff version 1.

@param array $data

@return string