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
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068 include_once( "lib/ezi18n/classes/eztranslatorhandler.php" );
00069
00070 class eZBorkTranslator extends eZTranslatorHandler
00071 {
00072
00073
00074
00075 function eZBorkTranslator()
00076 {
00077 $this->eZTranslatorHandler( false );
00078
00079 $this->Messages = array();
00080 }
00081
00082
00083
00084
00085 function findMessage( $context, $source, $comment = null )
00086 {
00087 $man = eZTranslatorManager::instance();
00088 $key = $man->createKey( $context, $source, $comment );
00089
00090 if ( !isset( $this->Messages[$key] ) )
00091 {
00092 $translation = $this->borkify( $source );
00093 $this->Messages[$key] = $man->createMessage( $context, $source, $comment, $translation );
00094 }
00095
00096 return $this->Messages[$key];
00097 }
00098
00099
00100
00101
00102 function borkify( $text )
00103 {
00104 $textBlocks = preg_split( "/(%[^ ]+)/", $text, -1, PREG_SPLIT_DELIM_CAPTURE );
00105 $newTextBlocks = array();
00106 foreach ( $textBlocks as $text )
00107 {
00108 if ( $text[0] == '%' )
00109 {
00110 $newTextBlocks[] = $text;
00111 continue;
00112 }
00113 $orgtext = $text;
00114 $text = preg_replace( "/a\B/", "e", $text );
00115 $text = preg_replace( "/an/", "un", $text );
00116 $text = preg_replace( "/au/", "oo", $text );
00117 $text = preg_replace( "/en\b/", "ee", $text );
00118 $text = preg_replace( "/\Bew/", "oo", $text );
00119 $text = preg_replace( "/\Bf/", "ff", $text );
00120 $text = preg_replace( "/\Bi/", "ee", $text );
00121 $text = preg_replace( "/\Bir/", "ur", $text );
00122 $text = preg_replace( "/\bo/", "oo", $text );
00123 $text = preg_replace( "/ow/", "oo", $text );
00124 $text = preg_replace( "/ph/", "f", $text );
00125 $text = preg_replace( "/th\b/", "t", $text );
00126 $text = preg_replace( "/\Btion/", "shun", $text );
00127 $text = preg_replace( "/\Bu/", "oo", $text );
00128 $text = preg_replace( "/\bU/", "Oo", $text );
00129 $text = preg_replace( "/y\b/", "ai", $text );
00130 $text = preg_replace( "/v/", "f", $text );
00131 $text = preg_replace( "/w/", "v", $text );
00132 $text = preg_replace( "/ooo/", "oo", $text );
00133 if ( $orgtext == $text )
00134 $text = $text . "-a";
00135 $newTextBlocks[] = $text;
00136 }
00137 $text = implode( '', $newTextBlocks );
00138 $text = preg_replace( "/([:.?!])(.*)/", "\\2\\1", $text );
00139 $text = "[" . $text . "]";
00140 return $text;
00141 }
00142
00143
00144
00145
00146 function translate( $context, $source, $comment = null )
00147 {
00148 $msg = $this->findMessage( $context, $source, $comment );
00149 if ( $msg !== null )
00150 {
00151 return $msg["translation"];
00152 }
00153
00154 return null;
00155 }
00156
00157
00158
00159
00160
00161 function &initialize()
00162 {
00163 $translator =& $GLOBALS["eZBorkTranslator"];
00164 if ( isset( $translator ) and get_class( $translator ) == "ezborktranslator" )
00165 return $translator;
00166 $translator = new eZBorkTranslator();
00167 $man =& eZTranslatorManager::instance();
00168 $man->registerHandler( $translator );
00169 return $translator;
00170 }
00171
00172
00173
00174 var $Messages;
00175 }
00176
00177 ?>