Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

eztranslatormanager.php
Go to the documentation of this file.
1 <?php
31 class eZTranslatorManager
32 {
33 const DYNAMIC_TRANSLATIONS_ENABLED = 'eZTMDynamicTranslationsEnabled';
34
35 public function __construct()
36 {
37 $this->Handlers = array();
38 }
39
51 function findKey( $key )
52 {
53 $msg = null;
54 for ( $i = 0; $i < count( $this->Handlers ) and $msg === null; ++$i )
55 {
56 $handler = $this->Handlers[$i];
57 if ( $handler->isKeyBased() )
58 $msg = $handler->findKey( $key );
59 }
60 return $msg;
61 }
62
72 function findMessage( $context, $source, $comment = null )
73 {
74 if ( !is_string( $context ) or $context == "" )
75 $context = "default";
76 $msg = null;
77 for ( $i = 0; $i < count( $this->Handlers ) and $msg === null; ++$i )
78 {
79 $handler = $this->Handlers[$i];
80 $msg = $handler->findMessage( $context, $source, $comment );
81 }
82 return $msg;
83 }
84
93 function keyTranslate( $key )
94 {
95 $trans = null;
96 for ( $i = 0; $i < count( $this->Handlers ) and $trans === null; ++$i )
97 {
98 $handler = $this->Handlers[$i];
99 if ( $handler->isKeyBased() )
100 $trans = $handler->keyTranslate( $key );
101 }
102 return $trans;
103 }
104
110 function translate( $context, $source, $comment = null )
111 {
112 if ( !is_string( $context ) or $context == "" )
113 $context = "default";
114 $trans = null;
115 for ( $i = 0; $i < count( $this->Handlers ) and $trans === null; ++$i )
116 {
117 $handler = $this->Handlers[$i];
118 $trans = $handler->translate( $context, $source, $comment );
119 }
120 return $trans;
121 }
122
128 static function instance()
129 {
130 if ( empty( $GLOBALS['eZTranslatorManagerInstance'] ) )
131 {
132 $GLOBALS['eZTranslatorManagerInstance'] = new eZTranslatorManager();
133 }
134 return $GLOBALS['eZTranslatorManagerInstance'];
135 }
136
141 static function registerHandler( $handler )
142 {
143 $instance = eZTranslatorManager::instance();
144 $instance->Handlers[] = $handler;
145 }
146
151 static function createKey( $context, $source, $comment = null )
152 {
153 if ( $comment === null )
154 $comment = "";
155 return md5( "$context\n$source\n$comment" );
156 }
157
163 static function createMessage( $context, $source, $comment = null, $translation = null )
164 {
165 $msg = array( "context" => $context,
166 "source" => $source,
167 "comment" => $comment,
168 "translation" => $translation );
169 return $msg;
170 }
171
175 static function resetGlobals()
176 {
177 unset( $GLOBALS["eZTranslatorManagerInstance"] );
178 }
179
183 static function resetTranslations()
184 {
185 eZTranslatorManager::resetGlobals();
186 eZTSTranslator::resetGlobals();
187 eZLocale::resetGlobals();
188 eZTranslationCache::resetGlobals();
189 }
190
194 static function dynamicTranslationsEnabled()
195 {
196 return isset( $GLOBALS[self::DYNAMIC_TRANSLATIONS_ENABLED] );
197 }
198
202 static function enableDynamicTranslations( $enable = true )
203 {
204 if ( $enable )
205 {
206 $GLOBALS[self::DYNAMIC_TRANSLATIONS_ENABLED] = true;
207 }
208 else
209 {
210 unset( $GLOBALS[self::DYNAMIC_TRANSLATIONS_ENABLED] );
211 }
212 }
213
217 static function setActiveTranslation( $locale, $permanently = true )
218 {
219 if( !eZTranslatorManager::dynamicTranslationsEnabled() )
220 return;
221
222 if ( $permanently )
223 $siteINI = eZINI::instance( 'site.ini.append', 'settings/override', null, null, false, true );
224 else
225 $siteINI = eZINI::instance();
226
227 $siteINI->setVariable( 'RegionalSettings', 'Locale', $locale );
228 $siteINI->setVariable( 'RegionalSettings', 'TextTranslation', 'enabled' );
229
230 if ( $permanently )
231 {
232 $siteINI->save( 'site.ini.append', '.php', false, false );
233 eZINI::resetInstance( "site.ini" );
234 }
235
236 eZTranslatorManager::resetTranslations();
237 }
238
239
240
243 public $Handlers;
244 }
245
246 ?>
$locale
$locale
Definition: admin/adlist.php:127
$i
$i
Definition: admin/adlist.php:91
eZTSTranslator\resetGlobals
static resetGlobals()
Definition: eztstranslator.php:720
eZTranslationCache\resetGlobals
static resetGlobals()
Definition: eztranslationcache.php:207
eZTranslatorManager
This provides internationalization support for text output.
Definition: eztranslatormanager.php:32
eZTranslatorManager\findMessage
findMessage( $context, $source, $comment=null)
Definition: eztranslatormanager.php:72
eZTranslatorManager\createKey
static createKey( $context, $source, $comment=null)
Definition: eztranslatormanager.php:151
eZTranslatorManager\dynamicTranslationsEnabled
static dynamicTranslationsEnabled()
Definition: eztranslatormanager.php:194
eZTranslatorManager\enableDynamicTranslations
static enableDynamicTranslations( $enable=true)
Definition: eztranslatormanager.php:202
eZTranslatorManager\__construct
__construct()
Definition: eztranslatormanager.php:35
eZTranslatorManager\keyTranslate
keyTranslate( $key)
Definition: eztranslatormanager.php:93
eZTranslatorManager\registerHandler
static registerHandler( $handler)
Definition: eztranslatormanager.php:141
eZTranslatorManager\instance
static instance()
Definition: eztranslatormanager.php:128
eZTranslatorManager\translate
translate( $context, $source, $comment=null)
Definition: eztranslatormanager.php:110
eZTranslatorManager\resetTranslations
static resetTranslations()
Definition: eztranslatormanager.php:183
eZTranslatorManager\createMessage
static createMessage( $context, $source, $comment=null, $translation=null)
Definition: eztranslatormanager.php:163
eZTranslatorManager\$Handlers
$Handlers
Definition: eztranslatormanager.php:243
eZTranslatorManager\findKey
findKey( $key)
Definition: eztranslatormanager.php:51
eZTranslatorManager\resetGlobals
static resetGlobals()
Definition: eztranslatormanager.php:175
eZTranslatorManager\setActiveTranslation
static setActiveTranslation( $locale, $permanently=true)
Definition: eztranslatormanager.php:217
eZTranslatorManager\DYNAMIC_TRANSLATIONS_ENABLED
const DYNAMIC_TRANSLATIONS_ENABLED
Definition: eztranslatormanager.php:33
$msg
$msg
Definition: editmessage.php:47
$instance
$instance
Definition: orderedit.php:667
$translation
$translation
Definition: ordersendt.php:62
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.