20 return [
'.strings' ];
29 $lines = explode(
"\n", $data );
30 $authors = $messages = [];
31 $linecontinuation =
false;
34 foreach ( $lines as $line ) {
35 $line = trim( $line );
36 if ( $linecontinuation ) {
37 if ( strpos( $line,
'*/' ) !==
false ) {
38 $linecontinuation =
false;
45 if ( substr( $line, 0, 2 ) ===
'//' ) {
48 $ok = preg_match(
'~//\s*Author:\s*(.*)~', $line, $match );
50 $authors[] = $match[1];
55 if ( substr( $line, 0, 2 ) ===
'/*' ) {
56 if ( strpos( $line,
'*/', 2 ) ===
false ) {
57 $linecontinuation =
true;
62 list( $key, $value ) = static::readRow( $line );
63 $messages[$key] = $value;
67 $messages = $this->group->getMangler()->mangleArray( $messages );
70 'AUTHORS' => $authors,
71 'MESSAGES' => $messages,
84 if ( preg_match(
'/^"((?:\\\"|[^"])*)"\s*=\s*"((?:\\\"|[^"])*)"\s*;\s*$/', $line, $match ) ) {
88 throw new MWException(
"Empty key in line $line" );
90 return [ $key, $value ];
92 throw new MWException(
"Unrecognized line format: $line" );
101 $header = $this->
doHeader( $collection );
102 $header .= $this->
doAuthors( $collection );
106 $mangler = $this->group->getMangler();
109 foreach ( $collection as $key => $m ) {
110 $value = $m->translation();
111 $value = str_replace( TRANSLATE_FUZZY,
'', $value );
113 if ( $value ===
'' ) {
118 if ( $m->hasTag(
'fuzzy' ) ) {
119 $output .=
"// Fuzzy\n";
122 $key = $mangler->unmangle( $key );
123 $output .= static::writeRow( $key, $value );
127 $data = $header . $output;
163 $str = addcslashes( $str,
'\\"' );
164 $str = str_replace(
"\n",
'\\n', $str );
177 return stripcslashes( $str );
185 if ( isset( $this->extra[
'header'] ) ) {
186 $output = $this->extra[
'header'];
190 $code = $collection->code;
191 $name = TranslateUtils::getLanguageName( $code );
192 $native = TranslateUtils::getLanguageName( $code, $code );
193 $output =
"// Messages for $name ($native)\n";
195 $output .=
"// Exported from $wgSitename\n";
208 $authors = $this->
filterAuthors( $authors, $collection->code );
210 foreach ( $authors as $author ) {
211 $output .=
"// Author: $author\n";
217 public static function getExtraSchema() {
AppleFFS class implements support for Apple .strings files.
static readRow( $line)
Parses non-empty strings file row to key and value.
doAuthors(MessageCollection $collection)
writeReal(MessageCollection $collection)
static writeRow( $key, $value)
Writes well-formed properties file row with key and value.
static escapeString( $str)
Escape Obj-C-style strings; use backslash-escapes etc.
static unescapeString( $str)
Unescape Obj-C-style strings; can include backslash-escapes.
supportsFuzzy()
Query the capabilities of this FFS.
static quoteString( $str)
Quote and escape Obj-C-style strings for .strings format.
getFileExtensions()
Return the commonly used file extensions for these formats.
doHeader(MessageCollection $collection)
Core message collection class.
getAuthors()
Lists all translators that have contributed to the latest revisions of each translation.
filterAuthors(array $authors, $code)
Remove excluded authors.