if ($data->action == 1) { $worka->add_string($strtranslateda); $workb->add_string($strtranslatedb); } else { $worka->add_string($strtranslatedrecent); $workb->add_string($strtranslatedrecent); } $num++; } } } // if some strings were detected, stage them if ($worka->has_string()) { $stage->add($worka); } if ($workb->has_string()) { $stage->add($workb); } // clear all the components used $englisha->clear(); $englishb->clear(); $translateda->clear(); $translatedb->clear(); $worka->clear(); $workb->clear(); } // store the persistant stage $stage->store(); // if no new strings are merged, inform the user if (!$stage->has_component()) { $progressbar->update($total, $total, get_string('nodiffs', 'local_amos'));
public function test_intersect() { $master = new mlang_component('moodle', 'en', mlang_version::by_branch('MOODLE_18_STABLE')); $master->add_string(new mlang_string('one', 'One')); $master->add_string(new mlang_string('two', 'Two')); $master->add_string(new mlang_string('three', 'Three')); $slave = new mlang_component('moodle', 'cs', mlang_version::by_branch('MOODLE_18_STABLE')); $slave->add_string(new mlang_string('one', 'Jedna')); $slave->add_string(new mlang_string('two', 'Dva')); $slave->add_string(new mlang_string('seven', 'Sedm')); $slave->add_string(new mlang_string('eight', 'Osm')); $slave->intersect($master); $this->assertEqual(2, count($slave->get_string_keys())); $this->assertTrue($slave->has_string('one')); $this->assertTrue($slave->has_string('two')); }
fputs(STDOUT, "!= AMOS GIT DIFF: {$version->dir} [{$amosstring->id},{$frankenstylename}]\n"); $gitstring->clean_text(); $fixcomponent->add_string($gitstring); continue; } } foreach ($gitcomponent->get_iterator() as $gitstring) { $amosstring = $amoscomponent->get_string($gitstring->id); if (is_null($amosstring)) { fputs(STDOUT, ">> GIT ONLY: {$version->dir} [{$gitstring->id},{$frankenstylename}]\n"); $gitstring->clean_text(); $fixcomponent->add_string($gitstring); continue; } } if ($fixcomponent->has_string()) { $stage->add($fixcomponent); } $fixcomponent->clear(); $amoscomponent->clear(); $gitcomponent->clear(); } } if ($options['execute']) { $stage->commit('Fixing the drift between Git and AMOS repository', array('source' => 'fixdrift', 'userinfo' => 'AMOS-bot <*****@*****.**>')); } else { list($x, $y, $z) = mlang_stage::analyze($stage); if ($x > 0) { fputs(STDOUT, "There are {$x} string changes prepared for sync execution\n"); } }
/** * 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)); } } }