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
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 ?>