今天找了下crm首页的翻译问题,找了一下午终于搞定,原来的思路不正确,以至于一开始像个苍蝇似的。
入正题:
首页控制面板的显示来源主要在modules/Home/HomeUtils.php
这个文件为每个视图选择不同的模板展示数据。
如:
$entries[$event['id']] = array(
'0' => '<a href="index.php?action=DetailView&module='.$event["module"].'&activity_mode='.$activity_type.'&record='.$event["id"].'" style="'.$font_color.';">'.$event["name"].'</a>',
'1' => getTranslatedString($event["type"], 'Calendar'),
);
就解决了翻译问题。
整理一下思路:
首页出问题:查看 index.php
$homedetails = $homeObj->getHomePageFrame();
$smarty->assign("HOMEFRAME",$homedetails);
跟踪 getHomePageFrame()函数到 include/home.php
function getHomePageFrame(){
global $adb;
global $current_user;
$querystuff ="select vtiger_homestuff.stuffid,stufftype,stufftitle,setype from vtiger_homestuff
left join vtiger_homedefault on vtiger_homedefault.stuffid=vtiger_homestuff.stuffid
where visible=0 and userid=? order by stuffsequence desc";
....................
}
getHomePageFrame()函数返回结果:
Array
(
[0] => Array
(
[Stuffid] => 31
[Stufftype] => ReportCharts
[Stufftitle] => 报表
)
[1] => Array
(
[Stuffid] => 14
[Stufftype] => Default
[Stufftitle] => 最新常见问答
)
根据其数组结构:
跟踪到模板页: Home/Homestuff.tpl
出现关键代码:
{foreach item=tablestuff from=$HOMEFRAME name="homeframe"}
{*<!-- create divs for each widget - the contents will be loaded dynamically from javascript -->*}
{include file="Home/MainHomeBlock.tpl"}
<script>
{*<!-- load contents for the widget-->*}
{if $tablestuff.Stufftype eq 'Default' && $tablestuff.Stufftitle eq 'Home Page Dashboard'|@getTranslatedString:'Home'}
fetch_homeDB({$tablestuff.Stuffid});
{elseif $tablestuff.Stufftype eq 'DashBoard'}
loadStuff({$tablestuff.Stuffid},'{$tablestuff.Stufftype}');
{elseif $tablestuff.Stufftype eq 'ReportCharts'}
loadStuff({$tablestuff.Stuffid},'{$tablestuff.Stufftype}');
{/if}
</script>
{/foreach}
loadAllWidgets(Vt_homePageWidgetInfoList, {$widgetBlockSize});
跟据上面红色字体函数:
function loadAllWidgets(widgetInfoList, batchSize){
var batchWidgetInfoList = [];
var widgetInfo = {};
for(var index =0 ; index < widgetInfoList.length;++index) {
var widgetId = widgetInfoList[index].widgetId;
var widgetType = widgetInfoList[index].widgetType;
widgetInfo[widgetId] = widgetType;
$('refresh_'+widgetId).innerHTML=$('vtbusy_homeinfo').innerHTML;
batchWidgetInfoList.push(widgetInfoList[index]);
if((index > 0 && (index+1) % batchSize == 0) || index+1 == widgetInfoList.length) {
new Ajax.Request(
'index.php',{
queue: {position: 'end', scope: 'command'},
method: 'post',
postBody:'module=Home&action=HomeAjax&file=HomeWidgetBlockList&widgetInfoList='
+ JSON.stringify(batchWidgetInfoList),
onComplete: function(response){
var responseVal=JSON.parse(response.responseText);
for(var widgetId in responseVal) {
if(responseVal.hasOwnProperty(widgetId)) {
$('stuffcont_'+widgetId).innerHTML = responseVal[widgetId];
$('refresh_'+widgetId).innerHTML='';
var widgetType = widgetInfo[widgetId];
if(widgetType=="Module" && $('more_'+widgetId).value != null &&
$('more_'+widgetId).value != '') {
$('a_'+widgetId).href = "index.php?module="+
$('more_'+widgetId).value+"&action=ListView&viewname="+
$('cvid_'+widgetId).value;
} else if(widgetType == "Default" && typeof($('a_'+widgetId)) !=
'undefined'){
if(typeof $('more_'+widgetId) != 'undefined' &&
$('more_'+widgetId).value != ''){
$('a_'+widgetId).style.display = 'block';
var url = "index.php?module="+$('more_'+widgetId).value+
"&action=index";
if($('search_qry_'+widgetId)!=''){
url += $('search_qry_'+widgetId).value;
}
$('a_'+widgetId).href = url;
}else{
$('a_'+widgetId).style.display = 'none';
}
} else if(widgetType=="RSS"){
$('a_'+widgetId).href = $('more_'+widgetId).value;
} else if(widgetType=="DashBoard"){
$('a_'+widgetId).href = "index.php?module=Dashboard&action="+
"index&type="+$('more_'+stuffid).value;
}
}
}
}
}
);
batchWidgetInfoList = [];
}
}
}
跟踪文件: Home/HomeWidgetBlockList.php
根据其返回的value找到:
$homestuff_values=$homeObj->getHomePageStuff($widgetId,$widgetType);
查找
getHomePageStuff
找出该函数在include/home.php定义
function getHomePageStuff($sid,$stuffType){
global $adb;
global $current_user;
$header=Array();
if($stuffType=="Module"){
$details=$this->getModuleFilters($sid);
}else if($stuffType=="RSS"){
$details=$this->getRssDetails($sid);
}else if($stuffType=="DashBoard" && vtlib_isModuleActive("Dashboard")){
$details=$this->getDashDetails($sid);
}else if($stuffType=="Default"){
$details=$this->getDefaultDetails($sid,'');
}
else if($stuffType=="ReportCharts" && vtlib_isModuleActive("Reports")){
$details = $this->getReportChartDetails($sid);
}
return $details;
}
根据其stuffType类型:
在include/home.php文件中找到函数:
private function getDefaultDetails($dfid,$calCnt){
global $adb;
$qry="select * from vtiger_homedefault where stuffid=?";
$result=$adb->pquery($qry, array($dfid));
$maxval=$adb->query_result($result,0,"maxentries");
$hometype=$adb->query_result($result,0,"hometype");
if($hometype=="ALVT" && vtlib_isModuleActive("Accounts")){
include_once("modules/Accounts/ListViewTop.php");
$home_values = getTopAccounts($maxval,$calCnt);
}elseif($hometype=="PLVT" && vtlib_isModuleActive("Potentials")){
if(isPermitted('Potentials','index') == "yes"){
include_once("modules/Potentials/ListViewTop.php");
$home_values=getTopPotentials($maxval,$calCnt);
}
}elseif($hometype=="QLTQ" && vtlib_isModuleActive("Quotes")){
if(isPermitted('Quotes','index') == "yes"){
require_once('modules/Quotes/ListTopQuotes.php');
$home_values=getTopQuotes($maxval,$calCnt);
}
}elseif($hometype=="HLT" && vtlib_isModuleActive("HelpDesk")){
if(isPermitted('HelpDesk','index') == "yes"){
require_once('modules/HelpDesk/ListTickets.php');
$home_values=getMyTickets($maxval,$calCnt);
}
}elseif($hometype=="GRT"){
$home_values = getGroupTaskLists($maxval,$calCnt);
}elseif($hometype=="OLTSO" && vtlib_isModuleActive("SalesOrder")){
if(isPermitted('SalesOrder','index') == "yes"){
require_once('modules/SalesOrder/ListTopSalesOrder.php');
$home_values=getTopSalesOrder($maxval,$calCnt);
}
}elseif($hometype=="ILTI" && vtlib_isModuleActive("Invoice")){
if(isPermitted('Invoice','index') == "yes"){
require_once('modules/Invoice/ListTopInvoice.php');
$home_values=getTopInvoice($maxval,$calCnt);
}
}elseif($hometype=="MNL" && vtlib_isModuleActive("Leads")){
if(isPermitted('Leads','index') == "yes"){
include_once("modules/Leads/ListViewTop.php");
$home_values=getNewLeads($maxval,$calCnt);
}
}elseif($hometype=="OLTPO" && vtlib_isModuleActive("PurchaseOrder")){
if(isPermitted('PurchaseOrder','index') == "yes"){
require_once('modules/PurchaseOrder/ListTopPurchaseOrder.php');
$home_values=getTopPurchaseOrder($maxval,$calCnt);
}
}elseif($hometype=="LTFAQ" && vtlib_isModuleActive("Faq")){
if(isPermitted('Faq','index') == "yes"){
require_once('modules/Faq/ListFaq.php');
$home_values=getMyFaq($maxval,$calCnt);
}
}elseif($hometype=="CVLVT"){
include_once("modules/CustomView/ListViewTop.php");
$home_values = getKeyMetrics($maxval,$calCnt);
}elseif($hometype == 'UA' && vtlib_isModuleActive("Calendar")){
require_once "modules/Home/HomeUtils.php";
$home_values = homepage_getUpcomingActivities($maxval, $calCnt);
}elseif($hometype == 'PA' && vtlib_isModuleActive("Calendar")){
require_once "modules/Home/HomeUtils.php";
$home_values = homepage_getPendingActivities($maxval, $calCnt);
}
if($calCnt == 'calculateCnt'){
return $home_values;
}
$return_value = Array();
if(count($home_values) > 0){
$return_value=Array('Maxentries'=>$maxval,'Details'=>$home_values);
}
return $return_value;
}
根据其数据库查寻后返回的homeType类型:
找出了上面红色字体的关键部分……
根据引用的模块文件: modules/Home/HomeUtils.php
进入函数: homepage_getPendingActivities
function homepage_getPendingActivities($maxval,$calCnt){
require_once("data/Tracker.php");
require_once("include/utils/utils.php");
require_once('include/utils/CommonUtils.php');
......................
$values = getActivityEntries($open_activity_list);
$values['ModuleName'] = 'Calendar';
$values['search_qry'] = "&action=ListView&from_homepage=pending_activities";
根据 getActivityEntries函数:
function getActivityEntries($open_activity_list){
global $current_language, $app_strings;
$current_module_strings = return_module_language($current_language, 'Calendar');
if(!empty($open_activity_list)){
$header=array();
$header[] =$current_module_strings['LBL_LIST_SUBJECT'];
$header[] =$current_module_strings['Type'];
$entries = array();
foreach($open_activity_list as $event){
$recur_date=preg_replace('/--/','',$event['recurringdate']);
if($recur_date!=""){
$event['date_start']=$event['recurringdate'];
}
$font_color_high = "color:#00DD00;";
$font_color_medium = "color:#DD00DD;";
switch ($event['priority']){
case 'High':
$font_color=$font_color_high;
break;
case 'Medium':
$font_color=$font_color_medium;
break;
default:
$font_color='';
}
if($event['type'] != 'Task' && $event['type'] != 'Emails' && $event['type'] != ''){
$activity_type = 'Events';
}else{
$activity_type = 'Task';
}
$entries[$event['id']] = array(
'0' => '<a href="index.php?action=DetailView&module='.$event["module"].'&activity_mode='.$activity_type.'&record='.$event["id"].'" style="'.$font_color.';">'.$event["name"].'</a>',
'1' => getTranslatedString($event["type"], 'Calendar'),
);
}
$values = array('noofactivities'=>count($open_activity_list),'Header'=>$header,'Entries'=>$entries);
}else{
$values = array('noofactivities'=>count($open_activity_list), 'Entries'=>
'<div class="componentName">'.$app_strings['LBL_NO_DATA'].'</div>');
}
return $values;
}
找出翻译问题的关键部分。
修改红色部分并在模块翻译文件里做好翻译字段的命名即可。
整理完成 。