21 parent::__construct( $group );
26 return [
'.yaml',
'.yml' ];
36 preg_match_all(
'/^#\s*Author:\s*(.*)$/m', $data, $matches );
37 $authors = $matches[1];
40 $messages = TranslateYaml::loadString( $data ) ?? [];
43 if ( isset( $this->extra[
'codeAsRoot'] ) ) {
44 $messages = array_shift( $messages ) ?? [];
47 $messages = $this->
flatten( $messages );
48 $messages = $this->group->getMangler()->mangleArray( $messages );
49 foreach ( $messages as &$value ) {
50 $value = rtrim( $value,
"\n" );
54 'AUTHORS' => $authors,
55 'MESSAGES' => $messages,
64 $output = $this->
doHeader( $collection );
65 $output .= $this->
doAuthors( $collection );
67 $mangler = $this->group->getMangler();
72 foreach ( $collection as $key => $m ) {
73 $key = $mangler->unmangle( $key );
74 $value = $m->translation();
75 $value = str_replace( TRANSLATE_FUZZY,
'', $value );
77 if ( $value ===
'' ) {
81 $messages[$key] = $value;
84 if ( !count( $messages ) ) {
88 $messages = $this->
unflatten( $messages );
91 if ( isset( $this->extra[
'codeAsRoot'] ) ) {
92 $code = $this->group->mapCode( $collection->code );
93 $messages = [ $code => $messages ];
96 $output .= TranslateYaml::dump( $messages );
107 global $wgTranslateYamlLibrary;
109 $code = $collection->code;
110 $name = Utilities::getLanguageName( $code );
111 $native = Utilities::getLanguageName( $code, $code );
112 $output =
"# Messages for $name ($native)\n";
113 $output .=
"# Exported from $wgSitename\n";
115 if ( isset( $wgTranslateYamlLibrary ) ) {
116 $output .=
"# Export driver: $wgTranslateYamlLibrary\n";
129 $authors = $this->
filterAuthors( $authors, $collection->code );
131 foreach ( $authors as $author ) {
132 $output .=
"# Author: $author\n";
145 $nestingSeparator = $this->extra[
'nestingSeparator'] ??
'.';
146 $parseCLDRPlurals = $this->extra[
'parseCLDRPlurals'] ??
false;
149 return new ArrayFlattener( $nestingSeparator, $parseCLDRPlurals );
161 return $this->flattener->flatten( $messages );
173 return $this->flattener->unflatten( $messages );
177 return $this->flattener->compareContent( $a, $b );
189 '_type' =>
'boolean',
191 'nestingSeparator' => [
194 'parseCLDRPlurals' => [
195 '_type' =>
'boolean',
This class implements default behavior for file based message groups.
filterAuthors(array $authors, $code)
Remove excluded authors.
Implements support for message storage in YAML format.
doAuthors(MessageCollection $collection)
__construct(FileBasedMessageGroup $group)
writeReal(MessageCollection $collection)
getFlattener()
Obtains object used to flatten and unflatten arrays.
isContentEqual( $a, $b)
Checks whether two strings are equal.
doHeader(MessageCollection $collection)
getFileExtensions()
Return the commonly used file extensions for these formats.
flatten( $messages)
Flattens multidimensional array by using the path to the value as key with each individual key separa...
unflatten( $messages)
Performs the reverse operation of flatten.
static getExtraSchema()
Return a data structure that will be merged with the base schema.