[ Index ]
 

Code source de eZ Publish 3.9.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/lib/ezi18n/classes/ -> ezshuffletranslator.php (source)

   1  <?php
   2  //
   3  // Definition of eZShuffleTranslator class
   4  //
   5  // Created on: <07-Jun-2002 12:40:42 amos>
   6  //
   7  // SOFTWARE NAME: eZ publish
   8  // SOFTWARE RELEASE: 3.9.0
   9  // BUILD VERSION: 17785
  10  // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS
  11  // SOFTWARE LICENSE: GNU General Public License v2.0
  12  // NOTICE: >
  13  //   This program is free software; you can redistribute it and/or
  14  //   modify it under the terms of version 2.0  of the GNU General
  15  //   Public License as published by the Free Software Foundation.
  16  //
  17  //   This program is distributed in the hope that it will be useful,
  18  //   but WITHOUT ANY WARRANTY; without even the implied warranty of
  19  //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20  //   GNU General Public License for more details.
  21  //
  22  //   You should have received a copy of version 2.0 of the GNU General
  23  //   Public License along with this program; if not, write to the Free
  24  //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  25  //   MA 02110-1301, USA.
  26  //
  27  //
  28  
  29  /*! \file ez1337translator.php
  30  */
  31  
  32  /*!
  33    \class eZShuffleTranslator ez1337translator.php
  34    \ingroup eZTranslation
  35    \brief Translates text by moving characters around
  36  
  37  */
  38  
  39  include_once ( "lib/ezi18n/classes/eztranslatorhandler.php" );
  40  
  41  class eZShuffleTranslator extends eZTranslatorHandler
  42  {
  43      /*!
  44       Construct the translator and loads the translation file $file if is set and exists.
  45      */
  46      function eZShuffleTranslator( $max_chars = 3 )
  47      {
  48          $this->eZTranslatorHandler( false );
  49  
  50          $this->MaxChars = $max_chars;
  51          $this->Messages = array();
  52      }
  53  
  54      /*!
  55       \reimp
  56      */
  57      function findMessage( $context, $source, $comment = null )
  58      {
  59          $man = eZTranslatorManager::instance();
  60          $translation = $this->shuffleText( $source );
  61          return $man->createMessage( $context, $source, $comment, $translation );
  62      }
  63  
  64      /*!
  65       Reorders some of the characters in $text and returns the new text string.
  66       The maximum number of reorders is taken from MaxChars.
  67      */
  68      function &shuffleText( $text )
  69      {
  70          $num = rand( 0, $this->MaxChars );
  71          for ( $i = 0; $i < $num; ++$i )
  72          {
  73              $len = strlen( $text );
  74              $offs = rand( 0, $len - 1 );
  75              if ( $offs == 0 )
  76              {
  77                  $tmp = $text[$offs];
  78                  $text[$offs] = $text[$len - 1];
  79                  $text[$len] = $tmp;
  80              }
  81              else
  82              {
  83                  $delta = -1;
  84                  if ( $text[$offs+$delta] == " " and
  85                       $offs + 1 < $len )
  86                      $delta = 1;
  87                  $tmp = $text[$offs];
  88                  $text[$offs] = $text[$offs+$delta];
  89                  $text[$offs+$delta] = $tmp;
  90              }
  91          }
  92          return $text;
  93      }
  94  
  95      /*!
  96       \reimp
  97      */
  98      function translate( $context, $source, $comment = null )
  99      {
 100          $msg = $this->findMessage( $context, $source, $comment );
 101          if ( $msg !== null )
 102          {
 103              return $msg["translation"];
 104          }
 105  
 106          return null;
 107      }
 108  
 109      /// \privatesection
 110      /// Contains the hash table with cached 1337 translations
 111      var $Messages;
 112  }
 113  
 114  ?>


Généré le : Sat Feb 24 10:30:04 2007 par Balluche grâce à PHPXref 0.7