@@ -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 | } |
@@ -16,21 +16,19 @@ |
||
16 | 16 | * @param \Closure $next |
17 | 17 | * @return mixed |
18 | 18 | */ |
19 | - public function handle($request, Closure $next) |
|
20 | - { |
|
19 | + public function handle($request, Closure $next) { |
|
21 | 20 | if (Session::has('locale') || auth()->check()) { |
22 | 21 | $locale = Session::has('locale') ? session()->get('locale') : auth()->user()->language; |
23 | 22 | |
24 | 23 | $locale = TranslatorFacade::validateLocale($locale); |
25 | 24 | |
26 | - if(Session::has('locale') == false){ |
|
25 | + if(Session::has('locale') == false) { |
|
27 | 26 | Session::put('locale', $locale); |
28 | 27 | Session::save(); |
29 | 28 | } |
30 | 29 | |
31 | 30 | app()->setLocale($locale); |
32 | - } |
|
33 | - else { |
|
31 | + } else { |
|
34 | 32 | // TODO: Validate Browser locale string (https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.4) |
35 | 33 | |
36 | 34 | Session::put('locale', TranslatorFacade::getConfigValue('default_locale')); |
@@ -47,8 +47,7 @@ discard block |
||
47 | 47 | throw new TranslationNotFoundException("The translation for identifier '".$identifier."' and locale '".$this->locale."' could not be found"); |
48 | 48 | } |
49 | 49 | return $this->translations[$identifier]->translation; |
50 | - } |
|
51 | - else { |
|
50 | + } else { |
|
52 | 51 | throw new NotFoundResourceException("The translation identifier '".$identifier."' could not be found"); |
53 | 52 | } |
54 | 53 | } |
@@ -74,8 +73,7 @@ discard block |
||
74 | 73 | * @param $group |
75 | 74 | * @return mixed |
76 | 75 | */ |
77 | - public function getAllTranslations($group = 'default') |
|
78 | - { |
|
76 | + public function getAllTranslations($group = 'default') { |
|
79 | 77 | $return = []; |
80 | 78 | foreach (collect($this->translations)->where('group', $group) as $key => $translation) { |
81 | 79 | if ($translation->translation == null) { |
@@ -8,7 +8,8 @@ discard block |
||
8 | 8 | * Class LocaleHandler |
9 | 9 | * @package Hokan22\LaravelTranslator\ |
10 | 10 | */ |
11 | -class CacheJSONHandler implements HandlerInterface { |
|
11 | +class CacheJSONHandler implements HandlerInterface |
|
12 | +{ |
|
12 | 13 | /** @var string The locale to translate to */ |
13 | 14 | private $locale; |
14 | 15 | /** @var array|array[] Array with the identifiers as keys and the Texts object as value */ |
@@ -46,8 +47,7 @@ discard block |
||
46 | 47 | // So not finding the same identifier twice in the cache, will result in an error. |
47 | 48 | if(isset($this->translations[$group][$identifier])) { |
48 | 49 | return $this->translations[$group][$identifier]; |
49 | - } |
|
50 | - else { |
|
50 | + } else { |
|
51 | 51 | throw new TranslationNotInCacheException("The translation identifier '".$identifier."' could not be found in Cache"); |
52 | 52 | } |
53 | 53 | } |
@@ -64,8 +64,7 @@ discard block |
||
64 | 64 | // If a Group is defined just get the translations from that group |
65 | 65 | try { |
66 | 66 | $trans_identifier = json_decode(file_get_contents($locale_dir.'/'.$group.'.json'), true); |
67 | - } |
|
68 | - catch (\ErrorException $e) { |
|
67 | + } catch (\ErrorException $e) { |
|
69 | 68 | throw new TranslationCacheNotFound("The Translation cache file '".$locale_dir.'/'.$group.'.json'."' could not be found!"); |
70 | 69 | } |
71 | 70 | |
@@ -78,8 +77,7 @@ discard block |
||
78 | 77 | * @return array|mixed |
79 | 78 | * @throws TranslationCacheNotFound |
80 | 79 | */ |
81 | - public function getAllTranslations($group) |
|
82 | - { |
|
80 | + public function getAllTranslations($group) { |
|
83 | 81 | if(!isset($this->translations[$group])) { |
84 | 82 | $this->refreshCache($group); |
85 | 83 | } |
@@ -11,7 +11,9 @@ discard block |
||
11 | 11 | * Class TranslationNotFoundException |
12 | 12 | * @package Hokan22\LaravelTranslator\Handler |
13 | 13 | */ |
14 | -class TranslationNotFoundException extends \Exception {} |
|
14 | +class TranslationNotFoundException extends \Exception |
|
15 | +{ |
|
16 | +} |
|
15 | 17 | |
16 | 18 | /** |
17 | 19 | * Custom Exception to distinguish if the Translation Identifier was not found in Cache but could be in DB |
@@ -19,7 +21,9 @@ discard block |
||
19 | 21 | * Class TranslationNotInCacheException |
20 | 22 | * @package Hokan22\LaravelTranslator\Handler |
21 | 23 | */ |
22 | -class TranslationNotInCacheException extends TranslationNotFoundException {} |
|
24 | +class TranslationNotInCacheException extends TranslationNotFoundException |
|
25 | +{ |
|
26 | +} |
|
23 | 27 | |
24 | 28 | /** |
25 | 29 | * Custom Exception thrown when a cache file could not be found |
@@ -27,7 +31,9 @@ discard block |
||
27 | 31 | * Class TranslationCacheNotFound |
28 | 32 | * @package Hokan22\LaravelTranslator\Handler |
29 | 33 | */ |
30 | -class TranslationCacheNotFound extends \Exception {} |
|
34 | +class TranslationCacheNotFound extends \Exception |
|
35 | +{ |
|
36 | +} |
|
31 | 37 | |
32 | 38 | /** |
33 | 39 | * Interface HandlerInterface |
@@ -14,8 +14,7 @@ discard block |
||
14 | 14 | * |
15 | 15 | * @return void |
16 | 16 | */ |
17 | - public function boot() |
|
18 | - { |
|
17 | + public function boot() { |
|
19 | 18 | Blade::directive('translate', function ($expression) { |
20 | 19 | |
21 | 20 | $expression = $this->stripParentheses($expression); |
@@ -39,8 +38,7 @@ discard block |
||
39 | 38 | * @param string $expression |
40 | 39 | * @return string |
41 | 40 | */ |
42 | - public function stripParentheses($expression) |
|
43 | - { |
|
41 | + public function stripParentheses($expression) { |
|
44 | 42 | if (Str::startsWith($expression, '(')) { |
45 | 43 | $expression = substr($expression, 1, -1); |
46 | 44 | } |
@@ -53,7 +51,6 @@ discard block |
||
53 | 51 | * |
54 | 52 | * @return void |
55 | 53 | */ |
56 | - public function register() |
|
57 | - { |
|
54 | + public function register() { |
|
58 | 55 | } |
59 | 56 | } |
@@ -13,8 +13,7 @@ |
||
13 | 13 | * |
14 | 14 | * @return void |
15 | 15 | */ |
16 | - public function register() |
|
17 | - { |
|
16 | + public function register() { |
|
18 | 17 | $this->mergeConfigFrom(__DIR__.'/../config/translator.php', 'translator'); |
19 | 18 | |
20 | 19 | $this->app->singleton('Translator', function () { |
@@ -34,8 +34,7 @@ |
||
34 | 34 | * |
35 | 35 | * @return string |
36 | 36 | */ |
37 | - protected static function getFacadeAccessor() |
|
38 | - { |
|
37 | + protected static function getFacadeAccessor() { |
|
39 | 38 | return 'Translator'; |
40 | 39 | } |
41 | 40 | } |
@@ -21,7 +21,8 @@ discard block |
||
21 | 21 | * Class SearchTranslationsCommand |
22 | 22 | * @package App\Console\Commands |
23 | 23 | */ |
24 | -class SearchTranslationsCommand extends Command{ |
|
24 | +class SearchTranslationsCommand extends Command |
|
25 | +{ |
|
25 | 26 | /** |
26 | 27 | * The name and signature of the console command. |
27 | 28 | * |
@@ -47,7 +48,7 @@ discard block |
||
47 | 48 | /** |
48 | 49 | * Create a new command instance. |
49 | 50 | */ |
50 | - public function __construct(){ |
|
51 | + public function __construct() { |
|
51 | 52 | parent::__construct(); |
52 | 53 | } |
53 | 54 | |
@@ -57,7 +58,7 @@ discard block |
||
57 | 58 | * @return mixed |
58 | 59 | * @throws \Exception |
59 | 60 | */ |
60 | - public function handle(){ |
|
61 | + public function handle() { |
|
61 | 62 | |
62 | 63 | // Get start time |
63 | 64 | $start = microtime(true); |
@@ -79,7 +80,7 @@ discard block |
||
79 | 80 | 'js' => '/\$filter\(\'translate\'\)\(\'(?\'identifier\'.*?)\'\)/' |
80 | 81 | ]; |
81 | 82 | |
82 | - foreach($folders as $folder){ |
|
83 | + foreach($folders as $folder) { |
|
83 | 84 | $aFiles = array_merge($aFiles, File::allFiles(base_path().'/'.$folder)); |
84 | 85 | } |
85 | 86 | |
@@ -95,13 +96,13 @@ discard block |
||
95 | 96 | |
96 | 97 | $extension = $file->getExtension(); |
97 | 98 | |
98 | - if(in_array($extension, $valid_extensions)){ |
|
99 | + if(in_array($extension, $valid_extensions)) { |
|
99 | 100 | $content = file_get_contents($file); |
100 | 101 | |
101 | 102 | foreach ($regexes as $key => $regex) { |
102 | 103 | preg_match_all($regex, $content, $result, PREG_SET_ORDER); |
103 | 104 | |
104 | - if(!empty($result[0])){ |
|
105 | + if(!empty($result[0])) { |
|
105 | 106 | $this->addMissing($result, $key); |
106 | 107 | } |
107 | 108 | } |
@@ -129,7 +130,7 @@ discard block |
||
129 | 130 | private function addMissing($result, $group) { |
130 | 131 | |
131 | 132 | foreach ($result as $item) { |
132 | - try{ |
|
133 | + try { |
|
133 | 134 | |
134 | 135 | $identifier = trim($item['identifier']); |
135 | 136 | $this->found_identifier++; |
@@ -147,8 +148,7 @@ discard block |
||
147 | 148 | $parameter_array = explode(",",$parameter_string); |
148 | 149 | |
149 | 150 | $parameters = array(); |
150 | - foreach($parameter_array as $parameter ) |
|
151 | - { |
|
151 | + foreach($parameter_array as $parameter ) { |
|
152 | 152 | $parameter = explode("=>",$parameter); |
153 | 153 | |
154 | 154 | $key = str_replace([" ", "'"],"", $parameter[0]); |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | $this->found_parameters++; |
161 | 161 | } |
162 | 162 | |
163 | - if(!isset($aTranslations[$identifier])){ |
|
163 | + if(!isset($aTranslations[$identifier])) { |
|
164 | 164 | $aTranslations[$identifier] = TranslatorFacade::hasIdentifier($identifier); |
165 | 165 | |
166 | 166 | if (! $aTranslations[$identifier]) { |
@@ -170,12 +170,11 @@ discard block |
||
170 | 170 | $this->bar->display(); |
171 | 171 | $this->new_identifier++; |
172 | 172 | } |
173 | - } |
|
174 | - else { |
|
173 | + } else { |
|
175 | 174 | $this->dupl_identifier++; |
176 | 175 | } |
177 | 176 | |
178 | - }catch(\Exception $e){ |
|
177 | + } catch(\Exception $e) { |
|
179 | 178 | $this->bar->clear(); |
180 | 179 | $this->info($identifier.' '.strlen($identifier)); |
181 | 180 | $this->info($e->getMessage()); |