protected function writeReal( MessageCollection $collection ) { $collection->loadTranslations(); $header = "<!--\n"; $header .= $this->doHeader( $collection ); $header .= $this->doAuthors( $collection ); $header .= "-->\n"; $output = ''; $mangler = $this->group->getMangler(); foreach ( $collection as $key => $m ) { $key = $mangler->unmangle( $key ); $trans = $m->translation(); $trans = str_replace( TRANSLATE_FUZZY, '', $trans ); if ( $trans === '' ) { continue; } $trans = str_replace( '"', '"', $trans ); $output .= "<!ENTITY $key \"$trans\">\n"; } return $output ? $header . $output : false; }
/** * @param $collection MessageCollection */ public function write( MessageCollection $collection ) { if ( $this->fw === null ) { $sourceLanguage = $this->group->getSourceLanguage(); $outputFile = $this->writePath . '/' . $this->group->getTargetFilename( $sourceLanguage ); wfMkdirParents( dirname( $outputFile ), null, __METHOD__ ); $this->fw = fopen( $outputFile, 'w' ); $this->fw = fopen( $this->writePath . '/' . $this->group->getTargetFilename( $sourceLanguage ), 'w' ); fwrite( $this->fw, "# -*- coding: utf-8 -*-\nmsg = {\n" ); } // Not sure why this is needed, only continue if there are translations. $collection->loadTranslations(); $ok = false; foreach ( $collection as $messages ) { if ( $messages->translation() != '' ) { $ok = true; } } if ( !$ok ) { return; } $authors = $this->doAuthors( $collection ); if ( $authors != '' ) { fwrite( $this->fw, "$authors" ); } $code = $this->group->mapCode( $collection->code ); fwrite( $this->fw, "\t'{$code}': {\n" ); fwrite( $this->fw, $this->writeBlock( $collection ) ); fwrite( $this->fw, "\t},\n" ); }
/** * Returns translation page with all possible translations replaced in * and ugly translation tags removed. * * @param MessageCollection $collection Collection that holds translated messages. * @return string Whole page as wikitext. */ public function getTranslationPageText($collection) { $text = $this->template; // The source // For finding the messages $prefix = $this->title->getPrefixedDBKey() . '/'; if ($collection instanceof MessageCollection) { $collection->loadTranslations(DB_MASTER); $collection->filter('translated', false); } foreach ($this->sections as $ph => $s) { $sectiontext = null; if (isset($collection[$prefix . $s->id])) { /** * @var TMessage $msg */ $msg = $collection[$prefix . $s->id]; $sectiontext = $msg->translation(); } // Use the original text if no translation is available. // For the source language, this will actually be the source, which // contains variable declarations (tvar) instead of variables ($1). // The getTextWithVariables will convert declarations to normal variables // for us so that the variable substitutions below will also work // for the source language. if ($sectiontext === null || $sectiontext === $s->getText()) { $sectiontext = $s->getTextWithVariables(); } // Substitute variables into section text and substitute text into document $sectiontext = strtr($sectiontext, $s->getVariables()); $text = str_replace($ph, $sectiontext, $text); } $nph = array(); $text = TranslatablePage::armourNowiki($nph, $text); // Remove translation markup from the template to produce final text $cb = array(__CLASS__, 'replaceTagCb'); $text = preg_replace_callback('~(<translate>)(.*)(</translate>)~sU', $cb, $text); $text = TranslatablePage::unArmourNowiki($nph, $text); return $text; }