Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

Closed
zfbot opened this Issue · 6 comments

4 participants

Zend Framework DevTeam Martin Keckeis Matthew Weier O'Phinney Maks3w
Zend Framework DevTeam
Owner

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")
Zend Framework DevTeam
Owner

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

Code tags added.

Zend Framework DevTeam
Owner

(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!

Zend Framework DevTeam
Owner

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

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

Zend Framework DevTeam
Owner

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

Martin Keckeis

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

Maks3w Maks3w closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.