Completed
Push — master ( 29af4c...6e7c94 )
by Michal
02:29
created
src/gettext.inc 1 patch
Indentation   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 // LC_MESSAGES is not available if php-gettext is not loaded
36 36
 // while the other constants are already available from session extension.
37 37
 if (!defined('LC_MESSAGES')) {
38
-  define('LC_MESSAGES',	5);
38
+    define('LC_MESSAGES',	5);
39 39
 }
40 40
 
41 41
 
@@ -50,9 +50,9 @@  discard block
 block discarded – undo
50 50
 
51 51
 /* Class to hold a single domain included in $text_domains. */
52 52
 class domain {
53
-  var $l10n;
54
-  var $path;
55
-  var $codeset;
53
+    var $l10n;
54
+    var $path;
55
+    var $codeset;
56 56
 }
57 57
 
58 58
 // Utility functions
@@ -61,50 +61,50 @@  discard block
 block discarded – undo
61 61
  * Return a list of locales to try for any POSIX-style locale specification.
62 62
  */
63 63
 function get_list_of_locales($locale) {
64
-  /* Figure out all possible locale names and start with the most
64
+    /* Figure out all possible locale names and start with the most
65 65
    * specific ones.  I.e. for sr_CS.UTF-8@latin, look through all of
66 66
    * sr_CS.UTF-8@latin, sr_CS@latin, sr@latin, sr_CS.UTF-8, sr_CS, sr.
67 67
    */
68
-  $locale_names = array();
69
-  $lang = NULL;
70
-  $country = NULL;
71
-  $charset = NULL;
72
-  $modifier = NULL;
73
-  if ($locale) {
68
+    $locale_names = array();
69
+    $lang = NULL;
70
+    $country = NULL;
71
+    $charset = NULL;
72
+    $modifier = NULL;
73
+    if ($locale) {
74 74
     if (preg_match("/^(?P<lang>[a-z]{2,3})"              // language code
75
-                   ."(?:_(?P<country>[A-Z]{2}))?"           // country code
76
-                   ."(?:\.(?P<charset>[-A-Za-z0-9_]+))?"    // charset
77
-                   ."(?:@(?P<modifier>[-A-Za-z0-9_]+))?$/",  // @ modifier
78
-                   $locale, $matches)) {
75
+                    ."(?:_(?P<country>[A-Z]{2}))?"           // country code
76
+                    ."(?:\.(?P<charset>[-A-Za-z0-9_]+))?"    // charset
77
+                    ."(?:@(?P<modifier>[-A-Za-z0-9_]+))?$/",  // @ modifier
78
+                    $locale, $matches)) {
79 79
 
80
-      if (isset($matches["lang"])) $lang = $matches["lang"];
81
-      if (isset($matches["country"])) $country = $matches["country"];
82
-      if (isset($matches["charset"])) $charset = $matches["charset"];
83
-      if (isset($matches["modifier"])) $modifier = $matches["modifier"];
80
+        if (isset($matches["lang"])) $lang = $matches["lang"];
81
+        if (isset($matches["country"])) $country = $matches["country"];
82
+        if (isset($matches["charset"])) $charset = $matches["charset"];
83
+        if (isset($matches["modifier"])) $modifier = $matches["modifier"];
84 84
 
85
-      if ($modifier) {
85
+        if ($modifier) {
86 86
         if ($country) {
87
-          if ($charset)
87
+            if ($charset)
88 88
             array_push($locale_names, "${lang}_$country.$charset@$modifier");
89
-          array_push($locale_names, "${lang}_$country@$modifier");
89
+            array_push($locale_names, "${lang}_$country@$modifier");
90 90
         } elseif ($charset)
91 91
             array_push($locale_names, "${lang}.$charset@$modifier");
92 92
         array_push($locale_names, "$lang@$modifier");
93
-      }
94
-      if ($country) {
93
+        }
94
+        if ($country) {
95 95
         if ($charset)
96
-          array_push($locale_names, "${lang}_$country.$charset");
96
+            array_push($locale_names, "${lang}_$country.$charset");
97 97
         array_push($locale_names, "${lang}_$country");
98
-      } elseif ($charset)
99
-          array_push($locale_names, "${lang}.$charset");
100
-      array_push($locale_names, $lang);
98
+        } elseif ($charset)
99
+            array_push($locale_names, "${lang}.$charset");
100
+        array_push($locale_names, $lang);
101 101
     }
102 102
 
103 103
     // If the locale name doesn't match POSIX style, just include it as-is.
104 104
     if (!in_array($locale, $locale_names))
105
-      array_push($locale_names, $locale);
106
-  }
107
-  return $locale_names;
105
+        array_push($locale_names, $locale);
106
+    }
107
+    return $locale_names;
108 108
 }
