protected function doAuthors(MessageCollection $collection) { $output = ''; $authors = $collection->getAuthors(); $authors = $this->filterAuthors($authors, $collection->code); foreach ($authors as $author) { $output .= "# Author: {$author}\n"; } return $output; }
/** * @param MessageCollection $collection * @return string */ protected function writeReal(MessageCollection $collection) { $messages = array(); $template = $this->read($collection->getLanguage()); if (isset($template['METADATA'])) { $messages['@metadata'] = $template['METADATA']; } $authors = $collection->getAuthors(); $authors = $this->filterAuthors($authors, $collection->code); if (isset($template['AUTHORS'])) { $authors = array_unique(array_merge($template['AUTHORS'], $authors)); } if ($authors !== array()) { $messages['@metadata']['authors'] = array_values($authors); } $mangler = $this->group->getMangler(); /** * @var $m ThinMessage */ 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 ''; } return FormatJson::encode($messages, "\t", FormatJson::ALL_OK) . "\n"; }
/** * @param $collection MessageCollection * @return string */ protected function doAuthors( MessageCollection $collection ) { $output = ''; // Read authors. $fr = fopen( $this->group->getSourceFilePath( $collection->code ), 'r' ); $authors = array(); while ( !feof( $fr ) ) { $line = fgets( $fr ); if ( strpos( $line, "\t# Author:" ) === 0 ) { $authors[] = trim( substr( $line, strlen( "\t# Author: " ) ) ); } elseif ( $line === "\t'{$collection->code}': {\n" ) { break; } else { $authors = array(); } } $authors2 = $collection->getAuthors(); $authors2 = $this->filterAuthors( $authors2, $collection->code ); $authors = array_unique( array_merge( $authors, $authors2 ) ); foreach ( $authors as $author ) { $output .= "\t# Author: $author\n"; } return $output; }
/** * @param MessageCollection $collection * @return string */ protected function writeReal(MessageCollection $collection) { $output = ''; $authors = $collection->getAuthors(); $authors = $this->filterAuthors($authors, $collection->code); $output .= implode(self::RECORD_SEPARATOR, $authors); $output .= self::PART_SEPARATOR; $mangler = $this->group->getMangler(); /** @var TMessage $m */ foreach ($collection as $key => $m) { $key = $mangler->unmangle($key); $trans = $m->translation(); $output .= "{$key}={$trans}" . self::RECORD_SEPARATOR; } return $output; }
public function webExport( MessageCollection $collection ) { $code = $collection->code; // shorthand // Open temporary stream $handle = fopen( 'php://temp', 'wt' ); $this->addAuthors( $collection->getAuthors(), $code ); $this->exportLanguage( $handle, $collection ); // Fetch data rewind( $handle ); $data = stream_get_contents( $handle ); fclose( $handle ); return $data; }
protected function writeReal(MessageCollection $collection) { $output = ''; $mangler = $this->group->getMangler(); /** * @var $m ThinMessage */ foreach ($collection as $key => $m) { $value = $m->translation(); if ($value === null) { continue; } $comment = ''; if ($m->hasTag('fuzzy')) { $value = str_replace(TRANSLATE_FUZZY, '', $value); $comment = "; Fuzzy\n"; } $key = $mangler->unmangle($key); $output .= "{$comment}{$key} = {$value}\n"; } // Do not create empty files if ($output === '') { return ''; } global $wgSitename; // Accumulator $header = "; Exported from {$wgSitename}\n"; $authors = $collection->getAuthors(); $authors = $this->filterAuthors($authors, $collection->getLanguage()); foreach ($authors as $author) { $header .= "; Author: {$author}\n"; } $header .= '[' . $collection->getLanguage() . "]\n"; return $header . $output; }
/** * @param MessageCollection $collection * @return string */ protected function writeReal(MessageCollection $collection) { $messages = array(); $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 $collection MessageCollection * @return string */ public function writeReal(MessageCollection $collection) { $header = $this->header($collection->code, $collection->getAuthors()); $mangler = $this->group->getMangler(); /** * Get and write messages. */ $body = ''; /** * @var TMessage $message */ foreach ($collection as $message) { if (strlen($message->translation()) === 0) { continue; } $key = $mangler->unmangle($message->key()); $key = $this->transformKey(self::escapeJsString($key)); $translation = self::escapeJsString($message->translation()); $body .= "\t{$key}: \"{$translation}\",\n"; } if (strlen($body) === 0) { return false; } /** * Strip last comma, re-add trailing newlines. */ $body = substr($body, 0, -2); $body .= "\n"; return $header . $body . $this->footer(); }