cvs: pear /Translation2/Container gettext.php

From: Date: Fri, 12 Mar 2004 16:00:21 +0000
Subject: cvs: pear /Translation2/Container gettext.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-17347@lists.php.net to get a copy of this message
quipo Fri Mar 12 11:00:21 2004 EDT Modified files: /pear/Translation2/Container gettext.php Log: added switchLang() method http://cvs.php.net/diff.php/pear/Translation2/Container/gettext.php?r1=1.4&r2=1.5&ty=u Index: pear/Translation2/Container/gettext.php diff -u pear/Translation2/Container/gettext.php:1.4 pear/Translation2/Container/gettext.php:1.5 --- pear/Translation2/Container/gettext.php:1.4 Thu Mar 11 12:06:53 2004 +++ pear/Translation2/Container/gettext.php Fri Mar 12 11:00:21 2004 @@ -16,7 +16,7 @@ // | Author: Lorenzo Alberton <l dot alberton at quipo dot it> | // +----------------------------------------------------------------------+ // -// $Id: gettext.php,v 1.4 2004/03/11 17:06:53 quipo Exp $ +// $Id: gettext.php,v 1.5 2004/03/12 16:00:21 quipo Exp $ // require_once 'Translation2'.DIRECTORY_SEPARATOR.'Container.php'; @@ -26,7 +26,7 @@ * * @see /docs/gettext_readme.txt for an usage example * @package Translation2 - * @version $Revision: 1.4 $ + * @version $Revision: 1.5 $ */ class Translation2_Container_gettext extends Translation2_Container { @@ -106,6 +106,23 @@ } // }}} + // {{{ switchLang() + + /** + * @param string new langID + * @return string previous lang + */ + function switchLang($langID) + { + if (is_null($langID) || ($langID == $this->currentLang['id'])) { + return $this->currentLang['id']; + } + $oldLang = $this->currentLang['id']; + $this->setLang($langID); + return $oldLang; + } + + // }}} // {{{ fetchLangs() /** @@ -132,6 +149,7 @@ * Sets the current lang * * @param string $langID + * @return array Lang data */ function setLang($langID) { @@ -172,6 +190,7 @@ */ function getPage($pageID=null, $langID=null) { + $oldLang = $this->switchLang($langID); if (array_key_exists($this->currentLang['id'], $this->cachedDomains) && array_key_exists($pageID, $this->cachedDomains[$this->currentLang['id']]) ) { @@ -192,16 +211,18 @@ $domainPath = $this->_domains[$pageID] . DIRECTORY_SEPARATOR.$this->currentLang['id'] . DIRECTORY_SEPARATOR.'LC_MESSAGES'; - if (!file_exists($domainPath.DIRECTORY_SEPARATOR.$pageID.'.po')) { + $file = $domainPath.DIRECTORY_SEPARATOR.$pageID.'.po'; + if (!file_exists($file)) { return $this->raiseError( - 'cannot find file '.$domainPath.DIRECTORY_SEPARATOR.$pageID.'.po' - .' in '.__FILE__.' on line '.__LINE__, + 'cannot find file '.$file .' ['.__FILE__.' on line '.__LINE__.']', TRANSLATION2_ERROR_CANNOT_FIND_FILE ); } + $this->cachedDomains[$this->currentLang['id']][$pageID] = Translation2_Utils::po_parser($domainPath, $pageID); - return $this->cachedDomains[$this->currentLang['id']][$pageID]; + $langID = $this->switchLang($oldLang); + return $this->cachedDomains[$langID][$pageID]; } // }}} @@ -216,12 +237,7 @@ */ function getOne($stringID, $pageID=null, $langID=null) { - $langChanged = false; - if (!is_null($langID) && ($langID != $this->currentLang['id'])) { - $bkpLang = $this->currentLang['id']; - $langChanged = true; - $this->setLang($langID); - } + $oldLang = $this->switchLang($langID); if (is_null($pageID)) { textdomain($this->options['default_domain']); @@ -231,10 +247,7 @@ $string = gettext($stringID); - if ($langChanged) { - $this->setLang($bkpLang); - } - + $this->switchLang($oldLang); return $string; }

« previous php.pear.cvs (#17347) next »