46 $mangler = $this->group->getMangler();
48 $reader =
new SimpleXMLElement( $data );
49 $reader->registerXPathNamespace(
51 'urn:oasis:names:tc:xliff:document:1.2'
55 $reader->xpath(
'//trans-unit' ),
56 $reader->xpath(
'//xliff:trans-unit' )
59 foreach ( $items as $item ) {
61 $source = $item->$element;
67 $key = (string)$item[
'id'];
71 $dom =
new DOMDocument(
'1.0' );
72 $dom->loadXML( $source->asXML() );
79 if ( (
string)$source[
'state'] ===
'needs-l10n' ) {
80 $value = TRANSLATE_FUZZY . $value;
84 $value = preg_replace(
'/<!\[CDATA\[(.*?)\]\]>/s',
'\1', $value );
86 $messages[$key] = $value;
90 'MESSAGES' => $mangler->mangleArray( $messages ),
131 $mangler = $this->group->getMangler();
133 $template =
new DomDocument(
'1.0' );
134 $template->preserveWhiteSpace =
false;
135 $template->formatOutput =
true;
138 $sourceLanguage = $this->group->getSourceLanguage();
139 $sourceFile = $this->group->getSourceFilePath( $sourceLanguage );
140 if ( file_exists( $sourceFile ) ) {
141 $template->load( $sourceFile );
144 $template->load( __DIR__ .
'/../data/xliff-template.xml' );
147 $list = $template->getElementsByTagName(
'body' )->item( 0 );
148 $list->nodeValue =
null;
151 foreach ( $collection as $key => $m ) {
152 $key = $mangler->unmangle( $key );
154 $value = $m->translation();
155 $value = str_replace( TRANSLATE_FUZZY,
'', $value );
158 $source = $template->createDocumentFragment();
159 $source->appendXML( htmlspecialchars( $m->definition() ) );
161 $target = $template->createDocumentFragment();
162 $target->appendXML( htmlspecialchars( $value ) );
164 $sourceElement = $template->createElement(
'source' );
165 $sourceElement->appendChild( $source );
167 $targetElement = $template->createElement(
'target' );
168 $targetElement->appendChild( $target );
169 if ( $m->getProperty(
'status' ) ===
'fuzzy' ) {
170 $targetElement->setAttribute(
'state',
'needs-l10n' );
172 if ( $m->getProperty(
'status' ) ===
'proofread' ) {
173 $targetElement->setAttribute(
'state',
'signed-off' );
176 $transUnit = $template->createElement(
'trans-unit' );
177 $transUnit->setAttribute(
'id', $key );
178 $transUnit->appendChild( $sourceElement );
179 $transUnit->appendChild( $targetElement );
181 $list->appendChild( $transUnit );
184 $template->encoding =
'UTF-8';
186 return $template->saveXML();