$object_name){ LanguageManager::_clearCache($module_dir, $lang); } } } /** * PRIVATE function used within clearLanguageCache so we do not repeat logic * @param string module_dir the module_dir to clear * @param string lang the name of the language file we are clearing this is for sugar_cache */ function _clearCache($module_dir = '', $lang){ if(!empty($module_dir) && !empty($lang)){ $file = $GLOBALS['sugar_config']['cache_dir'].'modules/'.$module_dir.'/language/'.$lang.'.lang.php'; if(file_exists($file)){ unlink($file); $key = "LanguageManager.$module_dir.$lang"; sugar_cache_clear($key); } } } /** * Given a module, search all of the specified locations, and any others as specified * in order to refresh the cache file * * @param string $module the given module we want to load the vardefs for * @param string $lang the given language we wish to load * @param array $additional_search_paths an array which allows a consumer to pass in additional vardef locations to search */ function refreshLanguage($module, $lang, $loaded_mod_strings = array(), $additional_search_paths = null){ // Some of the vardefs do not correctly define dictionary as global. Declare it first. $lang_paths = array( 'modules/'.$module.'/language/'.$lang.'.lang.php', 'modules/'.$module.'/language/'.$lang.'.lang.override.php', 'custom/modules/'.$module.'/Ext/Language/'.$lang.'.lang.ext.php', 'custom/modules/'.$module.'/language/'.$lang.'.lang.php', ); #27023, if this module template language file was not attached , get the template from this module vardef cache file if exsits and load the template language files. static $createdModules; if(empty($createdModules[$module]) && isset($GLOBALS['beanList'][$module])){ $object = $GLOBALS['beanList'][$module]; if ($object == 'aCase') $object = 'Case'; if(!empty($GLOBALS["dictionary"]["$object"]["templates"])){ $templates = $GLOBALS["dictionary"]["$object"]["templates"]; $loaded_mod_strings = LanguageManager::loadTemplateLanguage($module , $templates, $lang , $loaded_mod_strings); $createdModules[$module] = true; } } //end of fix #27023 // Add in additional search paths if they were provided. if(!empty($additional_search_paths) && is_array($additional_search_paths)) { $lang_paths = array_merge($lang_paths, $additional_search_paths); } //search a predefined set of locations for the vardef files foreach($lang_paths as $path){ if(file_exists($path)){ require($path); if(!empty($mod_strings)){ if (function_exists('sugarArrayMergeRecursive')){ $loaded_mod_strings = sugarArrayMergeRecursive($loaded_mod_strings, $mod_strings); } else{ $loaded_mod_strings = sugarArrayMerge($loaded_mod_strings, $mod_strings); } } } } //great! now that we have loaded all of our vardefs. //let's go save them to the cache file. if(!empty($loaded_mod_strings)) LanguageManager::saveCache($module, $lang, $loaded_mod_strings); } function loadModuleLanguage($module, $lang, $refresh=false){ //here check if the cache file exists, if it does then load it, if it doesn't //then call refreshVardef //if either our session or the system is set to developerMode then refresh is set to true // Retrieve the vardefs from cache. $key = "LanguageManager.$module.$lang"; if(!$refresh) { $return_result = sugar_cache_retrieve($key); if(!empty($return_result)){ return $return_result; } } // Some of the vardefs do not correctly define dictionary as global. Declare it first. if($refresh || !file_exists($GLOBALS['sugar_config']['cache_dir'].'modules/'.$module.'/language/'.$lang.'.lang.php')){ LanguageManager::refreshLanguage($module, $lang); } //at this point we should have the cache/modules/... file //which was created from the refreshVardefs so let's try to load it. if(file_exists($GLOBALS['sugar_config']['cache_dir'].'modules/'. $module . '/language/'.$lang.'.lang.php')){ global $mod_strings; require($GLOBALS['sugar_config']['cache_dir'].'modules/'. $module . '/language/'.$lang.'.lang.php'); // now that we hae loaded the data from disk, put it in the cache. if(!empty($mod_strings)) sugar_cache_put($key,$mod_strings); if(!empty($_SESSION['translation_mode'])){ $mod_strings = array_map('translated_prefix', $mod_strings); } return $mod_strings; } } } function translated_prefix($key){ return '[translated]' . $key; }