Issues

ZF-5928: getList() returns only current value and not all available lanuages in case we use Zend_Translate+Zend_Cache

Description

According API docs: {quote} getList Zend_Translate_Adapter::getList() in Adapter.php Returns the available languages from this adapter {/quote}

But it returns only language code for current (default) cached language, instead of returning the list of all available languages in translation data source.

This is a problem for me as I'm using the getList() method to extract values and build the languages selectbox to allow user to select interface language.

Will attach the code to reproduce this error

Comments

according the attached code sample:

Refresh the page couple times and you will see only one language in the list, even if we have three languages available in translation data source.

Clear the cache and you will see all three languages in the list, but only for this time. Refresh again and you will see one language in the list again.

getList() returns all loaded languages. This is independently of which language has been set.

So when the language is not loaded, it will not be returned.

I expect that you are having problems eighter with your implementation or with your cache. I am not able to reproduce this behaviour on my system.

My implementation actually is a quite simple script with only 46 lines. You can find it in attached "zend_translate_problem.zip". Can you please try it? ( tmp/ subdirectory must be writable)

All code works great if we disable Zend_Cache

I've perfomed some debug using ZendDebuger and found the following:

  1. During the first run of the script, Zend_Translate_Adapter loads the metadata (available languages) from translation source (TMX file in my case), and tranlation data only for current language (locale).

Then it writes all information into cache using Zend_Cache instance. As only current locale data was loaded then we have translation information cached only for one (current) locale.

  1. After we refresh the page, - Zend_Translate loads data from cache now and not from original translation data source. So we receiving only one language available in ->getList() method because we have cached information for one locale.

I've found this code in Zend/Translate/Adapter.php

{{monospaced}} if (isset(self::$cache)) { $id = 'Zend_Translate' . preg_replace('/[^a-zA-Z0-9_]/', '', $data) . '' . $locale . '_' . $this->toString(); $result = self::$_cache->load($id); if ($result) { $this->_translate[$locale] = unserialize($result); $read = false; } }

    if ($read) {
        $this->_loadTranslationData($data, $locale, $options);
    }

{{monospaced}}

If cache exists it loads the information from cache and "$read = false;" indicates that we don't need to read translation source file. Here is our issue: We have information only for ONE locale in the cache, and there is no any information about other locales available in the cache. Thats why when we calling ->getList() method we receiving only one available language instead of the list of available languages.

I can reproduce this on my clear install of ZendServer + WinXP + ZF 1.8dev (lates co from SVN)

I saw your last commit according this issue. I've tested new code and it looks OK right now, so I think the issue can be closed. Thanks.

Reworked cache handling with r14274 which solves also this issue.