/** * Loads appropriate language file if necessary. Returns translated string value for a module string. * Included in the module class when needed. * * @param mixed $modinstance pointer to the module instance * @since 1.0 * @return string translated */ function cms_module_Lang(&$modinstance) { global $gCms; $name = ''; $params = array(); if (func_num_args() > 0) { $name = func_get_arg(1); if (func_num_args() == 3 && is_array(func_get_arg(2))) { $params = func_get_arg(2); } else { if (func_num_args() > 2) { $params = array_slice(func_get_args(), 2); } } } else { return ''; } if ($modinstance->curlang == '') { $modinstance->curlang = cms_current_language(); } $ourlang = $modinstance->curlang; #Load the language if it's not loaded if (!isset($modinstance->langhash[$ourlang]) || !is_array($modinstance->langhash[$ourlang]) || is_array($modinstance->langhash[$ourlang]) && count(array_keys($modinstance->langhash[$ourlang])) == 0) { $dir = $gCms->config['root_path']; $lang = array(); //First load the default language to remove any "Add Me's" if (@is_file("{$dir}/modules/" . $modinstance->GetName() . "/lang/" . $modinstance->DefaultLanguage() . "/" . $modinstance->DefaultLanguage() . ".php")) { include "{$dir}/modules/" . $modinstance->GetName() . "/lang/" . $modinstance->DefaultLanguage() . "/" . $modinstance->DefaultLanguage() . ".php"; } else { if (@is_file("{$dir}/modules/" . $modinstance->GetName() . "/lang/" . $modinstance->DefaultLanguage() . ".php")) { include "{$dir}/modules/" . $modinstance->GetName() . "/lang/" . $modinstance->DefaultLanguage() . ".php"; } } //Now load the other language if necessary if (count($lang) == 0 || $modinstance->DefaultLanguage() != $ourlang) { if (@is_file("{$dir}/modules/" . $modinstance->GetName() . "/lang/{$ourlang}/{$ourlang}.php")) { include "{$dir}/modules/" . $modinstance->GetName() . "/lang/{$ourlang}/{$ourlang}.php"; } else { if (@is_file("{$dir}/modules/" . $modinstance->GetName() . "/lang/ext/{$ourlang}.php")) { include "{$dir}/modules/" . $modinstance->GetName() . "/lang/ext/{$ourlang}.php"; } else { if (@is_file("{$dir}/modules/" . $modinstance->GetName() . "/lang/{$ourlang}.php")) { include "{$dir}/modules/" . $modinstance->GetName() . "/lang/{$ourlang}.php"; } else { if (count($lang) == 0) { if (@is_file("{$dir}/modules/" . $modinstance->GetName() . "/lang/" . $modinstance->DefaultLanguage() . "/" . $modinstance->DefaultLanguage() . ".php")) { include "{$dir}/modules/" . $modinstance->GetName() . "/lang/" . $modinstance->DefaultLanguage() . "/" . $modinstance->DefaultLanguage() . ".php"; } else { if (@is_file("{$dir}/modules/" . $modinstance->GetName() . "/lang/" . $modinstance->DefaultLanguage() . ".php")) { include "{$dir}/modules/" . $modinstance->GetName() . "/lang/" . $modinstance->DefaultLanguage() . ".php"; } } } else { # Sucks to be here... Don't use Lang unless there are language files... # Get ready for a lot of Add Me's } } } } } # try to load an admin modifiable version of the lang file if one exists if (@is_file("{$dir}/module_custom/" . $modinstance->GetName() . "/lang/{$ourlang}.php")) { include "{$dir}/module_custom/" . $modinstance->GetName() . "/lang/{$ourlang}.php"; } else { if (@is_file("{$dir}/module_custom/" . $modinstance->GetName() . "/lang/" . $modinstance->DefaultLanguage() . ".php")) { include "{$dir}/module_custom/" . $modinstance->GetName() . "/lang/" . $modinstance->DefaultLanguage() . ".php"; } } $modinstance->langhash[$ourlang] =& $lang; } $result = ''; if (isset($modinstance->langhash[$ourlang][$name])) { if (count($params)) { $result = @vsprintf($modinstance->langhash[$ourlang][$name], $params); } else { $result = $modinstance->langhash[$ourlang][$name]; } } else { $result = "--Add Me - module:" . $modinstance->GetName() . " string:{$name}--"; } if (isset($gCms->config['admin_encoding']) && isset($gCms->variables['convertclass'])) { if (strtolower(get_encoding('', false)) != strtolower($gCms->config['admin_encoding'])) { $class =& $gCms->variables['convertclass']; $result = $class->Convert($result, get_encoding('', false), $gCms->config['admin_encoding']); } } return $result; }
/** * A method to return a translation for a specific string in a specific realm. * called with the realm first, followed by the key, this method will attempt * to load the specific realm data if necessary before doing translation. * * This method accepts a variable number of arguments. Any arguments after * the realm and the key are passed to the key via vsprintf * * i.e: lang_by_realm('tasks','my_string'); * * @since 1.8 * @param string The realm * @param string The lang key * @return string */ function lang_by_realm() { $gCms = cmsms(); $name = ''; $realm = 'admin'; $params = array(); $result = ''; $num = func_num_args(); if ($num == 0) { return ''; } $name = func_get_arg(0); if ($num > 1) { $realm = func_get_arg(1); if ($num > 2 && is_array(func_get_arg(2))) { $params = func_get_arg(2); } else { if ($num > 2) { $params = array_slice(func_get_args(), 2); } } } // we now have a name, a realm, and possible additonal arguments. cms_load_lang_realm($realm); $all_langs = cms_utils::get_app_data('cms_loaded_realms'); $cur_lang = cms_current_language(); // do processing. if (is_array($all_langs) && isset($all_langs[$cur_lang]) && isset($all_langs[$cur_lang][$realm]) && isset($all_langs[$cur_lang][$realm][$name])) { $lang = $all_langs[$cur_lang]; if (count($params)) { $result = vsprintf($lang[$realm][$name], $params); } else { $result = $lang[$realm][$name]; } } else { $result = "--Add Me - {$name} --"; } // conversion. if (isset($gCms->config['admin_encoding']) && isset($gCms->variables['convertclass'])) { if (strcasecmp(get_encoding('', false), $gCms->config['admin_encoding'])) { $class =& $gCms->variables['convertclass']; $result = $class->Convert($result, get_encoding('', false), $gCms->config['admin_encoding']); } } return $result; }
/** * Constructor * */ public function CMSModule() { global $CMS_STYLESHEET; global $CMS_ADMIN_PAGE; global $CMS_MODULE_PAGE; global $CMS_INSTALL_PAGE; $this->curlang = cms_current_language(); // current language for this request. if (!isset($CMS_ADMIN_PAGE) && !isset($CMS_STYLESHEET) && !isset($CMS_INSTALL_PAGE)) { $this->SetParameterType('assign', CLEAN_STRING); $this->SetParameterType('module', CLEAN_STRING); $this->SetParameterType('lang', CLEAN_STRING); $this->SetParameterType('returnid', CLEAN_INT); $this->SetParameterType('action', CLEAN_STRING); $this->SetParameterType('showtemplate', CLEAN_STRING); $this->SetParameterType('inline', CLEAN_INT); $this->InitializeFrontend(); } else { if (isset($CMS_ADMIN_PAGE) && !isset($CMS_STYLESHEET) && !isset($CMS_INSTALL_PAGE)) { $this->params[0]['help'] = lang('langparam'); $this->InitializeAdmin(); } } }
/** * Load a lang file for a specific realm. * * @since 1.8 * @internal * @param string The realm * @param string An optional base directory * @param boolean Indicates that the language is indicated by the directory name * @param boolean Indicates that the lang file has a sub array for the realm. * @return void */ function cms_load_lang_realm($realm, $basedir = '', $filename = '', $lang_is_dir = 0, $has_realm = 0) { global $gCms; global $lang; if (empty($realm)) { return fALSE; } if (empty($basedir)) { $basedir = cms_join_path($gCms->config['root_path'], 'lib', 'lang', $realm); } if (empty($filename)) { $filename = 'en_US.php'; } $cur_lang = cms_current_language(); // load the default (en_US) file first. $fn = cms_join_path($basedir, $filename); if ($lang_is_dir) { $fn = cms_join_path($basedir, 'en_US', $filename); } if (!isset($lang[$realm])) { if (@file_exists($fn)) { if (!$has_realm) { // the lang file doesn't create a subarray $hold_lang = $lang; $lang = array(); include $fn; $hold_lang[$realm] = $lang; $lang = $hold_lang; unset($hold_lang); } else { // the lang file defines the sub-array itself. include $fn; } if (!isset($lang[$realm])) { return FALSE; } } // now load the lang file itself. if ($cur_lang != 'en_US') { $cur_lang = basename($cur_lang); $fn = cms_join_path($basedir, 'ext', $cur_lang . '.php'); if ($lang_is_dir) { $fn = cms_join_path($basedir, 'ext', $cur_lang, $filename); } if (@file_exists($fn)) { if (!$has_realm) { // the lang file doesn't create a subarray $hold_lang = $lang; $lang = array(); include $fn; $hold_lang[$realm] = $lang; $lang = $hold_lang; unset($hold_lang); } else { // the lang file defines the sub-array itself. include $fn; } if (!isset($lang[$realm])) { return FALSE; } } } } return TRUE; }