squirrelmail-webmail  1.4.22
About: SquirrelMail is a standards-based webmail package with strong MIME support, address books, and folder manipulation (written in PHP4).
  Fossies Dox: squirrelmail-webmail-1.4.22.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

gettext.php
Go to the documentation of this file.
1 <?php
2 
20 require_once(SM_PATH . 'functions/global.php');
21 
25 
26 if (! isset($gettext_php_loaded)) {
27  $gettext_php_loaded = false;
28  sqsession_register($gettext_php_loaded, 'gettext_php_loaded');
29 }
30 if (! isset($gettext_php_domain)) {
32  sqsession_register($gettext_php_domain, 'gettext_php_domain');
33 }
34 if (! isset($gettext_php_dir)) {
35  $gettext_php_dir = '';
36  sqsession_register($gettext_php_dir, 'gettext_php_dir');
37 }
38 if (! isset($gettext_php_translateStrings)) {
40  sqsession_register($gettext_php_translateStrings, 'gettext_php_translateStrings');
41 }
42 if (! isset($gettext_php_loaded_language)) {
44  sqsession_register($gettext_php_loaded_language, 'gettext_php_loaded_language');
45 }
46 if (! isset($gettext_php_short_circuit)) {
48  sqsession_register($gettext_php_short_circuit, 'gettext_php_short_circuit');
49 }
50 
62 
63  /*
64  * $squirrelmail_language gives 'en' for English, 'de' for German,
65  * etc. I didn't wanna use getenv or similar, but you easily could
66  * change my code to do that.
67  */
68 
70 
71  $gettext_php_short_circuit = false; /* initialization */
72 
74  if (substr($filename, -1) != '/')
75  $filename .= '/';
76  $filename .= $squirrelmail_language . '/LC_MESSAGES/' .
77  $gettext_php_domain . '.po';
78 
79  $file = @fopen($filename, 'r');
80  if ($file == false) {
81  /* Uh-ho -- we can't load the file. Just fake it. :-)
82  This is also for English, which doesn't use translations */
83  $gettext_php_loaded = true;
85  /* Avoid fuzzy matching when we didn't load strings */
87  return;
88  }
89 
90  $key = '';
91  $SkipRead = false;
92  while (! feof($file)) {
93  if (! $SkipRead) {
94  $line = trim(fgets($file, 4096));
95  } else {
96  $SkipRead = false;
97  }
98 
99  if (preg_match('/^msgid "(.*)"$/', $line, $match)) {
100  if ($match[1] == '') {
101  /*
102  * Potential multi-line
103  * msgid ""
104  * "string string "
105  * "string string"
106  */
107  $key = '';
108  $line = trim(fgets($file, 4096));
109  while (preg_match('/^[ ]*"(.*)"[ ]*$/', $line, $match)) {
110  $key .= $match[1];
111  $line = trim(fgets($file, 4096));
112  }
113  $SkipRead = true;
114  } else {
115  /* msgid "string string" */
116  $key = $match[1];
117  }
118  } elseif (preg_match('/^msgstr "(.*)"$/', $line, $match)) {
119  if ($match[1] == '') {
120  /*
121  * Potential multi-line
122  * msgstr ""
123  * "string string "
124  * "string string"
125  */
127  $line = trim(fgets($file, 4096));
128  while (preg_match('/^[ ]*"(.*)"[ ]*$/', $line, $match)) {
129  $gettext_php_translateStrings[$key] .= $match[1];
130  $line = trim(fgets($file, 4096));
131  }
132  $SkipRead = true;
133  } else {
134  /* msgstr "string string" */
135  $gettext_php_translateStrings[$key] = $match[1];
136  }
138  stripslashes($gettext_php_translateStrings[$key]);
139  /* If there is no translation, just use the untranslated string */
140  if ($gettext_php_translateStrings[$key] == '') {
141  $gettext_php_translateStrings[$key] = $key;
142  }
143  $key = '';
144  }
145  }
146  fclose($file);
147 
148  $gettext_php_loaded = true;
150 }
151 
160 function _($str) {
164 
165  if (! $gettext_php_loaded ||
168  }
169 
170  /* Try finding the exact string */
171  if (isset($gettext_php_translateStrings[$str])) {
172  return $gettext_php_translateStrings[$str];
173  }
174 
175  /* See if we should short-circuit */
177  $gettext_php_translateStrings[$str] = $str;
178  return $str;
179  }
180 
181  /* don't do fuzzy matching for strings with sprintf() formating */
182  if (! preg_match('/\%[\%bcdeufFosxX]/',$str)) {
183  /* Look for a string that is very close to the one we want
184  * Very computationally expensive */
185  $oldPercent = 0;
186  $oldStr = '';
187  $newPercent = 0;
188  foreach ($gettext_php_translateStrings as $k => $v) {
189  similar_text($str, $k, $newPercent);
190  if ($newPercent > $oldPercent) {
191  $oldStr = $v;
192  $oldPercent = $newPercent;
193  }
194  }
195  /* Require 80% match or better
196  * Adjust to suit your needs */
197  if ($oldPercent > 80) {
198  /* Remember this so we don't need to search again */
199  $gettext_php_translateStrings[$str] = $oldStr;
200  return $oldStr;
201  }
202  }
203  /* Remember this so we don't need to search again */
204  $gettext_php_translateStrings[$str] = $str;
205  return $str;
206 }
207 
218 function bindtextdomain($name, $dir) {
220 
221  if ($gettext_php_domain != $name) {
222  $gettext_php_domain = $name;
223  $gettext_php_loaded = false;
224  }
225  if ($gettext_php_dir != $dir) {
226  $gettext_php_dir = $dir;
227  $gettext_php_loaded = false;
228  }
229 
230  return $dir;
231 }
232 
242 function textdomain($name = false) {
244 
245  if ($name != false && $gettext_php_domain != $name) {
246  $gettext_php_domain = $name;
247  $gettext_php_loaded = false;
248  }
249 
250  return $gettext_php_domain;
251 }
elseif
if(! sqgetGlobalVar('sound', $sound, SQ_GET)) elseif($sound=='(none)')
Definition: testsound.php:25
$gettext_php_loaded_language
global $gettext_php_loaded_language
Definition: gettext.php:20
bindtextdomain
bindtextdomain($name, $dir)
Definition: gettext.php:218
$gettext_php_loaded
global $gettext_php_loaded
Definition: gettext.php:20
$gettext_php_translateStrings
global $gettext_php_translateStrings
Definition: gettext.php:20
$gettext_php_short_circuit
global $gettext_php_short_circuit
Definition: gettext.php:20
$filename
if(isset($override_type0)) if(isset($override_type1)) $filename
Definition: download.php:97
SM_PATH
const SM_PATH
Definition: decrypt_headers.php:16
textdomain
textdomain($name=false)
Definition: gettext.php:242
sqsession_register
sqsession_register($var, $name)
Definition: global.php:289
_
_($str)
Definition: gettext.php:160
gettext_php_load_strings
if(! isset($gettext_php_loaded)) if(! isset($gettext_php_domain)) if(! isset($gettext_php_dir)) if(! isset($gettext_php_translateStrings)) if(! isset($gettext_php_loaded_language)) if(! isset($gettext_php_short_circuit)) gettext_php_load_strings()
Definition: gettext.php:58
$squirrelmail_language
global $squirrelmail_language
Definition: i18n.php:774
$gettext_php_dir
global $gettext_php_dir
Definition: gettext.php:20
$gettext_php_domain
global $gettext_php_domain
Definition: gettext.php:20