ezborktranslator.php

Go to the documentation of this file.
00001 <?php
00002 //
00003 // Definition of eZBorkTranslator class
00004 //
00005 // Created on: <07-Jun-2002 12:40:42 amos>
00006 //
00007 // Copyright (C) 1999-2003 Exponential. All rights reserved.
00008 //
00009 // This source file is part of the Exponential (tm) Open Source Content
00010 // Management System.
00011 //
00012 // This file may be distributed and/or modified under the terms of the
00013 // "GNU General Public License" version 2 as published by the Free
00014 // Software Foundation and appearing in the file LICENSE.GPL included in
00015 // the packaging of this file.
00016 //
00017 // Licencees holding valid "Exponential professional licences" may use this
00018 // file in accordance with the "Exponential professional licence" Agreement
00019 // provided with the Software.
00020 //
00021 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING
00022 // THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00023 // PURPOSE.
00024 //
00025 // The "Exponential professional licence" is available at
00026 // http://ez.no/products/licences/professional/. For pricing of this licence
00027 // please contact us via e-mail to licence@ez.no. Further contact
00028 // information is available at http://ez.no/home/contact/.
00029 //
00030 // The "GNU General Public License" (GPL) is available at
00031 // http://www.gnu.org/copyleft/gpl.html.
00032 //
00033 // Contact licence@ez.no if any conditions of this licencing isn't clear to
00034 // you.
00035 //
00036 
00074 include_once( "lib/ezi18n/classes/eztranslatorhandler.php" );
00075 
eZTranslatorHandler
00077 {
eZBorkTranslator()
00082     {
00083         $this->eZTranslatorHandler( false );
00084 
00085         $this->Messages = array();
00086     }
00087 
findMessage( $context, $source, $comment = null )
00092     {
00093         $man =& eZTranslatorManager::instance();
00094         $key = $man->createKey( $context, $source, $comment );
00095 
00096         if ( !isset( $this->Messages[$key] ) )
00097         {
00098             $translation = $this->borkify( $source );
00099             $msg = $man->createMessage( $context, $source, $comment, $translation );
00100             $this->Messages[$key] =& $msg;
00101         }
00102         else
00103             $msg =& $this->Messages[$key];
00104         return $msg;
00105     }
00106 
borkify( $text )
00111     {
00112         $orgtext = $text;
00113         $text = preg_replace( "/a\B/", "e", $text );
00114         $text = preg_replace( "/an/", "un", $text );
00115         $text = preg_replace( "/au/", "oo", $text );
00116         $text = preg_replace( "/en\b/", "ee", $text );
00117         $text = preg_replace( "/\Bew/", "oo", $text );
00118         $text = preg_replace( "/\Bf/", "ff", $text );
00119         $text = preg_replace( "/\Bi/", "ee", $text );
00120         $text = preg_replace( "/\Bir/", "ur", $text );
00121         $text = preg_replace( "/\bo/", "oo", $text );
00122         $text = preg_replace( "/ow/", "oo", $text );
00123         $text = preg_replace( "/ph/", "f", $text );
00124         $text = preg_replace( "/th\b/", "t", $text );
00125         $text = preg_replace( "/\Btion/", "shun", $text );
00126         $text = preg_replace( "/\Bu/", "oo", $text );
00127         $text = preg_replace( "/\bU/", "Oo", $text );
00128         $text = preg_replace( "/y\b/", "ai", $text );
00129         $text = preg_replace( "/v/", "f", $text );
00130         $text = preg_replace( "/w/", "v", $text );
00131         $text = preg_replace( "/ooo/", "oo", $text );
00132         if ( $orgtext == $text )
00133             $text = $text . "-a";
00134         $text = preg_replace( "/([:.?!])(.*)/", "\\2\\1", $text );
00135         $text = "[" . $text . "]";
00136         return $text;
00137     }
00138 
translate( $context, $source, $comment = null )
00143     {
00144         $msg =& $this->findMessage( $context, $source, $comment );
00145         if ( $msg !== null )
00146             return $msg["translation"];
00147         else
00148             return null;
00149     }
00150 
initialize()
00156     {
00157         $translator =& $GLOBALS["eZBorkTranslator"];
00158         if ( isset( $translator ) and get_class( $translator ) == "ezborktranslator" )
00159             return $translator;
00160         $translator = new eZBorkTranslator();
00161         $man =& eZTranslatorManager::instance();
00162         $man->registerHandler( $translator );
00163         return $translator;
00164     }
00165 
Messages;
00169 }
00170 
00171 ?>
 

Exponential