Issues

ZF-8764: Zend_Form_Element_Submit translates the label twice.

Issue Type: Sub-task Created: 2010-01-10T04:52:03.000+0000 Last Updated: 2011-07-28T18:40:49.000+0000 Status: Resolved Fix version(s): - 1.11.10 (04/Aug/11)

Reporter: purple ankh (purpleankh) Assignee: Menno Luiten (mluiten) Tags: - Zend_Form

Related issues: - ZF-9010

Attachments: - ZF-8764.patch

Description

Using ZendFramework 1.10.0alpha1

A change in r18965 to Zend_Form_Element->getLabel() has added translation of the label at this stage.

However, Zend_Form_Element_Submit->getLabel() translates this value again:

<pre class="highlight">
    /**
     * Return label
     *
     * If no label is present, returns the currently set name.
     *
     * If a translator is present, returns the translated label.
     *
     * @return string
     */
    public function getLabel()
    {
        $value = parent::getLabel();

        if (null === $value) {
            $value = $this->getName();
        }

        if (null !== ($translator = $this->getTranslator())) {
            return $translator->translate($value);
        }

        return $value;
    }

This could lead to some very subtle mistranslation artefacts.

A possible fix would be to only translate if the label in Submit is retrieved from getName() as below:

<pre class="highlight">
    /**
     * Return label
     *
     * If no label is present, returns the currently set name.
     *
     * If a translator is present, returns the translated label.
     *
     * @return string
     */
    public function getLabel()
    {
        $value = parent::getLabel();

        if (null === $value) {
            $value = $this->getName();
            if (null !== ($translator = $this->getTranslator())) {
                return $translator->translate($value);
            }
        }

        return $value;
    }

Comments

Posted by Menno Luiten (mluiten) on 2010-01-12T07:37:14.000+0000

See attachment for a proposed patch and two unit tests. One to test for duplicate translation, and one to insure that an element name that is used as label is properly translated still.

Posted by purple ankh (purpleankh) on 2010-01-15T15:28:32.000+0000

Changed the affected version to 'Next Minor Release'. I had incorrectly used 'Next Mini Release' originally, which became 1.9.7 .

Posted by Holger Schletz (hschletz) on 2010-01-28T11:36:11.000+0000

Zend_Form_Decorator_Label is affected by the same issue as of 1.10.0. In fact, r18965 breaks every piece of code that translates the result of Zend_Form_Element::getLabel().

Posted by Christian Albrecht (alab) on 2010-03-12T03:56:23.000+0000

Here ZF-8694 is the description for Zend_Form_Decorator_Label, i mark that as duplicate, as well as ZF-9371

Posted by David Fuhr (davidfuhr) on 2011-07-27T09:33:29.000+0000

The issue exists still in the current trunk. I agree with the suggested patch. The translation is done in the parent::getLabel() and should only be repeated if the value is used as label.

Posted by Matthew Weier O'Phinney (matthew) on 2011-07-28T18:40:09.000+0000

Patch reviewed and applied to both trunk and the 1.11 release branch.

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts