18 return [
'.properties' ];
21 protected $keySeparator =
'=';
25 parent::__construct( $group );
27 if ( isset( $this->extra[
'keySeparator'] ) ) {
28 $this->keySeparator = $this->extra[
'keySeparator'];
39 $lines = array_map(
'ltrim', explode(
"\n", $data ) );
40 $authors = $messages = [];
41 $linecontinuation =
false;
45 foreach ( $lines as $line ) {
46 if ( $linecontinuation ) {
47 $linecontinuation =
false;
49 $valuecont = str_replace(
'\n',
"\n", $valuecont );
56 if ( $line[0] ===
'#' || $line[0] ===
'!' ) {
58 $ok = preg_match(
'/#\s*Author:\s*(.*)/', $line, $match );
61 $authors[] = $match[1];
67 if ( strpos( $line, $this->keySeparator ) ===
false ) {
68 throw new MWException(
"Line without separator '{$this->keySeparator}': $line." );
71 list( $key, $value ) =
self::readRow( $line, $this->keySeparator );
73 throw new MWException(
"Empty key in line $line." );
79 $value = substr( $value, 0, strlen( $value ) - 1 );
80 $linecontinuation =
true;
82 $messages[$key] = ltrim( $value );
86 $messages = $this->group->getMangler()->mangleArray( $messages );
89 'AUTHORS' => $authors,
90 'MESSAGES' => $messages,
99 $header = $this->doHeader( $collection );
100 $header .= $this->doAuthors( $collection );
104 $mangler = $this->group->getMangler();
107 foreach ( $collection as $key => $m ) {
108 $value = $m->translation();
109 $value = str_replace( TRANSLATE_FUZZY,
'', $value );
111 if ( $value ===
'' ) {
116 if ( $m->hasTag(
'fuzzy' ) ) {
117 $output .=
"# Fuzzy\n";
120 $key = $mangler->unmangle( $key );
121 $output .= self::writeRow( $key, $this->keySeparator, $value );
125 return $header . $output;
139 public static function writeRow( $key, $sep, $value ) {
143 $key = addcslashes( $key,
"#!$sep\\" );
145 $value = str_replace(
"\n",
'\\n', $value );
147 return "$key$sep$value\n";
157 public static function readRow( $line, $sep ) {
158 if ( strpos( $line,
'\\' ) ===
false ) {
161 list( $key, $value ) = explode( $sep, $line, 2 );
182 $len = strlen( $line );
184 for ( $i = 0; $i < $len; $i++ ) {
186 if ( $char ===
'\\' ) {
187 $escaped = !$escaped;
188 } elseif ( $escaped ) {
190 } elseif ( $char === $sep ) {
191 $key = substr( $line, 0, $i );
193 $value = substr( $line, $i + 1 );
203 $key = stripcslashes( $key );
204 $value = ltrim( $value );
205 $value = str_replace(
'\n',
"\n", $value );
207 return [ $key, $value ];
215 if ( isset( $this->extra[
'header'] ) ) {
216 $output = $this->extra[
'header'];
220 $code = $collection->code;
221 $name = TranslateUtils::getLanguageName( $code );
222 $native = TranslateUtils::getLanguageName( $code, $code );
223 $output =
"# Messages for $name ($native)\n";
225 $output .=
"# Exported from $wgSitename\n";
238 $authors = $this->filterAuthors( $authors, $collection->code );
240 foreach ( $authors as $author ) {
241 $output .=
"# Author: $author\n";
This class implements default behavior for file based message groups.
JavaFFS class implements support for Java properties files.
__construct(FileBasedMessageGroup $group)
writeReal(MessageCollection $collection)
supportsFuzzy()
Query the capabilities of this FFS.
static writeRow( $key, $sep, $value)
Writes well-formed properties file row with key and value.
doAuthors(MessageCollection $collection)
static readRow( $line, $sep)
Parses non-empty properties file row to key and value.
getFileExtensions()
Return the commonly used file extensions for these formats.
static getExtraSchema()
Return a data structure that will be merged with the base schema.
doHeader(MessageCollection $collection)
Core message collection class.
getAuthors()
Lists all translators that have contributed to the latest revisions of each translation.
static fixNewLines( $data)
Replaces all Windows and Mac line endings with Unix line endings.