本文整理汇总了PHP中Dict::GetLanguages方法的典型用法代码示例。如果您正苦于以下问题:PHP Dict::GetLanguages方法的具体用法?PHP Dict::GetLanguages怎么用?PHP Dict::GetLanguages使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Dict
的用法示例。
在下文中一共展示了Dict::GetLanguages方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: GetAvailableLanguages
/**
* Helper function to get the available languages from the given directory
* @param $sDir Path to the dictionary
* @return an array of language code => description
*/
public static function GetAvailableLanguages($sDir)
{
require_once APPROOT . '/core/coreexception.class.inc.php';
require_once APPROOT . '/core/dict.class.inc.php';
$aFiles = scandir($sDir);
foreach ($aFiles as $sFile) {
if ($sFile == '.' || $sFile == '..' || $sFile == '.svn') {
// Skip
continue;
}
$sFilePath = $sDir . '/' . $sFile;
if (is_file($sFilePath) && preg_match('/^.*dict.*\\.php$/i', $sFilePath, $aMatches)) {
require_once $sFilePath;
}
}
return Dict::GetLanguages();
}
示例2: __construct
public function __construct($sCode, $aParams)
{
$this->m_sCode = $sCode;
$aAvailableLanguages = Dict::GetLanguages();
$aLanguageCodes = array();
foreach ($aAvailableLanguages as $sLangCode => $aInfo) {
$aLanguageCodes[$sLangCode] = $aInfo['description'] . ' (' . $aInfo['localized_description'] . ')';
}
$aParams["allowed_values"] = new ValueSetEnum($aLanguageCodes);
parent::__construct($sCode, $aParams);
}
示例3: DisplayPreferences
/**
* Displays the user's changeable preferences
* @param $oP WebPage The web page used for the output
*/
function DisplayPreferences($oP)
{
$oAppContext = new ApplicationContext();
$sURL = utils::GetAbsoluteUrlAppRoot() . 'pages/UI.php?' . $oAppContext->GetForLink();
$oP->add('<div class="page_header"><h1><img style="vertical-align:middle" src="../images/preferences.png"/> ' . Dict::S('UI:Preferences') . "</h1></div>\n");
$oP->add('<div id="user_prefs" style="max-width:800px; min-width:400px;">');
//////////////////////////////////////////////////////////////////////////
//
// User Language selection
//
//////////////////////////////////////////////////////////////////////////
$oP->add('<fieldset><legend>' . Dict::S('UI:FavoriteLanguage') . '</legend>');
$oP->add('<form method="post">');
$aLanguages = Dict::GetLanguages();
$aSortedlang = array();
foreach ($aLanguages as $sCode => $aLang) {
if (MetaModel::GetConfig()->Get('demo_mode')) {
if ($sCode != Dict::GetUserLanguage()) {
// Demo mode: only the current user language is listed in the available choices
continue;
}
}
$aSortedlang[$aLang['description']] = $sCode;
}
ksort($aSortedlang);
$oP->add('<p>' . Dict::S('UI:Favorites:SelectYourLanguage') . ' <select name="language">');
foreach ($aSortedlang as $sCode) {
$sSelected = $sCode == Dict::GetUserLanguage() ? 'selected' : '';
$oP->add('<option value="' . $sCode . '" ' . $sSelected . '/>' . $aLanguages[$sCode]['description'] . ' (' . $aLanguages[$sCode]['localized_description'] . ')</option>');
}
$oP->add('</select></p>');
$oP->add('<input type="hidden" name="operation" value="apply_language"/>');
$oP->add($oAppContext->GetForForm());
$oP->add('<p><input type="button" onClick="window.location.href=\'' . $sURL . '\'" value="' . Dict::S('UI:Button:Cancel') . '"/>');
$oP->add(' ');
$oP->add('<input type="submit" value="' . Dict::S('UI:Button:Apply') . '"/></p>');
$oP->add('</form>');
$oP->add('</fieldset>');
//////////////////////////////////////////////////////////////////////////
//
// Other (miscellaneous) settings
//
//////////////////////////////////////////////////////////////////////////
$oP->add('<fieldset><legend>' . Dict::S('UI:FavoriteOtherSettings') . '</legend>');
$oP->add('<form method="post" onsubmit="return ValidateOtherSettings()">');
$iDefaultPageSize = appUserPreferences::GetPref('default_page_size', MetaModel::GetConfig()->GetMinDisplayLimit());
$oP->add('<p>' . Dict::Format('UI:Favorites:Default_X_ItemsPerPage', '<input id="default_page_size" name="default_page_size" type="text" size="3" value="' . $iDefaultPageSize . '"/><span id="v_default_page_size"></span>') . '</p>');
$oP->add('<input type="hidden" name="operation" value="apply_others"/>');
$oP->add($oAppContext->GetForForm());
$oP->add('<p><input type="button" onClick="window.location.href=\'' . $sURL . '\'" value="' . Dict::S('UI:Button:Cancel') . '"/>');
$oP->add(' ');
$oP->add('<input id="other_submit" type="submit" value="' . Dict::S('UI:Button:Apply') . '"/></p>');
$oP->add('</form>');
$oP->add('</fieldset>');
$oP->add_script(<<<EOF
function ValidateOtherSettings()
{
\tvar sPageLength = \$('#default_page_size').val();
\tvar iPageLength = parseInt(sPageLength , 10);
\tif (/^[0-9]+\$/.test(sPageLength) && (iPageLength > 0))
\t{
\t\t\$('#v_default_page_size').html('');
\t\t\$('#other_submit').removeAttr('disabled');
\t\treturn true;
\t}
\telse
\t{
\t\t\$('#v_default_page_size').html('<img src="../images/validation_error.png"/>');
\t\t\$('#other_submit').attr('disabled', 'disabled');
\t\treturn false;
\t}
}
EOF
);
//////////////////////////////////////////////////////////////////////////
//
// Favorite Organizations
//
//////////////////////////////////////////////////////////////////////////
$oP->add('<fieldset><legend>' . Dict::S('UI:FavoriteOrganizations') . '</legend>');
$oP->p(Dict::S('UI:FavoriteOrganizations+'));
$oP->add('<form method="post">');
// Favorite organizations: the organizations listed in the drop-down menu
$sOQL = ApplicationMenu::GetFavoriteSiloQuery();
$oFilter = DBObjectSearch::FromOQL($sOQL);
$oBlock = new DisplayBlock($oFilter, 'list', false);
$oBlock->Display($oP, 1, array('menu' => false, 'selection_mode' => true, 'selection_type' => 'multiple', 'cssCount' => '.selectedCount', 'table_id' => 'user_prefs'));
$oP->add($oAppContext->GetForForm());
$oP->add('<input type="hidden" name="operation" value="apply"/>');
$oP->add('<p><input type="button" onClick="window.location.href=\'' . $sURL . '\'" value="' . Dict::S('UI:Button:Cancel') . '"/>');
$oP->add(' ');
$oP->add('<input type="submit" value="' . Dict::S('UI:Button:Apply') . '"/></p>');
$oP->add('</form>');
$oP->add('</fieldset>');
$aFavoriteOrgs = appUserPreferences::GetPref('favorite_orgs', null);
if ($aFavoriteOrgs == null) {
//.........这里部分代码省略.........
示例4: MakeDictionaryTemplate
function MakeDictionaryTemplate($sModules = '', $sLanguage = 'EN US')
{
$sRes = '';
Dict::SetDefaultLanguage($sLanguage);
$aAvailableLanguages = Dict::GetLanguages();
$sDesc = $aAvailableLanguages[$sLanguage]['description'];
$sLocalizedDesc = $aAvailableLanguages[$sLanguage]['localized_description'];
$sRes .= "// Dictionary conventions\n";
$sRes .= htmlentities("// Class:<class_name>\n", ENT_QUOTES, 'UTF-8');
$sRes .= htmlentities("// Class:<class_name>+\n", ENT_QUOTES, 'UTF-8');
$sRes .= htmlentities("// Class:<class_name>/Attribute:<attribute_code>\n", ENT_QUOTES, 'UTF-8');
$sRes .= htmlentities("// Class:<class_name>/Attribute:<attribute_code>+\n", ENT_QUOTES, 'UTF-8');
$sRes .= htmlentities("// Class:<class_name>/Attribute:<attribute_code>/Value:<value>\n", ENT_QUOTES, 'UTF-8');
$sRes .= htmlentities("// Class:<class_name>/Attribute:<attribute_code>/Value:<value>+\n", ENT_QUOTES, 'UTF-8');
$sRes .= htmlentities("// Class:<class_name>/Stimulus:<stimulus_code>\n", ENT_QUOTES, 'UTF-8');
$sRes .= htmlentities("// Class:<class_name>/Stimulus:<stimulus_code>+\n", ENT_QUOTES, 'UTF-8');
$sRes .= "\n";
// Note: I did not use EnumCategories(), because a given class maybe found in several categories
// Need to invent the "module", to characterize the origins of a class
if (strlen($sModules) == 0) {
$aModules = array('bizmodel', 'core/cmdb', 'gui', 'application', 'addon/userrights', 'monitoring');
} else {
$aModules = explode(', ', $sModules);
}
$sRes .= "//////////////////////////////////////////////////////////////////////\n";
$sRes .= "// Note: The classes have been grouped by categories: " . implode(', ', $aModules) . "\n";
$sRes .= "//////////////////////////////////////////////////////////////////////\n";
foreach ($aModules as $sCategory) {
$sRes .= "//////////////////////////////////////////////////////////////////////\n";
$sRes .= "// Classes in '{$sCategory}'\n";
$sRes .= "//////////////////////////////////////////////////////////////////////\n";
$sRes .= "//\n";
$sRes .= "\n";
foreach (MetaModel::GetClasses($sCategory) as $sClass) {
if (!MetaModel::HasTable($sClass)) {
continue;
}
$bNotInDico = false;
$bNotImportant = true;
$sClassRes = "//\n";
$sClassRes .= "// Class: {$sClass}\n";
$sClassRes .= "//\n";
$sClassRes .= "\n";
$sClassRes .= "Dict::Add('{$sLanguage}', '{$sDesc}', '{$sLocalizedDesc}', array(\n";
$sClassRes .= MakeDictEntry("Class:{$sClass}", MetaModel::GetName_Obsolete($sClass), $sClass, $bNotInDico);
$sClassRes .= MakeDictEntry("Class:{$sClass}+", MetaModel::GetClassDescription_Obsolete($sClass), '', $bNotImportant);
foreach (MetaModel::ListAttributeDefs($sClass) as $sAttCode => $oAttDef) {
if ($sAttCode == 'friendlyname') {
continue;
}
// Skip this attribute if not originaly defined in this class
if (MetaModel::GetAttributeOrigin($sClass, $sAttCode) != $sClass) {
continue;
}
$sClassRes .= MakeDictEntry("Class:{$sClass}/Attribute:{$sAttCode}", $oAttDef->GetLabel_Obsolete(), $sAttCode, $bNotInDico);
$sClassRes .= MakeDictEntry("Class:{$sClass}/Attribute:{$sAttCode}+", $oAttDef->GetDescription_Obsolete(), '', $bNotImportant);
if ($oAttDef instanceof AttributeEnum) {
if (MetaModel::GetStateAttributeCode($sClass) == $sAttCode) {
foreach (MetaModel::EnumStates($sClass) as $sStateCode => $aStateData) {
if (array_key_exists('label', $aStateData)) {
$sValue = $aStateData['label'];
} else {
$sValue = MetaModel::GetStateLabel($sClass, $sStateCode);
}
if (array_key_exists('description', $aStateData)) {
$sValuePlus = $aStateData['description'];
} else {
$sValuePlus = MetaModel::GetStateDescription($sClass, $sStateCode);
}
$sClassRes .= MakeDictEntry("Class:{$sClass}/Attribute:{$sAttCode}/Value:{$sStateCode}", $sValue, '', $bNotInDico);
$sClassRes .= MakeDictEntry("Class:{$sClass}/Attribute:{$sAttCode}/Value:{$sStateCode}+", $sValuePlus, '', $bNotImportant);
}
} else {
foreach ($oAttDef->GetAllowedValues() as $sKey => $value) {
$sClassRes .= MakeDictEntry("Class:{$sClass}/Attribute:{$sAttCode}/Value:{$sKey}", $value, '', $bNotInDico);
$sClassRes .= MakeDictEntry("Class:{$sClass}/Attribute:{$sAttCode}/Value:{$sKey}+", $value, '', $bNotImportant);
}
}
}
}
foreach (MetaModel::EnumStimuli($sClass) as $sStimulusCode => $oStimulus) {
$sClassRes .= MakeDictEntry("Class:{$sClass}/Stimulus:{$sStimulusCode}", $oStimulus->GetLabel_Obsolete(), '', $bNotInDico);
$sClassRes .= MakeDictEntry("Class:{$sClass}/Stimulus:{$sStimulusCode}+", $oStimulus->GetDescription_Obsolete(), '', $bNotImportant);
}
$sClassRes .= "));\n";
$sClassRes .= "\n";
$sRes .= $sClassRes;
}
}
return $sRes;
}
示例5: DoUpdateDBSchema
protected static function DoUpdateDBSchema($sMode, $aSelectedModules, $sModulesDir, $sDBServer, $sDBUser, $sDBPwd, $sDBName, $sDBPrefix, $sTargetEnvironment = '', $bOldAddon = false)
{
SetupPage::log_info("Update Database Schema for environment '{$sTargetEnvironment}'.");
$oConfig = new Config();
$aParamValues = array('mode' => $sMode, 'db_server' => $sDBServer, 'db_user' => $sDBUser, 'db_pwd' => $sDBPwd, 'db_name' => $sDBName, 'db_prefix' => $sDBPrefix);
$oConfig->UpdateFromParams($aParamValues, $sModulesDir);
if ($bOldAddon) {
// Old version of the add-on for backward compatibility with pre-2.0 data models
$oConfig->SetAddons(array('user rights' => 'addons/userrights/userrightsprofile.db.class.inc.php'));
}
$oProductionEnv = new RunTimeEnvironment($sTargetEnvironment);
$oProductionEnv->InitDataModel($oConfig, true);
// load data model only
// Migrate application data format
//
// priv_internalUser caused troubles because MySQL transforms table names to lower case under Windows
// This becomes an issue when moving your installation data to/from Windows
// Starting 2.0, all table names must be lowercase
if ($sMode != 'install') {
SetupPage::log_info("Renaming '{$sDBPrefix}priv_internalUser' into '{$sDBPrefix}priv_internaluser' (lowercase)");
// This command will have no effect under Windows...
// and it has been written in two steps so as to make it work under windows!
CMDBSource::SelectDB($sDBName);
try {
$sRepair = "RENAME TABLE `{$sDBPrefix}priv_internalUser` TO `{$sDBPrefix}priv_internaluser_other`, `{$sDBPrefix}priv_internaluser_other` TO `{$sDBPrefix}priv_internaluser`";
CMDBSource::Query($sRepair);
} catch (Exception $e) {
SetupPage::log_info("Renaming '{$sDBPrefix}priv_internalUser' failed (already done in a previous upgrade?)");
}
// let's remove the records in priv_change which have no counterpart in priv_changeop
SetupPage::log_info("Cleanup of '{$sDBPrefix}priv_change' to remove orphan records");
CMDBSource::SelectDB($sDBName);
try {
$sTotalCount = "SELECT COUNT(*) FROM `{$sDBPrefix}priv_change`";
$iTotalCount = (int) CMDBSource::QueryToScalar($sTotalCount);
SetupPage::log_info("There is a total of {$iTotalCount} records in {$sDBPrefix}priv_change.");
$sOrphanCount = "SELECT COUNT(c.id) FROM `{$sDBPrefix}priv_change` AS c left join `{$sDBPrefix}priv_changeop` AS o ON c.id = o.changeid WHERE o.id IS NULL";
$iOrphanCount = (int) CMDBSource::QueryToScalar($sOrphanCount);
SetupPage::log_info("There are {$iOrphanCount} useless records in {$sDBPrefix}priv_change (" . sprintf('%.2f', 100.0 * $iOrphanCount / $iTotalCount) . "%)");
if ($iOrphanCount > 0) {
SetupPage::log_info("Removing the orphan records...");
$sCleanup = "DELETE FROM `{$sDBPrefix}priv_change` USING `{$sDBPrefix}priv_change` LEFT JOIN `{$sDBPrefix}priv_changeop` ON `{$sDBPrefix}priv_change`.id = `{$sDBPrefix}priv_changeop`.changeid WHERE `{$sDBPrefix}priv_changeop`.id IS NULL;";
CMDBSource::Query($sCleanup);
SetupPage::log_info("Cleanup completed successfully.");
} else {
SetupPage::log_info("Ok, nothing to cleanup.");
}
} catch (Exception $e) {
SetupPage::log_info("Cleanup of orphan records in `{$sDBPrefix}priv_change` failed: " . $e->getMessage());
}
}
// Module specific actions (migrate the data)
//
$aAvailableModules = $oProductionEnv->AnalyzeInstallation(MetaModel::GetConfig(), APPROOT . $sModulesDir);
foreach ($aAvailableModules as $sModuleId => $aModule) {
if ($sModuleId != ROOT_MODULE && in_array($sModuleId, $aSelectedModules) && isset($aAvailableModules[$sModuleId]['installer'])) {
$sModuleInstallerClass = $aAvailableModules[$sModuleId]['installer'];
SetupPage::log_info("Calling Module Handler: {$sModuleInstallerClass}::BeforeDatabaseCreation(oConfig, {$aModule['version_db']}, {$aModule['version_code']})");
$aCallSpec = array($sModuleInstallerClass, 'BeforeDatabaseCreation');
call_user_func_array($aCallSpec, array(MetaModel::GetConfig(), $aModule['version_db'], $aModule['version_code']));
}
}
if (!$oProductionEnv->CreateDatabaseStructure(MetaModel::GetConfig(), $sMode)) {
throw new Exception("Failed to create/upgrade the database structure for environment '{$sTargetEnvironment}'");
}
// priv_change now has an 'origin' field to distinguish between the various input sources
// Let's initialize the field with 'interactive' for all records were it's null
// Then check if some records should hold a different value, based on a pattern matching in the userinfo field
CMDBSource::SelectDB($sDBName);
try {
$sCount = "SELECT COUNT(*) FROM `{$sDBPrefix}priv_change` WHERE `origin` IS NULL";
$iCount = (int) CMDBSource::QueryToScalar($sCount);
if ($iCount > 0) {
SetupPage::log_info("Initializing '{$sDBPrefix}priv_change.origin' ({$iCount} records to update)");
// By default all uninitialized values are considered as 'interactive'
$sInit = "UPDATE `{$sDBPrefix}priv_change` SET `origin` = 'interactive' WHERE `origin` IS NULL";
CMDBSource::Query($sInit);
// CSV Import was identified by the comment at the end
$sInit = "UPDATE `{$sDBPrefix}priv_change` SET `origin` = 'csv-import.php' WHERE `userinfo` LIKE '%Web Service (CSV)'";
CMDBSource::Query($sInit);
// CSV Import was identified by the comment at the end
$sInit = "UPDATE `{$sDBPrefix}priv_change` SET `origin` = 'csv-interactive' WHERE `userinfo` LIKE '%(CSV)' AND origin = 'interactive'";
CMDBSource::Query($sInit);
// Syncho data sources were identified by the comment at the end
// Unfortunately the comment is localized, so we have to search for all possible patterns
$sCurrentLanguage = Dict::GetUserLanguage();
foreach (Dict::GetLanguages() as $sLangCode => $aLang) {
Dict::SetUserLanguage($sLangCode);
$sSuffix = CMDBSource::Quote('%' . Dict::S('Core:SyncDataExchangeComment'));
$aSuffixes[$sSuffix] = true;
}
Dict::SetUserLanguage($sCurrentLanguage);
$sCondition = "`userinfo` LIKE " . implode(" OR `userinfo` LIKE ", array_keys($aSuffixes));
$sInit = "UPDATE `{$sDBPrefix}priv_change` SET `origin` = 'synchro-data-source' WHERE ({$sCondition})";
CMDBSource::Query($sInit);
SetupPage::log_info("Initialization of '{$sDBPrefix}priv_change.origin' completed.");
} else {
SetupPage::log_info("'{$sDBPrefix}priv_change.origin' already initialized, nothing to do.");
}
} catch (Exception $e) {
//.........这里部分代码省略.........