} // dump the given revision of the file to a temporary area $checkout = $commithash . '_' . str_replace('/', '_', $file); if (in_array($checkout, $MLANG_BROKEN_CHECKOUTS)) { fputs(STDERR, "BROKEN {$checkout}\n"); continue; } $checkout = $tmp . '/' . $checkout; exec(AMOS_PATH_GIT . " show {$commithash}:{$file} > {$checkout}"); // push the string on all branches where the English original is currently (or has ever been) defined // note that all English strings history must already be registered in AMOS repository // pushing into Moodle 1.x branches only to prevent conflicts with translations done via web foreach (array('MOODLE_19_STABLE') as $branch) { $version = mlang_version::by_branch($branch); // get the translated strings from PHP file - the lang repository in in 1.x format $component = mlang_component::from_phpfile($checkout, $langcode, $version, $timemodified, mlang_component::name_from_filename($file), 1); $encomponent = mlang_component::from_snapshot($component->name, 'en', $version, $timemodified); // keep just those defined in English on that branch - this is where we are reconstruct branching of lang packs. // langconfig.php is not compared with English because it may contain extra string like parentlanguage. if ($component->name !== 'langconfig') { $component->intersect($encomponent); } elseif ($version->code >= mlang_version::MOODLE_20) { if ($parentlanguage = $component->get_string('parentlanguage')) { if (substr($parentlanguage->text, -5) == '_utf8') { $parentlanguage->text = substr($parentlanguage->text, 0, -5); } } } $stage->add($component); $component->clear(); unset($component);
$string->timemodified = time(); } $stage->add($amoscomponent); continue; } // no string file and nothing in AMOS - that is correct continue; } if ($gitstatus != 0) { fputs(STDERR, "FATAL ERROR {$gitstatus} EXECUTING {$gitcmd}\n"); exit($gitstatus); } $tmp = make_upload_directory('amos/temp/fix-drift/' . $version->dir); $dumpfile = $tmp . '/' . $legacyname . '.php'; file_put_contents($dumpfile, implode("\n", $gitout)); $gitcomponent = mlang_component::from_phpfile($dumpfile, 'en', $version, time()); foreach ($amoscomponent->get_iterator() as $amosstring) { $gitstring = $gitcomponent->get_string($amosstring->id); if (is_null($gitstring)) { fputs(STDOUT, "<< AMOS ONLY: {$version->dir} [{$amosstring->id},{$frankenstylename}]\n"); $fixstring = clone $amosstring; $fixstring->deleted = true; $fixstring->clean_text(); $fixcomponent->add_string($fixstring); continue; } if ($gitstring->text !== $amosstring->text) { fputs(STDOUT, "!= AMOS GIT DIFF: {$version->dir} [{$amosstring->id},{$frankenstylename}]\n"); $gitstring->clean_text(); $fixcomponent->add_string($gitstring); continue;
if ($options['help'] or empty($options['message']) or empty($unrecognized)) { echo $usage . PHP_EOL; exit(1); } $filepath = $unrecognized[0]; if (!is_readable($filepath)) { echo 'File not readable' . PHP_EOL; echo $usage . PHP_EOL; exit(2); } $version = mlang_version::by_branch($options['version']); if (is_null($version)) { echo 'Invalid version' . PHP_EOL; exit(3); } $component = mlang_component::from_phpfile($filepath, $options['lang'], $version, $options['timemodified'], $options['name'], (int) $options['format']); fputs(STDOUT, "{$component->name} {$component->version->label} {$component->lang}" . PHP_EOL); $stage = new mlang_stage(); $stage->add($component); $stage->rebase(null, true, $options['timemodified']); if (!$stage->has_component()) { echo 'No strings found (after rebase)' . PHP_EOL; exit(4); } foreach ($stage->get_iterator() as $component) { foreach ($component->get_iterator() as $string) { if ($string->deleted) { $sign = '-'; } else { $sign = '+'; }
// dump the given revision of the file to a temporary area $checkout = $commithash . '_' . str_replace('/', '_', $file); if (in_array($checkout, $MLANG_BROKEN_CHECKOUTS)) { fputs(STDOUT, "BROKEN {$checkout}\n"); continue; } $checkout = $tmp . '/' . $checkout; exec(AMOS_PATH_GIT . " show {$commithash}:{$file} > {$checkout}"); // convert the php file into strings in the staging area if ($version->code >= mlang_version::MOODLE_20) { if ($committime >= 1270908105) { // since David's commit 30c8dd34f70437b15bd7960eb056d8de0c5e0375 // on 10th April 2010, strings are in the new format $checkoutformat = 2; } else { $checkoutformat = 1; } } else { $checkoutformat = 1; } $component = mlang_component::from_phpfile($checkout, 'en', $version, $timemodified, $componentname, $checkoutformat); $stage->add($component); $component->clear(); unset($component); unlink($checkout); } // we just parsed the last git commit at this branch - let us commit what we have amos_parse_core_commit(); } fputs(STDOUT, date('Y-m-d H:i', time())); fputs(STDOUT, " PARSE CORE JOB DONE\n");
public function test_component_from_phpfile_legacy_format() { $filecontents = <<<EOF <?php \$string['about'] = 'Multiline string'; \$string['pluginname'] = 'AMOS'; \$string['author'] = 'David Mudrak'; \$string['syntax'] = 'What \$a\\'Pe%%\\"be'; \$string['percents'] = '%%Y-%%m-%%d-%%H-%%M'; EOF; $tmp = make_upload_directory('temp/amos'); $filepath = $tmp . '/mlangunittest.php'; file_put_contents($filepath, $filecontents); $component = mlang_component::from_phpfile($filepath, 'en', mlang_version::by_branch('MOODLE_20_STABLE'), null, null, 1); $this->assertTrue($component->has_string('about')); $this->assertTrue($component->has_string('pluginname')); $this->assertTrue($component->has_string('author')); $this->assertTrue($component->has_string('syntax')); $this->assertEqual("Multiline\nstring", $component->get_string('about')->text); $this->assertEqual('What {$a}\'Pe%"be', $component->get_string('syntax')->text); $this->assertEqual('%Y-%m-%d-%H-%M', $component->get_string('percents')->text); $component->clear(); $component = mlang_component::from_phpfile($filepath, 'en', mlang_version::by_branch('MOODLE_20_STABLE')); $this->assertTrue($component->has_string('about')); $this->assertTrue($component->has_string('pluginname')); $this->assertTrue($component->has_string('author')); $this->assertTrue($component->has_string('syntax')); $this->assertEqual("Multiline\nstring", $component->get_string('about')->text); $this->assertEqual('What $a\'Pe%%"be', $component->get_string('syntax')->text); $this->assertEqual('%%Y-%%m-%%d-%%H-%%M', $component->get_string('percents')->text); $component->clear(); $component = mlang_component::from_phpfile($filepath, 'en', mlang_version::by_branch('MOODLE_19_STABLE')); $this->assertTrue($component->has_string('about')); $this->assertTrue($component->has_string('pluginname')); $this->assertTrue($component->has_string('author')); $this->assertTrue($component->has_string('syntax')); $this->assertEqual("Multiline\nstring", $component->get_string('about')->text); $this->assertEqual('What $a\'Pe%%\\"be', $component->get_string('syntax')->text); $this->assertEqual('%%Y-%%m-%%d-%%H-%%M', $component->get_string('percents')->text); $component->clear(); unlink($filepath); }