eZ Publish  [4.0]
ez1337translator.php
Go to the documentation of this file.
00001 <?php
00002 //
00003 // Definition of eZ1337Translator class
00004 //
00005 // Created on: <07-Jun-2002 12:40:42 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 ez1337translator.php
00032 */
00033 
00034 /*!
00035   \class eZ1337Translator ez1337translator.php
00036   \ingroup eZTranslation
00037   \brief Translates text into the leet (1337) language
00038 
00039   It translates the following characters/strings
00040   - to - 2
00041   - for - 4
00042   - ate - 8
00043   - you - u
00044   - l - 1
00045   - e - 3
00046   - o - 0
00047   - a - 4
00048   - t - 7
00049 
00050 */
00051 
00052 //include_once( "lib/ezi18n/classes/eztranslatorhandler.php" );
00053 
00054 class eZ1337Translator extends eZTranslatorHandler
00055 {
00056     /*!
00057      Construct the translator and loads the translation file $file if is set and exists.
00058     */
00059     function eZ1337Translator()
00060     {
00061         $this->eZTranslatorHandler( false );
00062 
00063         $this->Messages = array();
00064     }
00065 
00066     /*!
00067      \reimp
00068     */
00069     function findMessage( $context, $source, $comment = null )
00070     {
00071         $man = eZTranslatorManager::instance();
00072         $key = $man->createKey( $context, $source, $comment );
00073 
00074         if ( !isset( $this->Messages[$key] ) )
00075         {
00076             $translation = $this->leetify( $source );
00077             $this->Messages[$key] = $man->createMessage( $context, $source, $comment, $translation );
00078         }
00079 
00080         return $this->Messages[$key];
00081     }
00082 
00083     /*!
00084      Translates the text into 1337 code.
00085     */
00086     function leetify( $text )
00087     {
00088         $text = preg_replace( "/to/", "2", $text );
00089         $text = preg_replace( "/for/", "4", $text );
00090         $text = preg_replace( "/ate/", "8", $text );
00091         $text = preg_replace( "/you/", "u", $text );
00092         $text = preg_replace( array( "/l/",
00093                                      "/e/",
00094                                      "/o/",
00095                                      "/a/",
00096                                      "/t/" ),
00097                               array( "1",
00098                                      "3",
00099                                      "0",
00100                                      "4",
00101                                      "7" ), $text );
00102         return $text;
00103     }
00104 
00105     /*!
00106      \reimp
00107     */
00108     function translate( $context, $source, $comment = null )
00109     {
00110         $msg = $this->findMessage( $context, $source, $comment );
00111         if ( $msg !== null )
00112         {
00113             return $msg["translation"];
00114         }
00115 
00116         return null;
00117     }
00118 
00119     /*!
00120      \static
00121      Initialize the bork translator if this is not allready done.
00122     */
00123     static function initialize()
00124     {
00125         if ( !isset( $GLOBALS['eZ1337Translator'] ) ||
00126              !( $GLOBALS['eZ1337Translator'] instanceof eZ1337Translator ) )
00127         {
00128             $GLOBALS['eZ1337Translator'] = new eZ1337Translator();
00129         }
00130 
00131         $man = eZTranslatorManager::instance();
00132         $man->registerHandler( $GLOBALS['eZ1337Translator'] );
00133         return $GLOBALS['eZ1337Translator'];
00134     }
00135 
00136     /// \privatesection
00137     /// Contains the hash table with cached 1337 translations
00138     public $Messages;
00139 }
00140 
00141 ?>