diff --git a/datamodels/2.x/itop-structure/module.itop-structure.php b/datamodels/2.x/itop-structure/module.itop-structure.php index f1da9aeafe..d90667890f 100644 --- a/datamodels/2.x/itop-structure/module.itop-structure.php +++ b/datamodels/2.x/itop-structure/module.itop-structure.php @@ -99,6 +99,22 @@ if (!class_exists('StructureInstaller')) { */ public static function AfterDatabaseCreation(Config $oConfiguration, $sPreviousVersion, $sCurrentVersion) { + // Load localized structural data: contact types and contract types + static::LoadLocalizedData( + $sPreviousVersion, + $sCurrentVersion, + $oConfiguration, + '3.3.0', + dirname(__FILE__)."/data/{{language_code}}.data.itop-contacttype.xml" + ); + static::LoadLocalizedData( + $sPreviousVersion, + $sCurrentVersion, + $oConfiguration, + '3.3.0', + dirname(__FILE__)."/data/{{language_code}}.data.itop-contracttype.xml" + ); + // Default language will be used for actions // Note: There is a issue when upgrading, default language cannot be retrieved from the passed configuration, we have to read it from the disk if (utils::IsNullOrEmptyString($sPreviousVersion)) { diff --git a/setup/moduleinstaller.class.inc.php b/setup/moduleinstaller.class.inc.php index 3cd0c6dac3..0c12cedfc0 100644 --- a/setup/moduleinstaller.class.inc.php +++ b/setup/moduleinstaller.class.inc.php @@ -331,7 +331,16 @@ abstract class ModuleInstallerAPI (version_compare($sPreviousVersion, $sCurrentVersion, '<') && version_compare($sPreviousVersion, $sFirstLoadingVersion, '<'))) { - $sFileName = self::GetLocalizedFileName($oConfiguration, $sFilePattern); + // Note: There is an issue when upgrading, default language cannot be retrieved from the passed configuration, we have to read it from the disk + if (utils::IsNullOrEmptyString($sPreviousVersion)) { + // Fresh install + $sDefaultLanguage = $oConfiguration->GetDefaultLanguage(); + } else { + // Upgrade + $sDefaultLanguage = utils::GetConfig(true)->GetDefaultLanguage(); + } + + $sFileName = self::GetLocalizedFileName($sDefaultLanguage, $sFilePattern); if ($sFileName !== '') { SetupLog::Info("Loading file: $sFileName"); self::XMLFileLoad($sFileName); @@ -360,33 +369,16 @@ abstract class ModuleInstallerAPI } /** - * @param \Config $oConfiguration + * @param string $sLanguage The language code to use for localization (e.g. 'EN US') * @param string $sFilePattern The full path+name of the file to localize, with {{language_code}} as placeholder for the language code (e.g. 'data.sample.{{language_code}}.xml') * * @return string The localized file name if found, or an empty string if not found * @throws \ConfigException * @throws \CoreException */ - public static function GetLocalizedFileName(Config $oConfiguration, string $sFilePattern): string + public static function GetLocalizedFileName($sLanguage, string $sFilePattern): string { - $sLang = null; - if (is_object($oConfiguration)) { - $sLang = str_replace(' ', '_', strtolower($oConfiguration->GetDefaultLanguage())); - } - /** Old code relying on reading the file instead of using the configuration passed object - * Try to get app. language from configuration fil (app. upgrade) - $sConfigFileName = APPCONF.'production/'.ITOP_CONFIG_FILE; - if (file_exists($sConfigFileName)) { - $oFileConfig = new Config($sConfigFileName); - if (is_object($oFileConfig)) { - $sLang = str_replace(' ', '_', strtolower($oFileConfig->GetDefaultLanguage())); - } - } - **/ - // - I still no language, get the default one - if (null === $sLang) { - $sLang = str_replace(' ', '_', strtolower($oConfiguration->GetDefaultLanguage())); - } + $sLang = str_replace(' ', '_', strtolower($sLanguage)); $sFileName = str_replace('{{language_code}}', $sLang, $sFilePattern); if (!file_exists($sFileName)) { $sLang = 'en_us';