00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 function make_seed() {
00038 list($usec, $sec) = explode(' ', microtime());
00039 return (float) $sec + ((float) $usec * 100000);
00040 }
00041
00042 include_once( 'lib/ezi18n/classes/eztranslatormanager.php' );
00043 include_once( 'lib/ezi18n/classes/eztstranslator.php' );
00044
00045 class eZi18nOperator
00046 {
00047
00048
00049 function eZi18nOperator( $name = 'i18n', $extensionName = 'x18n' )
00050 {
00051 $this->Operators = array( $name, $extensionName );
00052 $this->Name = $name;
00053 $this->ExtensionName = $extensionName;
00054 }
00055
00056
00057
00058
00059 function &operatorList()
00060 {
00061 return $this->Operators;
00062 }
00063
00064
00065
00066
00067 function namedParameterPerOperator()
00068 {
00069 return true;
00070 }
00071
00072
00073
00074
00075 function namedParameterList()
00076 {
00077 return array( $this->Name => array( 'context' => array( 'type' => 'string',
00078 'required' => false,
00079 'default' => false ),
00080 'comment' => array( 'type' => 'string',
00081 'required' => false,
00082 'default' => '' ),
00083 'arguments' => array( 'type' => 'hash',
00084 'required' => false,
00085 'default' => false ) ),
00086 $this->ExtensionName => array( 'extension' => array( 'type' => 'string',
00087 'required' => true,
00088 'default' => false ),
00089 'context' => array( 'type' => 'string',
00090 'required' => false,
00091 'default' => false ),
00092 'comment' => array( 'type' => 'string',
00093 'required' => false,
00094 'default' => '' ),
00095 'arguments' => array( 'type' => 'hash',
00096 'required' => false,
00097 'default' => false ) ) );
00098 }
00099
00100 function operatorTemplateHints()
00101 {
00102 return array( $this->Name => array( 'input' => true,
00103 'output' => true,
00104 'parameters' => true,
00105 'element-transformation' => true,
00106 'transform-parameters' => true,
00107 'input-as-parameter' => 'always',
00108 'element-transformation-func' => 'i18nTrans') );
00109 }
00110
00111 function i18nTrans( $operatorName, &$node, &$tpl, &$resourceData,
00112 &$element, &$lastElement, &$elementList, &$elementTree, &$parameters )
00113 {
00114
00115
00116 foreach ( array_slice( $parameters, 0, 3 ) as $parameter )
00117 {
00118 if ( $parameter !== null &&
00119 !eZTemplateNodeTool::isConstantElement( $parameter ) )
00120 {
00121 return false;
00122 }
00123 }
00124
00125 include_once( 'kernel/common/i18n.php' );
00126 $value = eZTemplateNodeTool::elementStaticValue( $parameters[0] );
00127
00128 $numParameters = count ( $parameters );
00129 $context = ( $numParameters > 1 ) ? eZTemplateNodeTool::elementStaticValue( $parameters[1] ) : null;
00130 $comment = ( $numParameters > 2 ) ? eZTemplateNodeTool::elementStaticValue( $parameters[2] ) : null;
00131
00132 if ( $numParameters < 4 )
00133 {
00134 return array ( eZTemplateNodeTool::createStringElement( ezi18n( $context, $value, $comment, null ) ) );
00135 }
00136
00137 $values = array();
00138
00139 $ini =& eZINI::instance();
00140 if ( $ini->variable( 'RegionalSettings', 'TextTranslation' ) != 'disabled' )
00141 {
00142 $language = ezcurrentLanguage();
00143 if ( $language != "eng-GB" )
00144 {
00145 $file = 'translation.ts';
00146 $ini =& eZINI::instance();
00147 $useCache = $ini->variable( 'RegionalSettings', 'TranslationCache' ) != 'disabled';
00148 eZTSTranslator::initialize( $context, $language, $file, $useCache );
00149
00150 $man =& eZTranslatorManager::instance();
00151 $newValue = $man->translate( $context, $value, $comment );
00152 if ( $newValue )
00153 {
00154 $value = $newValue;
00155 }
00156 }
00157 }
00158
00159 $values[] = array( eZTemplateNodeTool::createStringElement( $value ) );
00160 $values[] = $parameters[3];
00161
00162 $code = '%tmp1% = array();' . "\n" .
00163 'foreach ( %2% as %tmp2% => %tmp3% )' . "\n" .
00164 '{' . "\n" .
00165 ' if ( is_int( %tmp2% ) )' . "\n" .
00166 ' %tmp1%[\'%\' . ( (%tmp2%%9) + 1 )] = %tmp3%;' . "\n" .
00167 ' else' . "\n" .
00168 ' %tmp1%[%tmp2%] = %tmp3%;' . "\n" .
00169 '}' . "\n" .
00170 '%output% = strtr( %1%, %tmp1% );' . "\n";
00171
00172 return array( eZTemplateNodeTool::createCodePieceElement( $code, $values, false, 3 ) );
00173 }
00174
00175
00176
00177
00178 function modify( &$tpl, &$operatorName, &$operatorParameters, &$rootNamespace, &$currentNamespace, &$value, &$namedParameters )
00179 {
00180 include_once( 'kernel/common/i18n.php' );
00181 switch ( $operatorName )
00182 {
00183 case $this->Name:
00184 {
00185 $context = $namedParameters['context'];
00186 $comment = $namedParameters['comment'];
00187 $arguments = $namedParameters['arguments'];
00188 $value = ezi18n( $context, $value, $comment, $arguments );
00189 } break;
00190 case $this->ExtensionName:
00191 {
00192 $extension = $namedParameters['extension'];
00193 $context = $namedParameters['context'];
00194 $comment = $namedParameters['comment'];
00195 $arguments = $namedParameters['arguments'];
00196 $value = ezx18n( $extension, $context, $value, $comment, $arguments );
00197 } break;
00198 }
00199 }
00200
00201
00202 var $Operators;
00203 var $Name;
00204 var $ExtensionName;
00205 };
00206
00207 ?>