Completed
Branch master (303d1b)
by Stefan
02:18
created
php-gettext/gettext.php 1 patch
Braces   +47 added lines, -35 removed lines patch added patch discarded remove patch
@@ -140,8 +140,9 @@  discard block
 block discarded – undo
140 140
   function load_tables() {
141 141
     if (is_array($this->cache_translations) &&
142 142
       is_array($this->table_originals) &&
143
-      is_array($this->table_translations))
144
-      return;
143
+      is_array($this->table_translations)) {
144
+          return;
145
+    }
145 146
 
146 147
     /* get original and translations tables */
147 148
     if (!is_array($this->table_originals)) {
@@ -176,8 +177,9 @@  discard block
 block discarded – undo
176 177
   function get_original_string($num) {
177 178
     $length = $this->table_originals[$num * 2 + 1];
178 179
     $offset = $this->table_originals[$num * 2 + 2];
179
-    if (! $length)
180
-      return '';
180
+    if (! $length) {
181
+          return '';
182
+    }
181 183
     $this->STREAM->seekto($offset);
182 184
     $data = $this->STREAM->read($length);
183 185
     return (string)$data;
@@ -193,8 +195,9 @@  discard block
 block discarded – undo
193 195
   function get_translation_string($num) {
194 196
     $length = $this->table_translations[$num * 2 + 1];
195 197
     $offset = $this->table_translations[$num * 2 + 2];
196
-    if (! $length)
197
-      return '';
198
+    if (! $length) {
199
+          return '';
200
+    }
198 201
     $this->STREAM->seekto($offset);
199 202
     $data = $this->STREAM->read($length);
200 203
     return (string)$data;
@@ -218,10 +221,11 @@  discard block
 block discarded – undo
218 221
     if (abs($start - $end) <= 1) {
219 222
       // We're done, now we either found the string, or it doesn't exist
220 223
       $txt = $this->get_original_string($start);
221
-      if ($string == $txt)
222
-        return $start;
223
-      else
224
-        return -1;
224
+      if ($string == $txt) {
225
+              return $start;
226
+      } else {
227
+              return -1;
228
+      }
225 229
     } else if ($start > $end) {
226 230
       // start > end -> turn around and start over
227 231
       return $this->find_string($string, $end, $start);
@@ -229,15 +233,16 @@  discard block
 block discarded – undo
229 233
       // Divide table in two parts
230 234
       $half = (int)(($start + $end) / 2);
231 235
       $cmp = strcmp($string, $this->get_original_string($half));
232
-      if ($cmp == 0)
233
-        // string is exactly in the middle => return it
236
+      if ($cmp == 0) {
237
+              // string is exactly in the middle => return it
234 238
         return $half;
235
-      else if ($cmp < 0)
236
-        // The string is in the upper half
239
+      } else if ($cmp < 0) {
240
+              // The string is in the upper half
237 241
         return $this->find_string($string, $start, $half);
238
-      else
239
-        // The string is in the lower half
242
+      } else {
243
+              // The string is in the lower half
240 244
         return $this->find_string($string, $half, $end);
245
+      }
241 246
     }
242 247
   }
243 248
 
@@ -249,23 +254,26 @@  discard block
 block discarded – undo
249 254
    * @return string translated string (or original, if not found)
250 255
    */
251 256
   function translate($string) {
252
-    if ($this->short_circuit)
253
-      return $string;
257
+    if ($this->short_circuit) {
258
+          return $string;
259
+    }
254 260
     $this->load_tables();
255 261
 
256 262
     if ($this->enable_cache) {
257 263
       // Caching enabled, get translated string from cache
258
-      if (array_key_exists($string, $this->cache_translations))
259
-        return $this->cache_translations[$string];
260
-      else
261
-        return $string;
264
+      if (array_key_exists($string, $this->cache_translations)) {
265
+              return $this->cache_translations[$string];
266
+      } else {
267
+              return $string;
268
+      }
262 269
     } else {
263 270
       // Caching not enabled, try to find string
264 271
       $num = $this->find_string($string);
265
-      if ($num == -1)
266
-        return $string;
267
-      else
268
-        return $this->get_translation_string($num);
272
+      if ($num == -1) {
273
+              return $string;
274
+      } else {
275
+              return $this->get_translation_string($num);
276
+      }
269 277
     }
270 278
   }
271 279
 
@@ -311,10 +319,11 @@  discard block
 block discarded – undo
311 319
    * @return string verbatim plural form header field
312 320
    */
313 321
   function extract_plural_forms_header_from_po_header($header) {
314
-    if (preg_match("/(^|\n)plural-forms: ([^\n]*)\n/i", $header, $regs))
315
-      $expr = $regs[2];
316
-    else
317
-      $expr = "nplurals=2; plural=n == 1 ? 0 : 1;";
322
+    if (preg_match("/(^|\n)plural-forms: ([^\n]*)\n/i", $header, $regs)) {
323
+          $expr = $regs[2];
324
+    } else {
325
+          $expr = "nplurals=2; plural=n == 1 ? 0 : 1;";
326
+    }
318 327
     return $expr;
319 328
   }
320 329
 
@@ -359,7 +368,9 @@  discard block
 block discarded – undo
359 368
     $plural = 0;
360 369
 
361 370
     eval("$string");
362
-    if ($plural >= $total) $plural = $total - 1;
371
+    if ($plural >= $total) {
372
+        $plural = $total - 1;
373
+    }
363 374
     return $plural;
364 375
   }
365 376
 
@@ -374,10 +385,11 @@  discard block
 block discarded – undo
374 385
    */
375 386
   function ngettext($single, $plural, $number) {
376 387
     if ($this->short_circuit) {
377
-      if ($number != 1)
378
-        return $plural;
379
-      else
380
-        return $single;
388
+      if ($number != 1) {
389
+              return $plural;
390
+      } else {
391
+              return $single;
392
+      }
381 393
     }
382 394
 
383 395
     // find out the appropriate form
Please login to merge, or discard this patch.
php-gettext/streams.php 1 patch
Braces   +9 added lines, -5 removed lines patch added patch discarded remove patch
@@ -57,16 +57,18 @@  discard block
 block discarded – undo
57 57
   function read($bytes) {
58 58
     $data = substr($this->_str, $this->_pos, $bytes);
59 59
     $this->_pos += $bytes;
60
-    if (strlen($this->_str)<$this->_pos)
61
-      $this->_pos = strlen($this->_str);
60
+    if (strlen($this->_str)<$this->_pos) {
61
+          $this->_pos = strlen($this->_str);
62
+    }
62 63
 
63 64
     return $data;
64 65
   }
65 66
 
66 67
   function seekto($pos) {
67 68
     $this->_pos = $pos;
68
-    if (strlen($this->_str)<$this->_pos)
69
-      $this->_pos = strlen($this->_str);
69
+    if (strlen($this->_str)<$this->_pos) {
70
+          $this->_pos = strlen($this->_str);
71
+    }
70 72
     return $this->_pos;
71 73
   }
72 74
 
@@ -117,7 +119,9 @@  discard block
 block discarded – undo
117 119
       $this->_pos = ftell($this->_fd);
118 120
 
119 121
       return $data;
120
-    } else return '';
122
+    } else {
123
+        return '';
124
+    }
121 125
   }
