@@ -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 | } |
@@ -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 |
@@ -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 |
@@ -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 |
@@ -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 | } |
@@ -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()); |
@@ -39,8 +39,7 @@ discard block |
||
39 | 39 | /** |
40 | 40 | * Create a new command instance. |
41 | 41 | */ |
42 | - public function __construct() |
|
43 | - { |
|
42 | + public function __construct() { |
|
44 | 43 | parent::__construct(); |
45 | 44 | } |
46 | 45 | |
@@ -49,8 +48,7 @@ discard block |
||
49 | 48 | * |
50 | 49 | * @throws \Exception |
51 | 50 | */ |
52 | - public function handle() |
|
53 | - { |
|
51 | + public function handle() { |
|
54 | 52 | $locale = $this->argument('locale'); |
55 | 53 | |
56 | 54 | if (!is_string($locale)) |
@@ -99,8 +97,7 @@ discard block |
||
99 | 97 | * |
100 | 98 | * @return array |
101 | 99 | */ |
102 | - protected function getGroups() |
|
103 | - { |
|
100 | + protected function getGroups() { |
|
104 | 101 | return DB::table('translation_identifiers')->select('group')->groupBy(['group'])->get()->pluck('group'); |
105 | 102 | } |
106 | 103 | |
@@ -110,12 +107,10 @@ discard block |
||
110 | 107 | * @param string $locale The locale from which the translations to load |
111 | 108 | * @return TranslationIdentifier|\Illuminate\Database\Eloquent\Collection|static[] |
112 | 109 | */ |
113 | - protected function loadFromDB($locale) |
|
114 | - { |
|
110 | + protected function loadFromDB($locale) { |
|
115 | 111 | $trans_identifier = new TranslationIdentifier(); |
116 | 112 | |
117 | - $trans_identifier = $trans_identifier->with('translations')->whereHas('translations', function ($item) use ($locale) |
|
118 | - { |
|
113 | + $trans_identifier = $trans_identifier->with('translations')->whereHas('translations', function ($item) use ($locale) { |
|
119 | 114 | return $item->where('locale', $locale); |
120 | 115 | } |
121 | 116 | )->orWhereHas('translations', null, '<=', 0) |