From 84efbac63fb231583b1e196e864f14eaf8b04a09 Mon Sep 17 00:00:00 2001 From: wangyidong Date: Sat, 25 Feb 2023 12:10:08 +0800 Subject: [PATCH] * code for custom menu lang. --- module/custom/config.php | 3 + module/custom/model.php | 10 +++- module/dev/config.php | 3 - module/dev/control.php | 51 +++++++--------- module/dev/js/langitem.js | 2 +- module/dev/model.php | 97 +++++++++++++++++++++++++++++++ module/dev/view/header.html.php | 3 - module/dev/view/langitem.html.php | 49 +++++++++------- 8 files changed, 160 insertions(+), 58 deletions(-) diff --git a/module/custom/config.php b/module/custom/config.php index dca615e25c..122ffa70d6 100644 --- a/module/custom/config.php +++ b/module/custom/config.php @@ -72,3 +72,6 @@ $config->custom->fieldList['user']['create'] = 'dept,role,email,commiter $config->custom->fieldList['user']['edit'] = 'dept,role,email,commiter,skype,qq,mobile,phone,address,zipcode,dingding,slack,whatsapp,weixin'; $config->custom->notSetMethods = array('required', 'browsestoryconcept', 'product', 'role', 'execution'); + +global $lang; +$config->custom->commonLang = array('$URCOMMON' => $lang->URCommon, '$SRCOMMON' => $lang->SRCommon, '$PRODUCTCOMMON' => $lang->productCommon, '$PROJECTCOMMON' => $lang->projectCommon, '$EXECUTIONCOMMON' => $lang->executionCommon); diff --git a/module/custom/model.php b/module/custom/model.php index 415e3f3843..4d965d2acb 100644 --- a/module/custom/model.php +++ b/module/custom/model.php @@ -27,7 +27,15 @@ class customModel extends model $stmt = $this->dbh->query($sql); $allCustomLang = array(); - while($row = $stmt->fetch()) $allCustomLang[$row->id] = $row; + while($row = $stmt->fetch()) + { + /* Replace common lang for menu. */ + if(strpos($row->module, 'Menu') !== false or strpos($row->section, 'featureBar-') !== false or $row->section == 'mainNav') + { + $row->value = strtr($row->value, $this->config->custom->commonLang); + } + $allCustomLang[$row->id] = $row; + } } catch(PDOException $e) { diff --git a/module/dev/config.php b/module/dev/config.php index cc5ff3fdc1..89fc7acf94 100644 --- a/module/dev/config.php +++ b/module/dev/config.php @@ -255,7 +255,4 @@ if($config->vision == 'lite') $config->dev->hideMainMenu = array('execution', 'kanban', 'admin'); } -global $lang; -$config->dev->commonLang = array('$URCOMMON' => $lang->URCommon, '$SRCOMMON' => $lang->SRCommon, '$PRODUCTCOMMON' => $lang->productCommon, '$PROJECTCOMMON' => $lang->projectCommon, '$EXECUTIONCOMMON' => $lang->executionCommon); - $config->dev->linkMethods['my']['my-calendar'] = array('my', 'todo'); diff --git a/module/dev/control.php b/module/dev/control.php index 969c33de63..315881e84e 100644 --- a/module/dev/control.php +++ b/module/dev/control.php @@ -128,35 +128,26 @@ class dev extends control if($this->server->request_method == 'POST') { - $section = ''; - if($type == 'common') $section = '§ion='; - if($type == 'first') $section = '§ion=mainNav'; - if($type == 'feature') $section = str_replace('_', '-', "§ion=featureBar-{$method}"); - $this->loadModel('custom')->deleteItems("lang={$language}&module={$moduleName}&vision={$this->config->vision}{$section}"); - - $data = fixer::input('post')->get(); - if($type == 'common') unset($data->common_SRCommon, $data->common_URCommon); - foreach($data as $langKey => $customedLang) - { - if(strpos($langKey, "{$moduleName}_") !== 0) continue; - if(empty($customedLang)) continue; - - $this->custom->setItem("{$language}." . str_replace('_', '.', $langKey), $customedLang); - } - - if($type == 'common' and $this->config->custom->URSR) - { - $post = $_POST; - $_POST = array(); - if(!empty($post['common_SRCommon'])) $_POST['SRName'] = $post['common_SRCommon']; - if(!empty($post['common_URCommon'])) $_POST['URName'] = $post['common_URCommon']; - $this->custom->updateURAndSR($this->config->custom->URSR, $language); - } - + $this->dev->saveCustomedLang($common, $moduleName, $method, $language); return $this->send(array('result' => 'success', 'locate' => 'reload', 'message' => $this->lang->saveSuccess)); } - if($clientLang != $language) $this->view->currentLangs = $this->dev->getOriginalLang($type, $module, $method, $clientLang); + if($clientLang != $language) + { + $currentCommonLang = $this->config->custom->commonLang; + + $commonLang = $this->dev->getOriginalLang('common', '', '', $language); + $commonLang = array_merge($commonLang, $this->dev->getCustomedLang('common', '', '', $language)); + foreach($commonLang as $commonKey => $langValue) + { + $upperKey = '$' . strtoupper($commonKey); + if(isset($this->config->custom->commonLang[$upperKey])) $this->config->custom->commonLang[$upperKey] = $langValue; + } + + $this->view->currentLangs = $this->dev->getOriginalLang($type, $module, $method, $clientLang); + $this->view->currentCommonLang = $currentCommonLang; + } + $this->view->title = $this->lang->langItem; $this->view->type = $type; $this->view->originalLangs = $this->dev->getOriginalLang($type, $module, $method, $language); @@ -172,7 +163,7 @@ class dev extends control /** * Reset customed menu lang. * - * @param string $type common|first|second|third|feature + * @param string $type common|first|second|third|tag * @param string $module * @param string $method * @param string $language zh_cn|en|fr|de|zh_tw @@ -186,9 +177,9 @@ class dev extends control $language = str_replace('_', '-', $language); $section = ''; - if($type == 'common') $section = '§ion='; - if($type == 'first') $section = '§ion=mainNav'; - if($type == 'feature') $section = str_replace('_', '-', "§ion=featureBar-{$method}"); + if($type == 'common') $section = '§ion='; + if($type == 'first') $section = '§ion=mainNav'; + if($type == 'tag') $section = str_replace('_', '-', "§ion=featureBar-{$method}"); $this->loadModel('custom')->deleteItems("lang={$language}&module={$module}&vision={$this->config->vision}{$section}"); if($type == 'common' and $this->config->custom->URSR) { diff --git a/module/dev/js/langitem.js b/module/dev/js/langitem.js index 9296eb11bb..ff5961478d 100644 --- a/module/dev/js/langitem.js +++ b/module/dev/js/langitem.js @@ -123,7 +123,7 @@ $(function() { var target = $(e.target); if (target.attr('data-has-children') === 'true') return; - self.location.href = createLink('dev', 'langItem', 'type=' + type + '&module=' + target.attr('data-module') + '&method=' + target.attr('data-method')); + self.location.href = createLink('dev', 'langItem', 'type=' + type + '&module=' + target.attr('data-module') + '&method=' + target.attr('data-method') + '&language=' + language); }) } diff --git a/module/dev/model.php b/module/dev/model.php index aa918b2e87..31d253e3ff 100644 --- a/module/dev/model.php +++ b/module/dev/model.php @@ -793,4 +793,101 @@ class devModel extends model return $linksTitle; } + + /** + * Parse lang that with commonLang. + * + * @param string $lang + * @access public + * @return string|array + */ + public function parseCommonLang($lang) + { + if(empty($lang)) return $lang; + + $reg = implode('|', str_replace('$', '\$', array_keys($this->config->custom->commonLang))); + if(!preg_match("/($reg)/", $lang)) return $lang; + + $lang = preg_replace("/($reg)/", '$$$1$$', $lang); + $subLangs = array_filter(explode('$$', $lang)); + + return $subLangs; + } + + /** + * Check original lang changed. + * + * @param string|array $defaultValue + * @param string|array $customedLang + * @access public + * @return bool + */ + public function isOriginalLangChanged($defaultValue, $customedLang) + { + if(empty($customedLang)) return false; + if(!is_array($defaultValue) and !is_array($customedLang)) return false; + if(!is_array($defaultValue) and is_array($customedLang)) return true; + if(!is_array($customedLang) or count($defaultValue) != count($customedLang)) return true; + + $commonLang = $this->config->custom->commonLang; + foreach($defaultValue as $i => $subLang) + { + if(!isset($customedLang[$i])) return true; + + $customedSubLang = $customedLang[$i]; + if(!isset($commonLang[$subLang]) and isset($commonLang[$customedSubLang])) return true; + if(isset($commonLang[$subLang]) and !isset($commonLang[$customedSubLang])) return true; + if(isset($commonLang[$subLang]) and $subLang != $customedSubLang) return true; + } + return false; + } + + /** + * Save customed lang. + * + * @param string $type common|first|second|third|tag + * @param string $moduleName + * @param string $method + * @param string $language zh-cn|zh-tw|en|fr|de + * @access public + * @return void + */ + public function saveCustomedLang($type, $moduleName, $method, $language) + { + $section = ''; + if($type == 'common') $section = '§ion='; + if($type == 'first') $section = '§ion=mainNav'; + if($type == 'tag') $section = str_replace('_', '-', "§ion=featureBar-{$method}"); + $this->loadModel('custom')->deleteItems("lang={$language}&module={$moduleName}&vision={$this->config->vision}{$section}"); + + $data = fixer::input('post')->get(); + if($type == 'common') unset($data->common_SRCommon, $data->common_URCommon); + foreach($data as $langKey => $customedLang) + { + if(strpos($langKey, "{$moduleName}_") !== 0) continue; + if(is_array($customedLang)) + { + $isCustomed = false; + foreach($customedLang as $subLang) + { + if(!isset($this->config->custom->commonLang[$subLang]) and !empty($subLang)) $isCustomed = true; + } + $customedLang = $isCustomed ? implode(common::checkNotCN() ? ' ' : '', $customedLang) : ''; + } + if(empty($customedLang)) continue; + + $this->custom->setItem("{$language}." . str_replace('_', '.', $langKey), $customedLang); + } + + if($type == 'common' and $this->config->custom->URSR) + { + $post = $_POST; + $_POST = array(); + if(!empty($post['common_SRCommon'])) $_POST['SRName'] = $post['common_SRCommon']; + if(!empty($post['common_URCommon'])) $_POST['URName'] = $post['common_URCommon']; + $this->custom->updateURAndSR($this->config->custom->URSR, $language); + + $_POST = $post; + } + } } diff --git a/module/dev/view/header.html.php b/module/dev/view/header.html.php index bca5b7c33b..22553cad6e 100644 --- a/module/dev/view/header.html.php +++ b/module/dev/view/header.html.php @@ -1,7 +1,4 @@ getModuleRoot() . 'common/view/header.html.php';?> - diff --git a/module/dev/view/langitem.html.php b/module/dev/view/langitem.html.php index b973d767ec..2641cfcab0 100644 --- a/module/dev/view/langitem.html.php +++ b/module/dev/view/langitem.html.php @@ -10,12 +10,13 @@ * @link http://www.zentao.net */ ?> + dev->navTypes); ?> - +