122 126
 
123 127
   function seekto($pos) {
Please login to merge, or discard this patch.
php-gettext/gettext.inc 1 patch
Braces   +147 added lines, -95 removed lines patch added patch discarded remove patch
@@ -80,32 +80,45 @@  discard block
 block discarded – undo
80 80
                    ."(?:@(?P<modifier>[-A-Za-z0-9_]+))?$/",  // @ modifier
81 81
                    $locale, $matches)) {
82 82
 
83
-      if (isset($matches["lang"])) $lang = $matches["lang"];
84
-      if (isset($matches["country"])) $country = $matches["country"];
85
-      if (isset($matches["charset"])) $charset = $matches["charset"];
86
-      if (isset($matches["modifier"])) $modifier = $matches["modifier"];
83
+      if (isset($matches["lang"])) {
84
+          $lang = $matches["lang"];
85
+      }
86
+      if (isset($matches["country"])) {
87
+          $country = $matches["country"];
88
+      }
89
+      if (isset($matches["charset"])) {
90
+          $charset = $matches["charset"];
91
+      }
92
+      if (isset($matches["modifier"])) {
93
+          $modifier = $matches["modifier"];
94
+      }
87 95
 
88 96
       if ($modifier) {
89 97
         if ($country) {
90
-          if ($charset)
91
-            array_push($locale_names, "${lang}_$country.$charset@$modifier");
98
+          if ($charset) {
99
+                      array_push($locale_names, "${lang}_$country.$charset@$modifier");
100
+          }
92 101
           array_push($locale_names, "${lang}_$country@$modifier");
93
-        } elseif ($charset)
94
-            array_push($locale_names, "${lang}.$charset@$modifier");
102
+        } elseif ($charset) {
103
+                    array_push($locale_names, "${lang}.$charset@$modifier");
104
+        }
95 105
         array_push($locale_names, "$lang@$modifier");
96 106
       }
