Index: trunk/extensions/Translate/MessageGroups.php |
— | — | @@ -845,17 +845,18 @@ |
846 | 846 | |
847 | 847 | foreach ( $wgTranslateGroupFiles as $file ) { |
848 | 848 | wfDebug( $file . "\n" ); |
849 | | - $conf = TranslateSpyc::load( $file ); |
| 849 | + $fgroups = TranslateSpyc::parseGroupFile( $file ); |
850 | 850 | |
851 | | - if ( !empty( $conf['AUTOLOAD'] ) && is_array( $conf['AUTOLOAD'] ) ) { |
852 | | - $dir = dirname( $file ); |
853 | | - foreach ( $conf['AUTOLOAD'] as $class => $file ) { |
854 | | - $wgAutoloadClasses[$class] = "$dir/$file"; |
| 851 | + foreach( $fgroups as $id => $conf ) { |
| 852 | + if ( !empty( $conf['AUTOLOAD'] ) && is_array( $conf['AUTOLOAD'] ) ) { |
| 853 | + $dir = dirname( $file ); |
| 854 | + foreach ( $conf['AUTOLOAD'] as $class => $file ) { |
| 855 | + $wgAutoloadClasses[$class] = "$dir/$file"; |
| 856 | + } |
855 | 857 | } |
| 858 | + $group = MessageGroupBase::factory( $conf ); |
| 859 | + $wgTranslateCC[$id] = $group; |
856 | 860 | } |
857 | | - |
858 | | - $group = MessageGroupBase::factory( $conf ); |
859 | | - $wgTranslateCC[$group->getId()] = $group; |
860 | 861 | } |
861 | 862 | |
862 | 863 | $loaded = true; |
Index: trunk/extensions/Translate/utils/TranslateYaml.php |
— | — | @@ -1,6 +1,50 @@ |
2 | 2 | <?php |
3 | 3 | |
| 4 | +/** |
| 5 | + * This class is a wrapper class to provide interface to parse |
| 6 | + * and generate YAML files with syck or spyc backend. |
| 7 | + */ |
4 | 8 | class TranslateYaml { |
| 9 | + public static function parseGroupFile( $filename ) { |
| 10 | + $data = file_get_contents( $filename ); |
| 11 | + $documents = preg_split( "/^---$/m", $data, -1, PREG_SPLIT_NO_EMPTY ); |
| 12 | + $groups = array(); |
| 13 | + $template = false; |
| 14 | + foreach ( $documents as $document ) { |
| 15 | + $document = self::loadString( $document ); |
| 16 | + if ( isset( $document['TEMPLATE'] ) ) { |
| 17 | + $template = $document['TEMPLATE']; |
| 18 | + } else { |
| 19 | + if ( !isset($document['BASIC']['id']) ) { |
| 20 | + trigger_error( "No path ./BASIC/id (group id not defined) in yaml document located in $filename" ); |
| 21 | + continue; |
| 22 | + } |
| 23 | + $groups[$document['BASIC']['id']] = $document; |
| 24 | + } |
| 25 | + } |
| 26 | + |
| 27 | + foreach ( $groups as $i => $group ) { |
| 28 | + $groups[$i] = self::mergeTemplate( $template, $group ); |
| 29 | + } |
| 30 | + |
| 31 | + return $groups; |
| 32 | + } |
| 33 | + |
| 34 | + /** |
| 35 | + * Merges a document template (base) to actual definition (specific) |
| 36 | + */ |
| 37 | + public static function mergeTemplate( $base, $specific ) { |
| 38 | + foreach ( $specific as $key => $value ) { |
| 39 | + if ( is_array( $value ) && isset( $base[$key] ) && is_array( $base[$key] ) ) { |
| 40 | + $base[$key] = self::mergeTemplate( $base[$key], $value ); |
| 41 | + } else { |
| 42 | + $base[$key] = $value; |
| 43 | + } |
| 44 | + } |
| 45 | + return $base; |
| 46 | + } |
| 47 | + |
| 48 | + |
5 | 49 | public static function loadString( $text ) { |
6 | 50 | global $wgTranslateYamlLibrary; |
7 | 51 | |