DtdFFS.php

Go to the documentation of this file.
00001 <?php
00018 class DtdFFS extends SimpleFFS {
00019     public function getFileExtensions() {
00020         return array( '.dtd' );
00021     }
00022 
00027     public function readFromVariable( $data ) {
00028         preg_match_all( ',# Author: ([^\n]+)\n,', $data, $matches );
00029         $authors = array();
00030 
00031         $count = count( $matches[1] );
00032         for ( $i = 0; $i < $count; $i++ ) {
00033             $authors[] = $matches[1][$i];
00034         }
00035 
00036         preg_match_all( ',<!ENTITY[ ]+([^ ]+)\s+"([^"]+)"[^>]*>,', $data, $matches );
00037 
00038         $keys = $matches[1];
00039         $values = $matches[2];
00040 
00041         $messages = array();
00042 
00043         $count = count( $matches[1] );
00044         for ( $i = 0; $i < $count; $i++ ) {
00045             $messages[$keys[$i]] = str_replace(
00046                 array( '&quot;', '&#34;', '&#39;' ),
00047                 array( '"', '"', "'" ),
00048                 $values[$i] );
00049         }
00050 
00051         $messages = $this->group->getMangler()->mangle( $messages );
00052 
00053         return array(
00054             'AUTHORS' => $authors,
00055             'MESSAGES' => $messages,
00056         );
00057     }
00058 
00059     protected function writeReal( MessageCollection $collection ) {
00060         $collection->loadTranslations();
00061 
00062         $header = "<!--\n";
00063         $header .= $this->doHeader( $collection );
00064         $header .= $this->doAuthors( $collection );
00065         $header .= "-->\n";
00066 
00067         $output = '';
00068         $mangler = $this->group->getMangler();
00069 
00073         foreach ( $collection as $key => $m ) {
00074             $key = $mangler->unmangle( $key );
00075             $trans = $m->translation();
00076             $trans = str_replace( TRANSLATE_FUZZY, '', $trans );
00077 
00078             if ( $trans === '' ) {
00079                 continue;
00080             }
00081 
00082             $trans = str_replace( '"', '&quot;', $trans );
00083             $output .= "<!ENTITY $key \"$trans\">\n";
00084         }
00085 
00086         return $output ? $header . $output : false;
00087     }
00088 
00089     protected function doHeader( MessageCollection $collection ) {
00090         global $wgSitename;
00091 
00092         $code = $collection->code;
00093         $name = TranslateUtils::getLanguageName( $code );
00094         $native = TranslateUtils::getLanguageName( $code, $code );
00095 
00096         $output = "# Messages for $name ($native)\n";
00097         $output .= "# Exported from $wgSitename\n\n";
00098 
00099         return $output;
00100     }
00101 
00102     protected function doAuthors( MessageCollection $collection ) {
00103         $output = '';
00104         $authors = $collection->getAuthors();
00105         $authors = $this->filterAuthors( $authors, $collection->code );
00106 
00107         foreach ( $authors as $author ) {
00108             $output .= "# Author: $author\n";
00109         }
00110 
00111         return $output;
00112     }
00113 }
Generated on Tue Oct 29 00:00:23 2013 for MediaWiki Translate Extension by  doxygen 1.6.3