97 107
       if ($country) {
98
-        if ($charset)
99
-          array_push($locale_names, "${lang}_$country.$charset");
108
+        if ($charset) {
109
+                  array_push($locale_names, "${lang}_$country.$charset");
110
+        }
100 111
         array_push($locale_names, "${lang}_$country");
101
-      } elseif ($charset)
102
-          array_push($locale_names, "${lang}.$charset");
112
+      } elseif ($charset) {
113
+                array_push($locale_names, "${lang}.$charset");
114
+      }
103 115
       array_push($locale_names, $lang);
104 116
     }
105 117
 
106 118
     // If the locale name doesn't match POSIX style, just include it as-is.
107
-    if (!in_array($locale, $locale_names))
108
-      array_push($locale_names, $locale);
119
+    if (!in_array($locale, $locale_names)) {
120
+          array_push($locale_names, $locale);
121
+    }
109 122
   }
110 123
   return $locale_names;
111 124
 }
@@ -115,7 +128,9 @@  discard block
 block discarded – undo
115 128
  */
116 129
 function _get_reader($domain=null, $category=5, $enable_cache=true) {
117 130
     global $text_domains, $default_domain, $LC_CATEGORIES;
118
-    if (!isset($domain)) $domain = $default_domain;
131
+    if (!isset($domain)) {
132
+        $domain = $default_domain;
133
+    }
119 134
     if (!isset($text_domains[$domain]->l10n)) {
120 135
         // get the current locale
121 136
         $locale = _setlocale(LC_MESSAGES, 0);
@@ -156,8 +171,9 @@  discard block
 block discarded – undo
156 171
  */
157 172
 function _check_locale_and_function($function=false) {
158 173
     global $EMULATEGETTEXT;
159
-    if ($function and !function_exists($function))
160
-        return false;
174
+    if ($function and !function_exists($function)) {
175
+            return false;
176
+    }
161 177
     return !$EMULATEGETTEXT;
162 178
 }
163 179
 
@@ -166,7 +182,9 @@  discard block
 block discarded – undo
166 182
  */
167 183
 function _get_codeset($domain=null) {
168 184
     global $text_domains, $default_domain, $LC_CATEGORIES;
169
-    if (!isset($domain)) $domain = $default_domain;
185
+    if (!isset($domain)) {
186
+        $domain = $default_domain;
187
+    }
170 188
     return (isset($text_domains[$domain]->codeset))? $text_domains[$domain]->codeset : ini_get('mbstring.internal_encoding');
171 189
 }
172 190
 
@@ -178,8 +196,7 @@  discard block
 block discarded – undo
178 196
     $target_encoding = _get_codeset();
179 197
     if ($source_encoding != $target_encoding) {
180 198
         return mb_convert_encoding($text, $target_encoding, $source_encoding);
181
-    }
182
-    else {
199
+    } else {
183 200
         return $text;
184 201
     }
185 202
 }
@@ -191,11 +208,13 @@  discard block
 block discarded – undo
191 208
  * Returns passed in $locale, or environment variable $LANG if $locale == ''.
192 209
  */
193 210
 function _get_default_locale($locale) {
194
-  if ($locale == '') // emulate variable support
211
+  if ($locale == '') {
212
+      // emulate variable support
195 213
     return getenv('LANG');
196
-  else
197
-    return $locale;
198
-}
214
+  } else {
215
+      return $locale;
216
+  }
217
+  }
199 218
 
