39 $reader =
new SimpleXMLElement( $data );
42 $mangler = $this->group->getMangler();
44 $regexBacktrackLimit = ini_get(
'pcre.backtrack_limit' );
45 ini_set(
'pcre.backtrack_limit', 10 );
48 foreach ( $reader as $element ) {
49 $key = (string)$element[
'name'];
51 if ( $element->getName() ===
'string' ) {
52 $value = $this->readElementContents( $element );
53 } elseif ( $element->getName() ===
'plurals' ) {
55 foreach ( $element as $item ) {
56 $forms[(string)$item[
'quantity']] = $this->readElementContents( $item );
58 $value = $this->flattener->flattenCLDRPlurals( $forms );
60 wfDebug( __METHOD__ .
': Unknown XML element name.' );
64 if ( isset( $element[
'fuzzy'] ) && (
string)$element[
'fuzzy'] ===
'true' ) {
65 $value = TRANSLATE_FUZZY . $value;
68 $messages[$key] = $value;
71 ini_set(
'pcre.backtrack_limit', $regexBacktrackLimit );
74 'AUTHORS' => $this->scrapeAuthors( $data ),
75 'MESSAGES' => $mangler->mangleArray( $messages ),
148 global $wgTranslateDocumentationLanguageCode;
150 $collection->
filter(
'hastranslation',
false );
151 if ( count( $collection ) === 0 ) {
155 $template =
'<?xml version="1.0" encoding="utf-8"?>';
156 $template .= $this->doAuthors( $collection );
157 $template .=
'<resources></resources>';
159 $writer =
new SimpleXMLElement( $template );
161 if ( $collection->
getLanguage() === $wgTranslateDocumentationLanguageCode ) {
162 $writer->addAttribute(
165 'http://schemas.android.com/tools'
169 $mangler = $this->group->getMangler();
171 foreach ( $collection as $key => $m ) {
172 $key = $mangler->unmangle( $key );
174 $value = $m->translation();
175 $value = str_replace( TRANSLATE_FUZZY,
'', $value );
177 $plurals = $this->flattener->unflattenCLDRPlurals(
'', $value );
179 if ( $plurals ===
false ) {
180 $element = $writer->addChild(
'string', $this->formatElementContents( $value ) );
182 $element = $writer->addChild(
'plurals' );
183 foreach ( $plurals as $quantity => $content ) {
184 $item = $element->addChild(
'item', $this->formatElementContents( $content ) );
185 $item->addAttribute(
'quantity', $quantity );
189 $element->addAttribute(
'name', $key );
191 if ( $m->hasTag(
'fuzzy' ) ) {
192 $element->addAttribute(
'fuzzy',
'true' );
197 $dom =
new DOMDocument(
'1.0' );
198 $dom->formatOutput =
true;
199 $dom->loadXML( $writer->asXML() );
201 return $dom->saveXML();