/**
  * @param $data
  * @return array Parsed data.
  */
 public function readFromVariable($data)
 {
     // Authors first.
     $matches = array();
     preg_match_all('/^#\\s*Author:\\s*(.*)$/m', $data, $matches);
     $authors = $matches[1];
     // Then messages.
     $messages = TranslateYaml::loadString($data);
     // Some groups have messages under language code
     if (isset($this->extra['codeAsRoot'])) {
         $messages = array_shift($messages);
     }
     $messages = $this->flatten($messages);
     $messages = $this->group->getMangler()->mangle($messages);
     foreach ($messages as &$value) {
         $value = rtrim($value, "\n");
     }
     return array('AUTHORS' => $authors, 'MESSAGES' => $messages);
 }
 /**
  * Returns group configurations from YAML documents. If there is document containing template,
  * it will be merged with other configurations.
  *
  * @param string $data
  * @return array Unvalidated group configurations
  */
 public function parseDocuments(array $documents)
 {
     $groups = array();
     $template = false;
     foreach ($documents as $document) {
         $document = TranslateYaml::loadString($document);
         if (isset($document['TEMPLATE'])) {
             $template = $document['TEMPLATE'];
         } else {
             $groups[] = $document;
         }
     }
     if ($template) {
         foreach ($groups as $i => $group) {
             $groups[$i] = self::mergeTemplate($template, $group);
             // Little hack to allow aggregate groups to be defined in same file with other groups.
             if ($groups[$i]['BASIC']['class'] === 'AggregateMessageGroup') {
                 unset($groups[$i]['FILES']);
             }
         }
     }
     return $groups;
 }
 public static function parseGroupFile($filename)
 {
     $data = file_get_contents($filename);
     $documents = preg_split("/^---\$/m", $data, -1, PREG_SPLIT_NO_EMPTY);
     $groups = array();
     $template = false;
     foreach ($documents as $document) {
         $document = TranslateYaml::loadString($document);
         if (isset($document['TEMPLATE'])) {
             $template = $document['TEMPLATE'];
         } else {
             if (!isset($document['BASIC']['id'])) {
                 trigger_error("No path ./BASIC/id (group id not defined) " . "in yaml document located in {$filename}");
                 continue;
             }
             $groups[$document['BASIC']['id']] = $document;
         }
     }
     foreach ($groups as $i => $group) {
         $groups[$i] = TranslateYaml::mergeTemplate($template, $group);
     }
     return $groups;
 }