Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

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