createElement('xliff'); $xliff->setAttribute('version', '1.2'); $xliff->setAttribute('xmlns', 'urn:oasis:names:tc:xliff:document:1.2'); $file = $xml->createElement('file'); $file->setAttribute('source-language', 'en'); if (func_num_args() > 2) { $file->setAttribute('target-language', $language); } $file->setAttribute('datatype', 'plaintext'); $file->setAttribute('original', 'messages'); $file->setAttribute('date', strftime('%Y-%m-%dT%H:%M:%SZ')); $file->setAttribute('product-name', 'zsb'); $header = $xml->createElement('header'); $file->appendChild($header); $body = $xml->createElement('body'); foreach ($data as $index => $label) { $unit = $xml->createElement('trans-unit'); $unit->setAttribute('id', $index); $unit->setAttribute('resname', $index); $unit->setAttribute('approved', 'yes'); $unit->setAttribute('xml:space', 'preserve'); $source = $xml->createElement('source', $label); $unit->appendChild($source); if (func_num_args() > 2) { $target = $xml->createElement('target', $translations[$index]); $unit->appendChild($target); } $body->appendChild($unit); } $file->appendChild($body); $xliff->appendChild($file); $xml->appendChild($xliff); $xml->formatOutput = true; return $xml->saveXML(); } $outputs = []; if (isset($_POST['xml'])) { $xml = $_POST['xml']; $xml = utf8_encode($xml); $doc = new DOMDocument(); $doc->loadXML($xml); $defaults = array(); $langs = array(); $xpath = new DOMXPath($doc); $languages = $xpath->query("//T3locallang/data/languageKey"); foreach ($languages as $language) { $lang = $language->attributes['index']->value; if ($lang !== 'default') { $langs[$lang] = array(); } foreach ($language->childNodes as $word) { if ($word->nodeName !== 'label') { continue; } $string = utf8_decode($word->attributes['index']->value); $translation = utf8_decode($word->nodeValue); if ($lang === 'default') { $defaults[$string] = $translation; } else { $langs[$lang][$string] = $translation; } } } $outputs = array( 'locallang.xlf' => Language2XML($defaults, 'en'), ); foreach ($langs as $lang => $words) { $outputs[$lang . '.locallang.xlf'] = Language2XML($defaults, $lang, $words); } } ?>