109 109
 
110 110
 /**
@@ -123,16 +123,16 @@  discard block
 block discarded – undo
123 123
         $locale_names = get_list_of_locales($locale);
124 124
         $input = null;
125 125
         foreach ($locale_names as $locale) {
126
-          $full_path = $bound_path . $locale . "/" . $subpath;
127
-          if (file_exists($full_path)) {
126
+            $full_path = $bound_path . $locale . "/" . $subpath;
127
+            if (file_exists($full_path)) {
128 128
             $input = new FileReader($full_path);
129 129
             break;
130
-          }
130
+            }
131 131
         }
132 132
 
133 133
         if (!array_key_exists($domain, $text_domains)) {
134
-          // Initialize an empty domain object.
135
-          $text_domains[$domain] = new domain();
134
+            // Initialize an empty domain object.
135
+            $text_domains[$domain] = new domain();
136 136
         }
137 137
         $text_domains[$domain]->l10n = new MoTranslator\MoTranslator($input);
138 138
     }
@@ -190,9 +190,9 @@  discard block
 block discarded – undo
190 190
  * Returns passed in $locale, or environment variable $LANG if $locale == ''.
191 191
  */
192 192
 function _get_default_locale($locale) {
193
-  if ($locale == '') // emulate variable support
193
+    if ($locale == '') // emulate variable support
194 194
     return getenv('LANG');
195
-  else
195
+    else
196 196
     return $locale;
197 197
 }
198 198
 
@@ -210,20 +210,20 @@  discard block
 block discarded – undo
210 210
             return _setlocale($category, $CURRENTLOCALE);
211 211
     } else {
212 212
         if (function_exists('setlocale')) {
213
-          $ret = setlocale($category, $locale);
214
-          if (($locale == '' and !$ret) or // failed setting it by env
213
+            $ret = setlocale($category, $locale);
214
+            if (($locale == '' and !$ret) or // failed setting it by env
215 215
               ($locale != '' and $ret != $locale)) { // failed setting it
216 216
             // Failed setting it according to environment.
217 217
             $CURRENTLOCALE = _get_default_locale($locale);
218 218
             $EMULATEGETTEXT = 1;
219
-          } else {
219
+            } else {
220 220
             $CURRENTLOCALE = $ret;
221 221
             $EMULATEGETTEXT = 0;
222
-          }
222
+            }
223 223
         } else {
224
-          // No function setlocale(), emulate it all.
225
-          $CURRENTLOCALE = _get_default_locale($locale);
226
-          $EMULATEGETTEXT = 1;
224
+            // No function setlocale(), emulate it all.
225
+            $CURRENTLOCALE = _get_default_locale($locale);
226
+            $EMULATEGETTEXT = 1;
227 227
         }
228 228
         // Allow locale to be changed on the go for one translation domain.
229 229
         global $text_domains, $default_domain;
@@ -241,15 +241,15 @@  discard block
 block discarded – undo
241 241
     global $text_domains;
242 242
     // ensure $path ends with a slash ('/' should work for both, but lets still play nice)
243 243
     if (DIRECTORY_SEPARATOR == '\\') {
244
-      if ($path[strlen($path)-1] != '\\' and $path[strlen($path)-1] != '/')
244
+        if ($path[strlen($path)-1] != '\\' and $path[strlen($path)-1] != '/')
245 245
         $path .= '\\';
246 246
     } else {
247
-      if ($path[strlen($path)-1] != '/')
247
+        if ($path[strlen($path)-1] != '/')
248 248
         $path .= '/';
249 249
     }
250 250
     if (!array_key_exists($domain, $text_domains)) {
251
-      // Initialize an empty domain object.
252
-      $text_domains[$domain] = new domain();
251
+        // Initialize an empty domain object.
252
+        $text_domains[$domain] = new domain();
253 253
     }
254 254
     $text_domains[$domain]->path = $path;
255 255
 }
