Issues

ZF-10300: Label gets translated twice

Issue Type: Bug Created: 2010-08-12T03:21:46.000+0000 Last Updated: 2011-12-01T12:26:31.000+0000 Status: Closed Fix version(s): Reporter: Markus Lanz (stahlstift) Assignee: Christian Albrecht (alab) Tags: - Zend_Form

Related issues: - ZF-8694

Attachments:

Description

For Example the message 'my.namespace.country.germany' will translate to 'Deutschland' and then it tries to translate 'Deutschland' again.

As far as I debugged the problem is relativ easy to solve:

Update: Also Zend_Form_Element_Submit uses the already translated Label

<pre class="highlight">
/**
     * Retrieve element label
     *
     * @return string
     */
    public function getLabel()
    {
        $translator = $this->getTranslator();
        if (null !== $translator) {
            return $translator->translate($this->_label);
        }

        return $this->_label;
    }



<pre class="highlight">
/**
     * Get label to render
     *
     * @return void
     */
    public function getLabel()
    {
        if (null === ($element = $this->getElement())) {
            return '';
        }

        $label = $element->getLabel();
        $label = trim($label);

        if (empty($label)) {
            return '';
        }

        if (null !== ($translator = $element->getTranslator())) {
            $label = $translator->translate($label);
        }

        $optPrefix = $this->getOptPrefix();
        $optSuffix = $this->getOptSuffix();
        $reqPrefix = $this->getReqPrefix();
        $reqSuffix = $this->getReqSuffix();
        $separator = $this->getSeparator();

        if (!empty($label)) {
            if ($element->isRequired()) {
                $label = $reqPrefix . $label . $reqSuffix;
            } else {
                $label = $optPrefix . $label . $optSuffix;
            }
        }

        return $label;
    }



<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;
    }

As you can see getLabel() from Zend_Form_Element will translate the string and getLabel() from Zend_Form_Element_Decorator translates the already translated string again

Comments

Posted by Markus Lanz (stahlstift) on 2010-08-12T03:26:22.000+0000

A simple fix would be to remove the translation of getLabel() from the decorator, which is also in my opinion a sideeffect.

A fecorator should decorate...

Posted by Thomas Weidner (thomas) on 2010-08-12T04:01:03.000+0000

Detaching Zend_Translate from the affected components.

The problem is not related to Zend_Translate as it translates whatever Zend_Form gives to be translated. There is no way for Zend_Translate to know if that string, which is given, is already translated, or if it's just an untranslated source string.

Posted by Saman Darougheh (excuvator) on 2010-09-27T05:31:56.000+0000

agree with markus - its simply the decorator that is overtaking irrelevant functions. He should decorate, not change content.

Posted by Saman Darougheh (excuvator) on 2010-09-27T05:35:53.000+0000

as i cannot edit my comment:

1 remove translating from decorator

2 move the conditional translation inside submit-element (ll 80-82 inside the $value === null condition before (ll76-78).

Posted by Tobias Stanzel (fctst) on 2010-10-27T05:33:14.000+0000

i run over the same problem, when i wrote a tool to list all untranslated id for me.

Imho the decorator should not change but decorate the content, so removing the translation from it makes sense. The translation is done by the element allready

Posted by Daniel Schroeren (adelius) on 2011-06-16T12:24:01.000+0000

i stumbled upon this issue while i was writing a custom Zend_Translate_Adapter which is able to organize the translations in my db and uses the logging to collect missing translations. fixed this issue as described above.

Posted by Adam Lundrigan (adamlundrigan) on 2011-12-01T12:26:31.000+0000

Duplicate of ZF-8694. A fix has been proposed there.

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