/** * Excercise various helper methods */ public function test_helpers() { $this->assertEqual('workshop', mlang_component::name_from_filename('/web/moodle/mod/workshop/lang/en/workshop.php')); $this->assertFalse(mlang_string::differ(new mlang_string('first', 'This is a test string'), new mlang_string('second', 'This is a test string'))); $this->assertFalse(mlang_string::differ(new mlang_string('first', ' This is a test string '), new mlang_string('second', 'This is a test string '))); $this->assertTrue(mlang_string::differ(new mlang_string('first', 'This is a test string'), new mlang_string('first', 'This is a test string!'))); $this->assertTrue(mlang_string::differ(new mlang_string('empty', ''), new mlang_string('null', null))); $this->assertFalse(mlang_string::differ(new mlang_string('null', null), new mlang_string('anothernull', null))); }
} // 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);
require_capability('local/amos:importfile', get_system_context()); $PAGE->set_pagelayout('standard'); $PAGE->set_url('/local/amos/importfile.php'); navigation_node::override_active_url(new moodle_url('/local/amos/stage.php')); $PAGE->set_title('AMOS ' . get_string('importfile', 'local_amos')); $PAGE->set_heading('AMOS ' . get_string('importfile', 'local_amos')); $importform = new local_amos_importfile_form(null, local_amos_importfile_options()); if ($data = $importform->get_data() and has_capability('local/amos:stage', get_system_context())) { $tmpdir = $CFG->dataroot . '/amos/temp/import-uploads/' . $USER->id; check_dir_exists($tmpdir); $filenameorig = basename($importform->get_new_filename('importfile')); $filename = $filenameorig . '-' . md5(time() . '-' . $USER->id . '-' . random_string(20)); $pathname = $tmpdir . '/' . $filename; if ($importform->save_file('importfile', $pathname)) { if (substr($filenameorig, -4) === '.php') { $name = mlang_component::name_from_filename($filenameorig); $version = mlang_version::by_code($data->version); $component = new mlang_component($name, $data->language, $version); $parser = mlang_parser_factory::get_parser('php'); try { $parser->parse(file_get_contents($pathname), $component); } catch (mlang_parser_exception $e) { notice($e->getMessage(), new moodle_url('/local/amos/stage.php')); } $encomponent = mlang_component::from_snapshot($component->name, 'en', $version); $component->intersect($encomponent); if (!$component->has_string()) { notice(get_string('nostringtoimport', 'local_amos'), new moodle_url('/local/amos/stage.php')); } $stage = mlang_persistent_stage::instance_for_user($USER->id, sesskey()); $stage->add($component, true);
// the original git commit's timestamp $timemodified = time(); // when the commit was processed by AMOS $affected = array(); // explicit list of strings affected by the commit continue; } if (in_array($commithash, $MLANG_IGNORE_COMMITS)) { fputs(STDOUT, "IGNORED {$commithash}\n"); continue; } $parts = explode("\t", $line); $changetype = substr($parts[0], -1); // A (added new file), M (modified), D (deleted) $file = $parts[1]; $componentname = mlang_component::name_from_filename($file); // series of checks that the file is proper language pack if ($version->code >= mlang_version::MOODLE_20 and $committime >= 1270884296) { // since Petr's commit 3a915b066765efc3cc166ae8186405f67c04ec2c // on 10th April 2010, strings are in 'en' folder again $enfolder = 'en'; } else { $enfolder = 'en_utf8'; } if (!strstr($file, "lang/{$enfolder}/")) { // this is not a language file continue; } if (strstr($file, "lang/{$enfolder}/docs/") or strstr($file, "lang/{$enfolder}/help/")) { // ignore continue;