Blame view

mobile/source/ext/phptal/PHPTAL/Php/Attribute/I18N/Source.php 1.37 KB
a1684257   Administrator   first commit
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
  <?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: 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);
      }
  }