@@ -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 | |
@@ -23,7 +23,7 @@ |
||
| 23 | 23 | |
| 24 | 24 | $locale = TranslatorFacade::validateLocale($locale); |
| 25 | 25 | |
| 26 | - if(Session::has('locale') == false){ |
|
| 26 | + if (Session::has('locale') == false) { |
|
| 27 | 27 | Session::put('locale', $locale); |
| 28 | 28 | Session::save(); |
| 29 | 29 | } |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | */ |
| 43 | 43 | public function getTranslation($identifier, $group) { |
| 44 | 44 | |
| 45 | - if(isset($this->translations[$identifier])) { |
|
| 45 | + if (isset($this->translations[$identifier])) { |
|
| 46 | 46 | if ($this->translations[$identifier]->translation == null) { |
| 47 | 47 | throw new TranslationNotFoundException("The translation for identifier '".$identifier."' and locale '".$this->locale."' could not be found"); |
| 48 | 48 | } |
@@ -58,9 +58,9 @@ discard block |
||
| 58 | 58 | */ |
| 59 | 59 | public function refreshCache() { |
| 60 | 60 | // Get all Texts with translations for the given locale |
| 61 | - $translations = new TranslationIdentifier(); |
|
| 62 | - $translations = $translations->leftJoin('translations', function ($join) { |
|
| 63 | - $join->on( 'translation_identifiers.id', '=', 'translations.translation_identifier_id') |
|
| 61 | + $translations = new TranslationIdentifier(); |
|
| 62 | + $translations = $translations->leftJoin('translations', function($join) { |
|
| 63 | + $join->on('translation_identifiers.id', '=', 'translations.translation_identifier_id') |
|
| 64 | 64 | ->where('locale', $this->locale); |
| 65 | 65 | })->get(); |
| 66 | 66 | |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | * @throws TranslationCacheNotFound |
| 21 | 21 | */ |
| 22 | 22 | public function __construct($locale) { |
| 23 | - $this->locale = $locale; |
|
| 23 | + $this->locale = $locale; |
|
| 24 | 24 | |
| 25 | 25 | $this->refreshCache(); |
| 26 | 26 | } |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | // NOTE: This should never trigger the addition of the identifier to the database, |
| 45 | 45 | // because the cache will not be updated automatically. |
| 46 | 46 | // So not finding the same identifier twice in the cache, will result in an error. |
| 47 | - if(isset($this->translations[$group][$identifier])) { |
|
| 47 | + if (isset($this->translations[$group][$identifier])) { |
|
| 48 | 48 | return $this->translations[$group][$identifier]; |
| 49 | 49 | } |
| 50 | 50 | else { |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | */ |
| 81 | 81 | public function getAllTranslations($group) |
| 82 | 82 | { |
| 83 | - if(!isset($this->translations[$group])) { |
|
| 83 | + if (!isset($this->translations[$group])) { |
|
| 84 | 84 | $this->refreshCache($group); |
| 85 | 85 | } |
| 86 | 86 | return $this->translations[$group]; |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | */ |
| 17 | 17 | public function boot() |
| 18 | 18 | { |
| 19 | - Blade::directive('translate', function ($expression) { |
|
| 19 | + Blade::directive('translate', function($expression) { |
|
| 20 | 20 | |
| 21 | 21 | $expression = $this->stripParentheses($expression); |
| 22 | 22 | |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | return "<?php echo Hokan22\\LaravelTranslator\\TranslatorFacade::translate({$expression}); ?>"; |
| 25 | 25 | }); |
| 26 | 26 | |
| 27 | - Blade::directive('t', function ($expression) { |
|
| 27 | + Blade::directive('t', function($expression) { |
|
| 28 | 28 | |
| 29 | 29 | $expression = $this->stripParentheses($expression); |
| 30 | 30 | |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | { |
| 18 | 18 | $this->mergeConfigFrom(__DIR__.'/../config/translator.php', 'translator'); |
| 19 | 19 | |
| 20 | - $this->app->singleton('Translator', function () { |
|
| 20 | + $this->app->singleton('Translator', function() { |
|
| 21 | 21 | return new Translator(); |
| 22 | 22 | }); |
| 23 | 23 | } |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | */ |
| 30 | 30 | public function boot() { |
| 31 | 31 | $this->publishes([ |
| 32 | - __DIR__ . '/../config/translator.php' => config_path('translator.php'), |
|
| 32 | + __DIR__.'/../config/translator.php' => config_path('translator.php'), |
|
| 33 | 33 | ], |
| 34 | 34 | 'config' |
| 35 | 35 | ); |
@@ -1,12 +1,12 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -if (! Hokan22\LaravelTranslator\TranslatorFacade::getConfigValue('custom_routes')) { |
|
| 3 | +if (!Hokan22\LaravelTranslator\TranslatorFacade::getConfigValue('custom_routes')) { |
|
| 4 | 4 | |
| 5 | - Route::group(['prefix' => 'translator'], function () { |
|
| 5 | + Route::group(['prefix' => 'translator'], function() { |
|
| 6 | 6 | |
| 7 | 7 | Route::get('/test', 'Hokan22\LaravelTranslator\Controllers\TranslatorAdminController@test')->name('translator.test'); |
| 8 | 8 | |
| 9 | - Route::group(['prefix' => 'admin'], function () { |
|
| 9 | + Route::group(['prefix' => 'admin'], function() { |
|
| 10 | 10 | |
| 11 | 11 | Route::get('/', 'Hokan22\LaravelTranslator\Controllers\TranslatorAdminController@index')->name('translator.admin'); |
| 12 | 12 | Route::post('/', 'Hokan22\LaravelTranslator\Controllers\TranslatorAdminController@postIdentifier')->name('translator.post.admin'); |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | /** |
| 21 | 21 | * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
| 22 | 22 | */ |
| 23 | - public function index () { |
|
| 23 | + public function index() { |
|
| 24 | 24 | |
| 25 | 25 | $locale = Input::get('locale', ''); |
| 26 | 26 | $search = Input::get('search', ''); |
@@ -28,24 +28,24 @@ discard block |
||
| 28 | 28 | $query = TranslationIdentifier::with('translations')->orderBy('updated_at', 'DESC')->orderBy('id', 'DESC'); |
| 29 | 29 | |
| 30 | 30 | if ($locale != '') { |
| 31 | - $query = TranslationIdentifier::wheredoesntHave('translations', function ($query) use ($locale) { |
|
| 31 | + $query = TranslationIdentifier::wheredoesntHave('translations', function($query) use ($locale) { |
|
| 32 | 32 | $query->where('locale', 'like', $locale); |
| 33 | 33 | }); |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | if ($search != '') { |
| 37 | - $query = TranslationIdentifier::where('identifier', 'LIKE', '%'.$search.'%') |
|
| 37 | + $query = TranslationIdentifier::where('identifier', 'LIKE', '%'.$search.'%') |
|
| 38 | 38 | ->orWhere('parameters', 'LIKE', '%'.$search.'%') |
| 39 | - ->orWhere('group', 'LIKE', '%'.$search.'%') |
|
| 40 | - ->orWhere('page_name', 'LIKE', '%'.$search.'%') |
|
| 41 | - ->orWhere('description','LIKE', '%'.$search.'%'); |
|
| 39 | + ->orWhere('group', 'LIKE', '%'.$search.'%') |
|
| 40 | + ->orWhere('page_name', 'LIKE', '%'.$search.'%') |
|
| 41 | + ->orWhere('description', 'LIKE', '%'.$search.'%'); |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | $trans_identifier = $query->orderBy('updated_at', 'DESC')->orderBy('id', 'DESC')->paginate(20)->appends(Input::except('page')); |
| 45 | 45 | |
| 46 | 46 | $available_locales = TranslatorFacade::getConfigValue('available_locales'); |
| 47 | 47 | |
| 48 | - return view('translator::index',[ |
|
| 48 | + return view('translator::index', [ |
|
| 49 | 49 | 'identifier' => $trans_identifier, |
| 50 | 50 | 'available_locales' => $available_locales, |
| 51 | 51 | ]); |
@@ -55,13 +55,13 @@ discard block |
||
| 55 | 55 | * @param $id |
| 56 | 56 | * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
| 57 | 57 | */ |
| 58 | - public function edit ($id) { |
|
| 58 | + public function edit($id) { |
|
| 59 | 59 | |
| 60 | 60 | $identifier = TranslationIdentifier::findOrFail($id); |
| 61 | 61 | |
| 62 | 62 | $available_locales = TranslatorFacade::getConfigValue('available_locales'); |
| 63 | 63 | |
| 64 | - return view('translator::edit',[ |
|
| 64 | + return view('translator::edit', [ |
|
| 65 | 65 | 'identifier' => $identifier, |
| 66 | 66 | 'available_locales' => $available_locales, |
| 67 | 67 | ]); |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | * @param Request $request |
| 74 | 74 | * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
| 75 | 75 | */ |
| 76 | - public function postEdit ($id, Request $request) { |
|
| 76 | + public function postEdit($id, Request $request) { |
|
| 77 | 77 | |
| 78 | 78 | TranslationIdentifier::findOrFail($id); |
| 79 | 79 | |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | * @param Request $request |
| 107 | 107 | * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
| 108 | 108 | */ |
| 109 | - public function postIdentifier (Request $request) { |
|
| 109 | + public function postIdentifier(Request $request) { |
|
| 110 | 110 | |
| 111 | 111 | /** @var TranslationIdentifier $translation_identifiers */ |
| 112 | 112 | $translation_identifiers = TranslationIdentifier::all()->whereIn('id', array_keys($request->all())); |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | /** |
| 134 | 134 | * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
| 135 | 135 | */ |
| 136 | - public function test () { |
|
| 136 | + public function test() { |
|
| 137 | 137 | return view('translator::test'); |
| 138 | 138 | } |
| 139 | 139 | } |
| 140 | 140 | \ No newline at end of file |
@@ -21,7 +21,7 @@ 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 | * The name and signature of the console command. |
| 27 | 27 | * |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | /** |
| 48 | 48 | * Create a new command instance. |
| 49 | 49 | */ |
| 50 | - public function __construct(){ |
|
| 50 | + public function __construct() { |
|
| 51 | 51 | parent::__construct(); |
| 52 | 52 | } |
| 53 | 53 | |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | * @return mixed |
| 58 | 58 | * @throws \Exception |
| 59 | 59 | */ |
| 60 | - public function handle(){ |
|
| 60 | + public function handle() { |
|
| 61 | 61 | |
| 62 | 62 | // Get start time |
| 63 | 63 | $start = microtime(true); |
@@ -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 | } |
@@ -113,23 +113,23 @@ discard block |
||
| 113 | 113 | $this->line(''); |
| 114 | 114 | $this->line(''); |
| 115 | 115 | |
| 116 | - $this->table(['Num', 'Translations...'],[ |
|
| 116 | + $this->table(['Num', 'Translations...'], [ |
|
| 117 | 117 | [$this->found_identifier, "Found"], |
| 118 | - [$this->new_identifier, "New"], |
|
| 119 | - [$this->dupl_identifier, "Duplicates"], |
|
| 118 | + [$this->new_identifier, "New"], |
|
| 119 | + [$this->dupl_identifier, "Duplicates"], |
|
| 120 | 120 | [$this->found_parameters, "With Parameters"], |
| 121 | - [$this->found_invalid, "Invalid"], |
|
| 121 | + [$this->found_invalid, "Invalid"], |
|
| 122 | 122 | ]); |
| 123 | 123 | |
| 124 | 124 | $this->line(''); |
| 125 | 125 | |
| 126 | - $this->info('Finished in: ' . number_format(microtime(true) - $start, 2) . 'sec'); |
|
| 126 | + $this->info('Finished in: '.number_format(microtime(true) - $start, 2).'sec'); |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | private function addMissing($result, $group) { |
| 130 | 130 | |
| 131 | 131 | foreach ($result as $item) { |
| 132 | - try{ |
|
| 132 | + try { |
|
| 133 | 133 | |
| 134 | 134 | $identifier = trim($item['identifier']); |
| 135 | 135 | $this->found_identifier++; |
@@ -140,19 +140,19 @@ discard block |
||
| 140 | 140 | |
| 141 | 141 | $parameter_string = $item['parameters']; |
| 142 | 142 | |
| 143 | - if (substr($parameter_string, 0, 1 ) === '[') { |
|
| 143 | + if (substr($parameter_string, 0, 1) === '[') { |
|
| 144 | 144 | $parameter_string = substr($parameter_string, 1, -1); |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | - $parameter_array = explode(",",$parameter_string); |
|
| 147 | + $parameter_array = explode(",", $parameter_string); |
|
| 148 | 148 | |
| 149 | 149 | $parameters = array(); |
| 150 | - foreach($parameter_array as $parameter ) |
|
| 150 | + foreach ($parameter_array as $parameter) |
|
| 151 | 151 | { |
| 152 | - $parameter = explode("=>",$parameter); |
|
| 152 | + $parameter = explode("=>", $parameter); |
|
| 153 | 153 | |
| 154 | - $key = str_replace([" ", "'"],"", $parameter[0]); |
|
| 155 | - $value = str_replace([" ", "'"],"", $parameter[1]); |
|
| 154 | + $key = str_replace([" ", "'"], "", $parameter[0]); |
|
| 155 | + $value = str_replace([" ", "'"], "", $parameter[1]); |
|
| 156 | 156 | |
| 157 | 157 | $parameters[$key] = $value; |
| 158 | 158 | } |
@@ -160,10 +160,10 @@ 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 | - if (! $aTranslations[$identifier]) { |
|
| 166 | + if (!$aTranslations[$identifier]) { |
|
| 167 | 167 | TranslatorFacade::addMissingIdentifier($identifier, $parameters, $group); |
| 168 | 168 | $this->bar->clear(); |
| 169 | 169 | $this->info('Adding: "'.$identifier.'" to database'); |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | $this->dupl_identifier++; |
| 176 | 176 | } |
| 177 | 177 | |
| 178 | - }catch(\Exception $e){ |
|
| 178 | + } catch (\Exception $e) { |
|
| 179 | 179 | $this->bar->clear(); |
| 180 | 180 | $this->info($identifier.' '.strlen($identifier)); |
| 181 | 181 | $this->info($e->getMessage()); |