00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 include_once( "lib/ezi18n/classes/eztranslatorhandler.php" );
00042
00043 class eZShuffleTranslator extends eZTranslatorHandler
00044 {
00045
00046
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
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
00068
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
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
00112
00113 var $Messages;
00114 }
00115
00116 ?>