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
00059 include_once( "lib/ezi18n/classes/eztranslatorhandler.php" );
00060
eZTranslatorManager
00062 {
00065 function eZTranslatorManager()
00066 {
00067 $this->Handlers = array();
00068 }
00069
findKey( $key )
00082 {
00083 $msg = null;
00084 for ( $i = 0; $i < count( $this->Handlers ) and $msg === null; ++$i )
00085 {
00086 $handler =& $this->Handlers[$i];
00087 if ( $handler->isKeyBased() )
00088 $msg =& $handler->findKey( $key );
00089 }
00090 return $msg;
00091 }
00092
findMessage( $context, $source, $comment = null )
00103 {
00104 if ( !is_string( $context ) or $context == "" )
00105 $context = "default";
00106 $msg = null;
00107 for ( $i = 0; $i < count( $this->Handlers ) and $msg === null; ++$i )
00108 {
00109 $handler =& $this->Handlers[$i];
00110 $msg =& $handler->findMessage( $context, $source, $comment );
00111 }
00112 return $msg;
00113 }
00114
keyTranslate( $key )
00124 {
00125 $trans = null;
00126 for ( $i = 0; $i < count( $this->Handlers ) and $trans === null; ++$i )
00127 {
00128 $handler =& $this->Handlers[$i];
00129 if ( $handler->isKeyBased() )
00130 $trans =& $handler->keyTranslate( $key );
00131 }
00132 return $trans;
00133 }
00134
translate( $context, $source, $comment = null )
00141 {
00142 if ( !is_string( $context ) or $context == "" )
00143 $context = "default";
00144
00145
00146 $trans = null;
00147 for ( $i = 0; $i < count( $this->Handlers ) and $trans === null; ++$i )
00148 {
00149 $handler =& $this->Handlers[$i];
00150 $trans =& $handler->translate( $context, $source, $comment );
00151 }
00152 return $trans;
00153 }
00154
instance()
00160 {
00161 $instance =& $GLOBALS["eZTranslatorManagerInstance"];
00162 if ( get_class( $instance ) != "eztranslatormanager" )
00163 {
00164 $eZTranslatorManager();
00165 }
00166 return $instance;
00167 }
00168
registerHandler( &$handler )
00174 {
00175 if ( !isset( $this ) or get_class( $this ) != "eztranslatormanager" )
00176 $this =& eZTranslatorManager::instance();
00177 $this->Handlers[] =& $handler;
00178 }
00179
createKey( $context, $source, $comment = null )
00185 {
00186 if ( $comment === null )
00187 $comment = "";
00188 return md5( "$context\n$source\n$comment" );
00189 }
00190
createMessage( $context, $source, $comment = null, $translation = null )
00197 {
00198 $msg = array( "context" => $context,
00199 "source" => $source,
00200 "comment" => $comment,
00201 "translation" => $translation );
00202 return $msg;
00203 }
00204
Handlers;
00208 }
00209
00210 ?>