Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 2.0.4

Bug #2972 cache_lite decorator not handling param sub as expected
Submitted: 2004-12-15 18:21 UTC
From: michael dot caplan at lechateau dot ca Assigned: quipo
Status: Closed Package: Translation2
PHP Version: 5.0.2 OS: irrelevant
Roadmaps: (Not assigned)    
Subscription  


 [2004-12-15 18:21 UTC] michael dot caplan at lechateau dot ca
Description: ------------ with the cache_light decorator, parameter substiution does not work as expected (at least what I expected). With caching on, I expect multiple calls to fetch a translation string to do parameter substitution each time. Instead, the first cached string is alwasy returned, which defeats the purpose of parameter substitution.

Comments

 [2004-12-15 19:19 UTC] michael dot caplan at lechateau dot ca
For what it is worth, here a patch (it's a really rough patch that doesn't fully take into consideration the different ways that the Cache_Lite_Function::call() method can be invoked. But, as a temporary messure it works): =================================================================== RCS file: /prod/cvs/intranet_3/lib/Translation2/Decorator/CacheLiteFunction.php,v retrieving revision 1.5 retrieving revision 1.3 diff -p --unified=3 -r1.5 -r1.3 --- CacheLiteFunction.php 2004/12/15 19:16:44 1.5 +++ CacheLiteFunction.php 2004/11/29 17:46:53 1.3 @@ -16,11 +16,11 @@ // | Authors: Lorenzo Alberton <l dot alberton at quipo dot it> | // +----------------------------------------------------------------------+ // -// $Id: CacheLiteFunction.php,v 1.5 2004/12/15 19:16:44 michael Exp $ +// $Id: CacheLiteFunction.php,v 1.3 2004/11/29 17:46:53 michael Exp $ // /** * @package Translation2 - * @version $Id: CacheLiteFunction.php,v 1.5 2004/12/15 19:16:44 michael Exp $ + * @version $Id: CacheLiteFunction.php,v 1.3 2004/11/29 17:46:53 michael Exp $ */ /** * Load Translation2 decorator base class @@ -156,9 +156,8 @@ class Translation2_Decorator_CacheLiteFu global ${$this->tempVarName}; // WITHOUT THIS, IT DOESN'T WORK ${$this->tempVarName} = $this->translation2; - $return = $this->cacheLiteFunction->call($this->tempVarName.'->get', - $stringID, $pageID, $langID, $defaultText, false); - return $this->translation2->_replaceParams($return); + return $this->cacheLiteFunction->call($this->tempVarName.'->get', + $stringID, $pageID, $langID, $defaultText); } // }}} =================================================================== RCS file: /prod/cvs/intranet_3/lib/Translation2.php,v retrieving revision 1.3 retrieving revision 1.4 diff -bB -p --unified=3 -r1.3 -r1.4 --- Translation2.php 2004/11/29 17:47:45 1.3 +++ Translation2.php 2004/12/15 18:55:30 1.4 @@ -16,11 +16,11 @@ // | Authors: Lorenzo Alberton <l dot alberton at quipo dot it> | // +----------------------------------------------------------------------+ // -// $Id: Translation2.php,v 1.3 2004/11/29 17:47:45 michael Exp $ +// $Id: Translation2.php,v 1.4 2004/12/15 18:55:30 michael Exp $ // /** * @package Translation2 - * @version $Id: Translation2.php,v 1.3 2004/11/29 17:47:45 michael Exp $ + * @version $Id: Translation2.php,v 1.4 2004/12/15 18:55:30 michael Exp $ */ /** @@ -396,16 +396,21 @@ class Translation2 * @param string $langID * @param string $defaultText Text to display when the strings in both * the default and the fallback lang are empty + * @param boolean $replace Should string parameter replacing take place (default true) * @return string */ - function get($stringID, $pageID=TRANSLATION2_DEFAULT_PAGEID, $langID=null, $defaultText='') + function get($stringID, $pageID=TRANSLATION2_DEFAULT_PAGEID, $langID=null, $defaultText='', $replace = true) { $pageID = ($pageID == TRANSLATION2_DEFAULT_PAGEID ? $this->currentPageID : $pageID); $str = $this->storage->getOne($stringID, $pageID, $langID); if (PEAR::isError($str)) { return $str; } + if ($replace) { return $this->_replaceParams($str); + } else { + return $str; + } } // }}}
 [2004-12-15 19:20 UTC] michael dot caplan at lechateau dot ca
ignore comment about Cache_Lite_Function::call() That would be part of the cache_light pacakge.
 [2004-12-15 22:57 UTC] michael dot caplan at lechateau dot ca
sorry about the messed up summary. IE auto-populated the summary using an old filed bug
 [2004-12-15 23:00 UTC] quipo
can you send me a reproducing script? Thanks
 [2004-12-16 00:50 UTC] michael dot caplan at lechateau dot ca
This is pretty much exactly what I am doing: $fw_tr =& Translation2::factory('mdb2', &$fw_db, $fw_tr_params); if (PEAR::isError($fw_tr)) { trigger_error($fw_tr->getMessage . $fw_tr->GetUserInfo(), E_USER_ERROR); die(); } // set default translation lang $fw_lang = (is_null($fw_locale)) ? $fw_ini['locales.locale']['default_locale'] : $fw_locale; $fw_lang = strtolower(substr($fw_lang, 0, 2)); $fw_tr->setLang($fw_lang); $fw_tr->setPageID(); // set translation caching $fw_tr =& $fw_tr->getDecorator('CacheLiteFunction'); define('TR_CACHE_DIR', ROOT . DIR_SEP . 'cache' . DIR_SEP . 'translation' . DIR_SEP); $fw_tr->setOption('cacheDir', TR_CACHE_DIR); $fw_tr->setOption('lifeTime', 3600*24); //one day $fw_tr->setOption('autoCleanCache', true); // set fallback language $fw_lang_fallback = ($fw_ini['locales.locale']['default_locale'] != $fw_locale) ? $fw_locale : 'en_CA'; $fw_lang_fallback = strtolower(substr($fw_lang_fallback, 0, 2)); $fw_tr =& $fw_tr->getDecorator('Lang'); $fw_tr->setOption('fallbackLang', $fw_lang_fallback); // set default text $fw_tr =& $fw_tr->getDecorator('DefaultText'); $fw_tr->setOption('emptyPrefix', '['); //mark empty strings $fw_tr->setOption('emptyPostfix', ']'); //enclose them within brackets $fw_tr->setParams(array('collection' => $collection)); $results[] = $fw_tr->get('result_restored'); $fw_tr->setParams(array('collection' => $collection2)); $results[] = $fw_tr->get('result_restored'); $fw_tr->setParams(array('collection' => $collection3)); $results[] = $fw_tr->get('result_restored'); Where results_restored is something like 'Collection &&collection&& has been restored.'
 [2004-12-16 19:08 UTC] quipo
This bug has been fixed in CVS. In case this was a documentation problem, the fix will show up at the end of next Sunday (CET) on pear.php.net. In case this was a pear.php.net website problem, the change will show up on the website in short time. Thank you for the report, and for helping us make PEAR better.