200 219
 /**
201 220
  * Sets a requested locale, if needed emulates it.
@@ -203,12 +222,13 @@  discard block
 block discarded – undo
203 222
 function _setlocale($category, $locale) {
204 223
     global $CURRENTLOCALE, $EMULATEGETTEXT;
205 224
     if ($locale === 0) { // use === to differentiate between string "0"
206
-        if ($CURRENTLOCALE != '')
207
-            return $CURRENTLOCALE;
208
-        else
209
-            // obey LANG variable, maybe extend to support all of LC_* vars
225
+        if ($CURRENTLOCALE != '') {
226
+                    return $CURRENTLOCALE;
227
+        } else {
228
+                    // obey LANG variable, maybe extend to support all of LC_* vars
210 229
             // even if we tried to read locale without setting it first
211 230
             return _setlocale($category, $CURRENTLOCALE);
231
+        }
212 232
     } else {
213 233
         if (function_exists('setlocale')) {
214 234
           $ret = setlocale($category, $locale);
@@ -242,11 +262,13 @@  discard block
 block discarded – undo
242 262
     global $text_domains;
243 263
     // ensure $path ends with a slash ('/' should work for both, but lets still play nice)
244 264
     if (substr(php_uname(), 0, 7) == "Windows") {
245
-      if ($path[strlen($path)-1] != '\\' and $path[strlen($path)-1] != '/')
246
-        $path .= '\\';
265
+      if ($path[strlen($path)-1] != '\\' and $path[strlen($path)-1] != '/') {
266
+              $path .= '\\';
267
+      }
247 268
     } else {
248
-      if ($path[strlen($path)-1] != '/')
249
-        $path .= '/';
269
+      if ($path[strlen($path)-1] != '/') {
270
+              $path .= '/';
271
+      }
250 272
     }
251 273
     if (!array_key_exists($domain, $text_domains)) {
252 274
       // Initialize an empty domain object.
@@ -385,96 +407,126 @@  discard block
 block discarded – undo
385 407
 }
386 408
 
387 409
 function T_bindtextdomain($domain, $path) {
388
-    if (_check_locale_and_function()) return bindtextdomain($domain, $path);
389
-    else return _bindtextdomain($domain, $path);
390
-}
410
+    if (_check_locale_and_function()) {
411
+        return bindtextdomain($domain, $path);
412
+    } else {
413
+        return _bindtextdomain($domain, $path);
414
+    }
415
+    }
391 416
 function T_bind_textdomain_codeset($domain, $codeset) {
392 417
     // bind_textdomain_codeset is available only in PHP 4.2.0+
393
-    if (_check_locale_and_function('bind_textdomain_codeset'))
394
-        return bind_textdomain_codeset($domain, $codeset);
395
-    else return _bind_textdomain_codeset($domain, $codeset);
396
-}
418
+    if (_check_locale_and_function('bind_textdomain_codeset')) {
419
+            return bind_textdomain_codeset($domain, $codeset);
420
+    } else {
421
+        return _bind_textdomain_codeset($domain, $codeset);
422
+    }
423
+    }
397 424
 function T_textdomain($domain) {
398
-    if (_check_locale_and_function()) return textdomain($domain);
399
-    else return _textdomain($domain);
400
-}
425
+    if (_check_locale_and_function()) {
426
+        return textdomain($domain);
427
+    } else {
428
+        return _textdomain($domain);
429
+    }
430
+    }
401 431
 function T_gettext($msgid) {
402
-    if (_check_locale_and_function()) return gettext($msgid);
403
-    else return _gettext($msgid);
404
-}
432
+    if (_check_locale_and_function()) {
433
+        return gettext($msgid);
434
+    } else {
435
+        return _gettext($msgid);
436
+    }
437
+    }
405 438
 function T_($msgid) {
406
-    if (_check_locale_and_function()) return _($msgid);
439
+    if (_check_locale_and_function()) {
440
+        return _($msgid);
441
+    }
407 442
     return __($msgid);
408 443
 }
409 444
 function T_ngettext($singular, $plural, $number) {
410
-    if (_check_locale_and_function())
411
-        return ngettext($singular, $plural, $number);
412
-    else return _ngettext($singular, $plural, $number);
413
-}
445
+    if (_check_locale_and_function()) {
446
+            return ngettext($singular, $plural, $number);
447
+    } else {
448
+        return _ngettext($singular, $plural, $number);
449
+    }
450
+    }
414 451
 function T_dgettext($domain, $msgid) {
415
-    if (_check_locale_and_function()) return dgettext($domain, $msgid);
416
-    else return _dgettext($domain, $msgid);
417
-}
452
+    if (_check_locale_and_function()) {
453
+        return dgettext($domain, $msgid);
454
+    } else {
455
+        return _dgettext($domain, $msgid);
456
+    }
457
+    }
418 458
 function T_dngettext($domain, $singular, $plural, $number) {
419
-    if (_check_locale_and_function())
420
-        return dngettext($domain, $singular, $plural, $number);
421
-    else return _dngettext($domain, $singular, $plural, $number);
422
-}
459
+    if (_check_locale_and_function()) {
460
+            return dngettext($domain, $singular, $plural, $number);
461
+    } else {
462
+        return _dngettext($domain, $singular, $plural, $number);
463
+    }
464
+    }
423 465
 function T_dcgettext($domain, $msgid, $category) {
424
-    if (_check_locale_and_function())
425
-        return dcgettext($domain, $msgid, $category);
426
-    else return _dcgettext($domain, $msgid, $category);
427
-}
466
+    if (_check_locale_and_function()) {
467
+            return dcgettext($domain, $msgid, $category);
468
+    } else {
469
+        return _dcgettext($domain, $msgid, $category);
470
+    }
471
+    }
428 472
 function T_dcngettext($domain, $singular, $plural, $number, $category) {
429
-    if (_check_locale_and_function())
430
-      return dcngettext($domain, $singular, $plural, $number, $category);
431
-    else return _dcngettext($domain, $singular, $plural, $number, $category);
432
-}
473
+    if (_check_locale_and_function()) {
474
+          return dcngettext($domain, $singular, $plural, $number, $category);
475
+    } else {
476
+        return _dcngettext($domain, $singular, $plural, $number, $category);
477
+    }
478
+    }
433 479
 
434 480
 function T_pgettext($context, $msgid) {
435
-  if (_check_locale_and_function('pgettext'))
436
-      return pgettext($context, $msgid);
437
-  else
438
-      return _pgettext($context, $msgid);
439
-}
481
+  if (_check_locale_and_function('pgettext')) {
482
+        return pgettext($context, $msgid);
483
+  } else {
484
+        return _pgettext($context, $msgid);
485
+  }
486
+  }
440 487
 
441 488
 function T_dpgettext($domain, $context, $msgid) {
442
-  if (_check_locale_and_function('dpgettext'))
443
-      return dpgettext($domain, $context, $msgid);
444
-  else
445
-      return _dpgettext($domain, $context, $msgid);
446
-}
489
+  if (_check_locale_and_function('dpgettext')) {
490
+        return dpgettext($domain, $context, $msgid);
491
+  } else {
492
+        return _dpgettext($domain, $context, $msgid);
493
+  }
494
+  }
447 495
 
448 496
 function T_dcpgettext($domain, $context, $msgid, $category) {
449
-  if (_check_locale_and_function('dcpgettext'))
450
-      return dcpgettext($domain, $context, $msgid, $category);
451
-  else
452
-      return _dcpgettext($domain, $context, $msgid, $category);
453
-}
497
+  if (_check_locale_and_function('dcpgettext')) {
498
+        return dcpgettext($domain, $context, $msgid, $category);
499
+  } else {
500
+        return _dcpgettext($domain, $context, $msgid, $category);
501
+  }
502
+  }
454 503
 
455 504
 function T_npgettext($context, $singular, $plural, $number) {
456
-    if (_check_locale_and_function('npgettext'))
457
-        return npgettext($context, $singular, $plural, $number);
458
-    else
459
-        return _npgettext($context, $singular, $plural, $number);
460
-}
505
+    if (_check_locale_and_function('npgettext')) {
506
+            return npgettext($context, $singular, $plural, $number);
507
+    } else {
508
+            return _npgettext($context, $singular, $plural, $number);
509
+    }
510
+    }
461 511
 
462 512
 function T_dnpgettext($domain, $context, $singular, $plural, $number) {
463
-  if (_check_locale_and_function('dnpgettext'))
464
-      return dnpgettext($domain, $context, $singular, $plural, $number);
465
-  else
466
-      return _dnpgettext($domain, $context, $singular, $plural, $number);
467
-}
513
+  if (_check_locale_and_function('dnpgettext')) {
514
+        return dnpgettext($domain, $context, $singular, $plural, $number);
515
+  } else {
516
+        return _dnpgettext($domain, $context, $singular, $plural, $number);
517
+  }
518
+  }
468 519
 
469 520
 function T_dcnpgettext($domain, $context, $singular, $plural,
470 521
                        $number, $category) {
471
-    if (_check_locale_and_function('dcnpgettext'))
472
-        return dcnpgettext($domain, $context, $singular,
522
+    if (_check_locale_and_function('dcnpgettext')) {
523
+            return dcnpgettext($domain, $context, $singular,
473 524
                            $plural, $number, $category);
474
-    else
475
-        return _dcnpgettext($domain, $context, $singular,
525
+    } else {
526
+            return _dcnpgettext($domain, $context, $singular,
476 527
                             $plural, $number, $category);
477
-}
528
+    }
529
+    }
478 530
 
479 531
 
480 532
 
Please login to merge, or discard this patch.
i12n.php 1 patch
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -86,8 +86,7 @@
 block discarded – undo
86 86
 
87 87
     if (locale_emulation()) {
88 88
         print "locale '$locale' is not supported on your system, using custom gettext implementation.\n";
89
-    }
90
-    else {
89
+    } else {
91 90
         print "locale '$locale' is supported on your system, using native gettext implementation.\n";
92 91
     }
93 92
 
Please login to merge, or discard this patch.
login.php 1 patch
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -145,8 +145,7 @@
 block discarded – undo
145 145
        if ($_SERVER['SERVER_PROTOCOL'] == 'HTTP/1.1') {
146 146
         if (php_sapi_name() == 'cgi') {
147 147
          header('Status: 303 See Other');
148
-         }
149
-        else {
148
+         } else {
150 149
          header('HTTP/1.1 303 See Other');
151 150
          }
152 151
         }
Please login to merge, or discard this patch.