blob: 9575fae00f83667c1b248813535395960865458e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
<?php
/**
* PHPTAL templating engine
*
* PHP Version 5
*
* @category HTML
* @package PHPTAL
* @author Laurent Bedubourg <lbedubourg@motion-twin.com>
* @author Kornel Lesiński <kornel@aardvarkmedia.co.uk>
* @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
* @version SVN: $Id$
* @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[] = ' . $codewriter->getTranslatorReference(). '->setSource('.$codewriter->str($this->expression).')');
}
public function after(PHPTAL_Php_CodeWriter $codewriter)
{
// restore source
$code = $codewriter->getTranslatorReference().'->setSource(array_pop($_i18n_sources))';
$codewriter->pushCode($code);
}
}
|