### Eclipse Workspace Patch 1.0 #P moodle_18 Index: help.php =================================================================== RCS file: /cvsroot/moodle/moodle/help.php,v retrieving revision 1.38 diff -u -r1.38 help.php --- help.php 10 Feb 2007 21:54:19 -0000 1.38 +++ help.php 6 Mar 2007 09:12:49 -0000 @@ -61,18 +61,24 @@ $locations[$CFG->dataroot.'/lang/'] = $modfile; $locations[$CFG->dirroot.'/lang/'] = $modfile; - if (strpos($module, 'block_') === 0) { // It's a block help file - $block = substr($module, 6); - $locations[$CFG->dirroot .'/blocks/'.$block.'/lang/'] = $block.'/'.$file; - } else if (strpos($module, 'report_') === 0) { // It's a report help file - $report = substr($module, 7); - $locations[$CFG->dirroot .'/'.$CFG->admin.'/report/'.$report.'/lang/'] = $report.'/'.$file; - $locations[$CFG->dirroot .'/course/report/'.$report.'/lang/'] = $report.'/'.$file; - } else if (strpos($module, 'format_') === 0) { // Course format - $format = substr($module,7); - $locations[$CFG->dirroot .'/course/format/'.$format.'/lang/'] = $format.'/'.$file; - } else { // It's a normal activity - $locations[$CFG->dirroot .'/mod/'.$module.'/lang/'] = $module.'/'.$file; + $rules = places_to_search_for_lang_strings(); + $exceptions = $rules['__exceptions']; + unset($rules['__exceptions']); + + if (!in_array($module, $exceptions)) { + $dividerpos = strpos($module, '_'); + if ($dividerpos === false) { + $type = ''; + $plugin = $module; + } else { + $type = substr($module, 0, $dividerpos + 1); + $plugin = substr($module, $dividerpos + 1); + } + if (!empty($rules[$type])) { + foreach ($rules[$type] as $location) { + $locations[$CFG->dirroot . "/$location/$plugin/lang/"] = "$block/$file"; + } + } } } Index: lib/moodlelib.php =================================================================== RCS file: /cvsroot/moodle/moodle/lib/moodlelib.php,v retrieving revision 1.837.2.16 diff -u -r1.837.2.16 moodlelib.php --- lib/moodlelib.php 6 Mar 2007 07:57:13 -0000 1.837.2.16 +++ lib/moodlelib.php 6 Mar 2007 09:12:53 -0000 @@ -4145,6 +4145,26 @@ } } +/** + * @return array places to look for lang strings based on the prefix to the + * module name. For example qtype_ in question/type. Used by get_string and + * help.php. + */ +function places_to_search_for_lang_strings() { + return array( + '__exceptions' => array('moodle', 'langconfig'), + 'block_' => array('blocks'), + 'report_' => array($CFG->admin.'/report', 'course/report', 'mod/quiz/report'), + 'resource_' => array('mod/resource/type'), + 'assignment_' => array('mod/assignment/type'), + 'enrol_' => array('enrol'), + 'auth_' => array('auth'), + 'format_' => array('course/format'), + 'qtype_' => array('question/type'), + '' => array('mod') + ); +} + /** * Returns a localized string. * @@ -4250,27 +4270,23 @@ } /// Add extra places to look for strings for particular plugin types. - if ($module != 'moodle' && $module != 'langconfig') { - if (strpos($module, 'block_') === 0) { // It's a block lang file - $locations[] = $CFG->dirroot .'/blocks/'.substr($module, 6).'/lang/'; - } else if (strpos($module, 'report_') === 0) { // It's a report lang file - $locations[] = $CFG->dirroot .'/'.$CFG->admin.'/report/'.substr($module, 7).'/lang/'; - $locations[] = $CFG->dirroot .'/course/report/'.substr($module, 7).'/lang/'; - $locations[] = $CFG->dirroot .'/mod/quiz/report/'.substr($module, 7).'/lang/'; - } else if (strpos($module, 'resource_') === 0) { // It's a resource module file - $locations[] = $CFG->dirroot .'/mod/resource/type/'.substr($module, 9).'/lang/'; - } else if (strpos($module, 'assignment_') === 0) { // It's an assignment module file - $locations[] = $CFG->dirroot .'/mod/assignment/type/'.substr($module, 11).'/lang/'; - } else if (strpos($module, 'enrol_') === 0) { // It's an enrolment plugin - $locations[] = $CFG->dirroot .'/enrol/'.substr($module, 6).'/lang/'; - } else if (strpos($module, 'auth_') === 0) { // It's an auth plugin - $locations[] = $CFG->dirroot .'/auth/'.substr($module, 5).'/lang/'; - } else if (strpos($module, 'format_') === 0) { // Course format - $locations[] = $CFG->dirroot .'/course/format/'.substr($module,7).'/lang/'; - } else if (strpos($module, 'qtype_') === 0) { // It's a question type - $locations[] = $CFG->dirroot .'/question/type/'.substr($module, 6).'/lang/'; - } else { // It's a normal activity - $locations[] = $CFG->dirroot .'/mod/'.$module.'/lang/'; + $rules = places_to_search_for_lang_strings(); + $exceptions = $rules['__exceptions']; + unset($rules['__exceptions']); + + if (!in_array($module, $exceptions)) { + $dividerpos = strpos($module, '_'); + if ($dividerpos === false) { + $type = ''; + $plugin = $module; + } else { + $type = substr($module, 0, $dividerpos + 1); + $plugin = substr($module, $dividerpos + 1); + } + if (!empty($rules[$type])) { + foreach ($rules[$type] as $location) { + $locations[] = $CFG->dirroot . "/$location/$plugin/lang/"; + } } }