Browse Source

Improved error handling and localization

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@437 a333f486-631f-4898-b8df-5754b55c2be0
romainq 15 years ago
parent
commit
0719452f5c
3 changed files with 23 additions and 9 deletions
  1. 12 1
      core/dict.class.inc.php
  2. 9 6
      core/metamodel.class.php
  3. 2 2
      pages/UI.php

+ 12 - 1
core/dict.class.inc.php

@@ -101,6 +101,11 @@ class Dict
 	{
 		// Attempt to find the string in the user language
 		//
+		if (!array_key_exists(self::$m_sCurrentLanguage, self::$m_aData))
+		{
+			// It may happen, when something happens before the dictionnaries get loaded
+			return $sStringCode;
+		}
 		$aCurrentDictionary = self::$m_aData[self::$m_sCurrentLanguage];
 		if (array_key_exists($sStringCode, $aCurrentDictionary))
 		{
@@ -140,8 +145,14 @@ class Dict
 	public static function Format($sFormatCode /*, ... arguments ....*/)
 	{
 		$sLocalizedFormat = self::S($sFormatCode);
-
 		$aArguments = func_get_args();
+		
+		if ($sLocalizedFormat == $sFormatCode)
+		{
+			// Make sure the information will be displayed (ex: an error occuring before the dictionary gets loaded)
+			return $sFormatCode.' - '.implode(', ', $aArguments);
+		}
+
 		array_shift($aArguments);
 		return vsprintf($sLocalizedFormat, $aArguments);
 	}

+ 9 - 6
core/metamodel.class.php

@@ -2935,6 +2935,15 @@ abstract class MetaModel
 			self::$m_bLogWebService = false;
 		}
 
+		// Note: load the dictionary as soon as possible, because it might be
+		//       needed when some error occur
+		foreach ($oConfig->GetDictionaries() as $sModule => $sToInclude)
+		{
+			self::Plugin($sConfigFile, 'dictionaries', $sToInclude);
+		}
+		// Set the language... after the dictionaries have been loaded!
+		Dict::SetDefaultLanguage($oConfig->GetDefaultLanguage());
+
 		foreach ($oConfig->GetAppModules() as $sModule => $sToInclude)
 		{
 			self::Plugin($sConfigFile, 'application', $sToInclude);
@@ -2947,12 +2956,6 @@ abstract class MetaModel
 		{
 			self::Plugin($sConfigFile, 'addons', $sToInclude);
 		}
-		foreach ($oConfig->GetDictionaries() as $sModule => $sToInclude)
-		{
-			self::Plugin($sConfigFile, 'dictionaries', $sToInclude);
-		}
-		// Set the language... after the dictionaries have been loaded!
-		Dict::SetDefaultLanguage($oConfig->GetDefaultLanguage());
 
 		$sServer = $oConfig->GetDBHost();
 		$sUser = $oConfig->GetDBUser();

+ 2 - 2
pages/UI.php

@@ -1306,7 +1306,7 @@ catch(CoreException $e)
 
 	if (MetaModel::IsLogEnabledIssue())
 	{
-		if (class_exists('EventIssue'))
+		if (MetaModel::IsValidClass('EventIssue'))
 		{
 			$oLog = new EventIssue();
 
@@ -1335,7 +1335,7 @@ catch(Exception $e)
 
 	if (MetaModel::IsLogEnabledIssue())
 	{
-		if (class_exists('EventIssue'))
+		if (MetaModel::IsValidClass('EventIssue'))
 		{
 			$oLog = new EventIssue();