static function getCustomLabels($language, $module, $basepath) { $deployedModule = false; if (is_null($basepath)) { $deployedModule = true; $basepath = "custom/modules/{$module}/language"; if (!is_dir($basepath)) { require_once 'modules/Administration/Common.php'; create_module_lang_dir($module); } } $filename = "{$basepath}/{$language}.lang.php"; $dir_exists = is_dir($basepath); $mod_strings = array(); if ($dir_exists) { if (file_exists($filename)) { // obtain $mod_strings include $filename; } } else { return false; } return array("file" => $filename, "deployed" => $deployedModule, "labels" => $mod_strings); }
/** * @return bool * @param module string, language string, key string, value string * @desc Returns true if new field label can be created, false otherwise. * Probable reason for returning false: new_field_key already exists. */ function create_field_label($module, $language, $key, $value, $overwrite = false) { $return_value = false; $mod_strings = return_module_language($language, $module); if (isset($mod_strings[$key]) && !$overwrite) { $GLOBALS['log']->info("Tried to create a key that already exists: {$key}"); } else { $mod_strings = array_merge($mod_strings, array($key => $value)); $dirname = "custom/modules/{$module}/language"; $dir_exists = is_dir($dirname); if (!$dir_exists) { $dir_exists = create_module_lang_dir($module); } if ($dir_exists) { $filename = "{$dirname}/{$language}.lang.php"; if (is_file($filename)) { $handle = sugar_fopen($filename, 'rb'); $old_contents = fread($handle, filesize($filename)); fclose($handle); } else { $old_contents = ''; } $handle = sugar_fopen($filename, 'wb'); if ($handle) { $contents = create_field_lang_pak_contents($old_contents, $key, $value, $language, $module); if (fwrite($handle, $contents)) { $return_value = true; $GLOBALS['log']->info("Successful write to: {$filename}"); } fclose($handle); } else { $GLOBALS['log']->info("Unable to write edited language pak to file: {$filename}"); } } else { $GLOBALS['log']->info("Unable to create dir: {$dirname}"); } } return $return_value; }
static function addLabels($language, $labels, $moduleName, $basepath = null) { $GLOBALS['log']->debug("ParserLabel->addLabels({$language}, \$labels, {$moduleName}, {$basepath} );"); $GLOBALS['log']->debug("\$labels:" . print_r($labels, true)); $deployedModule = false; if (is_null($basepath)) { $deployedModule = true; $basepath = "custom/modules/{$moduleName}/language"; if (!is_dir($basepath)) { require_once 'modules/Administration/Common.php'; create_module_lang_dir($moduleName); } } $filename = "{$basepath}/{$language}.lang.php"; $dir_exists = is_dir($basepath); $mod_strings = array(); if ($dir_exists) { if (file_exists($filename)) { // obtain $mod_strings include $filename; } } else { return false; } $changed = false; //$charset = (isset($app_strings['LBL_CHARSET'])) ? $app_strings['LBL_CHARSET'] : $GLOBALS['sugar_config']['default_charset'] ; foreach ($labels as $key => $value) { if (!isset($mod_strings[$key]) || strcmp($value, $mod_strings[$key]) != 0) { $mod_strings[$key] = html_entity_decode_utf8($value, ENT_QUOTES); // must match encoding used in view.labels.php $changed = true; } } if ($changed) { $GLOBALS['log']->debug("ParserLabel->addLabels: writing new mod_strings to {$filename}"); $GLOBALS['log']->debug("ParserLabel->addLabels: mod_strings=" . print_r($mod_strings, true)); if (!write_array_to_file("mod_strings", $mod_strings, $filename)) { $GLOBALS['log']->fatal("Could not write {$filename}"); } else { // if we have a cache to worry about, then clear it now if ($deployedModule) { $GLOBALS['log']->debug("PaserLabel->addLabels: clearing language cache"); $cache_key = "module_language." . $language . $moduleName; sugar_cache_clear($cache_key); LanguageManager::clearLanguageCache($moduleName, $language); } } } return true; }