| [ Index ] |
|
Code source de eZ Publish 3.9.0 |
1 <?php 2 // 3 // Definition of eZTranslatorManager class 4 // 5 // Created on: <10-Jun-2002 11:16:48 amos> 6 // 7 // SOFTWARE NAME: eZ publish 8 // SOFTWARE RELEASE: 3.9.0 9 // BUILD VERSION: 17785 10 // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS 11 // SOFTWARE LICENSE: GNU General Public License v2.0 12 // NOTICE: > 13 // This program is free software; you can redistribute it and/or 14 // modify it under the terms of version 2.0 of the GNU General 15 // Public License as published by the Free Software Foundation. 16 // 17 // This program is distributed in the hope that it will be useful, 18 // but WITHOUT ANY WARRANTY; without even the implied warranty of 19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 // GNU General Public License for more details. 21 // 22 // You should have received a copy of version 2.0 of the GNU General 23 // Public License along with this program; if not, write to the Free 24 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 25 // MA 02110-1301, USA. 26 // 27 // 28 29 /*! \file eztranslatormanager.php 30 */ 31 32 /*! \defgroup eZTranslation Translation 33 \ingroup eZI18N 34 */ 35 36 37 /*! 38 \class eZTranslatorManager eztranslatormanager.php 39 \ingroup eZTranslation 40 \brief This provides internationalization support for text output 41 42 Each message consists of: 43 - context - the context of the translation 44 - source - the source string 45 - comment - a variation of the context/source 46 - key - the uniquely generated key taken from context, source and eventually comment 47 48 49 */ 50 51 include_once ( "lib/ezi18n/classes/eztranslatorhandler.php" ); 52 53 class eZTranslatorManager 54 { 55 /*! 56 */ 57 function eZTranslatorManager() 58 { 59 $this->Handlers = array(); 60 } 61 62 /*! 63 Tries to find the translation message that matches \a $key in all it's handlers 64 and returns it. If no message could be found it either means that none of the 65 handlers have a translation for the key or that some of the handlers are not key based, 66 for instance realtime translators. 67 In the latter case an extra call to findMessage() or translate() is required. 68 69 Use keyTranslate if you only want to translate a message. 70 71 \sa findMessage, keyTranslate 72 */ 73 function findKey( $key ) 74 { 75 $msg = null; 76 for ( $i = 0; $i < count( $this->Handlers ) and $msg === null; ++$i ) 77 { 78 $handler = $this->Handlers[$i]; 79 if ( $handler->isKeyBased() ) 80 $msg = $handler->findKey( $key ); 81 } 82 return $msg; 83 } 84 85 /*! 86 Tries to find the translation message that matches \a $context, \a $source and 87 \a $comment. If that fails it tries \a $context and \a $source only. 88 The message is then returned or null if no translation message could be found/generated for it. 89 90 Use translate if you only want to translate a message. 91 92 \sa findKey, translate 93 */ 94 function findMessage( $context, $source, $comment = null ) 95 { 96 if ( !is_string( $context ) or $context == "" ) 97 $context = "default"; 98 $msg = null; 99 for ( $i = 0; $i < count( $this->Handlers ) and $msg === null; ++$i ) 100 { 101 $handler = $this->Handlers[$i]; 102 $msg = $handler->findMessage( $context, $source, $comment ); 103 } 104 return $msg; 105 } 106 107 /*! 108 \return the translation string for \a $key. 109 110 Note this returns the exact translation for the given key, use translate() 111 instead if you want to have variable comment support. 112 113 \sa findKey, translate 114 */ 115 function keyTranslate( $key ) 116 { 117 $trans = null; 118 for ( $i = 0; $i < count( $this->Handlers ) and $trans === null; ++$i ) 119 { 120 $handler = $this->Handlers[$i]; 121 if ( $handler->isKeyBased() ) 122 $trans = $handler->keyTranslate( $key ); 123 } 124 return $trans; 125 } 126 127 /*! 128 \return the translation string for \a $source and \a $context or null if the key does not exist. 129 130 \sa findMessage, findKey 131 */ 132 function translate( $context, $source, $comment = null ) 133 { 134 if ( !is_string( $context ) or $context == "" ) 135 $context = "default"; 136 $trans = null; 137 for ( $i = 0; $i < count( $this->Handlers ) and $trans === null; ++$i ) 138 { 139 $handler = $this->Handlers[$i]; 140 $trans = $handler->translate( $context, $source, $comment ); 141 } 142 return $trans; 143 } 144 145 /*! 146 \static 147 \return the unique instance of the translator system. 148 */ 149 function &instance() 150 { 151 $instance =& $GLOBALS["eZTranslatorManagerInstance"]; 152 if ( get_class( $instance ) != "eztranslatormanager" ) 153 { 154 $instance = new eZTranslatorManager(); 155 } 156 return $instance; 157 } 158 159 /*! 160 \static 161 Registers the handler object \a $handler. 162 */ 163 function registerHandler( &$handler ) 164 { 165 if ( isset( $this ) and get_class( $this ) == "eztranslatormanager" ) 166 $instance =& $this; 167 else 168 $instance =& eZTranslatorManager::instance(); 169 $instance->Handlers[] =& $handler; 170 } 171 172 /*! 173 \static 174 Creates an md5 key based on the \a $context, \a $source and \a $comment and returns it. 175 */ 176 function createKey( $context, $source, $comment = null ) 177 { 178 if ( $comment === null ) 179 $comment = ""; 180 return md5( "$context\n$source\n$comment" ); 181 } 182 183 /*! 184 \static 185 Creates a message structure out of \a $context, \a $source and \a $comment 186 and returns it. 187 */ 188 function createMessage( $context, $source, $comment = null, $translation = null ) 189 { 190 $msg = array( "context" => $context, 191 "source" => $source, 192 "comment" => $comment, 193 "translation" => $translation ); 194 return $msg; 195 } 196 197 /// \privatesection 198 /// The array of handler objects 199 var $Handlers; 200 } 201 202 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Sat Feb 24 10:30:04 2007 | par Balluche grâce à PHPXref 0.7 |