MDL-12192 Language specific label separator instead of hardcoded ': '

New string is available. Use get_string('labelsep', 'langconfig') to be used
as a separator between a label and the labelled text. If you want to
produce <label> HTML element, you may be interested in the new
html_writer::label() method. Simple selects and URL selects now use it.

There are bambillion places where ': ' is hardcoded as a separator. I do
not think we have to fix them manually now (and mass search and replace
would be tricky) but everybody should stop adding new.

Do not abuse 'labelsep' for any other purposes. Note that it may not be
colon in some languages or sites.
This commit is contained in:
David Mudrak 2010-07-02 12:15:36 +00:00
parent 8bf1e5295e
commit 995f2d51d7
8 changed files with 64 additions and 19 deletions

View File

@ -297,7 +297,7 @@ $url = new moodle_url('/admin/langimport.php', array('mode' => DELETION_OF_SELEC
echo html_writer::start_tag('td', array('valign' => 'top'));
echo html_writer::start_tag('form', array('id' => 'uninstallform', 'action' => $url->out(), 'method' => 'post'));
echo html_writer::start_tag('fieldset');
echo html_writer::tag('label', get_string('installedlangs','admin'), array('for' => 'uninstalllang'));
echo html_writer::label(get_string('installedlangs','admin'), 'uninstalllang');
echo html_writer::empty_tag('br');
echo html_writer::select($installedlangs, 'uninstalllang', '', false, array('size' => 15));
echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey()));
@ -325,7 +325,7 @@ if (!empty($options)) {
$url = new moodle_url('/admin/langimport.php', array('mode' => INSTALLATION_OF_SELECTED_LANG));
echo html_writer::start_tag('form', array('id' => 'installform', 'action' => $url->out(), 'method' => 'post'));
echo html_writer::start_tag('fieldset');
echo html_writer::tag('label', get_string('availablelangs','install'), array('for' => 'pack'));
echo html_writer::label(get_string('availablelangs','install'), 'pack');
echo html_writer::empty_tag('br');
echo html_writer::select($options, 'pack[]', '', false, array('size' => 15, 'multiple' => 'multiple'));
echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey()));

View File

