|
eZ Publish
[trunk]
|
00001 <?php 00002 /** 00003 * File containing the eZTranslatorGroup class. 00004 * 00005 * @copyright Copyright (C) 1999-2012 eZ Systems AS. All rights reserved. 00006 * @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2 00007 * @version //autogentag// 00008 * @package lib 00009 */ 00010 00011 /*! 00012 \class eZTranslatorGroup eztranslatorgroup.php 00013 \ingroup eZTranslation 00014 \brief Allows for picking translator handlers according to context 00015 00016 */ 00017 00018 class eZTranslatorGroup extends eZTranslatorHandler 00019 { 00020 /*! 00021 Constructor 00022 */ 00023 function eZTranslatorGroup( $is_key_based ) 00024 { 00025 $this->eZTranslatorHandler( $is_key_based ); 00026 $this->Handlers = array(); 00027 } 00028 00029 /*! 00030 \pure 00031 \return the translation message for the key \a $key or null if the key does not exist. 00032 00033 This function must overridden if isKeyBased() is true. 00034 */ 00035 function findKey( $key ) 00036 { 00037 $num = $this->keyPick( $key ); 00038 if ( $num >=0 and $num <= count( $this->Handlers ) ) 00039 { 00040 $handler = $this->Handlers[$num]; 00041 return $handler->findKey( $key ); 00042 } 00043 $retValue = null; 00044 return $retValue; 00045 } 00046 00047 /*! 00048 \pure 00049 \return the translation message for \a $source and \a $context or null if the key does not exist. 00050 00051 If you know the translation key use findKey() instead. 00052 00053 This function must overridden if isKeyBased() is true. 00054 */ 00055 function findMessage( $context, $source, $comment = null ) 00056 { 00057 $num = $this->pick( $context, $source, $comment ); 00058 if ( $num >=0 and $num <= count( $this->Handlers ) ) 00059 { 00060 $handler = $this->Handlers[$num]; 00061 return $handler->findMessage( $context, $source, $comment ); 00062 } 00063 $retValue = null; 00064 return $retValue; 00065 } 00066 00067 /*! 00068 \pure 00069 \return the translation string for \a $source and \a $context or null if the translation does not exist. 00070 00071 \sa findMessage, findKey 00072 */ 00073 function translate( $context, $source, $comment = null ) 00074 { 00075 $num = $this->pick( $context, $source, $comment ); 00076 if ( $num >=0 and $num <= count( $this->Handlers ) ) 00077 { 00078 $handler = $this->Handlers[$num]; 00079 return $handler->translate( $context, $source, $comment ); 00080 } 00081 00082 return null; 00083 } 00084 00085 /*! 00086 \pure 00087 \return the translation string for \a $key or null if the translation does not exist. 00088 00089 \sa findMessage, findKey 00090 */ 00091 function keyTranslate( $key ) 00092 { 00093 $num = $this->keyPick( $key ); 00094 if ( $num >=0 and $num <= count( $this->Handlers ) ) 00095 { 00096 $handler = $this->Handlers[$num]; 00097 return $handler->keyTranslate( $key ); 00098 } 00099 00100 return null; 00101 } 00102 00103 /*! 00104 \pure 00105 Reimplement this to pick one of the registered handlers based on \a $key. 00106 \return -1 for no handler or a number within the handler range (starting from 0). 00107 \sa pick 00108 */ 00109 function keyPick( $key ) 00110 { 00111 } 00112 00113 /*! 00114 \pure 00115 Reimplement this to pick one of the registered handlers based on \a $context, \a $source and \a $comment. 00116 \return -1 for no handler or a number within the handler range (starting from 0). 00117 \sa keyPick 00118 */ 00119 function pick( $context, $source, $comment ) 00120 { 00121 } 00122 00123 /*! 00124 \return the number of registered handlers. 00125 */ 00126 function handlerCount() 00127 { 00128 return count( $this->Handlers ); 00129 } 00130 00131 /*! 00132 Registers the handler object \a $handler. 00133 */ 00134 function registerHandler( $handler ) 00135 { 00136 if ( !$this->isKeyBased() and $handler->isKeyBased() ) 00137 { 00138 eZDebug::writeError( "Cannot register keybased handler for non-keybased group", "eZTranslatorGroup" ); 00139 return false; 00140 } 00141 $this->Handlers[] = $handler; 00142 return true; 00143 } 00144 00145 /// \privatesection 00146 /// The array of grouped handlers 00147 public $Handlers; 00148 } 00149 00150 ?>