/** * Checks the decsep and thousandssep config strings are set correctly * * @link http://tracker.moodle.org/browse/MDL-31332 * @return bool check success flag */ protected function check_decsep_thousandssep() { $details = array(); $langnames = array(); $tree = mlang_tools::components_tree(array('component' => 'langconfig')); foreach ($tree as $branch => $languages) { $version = mlang_version::by_code($branch); foreach (array_keys($languages) as $language) { $langconfig = mlang_component::from_snapshot('langconfig', $language, $version); if ($langname = $langconfig->get_string('thislanguageint')) { $langnames[$language] = $langname->text; } else { $langnames[$language] = $language; } if ($decsep = $langconfig->get_string('decsep')) { $decsep = $decsep->text; } if ($thousandssep = $langconfig->get_string('thousandssep')) { $thousandssep = $thousandssep->text; } if (empty($decsep) and empty($thousandssep)) { $details[$language][$version->label] = 1; } else { if (empty($decsep) or empty($thousandssep)) { $details[$language][$version->label] = 2; } else { if ($decsep === $thousandssep) { $details[$language][$version->label] = 3; } } } } } ksort($details); foreach ($details as $language => $branches) { $msg = sprintf('Invalid decsep and/or thousandssep in %s {%s} at', $langnames[$language], $language); foreach ($branches as $branch => $severity) { $msg .= ' ' . $branch . str_repeat('!', $severity); } $this->output($msg, true); } if (empty($details)) { return 0; } return 1; }
* needed during the very first steps of installation. This file was * generated automatically by export-installer.php (which is part of AMOS * {@link http://docs.moodle.org/dev/Languages/AMOS}) using the * list of strings defined in /install/stringnames.txt. * * @package installer * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ EOF; $status = 0; // exit status, 0 means no problems foreach ($list as $componentname => $stringids) { foreach ($langs as $lang) { $component = mlang_component::from_snapshot($componentname, $lang, $version, null, false, false, array_keys($stringids)); if ($component->has_string()) { $file = AMOS_EXPORT_INSTALLER_DIR . '/' . $version->dir . '/install/lang/' . $lang . '/' . $component->name . '.php'; if (!file_exists(dirname($file))) { mkdir(dirname($file), 0755, true); } $component->export_phpfile($file, $phpdoc); } if ($lang == 'en') { // check that all string were exported foreach (array_keys($stringids) as $stringid) { if (!$component->has_string($stringid)) { fputs(STDERR, "ERROR Unknown {$stringid},{$componentname}\n"); $status = 1; } }
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); $stage->store(); mlang_stash::autosave($stage); } else { notice(get_string('nostringtoimport', 'local_amos'), new moodle_url('/local/amos/stage.php')); } } else { notice(get_string('nofiletoimport', 'local_amos'), new moodle_url('/local/amos/stage.php')); } }
$sourceversion = mlang_version::by_code($data->sourceversion); $targetversion = mlang_version::by_code($data->targetversion); if (is_null($sourceversion) or is_null($targetversion)) { notice('Invalid version selected', new moodle_url('/local/amos/stage.php')); } $tree = mlang_tools::components_tree(array('branch' => $sourceversion->code, 'lang' => $data->language)); $sourcecomponentnames = array_keys(reset(reset($tree))); unset($tree); foreach ($sourcecomponentnames as $sourcecomponentname) { // get a snapshot of both components and merge source into target $sourcecomponent = mlang_component::from_snapshot($sourcecomponentname, $data->language, $sourceversion); $targetcomponent = mlang_component::from_snapshot($sourcecomponent->name, $sourcecomponent->lang, $targetversion); mlang_tools::merge($sourcecomponent, $targetcomponent); $sourcecomponent->clear(); // keep just strings that are defined in english $englishcomponent = mlang_component::from_snapshot($sourcecomponent->name, 'en', $targetversion); $targetcomponent->intersect($englishcomponent); $englishcomponent->clear(); // stage the target $stage->add($targetcomponent); $targetcomponent->clear(); } // prune the stage so that only committable strings are staged $allowed = mlang_tools::list_allowed_languages($USER->id); $stage->prune($allowed); // keep just really modified (that is new in this case) strings $stage->rebase(); // and store the persistant stage $stage->store(); // if no new strings are merged, inform the user if (!$stage->has_component()) {
// prints the HTML code of the progress bar // we may need a bit of extra execution time and memory here @set_time_limit(HOURSECS); raise_memory_limit(MEMORY_EXTRA); // number of differences $num = 0; foreach ($componentnames as $i => $componentname) { $progressbar->update($i, $total, get_string('diffprogress', 'local_amos')); // the most recent snapshots $englisha = mlang_component::from_snapshot($componentname, 'en', $versiona); $englishb = mlang_component::from_snapshot($componentname, 'en', $versionb); $translateda = mlang_component::from_snapshot($componentname, $data->language, $versiona); $translatedb = mlang_component::from_snapshot($componentname, $data->language, $versionb); // working components that holds the strings to be staged $worka = new mlang_component($componentname, $data->language, $versiona); $workb = new mlang_component($componentname, $data->language, $versionb); foreach ($englisha->get_iterator() as $strenglisha) { $strenglishb = $englishb->get_string($strenglisha->id); $strtranslateda = $translateda->get_string($strenglisha->id); $strtranslatedb = $translatedb->get_string($strenglisha->id); // nothing compares to you, my dear null string if (is_null($strenglishb) or is_null($strtranslateda) or is_null($strtranslatedb)) { continue; } // in case we will need it, decide which of the translations is the more recent if ($strtranslateda->timemodified >= $strtranslatedb->timemodified) { $strtranslatedrecent = $strtranslateda; } else { $strtranslatedrecent = $strtranslatedb; } $englishchanged = mlang_string::differ($strenglisha, $strenglishb);
$mem = memory_get_usage(); $memdiff = $memprev < $mem ? '+' : '-'; $memdiff = $memdiff . abs($mem - $memprev); $english = mlang_component::from_snapshot($componentname, 'en', $version, null, true, true); foreach ($english->get_iterator() as $string) { if (empty($options['full']) and $string->timemodified < time() - DAYSECS) { continue; } if ($string->deleted) { // propagate removal of this string to all other languages where it is present $stage = new mlang_stage(); foreach (array_keys($tree[$vercode]) as $otherlang) { if ($otherlang == 'en') { continue; } $other = mlang_component::from_snapshot($componentname, $otherlang, $version, null, true, false, array($string->id)); if ($other->has_string($string->id)) { $current = $other->get_string($string->id); if (!$current->deleted) { $current->deleted = true; $current->timemodified = time(); $stage->add($other); } } $other->clear(); unset($other); } $stage->rebase(); if ($stage->has_component()) { $string->timemodified = local_amos_renderer::commit_datetime($string->timemodified); $msg = <<<EOF
// 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");
* Register new language * * @package local-amos * @copyright 2010 David Mudrak <*****@*****.**> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ require_once dirname(dirname(dirname(dirname(__FILE__)))) . '/config.php'; require_once dirname(dirname(__FILE__)) . '/mlanglib.php'; require_once dirname(__FILE__) . '/newlanguage_form.php'; require_login(SITEID, false); require_capability('local/amos:manage', get_system_context()); $PAGE->set_pagelayout('standard'); $PAGE->set_url('/local/amos/admin/newlanguage.php'); $PAGE->set_title('AMOS ' . get_string('newlanguage', 'local_amos')); $PAGE->set_heading('AMOS ' . get_string('newlanguage', 'local_amos')); $form = new local_amos_newlanguage_form(); if ($data = $form->get_data()) { $component = new mlang_component('langconfig', $data->langcode, mlang_version::by_code(mlang_version::MOODLE_22)); $data->langname = mlang_string::fix_syntax($data->langname); $data->langnameint = mlang_string::fix_syntax($data->langnameint); $component->add_string(new mlang_string('thislanguage', $data->langname)); $component->add_string(new mlang_string('thislanguageint', $data->langnameint)); $stage = mlang_persistent_stage::instance_for_user($USER->id, sesskey()); $stage->add($component); $stage->store(); redirect(new moodle_url('/local/amos/stage.php')); } /// Output starts here echo $OUTPUT->header(); $form->display(); echo $OUTPUT->footer();
die; } if (!confirm_sesskey()) { header('HTTP/1.1 403 Forbidden'); die; } $stringid = optional_param('stringid', null, PARAM_ALPHANUMEXT); $text = optional_param('text', null, PARAM_RAW); if (is_null($stringid) or is_null($text)) { header('HTTP/1.1 400 Bad Request'); die; } list($lang, $originalid, $translationid) = local_amos_translator::decode_identifier($stringid); $record = $DB->get_record('amos_repository', array('id' => $originalid), 'id,stringid,component,branch', MUST_EXIST); $version = mlang_version::by_code($record->branch); $component = new mlang_component($record->component, $lang, $version); if ($version->code < mlang_version::MOODLE_20) { header('HTTP/1.1 400 Bad Request'); die; } $string = new mlang_string($record->stringid, $text); $string->clean_text(); $component->add_string($string); $stage = mlang_persistent_stage::instance_for_user($USER->id, sesskey()); $stage->add($component, true); $stage->store(); mlang_stash::autosave($stage); header('Content-Type: application/json; charset: utf-8'); $response = new stdclass(); $response->text = local_amos_renderer::add_breaks(s($string->text)); echo json_encode($response);
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 = '+'; }
/** * Initialize data * * @param mlang_version $version we are generating page for * @param array $packinfo data structure prepared by cli/export-zip.php */ public function __construct(mlang_version $version, array $packinfo) { $this->version = $version; $this->packinfo = fullclone($packinfo); $this->timemodified = time(); $this->percents = array('0' => 0, '40' => 0, '60' => 0, '80' => 0); // percents => number of langpacks // get the number of strings for standard plugins // only the standard plugins are taken into statistics calculation $standard = local_amos_standard_plugins(); $english = array(); // holds the number of English strings per component $nontranslatable = array(); // holds the number of strings per component that can not be translated via AMOS // and therefore we should consider them as translated when calculating the ratio foreach ($standard[$this->version->dir] as $componentname => $unused) { $component = mlang_component::from_snapshot($componentname, 'en', $this->version); $english[$componentname] = $component->get_number_of_strings(); $this->totalenglish += $english[$componentname]; foreach ($component->get_iterator() as $string) { if (substr($string->id, -5) === '_link') { if (isset($nontranslatable[$componentname])) { $nontranslatable[$componentname]++; } else { $nontranslatable[$componentname] = 1; } } } $component->clear(); } foreach ($this->packinfo as $langcode => $info) { if ($langcode !== 'en') { $this->numoflangpacks++; } $langpack = new stdclass(); $langpack->langname = $info['langname']; $langpack->filename = $langcode . '.zip'; $langpack->filesize = $info['filesize']; $langpack->modified = $info['modified']; if (!empty($info['parent'])) { $langpack->parent = $info['parent']; } else { $langpack->parent = 'en'; } // calculate the translation statistics if ($langpack->parent == 'en') { $langpack->totaltranslated = 0; foreach ($info['numofstrings'] as $component => $translated) { if (!empty($nontranslatable[$component])) { $translated += $nontranslatable[$component]; } if (isset($standard[$this->version->dir][$component])) { $langpack->totaltranslated += min($translated, $english[$component]); } } if ($this->totalenglish == 0) { $langpack->ratio = null; } else { $langpack->ratio = $langpack->totaltranslated / $this->totalenglish; if ($langpack->ratio > 0.8) { $this->percents['80']++; } elseif ($langpack->ratio > 0.6) { $this->percents['60']++; } elseif ($langpack->ratio > 0.4) { $this->percents['40']++; } else { $this->percents['0']++; } } } else { $langpack->totaltranslated = 0; foreach ($info['numofstrings'] as $component => $translated) { $langpack->totaltranslated += $translated; } $langpack->ratio = null; } $this->langpacks[$langcode] = $langpack; } }
public function test_stage_propagate() { $version20 = mlang_version::by_branch('MOODLE_20_STABLE'); $version21 = mlang_version::by_branch('MOODLE_21_STABLE'); $version22 = mlang_version::by_branch('MOODLE_22_STABLE'); $component20en = new mlang_component('admin', 'en', $version20); $component20en->add_string(new mlang_string('foo1', 'Bar1')); $component20en->add_string(new mlang_string('foo2', 'Bar2')); $component20cs = new mlang_component('admin', 'cs', $version20); $component20cs->add_string(new mlang_string('foo1', 'TranslatedOldBar1')); $component21en = new mlang_component('admin', 'en', $version21); $component21en->add_string(new mlang_string('foo1', 'Bar1')); $component21en->add_string(new mlang_string('foo2', 'Bar2')); $component21en->add_string(new mlang_string('foo3', 'Bar3')); $component22en = new mlang_component('admin', 'en', $version22); $component22en->add_string(new mlang_string('foo1', 'Bar1')); $component22en->add_string(new mlang_string('foo2', 'Bar2')); $component22en->add_string(new mlang_string('foo3', 'NewBar3')); $stage = new mlang_stage(); $stage->add($component20en); $stage->add($component20cs); $stage->add($component21en); $stage->add($component22en); $stage->commit('Initial strings', array('source' => 'unittest'), true); $component20en->clear(); $component21en->clear(); $component22en->clear(); unset($stage); // simple usage - the user translated a string on 2.1 and want it being applied to 2.2, too $stage = new mlang_stage(); $component21cs = new mlang_component('admin', 'cs', $version21); $component21cs->add_string(new mlang_string('foo1', 'TranslatedBar1')); $stage->add($component21cs); $component21cs->clear(); $this->assertEqual($stage->propagate(array($version22)), 1); $propagatedcomponent = $stage->get_component('admin', 'cs', $version22); $this->assertNotNull($propagatedcomponent, 'The component "admin" must exist on ' . $version22->label); $this->assertTrue($propagatedcomponent->has_string('foo1')); $propagatedstring = $propagatedcomponent->get_string('foo1'); $this->assertTrue($propagatedstring->text, 'TranslatedBar1'); $stage->clear(); // the change is not propagated if the changed string is staged several times and the values // are different $stage = new mlang_stage(); $component20cs = new mlang_component('admin', 'cs', $version20); $component20cs->add_string(new mlang_string('foo2', 'TranslatedOldBar2')); $component21cs = new mlang_component('admin', 'cs', $version21); $component21cs->add_string(new mlang_string('foo2', 'TranslatedBar2')); $stage->add($component20cs); $stage->add($component21cs); $component20cs->clear(); $component21cs->clear(); $this->assertEqual($stage->propagate(array($version20, $version21, $version22)), 0); $this->assertEqual($stage->get_component('admin', 'cs', $version20)->get_string('foo2')->text, 'TranslatedOldBar2'); $this->assertEqual($stage->get_component('admin', 'cs', $version21)->get_string('foo2')->text, 'TranslatedBar2'); $this->assertNull($stage->get_component('admin', 'cs', $version22)); $stage->clear(); // but the change is propagated if the changed string is staged several times and the values // are the same $stage = new mlang_stage(); $component20cs = new mlang_component('admin', 'cs', $version20); $component20cs->add_string(new mlang_string('foo2', 'TranslatedBar2')); $component21cs = new mlang_component('admin', 'cs', $version21); $component21cs->add_string(new mlang_string('foo2', 'TranslatedBar2')); $stage->add($component20cs); $stage->add($component21cs); $component20cs->clear(); $component21cs->clear(); $this->assertEqual($stage->propagate(array($version20, $version21, $version22)), 1); $this->assertEqual($stage->get_component('admin', 'cs', $version22)->get_string('foo2')->text, 'TranslatedBar2'); $this->assertEqual($stage->get_component('admin', 'cs', $version21)->get_string('foo2')->text, 'TranslatedBar2'); $this->assertEqual($stage->get_component('admin', 'cs', $version20)->get_string('foo2')->text, 'TranslatedBar2'); $stage->clear(); // the staged string is propagated to another branch only if the English originals match // in the following test, the 2.1 translation of foo3 should not propagate to neither 2.0 // (because the string does not exist there) not 2.2 (because the English originals differ) $stage = new mlang_stage(); $component21cs = new mlang_component('admin', 'cs', $version21); $component21cs->add_string(new mlang_string('foo3', 'TranslatedBar3')); $stage->add($component21cs); $component21cs->clear(); $this->assertEqual($stage->propagate(array($version20, $version21, $version22)), 0); $this->assertNull($stage->get_component('admin', 'cs', $version20)); $this->assertNull($stage->get_component('admin', 'cs', $version22)); $stage->clear(); }
/** * Migrate help file into a help string if such one does not exist yet * * This is a temporary method and will be dropped once we have all English helps migrated. It does not do anything * yet. It is intended to be run once upon a checkout of 1.9 language files prepared just for this purpose. * * @param mixed $helpfile * @param mixed $tostring * @param mixed $tocomponent * @param mixed $timestamp * @return mlang_stage */ protected static function migrate_helpfile($version, $helpfile, $tostring, $tocomponent, $timestamp = null) { global $CFG; require_once $CFG->dirroot . '/local/amos/cli/config.php'; $stage = new mlang_stage(); foreach (array_keys(self::list_languages(false)) as $lang) { $fullpath = AMOS_REPO_LANGS . '/' . $lang . '_utf8/help/' . $helpfile; if (!is_readable($fullpath)) { continue; } $helpstring = file_get_contents($fullpath); $helpstring = preg_replace('|<h1>.*</h1>|i', '', $helpstring); $helpstring = iconv('UTF-8', 'UTF-8//IGNORE', $helpstring); $helpstring = trim($helpstring); if (empty($helpstring)) { continue; } $to = mlang_component::from_snapshot($tocomponent, $lang, $version, $timestamp, false, false, array($tostring)); if (!$to->has_string($tostring)) { $to->add_string(new mlang_string($tostring, $helpstring, $timestamp)); $stage->add($to); } $to->clear(); } return $stage; }
// Let us get an information about existing components $sql = "SELECT branch,lang,component,COUNT(stringid) AS numofstrings\n FROM {amos_repository}\n WHERE deleted=0\n GROUP BY branch,lang,component\n ORDER BY branch,lang,component"; $rs = $DB->get_recordset_sql($sql); $tree = array(); // [branch][language][component] => numofstrings foreach ($rs as $record) { $tree[$record->branch][$record->lang][$record->component] = $record->numofstrings; } $rs->close(); remove_dir(AMOS_EXPORT_DIR, true); foreach ($tree as $vercode => $languages) { $version = mlang_version::by_code($vercode); foreach ($languages as $langcode => $components) { if ($langcode == 'en') { continue; } foreach ($components as $componentname => $unused) { $component = mlang_component::from_snapshot($componentname, $langcode, $version); if ($component->has_string()) { $file = AMOS_EXPORT_DIR . '/' . $version->dir . '/' . $langcode . '/' . $component->get_phpfile_location(false); if (!file_exists(dirname($file))) { mkdir(dirname($file), 0755, true); } echo "{$file}\n"; $component->export_phpfile($file); } $component->clear(); } } } echo "DONE\n";
$plugins = local_amos_standard_plugins(); $stage = new mlang_stage(); foreach ($plugins as $versionnumber => $plugintypes) { $version = mlang_version::by_dir($versionnumber); if ($version->branch == 'MOODLE_23_STABLE') { $gitbranch = 'origin/master'; } else { $gitbranch = 'origin/' . $version->branch; } foreach ($plugintypes as $legacyname => $frankenstylename) { // moodle.org was replaced with a local plugin and strings were dropped from 2.0 and 2.1 if ($legacyname == 'moodle.org') { continue; } // prepare an empty component containing the fixes $fixcomponent = new mlang_component($legacyname, 'en', $version); // get the most recent snapshot from the AMOS repository $amoscomponent = mlang_component::from_snapshot($legacyname, 'en', $version); // get the location of the plugin if ($frankenstylename == 'core') { $plugintype = 'core'; $pluginname = null; } else { $plugintype = substr($frankenstylename, 0, strpos($frankenstylename, '_')); $pluginname = substr($frankenstylename, strpos($frankenstylename, '_') + 1); } // very hacky way to get plugin basedirs for all versions $basedirs = array('mod' => 'mod', 'auth' => 'auth', 'enrol' => 'enrol', 'message' => 'message/output', 'block' => 'blocks', 'filter' => 'filter', 'editor' => 'lib/editor', 'format' => 'course/format', 'profilefield' => 'user/profile/field', 'report' => 'report', 'coursereport' => 'course/report', 'gradeexport' => 'grade/export', 'gradeimport' => 'grade/import', 'gradereport' => 'grade/report', 'mnetservice' => 'mnet/service', 'webservice' => 'webservice', 'repository' => 'repository', 'portfolio' => 'portfolio', 'qtype' => 'question/type', 'qformat' => 'question/format', 'qbehaviour' => 'question/behaviour', 'plagiarism' => 'plagiarism', 'theme' => 'theme', 'assignment' => 'mod/assignment/type', 'datafield' => 'mod/data/field', 'datapreset' => 'mod/data/preset', 'quiz' => 'mod/quiz/report', 'quizaccess' => 'mod/quiz/accessrule', 'scormreport' => 'mod/scorm/report', 'workshopform' => 'mod/workshop/form', 'workshopallocation' => 'mod/workshop/allocation', 'workshopeval' => 'mod/workshop/eval', 'local' => 'local', 'tool' => 'admin/tool', 'gradingform' => 'grade/grading/form'); if ($version->code <= mlang_version::MOODLE_21) { // since 2.2 beta, reports have moved $basedirs['report'] = 'admin/report';
// 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); }
/** * Parses the given data in Moodle PHP string format * * @param string $data definition of the associative array * @param mlang_component $component component to add strings to * @param int $format the data format on the input, defaults to the one used since 2.0 * @return void */ public function parse($data, mlang_component $component, $format = 2) { $strings = $this->extract_strings($data); foreach ($strings as $id => $text) { $text = mlang_string::fix_syntax($text, 2, $format); $component->add_string(new mlang_string($id, $text)); } }