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
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053 include_once( "lib/ezi18n/classes/eztranslatorhandler.php" );
00054
00055 define( 'EZ_TM_DYNAMIC_TRANSLATIONS_ENABLED', 'eZTMDynamicTranslationsEnabled' );
00056
00057 class eZTranslatorManager
00058 {
00059
00060
00061 function eZTranslatorManager()
00062 {
00063 $this->Handlers = array();
00064 }
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077 function findKey( $key )
00078 {
00079 $msg = null;
00080 for ( $i = 0; $i < count( $this->Handlers ) and $msg === null; ++$i )
00081 {
00082 $handler = $this->Handlers[$i];
00083 if ( $handler->isKeyBased() )
00084 $msg = $handler->findKey( $key );
00085 }
00086 return $msg;
00087 }
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098 function findMessage( $context, $source, $comment = null )
00099 {
00100 if ( !is_string( $context ) or $context == "" )
00101 $context = "default";
00102 $msg = null;
00103 for ( $i = 0; $i < count( $this->Handlers ) and $msg === null; ++$i )
00104 {
00105 $handler = $this->Handlers[$i];
00106 $msg = $handler->findMessage( $context, $source, $comment );
00107 }
00108 return $msg;
00109 }
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119 function keyTranslate( $key )
00120 {
00121 $trans = null;
00122 for ( $i = 0; $i < count( $this->Handlers ) and $trans === null; ++$i )
00123 {
00124 $handler = $this->Handlers[$i];
00125 if ( $handler->isKeyBased() )
00126 $trans = $handler->keyTranslate( $key );
00127 }
00128 return $trans;
00129 }
00130
00131
00132
00133
00134
00135
00136 function translate( $context, $source, $comment = null )
00137 {
00138 if ( !is_string( $context ) or $context == "" )
00139 $context = "default";
00140 $trans = null;
00141 for ( $i = 0; $i < count( $this->Handlers ) and $trans === null; ++$i )
00142 {
00143 $handler = $this->Handlers[$i];
00144 $trans = $handler->translate( $context, $source, $comment );
00145 }
00146 return $trans;
00147 }
00148
00149
00150
00151
00152
00153 function &instance()
00154 {
00155 $instance =& $GLOBALS["eZTranslatorManagerInstance"];
00156 if ( get_class( $instance ) != "eztranslatormanager" )
00157 {
00158 $instance = new eZTranslatorManager();
00159 }
00160 return $instance;
00161 }
00162
00163
00164
00165
00166
00167 function registerHandler( &$handler )
00168 {
00169 if ( isset( $this ) and get_class( $this ) == "eztranslatormanager" )
00170 $instance =& $this;
00171 else
00172 $instance =& eZTranslatorManager::instance();
00173 $instance->Handlers[] =& $handler;
00174 }
00175
00176
00177
00178
00179
00180 function createKey( $context, $source, $comment = null )
00181 {
00182 if ( $comment === null )
00183 $comment = "";
00184 return md5( "$context\n$source\n$comment" );
00185 }
00186
00187
00188
00189
00190
00191
00192 function createMessage( $context, $source, $comment = null, $translation = null )
00193 {
00194 $msg = array( "context" => $context,
00195 "source" => $source,
00196 "comment" => $comment,
00197 "translation" => $translation );
00198 return $msg;
00199 }
00200
00201
00202
00203
00204 function resetGlobals()
00205 {
00206 unset( $GLOBALS["eZTranslatorManagerInstance"] );
00207 }
00208
00209
00210
00211
00212 function resetTranslations()
00213 {
00214 include_once( 'lib/ezi18n/classes/eztstranslator.php' );
00215 eZTranslatorManager::resetGlobals();
00216 eZTSTranslator::resetGlobals();
00217 eZLocale::resetGlobals();
00218 eZTranslationCache::resetGlobals();
00219 }
00220
00221
00222
00223
00224 function dynamicTranslationsEnabled()
00225 {
00226 return isset( $GLOBALS[EZ_TM_DYNAMIC_TRANSLATIONS_ENABLED] );
00227 }
00228
00229
00230
00231
00232 function enableDynamicTranslations( $enable = true )
00233 {
00234 if ( $enable )
00235 {
00236 $GLOBALS[EZ_TM_DYNAMIC_TRANSLATIONS_ENABLED] = true;
00237 }
00238 else
00239 {
00240 unset( $GLOBALS[EZ_TM_DYNAMIC_TRANSLATIONS_ENABLED] );
00241 }
00242 }
00243
00244
00245
00246
00247 function setActiveTranslation( $locale, $permanently = true )
00248 {
00249 if( !eZTranslatorManager::dynamicTranslationsEnabled() )
00250 return;
00251
00252 if ( $permanently )
00253 $siteINI =& eZINI::instance( 'site.ini.append', 'settings/override', null, null, false, true );
00254 else
00255 $siteINI =& eZINI::instance();
00256
00257 $siteINI->setVariable( 'RegionalSettings', 'Locale', $locale );
00258 $siteINI->setVariable( 'RegionalSettings', 'TextTranslation', 'enabled' );
00259
00260 if ( $permanently )
00261 {
00262 $siteINI->save( 'site.ini.append', '.php', false, false );
00263 eZINI::resetGlobals( "site.ini" );
00264 }
00265
00266 eZTranslatorManager::resetTranslations();
00267 }
00268
00269
00270
00271
00272
00273 var $Handlers;
00274 }
00275
00276 ?>