Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezi18noperator.php
Go to the documentation of this file.
1 <?php
13
17 class eZi18nOperator
18 {
26 public function __construct( $name = 'i18n', $extensionName = 'x18n', $dynamicName = 'd18n' )
27 {
28 $this->Operators = array( $name, $extensionName, $dynamicName );
29 $this->Name = $name;
30 $this->ExtensionName = $extensionName;
31 // d18n is a i18n alias for use with dynamic variables as input
32 // where you don't want ezlupdate to pick up the string
33 $this->DynamicName = $dynamicName;
34 }
35
39 function operatorList()
40 {
41 return $this->Operators;
42 }
43
47 function namedParameterPerOperator()
48 {
49 return true;
50 }
51
55 function namedParameterList()
56 {
57 $def = array( $this->Name => array( 'context' => array( 'type' => 'string',
58 'required' => false,
59 'default' => false ),
60 'comment' => array( 'type' => 'string',
61 'required' => false,
62 'default' => '' ),
63 'arguments' => array( 'type' => 'hash',
64 'required' => false,
65 'default' => false ) ),
66 $this->ExtensionName => array( 'extension' => array( 'type' => 'string',
67 'required' => true,
68 'default' => false ),
69 'context' => array( 'type' => 'string',
70 'required' => false,
71 'default' => false ),
72 'comment' => array( 'type' => 'string',
73 'required' => false,
74 'default' => '' ),
75 'arguments' => array( 'type' => 'hash',
76 'required' => false,
77 'default' => false ) ) );
78 $def[ $this->DynamicName ] = $def[ $this->Name ];
79 return $def;
80 }
81
82 function operatorTemplateHints()
83 {
84 $def = array( $this->Name => array( 'input' => true,
85 'output' => true,
86 'parameters' => true,
87 'element-transformation' => true,
88 'transform-parameters' => true,
89 'input-as-parameter' => 'always',
90 'element-transformation-func' => 'i18nTrans') );
91 $def[ $this->DynamicName ] = $def[ $this->Name ];
92 return $def;
93 }
94
95 function i18nTrans( $operatorName, &$node, $tpl, &$resourceData,
96 $element, $lastElement, $elementList, $elementTree, &$parameters )
97 {
98 // i18n( $input, $context, $comment, $arguments )
99 // Check if if the three first parameters are constants, if not we cannot compile it
100 foreach ( array_slice( $parameters, 0, 3 ) as $parameter )
101 {
102 if ( $parameter !== null &&
103 !eZTemplateNodeTool::isConstantElement( $parameter ) )
104 {
105 return false;
106 }
107 }
108
109 $value = eZTemplateNodeTool::elementConstantValue( $parameters[0] );
110
111 $numParameters = count ( $parameters );
112 $context = ( $numParameters > 1 ) ? eZTemplateNodeTool::elementConstantValue( $parameters[1] ) : null;
113 $comment = ( $numParameters > 2 ) ? eZTemplateNodeTool::elementConstantValue( $parameters[2] ) : null;
114
115 if ( $numParameters < 4 )
116 {
117 return array ( eZTemplateNodeTool::createStringElement( ezpI18n::tr( $context, $value, $comment, null ) ) );
118 }
119
120 $values = array();
121
122 $ini = eZINI::instance();
123 if ( $ini->variable( 'RegionalSettings', 'TextTranslation' ) != 'disabled' )
124 {
125 $language = eZLocale::instance()->localeFullCode();
126 if ( $language != "eng-GB" ) // eng-GB does not need translation
127 {
128 $file = 'translation.ts';
129 $ini = eZINI::instance();
130 $useCache = $ini->variable( 'RegionalSettings', 'TranslationCache' ) != 'disabled';
131 eZTSTranslator::initialize( $context, $language, $file, $useCache );
132
133 $man = eZTranslatorManager::instance();
134 $newValue = $man->translate( $context, $value, $comment );
135 if ( $newValue )
136 {
137 $value = $newValue;
138 }
139 }
140 }
141
142 $values[] = array( eZTemplateNodeTool::createStringElement( $value ) );
143 $values[] = $parameters[3];
144
145 $code = '%tmp1% = array();' . "\n" .
146 'foreach ( %2% as %tmp2% => %tmp3% )' . "\n" .
147 '{' . "\n" .
148 ' if ( is_int( %tmp2% ) )' . "\n" .
149 ' %tmp1%[\'%\' . ( (%tmp2%%9) + 1 )] = %tmp3%;' . "\n" .
150 ' else' . "\n" .
151 ' %tmp1%[%tmp2%] = %tmp3%;' . "\n" .
152 '}' . "\n" .
153 '%output% = strtr( %1%, %tmp1% );' . "\n";
154
155 return array( eZTemplateNodeTool::createCodePieceElement( $code, $values, false, 3 ) );
156 }
157
158 function modify( $tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$value, $namedParameters, $placement )
159 {
160 switch ( $operatorName )
161 {
162 case $this->Name:
163 case $this->DynamicName:
164 {
165 $context = $namedParameters['context'];
166 $comment = $namedParameters['comment'];
167 $arguments = $namedParameters['arguments'];
168 $value = ezpI18n::tr( $context, $value, $comment, $arguments );
169 } break;
170 case $this->ExtensionName:
171 {
172 $extension = $namedParameters['extension'];
173 $context = $namedParameters['context'];
174 $comment = $namedParameters['comment'];
175 $arguments = $namedParameters['arguments'];
176 $value = ezpI18n::tr( $context, $value, $comment, $arguments );
177 } break;
178 }
179 }
180
182 public $Operators;
183 public $Name;
184 public $ExtensionName;
185 public $DynamicName;
186 }
187
188 ?>
eZLocale\instance
static instance( $localeString=false)
Definition: ezlocale.php:1536
eZTSTranslator\initialize
static initialize( $context, $locale, $filename, $useCache=true)
Definition: eztstranslator.php:53
eZTemplateNodeTool\elementConstantValue
static elementConstantValue( $elements)
Definition: eztemplatenodetool.php:197
eZTemplateNodeTool\createCodePieceElement
static createCodePieceElement( $codePiece, $values=false, $placement=false, $tmpValues=false, $knownTypes=true)
Definition: eztemplatenodetool.php:437
eZTemplateNodeTool\createStringElement
static createStringElement( $string, $variablePlacement=false)
Definition: eztemplatenodetool.php:79
eZTemplateNodeTool\isConstantElement
static isConstantElement( $elements)
Definition: eztemplatenodetool.php:233
eZTranslatorManager\instance
static instance()
Definition: eztranslatormanager.php:127
eZi18nOperator
Definition: ezi18noperator.php:18
eZi18nOperator\operatorList
operatorList()
Definition: ezi18noperator.php:39
eZi18nOperator\$ExtensionName
$ExtensionName
Definition: ezi18noperator.php:184
eZi18nOperator\operatorTemplateHints
operatorTemplateHints()
Definition: ezi18noperator.php:82
eZi18nOperator\$Name
$Name
Definition: ezi18noperator.php:183
eZi18nOperator\__construct
__construct( $name='i18n', $extensionName='x18n', $dynamicName='d18n')
Definition: ezi18noperator.php:26
eZi18nOperator\$DynamicName
$DynamicName
Definition: ezi18noperator.php:185
eZi18nOperator\i18nTrans
i18nTrans( $operatorName, &$node, $tpl, &$resourceData, $element, $lastElement, $elementList, $elementTree, &$parameters)
Definition: ezi18noperator.php:95
eZi18nOperator\namedParameterPerOperator
namedParameterPerOperator()
Definition: ezi18noperator.php:47
eZi18nOperator\namedParameterList
namedParameterList()
Definition: ezi18noperator.php:55
eZi18nOperator\modify
modify( $tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$value, $namedParameters, $placement)
Definition: ezi18noperator.php:158
eZi18nOperator\$Operators
$Operators
Definition: ezi18noperator.php:182
ezpI18n\tr
static tr( $context, $source, $comment=null, $arguments=null)
Definition: ezpi18n.php:86
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.