@@ -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 | } |
@@ -49,7 +49,7 @@ |
||
49 | 49 | * @param $locale |
50 | 50 | */ |
51 | 51 | function __construct($locale){ |
52 | - $this->locale = $locale; |
|
52 | + $this->locale = $locale; |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | /** |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | * |
49 | 49 | * @param $locale |
50 | 50 | */ |
51 | - function __construct($locale){ |
|
51 | + function __construct($locale) { |
|
52 | 52 | $this->locale = $locale; |
53 | 53 | } |
54 | 54 | |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | * |
58 | 58 | * @return string |
59 | 59 | */ |
60 | - function getLocale(){ |
|
60 | + function getLocale() { |
|
61 | 61 | return $this->locale; |
62 | 62 | } |
63 | 63 | |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | * @param string $group |
69 | 69 | * @return string |
70 | 70 | */ |
71 | - function getTranslation($identifier, $group){ |
|
71 | + function getTranslation($identifier, $group) { |
|
72 | 72 | return $identifier; |
73 | 73 | } |
74 | 74 | |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | * |
78 | 78 | * @return bool |
79 | 79 | */ |
80 | - function refreshCache(){ |
|
80 | + function refreshCache() { |
|
81 | 81 | return true; |
82 | 82 | } |
83 | 83 | |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | * @param string $group |
88 | 88 | * @return array |
89 | 89 | */ |
90 | - function getAllTranslations($group){ |
|
90 | + function getAllTranslations($group) { |
|
91 | 91 | return []; |
92 | 92 | } |
93 | 93 |
@@ -16,21 +16,27 @@ discard block |
||
16 | 16 | * |
17 | 17 | * Class TranslationNotFoundException |
18 | 18 | */ |
19 | -class TranslationNotFoundException extends \Exception {} |
|
19 | +class TranslationNotFoundException extends \Exception |
|
20 | +{ |
|
21 | +} |
|
20 | 22 | |
21 | 23 | /** |
22 | 24 | * Custom Exception to distinguish if the Translation Identifier was not found in Cache but could be in DB |
23 | 25 | * |
24 | 26 | * Class TranslationNotInCacheException |
25 | 27 | */ |
26 | -class TranslationNotInCacheException extends TranslationNotFoundException {} |
|
28 | +class TranslationNotInCacheException extends TranslationNotFoundException |
|
29 | +{ |
|
30 | +} |
|
27 | 31 | |
28 | 32 | /** |
29 | 33 | * Custom Exception thrown when a cache file could not be found |
30 | 34 | * |
31 | 35 | * Class TranslationCacheNotFound |
32 | 36 | */ |
33 | -class TranslationCacheNotFound extends \Exception {} |
|
37 | +class TranslationCacheNotFound extends \Exception |
|
38 | +{ |
|
39 | +} |
|
34 | 40 | |
35 | 41 | /** |
36 | 42 | * Interface HandlerInterface |
@@ -48,7 +54,7 @@ discard block |
||
48 | 54 | * |
49 | 55 | * @param $locale |
50 | 56 | */ |
51 | - function __construct($locale){ |
|
57 | + function __construct($locale) { |
|
52 | 58 | $this->locale = $locale; |
53 | 59 | } |
54 | 60 | |
@@ -57,7 +63,7 @@ discard block |
||
57 | 63 | * |
58 | 64 | * @return string |
59 | 65 | */ |
60 | - function getLocale(){ |
|
66 | + function getLocale() { |
|
61 | 67 | return $this->locale; |
62 | 68 | } |
63 | 69 | |
@@ -68,7 +74,7 @@ discard block |
||
68 | 74 | * @param string $group |
69 | 75 | * @return string |
70 | 76 | */ |
71 | - function getTranslation($identifier, $group){ |
|
77 | + function getTranslation($identifier, $group) { |
|
72 | 78 | return $identifier; |
73 | 79 | } |
74 | 80 | |
@@ -77,7 +83,7 @@ discard block |
||
77 | 83 | * |
78 | 84 | * @return bool |
79 | 85 | */ |
80 | - function refreshCache(){ |
|
86 | + function refreshCache() { |
|
81 | 87 | return true; |
82 | 88 | } |
83 | 89 | |
@@ -87,7 +93,7 @@ discard block |
||
87 | 93 | * @param string $group |
88 | 94 | * @return array |
89 | 95 | */ |
90 | - function getAllTranslations($group){ |
|
96 | + function getAllTranslations($group) { |
|
91 | 97 | return []; |
92 | 98 | } |
93 | 99 |
@@ -61,7 +61,7 @@ |
||
61 | 61 | $locale_dir = TranslatorFacade::getConfigValue('cache_path').$this->locale; |
62 | 62 | |
63 | 63 | try { |
64 | - $trans_identifier = json_decode(file_get_contents($locale_dir.'/'.$group.'.json'), true); |
|
64 | + $trans_identifier = json_decode(file_get_contents($locale_dir.'/'.$group.'.json'), true); |
|
65 | 65 | } catch (\ErrorException $e) { |
66 | 66 | throw new TranslationCacheNotFound("The Translation cache file '".$locale_dir.'/'.$group.'.json'."' could not be found!"); |
67 | 67 | } |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | return $this->translations[$group][$identifier]; |
47 | 47 | } |
48 | 48 | else { |
49 | - throw new TranslationNotInCacheException("The translation identifier '".$identifier."' could not be found in Cache"); |
|
49 | + throw new TranslationNotInCacheException("The translation identifier '" . $identifier . "' could not be found in Cache"); |
|
50 | 50 | } |
51 | 51 | } |
52 | 52 | |
@@ -58,12 +58,12 @@ discard block |
||
58 | 58 | */ |
59 | 59 | public function refreshCache($group = 'default') |
60 | 60 | { |
61 | - $locale_dir = TranslatorFacade::getConfigValue('cache_path').$this->locale; |
|
61 | + $locale_dir = TranslatorFacade::getConfigValue('cache_path') . $this->locale; |
|
62 | 62 | |
63 | 63 | try { |
64 | - $trans_identifier = json_decode(file_get_contents($locale_dir.'/'.$group.'.json'), true); |
|
64 | + $trans_identifier = json_decode(file_get_contents($locale_dir . '/' . $group . '.json'), true); |
|
65 | 65 | } catch (\ErrorException $e) { |
66 | - throw new TranslationCacheNotFound("The Translation cache file '".$locale_dir.'/'.$group.'.json'."' could not be found!"); |
|
66 | + throw new TranslationCacheNotFound("The Translation cache file '" . $locale_dir . '/' . $group . '.json' . "' could not be found!"); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | $this->translations[$group] = $trans_identifier; |
@@ -22,8 +22,7 @@ discard block |
||
22 | 22 | * @param string $locale The locale of the translations |
23 | 23 | * @throws TranslationCacheNotFound |
24 | 24 | */ |
25 | - public function __construct($locale) |
|
26 | - { |
|
25 | + public function __construct($locale) { |
|
27 | 26 | parent::__construct($locale); |
28 | 27 | |
29 | 28 | $this->refreshCache(); |
@@ -37,15 +36,13 @@ discard block |
||
37 | 36 | * @throws TranslationNotInCacheException |
38 | 37 | * @return string returns the found translation for locale and identifier |
39 | 38 | */ |
40 | - public function getTranslation($identifier, $group = 'default') |
|
41 | - { |
|
39 | + public function getTranslation($identifier, $group = 'default') { |
|
42 | 40 | // NOTE: This should never trigger the addition of the identifier to the database! |
43 | 41 | // Because the cache will not be updated automatically. |
44 | 42 | // the same identifier will not be found twice in the cache, which will result in a duplicate key sql error. |
45 | 43 | if (isset($this->translations[$group][$identifier])) { |
46 | 44 | return $this->translations[$group][$identifier]; |
47 | - } |
|
48 | - else { |
|
45 | + } else { |
|
49 | 46 | throw new TranslationNotInCacheException("The translation identifier '".$identifier."' could not be found in Cache"); |
50 | 47 | } |
51 | 48 | } |
@@ -56,8 +53,7 @@ discard block |
||
56 | 53 | * @param string $group |
57 | 54 | * @throws TranslationCacheNotFound |
58 | 55 | */ |
59 | - public function refreshCache($group = 'default') |
|
60 | - { |
|
56 | + public function refreshCache($group = 'default') { |
|
61 | 57 | $locale_dir = TranslatorFacade::getConfigValue('cache_path').$this->locale; |
62 | 58 | |
63 | 59 | try { |
@@ -75,8 +71,7 @@ discard block |
||
75 | 71 | * @param string $group Group of the translations to return |
76 | 72 | * @return array|mixed Translations of the given group |
77 | 73 | */ |
78 | - public function getAllTranslations($group) |
|
79 | - { |
|
74 | + public function getAllTranslations($group) { |
|
80 | 75 | return $this->translations[$group]; |
81 | 76 | } |
82 | 77 | } |
83 | 78 | \ No newline at end of file |
@@ -131,12 +131,12 @@ |
||
131 | 131 | return $translation; |
132 | 132 | } |
133 | 133 | |
134 | - /** |
|
135 | - * Sets the Handler |
|
136 | - * |
|
137 | - * @param $locale |
|
138 | - * @return DefaultHandler |
|
139 | - */ |
|
134 | + /** |
|
135 | + * Sets the Handler |
|
136 | + * |
|
137 | + * @param $locale |
|
138 | + * @return DefaultHandler |
|
139 | + */ |
|
140 | 140 | protected function createHandler($locale) |
141 | 141 | { |
142 | 142 | $handler_class = $this->config['handler']; |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | |
189 | 189 | $keys = []; |
190 | 190 | if (is_array($parameters)) { |
191 | - foreach($parameters as $key => $value) { |
|
191 | + foreach ($parameters as $key => $value) { |
|
192 | 192 | $keys[] = $key; |
193 | 193 | } |
194 | 194 | } |
@@ -206,9 +206,9 @@ discard block |
||
206 | 206 | // When using file Cache, adding the Identifier to the Database will not add it to file Cache! |
207 | 207 | $this->aHandler[$this->locale]->refreshCache(); |
208 | 208 | } |
209 | - $this->log('The translation string "'.$identifier.'" will be written to the Database', 'notice'); |
|
209 | + $this->log('The translation string "' . $identifier . '" will be written to the Database', 'notice'); |
|
210 | 210 | } else { |
211 | - $this->log('The translation string "'.$identifier.'" is already in the Database!', 'warning'); |
|
211 | + $this->log('The translation string "' . $identifier . '" is already in the Database!', 'warning'); |
|
212 | 212 | } |
213 | 213 | } |
214 | 214 | |
@@ -236,7 +236,7 @@ discard block |
||
236 | 236 | { |
237 | 237 | foreach ($parameters as $key => $parameter) { |
238 | 238 | // If the string (e.g "{name}") is not specified within the "parameters" array it won't be replaced! |
239 | - $translation = str_replace("{".$key."}", $parameter, $translation); |
|
239 | + $translation = str_replace("{" . $key . "}", $parameter, $translation); |
|
240 | 240 | } |
241 | 241 | return $translation; |
242 | 242 | } |
@@ -252,7 +252,7 @@ discard block |
||
252 | 252 | protected function returnMissingTranslation($identifier, $locale) |
253 | 253 | { |
254 | 254 | if (config('app.env') !== 'production') { |
255 | - return '<'.$identifier.':'.$locale.'>'; |
|
255 | + return '<' . $identifier . ':' . $locale . '>'; |
|
256 | 256 | } |
257 | 257 | return $identifier; |
258 | 258 | } |
@@ -304,17 +304,17 @@ discard block |
||
304 | 304 | $found_locales = []; |
305 | 305 | |
306 | 306 | foreach ($avail_locales as $avail_locale) { |
307 | - if (strpos($avail_locale, $locale) !== false){ |
|
307 | + if (strpos($avail_locale, $locale) !== false) { |
|
308 | 308 | $found_locales[] = $avail_locale; |
309 | 309 | } |
310 | 310 | } |
311 | 311 | |
312 | - if (in_array($default_locale, $found_locales) || count($found_locales) == 0){ |
|
313 | - $message = 'Locale "'.$locale.'" was not found! Falling back to default locale "'.$default_locale.'"'; |
|
312 | + if (in_array($default_locale, $found_locales) || count($found_locales) == 0) { |
|
313 | + $message = 'Locale "' . $locale . '" was not found! Falling back to default locale "' . $default_locale . '"'; |
|
314 | 314 | $locale = $default_locale; |
315 | 315 | |
316 | 316 | } else { |
317 | - $message = 'Locale "'.$locale.'" was not found! Falling back to similar locale "'.$found_locales[0].'"'; |
|
317 | + $message = 'Locale "' . $locale . '" was not found! Falling back to similar locale "' . $found_locales[0] . '"'; |
|
318 | 318 | $locale = $found_locales[0]; |
319 | 319 | } |
320 | 320 |
@@ -40,8 +40,7 @@ discard block |
||
40 | 40 | * @param string $locale The locale to translate to |
41 | 41 | * @throws \Exception |
42 | 42 | */ |
43 | - public function __construct($locale = '') |
|
44 | - { |
|
43 | + public function __construct($locale = '') { |
|
45 | 44 | $this->config = Config::get($this->configName); |
46 | 45 | |
47 | 46 | $this->setLocale($locale); |
@@ -53,8 +52,7 @@ discard block |
||
53 | 52 | * @param string $key Key for the config value to get |
54 | 53 | * @return string|array Config value for $key |
55 | 54 | */ |
56 | - public function getConfigValue($key) |
|
57 | - { |
|
55 | + public function getConfigValue($key) { |
|
58 | 56 | return $this->config[$key]; |
59 | 57 | } |
60 | 58 | |
@@ -69,8 +67,7 @@ discard block |
||
69 | 67 | * @return string Returns the translation with replaced parameters |
70 | 68 | * |
71 | 69 | */ |
72 | - public function translate($identifier, $parameters = null, $locale = null) |
|
73 | - { |
|
70 | + public function translate($identifier, $parameters = null, $locale = null) { |
|
74 | 71 | if ($locale !== null) { |
75 | 72 | $locale = $this->validateLocale($locale); |
76 | 73 | } else { |
@@ -137,8 +134,7 @@ discard block |
||
137 | 134 | * @param $locale |
138 | 135 | * @return DefaultHandler |
139 | 136 | */ |
140 | - protected function createHandler($locale) |
|
141 | - { |
|
137 | + protected function createHandler($locale) { |
|
142 | 138 | $handler_class = $this->config['handler']; |
143 | 139 | |
144 | 140 | if (session('translation_live_mode')) { |
@@ -164,8 +160,7 @@ discard block |
||
164 | 160 | * |
165 | 161 | * @param string $locale The locale to use |
166 | 162 | */ |
167 | - public function setLocale($locale) |
|
168 | - { |
|
163 | + public function setLocale($locale) { |
|
169 | 164 | $locale = $this->validateLocale($locale); |
170 | 165 | |
171 | 166 | if (!isset($this->aHandler[$locale])) { |
@@ -182,8 +177,7 @@ discard block |
||
182 | 177 | * @param array $parameters The parameters available for the translation |
183 | 178 | * @param string $group The group to put the identifier in |
184 | 179 | */ |
185 | - public function addMissingIdentifierToDB($identifier, $parameters, $group) |
|
186 | - { |
|
180 | + public function addMissingIdentifierToDB($identifier, $parameters, $group) { |
|
187 | 181 | if (!$this->hasIdentifier($identifier)) { |
188 | 182 | |
189 | 183 | $keys = []; |
@@ -218,8 +212,7 @@ discard block |
||
218 | 212 | * @param string $identifier The identifier to check |
219 | 213 | * @return boolean Returns true if the identifier was found |
220 | 214 | */ |
221 | - public function hasIdentifier($identifier) |
|
222 | - { |
|
215 | + public function hasIdentifier($identifier) { |
|
223 | 216 | return TranslationIdentifier::where('identifier', $identifier)->count() > 0; |
224 | 217 | } |
225 | 218 | |
@@ -232,8 +225,7 @@ discard block |
||
232 | 225 | * |
233 | 226 | * @todo Make Prefix and Suffix configurable |
234 | 227 | */ |
235 | - protected function replaceParameter($translation, $parameters) |
|
236 | - { |
|
228 | + protected function replaceParameter($translation, $parameters) { |
|
237 | 229 | foreach ($parameters as $key => $parameter) { |
238 | 230 | // If the string (e.g "{name}") is not specified within the "parameters" array it won't be replaced! |
239 | 231 | $translation = str_replace("{".$key."}", $parameter, $translation); |
@@ -249,8 +241,7 @@ discard block |
||
249 | 241 | * @throws \Exception |
250 | 242 | * @return string The string to display instead of the translation |
251 | 243 | */ |
252 | - protected function returnMissingTranslation($identifier, $locale) |
|
253 | - { |
|
244 | + protected function returnMissingTranslation($identifier, $locale) { |
|
254 | 245 | if (config('app.env') !== 'production') { |
255 | 246 | return '<'.$identifier.':'.$locale.'>'; |
256 | 247 | } |
@@ -264,8 +255,7 @@ discard block |
||
264 | 255 | * @param string $locale The locale to validate |
265 | 256 | * @return string Returns the validated Locale |
266 | 257 | */ |
267 | - public function validateLocale($locale) |
|
268 | - { |
|
258 | + public function validateLocale($locale) { |
|
269 | 259 | $avail_locales = $this->config['available_locales']; |
270 | 260 | $default_locale = $this->config['default_locale']; |
271 | 261 | |
@@ -296,8 +286,7 @@ discard block |
||
296 | 286 | * @throws NotFoundResourceException |
297 | 287 | * @return string Returns the guessed Locale |
298 | 288 | */ |
299 | - private function guessLocale($locale) |
|
300 | - { |
|
289 | + private function guessLocale($locale) { |
|
301 | 290 | $avail_locales = $this->config['available_locales']; |
302 | 291 | $default_locale = $this->config['default_locale']; |
303 | 292 | |
@@ -318,7 +307,9 @@ discard block |
||
318 | 307 | $locale = $found_locales[0]; |
319 | 308 | } |
320 | 309 | |
321 | - if ($message !== '') $this->log($message, 'warning'); |
|
310 | + if ($message !== '') { |
|
311 | + $this->log($message, 'warning'); |
|
312 | + } |
|
322 | 313 | |
323 | 314 | return $locale; |
324 | 315 | } |
@@ -330,8 +321,7 @@ discard block |
||
330 | 321 | * @param string $group The group of the translations to get |
331 | 322 | * @return array|mixed Returns an array of all translation in the $locale from group $group |
332 | 323 | */ |
333 | - public function getAllTranslations($locale, $group) |
|
334 | - { |
|
324 | + public function getAllTranslations($locale, $group) { |
|
335 | 325 | if (!isset($this->aHandler[$locale])) { |
336 | 326 | $this->aHandler[$locale] = $this->createHandler($locale); |
337 | 327 | } |
@@ -345,8 +335,7 @@ discard block |
||
345 | 335 | * @param \Exception|string $exception The Exception to log |
346 | 336 | * @param string $log_type The type of the log to write in the log file |
347 | 337 | */ |
348 | - protected function log($exception, $log_type = 'notice') |
|
349 | - { |
|
338 | + protected function log($exception, $log_type = 'notice') { |
|
350 | 339 | if ($this->config['log_level'] !== 'debug') { |
351 | 340 | return; |
352 | 341 | } |
@@ -7,11 +7,11 @@ |
||
7 | 7 | * @license http://opensource.org/licenses/MIT MIT |
8 | 8 | */ |
9 | 9 | |
10 | -if (! Hokan22\LaravelTranslator\TranslatorFacade::getConfigValue('custom_routes')) { |
|
11 | - Route::group(['prefix' => 'translator'], function () { |
|
10 | +if (!Hokan22\LaravelTranslator\TranslatorFacade::getConfigValue('custom_routes')) { |
|
11 | + Route::group(['prefix' => 'translator'], function() { |
|
12 | 12 | Route::get('/test', 'Hokan22\LaravelTranslator\Controllers\TranslatorAdminController@test')->name('translator.test'); |
13 | 13 | |
14 | - Route::group(['prefix' => 'admin'], function () { |
|
14 | + Route::group(['prefix' => 'admin'], function() { |
|
15 | 15 | Route::get('/', 'Hokan22\LaravelTranslator\Controllers\TranslatorAdminController@index')->name('translator.admin'); |
16 | 16 | Route::post('/', 'Hokan22\LaravelTranslator\Controllers\TranslatorAdminController@postIdentifier')->name('translator.post.admin'); |
17 | 17 | Route::get('/{id}', 'Hokan22\LaravelTranslator\Controllers\TranslatorAdminController@edit')->where('id', '[0-9]+')->name('translator.admin.edit'); |
@@ -42,11 +42,11 @@ discard block |
||
42 | 42 | { |
43 | 43 | if (isset($this->translations[$identifier])) { |
44 | 44 | if ($this->translations[$identifier]->translation == null) { |
45 | - throw new TranslationNotFoundException("The translation for identifier '".$identifier."' and locale '".$this->locale."' could not be found"); |
|
45 | + throw new TranslationNotFoundException("The translation for identifier '" . $identifier . "' and locale '" . $this->locale . "' could not be found"); |
|
46 | 46 | } |
47 | 47 | return $this->translations[$identifier]->translation; |
48 | 48 | } else { |
49 | - throw new NotFoundResourceException("The translation identifier '".$identifier."' could not be found"); |
|
49 | + throw new NotFoundResourceException("The translation identifier '" . $identifier . "' could not be found"); |
|
50 | 50 | } |
51 | 51 | } |
52 | 52 | |
@@ -58,9 +58,9 @@ discard block |
||
58 | 58 | public function refreshCache() |
59 | 59 | { |
60 | 60 | $translations = new TranslationIdentifier(); |
61 | - $translations = $translations->leftJoin('translations', function ($join) |
|
61 | + $translations = $translations->leftJoin('translations', function($join) |
|
62 | 62 | { |
63 | - $join->on( 'translation_identifiers.id', '=', 'translations.translation_identifier_id') |
|
63 | + $join->on('translation_identifiers.id', '=', 'translations.translation_identifier_id') |
|
64 | 64 | ->where('locale', $this->locale); |
65 | 65 | } |
66 | 66 | )->get(); |
@@ -98,10 +98,10 @@ discard block |
||
98 | 98 | */ |
99 | 99 | function getDatabaseID($identifier) |
100 | 100 | { |
101 | - if(isset($this->translations[$identifier])) { |
|
101 | + if (isset($this->translations[$identifier])) { |
|
102 | 102 | return $this->translations[$identifier]->id; |
103 | 103 | } else { |
104 | - throw new NotFoundResourceException("The translation identifier '".$identifier."' could not be found"); |
|
104 | + throw new NotFoundResourceException("The translation identifier '" . $identifier . "' could not be found"); |
|
105 | 105 | } |
106 | 106 | } |
107 | 107 | } |
108 | 108 | \ No newline at end of file |
@@ -22,8 +22,7 @@ discard block |
||
22 | 22 | * |
23 | 23 | * @param string $locale The locale of the translations |
24 | 24 | */ |
25 | - public function __construct($locale) |
|
26 | - { |
|
25 | + public function __construct($locale) { |
|
27 | 26 | parent::__construct($locale); |
28 | 27 | |
29 | 28 | $this->refreshCache(); |
@@ -38,8 +37,7 @@ discard block |
||
38 | 37 | * @throws TranslationNotFoundException |
39 | 38 | * @return string returns the found translation for identifier |
40 | 39 | */ |
41 | - public function getTranslation($identifier, $group) |
|
42 | - { |
|
40 | + public function getTranslation($identifier, $group) { |
|
43 | 41 | if (isset($this->translations[$identifier])) { |
44 | 42 | if ($this->translations[$identifier]->translation == null) { |
45 | 43 | throw new TranslationNotFoundException("The translation for identifier '".$identifier."' and locale '".$this->locale."' could not be found"); |
@@ -55,11 +53,9 @@ discard block |
||
55 | 53 | * |
56 | 54 | * @return void |
57 | 55 | */ |
58 | - public function refreshCache() |
|
59 | - { |
|
56 | + public function refreshCache() { |
|
60 | 57 | $translations = new TranslationIdentifier(); |
61 | - $translations = $translations->leftJoin('translations', function ($join) |
|
62 | - { |
|
58 | + $translations = $translations->leftJoin('translations', function ($join) { |
|
63 | 59 | $join->on( 'translation_identifiers.id', '=', 'translations.translation_identifier_id') |
64 | 60 | ->where('locale', $this->locale); |
65 | 61 | } |
@@ -76,8 +72,7 @@ discard block |
||
76 | 72 | * @param string $group Group of the translations to return |
77 | 73 | * @return array Translations of the given group |
78 | 74 | */ |
79 | - public function getAllTranslations($group = 'default') |
|
80 | - { |
|
75 | + public function getAllTranslations($group = 'default') { |
|
81 | 76 | $return = []; |
82 | 77 | foreach (collect($this->translations)->where('group', $group) as $key => $translation) { |
83 | 78 | if ($translation->translation == null) { |
@@ -96,8 +91,7 @@ discard block |
||
96 | 91 | * @throws NotFoundResourceException |
97 | 92 | * @return integer |
98 | 93 | */ |
99 | - function getDatabaseID($identifier) |
|
100 | - { |
|
94 | + function getDatabaseID($identifier) { |
|
101 | 95 | if(isset($this->translations[$identifier])) { |
102 | 96 | return $this->translations[$identifier]->id; |
103 | 97 | } else { |
@@ -60,8 +60,7 @@ |
||
60 | 60 | * |
61 | 61 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
62 | 62 | */ |
63 | - public function translationIdentifier() |
|
64 | - { |
|
63 | + public function translationIdentifier() { |
|
65 | 64 | return $this->belongsTo(TranslationIdentifier::class); |
66 | 65 | } |
67 | 66 | } |
68 | 67 | \ No newline at end of file |
@@ -62,8 +62,7 @@ |
||
62 | 62 | * |
63 | 63 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
64 | 64 | */ |
65 | - public function translations() |
|
66 | - { |
|
65 | + public function translations() { |
|
67 | 66 | return $this->hasMany(Translations::class); |
68 | 67 | } |
69 | 68 |
@@ -76,8 +76,8 @@ discard block |
||
76 | 76 | 'js' => '/\$filter\(\'translate\'\)\(\'(?\'identifier\'.*?)\'\)/' |
77 | 77 | ]; |
78 | 78 | |
79 | - foreach($folders as $folder) { |
|
80 | - $aFiles = array_merge($aFiles, File::allFiles(base_path().'/'.$folder)); |
|
79 | + foreach ($folders as $folder) { |
|
80 | + $aFiles = array_merge($aFiles, File::allFiles(base_path() . '/' . $folder)); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | TranslatorFacade::setLocale('de_DE'); |
@@ -85,20 +85,20 @@ discard block |
||
85 | 85 | $num_files = count($aFiles); |
86 | 86 | |
87 | 87 | $this->bar = $this->output->createProgressBar($num_files); |
88 | - $this->bar->setMessage('Analyzing '.$num_files.' files'); |
|
88 | + $this->bar->setMessage('Analyzing ' . $num_files . ' files'); |
|
89 | 89 | $this->bar->setFormat('very_verbose'); |
90 | 90 | |
91 | 91 | foreach ($aFiles as $file) { |
92 | 92 | |
93 | 93 | $extension = $file->getExtension(); |
94 | 94 | |
95 | - if(in_array($extension, $valid_extensions)) { |
|
95 | + if (in_array($extension, $valid_extensions)) { |
|
96 | 96 | $content = file_get_contents($file); |
97 | 97 | |
98 | 98 | foreach ($regexes as $key => $regex) { |
99 | 99 | preg_match_all($regex, $content, $result, PREG_SET_ORDER); |
100 | 100 | |
101 | - if(!empty($result[0])) { |
|
101 | + if (!empty($result[0])) { |
|
102 | 102 | $this->addMissing($result, $key); |
103 | 103 | } |
104 | 104 | } |
@@ -114,10 +114,10 @@ discard block |
||
114 | 114 | ['Num', 'Translations...'], |
115 | 115 | [ |
116 | 116 | [$this->found_identifier, "Found"], |
117 | - [$this->new_identifier, "New"], |
|
118 | - [$this->dupl_identifier, "Duplicates"], |
|
117 | + [$this->new_identifier, "New"], |
|
118 | + [$this->dupl_identifier, "Duplicates"], |
|
119 | 119 | [$this->found_parameters, "With Parameters"], |
120 | - [$this->found_invalid, "Invalid"], |
|
120 | + [$this->found_invalid, "Invalid"], |
|
121 | 121 | ] |
122 | 122 | ); |
123 | 123 | |
@@ -148,14 +148,14 @@ discard block |
||
148 | 148 | $parameter_string = substr($parameter_string, 1, -1); |
149 | 149 | } |
150 | 150 | |
151 | - $parameter_array = explode(",",$parameter_string); |
|
151 | + $parameter_array = explode(",", $parameter_string); |
|
152 | 152 | $parameters = array(); |
153 | 153 | |
154 | - foreach($parameter_array as $parameter) { |
|
155 | - $parameter = explode("=>",$parameter); |
|
154 | + foreach ($parameter_array as $parameter) { |
|
155 | + $parameter = explode("=>", $parameter); |
|
156 | 156 | |
157 | - $key = str_replace([" ", "'"],"", $parameter[0]); |
|
158 | - $value = str_replace([" ", "'"],"", $parameter[1]); |
|
157 | + $key = str_replace([" ", "'"], "", $parameter[0]); |
|
158 | + $value = str_replace([" ", "'"], "", $parameter[1]); |
|
159 | 159 | |
160 | 160 | $parameters[$key] = $value; |
161 | 161 | } |
@@ -163,13 +163,13 @@ discard block |
||
163 | 163 | $this->found_parameters++; |
164 | 164 | } |
165 | 165 | |
166 | - if(!isset($aTranslations[$identifier])) { |
|
166 | + if (!isset($aTranslations[$identifier])) { |
|
167 | 167 | $aTranslations[$identifier] = TranslatorFacade::hasIdentifier($identifier); |
168 | 168 | |
169 | 169 | if (!$aTranslations[$identifier]) { |
170 | 170 | TranslatorFacade::addMissingIdentifier($identifier, $parameters, $group); |
171 | 171 | $this->bar->clear(); |
172 | - $this->info('Adding: "'.$identifier.'" to database'); |
|
172 | + $this->info('Adding: "' . $identifier . '" to database'); |
|
173 | 173 | $this->bar->display(); |
174 | 174 | $this->new_identifier++; |
175 | 175 | } |
@@ -177,9 +177,9 @@ discard block |
||
177 | 177 | $this->dupl_identifier++; |
178 | 178 | } |
179 | 179 | |
180 | - } catch(\Exception $e){ |
|
180 | + } catch (\Exception $e) { |
|
181 | 181 | $this->bar->clear(); |
182 | - $this->info($identifier.' '.strlen($identifier)); |
|
182 | + $this->info($identifier . ' ' . strlen($identifier)); |
|
183 | 183 | $this->info($e->getMessage()); |
184 | 184 | $this->line(''); |
185 | 185 | $this->bar->display(); |
@@ -45,8 +45,7 @@ discard block |
||
45 | 45 | /** |
46 | 46 | * Create a new command instance. |
47 | 47 | */ |
48 | - public function __construct() |
|
49 | - { |
|
48 | + public function __construct() { |
|
50 | 49 | parent::__construct(); |
51 | 50 | } |
52 | 51 | |
@@ -56,8 +55,7 @@ discard block |
||
56 | 55 | * @return mixed |
57 | 56 | * @throws \Exception |
58 | 57 | */ |
59 | - public function handle() |
|
60 | - { |
|
58 | + public function handle() { |
|
61 | 59 | $start = microtime(true); |
62 | 60 | |
63 | 61 | $this->line(''); |
@@ -132,8 +130,7 @@ discard block |
||
132 | 130 | * @param array $result Array with |
133 | 131 | * @param string $group |
134 | 132 | */ |
135 | - protected function addMissing($result, $group) |
|
136 | - { |
|
133 | + protected function addMissing($result, $group) { |
|
137 | 134 | foreach ($result as $item) { |
138 | 135 | try { |
139 | 136 | $identifier = trim($item['identifier']); |
@@ -177,7 +174,7 @@ discard block |
||
177 | 174 | $this->dupl_identifier++; |
178 | 175 | } |
179 | 176 | |
180 | - } catch(\Exception $e){ |
|
177 | + } catch(\Exception $e) { |
|
181 | 178 | $this->bar->clear(); |
182 | 179 | $this->info($identifier.' '.strlen($identifier)); |
183 | 180 | $this->info($e->getMessage()); |