@ -165,7 +165,7 @@ class blog_entry {
if ($this->uniquehash && $this->content) {
if ($externalblog = $DB->get_record('blog_external', array('id' => $this->content))) {
$urlparts = parse_url($externalblog->url);
$topiccell->text .= $OUTPUT->container(get_string('retrievedfrom', 'blog') .': '. html_writer::link($urlparts['scheme'].'://'.$urlparts['host'], $externalblog->name), 'externalblog');
$topiccell->text .= $OUTPUT->container(get_string('retrievedfrom', 'blog').get_string('labelsep', 'langconfig').html_writer::link($urlparts['scheme'].'://'.$urlparts['host'], $externalblog->name), 'externalblog');
}
}

View File

@ -156,7 +156,7 @@ abstract class grade_export {
*/
public function format_column_name($grade_item, $feedback=false) {
if ($grade_item->itemtype == 'mod') {
$name = get_string('modulename', $grade_item->itemmodule).': '.$grade_item->get_name();
$name = get_string('modulename', $grade_item->itemmodule).get_string('labelsep', 'langconfig').$grade_item->get_name();
} else {
$name = $grade_item->get_name();
}

View File

@ -29,6 +29,7 @@ $string['decsep'] = '.';
$string['firstdayofweek'] = '0';
$string['iso6391'] = 'en';
$string['iso6392'] = 'eng';
$string['labelsep'] = ': ';
$string['listsep'] = ',';
$string['locale'] = 'en_AU.UTF-8';
$string['localewin'] = 'English_Australia.1252';

View File

@ -743,7 +743,7 @@ class single_select implements renderable {
}
/**
* Set's select lable
* Sets select's label
* @param string $label
* @return void
*/
@ -851,7 +851,7 @@ class url_select implements renderable {
}
/**
* Set's select lable
* Sets select's label
* @param string $label
* @return void
*/
@ -1521,6 +1521,50 @@ class html_writer {
return $output;
}
/**
* Renders form element label
*
* By default, the label is suffixed with a label separator defined in the
* current language pack (colon by default in the English lang pack).
* Adding the colon can be explicitly disabled if needed. Label separators
* are put outside the label tag itself so they are not read by
* screenreaders (accessibility).
*
* Parameter $for explicitly associates the label with a form control. When
* set, the value of this attribute must be the same as the value of
* the id attribute of the form control in the same document. When null,
* the label being defined is associated with the control inside the label
* element.
*
* @param string $text content of the label tag
* @param string|null $for id of the element this label is associated with, null for no association
* @param bool $colonize add label separator (colon) to the label text, if it is not there yet
* @param array $attributes to be inserted in the tab, for example array('accesskey' => 'a')
* @return string HTML of the label element
*/
public static function label($text, $for, $colonize=true, array $attributes=array()) {
if (!is_null($for)) {
$attributes = array_merge($attributes, array('for' => $for));
}
$text = trim($text);
$label = self::tag('label', $text, $attributes);
if ($colonize) {
// the $text may end with the colon already, though it is bad string definition style
$colon = get_string('labelsep', 'langconfig');
if (!empty($colon)) {
$trimmed = trim($colon);
if ((substr($text, -strlen($trimmed)) == $trimmed) or (substr($text, -1) == ':')) {
//debugging('The label text should not end with colon or other label separator,
// please fix the string definition.', DEBUG_DEVELOPER);
} else {
$label .= $colon;
}
}
}
return $label;
}
}
// ==== JS writer and helper classes, will be probably moved elsewhere ======

View File

@ -1091,7 +1091,7 @@ class core_renderer extends renderer_base {
}
if ($select->label) {
$output .= html_writer::tag('label', $select->label, array('for'=>$select->attributes['id']));
$output .= html_writer::label($select->label, $select->attributes['id']);
}
if ($select->helpicon instanceof help_icon) {
@ -1162,7 +1162,7 @@ class core_renderer extends renderer_base {
$output = '';
if ($select->label) {
$output .= html_writer::tag('label', $select->label, array('for'=>$select->attributes['id']));
$output .= html_writer::label($select->label, $select->attributes['id']);
}
if ($select->helpicon instanceof help_icon) {
@ -1369,9 +1369,9 @@ class core_renderer extends renderer_base {
$popuplink = new moodle_url("$url&popup=1");
$action = new popup_action('click', $popuplink, 'ratings', array('height' => 400, 'width' => 600));
$ratinghtml .= $aggregatelabel.': '.$this->action_link($nonpopuplink, $aggregatehtml, $action);
$ratinghtml .= $aggregatelabel.get_string('labelsep', 'langconfig').$this->action_link($nonpopuplink, $aggregatehtml, $action);
} else {
$ratinghtml .= "{$aggregatelabel}: $aggregatehtml";
$ratinghtml .= $aggregatelabel.get_string('labelsep', 'langconfig').$aggregatehtml;
}
}

View File

@ -546,7 +546,7 @@ function choice_show_results($choice, $course, $cm, $allresponses, $forcepublish
echo '<a href="javascript:select_all_in(\'DIV\',null,\'tablecontainer\');">'.get_string('selectall', 'quiz').'</a> / ';
echo '<a href="javascript:deselect_all_in(\'DIV\',null,\'tablecontainer\');">'.get_string('selectnone', 'quiz').'</a> ';
echo '&nbsp;&nbsp;';
echo html_writer::tag('label', get_string('withselected', 'quiz'), array('for'=>'menuaction'));
echo html_writer::label(get_string('withselected', 'quiz'), 'menuaction');
echo html_writer::select(array('delete' => get_string('delete')), 'action', '', array(''=>get_string('moveselectedcoursesto')), array('id'=>'menuaction'));
$PAGE->requires->js_init_call('M.util.init_select_autosubmit', array('attemptsform', 'menuaction', ''));
echo '<noscript id="noscriptmenuaction" style="display:inline">';

View File

@ -459,7 +459,7 @@
} else if (count($rolenames) == 1) {
// when all users with the same role - print its name
echo '<div class="rolesform">';
echo get_string('role').': ';
echo get_string('role').get_string('labelsep', 'langconfig');
$rolename = reset($rolenames);
echo $rolename;
echo '</div>';
@ -499,9 +499,9 @@
$strallparticipants = get_string('allparticipants');
}
if ($matchcount < $totalcount) {
echo $OUTPUT->heading($strallparticipants.': '.$matchcount.'/'.$totalcount . $editlink, 3);
echo $OUTPUT->heading($strallparticipants.get_string('labelsep', 'langconfig').$matchcount.'/'.$totalcount . $editlink, 3);
} else {
echo $OUTPUT->heading($strallparticipants.': '.$matchcount . $editlink, 3);
echo $OUTPUT->heading($strallparticipants.get_string('labelsep', 'langconfig').$matchcount . $editlink, 3);
}
}
@ -603,14 +603,14 @@
$row->cells[1]->text .= $OUTPUT->container_start('info');
if (!empty($user->role)) {
$row->cells[1]->text .= get_string('role') .': '. $user->role .'<br />';
$row->cells[1]->text .= get_string('role').get_string('labelsep', 'langconfig').$user->role.'<br />';
}
if ($user->maildisplay == 1 or ($user->maildisplay == 2 and ($course->id != SITEID) and !isguestuser()) or
has_capability('moodle/course:viewhiddenuserfields', $context)) {
$row->cells[1]->text .= get_string('email') .': ' . html_writer::link("mailto:$user->email", $user->email) . '<br />';
$row->cells[1]->text .= get_string('email').get_string('labelsep', 'langconfig').html_writer::link("mailto:$user->email", $user->email) . '<br />';
}
if (($user->city or $user->country) and (!isset($hiddenfields['city']) or !isset($hiddenfields['country']))) {
$row->cells[1]->text .= get_string('city') .': ';
$row->cells[1]->text .= get_string('city').get_string('labelsep', 'langconfig');
if ($user->city && !isset($hiddenfields['city'])) {
$row->cells[1]->text .= $user->city;
}
@ -625,10 +625,10 @@
if (!isset($hiddenfields['lastaccess'])) {
if ($user->lastaccess) {
$row->cells[1]->text .= get_string('lastaccess') .': '. userdate($user->lastaccess);
$row->cells[1]->text .= get_string('lastaccess').get_string('labelsep', 'langconfig').userdate($user->lastaccess);
$row->cells[1]->text .= '&nbsp; ('. format_time(time() - $user->lastaccess, $datestring) .')';
} else {
$row->cells[1]->text .= get_string('lastaccess') .': '. get_string('never');
$row->cells[1]->text .= get_string('lastaccess').get_string('labelsep', 'langconfig').get_string('never');
}
}