eZ Publish  [4.0]
eztranslatorgroup.php
Go to the documentation of this file.
00001 <?php
00002 //
00003 // Definition of eZTranslatorGroup class
00004 //
00005 // Created on: <10-Jun-2002 11:05:00 amos>
00006 //
00007 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
00008 // SOFTWARE NAME: eZ Publish
00009 // SOFTWARE RELEASE: 4.0.x
00010 // COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS
00011 // SOFTWARE LICENSE: GNU General Public License v2.0
00012 // NOTICE: >
00013 //   This program is free software; you can redistribute it and/or
00014 //   modify it under the terms of version 2.0  of the GNU General
00015 //   Public License as published by the Free Software Foundation.
00016 //
00017 //   This program is distributed in the hope that it will be useful,
00018 //   but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 //   GNU General Public License for more details.
00021 //
00022 //   You should have received a copy of version 2.0 of the GNU General
00023 //   Public License along with this program; if not, write to the Free
00024 //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00025 //   MA 02110-1301, USA.
00026 //
00027 //
00028 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
00029 //
00030 
00031 /*! \file eztranslatorgroup.php
00032 */
00033 
00034 /*!
00035   \class eZTranslatorGroup eztranslatorgroup.php
00036   \ingroup eZTranslation
00037   \brief Allows for picking translator handlers according to context
00038 
00039 */
00040 
00041 //include_once( "lib/ezi18n/classes/eztranslatorhandler.php" );
00042 
00043 class eZTranslatorGroup extends eZTranslatorHandler
00044 {
00045     /*!
00046      Constructor
00047     */
00048     function eZTranslatorGroup( $is_key_based )
00049     {
00050         $this->eZTranslatorHandler( $is_key_based );
00051         $this->Handlers = array();
00052     }
00053 
00054     /*!
00055      \pure
00056      \return the translation message for the key \a $key or null if the key does not exist.
00057 
00058      This function must overridden if isKeyBased() is true.
00059     */
00060     function findKey( $key )
00061     {
00062         $num = $this->keyPick( $key );
00063         if ( $num >=0 and $num <= count( $this->Handlers ) )
00064         {
00065             $handler = $this->Handlers[$num];
00066             return $handler->findKey( $key );
00067         }
00068         $retValue = null;
00069         return $retValue;
00070     }
00071 
00072     /*!
00073      \pure
00074      \return the translation message for \a $source and \a $context or null if the key does not exist.
00075 
00076      If you know the translation key use findKey() instead.
00077 
00078      This function must overridden if isKeyBased() is true.
00079     */
00080     function findMessage( $context, $source, $comment = null )
00081     {
00082         $num = $this->pick( $context, $source, $comment );
00083         if ( $num >=0 and $num <= count( $this->Handlers ) )
00084         {
00085             $handler = $this->Handlers[$num];
00086             return $handler->findMessage( $context, $source, $comment );
00087         }
00088         $retValue = null;
00089         return $retValue;
00090     }
00091 
00092     /*!
00093      \pure
00094      \return the translation string for \a $source and \a $context or null if the translation does not exist.
00095 
00096      \sa findMessage, findKey
00097     */
00098     function translate( $context, $source, $comment = null )
00099     {
00100         $num = $this->pick( $context, $source, $comment );
00101         if ( $num >=0 and $num <= count( $this->Handlers ) )
00102         {
00103             $handler = $this->Handlers[$num];
00104             return $handler->translate( $context, $source, $comment );
00105         }
00106 
00107         return null;
00108     }
00109 
00110     /*!
00111      \pure
00112      \return the translation string for \a $key or null if the translation does not exist.
00113 
00114      \sa findMessage, findKey
00115     */
00116     function keyTranslate( $key )
00117     {
00118         $num = $this->keyPick( $key );
00119         if ( $num >=0 and $num <= count( $this->Handlers ) )
00120         {
00121             $handler = $this->Handlers[$num];
00122             return $handler->keyTranslate( $key );
00123         }
00124 
00125         return null;
00126     }
00127 
00128     /*!
00129      \pure
00130      Reimplement this to pick one of the registered handlers based on \a $key.
00131      \return -1 for no handler or a number within the handler range (starting from 0).
00132      \sa pick
00133     */
00134     function keyPick( $key )
00135     {
00136     }
00137 
00138     /*!
00139      \pure
00140      Reimplement this to pick one of the registered handlers based on \a $context, \a $source and \a $comment.
00141      \return -1 for no handler or a number within the handler range (starting from 0).
00142      \sa keyPick
00143     */
00144     function pick( $context, $source, $comment )
00145     {
00146     }
00147 
00148     /*!
00149      \return the number of registered handlers.
00150     */
00151     function handlerCount()
00152     {
00153         return count( $this->Handlers );
00154     }
00155 
00156     /*!
00157      Registers the handler object \a $handler.
00158     */
00159     function registerHandler( $handler )
00160     {
00161         if ( !$this->isKeyBased() and $handler->isKeyBased() )
00162         {
00163             eZDebug::writeError( "Cannot register keybased handler for non-keybased group", "eZTranslatorGroup" );
00164             return false;
00165         }
00166         $this->Handlers[] = $handler;
00167         return true;
00168     }
00169 
00170     /// \privatesection
00171     /// The array of grouped handlers
00172     public $Handlers;
00173 }
00174 
00175 ?>