group->getMangler()->mangle( $messages['root'] ); } else { $messages = $this->group->getMangler()->mangle( $messages ); } return [ 'MESSAGES' => $messages, 'AUTHORS' => $authors, 'METADATA' => $metadata, ]; } /** * @param MessageCollection $collection * @return string */ protected function writeReal( MessageCollection $collection ) { $messages = []; $mangler = $this->group->getMangler(); /** @var ThinMessage $m */ foreach ( $collection as $key => $m ) { $value = $m->translation(); if ( $value === null ) { continue; } if ( $m->hasTag( 'fuzzy' ) ) { $value = str_replace( TRANSLATE_FUZZY, '', $value ); } $key = $mangler->unmangle( $key ); $messages[$key] = $value; } // Do not create empty files if ( !count( $messages ) ) { return ''; } $header = $this->header( $collection->code, $collection->getAuthors() ); return $header . FormatJson::encode( $messages, "\t", FormatJson::UTF8_OK ) . ");\n"; } /** * @param string $data * @return string of JSON */ private static function extractMessagePart( $data ) { // Find the start and end of the data section (enclosed in the define function call). $dataStart = strpos( $data, 'define(' ) + 6; $dataEnd = strrpos( $data, ')' ); // Strip everything outside of the data section. return substr( $data, $dataStart + 1, $dataEnd - $dataStart - 1 ); } /** * @param string $data * @return array */ private static function extractAuthors( $data ) { preg_match_all( '~\n \* - (.+)~', $data, $result ); return $result[1]; } /** * @param string $code * @param array $authors * @return string */ private function header( $code, $authors ) { global $wgSitename; $name = TranslateUtils::getLanguageName( $code ); $authorsList = $this->authorsList( $authors ); return <<