Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezborktranslator.php
Go to the documentation of this file.
1 <?php
45 class eZBorkTranslator extends eZTranslatorHandler
46 {
47 public function __construct()
48 {
49 parent::__construct( false );
50
51 $this->Messages = array();
52 }
53
54 function findMessage( $context, $source, $comment = null )
55 {
56 $man = eZTranslatorManager::instance();
57 $key = $man->createKey( $context, $source, $comment );
58
59 if ( !isset( $this->Messages[$key] ) )
60 {
61 $translation = $this->borkify( $source );
62 $this->Messages[$key] = $man->createMessage( $context, $source, $comment, $translation );
63 }
64
65 return $this->Messages[$key];
66 }
67
71 function borkify( $text )
72 {
73 $textBlocks = preg_split( "/(%[^ ]+)/", $text, -1, PREG_SPLIT_DELIM_CAPTURE );
74 $newTextBlocks = array();
75 foreach ( $textBlocks as $text )
76 {
77 if ( $text[0] == '%' )
78 {
79 $newTextBlocks[] = $text;
80 continue;
81 }
82 $orgtext = $text;
83 $text = preg_replace( "/a\B/", "e", $text );
84 $text = preg_replace( "/an/", "un", $text );
85 $text = preg_replace( "/au/", "oo", $text );
86 $text = preg_replace( "/en\b/", "ee", $text );
87 $text = preg_replace( "/\Bew/", "oo", $text );
88 $text = preg_replace( "/\Bf/", "ff", $text );
89 $text = preg_replace( "/\Bi/", "ee", $text );
90 $text = preg_replace( "/\Bir/", "ur", $text );
91 $text = preg_replace( "/\bo/", "oo", $text );
92 $text = preg_replace( "/ow/", "oo", $text );
93 $text = preg_replace( "/ph/", "f", $text );
94 $text = preg_replace( "/th\b/", "t", $text );
95 $text = preg_replace( "/\Btion/", "shun", $text );
96 $text = preg_replace( "/\Bu/", "oo", $text );
97 $text = preg_replace( "/\bU/", "Oo", $text );
98 $text = preg_replace( "/y\b/", "ai", $text );
99 $text = preg_replace( "/v/", "f", $text );
100 $text = preg_replace( "/w/", "v", $text );
101 $text = preg_replace( "/ooo/", "oo", $text );
102 if ( $orgtext == $text )
103 $text = $text . "-a";
104 $newTextBlocks[] = $text;
105 }
106 $text = implode( '', $newTextBlocks );
107 $text = preg_replace( "/([:.?!])(.*)/", "\\2\\1", $text );
108 $text = "[" . $text . "]";
109 return $text;
110 }
111
112 function translate( $context, $source, $comment = null )
113 {
114 $msg = $this->findMessage( $context, $source, $comment );
115 if ( $msg !== null )
116 {
117 return $msg["translation"];
118 }
119
120 return null;
121 }
122
127 static function initialize()
128 {
129 if ( !isset( $GLOBALS['eZBorkTranslator'] ) ||
130 !( $GLOBALS['eZBorkTranslator'] instanceof eZBorkTranslator ) )
131 {
132 $GLOBALS['eZBorkTranslator'] = new eZBorkTranslator();
133 }
134
135 $man = eZTranslatorManager::instance();
136 $man->registerHandler( $GLOBALS['eZBorkTranslator'] );
137 return $GLOBALS['eZBorkTranslator'];
138 }
139
142 public $Messages;
143 }
144
145 ?>
eZBorkTranslator
Translates text into the Bork language (Mock Swedish)
Definition: ezborktranslator.php:46
eZBorkTranslator\__construct
__construct()
Definition: ezborktranslator.php:47
eZBorkTranslator\borkify
borkify( $text)
Definition: ezborktranslator.php:71
eZBorkTranslator\$Messages
$Messages
Definition: ezborktranslator.php:142
eZBorkTranslator\findMessage
findMessage( $context, $source, $comment=null)
Definition: ezborktranslator.php:54
eZBorkTranslator\initialize
static initialize()
Definition: ezborktranslator.php:127
eZBorkTranslator\translate
translate( $context, $source, $comment=null)
Definition: ezborktranslator.php:112
eZTranslatorHandler
Base class for translation handling.
Definition: eztranslatorhandler.php:19
eZTranslatorManager\instance
static instance()
Definition: eztranslatormanager.php:127
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.