Moodle
  1. Moodle
  2. MDL-30657

Attempt to re-define already required string 'cancel'

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Minor Minor
    • Resolution: Unresolved
    • Affects Version/s: 2.2
    • Fix Version/s: None
    • Component/s: Blog
    • Labels:
      None
    • Database:
      MySQL
    • Workaround:
      Hide

      Display course with language set to englisch(en)

      Show
      Display course with language set to englisch(en)
    • Affected Branches:
      MOODLE_22_STABLE
    • Rank:
      33474

      Description

      Situation:

      • Language Settings: autolang:false, lang:Deutsch (de), langcache: false
      • no language customization
      • User Profile: prefered language: englisch
      • Course: force language: deutsch (de)
      • no blog entries created so far ...
      • inside a course ...

      Action:

      • Click on 'Blockmenü' - 'Alle Beiträge zum Kurs'
        (english equivalent: 'Block menu' - 'View all entries for this course')
        or
      • Click on 'Blockmenü' - 'Meine Beiträge zum Kurs' (en: 'View my entries for this course')

      Result: Error Message

      Fehler in der Kodierung gefunden, den nur ein Programmierer korrigieren kann: Attempt to re-define already required string 'cancel' from lang file 'moodle'. Did you already ask for it with a different $a? Cancel !== Abbrechen

      The problem does not appear, when the course is displayed in english.

        Activity

        Hide
        Michael de Raadt added a comment -

        Thanks for reporting that.

        What is "Alle Beiträge zum Kurs"? I couldn't find that in the standard blocks.

        Show
        Michael de Raadt added a comment - Thanks for reporting that. What is "Alle Beiträge zum Kurs"? I couldn't find that in the standard blocks.
        Hide
        Troy Williams added a comment -

        Hi,

        I think it due to incorrect sequence, like require_login coming after $OUTPUT setup as just came across same issue in a wimba plugins.

        Example

        Error:
        $PAGE->set_url('/mod/voiceauthoring/view.php');
        $PAGE->requires->css('/mod/voiceauthoring/css/StyleSheet.css');
        $cm = get_coursemodule_from_instance("voiceemail", $voicetool->id, $course->id);
        require_login($course->id, false, $cm);
        $PAGE->set_pagelayout('base');

        Worked:
        require_login($course->id, false, $cm);
        $PAGE->set_url('/mod/voiceauthoring/view.php');
        $PAGE->requires->css('/mod/voiceauthoring/css/StyleSheet.css');
        $cm = get_coursemodule_from_instance("voiceemail", $voicetool->id, $course->id);
        $PAGE->set_pagelayout('base');

        Regards,

        Troy

        Show
        Troy Williams added a comment - Hi, I think it due to incorrect sequence, like require_login coming after $OUTPUT setup as just came across same issue in a wimba plugins. Example Error: $PAGE->set_url('/mod/voiceauthoring/view.php'); $PAGE->requires->css('/mod/voiceauthoring/css/StyleSheet.css'); $cm = get_coursemodule_from_instance("voiceemail", $voicetool->id, $course->id); require_login($course->id, false, $cm); $PAGE->set_pagelayout('base'); Worked: require_login($course->id, false, $cm); $PAGE->set_url('/mod/voiceauthoring/view.php'); $PAGE->requires->css('/mod/voiceauthoring/css/StyleSheet.css'); $cm = get_coursemodule_from_instance("voiceemail", $voicetool->id, $course->id); $PAGE->set_pagelayout('base'); Regards, Troy
        Hide
        Mart Mangus added a comment -

        We have the same problem with Russian language.

        Обнаружена ошибка кодирования, она должна быть исправлена программистом:
        Attempt to re-define already required string 'cancel' from lang file 'moodle'.
        Did you already ask for it with a different $a? Cancel !== Отмена 
        

        Is there any other workaround, that doesn't require changing the course display language?

        Thanks!

        Show
        Mart Mangus added a comment - We have the same problem with Russian language. Обнаружена ошибка кодирования, она должна быть исправлена программистом: Attempt to re-define already required string 'cancel' from lang file 'moodle'. Did you already ask for it with a different $a? Cancel !== Отмена Is there any other workaround, that doesn't require changing the course display language? Thanks!
        Hide
        Tatsuya Shirai added a comment -

        In japanese language environment, this problem occurs too.

        Let you see moodle/lib/outputrequirementslib.php

        (1) Line 300
        $this->string_for_js('confirmation', 'admin');
        $this->string_for_js('cancel', 'moodle');
        $this->string_for_js('yes', 'moodle');

        (2) Line 830, public function string_for_js()
        public function string_for_js($identifier, $component, $a = NULL) {
        $string = get_string($identifier, $component, $a);
        if (!$component)

        { throw new coding_exception('The $module parameter is required for page_requirements_manager::string_for_js.'); }

        if (isset($this->stringsforjs[$component][$identifier]) && $this->stringsforjs[$component][$identifier] !== $string) {
        throw new coding_exception("Attempt to re-define already required string '$identifier' " .
        "from lang file '$component'. Did you already ask for it with a different \$a? {$this->stringsforjs[$component][$identifier]} !== $string");
        }
        $this->stringsforjs[$component][$identifier] = $string;
        }

        Before changing language pack, $this->stringforjs['moodle']['cancel'] is 'Cancel' by $string = get_string('cancel', 'moodle', null).
        If you change langage pack for other language, $string = get_string('cancel', 'moodle', null) will return 'Abbrechen', 'Отмена' or 'キャンセル'. Then, error check code 'if (isset($this->srringforjs...' throw exception. This is a mechanism of this problem.

        Show
        Tatsuya Shirai added a comment - In japanese language environment, this problem occurs too. Let you see moodle/lib/outputrequirementslib.php (1) Line 300 $this->string_for_js('confirmation', 'admin'); $this->string_for_js('cancel', 'moodle'); $this->string_for_js('yes', 'moodle'); (2) Line 830, public function string_for_js() public function string_for_js($identifier, $component, $a = NULL) { $string = get_string($identifier, $component, $a); if (!$component) { throw new coding_exception('The $module parameter is required for page_requirements_manager::string_for_js.'); } if (isset($this->stringsforjs [$component] [$identifier] ) && $this->stringsforjs [$component] [$identifier] !== $string) { throw new coding_exception("Attempt to re-define already required string '$identifier' " . "from lang file '$component'. Did you already ask for it with a different \$a? {$this->stringsforjs [$component] [$identifier] } !== $string"); } $this->stringsforjs [$component] [$identifier] = $string; } Before changing language pack, $this->stringforjs ['moodle'] ['cancel'] is 'Cancel' by $string = get_string('cancel', 'moodle', null). If you change langage pack for other language, $string = get_string('cancel', 'moodle', null) will return 'Abbrechen', 'Отмена' or 'キャンセル'. Then, error check code 'if (isset($this->srringforjs...' throw exception. This is a mechanism of this problem.
        Hide
        Tatsuya Shirai added a comment -

        This error message is displayed by admin/langimport.php line 214 as follows while redrawing display after finishing install/uninstall a lang pack.

        212: get_string_manager()->reset_caches();
        213:
        214: echo $OUTPUT->header();
        215: echo $OUTPUT->heading(get_string('langimport', 'admin'));

        Show
        Tatsuya Shirai added a comment - This error message is displayed by admin/langimport.php line 214 as follows while redrawing display after finishing install/uninstall a lang pack. 212: get_string_manager()->reset_caches(); 213: 214: echo $OUTPUT->header(); 215: echo $OUTPUT->heading(get_string('langimport', 'admin'));
        Hide
        Tatsuya Shirai added a comment -

        This is not safety and not perfect patch, only for explaining a cause/mechanism of this problem.

        (1) moodle/lib/outputrequirementslib.phpのfunction string_for_js()

        public function string_for_js($identifier, $component, $a = NULL) {
        $string = get_string($identifier, $component, $a);
        if (!$component)

        { throw new coding_exception('The $module parameter is required for page_requirements_manager::string_for_js.'); }

        if (isset($this->stringsforjs[$component][$identifier]) && $this->stringsforjs[$component][$identifier] !== $string) {
        // Add these two lines (by T.Shirai)
        $estring = get_string($identifier, $component, $a, 'en');
        if ($this->stringsforjs[$component][$identifier] !== $estring and $string !== $estring)

        throw new coding_exception("Attempt to re-define already required string '$identifier' " .
        "from lang file '$component'. Did you already ask for it with a different \$a? {$this->stringsforjs[$component][$identifier]} !== $string");
        }
        $this->stringsforjs[$component][$identifier] = $string;
        }

        (2)lib/moodlelib.php, function get_string(), add 4th parameter, $lang

        // function get_string($identifier, $component = '', $a = NULL) {
        function get_string($identifier, $component = '', $a = NULL, $lang = NULL) { // <= 4th parameter by T.Shirai

        $identifier = clean_param($identifier, PARAM_STRINGID);
        if (empty($identifier))

        { throw new coding_exception('Invalid string identifier. Most probably some illegal character is part of the string identifier. Please fix your get_string() call and string definition'); }

        // if (func_num_args() > 3) {
        if (func_num_args() > 4)

        { // change 3->4 by T.Shirai debugging('extralocations parameter in get_string() is not supported any more, please use standard lang locations only.'); }

        if (strpos($component, '/') !== false)

        { .... // return get_string_manager()->get_string($identifier, $component, $a); return get_string_manager()->get_string($identifier, $component, $a, $lang); // add $lang by T.Shirai }
        Show
        Tatsuya Shirai added a comment - This is not safety and not perfect patch, only for explaining a cause/mechanism of this problem. (1) moodle/lib/outputrequirementslib.phpのfunction string_for_js() public function string_for_js($identifier, $component, $a = NULL) { $string = get_string($identifier, $component, $a); if (!$component) { throw new coding_exception('The $module parameter is required for page_requirements_manager::string_for_js.'); } if (isset($this->stringsforjs [$component] [$identifier] ) && $this->stringsforjs [$component] [$identifier] !== $string) { // Add these two lines (by T.Shirai) $estring = get_string($identifier, $component, $a, 'en'); if ($this->stringsforjs [$component] [$identifier] !== $estring and $string !== $estring) throw new coding_exception("Attempt to re-define already required string '$identifier' " . "from lang file '$component'. Did you already ask for it with a different \$a? {$this->stringsforjs [$component] [$identifier] } !== $string"); } $this->stringsforjs [$component] [$identifier] = $string; } (2)lib/moodlelib.php, function get_string(), add 4th parameter, $lang // function get_string($identifier, $component = '', $a = NULL) { function get_string($identifier, $component = '', $a = NULL, $lang = NULL) { // <= 4th parameter by T.Shirai $identifier = clean_param($identifier, PARAM_STRINGID); if (empty($identifier)) { throw new coding_exception('Invalid string identifier. Most probably some illegal character is part of the string identifier. Please fix your get_string() call and string definition'); } // if (func_num_args() > 3) { if (func_num_args() > 4) { // change 3->4 by T.Shirai debugging('extralocations parameter in get_string() is not supported any more, please use standard lang locations only.'); } if (strpos($component, '/') !== false) { .... // return get_string_manager()->get_string($identifier, $component, $a); return get_string_manager()->get_string($identifier, $component, $a, $lang); // add $lang by T.Shirai }
        Hide
        Tatsuya Shirai added a comment -

        Michael reported this error message when we click "blockmenu" button.
        I had reported this error message when we install/unsintall language pack in language inport utility.
        Sorry! but I assume that the mechanism is the same.

        Show
        Tatsuya Shirai added a comment - Michael reported this error message when we click "blockmenu" button. I had reported this error message when we install/unsintall language pack in language inport utility. Sorry! but I assume that the mechanism is the same.
        Hide
        Angelo Rigo added a comment -

        It happens on grade/report/grader/index.php too!

        Show
        Angelo Rigo added a comment - It happens on grade/report/grader/index.php too!
        Hide
        Nadav Kavalerchik added a comment -

        Same issue with mod/OUBLOG (Moodle 2.3)

        Coding error detected, it must be fixed by a programmer: Attempt to re-define already required string 'error' from lang file 'moodle'. Did you already ask for it with a different $a? טעות !== Error
        
        More information about this error
        
        Debug info: 
        Error code: codingerror
        Stack trace:
        line 870 of /lib/outputrequirementslib.php: coding_exception thrown
        line 559 of /lib/outputrequirementslib.php: call to page_requirements_manager->string_for_js()
        line 803 of /lib/outputrequirementslib.php: call to page_requirements_manager->js_module()
        line 787 of /lib/outputrequirementslib.php: call to page_requirements_manager->js_init_code()
        line 123 of /files/renderer.php: call to page_requirements_manager->js_init_call()
        line 215 of /lib/outputrenderers.php: call to core_files_renderer->render_form_filemanager()
        line 257 of /lib/form/filemanager.php: call to plugin_renderer_base->render()
        line 183 of /lib/pear/HTML/QuickForm/Renderer/Tableless.php: call to MoodleQuickForm_filemanager->toHtml()
        line 2384 of /lib/formslib.php: call to HTML_QuickForm_Renderer_Tableless->renderElement()
        line 403 of /lib/pear/HTML/QuickForm/element.php: call to MoodleQuickForm_Renderer->renderElement()
        line 1631 of /lib/pear/HTML/QuickForm.php: call to HTML_QuickForm_element->accept()
        line 1414 of /lib/formslib.php: call to HTML_QuickForm->accept()
        line 1674 of /lib/pear/HTML/QuickForm.php: call to MoodleQuickForm->accept()
        line 435 of /lib/pear/HTML/Common.php: call to HTML_QuickForm->toHtml()
        line 204 of /lib/pear/HTML/QuickForm/DHTMLRulesTableless.php: call to HTML_Common->display()
        line 896 of /lib/formslib.php: call to HTML_QuickForm_DHTMLRulesTableless->display()
        line 146 of /mod/oublog/editpost.php: call to moodleform->display()
        
        Show
        Nadav Kavalerchik added a comment - Same issue with mod/OUBLOG (Moodle 2.3) Coding error detected, it must be fixed by a programmer: Attempt to re-define already required string 'error' from lang file 'moodle'. Did you already ask for it with a different $a? טעות !== Error More information about this error Debug info: Error code: codingerror Stack trace: line 870 of /lib/outputrequirementslib.php: coding_exception thrown line 559 of /lib/outputrequirementslib.php: call to page_requirements_manager->string_for_js() line 803 of /lib/outputrequirementslib.php: call to page_requirements_manager->js_module() line 787 of /lib/outputrequirementslib.php: call to page_requirements_manager->js_init_code() line 123 of /files/renderer.php: call to page_requirements_manager->js_init_call() line 215 of /lib/outputrenderers.php: call to core_files_renderer->render_form_filemanager() line 257 of /lib/form/filemanager.php: call to plugin_renderer_base->render() line 183 of /lib/pear/HTML/QuickForm/Renderer/Tableless.php: call to MoodleQuickForm_filemanager->toHtml() line 2384 of /lib/formslib.php: call to HTML_QuickForm_Renderer_Tableless->renderElement() line 403 of /lib/pear/HTML/QuickForm/element.php: call to MoodleQuickForm_Renderer->renderElement() line 1631 of /lib/pear/HTML/QuickForm.php: call to HTML_QuickForm_element->accept() line 1414 of /lib/formslib.php: call to HTML_QuickForm->accept() line 1674 of /lib/pear/HTML/QuickForm.php: call to MoodleQuickForm->accept() line 435 of /lib/pear/HTML/Common.php: call to HTML_QuickForm->toHtml() line 204 of /lib/pear/HTML/QuickForm/DHTMLRulesTableless.php: call to HTML_Common->display() line 896 of /lib/formslib.php: call to HTML_QuickForm_DHTMLRulesTableless->display() line 146 of /mod/oublog/editpost.php: call to moodleform->display()
        Hide
        Nadav Kavalerchik added a comment -

        Update: to the above mod/oublog issue:
        Here is DavoSmith's fix: https://github.com/davosmith/moodle-mod_oublog/commit/9b4ec071bef79464e366d08da6889903c18435df

        Show
        Nadav Kavalerchik added a comment - Update: to the above mod/oublog issue: Here is DavoSmith's fix: https://github.com/davosmith/moodle-mod_oublog/commit/9b4ec071bef79464e366d08da6889903c18435df

          People

          • Votes:
            10 Vote for this issue
            Watchers:
            11 Start watching this issue

            Dates

            • Created:
              Updated: