formRow View Helper does not recognize / utilize injected translator service #2551

Closed
zfbot opened this Issue Sep 28, 2012 · 6 comments

Projects

None yet

4 participants

zfbot commented Sep 28, 2012

Jira Information

Original Issue:ZF2-516
Issue Type:Bug
Reporter:Michael Romer
Created:09/03/12
Assignee:weierophinney
Components:Zend\Form

Description

The FormRow-Helper seems not to use a translator service present for the label portion:

        $this->add(array(
            'name' => 'username',
            'attributes' => array(
                'type'  => 'text',
            ),
            'options' => array(
                'label' => 'username',
            )
        ));
public function onBootstrap($e)
{
    \Locale::setDefault('de_DE');
}
echo $this->formRow($this->form->get('username')); 
echo $this->formLabel($this->form->get('username'));
Output incorrect: "username", even if translation available
Output correct: "Benutzername" (DE translation of "username")
zfbot commented Sep 28, 2012

(Originally posted by: froschdesign on 09/04/12)

Code tags added.

zfbot commented Sep 28, 2012

(Originally posted by: cgmartin on 09/05/12)

The FormLabel's translation functionality is covered with a unit test (and currently passing):
https://github.com/zendframework/zf2/blob/master/tests/ZendTest/Form/View/Helper/FormLabelTest.php#L145-L160

For the translator to automatically attach to the view helpers, the translator should be in the service locator. Example via config from the skeleton application:
https://github.com/zendframework/ZendSkeletonApplication/blob/master/module/Application/config/module.config.php#L60-L69

Here is the code that pulls it out of the service locator and attaches it to the view helpers (including FormLabel):
https://github.com/zendframework/zf2/blob/master/library/Zend/View/HelperPluginManager.php#L136-L144

Some things to check:

  • Confirm that the translator is set on the FormLabel helper: var_dump($this->formLabel()->getTranslator())
  • Do the translation text domains match?: var_dump($this->formLabel()->getTranslatorTextDomain())
  • Does the translation key match and exist in your DE translation file?

EDIT: Apologies, I just noticed your output of both FormRow and FormLabel together... I will set up a test here and take a look see. Thanks!

zfbot commented Sep 28, 2012

(Originally posted by: cgmartin on 09/05/12)

FormRow was not translating the label. Fixed in this PR:
#2300

zfbot commented Sep 28, 2012

This issue was ported from the ZF2 Jira Issue Tracker at
http://framework.zend.com/issues/browse/ZF2-516

Known GitHub users mentioned in the original message or comment:
@weierophinney, @froschdesign, @cgmartin

Contributor

@weierophinney @michael-romer i think this can be closed as well. Translation for labels in formRow works.

@Maks3w Maks3w closed this Mar 7, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment