* @author Kornel LesiƄski * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License * @version SVN: $Id: Source.php 605 2009-05-03 02:50:26Z kornel $ * @link http://phptal.org/ */ /** * i18n:source * * The i18n:source attribute specifies the language of the text to be * translated. The default is "nothing", which means we don't provide * this information to the translation services. * * * @package PHPTAL * @subpackage Php.attribute.i18n */ class PHPTAL_Php_Attribute_I18N_Source extends PHPTAL_Php_Attribute { public function before(PHPTAL_Php_CodeWriter $codewriter) { // ensure that a sources stack exists or create it $codewriter->doIf('!isset($_i18n_sources)'); $codewriter->pushCode('$_i18n_sources = array()'); $codewriter->end(); // push current source and use new one $codewriter->pushCode('$_i18n_sources[] = $_translator->setSource('.$codewriter->str($this->expression).')'); } public function after(PHPTAL_Php_CodeWriter $codewriter) { // restore source $code = '$_translator->setSource(array_pop($_i18n_sources))'; $codewriter->pushCode($code); } }