[ 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/ -> ezborktranslator.php (source)

   1  <?php
   2  //
   3  // Definition of eZBorkTranslator 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 ezborktranslator.php
  30  */
  31  
  32  /*!
  33    \class eZBorkTranslator ezborktranslator.php
  34    \ingroup eZTranslation
  35    \brief Translates text into the Bork language (Mock Swedish)
  36  
  37    This translation is adapted from the Mock Swedish translation in Qt Quarterly 3/2002:
  38    http://doc.trolltech.com/qq/qq03-swedish-chef.html
  39  
  40    It translates the following characters/strings:
  41    (The "|" sign stands for a word boundary, and "-" stands for mid-word.)
  42  
  43    a-    -> e
  44    an    -> un
  45    au    -> oo
  46    en|   -> ee
  47    -ew   -> oo
  48    -f    -> ff
  49    -i    -> ee
  50    -ir   -> ur
  51    |o    -> oo
  52    ow    -> oo
  53    ph    -> f
  54    th|   -> t
  55    -tion -> shun
  56    -u    -> oo
  57    |U-   -> Oo
  58    y|    -> ai
  59    v     -> f
  60    w     -> v
  61  
  62    Words that are not changed by these rules will have "-a" appended to them.
  63  
  64  */
  65  
  66  include_once ( "lib/ezi18n/classes/eztranslatorhandler.php" );
  67  
  68  class eZBorkTranslator extends eZTranslatorHandler
  69  {
  70      /*!
  71       Construct the translator.
  72      */
  73      function eZBorkTranslator()
  74      {
  75          $this->eZTranslatorHandler( false );
  76  
  77          $this->Messages = array();
  78      }
  79  
  80      /*!
  81       \reimp
  82      */
  83      function findMessage( $context, $source, $comment = null )
  84      {
  85          $man = eZTranslatorManager::instance();
  86          $key = $man->createKey( $context, $source, $comment );
  87  
  88          if ( !isset( $this->Messages[$key] ) )
  89          {
  90              $translation = $this->borkify( $source );
  91              $this->Messages[$key] = $man->createMessage( $context, $source, $comment, $translation );
  92          }
  93  
  94          return $this->Messages[$key];
  95      }
  96  
  97      /*!
  98       Translates the text into bork code.
  99      */
 100      function borkify( $text )
 101      {
 102          $textBlocks = preg_split( "/(%[^ ]+)/", $text, -1, PREG_SPLIT_DELIM_CAPTURE );
 103          $newTextBlocks = array();
 104          foreach ( $textBlocks as $text )
 105          {
 106              if ( $text[0] == '%' )
 107              {
 108                  $newTextBlocks[] = $text;
 109                  continue;
 110              }
 111              $orgtext = $text;
 112              $text = preg_replace( "/a\B/", "e", $text );
 113              $text = preg_replace( "/an/", "un", $text );
 114              $text = preg_replace( "/au/", "oo", $text );
 115              $text = preg_replace( "/en\b/", "ee", $text );
 116              $text = preg_replace( "/\Bew/", "oo", $text );
 117              $text = preg_replace( "/\Bf/", "ff", $text );
 118              $text = preg_replace( "/\Bi/", "ee", $text );
 119              $text = preg_replace( "/\Bir/", "ur", $text );
 120              $text = preg_replace( "/\bo/", "oo", $text );
 121              $text = preg_replace( "/ow/", "oo", $text );
 122              $text = preg_replace( "/ph/", "f", $text );
 123              $text = preg_replace( "/th\b/", "t", $text );
 124              $text = preg_replace( "/\Btion/", "shun", $text );
 125              $text = preg_replace( "/\Bu/", "oo", $text );
 126              $text = preg_replace( "/\bU/", "Oo", $text );
 127              $text = preg_replace( "/y\b/", "ai", $text );
 128              $text = preg_replace( "/v/", "f", $text );
 129              $text = preg_replace( "/w/", "v", $text );
 130              $text = preg_replace( "/ooo/", "oo", $text );
 131              if ( $orgtext == $text )
 132                  $text = $text . "-a";
 133              $newTextBlocks[] = $text;
 134          }
 135          $text = implode( '', $newTextBlocks );
 136          $text = preg_replace( "/([:.?!])(.*)/", "\\2\\1", $text );
 137          $text = "[" . $text . "]";
 138          return $text;
 139      }
 140  
 141      /*!
 142       \reimp
 143      */
 144      function translate( $context, $source, $comment = null )
 145      {
 146          $msg = $this->findMessage( $context, $source, $comment );
 147          if ( $msg !== null )
 148          {
 149              return $msg["translation"];
 150          }
 151  
 152          return null;
 153      }
 154  
 155      /*!
 156       \static
 157       Initialize the bork translator if this is not allready done.
 158      */
 159      function &initialize()
 160      {
 161          $translator =& $GLOBALS["eZBorkTranslator"];
 162          if ( isset( $translator ) and get_class( $translator ) == "ezborktranslator" )
 163              return $translator;
 164          $translator = new eZBorkTranslator();
 165          $man =& eZTranslatorManager::instance();
 166          $man->registerHandler( $translator );
 167          return $translator;
 168      }
 169  
 170      /// \privatesection
 171      /// Contains the hash table with cached bork translations
 172      var $Messages;
 173  }
 174  
 175  ?>


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