Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

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