r67634 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r67633‎ | r67634 | r67635 >
Date:16:33, 8 June 2010
Author:nikerabbit
Status:ok
Tags:
Comment:
Code support for r67625 (template and multiple group definitions per file)
Modified paths:
  • /trunk/extensions/Translate/MessageGroups.php (modified) (history)
  • /trunk/extensions/Translate/utils/TranslateYaml.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/MessageGroups.php
@@ -845,17 +845,18 @@
846846
847847 foreach ( $wgTranslateGroupFiles as $file ) {
848848 wfDebug( $file . "\n" );
849 - $conf = TranslateSpyc::load( $file );
 849+ $fgroups = TranslateSpyc::parseGroupFile( $file );
850850
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+ }
855857 }
 858+ $group = MessageGroupBase::factory( $conf );
 859+ $wgTranslateCC[$id] = $group;
856860 }
857 -
858 - $group = MessageGroupBase::factory( $conf );
859 - $wgTranslateCC[$group->getId()] = $group;
860861 }
861862
862863 $loaded = true;
Index: trunk/extensions/Translate/utils/TranslateYaml.php
@@ -1,6 +1,50 @@
22 <?php
33
 4+/**
 5+ * This class is a wrapper class to provide interface to parse
 6+ * and generate YAML files with syck or spyc backend.
 7+ */
48 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+
549 public static function loadString( $text ) {
650 global $wgTranslateYamlLibrary;
751

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r67625One file alternative up for discussionnikerabbit15:01, 8 June 2010

Status & tagging log