From 2bfd19267adacd0d26aa480cdf0d81ded0d6af03 Mon Sep 17 00:00:00 2001 From: PPPSCN <35696959@qq.com> Date: Sat, 16 Feb 2019 19:51:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96CRUD=E7=94=9F=E6=88=90?= =?UTF-8?q?=E7=9A=84lang=E6=96=87=E4=BB=B6=E2=80=94=E2=80=94=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E7=BE=8E=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/command/Crud.php | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/application/admin/command/Crud.php b/application/admin/command/Crud.php index d5e5650c..fdf0997b 100755 --- a/application/admin/command/Crud.php +++ b/application/admin/command/Crud.php @@ -116,6 +116,11 @@ class Crud extends Command */ protected $editorClass = 'editor'; + /** + * langList的key最长字节数 + */ + protected $fieldMaxLen = 0; + protected function configure() { $this @@ -730,6 +735,15 @@ class Crud extends Command $editList = implode("\n", array_filter($editList)); $javascriptList = implode(",\n", array_filter($javascriptList)); $langList = implode(",\n", array_filter($langList)); + //数组等号对齐 + $langList = array_filter(explode(",\n", $langList . ",\n")); + foreach ($langList as &$line) { + if (preg_match("/^\s+'([^']+)'\s*=>\s*'([^']+)'\s*/is", $line, $matches)) { + $line = " '{$matches[1]}'" . str_pad('=>', ($this->fieldMaxLen - strlen($matches[1]) + 3), ' ', STR_PAD_LEFT) . " '{$matches[2]}'"; + } + } + unset($line); + $langList = implode(",\n", array_filter($langList)). ","; //表注释 $tableComment = $modelTableInfo['Comment']; @@ -1072,6 +1086,7 @@ EOD; { if ($content || !Lang::has($field)) { $itemArr = []; + $this->fieldMaxLen = strlen($field) > $this->fieldMaxLen ? strlen($field) : $this->fieldMaxLen; $content = str_replace(',', ',', $content); if (stripos($content, ':') !== false && stripos($content, ',') && stripos($content, '=') !== false) { list($fieldLang, $item) = explode(':', $content); @@ -1081,6 +1096,7 @@ EOD; if (count($valArr) == 2) { list($key, $value) = $valArr; $itemArr[$field . ' ' . $key] = $value; + $this->fieldMaxLen = strlen($field . ' ' . $key) > $this->fieldMaxLen ? strlen($field . ' ' . $key) : $this->fieldMaxLen; } } } else { @@ -1088,7 +1104,7 @@ EOD; } $resultArr = []; foreach ($itemArr as $k => $v) { - $resultArr[] = " '" . mb_ucfirst($k) . "' => '{$v}'"; + $resultArr[] = " '" . mb_ucfirst($k) . "' => '{$v}'"; } return implode(",\n", $resultArr); } else { @@ -1129,7 +1145,7 @@ EOD; } $stringArr[] = "'" . $k . "' => " . ($is_var ? $v : "'{$v}'"); } - return implode(",", $stringArr); + return implode(", ", $stringArr); } protected function getItemArray($item, $field, $comment)