@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | // TODO: Cleanup (avoid repetition) |
147 | 147 | // Try to create new Instance of Handler and return it |
148 | 148 | try { |
149 | - $oHandler = new $oHandler($locale); |
|
149 | + $oHandler = new $oHandler($locale); |
|
150 | 150 | } |
151 | 151 | catch (TranslationCacheNotFound $exception) { |
152 | 152 | // Log error and fallback procedure |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | private function replaceParameter ($translation, $parameters) { |
232 | 232 | |
233 | 233 | // Go through each specified Parameter and replace its placeholder "{$key}" |
234 | - foreach ($parameters as $key => $parameter) { |
|
234 | + foreach ($parameters as $key => $parameter) { |
|
235 | 235 | // TODO: Make Prefix and Suffix configurable |
236 | 236 | // If the string (e.g "{name}") is not specified within the "parameters" array it won't be replaced! |
237 | 237 | $translation = str_replace("{".$key."}", $parameter, $translation); |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | * @throws \Exception |
60 | 60 | * TODO: Make function Parameters interchangeable |
61 | 61 | */ |
62 | - public function translate($identifier , $parameters = null, $locale = '') { |
|
62 | + public function translate($identifier, $parameters = null, $locale = '') { |
|
63 | 63 | |
64 | 64 | // Validate the locale given as parameter or take the saved locale |
65 | 65 | if ($locale !== '' || $this->locale === '') { |
@@ -181,12 +181,12 @@ discard block |
||
181 | 181 | */ |
182 | 182 | public function addMissingIdentifier($identifier, $parameters, $group) { |
183 | 183 | |
184 | - if(! $this->hasIdentifier($identifier)) { |
|
184 | + if (!$this->hasIdentifier($identifier)) { |
|
185 | 185 | |
186 | 186 | // Save only the keys from the parameter array |
187 | 187 | $keys = []; |
188 | 188 | if (is_array($parameters)) { |
189 | - foreach($parameters as $key => $value) { |
|
189 | + foreach ($parameters as $key => $value) { |
|
190 | 190 | $keys[] = $key; |
191 | 191 | } |
192 | 192 | } |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | * @param $parameters |
229 | 229 | * @return string |
230 | 230 | */ |
231 | - private function replaceParameter ($translation, $parameters) { |
|
231 | + private function replaceParameter($translation, $parameters) { |
|
232 | 232 | |
233 | 233 | // Go through each specified Parameter and replace its placeholder "{$key}" |
234 | 234 | foreach ($parameters as $key => $parameter) { |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | * @return string |
250 | 250 | * @throws \Exception |
251 | 251 | */ |
252 | - private function returnMissingTranslation ($identifier, $locale) { |
|
252 | + private function returnMissingTranslation($identifier, $locale) { |
|
253 | 253 | |
254 | 254 | // Return identifier and locale for easier debug |
255 | 255 | if (config('app.env') !== 'production') { |
@@ -279,7 +279,7 @@ discard block |
||
279 | 279 | } |
280 | 280 | |
281 | 281 | // Fallback if empty locale was given (should be handled in middleware) |
282 | - if ($locale == ''){ |
|
282 | + if ($locale == '') { |
|
283 | 283 | if (session()->get('locale') != '') { |
284 | 284 | $locale = session()->get('locale'); |
285 | 285 | } |
@@ -289,19 +289,19 @@ discard block |
||
289 | 289 | } |
290 | 290 | |
291 | 291 | // If the given locale is not defined as valid, try to get a fallback locale |
292 | - if (!in_array($locale, $avail_locales)){ |
|
292 | + if (!in_array($locale, $avail_locales)) { |
|
293 | 293 | |
294 | 294 | $found_locales = []; |
295 | 295 | |
296 | 296 | // Find any available locale which contains the locale as substring |
297 | 297 | foreach ($avail_locales as $avail_locale) { |
298 | - if (strpos($avail_locale, $locale) !== false){ |
|
298 | + if (strpos($avail_locale, $locale) !== false) { |
|
299 | 299 | $found_locales[] = $avail_locale; |
300 | 300 | } |
301 | 301 | } |
302 | 302 | |
303 | 303 | // Check if default locale is inside the found locales. If it was, use it! |
304 | - if (in_array($default_locale, $found_locales)){ |
|
304 | + if (in_array($default_locale, $found_locales)) { |
|
305 | 305 | Log::warning('Locale "'.$locale.'" was not found! Falling back to default locale "'.$default_locale.'"'); |
306 | 306 | $locale = $default_locale; |
307 | 307 | } |
@@ -324,7 +324,7 @@ discard block |
||
324 | 324 | * @return array|mixed |
325 | 325 | */ |
326 | 326 | public function getAllTranslations($locale, $group) { |
327 | - if(!isset($this->aHandler[$locale])) { |
|
327 | + if (!isset($this->aHandler[$locale])) { |
|
328 | 328 | $this->aHandler[$locale] = $this->createHandler($locale); |
329 | 329 | } |
330 | 330 |
@@ -124,14 +124,12 @@ discard block |
||
124 | 124 | // Check if the class from the config exists and implements HandlerInterface |
125 | 125 | if (class_exists($handler_class) && is_a($handler_class, 'Hokan22\LaravelTranslator\Handler\HandlerInterface', TRUE)) { |
126 | 126 | $oHandler = $handler_class; |
127 | - } |
|
128 | - elseif (!class_exists($handler_class)) { |
|
127 | + } elseif (!class_exists($handler_class)) { |
|
129 | 128 | // If one of the previous check fails check if the class does not exists and set message accordingly |
130 | 129 | // As it could either be the class does not exist or does not implement HandlerInterface |
131 | 130 | // check only the shorter statement to improve readability |
132 | 131 | $message = "Handler '".$handler_class."' not found."; |
133 | - } |
|
134 | - else { |
|
132 | + } else { |
|
135 | 133 | // If the class exists but the class does not implement HandlerInterface set the message accordingly |
136 | 134 | $message = "Handler '".$handler_class."' does not implement HandlerInterface."; |
137 | 135 | } |
@@ -147,8 +145,7 @@ discard block |
||
147 | 145 | // Try to create new Instance of Handler and return it |
148 | 146 | try { |
149 | 147 | $oHandler = new $oHandler($locale); |
150 | - } |
|
151 | - catch (TranslationCacheNotFound $exception) { |
|
148 | + } catch (TranslationCacheNotFound $exception) { |
|
152 | 149 | // Log error and fallback procedure |
153 | 150 | Log::error($exception); |
154 | 151 | Log::warning('Falling back to DatabaseHandler'); |
@@ -207,8 +204,7 @@ discard block |
||
207 | 204 | |
208 | 205 | // Print notice about creation to laravel log |
209 | 206 | Log::notice('The translation string "'.$identifier.'" will be written to the Database'); |
210 | - } |
|
211 | - else { |
|
207 | + } else { |
|
212 | 208 | Log::warning('The translation string "'.$identifier.'" is already in the Database!'); |
213 | 209 | } |
214 | 210 | } |
@@ -279,29 +275,28 @@ discard block |
||
279 | 275 | } |
280 | 276 | |
281 | 277 | // Fallback if empty locale was given (should be handled in middleware) |
282 | - if ($locale == ''){ |
|
278 | + if ($locale == '') { |
|
283 | 279 | if (session()->get('locale') != '') { |
284 | 280 | $locale = session()->get('locale'); |
285 | - } |
|
286 | - else { |
|
281 | + } else { |
|
287 | 282 | return $default_locale; |
288 | 283 | } |
289 | 284 | } |
290 | 285 | |
291 | 286 | // If the given locale is not defined as valid, try to get a fallback locale |
292 | - if (!in_array($locale, $avail_locales)){ |
|
287 | + if (!in_array($locale, $avail_locales)) { |
|
293 | 288 | |
294 | 289 | $found_locales = []; |
295 | 290 | |
296 | 291 | // Find any available locale which contains the locale as substring |
297 | 292 | foreach ($avail_locales as $avail_locale) { |
298 | - if (strpos($avail_locale, $locale) !== false){ |
|
293 | + if (strpos($avail_locale, $locale) !== false) { |
|
299 | 294 | $found_locales[] = $avail_locale; |
300 | 295 | } |
301 | 296 | } |
302 | 297 | |
303 | 298 | // Check if default locale is inside the found locales. If it was, use it! |
304 | - if (in_array($default_locale, $found_locales)){ |
|
299 | + if (in_array($default_locale, $found_locales)) { |
|
305 | 300 | Log::warning('Locale "'.$locale.'" was not found! Falling back to default locale "'.$default_locale.'"'); |
306 | 301 | $locale = $default_locale; |
307 | 302 | } |
@@ -309,8 +304,7 @@ discard block |
||
309 | 304 | elseif (count($found_locales, 0) >= 1) { |
310 | 305 | Log::warning('Locale "'.$locale.'" was not found! Falling back to similar locale "'.$found_locales[0].'"'); |
311 | 306 | $locale = $found_locales[0]; |
312 | - } |
|
313 | - else { |
|
307 | + } else { |
|
314 | 308 | throw new NotFoundResourceException("Locale '".$locale."' was not found in available locales"); |
315 | 309 | } |
316 | 310 | } |