Issues

ZF-7214: addTranslation 'clear' option is sticky!

Issue Type: Bug Created: 2009-07-07T05:01:24.000+0000 Last Updated: 2009-08-25T13:01:25.000+0000 Status: Resolved Fix version(s): - 1.10.0 (27/Jan/10)

Reporter: Yisrael Dov (yisraeldov) Assignee: Thomas Weidner (thomas) Tags: - Zend_Translate

Related issues: Attachments:

Description

When using the Zend_Translate_Adapter->addTranslation() with the 'clear' option. The clear option sticks and data never gets set.

here is my work around: {quote} $adapter->addTranslation($data,$locale,array('clear'=>true)); //due to a bug in zend , 'clear' is sticky, so we need to unset it ! $adapter->addTranslation($data,$locale,array('clear'=>false)); //now you can add more data {quote}

This might be only in the gettext adapter

Comments

Posted by Thomas Weidner (thomas) on 2009-07-07T05:13:45.000+0000

What do you mean with "sticky" ?

The clear options erases previous set data so only the newly given data is available. It works only for the given locale.

Additionally all set options are internally stored so they don't have to be given again as this would not work when searching through directory structures.

Posted by Thomas Weidner (thomas) on 2009-07-07T05:14:57.000+0000

Changing priority as it does not block behaviour.

Posted by Yisrael Dov (yisraeldov) on 2009-07-07T05:20:56.000+0000

actually it does block behavior.

if you call:

$adapter->addTranslation($data,$locale,array('clear'=>true));

and then call

$adapter->addTranslation($data2,$locale);

the second call will also have option['clear'] set to true. That means that $data2 will overwrite $data.

even worse than this $data and $data2 will be cleared immediately and the translation adapter will have no data!

Posted by Thomas Weidner (thomas) on 2009-07-07T05:39:41.000+0000

Again: This is expected behaviour.

Options are set and stored so they don't have to be given again as described before. A simple call of setOptions() does also set options but will not add data.

And the translation adapter does not have no data... the data which are read with the call of addTranslation are always available even if you give the 'clear' option.

Posted by Thomas Weidner (thomas) on 2009-07-07T08:04:27.000+0000

Also to mention as I just saw it:

The input $data and $data2 is not touched by Zend_Translate. It does not delete given data, it could just access it's own data.

What you described is not possible by Zend_Translate. I expect that you access and delete your input data in another way.

Posted by Yisrael Dov (yisraeldov) on 2009-07-08T03:29:54.000+0000

Here I will show an example that might make it more clear :

<pre class="highlight">
    if(is_readable($data)){
        print_r($adapter->getMessageIds());
        /*
        Outputs:
        Array
        (
            [0] => afghanistan
            [1] => aland_islands
            ...
            [310] => wrong_phone_length
            [311] => missingToken
            [312] => notSame
        )
        */
        $adapter->addTranslation($data,$locale,array('clear'=>true));
        //due to a bug in zend , 'clear' is sticky, so we need to unset it !
        //$adapter->addTranslation($data,$locale,array('clear'=>false));
        print_r($adapter->getOptions());
        /*
        Array
        (
            [clear] => 1
            [disableNotices] => 
            [ignore] => .
            [locale] => he
            [log] => 
            [logMessage] => Untranslated message within '%locale%': %message%
            [logUntranslated] => 1
            [scan] => filename
            [automatic] => 
        )
        */
        print_r($adapter->getMessageIds());
        /*
        Array
        (
        )
        NO KEYS !!
        */
    }
    //add shared translations
    $data = $data = APPLICATION_PATH . "/languages/shared"; 
    if(is_readable($data)){
        $adapter->addTranslation($data,$adapter->getLocale());
        print_r($adapter->getOptions());
        /*
        Array
        (
            [clear] => 1
            [disableNotices] => 
            [ignore] => .
            [locale] => ru
            [log] => 
            [logMessage] => Untranslated message within '%locale%': %message%
            [logUntranslated] => 1
            [scan] => filename
            [automatic] => 
        )
        
        (some how the locale changed !?)
        */
        
        print_r($adapter->getMessageIds());
        /*
        Array
        (
        )
        STILL NO KEYS !!
        */
    }

In the above example my fix was commented out.

The expected behaviour when using clear, is that the old data will be replaced but the new data. Not that it will remain with no data at all!

Additionally I would expect that the clear would only happen once, not every time I call addTranslation.

But if I use my fix it works like expected.

<pre class="highlight">
    if(is_readable($data)){
        print_r($adapter->getMessageIds());
        /*
        Outputs:
        Array
        (
            [0] => afghanistan
            [1] => aland_islands
            ...
            [310] => wrong_phone_length
            [311] => missingToken
            [312] => notSame
        )
        */
        $adapter->addTranslation($data,$locale,array('clear'=>true));
        //due to a bug in zend , 'clear' is sticky, so we need to unset it !
        $adapter->addTranslation($data,$locale,array('clear'=>false));
        print_r($adapter->getOptions());
        /*
        Array
        (
            [clear] => 
            [disableNotices] => 
            [ignore] => .
            [locale] => en
            [log] => 
            [logMessage] => Untranslated message within '%locale%': %message%
            [logUntranslated] => 1
            [scan] => filename
            [automatic] => 
        )
        */
        print_r($adapter->getMessageIds());
        /*
        Array
        (
            [0] => Continue
            [1] => Give Super Forex Your money.
            [2] => Super Forex
            [3] => SuperFX
            [4] => Your email
        )
        Now we have KEYS !!
        */
    }
    //add shared translations
    $data = $data = APPLICATION_PATH . "/languages/shared"; 
    if(is_readable($data)){
        $adapter->addTranslation($data,$adapter->getLocale());
        print_r($adapter->getOptions());
        /*
        Array
        (
            [clear] => 
            [disableNotices] => 
            [ignore] => .
            [locale] => en
            [log] => 
            [logMessage] => Untranslated message within '%locale%': %message%
            [logUntranslated] => 1
            [scan] => filename
            [automatic] => 
        )
        
        (now the locale also stayed the same)
        */
        
        print_r($adapter->getMessageIds());
        /*
        Array
        (
            [0] => Continue
            [1] => Give Super Forex Your money.
            [2] => Super Forex
            [3] => SuperFX
            [4] => Your email
            [5] => afghanistan
            [6] => aland_islands
            ...
            [314] => wrong_phone_length
            [315] => missingToken
            [316] => notSame
        )
            
        Now we have keys from BOTH data sources!
        */
    }

Let me know if this is still not clear.

(Additionally if the intended behaviour of the 'clear' option was to leave the adapter without any data, then the data paramater should not be required!)

Posted by Yisrael Dov (yisraeldov) on 2009-07-08T03:56:11.000+0000

I've noticed this problem also in 1.8.1 and 1.8.4

Posted by Thomas Weidner (thomas) on 2009-08-25T13:01:24.000+0000

Fixed with r17813

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