* finish task #5833.
This commit is contained in:
+2
-1
@@ -9,8 +9,9 @@ CREATE TABLE `zt_translation` (
|
||||
`translationTime` datetime NOT NULL,
|
||||
`reviewer` char(30) NOT NULL,
|
||||
`reviewTime` datetime NOT NULL,
|
||||
`reason` text NOT NULL,
|
||||
`version` varchar(20) NOT NULL,
|
||||
`mode` varchar(20) NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `lang_module_key_mode` (`lang`,`module`,`key`,`mode`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||
) ENGINE=MyISAM AUTO_INCREMENT=5216 DEFAULT CHARSET=utf8
|
||||
|
||||
@@ -33,8 +33,28 @@ class translate extends control
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$this->view->title = $this->lang->translate->common;
|
||||
$this->view->position[] = $this->lang->translate->common;
|
||||
$itemCount = $this->translate->getLangItemCount();
|
||||
$progress = $this->translate->getProgress();
|
||||
$finishedLangs = $translatingLangs = array();
|
||||
foreach($this->config->translate->defaultLang as $defaultLang) $finishedLangs[$defaultLang] = $this->config->langs[$defaultLang];
|
||||
foreach($progress as $translateLang => $data)
|
||||
{
|
||||
if($data->progress == 1)
|
||||
{
|
||||
$finishedLangs[$translateLang] = $this->config->langs[$translateLang];
|
||||
}
|
||||
else
|
||||
{
|
||||
$data->name = $this->config->langs[$translateLang];
|
||||
$translatingLangs[$translateLang] = $data;
|
||||
}
|
||||
}
|
||||
|
||||
$this->view->title = $this->lang->translate->common;
|
||||
$this->view->position[] = $this->lang->translate->common;
|
||||
$this->view->finishedLangs = $finishedLangs;
|
||||
$this->view->translatingLangs = $translatingLangs;
|
||||
$this->view->itemCount = $itemCount;
|
||||
$this->display();
|
||||
}
|
||||
|
||||
@@ -93,8 +113,6 @@ class translate extends control
|
||||
$this->view->modules = $this->translate->getModules();
|
||||
$this->view->language = $language;
|
||||
|
||||
foreach($this->lang->dev->endGroupList as $group => $groupName) $this->lang->dev->groupList[$group] = $groupName;
|
||||
|
||||
$this->display();
|
||||
}
|
||||
|
||||
@@ -108,29 +126,39 @@ class translate extends control
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function module($language, $module = '', $referLang = 'en')
|
||||
public function module($language, $module = '', $referLang = '')
|
||||
{
|
||||
$modules = $this->translate->getModules();
|
||||
if(empty($module)) $module = current($modules);
|
||||
$moduleGroup = $this->translate->getModules();
|
||||
if(empty($module))
|
||||
{
|
||||
$group = current($this->lang->dev->groupList);
|
||||
$module = current($moduleGroup[$group]);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach($moduleGroup as $group => $modules)
|
||||
{
|
||||
if(in_array($module, $modules)) break;
|
||||
}
|
||||
}
|
||||
if(empty($referLang))
|
||||
{
|
||||
$langs = json_decode($this->config->global->langs, true);
|
||||
$referLang = $langs[$language]['reference'];
|
||||
}
|
||||
if($_POST)
|
||||
{
|
||||
$this->translate->addTranslation($zentaoVersion, $language, $module);
|
||||
if(dao::isError()) die(js::error(dao::getError()));
|
||||
die(js::locate(inlink('showLang', "zentaoVersion=$zentaoVersion&language=$language&module=$module&consultLang=$consultLang"), 'parent'));
|
||||
}
|
||||
$filePath = $this->translate->getLangFilePath($zentaoVersion, $consultLang, $module);
|
||||
if(file_exists($filePath)) include($filePath);
|
||||
|
||||
$this->view->percents = $this->translate->getPercents($zentaoVersion, $language);
|
||||
$this->view->modules = $modules;
|
||||
$this->view->module = $module;
|
||||
$this->view->referItems = $this->translate->getModuleLangs($module, $referLang);
|
||||
$this->view->translations = $this->translate->getTranslations($language, $module);
|
||||
$this->view->moduleGroup = $moduleGroup;
|
||||
$this->view->currentModule = $module;
|
||||
$this->view->currentGroup = $group;
|
||||
$this->view->language = $language;
|
||||
$this->view->zentaoVersion = $zentaoVersion;
|
||||
$this->view->consultLang = $consultLang;
|
||||
$this->view->moduleLangs = $this->translate->untieModuleLang($lang);
|
||||
$this->view->translations = $this->translate->getTranslations($zentaoVersion, $language, $module);
|
||||
|
||||
unset($lang);
|
||||
$this->display();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
#mainMenu{font-size:16px;padding:5px 0px;}
|
||||
.panel{margin-bottom:0px; border:0px;}
|
||||
.panel .panel-body{padding-bottom:5px;}
|
||||
.panel .text-progress{color:#999;}
|
||||
.panel p{padding-bottom:5px;}
|
||||
.item .pull-right{color:#999;}
|
||||
@@ -15,9 +15,25 @@ $lang->translate->chooseModule = '选择翻译模块';
|
||||
|
||||
$lang->translate->name = '语言名称';
|
||||
$lang->translate->code = '代号';
|
||||
$lang->translate->key = '键';
|
||||
$lang->translate->reference = '参考语言';
|
||||
$lang->translate->status = '状态';
|
||||
$lang->translate->refreshPage = '刷新';
|
||||
|
||||
$lang->translate->builtIn = '内置语音';
|
||||
$lang->translate->finished = '翻译完成';
|
||||
$lang->translate->progress = '完成 %s';
|
||||
|
||||
$lang->translate->finishedLang = '已经完成的语言';
|
||||
$lang->translate->translatingLang = '正在翻译的语言';
|
||||
$lang->translate->allItems = '所有的语言条目数:%s条';
|
||||
|
||||
$lang->translate->statusList['waiting'] = '未翻译';
|
||||
$lang->translate->statusList['translated'] = '已翻译';
|
||||
$lang->translate->statusList['reviewed'] = '已评审';
|
||||
$lang->translate->statusList['rejected'] = '已拒绝';
|
||||
$lang->translate->statusList['changed'] = '已改变';
|
||||
|
||||
$lang->translate->notice = new stdclass();
|
||||
$lang->translate->notice->failDirPriv = "目录没有写入权限,请修改权限。<br /><code>%s</code>";
|
||||
$lang->translate->notice->failCopyFile = "复制文件%s到%s失败,请检查权限!";
|
||||
|
||||
+72
-61
@@ -23,13 +23,14 @@ class translateModel extends model
|
||||
$langs[$data->code] = $data;
|
||||
$this->loadModel('setting')->setItem('system.common.global.langs', json_encode($langs));
|
||||
|
||||
foreach(glob($this->app->getModuleRoot() . '*') as $modulePath)
|
||||
$modules = glob($this->app->getModuleRoot() . '*');
|
||||
foreach($modules as $modulePath)
|
||||
{
|
||||
$moduleName = basename($modulePath);
|
||||
$mainLangFile = $modulePath . DS . 'lang' . DS . $data->reference . '.php';
|
||||
$this->initModuleLang($moduleName, $data->code);
|
||||
if(file_exists($mainLangFile))
|
||||
{
|
||||
$this->initLangByFile($mainLangFile, $moduleName, $data->code);
|
||||
$targetFile = $modulePath . DS . 'lang' . DS . $data->code . '.php';
|
||||
if(!copy($mainLangFile, $targetFile)) dao::$errors['message'][] = sprintf($this->lang->translate->notice->failCopyFile, $mainLangFile, $targetFile);
|
||||
}
|
||||
@@ -38,11 +39,10 @@ class translateModel extends model
|
||||
if(is_dir($extLangPath))
|
||||
{
|
||||
mkdir($modulePath . DS . 'ext' . DS . 'lang' . DS . $data->code);
|
||||
foreach(glob($extLangPath . DS . '*.php') as $extLangFile)
|
||||
$extLangFiles = glob($extLangPath . DS . '*.php');
|
||||
foreach($extLangFiles as $extLangFile)
|
||||
{
|
||||
$fileName = basename($extLangFile);
|
||||
$this->initLangByFile($extLangFile, $moduleName, $data->code);
|
||||
$targetFile = $modulePath . DS . 'ext' . DS . 'lang' . DS . $data->code . DS . $fileName;
|
||||
$targetFile = $modulePath . DS . 'ext' . DS . 'lang' . DS . $data->code . DS . basename($extLangFile);
|
||||
if(!copy($extLangPath, $targetFile)) dao::$errors['message'][] = sprintf($this->lang->translate->notice->failCopyFile, $extLangFile, $targetFile);
|
||||
}
|
||||
}
|
||||
@@ -51,18 +51,18 @@ class translateModel extends model
|
||||
return true;
|
||||
}
|
||||
|
||||
public function initLangByFile($fileName, $moduleName, $langCode)
|
||||
public function initModuleLang($moduleName, $langCode)
|
||||
{
|
||||
$flow = $this->config->global->flow;
|
||||
$now = helper::now();
|
||||
$initLangs = $this->getActiveItems($fileName);
|
||||
$initLangs = $this->getModuleLangs($moduleName, $langCode);
|
||||
foreach($initLangs as $key => $value)
|
||||
{
|
||||
$translation = new stdclass();
|
||||
$translation->lang = $langCode;
|
||||
$translation->module = $moduleName;
|
||||
$translation->key = $key;
|
||||
$translation->value = $value;
|
||||
$translation->value = trim($value, ';');
|
||||
$translation->status = 'waiting';
|
||||
$translation->version = $this->config->version;
|
||||
$translation->translator = $this->app->user->account;
|
||||
@@ -72,7 +72,23 @@ class translateModel extends model
|
||||
}
|
||||
}
|
||||
|
||||
public function getActiveItems($fileName)
|
||||
public function getModuleLangs($moduleName, $langCode)
|
||||
{
|
||||
$modulePath = $this->app->getModuleRoot() . $moduleName;
|
||||
$mainLangFile = $modulePath . "/lang/{$langCode}.php";
|
||||
$langItems = array();
|
||||
if(file_exists($mainLangFile)) $langItems += $this->getActiveItemsByFile($mainLangFile);
|
||||
|
||||
$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);
|
||||
}
|
||||
return $langItems;
|
||||
}
|
||||
|
||||
public function getActiveItemsByFile($fileName)
|
||||
{
|
||||
$lines = file($fileName);
|
||||
$flow = $this->config->global->flow;
|
||||
@@ -83,8 +99,12 @@ class translateModel extends model
|
||||
foreach($lines as $i => $line)
|
||||
{
|
||||
$line = trim($line);
|
||||
if(empty($line)) continue;
|
||||
if(strpos($line, '$lang->menuOrder') === 0) continue;
|
||||
if(strpos($line, 'if(') !== false and trim($lines[$i + 1]) == '{')
|
||||
if(strpos($line, 'include') === 0 or strpos($line, 'global') === 0) continue;
|
||||
if(strpos($line, 'unset(') !== false) continue;
|
||||
if(strpos($line, '/*') === 0 or strpos($line, '//') === 0 or strpos($line, '<?php') === 0) continue;
|
||||
if(strpos($line, 'if') !== false and trim($lines[$i + 1]) == '{')
|
||||
{
|
||||
$inCondition = true;
|
||||
$level ++;
|
||||
@@ -99,12 +119,20 @@ class translateModel extends model
|
||||
$inFlow = true;
|
||||
}
|
||||
}
|
||||
if(strpos($line, '$lang') === 0 and strpos($line, '=') !== false and $inFlow)
|
||||
if($line == '{' or $line == '}' or strpos($line, 'if') === 0 or strpos($line, 'else') === 0) continue;
|
||||
if($inFlow)
|
||||
{
|
||||
$position = strpos($line, '=');
|
||||
$key = trim(substr($line, 0, $position));
|
||||
$value = trim(trim(substr($line, $position + 1)), ';');
|
||||
$items[$key] = $value;
|
||||
if(strpos($line, '$lang') === 0 and strpos($line, '=') !== false)
|
||||
{
|
||||
$position = strpos($line, '=');
|
||||
$key = trim(substr($line, 0, $position));
|
||||
$value = trim(trim(substr($line, $position + 1)), ';');
|
||||
$items[$key] = $value;
|
||||
}
|
||||
elseif(isset($key) and strpos($key, '$lang') === 0)
|
||||
{
|
||||
$items[$key] .= "\n" . $line;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
@@ -112,8 +140,9 @@ class translateModel extends model
|
||||
|
||||
public function checkDirPriv()
|
||||
{
|
||||
$cmd = '';
|
||||
foreach(glob($this->app->getModuleRoot() . '*') as $modulePath)
|
||||
$cmd = '';
|
||||
$modules = glob($this->app->getModuleRoot() . '*');
|
||||
foreach($modules as $modulePath)
|
||||
{
|
||||
if(is_dir($modulePath . '/lang') and !is_writable($modulePath . '/lang')) $cmd .= "chmod 777 {$modulePath}/lang <br />";
|
||||
if(is_dir($modulePath . '/ext/lang') and !is_writable($modulePath . '/ext/lang')) $cmd .= "chmod -R 777 {$modulePath}/ext/lang <br />";
|
||||
@@ -124,6 +153,8 @@ class translateModel extends model
|
||||
public function getModules()
|
||||
{
|
||||
$this->loadModel('dev');
|
||||
foreach($this->lang->dev->endGroupList as $group => $groupName) $this->lang->dev->groupList[$group] = $groupName;
|
||||
|
||||
$moduleList = glob($this->app->getModuleRoot() . '*');
|
||||
$modules = array();
|
||||
foreach($moduleList as $module)
|
||||
@@ -133,50 +164,31 @@ class translateModel extends model
|
||||
$group = zget($this->config->dev->group, $module, 'other');
|
||||
$modules[$group][] = $module;
|
||||
}
|
||||
|
||||
return $modules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get lang file path.
|
||||
*
|
||||
* @param string $zentaoVersion
|
||||
* @param string $language
|
||||
* @param string $module
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function getLangFilePath($zentaoVersion, $language, $module)
|
||||
public function getLangItemCount()
|
||||
{
|
||||
$language = str_replace('_', '-', $language);
|
||||
$langPath = dirname(__FILE__) . "/zentaoLangs/module$zentaoVersion/";
|
||||
return $langPath . $module . "/lang/$language.php";
|
||||
$moduleGroups = $this->getModules();
|
||||
$moduleRoot = $this->app->getModuleRoot();
|
||||
$itemCount = 0;
|
||||
foreach($moduleGroups as $group => $modules)
|
||||
{
|
||||
foreach($modules as $module)
|
||||
{
|
||||
$items = $this->getModuleLangs($module, 'zh-cn');
|
||||
$itemCount += count($items);
|
||||
}
|
||||
}
|
||||
return $itemCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get language percents
|
||||
*
|
||||
* @param string $version
|
||||
* @param string $language
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function getPercents($version, $language = '')
|
||||
public function getProgress()
|
||||
{
|
||||
if(empty($language))
|
||||
{
|
||||
$langPercents = array();
|
||||
$allPercents = $this->dao->select('*')->from(TABLE_LANGUAGELOG)->where('version')->eq($version)->fetchGroup('language', 'module', false);
|
||||
$modules = $this->getModules($version);
|
||||
$moduleNum = count($modules);
|
||||
foreach($allPercents as $lang => $percents)
|
||||
{
|
||||
$sum = 0;
|
||||
foreach($percents as $percent) $sum += $percent->percent;
|
||||
$langPercents[$lang] = round($sum / $moduleNum, 2) . '%';
|
||||
}
|
||||
return $langPercents;
|
||||
}
|
||||
return $this->dao->select('*')->from(TABLE_LANGUAGELOG)->where('version')->eq($version)->andWhere('language')->eq($language)->fetchAll('module', false);
|
||||
$langs = $this->dao->select("`lang`,sum(if((status != 'waiting'),1,0)) as waitItems, count(*) as count")->from(TABLE_TRANSLATION)->groupBy('`lang`')->fetchAll('lang');
|
||||
foreach($langs as $lang => $data) $data->progress = round($data->waitItems / $data->count, 3);
|
||||
return $langs;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -189,15 +201,14 @@ class translateModel extends model
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function getTranslations($version, $language, $module = '', $langKeys = array())
|
||||
public function getTranslations($language, $module = '', $langKeys = array())
|
||||
{
|
||||
return $this->dao->select('id, account, langKey, translation, vote')->from(TABLE_TRANSLATE)
|
||||
->where('version')->eq($version)
|
||||
->andWhere('language')->eq($language)
|
||||
return $this->dao->select('id,lang,`key`,`value`,status')->from(TABLE_TRANSLATION)
|
||||
->where('lang')->eq($language)
|
||||
->beginIF(!empty($module))->andWhere('module')->eq($module)->fi()
|
||||
->beginIF(!empty($langKeys))->andWhere('langKey')->in($langKeys)->fi()
|
||||
->orderBy('vote desc, id asc')
|
||||
->fetchGroup('langKey', 'translation', false);
|
||||
->orderBy('id asc')
|
||||
->fetchAll('key');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
<?php include '../../common/view/header.html.php';?>
|
||||
<div id='mainContent' class='main-content'>
|
||||
<div class='main-header'>
|
||||
<h2><?php echo $lang->dev->moduleList;?></h2>
|
||||
<h2><?php echo $lang->dev->moduleList . ' > ' . $lang->translate->chooseModule;?></h2>
|
||||
</div>
|
||||
<table class='table table-form'>
|
||||
<?php foreach($lang->dev->groupList as $group => $groupName):?>
|
||||
|
||||
@@ -1,37 +1,43 @@
|
||||
<?php include '../../common/view/header.html.php';?>
|
||||
<div class='row'>
|
||||
<div class='u-24-5'>
|
||||
<div class='cont-left'>
|
||||
<div class='box-title'><?php echo $lang->translate->langVersion?></div>
|
||||
<div class='box-content'>
|
||||
<ul><?php foreach($lang->translate->zentaoVersions as $key => $version) echo '<li>' . html::a(inlink('index', "zentaoVersion=$key"), $version) . '</li>';?></ul>
|
||||
<div class='center-block mw-800px'>
|
||||
<div id="mainMenu" class="clearfix"><?php printf($lang->translate->allItems, $itemCount);?></div>
|
||||
<div class='row'>
|
||||
<div class='col-sm-6'>
|
||||
<div class='panel'>
|
||||
<div class='panel-heading'>
|
||||
<div class='panel-title'><?php echo $lang->translate->finishedLang;?></div>
|
||||
<div class='panel-actions'><?php echo "(" . count($finishedLangs) . ")";?></div>
|
||||
</div>
|
||||
<div class='panel-body'>
|
||||
<?php foreach($finishedLangs as $langKey => $langName):?>
|
||||
<div class='item'>
|
||||
<div class='pull-right'><?php echo in_array($langKey, $config->translate->defaultLang) ? $lang->translate->builtIn : $lang->translate->finished;?></div>
|
||||
<h4><?php echo $langName;?></h4>
|
||||
</div>
|
||||
<?php endforeach;?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class='col-sm-6'>
|
||||
<div class='panel'>
|
||||
<div class='panel-heading'>
|
||||
<div class='panel-title'><?php echo $lang->translate->translatingLang;?></div>
|
||||
<div class='panel-actions'><?php echo "(" . count($translatingLangs) . ")";?></div>
|
||||
</div>
|
||||
<div class='panel-body'>
|
||||
<table class='table table-form'>
|
||||
<?php foreach($translatingLangs as $langKey => $data):?>
|
||||
<tr>
|
||||
<th class='text-left'><?php echo $data->name;?></th>
|
||||
<td class='text-progress text-center'><?php printf($lang->translate->progress, ($data->progress * 100) . '%');?></td>
|
||||
<td class='w-50px'><?php echo html::a(inlink('chooseModule', "language=$langKey"), $lang->translate->common, '', "class='btn btn-sm'");?></td>
|
||||
</tr>
|
||||
<?php endforeach;?>
|
||||
</table>
|
||||
</div>
|
||||
<p class='text-center'><?php echo html::a(inlink('addLang'), $lang->translate->addLang, '', "class='btn btn-primary'");?></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class='u-24-19'>
|
||||
<table class='table-1 f-14px' align='center'>
|
||||
<?php if(empty($zentaoVersion)):?>
|
||||
<tr><td class='red'><?php echo $lang->translate->notice->noVersion?></td></tr>
|
||||
<?php else:?>
|
||||
<?php
|
||||
$i = 0;
|
||||
foreach($lang->translate->langs as $key => $language)
|
||||
{
|
||||
if($i % $config->translate->columnNum == 0) echo '<tr>';
|
||||
echo '<td class="pd-5px">';
|
||||
echo html::a(inlink('showLang', "zentaoversion=$zentaoVersion&language=$key"), $language);
|
||||
echo "<span class='f-right'>";
|
||||
echo isset($percents[$key]) ? $percents[$key] : (in_array($key, $config->translate->defaultLang) ? '100%' : '0%');
|
||||
echo ' ' . html::a(inlink('translate', "zentaoversion=$zentaoVersion&language=$key"), $lang->translate->translate) . ' ';
|
||||
echo html::a(inlink('download', "zentaoversion=$zentaoVersion&language=$key"), $lang->translate->download);
|
||||
echo '</span></td>';
|
||||
$i++;
|
||||
if($i % $config->translate->columnNum == 0) echo '</tr>';
|
||||
}
|
||||
if($i % $config->translate->columnNum != 0) echo '</tr>';
|
||||
?>
|
||||
<?php endif;?>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<?php include '../../common/view/footer.html.php';?>
|
||||
|
||||
Reference in New Issue
Block a user