Skip to content

Commit

Permalink
MDL-8772 - Use the same list of places to search in get_string and he…
Browse files Browse the repository at this point in the history
…lp.php. Merged from MOODLE_18_STABLE.
  • Loading branch information
tjhunt committed Mar 14, 2007
1 parent 381b885 commit 6cad9e6
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 33 deletions.
30 changes: 18 additions & 12 deletions help.php
Original file line number Diff line number Diff line change
Expand Up @@ -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/"] = "$plugin/$file";
}
}
}
}

Expand Down
60 changes: 39 additions & 21 deletions lib/moodlelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -4177,6 +4177,28 @@ function clean_getstring_data( $a ) {
}
}

/**
* @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'),
'assignment_' => array('mod/assignment/type'),
'auth_' => array('auth'),
'block_' => array('blocks'),
'datafield_' => array('mod/data/field'),
'datapreset_' => array('mod/data/preset'),
'enrol_' => array('enrol'),
'format_' => array('course/format'),
'qtype_' => array('question/type'),
'report_' => array($CFG->admin.'/report', 'course/report', 'mod/quiz/report'),
'resource_' => array('mod/resource/type'),
'' => array('mod')
);
}

/**
* Returns a localized string.
*
Expand Down Expand Up @@ -4282,27 +4304,23 @@ function get_string($identifier, $module='', $a=NULL, $extralocations=NULL) {
}

/// 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/";
}
}
}

Expand Down

0 comments on commit 6cad9e6

Please sign in to comment.