@@ -317,8 +317,8 @@  discard block
 block discarded – undo
317 317
     return _encode($l10n->translate($msgid));
318 318
 }
319 319
 /**
320
- * Plural version of dcgettext.
321
- */
320
+     * Plural version of dcgettext.
321
+     */
322 322
 function _dcngettext($domain, $singular, $plural, $number, $category) {
323 323
     $l10n = _get_reader($domain, $category);
324 324
     return _encode($l10n->ngettext($singular, $plural, $number));
@@ -426,29 +426,29 @@  discard block
 block discarded – undo
426 426
 }
427 427
 function T_dcngettext($domain, $singular, $plural, $number, $category) {
428 428
     if (_check_locale_and_function())
429
-      return dcngettext($domain, $singular, $plural, $number, $category);
429
+        return dcngettext($domain, $singular, $plural, $number, $category);
430 430
     else return _dcngettext($domain, $singular, $plural, $number, $category);
431 431
 }
432 432
 
433 433
 function T_pgettext($context, $msgid) {
434
-  if (_check_locale_and_function('pgettext'))
435
-      return pgettext($context, $msgid);
436
-  else
437
-      return _pgettext($context, $msgid);
434
+    if (_check_locale_and_function('pgettext'))
435
+        return pgettext($context, $msgid);
436
+    else
437
+        return _pgettext($context, $msgid);
438 438
 }
439 439
 
440 440
 function T_dpgettext($domain, $context, $msgid) {
441
-  if (_check_locale_and_function('dpgettext'))
442
-      return dpgettext($domain, $context, $msgid);
443
-  else
444
-      return _dpgettext($domain, $context, $msgid);
441
+    if (_check_locale_and_function('dpgettext'))
442
+        return dpgettext($domain, $context, $msgid);
443
+    else
444
+        return _dpgettext($domain, $context, $msgid);
445 445
 }
446 446
 
447 447
 function T_dcpgettext($domain, $context, $msgid, $category) {
448
-  if (_check_locale_and_function('dcpgettext'))
449
-      return dcpgettext($domain, $context, $msgid, $category);
450
-  else
451
-      return _dcpgettext($domain, $context, $msgid, $category);
448
+    if (_check_locale_and_function('dcpgettext'))
449
+        return dcpgettext($domain, $context, $msgid, $category);
450
+    else
451
+        return _dcpgettext($domain, $context, $msgid, $category);
452 452
 }
453 453
 
454 454
 function T_npgettext($context, $singular, $plural, $number) {
@@ -459,17 +459,17 @@  discard block
 block discarded – undo
459 459
 }
460 460
 
461 461
 function T_dnpgettext($domain, $context, $singular, $plural, $number) {
462
-  if (_check_locale_and_function('dnpgettext'))
463
-      return dnpgettext($domain, $context, $singular, $plural, $number);
464
-  else
465
-      return _dnpgettext($domain, $context, $singular, $plural, $number);
462
+    if (_check_locale_and_function('dnpgettext'))
463
+        return dnpgettext($domain, $context, $singular, $plural, $number);
464
+    else
465
+        return _dnpgettext($domain, $context, $singular, $plural, $number);
466 466
 }
467 467
 
468 468
 function T_dcnpgettext($domain, $context, $singular, $plural,
469
-                       $number, $category) {
469
+                        $number, $category) {
470 470
     if (_check_locale_and_function('dcnpgettext'))
471 471
         return dcnpgettext($domain, $context, $singular,
472
-                           $plural, $number, $category);
472
+                            $plural, $number, $category);
473 473
     else
474 474
         return _dcnpgettext($domain, $context, $singular,
475 475
                             $plural, $number, $category);
@@ -526,9 +526,9 @@  discard block
 block discarded – undo
526 526
         return _dcpgettext($domain, $context, $msgid, $category);
527 527
     }
528 528
     function dcnpgettext($domain, $context, $singular, $plural,
529
-                         $number, $category) {
530
-      return _dcnpgettext($domain, $context, $singular, $plural,
531
-                          $number, $category);
529
+                            $number, $category) {
530
+        return _dcnpgettext($domain, $context, $singular, $plural,
531
+                            $number, $category);
532 532
     }
533 533
 }
534 534
 
Please login to merge, or discard this patch.