|
eZ Publish
[4.0]
|
00001 <?php 00002 // 00003 // Definition of eZShuffleTranslator 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 eZShuffleTranslator ez1337translator.php 00036 \ingroup eZTranslation 00037 \brief Translates text by moving characters around 00038 00039 */ 00040 00041 //include_once( "lib/ezi18n/classes/eztranslatorhandler.php" ); 00042 00043 class eZShuffleTranslator extends eZTranslatorHandler 00044 { 00045 /*! 00046 Construct the translator and loads the translation file $file if is set and exists. 00047 */ 00048 function eZShuffleTranslator( $max_chars = 3 ) 00049 { 00050 $this->eZTranslatorHandler( false ); 00051 00052 $this->MaxChars = $max_chars; 00053 $this->Messages = array(); 00054 } 00055 00056 /*! 00057 \reimp 00058 */ 00059 function findMessage( $context, $source, $comment = null ) 00060 { 00061 $man = eZTranslatorManager::instance(); 00062 $translation = $this->shuffleText( $source ); 00063 return $man->createMessage( $context, $source, $comment, $translation ); 00064 } 00065 00066 /*! 00067 Reorders some of the characters in $text and returns the new text string. 00068 The maximum number of reorders is taken from MaxChars. 00069 */ 00070 function &shuffleText( $text ) 00071 { 00072 $num = rand( 0, $this->MaxChars ); 00073 for ( $i = 0; $i < $num; ++$i ) 00074 { 00075 $len = strlen( $text ); 00076 $offs = rand( 0, $len - 1 ); 00077 if ( $offs == 0 ) 00078 { 00079 $tmp = $text[$offs]; 00080 $text[$offs] = $text[$len - 1]; 00081 $text[$len] = $tmp; 00082 } 00083 else 00084 { 00085 $delta = -1; 00086 if ( $text[$offs+$delta] == " " and 00087 $offs + 1 < $len ) 00088 $delta = 1; 00089 $tmp = $text[$offs]; 00090 $text[$offs] = $text[$offs+$delta]; 00091 $text[$offs+$delta] = $tmp; 00092 } 00093 } 00094 return $text; 00095 } 00096 00097 /*! 00098 \reimp 00099 */ 00100 function translate( $context, $source, $comment = null ) 00101 { 00102 $msg = $this->findMessage( $context, $source, $comment ); 00103 if ( $msg !== null ) 00104 { 00105 return $msg["translation"]; 00106 } 00107 00108 return null; 00109 } 00110 00111 /// \privatesection 00112 /// Contains the hash table with cached 1337 translations 00113 public $Messages; 00114 } 00115 00116 ?>