Completed
Push — master ( 7644f9...ee2839 )
by Michal
04:25 queued 01:21
created
src/gettext.inc 3 patches
Indentation   +51 added lines, -51 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
     }
@@ -164,9 +164,9 @@  discard block
 block discarded – undo
164 164
  * Returns passed in $locale, or environment variable $LANG if $locale == ''.
165 165
  */
166 166
 function _get_default_locale($locale) {
167
-  if ($locale == '') // emulate variable support
167
+    if ($locale == '') // emulate variable support
168 168
     return getenv('LANG');
169
-  else
169
+    else
170 170
     return $locale;
171 171
 }
172 172
 
@@ -184,20 +184,20 @@  discard block
 block discarded – undo
184 184
             return _setlocale($category, $CURRENTLOCALE);
185 185
     } else {
186 186
         if (function_exists('setlocale')) {
187
-          $ret = setlocale($category, $locale);
188
-          if (($locale == '' and !$ret) or // failed setting it by env
187
+            $ret = setlocale($category, $locale);
188
+            if (($locale == '' and !$ret) or // failed setting it by env
189 189
               ($locale != '' and $ret != $locale)) { // failed setting it
190 190
             // Failed setting it according to environment.
191 191
             $CURRENTLOCALE = _get_default_locale($locale);
192 192
             $EMULATEGETTEXT = 1;
193
-          } else {
193
+            } else {
194 194
             $CURRENTLOCALE = $ret;
195 195
             $EMULATEGETTEXT = 0;
196
-          }
196
+            }
197 197
         } else {
198
-          // No function setlocale(), emulate it all.
199
-          $CURRENTLOCALE = _get_default_locale($locale);
200
-          $EMULATEGETTEXT = 1;
198
+            // No function setlocale(), emulate it all.
199
+            $CURRENTLOCALE = _get_default_locale($locale);
200
+            $EMULATEGETTEXT = 1;
201 201
         }
202 202
         // Allow locale to be changed on the go for one translation domain.
203 203
         global $text_domains, $default_domain;
@@ -215,15 +215,15 @@  discard block
 block discarded – undo
215 215
     global $text_domains;
216 216
     // ensure $path ends with a slash ('/' should work for both, but lets still play nice)
217 217
     if (DIRECTORY_SEPARATOR == '\\') {
218
-      if ($path[strlen($path)-1] != '\\' and $path[strlen($path)-1] != '/')
218
+        if ($path[strlen($path)-1] != '\\' and $path[strlen($path)-1] != '/')
219 219
         $path .= '\\';
220 220
     } else {
221
-      if ($path[strlen($path)-1] != '/')
221
+        if ($path[strlen($path)-1] != '/')
222 222
         $path .= '/';
223 223
     }
224 224
     if (!array_key_exists($domain, $text_domains)) {
225
-      // Initialize an empty domain object.
226
-      $text_domains[$domain] = new domain();
225
+        // Initialize an empty domain object.
226
+        $text_domains[$domain] = new domain();
227 227
     }
228 228
     $text_domains[$domain]->path = $path;
229 229
 }
@@ -291,8 +291,8 @@  discard block
 block discarded – undo
291 291
     return $l10n->gettext($msgid);
292 292
 }
