@@ -28,8 +28,9 @@ discard block |
||
| 28 | 28 | $this->detect_language_env(); |
| 29 | 29 | $the_one_language = current(array_intersect($this->detect_language_files(), $this->detect_language_env())); |
| 30 | 30 | |
| 31 | - if($the_one_language) |
|
| 32 | - $this->setForcedLang($the_one_language); |
|
| 31 | + if($the_one_language) { |
|
| 32 | + $this->setForcedLang($the_one_language); |
|
| 33 | + } |
|
| 33 | 34 | |
| 34 | 35 | return $the_one_language; |
| 35 | 36 | } |
@@ -37,13 +38,16 @@ discard block |
||
| 37 | 38 | public function detect_language_files() |
| 38 | 39 | { |
| 39 | 40 | $files = FileSystem::preg_scandir(dirname($this->filePath), '/.json$/'); |
| 40 | - if(empty($files)) |
|
| 41 | - return []; |
|
| 41 | + if(empty($files)) { |
|
| 42 | + return []; |
|
| 43 | + } |
|
| 42 | 44 | |
| 43 | 45 | $files = implode('',$files); |
| 44 | 46 | $res = preg_match_all('/([a-z]{3})\.json/', $files, $m); |
| 45 | - if($res) // false or 0 is none found |
|
| 47 | + if($res) { |
|
| 48 | + // false or 0 is none found |
|
| 46 | 49 | $this->detected_language_files = $m[1]; |
| 50 | + } |
|
| 47 | 51 | return $this->detected_language_files; |
| 48 | 52 | } |
| 49 | 53 | |
@@ -91,8 +95,9 @@ discard block |
||
| 91 | 95 | // remove illegal userLangs |
| 92 | 96 | foreach ($userLangs as $key => $value) { |
| 93 | 97 | // only allow a-z, A-Z and 0-9 and _ and - |
| 94 | - if (preg_match('/^[a-zA-Z0-9_-]*$/', $value) === 1) |
|
| 95 | - $this->detected_language_env[$key] = $value; |
|
| 98 | + if (preg_match('/^[a-zA-Z0-9_-]*$/', $value) === 1) { |
|
| 99 | + $this->detected_language_env[$key] = $value; |
|
| 100 | + } |
|
| 96 | 101 | } |
| 97 | 102 | |
| 98 | 103 | return $this->detected_language_env; |
@@ -119,12 +124,13 @@ discard block |
||
| 119 | 124 | return __FUNCTION__.': error'; |
| 120 | 125 | } |
| 121 | 126 | |
| 122 | - if($amount_of_days === -1) |
|
| 123 | - return L('DATETIME_RANGE_YESTERDAY'); |
|
| 124 | - elseif($amount_of_days === 0) |
|
| 125 | - return L('DATETIME_RANGE_TODAY'); |
|
| 126 | - elseif($amount_of_days === 1) |
|
| 127 | - return L('DATETIME_RANGE_TOMORROW'); |
|
| 127 | + if($amount_of_days === -1) { |
|
| 128 | + return L('DATETIME_RANGE_YESTERDAY'); |
|
| 129 | + } elseif($amount_of_days === 0) { |
|
| 130 | + return L('DATETIME_RANGE_TODAY'); |
|
| 131 | + } elseif($amount_of_days === 1) { |
|
| 132 | + return L('DATETIME_RANGE_TOMORROW'); |
|
| 133 | + } |
|
| 128 | 134 | |
| 129 | 135 | |
| 130 | 136 | $datetime_parts = [ |
@@ -141,18 +147,21 @@ discard block |
||
| 141 | 147 | $ordering = []; |
| 142 | 148 | foreach($datetime_parts as $unit => $label) |
| 143 | 149 | { |
| 144 | - if(!isset($date_diff[$unit])) |
|
| 145 | - continue; |
|
| 150 | + if(!isset($date_diff[$unit])) { |
|
| 151 | + continue; |
|
| 152 | + } |
|
| 146 | 153 | |
| 147 | 154 | $qty = (int)$date_diff[$unit]; |
| 148 | 155 | |
| 149 | - if($qty === 0) |
|
| 150 | - continue; |
|
| 156 | + if($qty === 0) { |
|
| 157 | + continue; |
|
| 158 | + } |
|
| 151 | 159 | |
| 152 | - if(isset($options['abbrev'])) |
|
| 153 | - $label.= '_ABBREV'; |
|
| 154 | - elseif($qty > 1) |
|
| 155 | - $label.= '_PLURAL'; |
|
| 160 | + if(isset($options['abbrev'])) { |
|
| 161 | + $label.= '_ABBREV'; |
|
| 162 | + } elseif($qty > 1) { |
|
| 163 | + $label.= '_PLURAL'; |
|
| 164 | + } |
|
| 156 | 165 | |
| 157 | 166 | $ordering[$unit] = $qty.' '.L($label).'.'; |
| 158 | 167 | } |
@@ -164,27 +173,31 @@ discard block |
||
| 164 | 173 | |
| 165 | 174 | public static function time($time_string, $short=true) |
| 166 | 175 | { |
| 167 | - if ($short === true) |
|
| 168 | - $time_string = substr($time_string, 0, 5); |
|
| 176 | + if ($short === true) { |
|
| 177 | + $time_string = substr($time_string, 0, 5); |
|
| 178 | + } |
|
| 169 | 179 | return $time_string; |
| 170 | 180 | } |
| 171 | 181 | |
| 172 | 182 | public static function human_date($date_string, $short=true) |
| 173 | 183 | { |
| 174 | - if($date_string === '0000-00-00' || empty($date_string)) |
|
| 175 | - return L('MODEL_common_VALUE_EMPTY'); |
|
| 184 | + if($date_string === '0000-00-00' || empty($date_string)) { |
|
| 185 | + return L('MODEL_common_VALUE_EMPTY'); |
|
| 186 | + } |
|
| 176 | 187 | |
| 177 | - if(preg_match('/^[0-9]{4}$/', $date_string) === 1) |
|
| 178 | - return intval($date_string); |
|
| 188 | + if(preg_match('/^[0-9]{4}$/', $date_string) === 1) { |
|
| 189 | + return intval($date_string); |
|
| 190 | + } |
|
| 179 | 191 | |
| 180 | 192 | list($year, $month, $day) = explode('-',$date_string); |
| 181 | 193 | |
| 182 | 194 | $ret = intval($day).' '.L("DATETIME_CALENDAR_MONTH_$month"); |
| 183 | 195 | |
| 184 | - if($short === true && Dato::format(null, 'Y') === $year) |
|
| 185 | - return $ret; |
|
| 186 | - else |
|
| 187 | - return "$ret $year"; |
|
| 196 | + if($short === true && Dato::format(null, 'Y') === $year) { |
|
| 197 | + return $ret; |
|
| 198 | + } else { |
|
| 199 | + return "$ret $year"; |
|
| 200 | + } |
|
| 188 | 201 | } |
| 189 | 202 | |
| 190 | 203 | public static function human_month($date_string) |
@@ -9,9 +9,9 @@ discard block |
||
| 9 | 9 | namespace HexMakina\Lezer; |
| 10 | 10 | |
| 11 | 11 | use \HexMakina\LocalFS\FileSystem; |
| 12 | -use \HexMakina\Tempus\{Dato,DatoTempo,Tempo}; |
|
| 12 | +use \HexMakina\Tempus\{Dato, DatoTempo, Tempo}; |
|
| 13 | 13 | |
| 14 | -class Lezer extends \i18n{ |
|
| 14 | +class Lezer extends \i18n { |
|
| 15 | 15 | |
| 16 | 16 | private $detected_language_files = []; |
| 17 | 17 | private $detected_language_env = []; |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | $this->detect_language_env(); |
| 29 | 29 | $the_one_language = current(array_intersect($this->detect_language_files(), $this->detect_language_env())); |
| 30 | 30 | |
| 31 | - if($the_one_language) |
|
| 31 | + if ($the_one_language) |
|
| 32 | 32 | $this->setForcedLang($the_one_language); |
| 33 | 33 | |
| 34 | 34 | return $the_one_language; |
@@ -37,12 +37,12 @@ discard block |
||
| 37 | 37 | public function detect_language_files() |
| 38 | 38 | { |
| 39 | 39 | $files = FileSystem::preg_scandir(dirname($this->filePath), '/.json$/'); |
| 40 | - if(empty($files)) |
|
| 40 | + if (empty($files)) |
|
| 41 | 41 | return []; |
| 42 | 42 | |
| 43 | - $files = implode('',$files); |
|
| 43 | + $files = implode('', $files); |
|
| 44 | 44 | $res = preg_match_all('/([a-z]{3})\.json/', $files, $m); |
| 45 | - if($res) // false or 0 is none found |
|
| 45 | + if ($res) // false or 0 is none found |
|
| 46 | 46 | $this->detected_language_files = $m[1]; |
| 47 | 47 | return $this->detected_language_files; |
| 48 | 48 | } |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | public function compileFunction() |
| 51 | 51 | { |
| 52 | 52 | return '' |
| 53 | - . "function ".$this->prefix .'($string, $args=NULL) {'."\n" |
|
| 53 | + . "function ".$this->prefix.'($string, $args=NULL) {'."\n" |
|
| 54 | 54 | . ' if (!defined("'.$this->prefix.'::".$string))' |
| 55 | 55 | . ' return $string;' |
| 56 | 56 | . ' $return = constant("'.$this->prefix.'::".$string);'."\n" |
@@ -111,16 +111,16 @@ discard block |
||
| 111 | 111 | |
| 112 | 112 | public static function model_type_to_label($form_model) |
| 113 | 113 | { |
| 114 | - return L(sprintf('MODEL_%s_INSTANCE',get_class($form_model)::model_type())); |
|
| 114 | + return L(sprintf('MODEL_%s_INSTANCE', get_class($form_model)::model_type())); |
|
| 115 | 115 | } |
| 116 | 116 | public static function field_name_to_label($form_model, $field_name) |
| 117 | 117 | { |
| 118 | - return L(sprintf('MODEL_%s_FIELD_%s',(get_class($form_model))::model_type(), $field_name)); |
|
| 118 | + return L(sprintf('MODEL_%s_FIELD_%s', (get_class($form_model))::model_type(), $field_name)); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | // options['decimals'] = int |
| 122 | 122 | // options['abbrev'] = mixed: key needs to be set |
| 123 | - public static function when($event, $options=[]) |
|
| 123 | + public static function when($event, $options = []) |
|
| 124 | 124 | { |
| 125 | 125 | try { |
| 126 | 126 | $amount_of_days = DatoTempo::days_diff(new \DateTime($event), new \DateTime()); |
@@ -129,11 +129,11 @@ discard block |
||
| 129 | 129 | return __FUNCTION__.': error'; |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | - if($amount_of_days === -1) |
|
| 132 | + if ($amount_of_days === -1) |
|
| 133 | 133 | return L('DATETIME_RANGE_YESTERDAY'); |
| 134 | - elseif($amount_of_days === 0) |
|
| 134 | + elseif ($amount_of_days === 0) |
|
| 135 | 135 | return L('DATETIME_RANGE_TODAY'); |
| 136 | - elseif($amount_of_days === 1) |
|
| 136 | + elseif ($amount_of_days === 1) |
|
| 137 | 137 | return L('DATETIME_RANGE_TOMORROW'); |
| 138 | 138 | |
| 139 | 139 | |
@@ -149,49 +149,49 @@ discard block |
||
| 149 | 149 | |
| 150 | 150 | $date_diff = DatoTempo::days_diff_in_parts(abs($amount_of_days)); |
| 151 | 151 | $ordering = []; |
| 152 | - foreach($datetime_parts as $unit => $label) |
|
| 152 | + foreach ($datetime_parts as $unit => $label) |
|
| 153 | 153 | { |
| 154 | - if(!isset($date_diff[$unit])) |
|
| 154 | + if (!isset($date_diff[$unit])) |
|
| 155 | 155 | continue; |
| 156 | 156 | |
| 157 | 157 | $qty = (int)$date_diff[$unit]; |
| 158 | 158 | |
| 159 | - if($qty === 0) |
|
| 159 | + if ($qty === 0) |
|
| 160 | 160 | continue; |
| 161 | 161 | |
| 162 | - if(isset($options['abbrev'])) |
|
| 163 | - $label.= '_ABBREV'; |
|
| 164 | - elseif($qty > 1) |
|
| 165 | - $label.= '_PLURAL'; |
|
| 162 | + if (isset($options['abbrev'])) |
|
| 163 | + $label .= '_ABBREV'; |
|
| 164 | + elseif ($qty > 1) |
|
| 165 | + $label .= '_PLURAL'; |
|
| 166 | 166 | |
| 167 | 167 | $ordering[$unit] = $qty.' '.L($label).'.'; |
| 168 | 168 | } |
| 169 | 169 | $ret = (isset($amount_of_days) && $amount_of_days >= 0) ? L('DATETIME_RANGE_PREFIX_FUTURE') : L('DATETIME_RANGE_PREFIX_PAST'); |
| 170 | - $ret.= ' '.implode(' & ', array_slice($ordering, 0,2)); |
|
| 170 | + $ret .= ' '.implode(' & ', array_slice($ordering, 0, 2)); |
|
| 171 | 171 | |
| 172 | 172 | return $ret; |
| 173 | 173 | } |
| 174 | 174 | |
| 175 | - public static function time($time_string, $short=true) |
|
| 175 | + public static function time($time_string, $short = true) |
|
| 176 | 176 | { |
| 177 | 177 | if ($short === true) |
| 178 | 178 | $time_string = substr($time_string, 0, 5); |
| 179 | 179 | return $time_string; |
| 180 | 180 | } |
| 181 | 181 | |
| 182 | - public static function human_date($date_string, $short=true) |
|
| 182 | + public static function human_date($date_string, $short = true) |
|
| 183 | 183 | { |
| 184 | - if($date_string === '0000-00-00' || empty($date_string)) |
|
| 184 | + if ($date_string === '0000-00-00' || empty($date_string)) |
|
| 185 | 185 | return L('MODEL_common_VALUE_EMPTY'); |
| 186 | 186 | |
| 187 | - if(preg_match('/^[0-9]{4}$/', $date_string) === 1) |
|
| 187 | + if (preg_match('/^[0-9]{4}$/', $date_string) === 1) |
|
| 188 | 188 | return intval($date_string); |
| 189 | 189 | |
| 190 | - list($year, $month, $day) = explode('-',$date_string); |
|
| 190 | + list($year, $month, $day) = explode('-', $date_string); |
|
| 191 | 191 | |
| 192 | 192 | $ret = intval($day).' '.L("DATETIME_CALENDAR_MONTH_$month"); |
| 193 | 193 | |
| 194 | - if($short === true && Dato::format(null, 'Y') === $year) |
|
| 194 | + if ($short === true && Dato::format(null, 'Y') === $year) |
|
| 195 | 195 | return $ret; |
| 196 | 196 | else |
| 197 | 197 | return "$ret $year"; |
@@ -210,10 +210,10 @@ discard block |
||
| 210 | 210 | public static function human_seconds($seconds) |
| 211 | 211 | { |
| 212 | 212 | $hours = floor($seconds / 3600); |
| 213 | - $mins = floor(($seconds-$hours*3600) / 60); |
|
| 213 | + $mins = floor(($seconds-$hours * 3600) / 60); |
|
| 214 | 214 | $secs = floor($seconds % 60); |
| 215 | 215 | |
| 216 | - $hours_format ='%dh %dm %ds'; |
|
| 216 | + $hours_format = '%dh %dm %ds'; |
|
| 217 | 217 | return sprintf($hours_format, $hours, $mins, $secs); |
| 218 | 218 | } |
| 219 | 219 | |