@@ -144,12 +144,12 @@ |
||
| 144 | 144 | return $translation; |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | - /** |
|
| 148 | - * Sets the Handler |
|
| 149 | - * |
|
| 150 | - * @param $locale |
|
| 151 | - * @return HandlerInterface |
|
| 152 | - */ |
|
| 147 | + /** |
|
| 148 | + * Sets the Handler |
|
| 149 | + * |
|
| 150 | + * @param $locale |
|
| 151 | + * @return HandlerInterface |
|
| 152 | + */ |
|
| 153 | 153 | protected function createHandler($locale) |
| 154 | 154 | { |
| 155 | 155 | // Get the Handler class from config file |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | try { |
| 168 | 168 | $oHandler = new $handler_class($locale); |
| 169 | 169 | if (!is_a($handler_class, 'Hokan22\LaravelTranslator\Handler\HandlerInterface', true)) { |
| 170 | - throw new \Exception($handler_class . ' does not implement HandlerInterface!'); |
|
| 170 | + throw new \Exception($handler_class.' does not implement HandlerInterface!'); |
|
| 171 | 171 | } |
| 172 | 172 | } catch (\Exception $exception) { |
| 173 | 173 | // Log error and fallback procedure |
@@ -210,7 +210,7 @@ discard block |
||
| 210 | 210 | // Save only the keys from the parameter array |
| 211 | 211 | $keys = []; |
| 212 | 212 | if (is_array($parameters)) { |
| 213 | - foreach($parameters as $key => $value) { |
|
| 213 | + foreach ($parameters as $key => $value) { |
|
| 214 | 214 | $keys[] = $key; |
| 215 | 215 | } |
| 216 | 216 | } |
@@ -308,7 +308,7 @@ discard block |
||
| 308 | 308 | } |
| 309 | 309 | |
| 310 | 310 | // Fallback if empty locale was given (should be handled in middleware) |
| 311 | - if ($locale == null){ |
|
| 311 | + if ($locale == null) { |
|
| 312 | 312 | if (session()->get('locale') != '') { |
| 313 | 313 | $locale = session()->get('locale'); |
| 314 | 314 | } |
@@ -318,19 +318,19 @@ discard block |
||
| 318 | 318 | } |
| 319 | 319 | |
| 320 | 320 | // If the given locale is not defined as valid, try to get a fallback locale |
| 321 | - if (!in_array($locale, $avail_locales)){ |
|
| 321 | + if (!in_array($locale, $avail_locales)) { |
|
| 322 | 322 | |
| 323 | 323 | $found_locales = []; |
| 324 | 324 | |
| 325 | 325 | // Find any available locale which contains the locale as substring |
| 326 | 326 | foreach ($avail_locales as $avail_locale) { |
| 327 | - if (strpos($avail_locale, $locale) !== false){ |
|
| 327 | + if (strpos($avail_locale, $locale) !== false) { |
|
| 328 | 328 | $found_locales[] = $avail_locale; |
| 329 | 329 | } |
| 330 | 330 | } |
| 331 | 331 | |
| 332 | 332 | // Check if default locale is inside the found locales. If it was, use it! |
| 333 | - if (in_array($default_locale, $found_locales)){ |
|
| 333 | + if (in_array($default_locale, $found_locales)) { |
|
| 334 | 334 | $message = 'Locale "'.$locale.'" was not found! Falling back to default locale "'.$default_locale.'"'; |
| 335 | 335 | $locale = $default_locale; |
| 336 | 336 | |
@@ -311,8 +311,7 @@ discard block |
||
| 311 | 311 | if ($locale == null){ |
| 312 | 312 | if (session()->get('locale') != '') { |
| 313 | 313 | $locale = session()->get('locale'); |
| 314 | - } |
|
| 315 | - else { |
|
| 314 | + } else { |
|
| 316 | 315 | return $default_locale; |
| 317 | 316 | } |
| 318 | 317 | } |
@@ -343,7 +342,9 @@ discard block |
||
| 343 | 342 | } |
| 344 | 343 | } |
| 345 | 344 | |
| 346 | - if ($message !== '') $this->log($message, 'warning'); |
|
| 345 | + if ($message !== '') { |
|
| 346 | + $this->log($message, 'warning'); |
|
| 347 | + } |
|
| 347 | 348 | |
| 348 | 349 | return $locale; |
| 349 | 350 | } |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | { |
| 29 | 29 | $this->mergeConfigFrom(__DIR__.'/../config/translator.php', 'translator'); |
| 30 | 30 | |
| 31 | - $this->app->singleton('Translator', function () |
|
| 31 | + $this->app->singleton('Translator', function() |
|
| 32 | 32 | { |
| 33 | 33 | return new Translator(); |
| 34 | 34 | } |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | { |
| 43 | 43 | $this->publishes( |
| 44 | 44 | [ |
| 45 | - __DIR__ . '/../config/translator.php' => config_path('translator.php'), |
|
| 45 | + __DIR__.'/../config/translator.php' => config_path('translator.php'), |
|
| 46 | 46 | ], |
| 47 | 47 | 'config' |
| 48 | 48 | ); |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | */ |
| 27 | 27 | public function boot() |
| 28 | 28 | { |
| 29 | - Blade::directive('translate', function ($expression) { |
|
| 29 | + Blade::directive('translate', function($expression) { |
|
| 30 | 30 | |
| 31 | 31 | $expression = $this->stripParentheses($expression); |
| 32 | 32 | |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | } |
| 36 | 36 | ); |
| 37 | 37 | |
| 38 | - Blade::directive('t', function ($expression) { |
|
| 38 | + Blade::directive('t', function($expression) { |
|
| 39 | 39 | |
| 40 | 40 | $expression = $this->stripParentheses($expression); |
| 41 | 41 | |
@@ -122,9 +122,9 @@ |
||
| 122 | 122 | protected function loadFromDB($locale) |
| 123 | 123 | { |
| 124 | 124 | // Get all Texts with translations for the given locale |
| 125 | - $trans_identifier = new TranslationIdentifier(); |
|
| 125 | + $trans_identifier = new TranslationIdentifier(); |
|
| 126 | 126 | |
| 127 | - $trans_identifier = $trans_identifier->with('translations')->whereHas('translations', function ($item) use ($locale) |
|
| 127 | + $trans_identifier = $trans_identifier->with('translations')->whereHas('translations', function($item) use ($locale) |
|
| 128 | 128 | { |
| 129 | 129 | return $item->where('locale', $locale); |
| 130 | 130 | } |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | 'js' => '/\$filter\(\'translate\'\)\(\'(?\'identifier\'.*?)\'\)/' |
| 80 | 80 | ]; |
| 81 | 81 | |
| 82 | - foreach($folders as $folder) { |
|
| 82 | + foreach ($folders as $folder) { |
|
| 83 | 83 | $aFiles = array_merge($aFiles, File::allFiles(base_path().'/'.$folder)); |
| 84 | 84 | } |
| 85 | 85 | |
@@ -95,13 +95,13 @@ discard block |
||
| 95 | 95 | |
| 96 | 96 | $extension = $file->getExtension(); |
| 97 | 97 | |
| 98 | - if(in_array($extension, $valid_extensions)) { |
|
| 98 | + if (in_array($extension, $valid_extensions)) { |
|
| 99 | 99 | $content = file_get_contents($file); |
| 100 | 100 | |
| 101 | 101 | foreach ($regexes as $key => $regex) { |
| 102 | 102 | preg_match_all($regex, $content, $result, PREG_SET_ORDER); |
| 103 | 103 | |
| 104 | - if(!empty($result[0])) { |
|
| 104 | + if (!empty($result[0])) { |
|
| 105 | 105 | $this->addMissing($result, $key); |
| 106 | 106 | } |
| 107 | 107 | } |
@@ -117,16 +117,16 @@ discard block |
||
| 117 | 117 | ['Num', 'Translations...'], |
| 118 | 118 | [ |
| 119 | 119 | [$this->found_identifier, "Found"], |
| 120 | - [$this->new_identifier, "New"], |
|
| 121 | - [$this->dupl_identifier, "Duplicates"], |
|
| 120 | + [$this->new_identifier, "New"], |
|
| 121 | + [$this->dupl_identifier, "Duplicates"], |
|
| 122 | 122 | [$this->found_parameters, "With Parameters"], |
| 123 | - [$this->found_invalid, "Invalid"], |
|
| 123 | + [$this->found_invalid, "Invalid"], |
|
| 124 | 124 | ] |
| 125 | 125 | ); |
| 126 | 126 | |
| 127 | 127 | $this->line(''); |
| 128 | 128 | |
| 129 | - $this->info('Finished in: ' . number_format(microtime(true) - $start, 2) . 'sec'); |
|
| 129 | + $this->info('Finished in: '.number_format(microtime(true) - $start, 2).'sec'); |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | /** |
@@ -151,14 +151,14 @@ discard block |
||
| 151 | 151 | $parameter_string = substr($parameter_string, 1, -1); |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | - $parameter_array = explode(",",$parameter_string); |
|
| 154 | + $parameter_array = explode(",", $parameter_string); |
|
| 155 | 155 | $parameters = array(); |
| 156 | 156 | |
| 157 | - foreach($parameter_array as $parameter) { |
|
| 158 | - $parameter = explode("=>",$parameter); |
|
| 157 | + foreach ($parameter_array as $parameter) { |
|
| 158 | + $parameter = explode("=>", $parameter); |
|
| 159 | 159 | |
| 160 | - $key = str_replace([" ", "'"],"", $parameter[0]); |
|
| 161 | - $value = str_replace([" ", "'"],"", $parameter[1]); |
|
| 160 | + $key = str_replace([" ", "'"], "", $parameter[0]); |
|
| 161 | + $value = str_replace([" ", "'"], "", $parameter[1]); |
|
| 162 | 162 | |
| 163 | 163 | $parameters[$key] = $value; |
| 164 | 164 | } |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | $this->found_parameters++; |
| 167 | 167 | } |
| 168 | 168 | |
| 169 | - if(!isset($aTranslations[$identifier])) { |
|
| 169 | + if (!isset($aTranslations[$identifier])) { |
|
| 170 | 170 | $aTranslations[$identifier] = TranslatorFacade::hasIdentifier($identifier); |
| 171 | 171 | |
| 172 | 172 | if (!$aTranslations[$identifier]) { |
@@ -180,7 +180,7 @@ discard block |
||
| 180 | 180 | $this->dupl_identifier++; |
| 181 | 181 | } |
| 182 | 182 | |
| 183 | - } catch(\Exception $e){ |
|
| 183 | + } catch (\Exception $e) { |
|
| 184 | 184 | $this->bar->clear(); |
| 185 | 185 | $this->info($identifier.' '.strlen($identifier)); |
| 186 | 186 | $this->info($e->getMessage()); |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | $query = TranslationIdentifier::with('translations'); |
| 38 | 38 | |
| 39 | 39 | if ($locale != '') { |
| 40 | - $query = $query->whereDoesntHave('translations', function ($query) use ($locale) |
|
| 40 | + $query = $query->whereDoesntHave('translations', function($query) use ($locale) |
|
| 41 | 41 | { |
| 42 | 42 | $query->where('translations.locale', 'like', $locale); |
| 43 | 43 | } |
@@ -45,12 +45,12 @@ discard block |
||
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | if ($search != '') { |
| 48 | - $query = $query->where(function ($query) use ($search) { |
|
| 49 | - $query ->where('identifier', 'LIKE', '%'.$search.'%') |
|
| 48 | + $query = $query->where(function($query) use ($search) { |
|
| 49 | + $query ->where('identifier', 'LIKE', '%'.$search.'%') |
|
| 50 | 50 | ->orWhere('parameters', 'LIKE', '%'.$search.'%') |
| 51 | - ->orWhere('group', 'LIKE', '%'.$search.'%') |
|
| 52 | - ->orWhere('page_name', 'LIKE', '%'.$search.'%') |
|
| 53 | - ->orWhere('description','LIKE', '%'.$search.'%'); |
|
| 51 | + ->orWhere('group', 'LIKE', '%'.$search.'%') |
|
| 52 | + ->orWhere('page_name', 'LIKE', '%'.$search.'%') |
|
| 53 | + ->orWhere('description', 'LIKE', '%'.$search.'%'); |
|
| 54 | 54 | }); |
| 55 | 55 | } |
| 56 | 56 | |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | * @param $state string 'enabled|disabled' |
| 172 | 172 | * @return \Illuminate\Http\RedirectResponse |
| 173 | 173 | */ |
| 174 | - public function changeLiveMode ($state) { |
|
| 174 | + public function changeLiveMode($state) { |
|
| 175 | 175 | |
| 176 | 176 | if ($state == 'enable') { |
| 177 | 177 | session(['translation_live_mode' => true]); |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | DB::beginTransaction(); |
| 29 | 29 | |
| 30 | 30 | // Create table for storing roles |
| 31 | - Schema::create('translation_identifiers', function (Blueprint $table) |
|
| 31 | + Schema::create('translation_identifiers', function(Blueprint $table) |
|
| 32 | 32 | { |
| 33 | 33 | $table->increments('id')->unique(); |
| 34 | 34 | $table->text('identifier'); |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | }); |
| 44 | 44 | |
| 45 | 45 | // Create table for storing roles |
| 46 | - Schema::create('translations', function (Blueprint $table) |
|
| 46 | + Schema::create('translations', function(Blueprint $table) |
|
| 47 | 47 | { |
| 48 | 48 | $table->integer('translation_identifier_id')->unsigned(); |
| 49 | 49 | $table->foreign('translation_identifier_id')->references('id')->on('translation_identifiers')->onDelete('no action')->onUpdate('no action'); |
@@ -81,7 +81,7 @@ |
||
| 81 | 81 | $translations = $translations->leftJoin('translations', function ($join) |
| 82 | 82 | { |
| 83 | 83 | $join->on( 'translation_identifiers.id', '=', 'translations.translation_identifier_id') |
| 84 | - ->where('locale', $this->locale); |
|
| 84 | + ->where('locale', $this->locale); |
|
| 85 | 85 | } |
| 86 | 86 | )->get(); |
| 87 | 87 | |
@@ -78,9 +78,9 @@ discard block |
||
| 78 | 78 | { |
| 79 | 79 | // Get all Texts with translations for the given locale |
| 80 | 80 | $translations = new TranslationIdentifier(); |
| 81 | - $translations = $translations->leftJoin('translations', function ($join) |
|
| 81 | + $translations = $translations->leftJoin('translations', function($join) |
|
| 82 | 82 | { |
| 83 | - $join->on( 'translation_identifiers.id', '=', 'translations.translation_identifier_id') |
|
| 83 | + $join->on('translation_identifiers.id', '=', 'translations.translation_identifier_id') |
|
| 84 | 84 | ->where('locale', $this->locale); |
| 85 | 85 | } |
| 86 | 86 | )->get(); |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | */ |
| 119 | 119 | function getDatabaseID($identifier) |
| 120 | 120 | { |
| 121 | - if(isset($this->translations[$identifier])) { |
|
| 121 | + if (isset($this->translations[$identifier])) { |
|
| 122 | 122 | return $this->translations[$identifier]->id; |
| 123 | 123 | } else { |
| 124 | 124 | throw new NotFoundResourceException("The translation identifier '".$identifier."' could not be found"); |
@@ -82,7 +82,7 @@ |
||
| 82 | 82 | |
| 83 | 83 | // If a Group is defined just get the translations from that group |
| 84 | 84 | try { |
| 85 | - $trans_identifier = json_decode(file_get_contents($locale_dir.'/'.$group.'.json'), true); |
|
| 85 | + $trans_identifier = json_decode(file_get_contents($locale_dir.'/'.$group.'.json'), true); |
|
| 86 | 86 | } catch (\ErrorException $e) { |
| 87 | 87 | throw new TranslationCacheNotFound("The Translation cache file '".$locale_dir.'/'.$group.'.json'."' could not be found!"); |
| 88 | 88 | } |
@@ -32,7 +32,7 @@ |
||
| 32 | 32 | */ |
| 33 | 33 | public function __construct($locale) |
| 34 | 34 | { |
| 35 | - $this->locale = $locale; |
|
| 35 | + $this->locale = $locale; |
|
| 36 | 36 | |
| 37 | 37 | $this->refreshCache(); |
| 38 | 38 | } |
@@ -63,8 +63,7 @@ |
||
| 63 | 63 | // So not finding the same identifier twice in the cache, will result in an error. |
| 64 | 64 | if (isset($this->translations[$group][$identifier])) { |
| 65 | 65 | return $this->translations[$group][$identifier]; |
| 66 | - } |
|
| 67 | - else { |
|
| 66 | + } else { |
|
| 68 | 67 | throw new TranslationNotInCacheException("The translation identifier '".$identifier."' could not be found in Cache"); |
| 69 | 68 | } |
| 70 | 69 | } |