diff --git a/db/update11.5.sql b/db/update11.5.1.sql similarity index 89% rename from db/update11.5.sql rename to db/update11.5.1.sql index 79762070fe..a0b50128e1 100644 --- a/db/update11.5.sql +++ b/db/update11.5.1.sql @@ -4,6 +4,7 @@ CREATE TABLE `zt_translation` ( `module` varchar(30) NOT NULL, `key` varchar(100) NOT NULL, `value` text NOT NULL, + `refer` text NOT NULL, `status` varchar(30) NOT NULL, `translator` char(30) NOT NULL, `translationTime` datetime NOT NULL, @@ -14,4 +15,4 @@ CREATE TABLE `zt_translation` ( `mode` varchar(20) NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `lang_module_key_mode` (`lang`,`module`,`key`,`mode`) -) ENGINE=MyISAM AUTO_INCREMENT=5216 DEFAULT CHARSET=utf8 +) ENGINE=MyISAM DEFAULT CHARSET=utf8; diff --git a/module/translate/control.php b/module/translate/control.php index 2bdef250e3..18de4317ba 100644 --- a/module/translate/control.php +++ b/module/translate/control.php @@ -33,6 +33,7 @@ class translate extends control */ public function index() { + $this->translate->compare(); $itemCount = $this->translate->getLangItemCount(); $statistics = $this->translate->getLangStatistics(); $finishedLangs = $translatingLangs = array(); @@ -261,8 +262,7 @@ class translate extends control if(!is_dir($downloadPath . "module/{$moduleName}/lang/")) mkdir($downloadPath . "module/{$moduleName}/lang/", 0777, true); if(!file_exists($modulePath . "/lang/{$language}.php") and !empty($referLang) and file_exists($modulePath . "/lang/{$referLang}.php")) { - $translations = $this->dao->select('*')->from(TABLE_TRANSLATION)->where('lang')->eq($language)->andWhere('module')->eq($moduleName)->andWhere('flow')->eq($this->config->global->flow)->fetchAll('key'); - $this->translate->buildLangFile($language, $moduleName, $translations, $referLang); + $this->translate->buildLangFile($language, $moduleName, $referLang); } if(file_exists($modulePath . "/lang/{$language}.php")) copy($modulePath . "/lang/{$language}.php", $downloadPath . "module/{$moduleName}/lang/{$language}.php"); } diff --git a/module/translate/css/index.css b/module/translate/css/index.css index 14767e94e8..e913dfbd0a 100644 --- a/module/translate/css/index.css +++ b/module/translate/css/index.css @@ -2,6 +2,8 @@ .panel{margin-bottom:0px; border:0px;} .panel .panel-body{padding-bottom:5px;} #translatingLangs .panel .panel-body{padding-right:0px;} +#translatingLangs .panel .panel-body .actions{padding:0px; width:95px;} .panel .text-progress{color:#999;} +.panel .panel-actions{top:5px;} .panel p{padding-bottom:5px;} .item .pull-right{color:#999;} diff --git a/module/translate/model.php b/module/translate/model.php index 0536362ede..5c59e24901 100644 --- a/module/translate/model.php +++ b/module/translate/model.php @@ -60,45 +60,51 @@ class translateModel extends model public function initModuleLang($moduleName, $langCode, $referLang) { - $flow = $this->config->global->flow; + $this->app->loadLang('custom'); + $flows = array_keys($this->lang->custom->workingList); $now = helper::now(); - $initLangs = $this->getModuleLangs($moduleName, $referLang); - foreach($initLangs as $key => $value) + foreach($flows as $flow) { - $translation = new stdclass(); - $translation->lang = $langCode; - $translation->module = $moduleName; - $translation->key = $key; - $translation->value = trim($value, ';'); - $translation->status = 'waiting'; - $translation->version = $this->config->version; - $translation->translator = $this->app->user->account; - $translation->translationTime = $now; - $translation->mode = $flow; - $this->dao->replace(TABLE_TRANSLATION)->data($translation)->exec(); + $initLangs = $this->getModuleLangs($moduleName, $referLang, $flow); + foreach($initLangs as $key => $value) + { + $translation = new stdclass(); + $translation->lang = $langCode; + $translation->module = $moduleName; + $translation->key = $key; + $translation->value = $value; + $translation->refer = htmlspecialchars($translation->value); + $translation->status = 'waiting'; + $translation->version = $this->config->version; + $translation->translator = $this->app->user->account; + $translation->translationTime = $now; + $translation->mode = $flow; + $this->dao->replace(TABLE_TRANSLATION)->data($translation)->exec(); + } } } - public function getModuleLangs($moduleName, $langCode) + public function getModuleLangs($moduleName, $langCode, $flow = '') { + if(empty($flow))$flow = $this->config->global->flow; $modulePath = $this->app->getModuleRoot() . $moduleName; $mainLangFile = $modulePath . "/lang/{$langCode}.php"; $langItems = array(); - if(file_exists($mainLangFile)) $langItems += $this->getActiveItemsByFile($mainLangFile); + if(file_exists($mainLangFile)) $langItems += $this->getActiveItemsByFile($mainLangFile, $flow); $extLangPath = $modulePath . DS . 'ext' . DS . 'lang' . DS . $langCode; if(is_dir($extLangPath)) { $extLangFiles = glob($extLangPath . DS . '*.php'); - foreach($extLangFiles as $extLangFile) $langItems += $this->getActiveItemsByFile($extLangFile); + foreach($extLangFiles as $extLangFile) $langItems += $this->getActiveItemsByFile($extLangFile, $flow); } return $langItems; } - public function getActiveItemsByFile($fileName) + public function getActiveItemsByFile($fileName, $flow = '') { + if(empty($flow)) $flow = $this->config->global->flow; $lines = file($fileName); - $flow = $this->config->global->flow; $inCondition = false; $inFlow = true; $level = 0; @@ -127,7 +133,7 @@ class translateModel extends model } } if($line == '{' or $line == '}' or strpos($line, 'if') === 0 or strpos($line, 'else') === 0) continue; - if($inFlow) + if($inFlow and ($flow == 'full' or ($flow != 'full' and $inCondition))) { if(strpos($line, '$lang') === 0 and strpos($line, '=') !== false) { @@ -260,6 +266,7 @@ class translateModel extends model { $dbItem = zget($dbItems, $key, ''); $value = $referItems[$key]; + $refer = $this->post->refers[$i]; $now = helper::now(); if(!empty($_POST['values'][$i])) $value = $this->post->values[$i]; if($dbItem) @@ -268,13 +275,14 @@ class translateModel extends model $translation->version = $this->config->version; if($dbItem->value != $value) { - $translation->value = $value; - $translation->status = 'translated'; - $translation->translator = $this->app->user->account; + $translation->value = $value; + $translation->refer = $refer; + $translation->status = 'translated'; + $translation->translator = $this->app->user->account; $translation->translationTime = $now; if($translation->reason) $translation->reason = ''; } - elseif(!$this->checkNeedTranslate($value) and !empty($_POST['values'][$i]) and strpos("waiting|changed", $translation->status) !== false) + elseif(!empty($_POST['values'][$i]) and strpos("waiting|changed", $translation->status) !== false) { $translation->status = 'translated'; } @@ -286,6 +294,7 @@ class translateModel extends model $translation->module = $module; $translation->key = $key; $translation->value = $value; + $translation->refer = $refer; $translation->status = 'translated'; $translation->translator = $this->app->user->account; $translation->translationTime = $now; @@ -297,14 +306,15 @@ class translateModel extends model $this->dao->delete()->from(TABLE_TRANSLATION)->where('lang')->eq($language)->andWhere('module')->eq($module)->andWhere('mode')->eq($flow)->exec(); foreach($translations as $translation) $this->dao->replace(TABLE_TRANSLATION)->data($translation)->exec(); - if(!dao::isError()) $this->buildLangFile($language, $module, $translations, $referLang); + if(!dao::isError()) $this->buildLangFile($language, $module, $referLang); } - public function buildLangFile($language, $module, $translations, $referLang) + public function buildLangFile($language, $module, $referLang) { - $moduleRoot = $this->app->getModuleRoot(); - $newLangFile = $moduleRoot . $module . "/lang/{$language}.php"; - $newContent = "app->getModuleRoot(); + $newLangFile = $moduleRoot . $module . "/lang/{$language}.php"; + $translations = $this->dao->select('*')->from(TABLE_TRANSLATION)->where('lang')->eq($language)->andWhere('module')->eq($module)->fetchGroup('mode', 'key'); + $newContent = "getTranslatedLang($mainReferLangFile, $translations) . "\n"; @@ -319,10 +329,11 @@ class translateModel extends model public function getTranslatedLang($referLang, $translations) { $lines = file($referLang); - $flow = $this->config->global->flow; $inFlow = true; $level = 0; $content = ''; + $flow = 'full'; + $flows = array_keys($translations); foreach($lines as $i => $line) { $line = trim($line); @@ -341,7 +352,16 @@ class translateModel extends model { $inCondition = true; $level ++; - if(strpos($line, 'config->global->flow') !== false and strpos($line, $flow) === false) $inFlow = false; + + $inFlow = false; + foreach($flows as $flow) + { + if(strpos($line, 'config->global->flow') !== false and strpos($line, $flow) === false) + { + $inFlow = true; + break; + } + } } if($line == '}' and $inCondition) { @@ -350,6 +370,7 @@ class translateModel extends model { $inCondition = false; $inFlow = true; + $flow = 'full'; } } if($line == '{' or $line == '}' or strpos($line, 'if') === 0 or strpos($line, 'else') === 0) @@ -365,9 +386,9 @@ class translateModel extends model { $position = strpos($line, '='); $key = trim(substr($line, 0, $position)); - if(isset($translations[$key])) + if(isset($translations[$flow][$key])) { - $translation = $translations[$key]; + $translation = $translations[$flow][$key]; $value = $translation->value; if($this->checkNeedTranslate($value) and strpos($value, 'array(') === false) { @@ -393,4 +414,79 @@ class translateModel extends model return $result; } + + public function compare() + { + $version = $this->config->version; + $translations = $this->dao->select('*')->from(TABLE_TRANSLATION)->where('version')->ne($version)->fetchAll(); + if(empty($translations)) return true; + + $translateGroups = array(); + foreach($translations as $translation) $translateGroups[$translation->lang][$translation->mode][$translation->module][$translation->key] = $translation; + + $moduleGroups = $this->getModules(); + $allModules = array(); + foreach($moduleGroups as $group => $modules) + { + foreach($modules as $module) $allModules[$module] = $module; + } + + $this->app->loadLang('custom'); + $flows = array_keys($this->lang->custom->workingList); + $langs = json_decode($this->config->global->langs, true); + $referGroups = array(); + foreach($langs as $code => $data) $referGroups[$data['reference']][$code] = $code; + foreach($referGroups as $referLang => $languages) + { + foreach($languages as $langCode) + { + $langTranslations = zget($translateGroups, $translation->lang, array()); + foreach($flows as $flow) + { + foreach($allModules as $moduleName) + { + $langItems = $this->getModuleLangs($moduleName, $referLang, $flow); + $translations = isset($langTranslations[$flow][$moduleName]) ? $langTranslations[$flow][$moduleName] : array(); + foreach($langItems as $langKey => $langValue) + { + $translation = isset($translations[$langKey]) ? $translations[$langKey] : ''; + if(empty($translation)) + { + $translation = new stdclass(); + $translation->lang = $langCode; + $translation->module = $moduleName; + $translation->key = $langKey; + $translation->value = $langValue; + $translation->refer = htmlspecialchars($langValue); + $translation->status = 'waiting'; + $translation->translator = $this->app->user->account; + $translation->translationTime = helper::now(); + $translation->version = $version; + $translation->mode = $flow; + $this->dao->replace(TABLE_TRANSLATION)->data($translation)->exec(); + } + else + { + if($langValue == $translation->refer) + { + $this->dao->update(TABLE_TRANSLATION)->set('version')->eq($version)->where('id')->eq($translation->id)->exec(); + } + elseif($langValue != $translation->refer) + { + $this->dao->update(TABLE_TRANSLATION)->set('version')->eq($version)->set('status')->eq('changed')->set('refer')->eq(htmlspecialchars($langValue))->where('id')->eq($translation->id)->exec(); + } + unset($translations[$langKey]); + } + if($translations) + { + $idList = array(); + foreach($translations as $translation) $idList[$translation->id] = $translation->id; + $this->dao->delete()->from(TABLE_TRANSLATION)->where('id')->in($idList)->exec(); + } + } + } + } + } + } + } } diff --git a/module/translate/view/index.html.php b/module/translate/view/index.html.php index 35f1542f89..c0c18953c5 100644 --- a/module/translate/view/index.html.php +++ b/module/translate/view/index.html.php @@ -35,7 +35,7 @@