Example #1
0
 /**
  * Merges all strings from one component to another and fixes syntax if needed
  *
  * If the string already exists in the target component, it is skipped (even
  * if it is set as deleted there). Does not modify the source component.
  *
  * @param mlang_component $source component to take strings from
  * @param mlang_component $target component to add strings to
  * @return void modifies $target component
  */
 public static function merge(mlang_component $source, mlang_component $target)
 {
     if ($source->version->code <= mlang_version::MOODLE_19) {
         $sourceformat = 1;
     } else {
         $sourceformat = 2;
     }
     if ($target->version->code <= mlang_version::MOODLE_19) {
         throw new mlang_exception('Can not merge into Moodle 1.x branches');
     } else {
         $targetformat = 2;
     }
     foreach ($source->get_iterator() as $string) {
         $stringid = clean_param($string->id, PARAM_STRINGID);
         if (empty($stringid)) {
             throw new mlang_exception('Invalid string identifier ' . s($string->id));
         }
         if (!$target->has_string($stringid)) {
             $text = mlang_string::fix_syntax($string->text, $targetformat, $sourceformat);
             $target->add_string(new mlang_string($stringid, $text));
         }
     }
 }