Skip to content

Commit

Permalink
BaseControl: labels are translated using form's translator
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Feb 25, 2015
1 parent 794d0e2 commit 0e0b661
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 18 deletions.
4 changes: 3 additions & 1 deletion src/Forms/Controls/BaseControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,9 @@ public function getLabel($caption = NULL)
{
$label = clone $this->label;
$label->for = $this->getHtmlId();
$label->setText($this->translate($caption === NULL ? $this->caption : $caption));
$caption = $caption === NULL ? $this->caption : $caption;
$translator = $this->getForm()->getTranslator();
$label->setText($translator ? $translator->translate($caption) : $caption);
return $label;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Forms/Controls.Checkbox.render.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ test(function() { // Html with translator
$input = $form->addCheckbox('on', 'Label');
$input->setTranslator(new Translator);

Assert::same('<label for="frm-on"><input type="checkbox" name="on" id="frm-on">LABEL</label>', (string) $input->getControl());
Assert::same('<label for="frm-on"><input type="checkbox" name="on" id="frm-on">Label</label>', (string) $input->getControl());
});


Expand Down
6 changes: 3 additions & 3 deletions tests/Forms/Controls.CheckboxList.render.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ test(function() { // translator
));
$input->setTranslator(new Translator);

Assert::same('<label>LABEL</label>', (string) $input->getLabel());
Assert::same('<label>ANOTHER LABEL</label>', (string) $input->getLabel('Another label'));
Assert::same('<label for="frm-list-0">SECOND</label>', (string) $input->getLabelPart(0));
Assert::same('<label>Label</label>', (string) $input->getLabel());
Assert::same('<label>Another label</label>', (string) $input->getLabel('Another label'));
Assert::same('<label for="frm-list-0">Second</label>', (string) $input->getLabelPart(0));

Assert::same('<label><input type="checkbox" name="list[]" value="a">FIRST</label><br><label><input type="checkbox" name="list[]" value="0">SECOND</label>', $input->getControl());
Assert::same('<input type="checkbox" name="list[]" id="frm-list-0" value="0">', (string) $input->getControlPart(0));
Expand Down
4 changes: 2 additions & 2 deletions tests/Forms/Controls.MultiSelectBox.render.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ test(function() { // translator & groups
));
$input->setTranslator(new Translator);

Assert::same('<label for="frm-list">LABEL</label>', (string) $input->getLabel());
Assert::same('<label for="frm-list">ANOTHER LABEL</label>', (string) $input->getLabel('Another label'));
Assert::same('<label for="frm-list">Label</label>', (string) $input->getLabel());
Assert::same('<label for="frm-list">Another label</label>', (string) $input->getLabel('Another label'));
Assert::same('<select name="list[]" id="frm-list" multiple><option value="a">FIRST</option><optgroup label="GROUP"><option value="0">SECOND</option><option value="1">THIRD</option></optgroup></select>', (string) $input->getControl());
});

Expand Down
6 changes: 3 additions & 3 deletions tests/Forms/Controls.RadioList.render.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ test(function() { // translator
));
$input->setTranslator(new Translator);

Assert::same('<label>LABEL</label>', (string) $input->getLabel());
Assert::same('<label>ANOTHER LABEL</label>', (string) $input->getLabel('Another label'));
Assert::same('<label for="frm-list-0">SECOND</label>', (string) $input->getLabelPart(0));
Assert::same('<label>Label</label>', (string) $input->getLabel());
Assert::same('<label>Another label</label>', (string) $input->getLabel('Another label'));
Assert::same('<label for="frm-list-0">Second</label>', (string) $input->getLabelPart(0));

Assert::same('<label><input type="radio" name="list" value="a">FIRST</label><br><label><input type="radio" name="list" value="0">SECOND</label>', (string) $input->getControl());
Assert::same('<input type="radio" name="list" id="frm-list-0" value="0">', (string) $input->getControlPart(0));
Expand Down
4 changes: 2 additions & 2 deletions tests/Forms/Controls.SelectBox.render.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ test(function() { // translator & groups
))->setPrompt('Prompt');
$input->setTranslator(new Translator);

Assert::same('<label for="frm-list">LABEL</label>', (string) $input->getLabel());
Assert::same('<label for="frm-list">ANOTHER LABEL</label>', (string) $input->getLabel('Another label'));
Assert::same('<label for="frm-list">Label</label>', (string) $input->getLabel());
Assert::same('<label for="frm-list">Another label</label>', (string) $input->getLabel('Another label'));
Assert::same('<select name="list" id="frm-list"><option value="">PROMPT</option><option value="a">FIRST</option><optgroup label="GROUP"><option value="0">SECOND</option><option value="1">THIRD</option></optgroup></select>', (string) $input->getControl());
});

Expand Down
4 changes: 2 additions & 2 deletions tests/Forms/Controls.TextArea.render.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ test(function() { // translator
->setValue('text')
->setTranslator(new Translator);

Assert::same('<label for="frm-text">LABEL</label>', (string) $input->getLabel());
Assert::same('<label for="frm-text">ANOTHER LABEL</label>', (string) $input->getLabel('Another label'));
Assert::same('<label for="frm-text">Label</label>', (string) $input->getLabel());
Assert::same('<label for="frm-text">Another label</label>', (string) $input->getLabel('Another label'));
Assert::same('<textarea name="text" placeholder="PLACE" id="frm-text">text</textarea>', (string) $input->getControl());
});

Expand Down
4 changes: 2 additions & 2 deletions tests/Forms/Controls.TextInput.render.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ test(function() { // translator
->setTranslator(new Translator)
->setEmptyValue('xxx');

Assert::same('<label for="frm-text">LABEL</label>', (string) $input->getLabel());
Assert::same('<label for="frm-text">ANOTHER LABEL</label>', (string) $input->getLabel('Another label'));
Assert::same('<label for="frm-text">Label</label>', (string) $input->getLabel());
Assert::same('<label for="frm-text">Another label</label>', (string) $input->getLabel('Another label'));
Assert::same('<input type="text" name="text" placeholder="PLACE" id="frm-text" data-nette-empty-value="XXX" value="text">', (string) $input->getControl());
});

Expand Down
4 changes: 2 additions & 2 deletions tests/Forms/Controls.UploadControl.render.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ test(function() { // Html with translator
$input = $form->addUpload('file', 'Label');
$input->setTranslator(new Translator);

Assert::same('<label for="frm-file">LABEL</label>', (string) $input->getLabel());
Assert::same('<label for="frm-file">ANOTHER LABEL</label>', (string) $input->getLabel('Another label'));
Assert::same('<label for="frm-file">Label</label>', (string) $input->getLabel());
Assert::same('<label for="frm-file">Another label</label>', (string) $input->getLabel('Another label'));
Assert::same('<label for="frm-file"><b>Another label</b></label>', (string) $input->getLabel(Html::el('b', 'Another label')));
});

Expand Down

0 comments on commit 0e0b661

Please sign in to comment.