[ Index ]
 

Code source de eZ Publish 3.9.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/kernel/common/ -> ezi18noperator.php (source)

   1  <?php
   2  //
   3  // Definition of eZi18nOperator class
   4  //
   5  // Created on: <18-Apr-2002 12:15:07 amos>
   6  //
   7  // SOFTWARE NAME: eZ publish
   8  // SOFTWARE RELEASE: 3.9.0
   9  // BUILD VERSION: 17785
  10  // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS
  11  // SOFTWARE LICENSE: GNU General Public License v2.0
  12  // NOTICE: >
  13  //   This program is free software; you can redistribute it and/or
  14  //   modify it under the terms of version 2.0  of the GNU General
  15  //   Public License as published by the Free Software Foundation.
  16  //
  17  //   This program is distributed in the hope that it will be useful,
  18  //   but WITHOUT ANY WARRANTY; without even the implied warranty of
  19  //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20  //   GNU General Public License for more details.
  21  //
  22  //   You should have received a copy of version 2.0 of the GNU General
  23  //   Public License along with this program; if not, write to the Free
  24  //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  25  //   MA 02110-1301, USA.
  26  //
  27  //
  28  
  29  //!! eZKernel
  30  //! The class eZi18nOperator does
  31  /*!
  32  
  33  */
  34  
  35  function make_seed() {
  36      list($usec, $sec) = explode(' ', microtime());
  37      return (float) $sec + ((float) $usec * 100000);
  38  }
  39  
  40  class eZi18nOperator
  41  {
  42      /*!
  43      */
  44      function eZi18nOperator( $name = 'i18n', $extensionName = 'x18n' )
  45      {
  46          $this->Operators = array( $name, $extensionName );
  47          $this->Name = $name;
  48          $this->ExtensionName = $extensionName;
  49      }
  50  
  51      /*!
  52       Returns the operators in this class.
  53      */
  54      function &operatorList()
  55      {
  56          return $this->Operators;
  57      }
  58  
  59      /*!
  60       \return true to tell the template engine that the parameter list exists per operator type.
  61      */
  62      function namedParameterPerOperator()
  63      {
  64          return true;
  65      }
  66  
  67      /*!
  68       See eZTemplateOperator::namedParameterList()
  69      */
  70      function namedParameterList()
  71      {
  72          return array( $this->Name => array( 'context' => array( 'type' => 'string',
  73                                                                  'required' => false,
  74                                                                  'default' => false ),
  75                                              'comment' => array( 'type' => 'string',
  76                                                                  'required' => false,
  77                                                                  'default' => '' ),
  78                                              'arguments' => array( 'type' => 'hash',
  79                                                                    'required' => false,
  80                                                                    'default' => false ) ),
  81                        $this->ExtensionName => array( 'extension' => array( 'type' => 'string',
  82                                                                             'required' => true,
  83                                                                             'default' => false ),
  84                                                       'context' => array( 'type' => 'string',
  85                                                                           'required' => false,
  86                                                                           'default' => false ),
  87                                                       'comment' => array( 'type' => 'string',
  88                                                                           'required' => false,
  89                                                                           'default' => '' ),
  90                                                       'arguments' => array( 'type' => 'hash',
  91                                                                             'required' => false,
  92                                                                             'default' => false ) ) );
  93      }
  94  
  95      function operatorTemplateHints()
  96      {
  97          return array( $this->Name => array( 'input' => true,
  98                                              'output' => true,
  99                                              'parameters' => true,
 100                                              'element-transformation' => true,
 101                                              'transform-parameters' => true,
 102                                              'input-as-parameter' => 'always',
 103                                              'element-transformation-func' => 'i18nTrans') );
 104      }
 105  
 106      function i18nTrans( $operatorName, &$node, &$tpl, &$resourceData,
 107                          &$element, &$lastElement, &$elementList, &$elementTree, &$parameters )
 108      {
 109          // i18n( $input, $context, $comment, $arguments )
 110          // Check if if the three first parameters are constants, if not we cannot compile it
 111          foreach ( array_slice( $parameters, 0, 3 ) as $parameter )
 112          {
 113              if ( $parameter !== null &&
 114                   !eZTemplateNodeTool::isConstantElement( $parameter ) )
 115              {
 116                  return false;
 117              }
 118          }
 119  
 120          include_once ( 'kernel/common/i18n.php' );
 121          $value = eZTemplateNodeTool::elementStaticValue( $parameters[0] );
 122  
 123          $numParameters = count ( $parameters );
 124          $context = ( $numParameters > 1 ) ? eZTemplateNodeTool::elementStaticValue( $parameters[1] ) : null;
 125          $comment = ( $numParameters > 2 ) ? eZTemplateNodeTool::elementStaticValue( $parameters[2] ) : null;
 126  
 127          if ( $numParameters < 4 )
 128          {
 129              return array ( eZTemplateNodeTool::createStringElement( ezi18n( $context, $value, $comment, null ) ) );
 130          }
 131  
 132          $values = array();
 133  
 134          $ini =& eZINI::instance();
 135          if ( $ini->variable( 'RegionalSettings', 'TextTranslation' ) != 'disabled' )
 136          {
 137              $language = ezcurrentLanguage();
 138              if ( $language != "eng-GB" ) // eng-GB does not need translation
 139              {
 140                  $file = 'translation.ts';
 141                  $ini =& eZINI::instance();
 142                  $useCache = $ini->variable( 'RegionalSettings', 'TranslationCache' ) != 'disabled';
 143                  eZTSTranslator::initialize( $context, $language, $file, $useCache );
 144  
 145                  $man =& eZTranslatorManager::instance();
 146                  $newValue = $man->translate( $context, $value, $comment );
 147                  if ( $newValue )
 148                  {
 149                      $value = $newValue;
 150                  }
 151              }
 152          }
 153  
 154          $values[] = array( eZTemplateNodeTool::createStringElement( $value ) );
 155          $values[] = $parameters[3];
 156  
 157          $code = '%tmp1% = array();' . "\n" .
 158               'foreach ( %2% as %tmp2% => %tmp3% )' . "\n" .
 159               '{' . "\n" .
 160               '  if ( is_int( %tmp2% ) )' . "\n" .
 161               '    %tmp1%[\'%\' . ( (%tmp2%%9) + 1 )] = %tmp3%;' . "\n" .
 162               '  else' . "\n" .
 163               '    %tmp1%[%tmp2%] = %tmp3%;' . "\n" .
 164               '}' . "\n" .
 165               '%output% = strtr( %1%, %tmp1% );' . "\n";
 166  
 167          return array( eZTemplateNodeTool::createCodePieceElement( $code, $values, false, 3 ) );
 168      }
 169  
 170      /*!
 171       \reimp
 172      */
 173      function modify( &$tpl, &$operatorName, &$operatorParameters, &$rootNamespace, &$currentNamespace, &$value, &$namedParameters )
 174      {
 175          include_once ( 'kernel/common/i18n.php' );
 176          switch ( $operatorName )
 177          {
 178              case $this->Name:
 179              {
 180                  $context = $namedParameters['context'];
 181                  $comment = $namedParameters['comment'];
 182                  $arguments = $namedParameters['arguments'];
 183                  $value = ezi18n( $context, $value, $comment, $arguments );
 184              } break;
 185              case $this->ExtensionName:
 186              {
 187                  $extension = $namedParameters['extension'];
 188                  $context = $namedParameters['context'];
 189                  $comment = $namedParameters['comment'];
 190                  $arguments = $namedParameters['arguments'];
 191                  $value = ezx18n( $extension, $context, $value, $comment, $arguments );
 192              } break;
 193          }
 194      }
 195  
 196      /// \privatesection
 197      var $Operators;
 198      var $Name;
 199      var $ExtensionName;
 200  };
 201  
 202  ?>


Généré le : Sat Feb 24 10:30:04 2007 par Balluche grâce à PHPXref 0.7