22 return [
'.properties' ];
25 protected $keySeparator =
'=';
29 parent::__construct( $group );
31 if ( isset( $this->extra[
'keySeparator'] ) ) {
32 $this->keySeparator = $this->extra[
'keySeparator'];
42 $data = TextContent::normalizeLineEndings( $data );
43 $lines = array_map(
'ltrim', explode(
"\n", $data ) );
44 $authors = $messages = [];
45 $linecontinuation =
false;
49 foreach ( $lines as $line ) {
50 if ( $linecontinuation ) {
51 $linecontinuation =
false;
53 $valuecont = str_replace(
'\n',
"\n", $valuecont );
60 if ( $line[0] ===
'#' || $line[0] ===
'!' ) {
62 $ok = preg_match(
'/#\s*Author:\s*(.*)/', $line, $match );
65 $authors[] = $match[1];
71 if ( strpos( $line, $this->keySeparator ) ===
false ) {
72 throw new MWException(
"Line without separator '{$this->keySeparator}': $line." );
75 list( $key, $value ) =
self::readRow( $line, $this->keySeparator );
77 throw new MWException(
"Empty key in line $line." );
83 $value = substr( $value, 0, strlen( $value ) - 1 );
84 $linecontinuation =
true;
86 $messages[$key] = ltrim( $value );
90 $messages = $this->group->getMangler()->mangleArray( $messages );
93 'AUTHORS' => $authors,
94 'MESSAGES' => $messages,
103 $header = $this->doHeader( $collection );
104 $header .= $this->doAuthors( $collection );
108 $mangler = $this->group->getMangler();
111 foreach ( $collection as $key => $m ) {
112 $value = $m->translation();
113 $value = str_replace( TRANSLATE_FUZZY,
'', $value );
115 if ( $value ===
'' ) {
120 if ( $m->hasTag(
'fuzzy' ) ) {
121 $output .=
"# Fuzzy\n";
124 $key = $mangler->unmangle( $key );
125 $output .= self::writeRow( $key, $this->keySeparator, $value );
129 return $header . $output;
143 public static function writeRow( $key, $sep, $value ) {
147 $key = addcslashes( $key,
"#!$sep\\" );
149 $value = str_replace(
"\n",
'\\n', $value );
151 return "$key$sep$value\n";
161 public static function readRow( $line, $sep ) {
162 if ( strpos( $line,
'\\' ) ===
false ) {
165 list( $key, $value ) = explode( $sep, $line, 2 );
186 $len = strlen( $line );
188 for ( $i = 0; $i < $len; $i++ ) {
190 if ( $char ===
'\\' ) {
191 $escaped = !$escaped;
192 } elseif ( $escaped ) {
194 } elseif ( $char === $sep ) {
195 $key = substr( $line, 0, $i );
197 $value = substr( $line, $i + 1 );
207 $key = stripcslashes( $key );
208 $value = ltrim( $value );
209 $value = str_replace(
'\n',
"\n", $value );
211 return [ $key, $value ];
219 if ( isset( $this->extra[
'header'] ) ) {
220 $output = $this->extra[
'header'];
224 $code = $collection->code;
225 $name = Utilities::getLanguageName( $code );
226 $native = Utilities::getLanguageName( $code, $code );
227 $output =
"# Messages for $name ($native)\n";
228 $output .=
"# Exported from $wgSitename\n";
241 $authors = $this->filterAuthors( $authors, $collection->code );
243 foreach ( $authors as $author ) {
244 $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)