// it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // Moodle is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with Moodle. If not, see <http://www.gnu.org/licenses/>. /** * Handles submission of the whole translation table * * This adds the submitted strings into the user's instance of mlang_persistent_stage * and redirects back to view.php * * @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(__FILE__))) . '/config.php'; require_once dirname(__FILE__) . '/locallib.php'; require_login(SITEID, false); require_capability('local/amos:stage', get_system_context()); require_sesskey(); $fields = required_param('fields', PARAM_ALPHANUMEXT); foreach ($fields as $field) { list($originalid, $translationid) = local_amos_translator::decode_identifier($field); } redirect(new moodle_url('/local/amos/view.php'));
require_login(SITEID, false); if (!has_capability('local/amos:stage', get_system_context())) { header('HTTP/1.1 403 Forbidden'); 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');
/** * Renders the translation tool * * @param local_amos_translator $translator * @return string */ protected function render_local_amos_translator(local_amos_translator $translator) { global $PAGE; $table = new html_table(); $table->id = 'amostranslator'; $table->head = array(get_string('translatorstring', 'local_amos') . $this->help_icon('translatorstring', 'local_amos'), get_string('translatororiginal', 'local_amos') . $this->help_icon('translatororiginal', 'local_amos'), get_string('translatorlang', 'local_amos') . $this->help_icon('translatorlang', 'local_amos'), get_string('translatortranslation', 'local_amos') . $this->help_icon('translatortranslation', 'local_amos')); $table->colclasses = array('stringinfo', 'original', 'lang', 'translation'); if (empty($translator->strings)) { if ($translator->currentpage > 1) { $output = $this->heading(get_string('nostringsfoundonpage', 'local_amos', $translator->currentpage)); $output .= html_writer::tag('div', html_writer::link(new moodle_url($PAGE->url, array('fpg' => 1)), get_string('gotofirst', 'local_amos')) . ' | ' . html_writer::link(new moodle_url($PAGE->url, array('fpg' => $translator->currentpage - 1)), get_string('gotoprevious', 'local_amos')), array('style' => 'text-align:center')); $output = html_writer::tag('div', $output, array('class' => 'translatorwrapper no-overflow')); } else { $output = $this->heading(get_string('nostringsfound', 'local_amos')); $output = html_writer::tag('div', $output, array('class' => 'translatorwrapper no-overflow')); } return $output; } $missing = 0; $standard = array(); foreach (local_amos_standard_plugins() as $plugins) { $standard = array_merge($standard, $plugins); } foreach ($translator->strings as $string) { $cells = array(); // string identification if (isset($standard[$string->component])) { $componentname = $standard[$string->component]; } else { $componentname = $string->component; } $stringinfo = html_writer::tag('span', $string->branch, array('class' => 'version')); $stringinfo .= ' [' . html_writer::tag('span', $string->stringid, array('class' => 'stringid')) . ',' . html_writer::tag('span', $componentname, array('class' => 'component')) . ']'; $cells[0] = new html_table_cell($stringinfo); // original of the string $o = html_writer::tag('div', self::add_breaks(s($string->original)), array('class' => 'preformatted english')); $g = html_writer::tag('div', '', array('class' => 'googleicon')); $p = ''; if (preg_match('/\\{\\$a(->.+)?\\}/', $string->original)) { $p = html_writer::tag('div', $this->help_icon('placeholder', 'local_amos', get_string('placeholderwarning', 'local_amos')), array('class' => 'placeholderinfo')); } $l = ''; if ($string->greylisted) { $l = html_writer::tag('div', $this->help_icon('greylisted', 'local_amos', get_string('greylistedwarning', 'local_amos')), array('class' => 'greylistedinfo')); } $cells[1] = new html_table_cell($o . $g . $p . $l); if ($string->greylisted) { $cells[1]->attributes['class'] .= ' greylisted'; } // the language in which the original is displayed and the timeline link $url = new moodle_url('/local/amos/timeline.php', array('component' => $string->component, 'language' => $string->language, 'branch' => $string->branchcode, 'stringid' => $string->stringid)); $text = html_writer::tag('span', '+', array('class' => 'plus')); $text .= html_writer::tag('span', '-', array('class' => 'minus')); $cells[2] = new html_table_cell(html_writer::tag('div', $string->language, array('class' => 'langcode')) . html_writer::tag('div', html_writer::tag('a', $text, array('href' => $url, 'target' => '_blank', 'title' => get_string('stringhistory', 'local_amos'))), array('class' => 'timelinelink'))); // Translation if (empty($string->translation) and $string->translation !== '0') { $missing++; } $t = self::add_breaks(s($string->translation)); $sid = local_amos_translator::encode_identifier($string->language, $string->originalid, $string->translationid); $t = html_writer::tag('div', $t, array('class' => 'preformatted translation-view')); $i = html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'fields[]', 'value' => $sid)); if ($string->outdated and $string->committable and $string->translation) { if ($string->translationid) { $c = html_writer::empty_tag('input', array('type' => 'checkbox', 'id' => 'update_' . $string->translationid, 'name' => 'updates[]', 'value' => $string->translationid)); $help = $this->help_icon('markuptodate', 'local_amos'); $c .= html_writer::tag('label', 'mark as up-to-date' . $help, array('for' => 'update_' . $string->translationid)); } else { $c = $this->help_icon('outdatednotcommitted', 'local_amos', get_string('outdatednotcommittedwarning', 'local_amos')); } $c = html_writer::tag('div', $c, array('class' => 'uptodatewrapper')); } else { $c = ''; } $cells[3] = new html_table_cell($t . $c . $i); $cells[3]->id = $sid; $cells[3]->attributes['width'] = '30%'; $cells[3]->attributes['class'] = $string->class; if ($string->translatable) { $cells[3]->attributes['class'] .= ' translatable'; } else { $cells[3]->attributes['class'] .= ' nontranslatable'; } if ($string->committable) { $cells[3]->attributes['class'] .= ' committable'; } if ($string->outdated) { $cells[3]->attributes['class'] .= ' outdated'; } $row = new html_table_row($cells); $table->data[] = $row; } $a = new stdClass(); $a->found = $translator->numofrows; $a->missing = $translator->numofmissing; $a->missingonpage = $missing; $heading = get_string('found', 'local_amos', $a); $output = $this->heading_with_help($heading, 'foundinfo', 'local_amos'); $pages = ceil($translator->numofrows / local_amos_translator::PERPAGE); $output .= html_writer::tag('div', self::page_links($pages, $translator->currentpage), array('class' => 'pagination')); $output .= html_writer::table($table); $output .= html_writer::tag('div', self::page_links($pages, $translator->currentpage), array('class' => 'pagination')); $output = html_writer::tag('div', $output, array('class' => 'translatorwrapper no-overflow')); return $output; }