|
eZ Publish
[4.0]
|
00001 <?php 00002 // 00003 // Definition of eZBorkTranslator class 00004 // 00005 // Created on: <07-Jun-2002 12:40:42 amos> 00006 // 00007 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00008 // SOFTWARE NAME: eZ Publish 00009 // SOFTWARE RELEASE: 4.0.x 00010 // COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS 00011 // SOFTWARE LICENSE: GNU General Public License v2.0 00012 // NOTICE: > 00013 // This program is free software; you can redistribute it and/or 00014 // modify it under the terms of version 2.0 of the GNU General 00015 // Public License as published by the Free Software Foundation. 00016 // 00017 // This program is distributed in the hope that it will be useful, 00018 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 // GNU General Public License for more details. 00021 // 00022 // You should have received a copy of version 2.0 of the GNU General 00023 // Public License along with this program; if not, write to the Free 00024 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 00025 // MA 02110-1301, USA. 00026 // 00027 // 00028 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00029 // 00030 00031 /*! \file ezborktranslator.php 00032 */ 00033 00034 /*! 00035 \class eZBorkTranslator ezborktranslator.php 00036 \ingroup eZTranslation 00037 \brief Translates text into the Bork language (Mock Swedish) 00038 00039 This translation is adapted from the Mock Swedish translation in Qt Quarterly 3/2002: 00040 http://doc.trolltech.com/qq/qq03-swedish-chef.html 00041 00042 It translates the following characters/strings: 00043 (The "|" sign stands for a word boundary, and "-" stands for mid-word.) 00044 00045 a- -> e 00046 an -> un 00047 au -> oo 00048 en| -> ee 00049 -ew -> oo 00050 -f -> ff 00051 -i -> ee 00052 -ir -> ur 00053 |o -> oo 00054 ow -> oo 00055 ph -> f 00056 th| -> t 00057 -tion -> shun 00058 -u -> oo 00059 |U- -> Oo 00060 y| -> ai 00061 v -> f 00062 w -> v 00063 00064 Words that are not changed by these rules will have "-a" appended to them. 00065 00066 */ 00067 00068 //include_once( "lib/ezi18n/classes/eztranslatorhandler.php" ); 00069 00070 class eZBorkTranslator extends eZTranslatorHandler 00071 { 00072 /*! 00073 Construct the translator. 00074 */ 00075 function eZBorkTranslator() 00076 { 00077 $this->eZTranslatorHandler( false ); 00078 00079 $this->Messages = array(); 00080 } 00081 00082 /*! 00083 \reimp 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 Translates the text into bork code. 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 \reimp 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 \static 00159 Initialize the bork translator if this is not allready done. 00160 */ 00161 static function initialize() 00162 { 00163 if ( !isset( $GLOBALS['eZBorkTranslator'] ) || 00164 !( $GLOBALS['eZBorkTranslator'] instanceof eZBorkTranslator ) ) 00165 { 00166 $GLOBALS['eZBorkTranslator'] = new eZBorkTranslator(); 00167 } 00168 00169 $man = eZTranslatorManager::instance(); 00170 $man->registerHandler( $GLOBALS['eZBorkTranslator'] ); 00171 return $GLOBALS['eZBorkTranslator']; 00172 } 00173 00174 /// \privatesection 00175 /// Contains the hash table with cached bork translations 00176 public $Messages; 00177 } 00178 00179 ?>