mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 07:24:13 +01:00
Localization: tools to report missing entries, and build the dictionary out of a data model made with the previous format
SVN:trunk[352]
This commit is contained in:
@@ -133,7 +133,31 @@ abstract class AttributeDefinition
|
||||
public function GetNullValue() {return null;}
|
||||
public function GetCode() {return $this->m_sCode;}
|
||||
public function GetLabel() {return Dict::S('Class:'.$this->m_sHostClass.'/Attribute:'.$this->m_sCode, $this->m_sCode);}
|
||||
public function GetLabel_Obsolete()
|
||||
{
|
||||
// Written for compatibility with a data model written prior to version 0.9.1
|
||||
if (array_key_exists('label', $this->m_aParams))
|
||||
{
|
||||
return $this->m_aParams['label'];
|
||||
}
|
||||
else
|
||||
{
|
||||
return $this->GetLabel();
|
||||
}
|
||||
}
|
||||
public function GetDescription() {return Dict::S('Class:'.$this->m_sHostClass.'/Attribute:'.$this->m_sCode.'+', '');}
|
||||
public function GetDescription_Obsolete()
|
||||
{
|
||||
// Written for compatibility with a data model written prior to version 0.9.1
|
||||
if (array_key_exists('description', $this->m_aParams))
|
||||
{
|
||||
return $this->m_aParams['description'];
|
||||
}
|
||||
else
|
||||
{
|
||||
return $this->GetDescription();
|
||||
}
|
||||
}
|
||||
public function GetValuesDef() {return null;}
|
||||
public function GetPrerequisiteAttributes() {return array();}
|
||||
//public function IsSearchableStd() {return $this->Get("search_std");}
|
||||
|
||||
@@ -198,6 +198,19 @@ abstract class MetaModel
|
||||
$sStringCode = 'Class:'.$sClass;
|
||||
return Dict::S($sStringCode, $sClass);
|
||||
}
|
||||
final static public function GetName_Obsolete($sClass)
|
||||
{
|
||||
// Written for compatibility with a data model written prior to version 0.9.1
|
||||
self::_check_subclass($sClass);
|
||||
if (array_key_exists('name', self::$m_aClassParams[$sClass]))
|
||||
{
|
||||
return self::$m_aClassParams[$sClass]['name'];
|
||||
}
|
||||
else
|
||||
{
|
||||
return self::GetName($sClass);
|
||||
}
|
||||
}
|
||||
final static public function GetCategory($sClass)
|
||||
{
|
||||
self::_check_subclass($sClass);
|
||||
@@ -214,6 +227,19 @@ abstract class MetaModel
|
||||
$sStringCode = 'Class:'.$sClass.'+';
|
||||
return Dict::S($sStringCode, '');
|
||||
}
|
||||
final static public function GetClassDescription_Obsolete($sClass)
|
||||
{
|
||||
// Written for compatibility with a data model written prior to version 0.9.1
|
||||
self::_check_subclass($sClass);
|
||||
if (array_key_exists('description', self::$m_aClassParams[$sClass]))
|
||||
{
|
||||
return self::$m_aClassParams[$sClass]['description'];
|
||||
}
|
||||
else
|
||||
{
|
||||
return self::GetDescription($sClass);
|
||||
}
|
||||
}
|
||||
final static public function IsAutoIncrementKey($sClass)
|
||||
{
|
||||
self::_check_subclass($sClass);
|
||||
@@ -679,7 +705,7 @@ abstract class MetaModel
|
||||
public static function GetStateLabel($sClass, $sStateValue)
|
||||
{
|
||||
$sStateAttrCode = self::GetStateAttributeCode($sClass);
|
||||
return Dict::S("Class:$sClass/Attribute:$sStateAttrCode/Value:$sStateValue+");
|
||||
return Dict::S("Class:$sClass/Attribute:$sStateAttrCode/Value:$sStateValue", $sStateValue);
|
||||
|
||||
// I've decided the current implementation, because I need
|
||||
// to get the description as well -GetAllowedValues does not render the description,
|
||||
@@ -692,7 +718,7 @@ abstract class MetaModel
|
||||
public static function GetStateDescription($sClass, $sStateValue)
|
||||
{
|
||||
$sStateAttrCode = self::GetStateAttributeCode($sClass);
|
||||
return Dict::S("Class:$sClass/Attribute:$sStateAttrCode/Value:$sStateValue+");
|
||||
return Dict::S("Class:$sClass/Attribute:$sStateAttrCode/Value:$sStateValue+", '');
|
||||
}
|
||||
|
||||
public static function EnumTransitions($sClass, $sStateCode)
|
||||
@@ -2112,16 +2138,25 @@ abstract class MetaModel
|
||||
return $aDataDump;
|
||||
}
|
||||
|
||||
public static function MakeDictionaryTemplate()
|
||||
protected static function MakeDictEntry($sKey, $sValueFromOldSystem, $sDefaultValue, &$bNotInDico)
|
||||
{
|
||||
$sValue = Dict::S($sKey, 'x-no-nothing');
|
||||
if ($sValue == 'x-no-nothing')
|
||||
{
|
||||
$bNotInDico = true;
|
||||
$sValue = $sValueFromOldSystem;
|
||||
if (strlen($sValue) == 0)
|
||||
{
|
||||
$sValue = $sDefaultValue;
|
||||
}
|
||||
}
|
||||
return " '$sKey' => '".str_replace("'", "\\'", $sValue)."',\n";
|
||||
}
|
||||
|
||||
public static function MakeDictionaryTemplate($sModules = '', $sOutputFilter = 'NotInDictionary')
|
||||
{
|
||||
$sRes = '';
|
||||
|
||||
foreach (Dict::GetLanguages() as $sLanguageCode => $aLanguageData)
|
||||
{
|
||||
list($aMissing, $aUnexpected, $aNotTranslated, $aOK) = Dict::MakeStats($sLanguageCode, 'EN US');
|
||||
echo "<p>Stats for language: $sLanguageCode</p>\n";
|
||||
echo "<ul><li>Missing:".count($aMissing)."</li><li>Unexpected:".count($aUnexpected)."</li><li>NotTranslated:".count($aNotTranslated)."</li><li>OK:".count($aOK)."</li></ul>\n";
|
||||
}
|
||||
$sRes .= "// Dictionnay conventions\n";
|
||||
$sRes .= htmlentities("// Class:<class_name>\n");
|
||||
$sRes .= htmlentities("// Class:<class_name>+\n");
|
||||
@@ -2135,7 +2170,14 @@ abstract class MetaModel
|
||||
|
||||
// Note: I did not use EnumCategories(), because a given class maybe found in several categories
|
||||
// Need to invent the "module", to characterize the origins of a class
|
||||
$aModules = array('bizmodel', 'core/cmdb', 'gui' , 'application', 'addon/userrights');
|
||||
if (strlen($sModules) == 0)
|
||||
{
|
||||
$aModules = array('bizmodel', 'core/cmdb', 'gui' , 'application', 'addon/userrights');
|
||||
}
|
||||
else
|
||||
{
|
||||
$aModules = explode(', ', $sModules);
|
||||
}
|
||||
|
||||
$sRes .= "//////////////////////////////////////////////////////////////////////\n";
|
||||
$sRes .= "// Note: The classes have been grouped by categories: ".implode(', ', $aModules)."\n";
|
||||
@@ -2152,51 +2194,71 @@ abstract class MetaModel
|
||||
{
|
||||
if (self::IsAbstract($sClass)) continue;
|
||||
|
||||
$sRes .= "//\n";
|
||||
$sRes .= "// Class: $sClass\n";
|
||||
$sRes .= "//\n";
|
||||
$sRes .= "\n";
|
||||
$sRes .= "Dict::Add('EN US', 'English', 'English', array(\n";
|
||||
$sRes .= " 'Class:$sClass' => '".self::GetName($sClass)."',\n";
|
||||
$sRes .= " 'Class:$sClass+' => '".self::GetClassDescription($sClass)."',\n";
|
||||
$bNotInDico = false;
|
||||
|
||||
$sClassRes = "//\n";
|
||||
$sClassRes .= "// Class: $sClass\n";
|
||||
$sClassRes .= "//\n";
|
||||
$sClassRes .= "\n";
|
||||
$sClassRes .= "Dict::Add('EN US', 'English', 'English', array(\n";
|
||||
$sClassRes .= self::MakeDictEntry("Class:$sClass", self::GetName_Obsolete($sClass), $sClass, $bNotInDico);
|
||||
$sClassRes .= self::MakeDictEntry("Class:$sClass+", self::GetClassDescription_Obsolete($sClass), '', $bNotInDico);
|
||||
foreach(self::ListAttributeDefs($sClass) as $sAttCode => $oAttDef)
|
||||
{
|
||||
// Skip this attribute if not originaly defined in this class
|
||||
if (self::$m_aAttribOrigins[$sClass][$sAttCode] != $sClass) continue;
|
||||
|
||||
$sRes .= " 'Class:$sClass/Attribute:$sAttCode' => '".$oAttDef->GetLabel()."',\n";
|
||||
$sRes .= " 'Class:$sClass/Attribute:$sAttCode+' => '".$oAttDef->GetDescription()."',\n";
|
||||
$sClassRes .= self::MakeDictEntry("Class:$sClass/Attribute:$sAttCode", $oAttDef->GetLabel_Obsolete(), $sAttCode, $bNotInDico);
|
||||
$sClassRes .= self::MakeDictEntry("Class:$sClass/Attribute:$sAttCode+", $oAttDef->GetDescription_Obsolete(), '', $bNotInDico);
|
||||
if ($oAttDef instanceof AttributeEnum)
|
||||
{
|
||||
if (self::GetStateAttributeCode($sClass) == $sAttCode)
|
||||
{
|
||||
foreach (self::EnumStates($sClass) as $sStateCode => $aStateData)
|
||||
{
|
||||
$sValue = str_replace("'", "\\'", $aStateData['label']);
|
||||
$sValuePlus = str_replace("'", "\\'", $aStateData['description']);
|
||||
$sRes .= " 'Class:$sClass/Attribute:$sAttCode/Value:$sStateCode' => '$sValue',\n";
|
||||
$sRes .= " 'Class:$sClass/Attribute:$sAttCode/Value:$sStateCode+' => '$sValuePlus',\n";
|
||||
if (array_key_exists('label', $aStateData))
|
||||
{
|
||||
$sValue = $aStateData['label'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$sValue = MetaModel::GetStateLabel($sClass, $sStateCode);
|
||||
}
|
||||
if (array_key_exists('description', $aStateData))
|
||||
{
|
||||
$sValuePlus = $aStateData['description'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$sValuePlus = MetaModel::GetStateDescription($sClass, $sStateCode);
|
||||
}
|
||||
$sClassRes .= self::MakeDictEntry("Class:$sClass/Attribute:$sAttCode/Value:$sStateCode", $sValue, '', $bNotInDico);
|
||||
$sClassRes .= self::MakeDictEntry("Class:$sClass/Attribute:$sAttCode/Value:$sStateCode+", $sValuePlus, '', $bNotInDico);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach ($oAttDef->GetAllowedValues() as $sKey => $value)
|
||||
{
|
||||
$sValue = str_replace("'", "\\'", $value);
|
||||
$sRes .= " 'Class:$sClass/Attribute:$sAttCode/Value:$sKey' => '$sValue',\n";
|
||||
$sRes .= " 'Class:$sClass/Attribute:$sAttCode/Value:$sKey+' => '$sValue',\n";
|
||||
$sClassRes .= self::MakeDictEntry("Class:$sClass/Attribute:$sAttCode/Value:$sKey", $sValue, '', $bNotInDico);
|
||||
$sClassRes .= self::MakeDictEntry("Class:$sClass/Attribute:$sAttCode/Value:$sKey+", $sValue, '', $bNotInDico);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach(self::EnumStimuli($sClass) as $sStimulusCode => $oStimulus)
|
||||
{
|
||||
$sRes .= " 'Class:$sClass/Stimulus:$sStimulusCode' => '".$oStimulus->GetLabel()."',\n";
|
||||
$sRes .= " 'Class:$sClass/Stimulus:$sStimulusCode+' => '".$oStimulus->GetDescription()."',\n";
|
||||
$sClassRes .= self::MakeDictEntry("Class:$sClass/Stimulus:$sStimulusCode", $oStimulus->GetLabel_Obsolete(), '', $bNotInDico);
|
||||
$sClassRes .= self::MakeDictEntry("Class:$sClass/Stimulus:$sStimulusCode+", $oStimulus->GetDescription_Obsolete(), '', $bNotInDico);
|
||||
}
|
||||
|
||||
$sRes .= "));\n";
|
||||
$sRes .= "\n";
|
||||
$sClassRes .= "));\n";
|
||||
$sClassRes .= "\n";
|
||||
|
||||
if ($bNotInDico || ($sOutputFilter != 'NotInDictionary'))
|
||||
{
|
||||
$sRes .= $sClassRes;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $sRes;
|
||||
|
||||
@@ -50,6 +50,32 @@ class ObjectStimulus
|
||||
return Dict::S('Class:'.$this->m_sHostClass.'/Stimulus:'.$this->m_sCode.'+', '');
|
||||
}
|
||||
|
||||
public function GetLabel_Obsolete()
|
||||
{
|
||||
// Written for compatibility with a data model written prior to version 0.9.1
|
||||
if (array_key_exists('label', $this->m_aParams))
|
||||
{
|
||||
return $this->m_aParams['label'];
|
||||
}
|
||||
else
|
||||
{
|
||||
return $this->GetLabel();
|
||||
}
|
||||
}
|
||||
|
||||
public function GetDescription_Obsolete()
|
||||
{
|
||||
// Written for compatibility with a data model written prior to version 0.9.1
|
||||
if (array_key_exists('description', $this->m_aParams))
|
||||
{
|
||||
return $this->m_aParams['description'];
|
||||
}
|
||||
else
|
||||
{
|
||||
return $this->GetDescription();
|
||||
}
|
||||
}
|
||||
|
||||
// obsolete- public function Get($sParamName) {return $this->m_aParams[$sParamName];}
|
||||
|
||||
// Note: I could factorize this code with the parameter management made for the AttributeDef class
|
||||
|
||||
@@ -263,7 +263,8 @@ function printMenu($sConfigFile)
|
||||
echo "<h4>Target database: $sConfigFile</h4>\n";
|
||||
echo "<p>$sClassCount classes referenced in the model</p>\n";
|
||||
echo "<ul>";
|
||||
echo " <li><a href=\"$sUrl&todo=checkdictionary\">Dictionary</a></li>";
|
||||
echo " <li><a href=\"$sUrl&todo=checkdictionary&categories=bizmodel&outputfilter=NotInDictionary\">Dictionary - missing entries (EN US)</a></li>";
|
||||
echo " <li><a href=\"$sUrl&todo=dictionarystats\">Dictionary - statistics by language</a></li>";
|
||||
echo " <li><a href=\"$sUrl&todo=checkmodel\">Biz model consistency</a></li>";
|
||||
echo " <li><a href=\"$sUrl&todo=showzlists\">Show ZLists</a></li>";
|
||||
echo " <li><a href=\"$sUrl&todo=showbizmodel\">Browse business model</a></li>";
|
||||
@@ -472,10 +473,21 @@ else
|
||||
printMenu($sConfigFile);
|
||||
echo $sRes;
|
||||
break;
|
||||
case "dictionarystats":
|
||||
echo "Dictionary: statistics by language<br/>\n";
|
||||
foreach (Dict::GetLanguages() as $sLanguageCode => $aLanguageData)
|
||||
{
|
||||
list($aMissing, $aUnexpected, $aNotTranslated, $aOK) = Dict::MakeStats($sLanguageCode, 'EN US');
|
||||
echo "<p>Stats for language: $sLanguageCode</p>\n";
|
||||
echo "<ul><li>Missing:".count($aMissing)."</li><li>Unexpected:".count($aUnexpected)."</li><li>NotTranslated:".count($aNotTranslated)."</li><li>OK:".count($aOK)."</li></ul>\n";
|
||||
}
|
||||
break;
|
||||
case "checkdictionary":
|
||||
echo "Dictionary template...</br>\n";
|
||||
$sCategories = ReadMandatoryParam("categories");
|
||||
$sOutputFilter = ReadParam("outputfilter", '');
|
||||
echo "Dictionary: missing entries (categories: $sCategories, output: '$sOutputFilter')</br>\n";
|
||||
echo "<pre>\n";
|
||||
echo MetaModel::MakeDictionaryTemplate();
|
||||
echo MetaModel::MakeDictionaryTemplate($sCategories, $sOutputFilter);
|
||||
echo "</pre>\n";
|
||||
break;
|
||||
case "checkmodel":
|
||||
|
||||
Reference in New Issue
Block a user