示例#1
0
	/**
	 * Returns translation page with all possible translations replaced in, ugly
	 * translation tags removed and outdated translation marked with a class
	 * mw-translate-fuzzy.
	 * @todo The class marking has to be more intelligent with span&div use.
	 * @param $collection \type{MessageCollection} Collection that holds translated messages.
	 * @return \string Whole page as wikitext.
	 */
	public function getTranslationPageText( /*MessageCollection*/ $collection ) {
		$text = $this->template; // The source

		// For finding the messages
		$prefix = $this->title->getPrefixedDBKey() . '/';

		if ( $collection instanceof MessageCollection ) {
			$collection->filter( 'hastranslation', false );
			$collection->loadTranslations();
		}

		foreach ( $this->sections as $ph => $s ) {
			$sectiontext = null;

			if ( isset( $collection[$prefix . $s->id] ) ) {
				$msg = $collection[$prefix . $s->id];
				$translation = $msg->translation();

				if ( $translation !== null ) {
					// Ideally we should not have fuzzy here, but old texts do
					$sectiontext = str_replace( TRANSLATE_FUZZY, '', $translation );

					if ( $msg->hasTag( 'fuzzy' ) ) {
						$sectiontext = "<span class=\"mw-translate-fuzzy\">\n$sectiontext\n</span>";
					}
				}
			}

			// Use the original text if no translation is available
			if ( $sectiontext === null ) {
				$sectiontext = $s->getTextForTrans();
			}

			// Substitute variables into section text and substitute text into document
			$sectiontext = self::replaceVariables( $s->getVariables(), $sectiontext );
			$text = str_replace( $ph, $sectiontext, $text );
		}

		$nph = array();
		$text = TranslatablePage::armourNowiki( $nph, $text );

		// Remove translation markup
		$cb = array( __CLASS__, 'replaceTagCb' );
		$text = preg_replace_callback( '~(<translate>)(.*)(</translate>)~sU', $cb, $text );
		$text = TranslatablePage::unArmourNowiki( $nph, $text );

		return $text;
	}
 /**
  * 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;
 }