293 293
 /**
294
- * Plural version of dcgettext.
295
- */
294
+     * Plural version of dcgettext.
295
+     */
296 296
 function _dcngettext($domain, $singular, $plural, $number, $category) {
297 297
     $l10n = _get_reader($domain, $category);
298 298
     return $l10n->ngettext($singular, $plural, $number);
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 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
 
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
     if (preg_match("/^(?P<lang>[a-z]{2,3})"              // language code
75 75
                    ."(?:_(?P<country>[A-Z]{2}))?"           // country code
76 76
                    ."(?:\.(?P<charset>[-A-Za-z0-9_]+))?"    // charset
77
-                   ."(?:@(?P<modifier>[-A-Za-z0-9_]+))?$/",  // @ modifier
77
+                   ."(?:@(?P<modifier>[-A-Za-z0-9_]+))?$/", // @ modifier
78 78
                    $locale, $matches)) {
79 79
 
80 80
       if (isset($matches["lang"])) $lang = $matches["lang"];
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
 /**
111 111
  * Utility function to get a StreamReader for the given text domain.
112 112
  */
113
-function _get_reader($domain=null, $category=5) {
113
+function _get_reader($domain = null, $category = 5) {
114 114
     global $text_domains, $default_domain, $LC_CATEGORIES;
115 115
     if (!isset($domain)) $domain = $default_domain;
116 116
     if (!isset($text_domains[$domain]->l10n)) {
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
         $locale = _setlocale(LC_MESSAGES, 0);
119 119
         $bound_path = isset($text_domains[$domain]->path) ?
120 120
           $text_domains[$domain]->path : './';
121
-        $subpath = $LC_CATEGORIES[$category] ."/$domain.mo";
121
+        $subpath = $LC_CATEGORIES[$category] . "/$domain.mo";
122 122
 
123 123
         $locale_names = get_list_of_locales($locale);
124 124
         $input = null;
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
 /**
151 151
  * Checks if the current locale is supported on this system.
152 152
  */
153
-function _check_locale_and_function($function=false) {
153
+function _check_locale_and_function($function = false) {
154 154
     global $EMULATEGETTEXT;
155 155
     if ($function and !function_exists($function))
156 156
         return false;
@@ -215,10 +215,10 @@  discard block
 block discarded – undo
215 215
     global $text_domains;
216 216
     // ensure $path ends with a slash ('/' should work for both, but lets still play nice)
217 217
     if (DIRECTORY_SEPARATOR == '\\') {
218
-      if ($path[strlen($path)-1] != '\\' and $path[strlen($path)-1] != '/')
218
+      if ($path[strlen($path) - 1] != '\\' and $path[strlen($path) - 1] != '/')
219 219
         $path .= '\\';
220 220
     } else {
221
-      if ($path[strlen($path)-1] != '/')
221
+      if ($path[strlen($path) - 1] != '/')
222 222
         $path .= '/';
223 223
     }
224 224
     if (!array_key_exists($domain, $text_domains)) {
Please login to merge, or discard this patch.
Braces   +50 added lines, -29 removed lines patch added patch discarded remove patch
@@ -77,32 +77,45 @@  discard block
 block discarded – undo
77 77
                    ."(?:@(?P<modifier>[-A-Za-z0-9_]+))?$/",  // @ modifier
78 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"])) {
81
+          $lang = $matches["lang"];
82
+      }
83
+      if (isset($matches["country"])) {
84
+          $country = $matches["country"];
85
+      }
86
+      if (isset($matches["charset"])) {
87
+          $charset = $matches["charset"];
88
+      }
89
+      if (isset($matches["modifier"])) {
90
+          $modifier = $matches["modifier"];
91
+      }
84 92
 
85 93
       if ($modifier) {
86 94
         if ($country) {
87
-          if ($charset)
88
-            array_push($locale_names, "${lang}_$country.$charset@$modifier");
95
+          if ($charset) {
96
+                      array_push($locale_names, "${lang}_$country.$charset@$modifier");
97
+          }
89 98
           array_push($locale_names, "${lang}_$country@$modifier");
90
-        } elseif ($charset)
91
-            array_push($locale_names, "${lang}.$charset@$modifier");
99
+        } elseif ($charset) {
100
+                    array_push($locale_names, "${lang}.$charset@$modifier");
101
+        }
92 102
         array_push($locale_names, "$lang@$modifier");
93 103
       }
94 104
       if ($country) {
95
-        if ($charset)
96
-          array_push($locale_names, "${lang}_$country.$charset");
105
+        if ($charset) {
106
+                  array_push($locale_names, "${lang}_$country.$charset");
107
+        }
97 108
         array_push($locale_names, "${lang}_$country");
98
-      } elseif ($charset)
99
-          array_push($locale_names, "${lang}.$charset");
109
+      } elseif ($charset) {
110
+                array_push($locale_names, "${lang}.$charset");
111
+      }
100 112
       array_push($locale_names, $lang);
101 113
     }
102 114
 
103 115
     // If the locale name doesn't match POSIX style, just include it as-is.
104
-    if (!in_array($locale, $locale_names))
105
-      array_push($locale_names, $locale);
116
+    if (!in_array($locale, $locale_names)) {
117
+          array_push($locale_names, $locale);
118
+    }
106 119
   }
107 120
   return $locale_names;
108 121
 }
@@ -112,7 +125,9 @@  discard block
 block discarded – undo
112 125
  */
113 126
 function _get_reader($domain=null, $category=5) {
114 127
     global $text_domains, $default_domain, $LC_CATEGORIES;
115
-    if (!isset($domain)) $domain = $default_domain;
128
+    if (!isset($domain)) {
129
+        $domain = $default_domain;
130
+    }
116 131
     if (!isset($text_domains[$domain]->l10n)) {
117 132
         // get the current locale
118 133
         $locale = _setlocale(LC_MESSAGES, 0);
@@ -152,8 +167,9 @@  discard block
 block discarded – undo
152 167
  */
153 168
 function _check_locale_and_function($function=false) {
154 169
     global $EMULATEGETTEXT;
155
-    if ($function and !function_exists($function))
156
-        return false;
170
+    if ($function and !function_exists($function)) {
171
+            return false;
172
+    }
157 173
     return !$EMULATEGETTEXT;
158 174
 }
159 175
 
@@ -164,11 +180,13 @@  discard block
 block discarded – undo
164 180
  * Returns passed in $locale, or environment variable $LANG if $locale == ''.
165 181
  */
166 182
 function _get_default_locale($locale) {
167
-  if ($locale == '') // emulate variable support
183
+  if ($locale == '') {
184
+      // emulate variable support
168 185
     return getenv('LANG');
169
-  else
170
-    return $locale;
171
-}
186
+  } else {
187
+      return $locale;
188
+  }
189
+  }
172 190
 
173 191
 /**
174 192
  * Sets a requested locale, if needed emulates it.
@@ -176,12 +194,13 @@  discard block
 block discarded – undo
176 194
 function _setlocale($category, $locale) {
177 195
     global $CURRENTLOCALE, $EMULATEGETTEXT;
178 196
     if ($locale === 0) { // use === to differentiate between string "0"
179
-        if ($CURRENTLOCALE != '')
180
-            return $CURRENTLOCALE;
181
-        else
182
-            // obey LANG variable, maybe extend to support all of LC_* vars
197
+        if ($CURRENTLOCALE != '') {
198
+                    return $CURRENTLOCALE;
199
+        } else {
200
+                    // obey LANG variable, maybe extend to support all of LC_* vars
183 201
             // even if we tried to read locale without setting it first
184 202
             return _setlocale($category, $CURRENTLOCALE);
203
+        }
185 204
     } else {
186 205
         if (function_exists('setlocale')) {
187 206
           $ret = setlocale($category, $locale);
@@ -215,11 +234,13 @@  discard block
 block discarded – undo
215 234
     global $text_domains;
216 235
     // ensure $path ends with a slash ('/' should work for both, but lets still play nice)
217 236
     if (DIRECTORY_SEPARATOR == '\\') {
218
-      if ($path[strlen($path)-1] != '\\' and $path[strlen($path)-1] != '/')
219
-        $path .= '\\';
237
+      if ($path[strlen($path)-1] != '\\' and $path[strlen($path)-1] != '/') {
238
+              $path .= '\\';
239
+      }
220 240
     } else {
221
-      if ($path[strlen($path)-1] != '/')
222
-        $path .= '/';
241
+      if ($path[strlen($path)-1] != '/') {
242
+              $path .= '/';
243
+      }
223 244
     }
224 245
     if (!array_key_exists($domain, $text_domains)) {
225 246
       // Initialize an empty domain object.
Please login to merge, or discard this patch.
src/MoLoader.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
             if (preg_match("/^(?P<lang>[a-z]{2,3})"              // language code
61 61
                 ."(?:_(?P<country>[A-Z]{2}))?"           // country code
62 62
                 ."(?:\.(?P<charset>[-A-Za-z0-9_]+))?"    // charset
63
-                ."(?:@(?P<modifier>[-A-Za-z0-9_]+))?$/",  // @ modifier
63
+                ."(?:@(?P<modifier>[-A-Za-z0-9_]+))?$/", // @ modifier
64 64
                 $locale, $matches)) {
65 65
 
66 66
                 extract($matches);
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
         return $locale_names;
95 95
     }
96 96
 
97
-    public function get_translator($domain='')
97
+    public function get_translator($domain = '')
98 98
     {
99 99
         if (empty($domain)) {
100 100
             $domain = $this->default_domain;
Please login to merge, or discard this patch.
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -71,8 +71,9 @@
 block discarded – undo
71 71
                             array_push($locale_names, "${lang}_$country.$charset@$modifier");
72 72
                         }
73 73
                         array_push($locale_names, "${lang}_$country@$modifier");
74
-                    } elseif ($charset)
75
-                        array_push($locale_names, "${lang}.$charset@$modifier");
74
+                    } elseif ($charset) {
75
+                                            array_push($locale_names, "${lang}.$charset@$modifier");
76
+                    }
76 77
                         array_push($locale_names, "$lang@$modifier");
77 78
                     }
78 79
                 if ($country) {
Please login to merge, or discard this patch.