Blame view

mobile/source/ext/phptal/PHPTAL/Php/Attribute/I18N/Domain.php 1.51 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
48
49
  <?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: Domain.php 671 2009-07-11 18:11:35Z kornel $
   * @link     http://phptal.org/
   */
  
  /**
   * i18n:domain
   *
   * The i18n:domain attribute is used to specify the domain to be used to get
   * the translation. If not specified, the translation services will use a
   * default domain. The value of the attribute is used directly; it is not
   * a TALES expression.
   *
   * @package PHPTAL
   * @subpackage Php.attribute.i18n
   */
  class PHPTAL_Php_Attribute_I18N_Domain extends PHPTAL_Php_Attribute
  {
      public function before(PHPTAL_Php_CodeWriter $codewriter)
      {
          // ensure a domain stack exists or create it
          $codewriter->doIf('!isset($_i18n_domains)');
          $codewriter->pushCode('$_i18n_domains = array()');
          $codewriter->doEnd('if');
  
          $expression = $codewriter->interpolateTalesVarsInString($this->expression);
  
          // push current domain and use new domain
          $code = '$_i18n_domains[] = $_translator->useDomain('.$expression.')';
          $codewriter->pushCode($code);
      }
  
      public function after(PHPTAL_Php_CodeWriter $codewriter)
      {
          // restore domain
          $code = '$_translator->useDomain(array_pop($_i18n_domains))';
          $codewriter->pushCode($code);
      }
  }