Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezshuffletranslator.php
Go to the documentation of this file.
1 <?php
18 class eZShuffleTranslator extends eZTranslatorHandler
19 {
20 public $MaxChars;
26 public function __construct( $max_chars = 3 )
27 {
28 parent::__construct( false );
29
30 $this->MaxChars = $max_chars;
31 $this->Messages = array();
32 }
33
34 function findMessage( $context, $source, $comment = null )
35 {
36 $man = eZTranslatorManager::instance();
37 $translation = $this->shuffleText( $source );
38 return $man->createMessage( $context, $source, $comment, $translation );
39 }
40
45 function &shuffleText( $text )
46 {
47 $num = mt_rand( 0, $this->MaxChars );
48 for ( $i = 0; $i < $num; ++$i )
49 {
50 $len = strlen( $text );
51 $offs = mt_rand( 0, $len - 1 );
52 if ( $offs == 0 )
53 {
54 $tmp = $text[$offs];
55 $text[$offs] = $text[$len - 1];
56 $text[$len] = $tmp;
57 }
58 else
59 {
60 $delta = -1;
61 if ( $text[$offs+$delta] == " " and
62 $offs + 1 < $len )
63 $delta = 1;
64 $tmp = $text[$offs];
65 $text[$offs] = $text[$offs+$delta];
66 $text[$offs+$delta] = $tmp;
67 }
68 }
69 return $text;
70 }
71
72 function translate( $context, $source, $comment = null )
73 {
74 $msg = $this->findMessage( $context, $source, $comment );
75 if ( $msg !== null )
76 {
77 return $msg["translation"];
78 }
79
80 return null;
81 }
82
85 public $Messages;
86 }
87
88 ?>
eZShuffleTranslator
Translates text by moving characters around.
Definition: ezshuffletranslator.php:19
eZShuffleTranslator\translate
translate( $context, $source, $comment=null)
Definition: ezshuffletranslator.php:72
eZShuffleTranslator\findMessage
findMessage( $context, $source, $comment=null)
Definition: ezshuffletranslator.php:34
eZShuffleTranslator\shuffleText
& shuffleText( $text)
Definition: ezshuffletranslator.php:45
eZShuffleTranslator\$MaxChars
$MaxChars
Definition: ezshuffletranslator.php:20
eZShuffleTranslator\$Messages
$Messages
Definition: ezshuffletranslator.php:85
eZShuffleTranslator\__construct
__construct( $max_chars=3)
Definition: ezshuffletranslator.php:26
eZTranslatorHandler
Base class for translation handling.
Definition: eztranslatorhandler.php:19
eZTranslatorManager\instance
static instance()
Definition: eztranslatormanager.php:127
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.