本文整理汇总了PHP中Gdn::Locale方法的典型用法代码示例。如果您正苦于以下问题:PHP Gdn::Locale方法的具体用法?PHP Gdn::Locale怎么用?PHP Gdn::Locale使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Gdn
的用法示例。
在下文中一共展示了Gdn::Locale方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Base_Render_Before
/**
* Show alternate locale options in Foot.
*/
public function Base_Render_Before($Sender)
{
// Not in Dashboard
// Block guests until guest sessions are restored
if ($Sender->MasterView == 'admin') {
return;
}
// Get locales
$LocaleModel = new LocaleModel();
$Options = $LocaleModel->EnabledLocalePacks();
$Locales = $LocaleModel->AvailableLocalePacks();
// Build & add links
$Links = '';
foreach ($Options as $Slug => $Code) {
$LocaleInfo = GetValue($Slug, $Locales);
$LocaleName = str_replace(' Transifex', '', GetValue('Name', $LocaleInfo));
// No 'Transifex' in names, pls.
$Links .= $this->BuildLocaleLink($LocaleName, $Code);
}
// Hackily add English option
$Links .= $this->BuildLocaleLink('English', 'en-CA');
$LocaleLinks = Wrap($Links, 'div', array('class' => 'languages'));
$Sender->AddAsset('Foot', $LocaleLinks);
// Add a simple style
$Sender->AddAsset('Head', '<style>.Dashboard .LocaleOptions { display: none; }</style>');
$Sender->setData('Locale', substr(Gdn::Locale()->Current(), 0, 2));
}
示例2: Gdn_Dispatcher_AfterAnalyzeRequest_Handler
/**
* Set user's preferred locale.
*
* Moved event from AppStart to AfterAnalyzeRequest to allow Embed to set P3P header first.
*/
public function Gdn_Dispatcher_AfterAnalyzeRequest_Handler($Sender)
{
// Set user preference
if ($TempLocale = $this->GetAlternateLocale()) {
Gdn::Locale()->Set($TempLocale, Gdn::ApplicationManager()->EnabledApplicationFolders(), Gdn::PluginManager()->EnabledPluginFolders());
}
}
示例3: UserController_TempBan_Create
public function UserController_TempBan_Create($Sender, $Args)
{
$Sender->Permission('Garden.Moderation.Manage');
$UserID = (int) GetValue('0', $Args);
$Unban = (bool) GetValue('1', $Args);
$User = Gdn::UserModel()->GetID($UserID, DATASET_TYPE_ARRAY);
if (!$User) {
throw NotFoundException($User);
}
$UserModel = Gdn::UserModel();
if ($Sender->Form->AuthenticatedPostBack()) {
if ($Unban) {
$UserModel->Unban($UserID, array('RestoreContent' => $Sender->Form->GetFormValue('RestoreContent')));
} else {
$Minutes = $Sender->Form->GetValue('TempBanPeriodMinutes');
$Hours = $Sender->Form->GetValue('TempBanPeriodHours');
$Days = $Sender->Form->GetValue('TempBanPeriodDays');
$Months = $Sender->Form->GetValue('TempBanPeriodMonths');
$Years = $Sender->Form->GetValue('TempBanPeriodYears');
if (!(empty($Minutes) && empty($Hours) && empty($Days) && empty($Months) && empty($Years))) {
$AutoExpirePeriod = Gdn_Format::ToDateTime(strtotime("+{$Years} years {$Months} months {$Days} days {$Hours} hours {$Minutes} minutes"));
} else {
$Sender->Form->AddError('ValidateRequired', 'Ban Period');
}
if (!ValidateRequired($Sender->Form->GetFormValue('Reason'))) {
$Sender->Form->AddError('ValidateRequired', 'Reason');
}
if ($Sender->Form->GetFormValue('Reason') == 'Other' && !ValidateRequired($Sender->Form->GetFormValue('ReasonText'))) {
$Sender->Form->AddError('ValidateRequired', 'Reason Text');
}
if ($Sender->Form->ErrorCount() == 0) {
if ($Sender->Form->GetFormValue('Reason') == 'Other') {
$Reason = $Sender->Form->GetFormValue('ReasonText');
} else {
$Reason = $Sender->Form->GetFormValue('Reason');
}
Gdn::Locale()->SetTranslation('HeadlineFormat.Ban', FormatString('{RegardingUserID,You} banned {ActivityUserID,you} until {BanExpire, date}.', array('BanExpire' => $AutoExpirePeriod)));
$UserModel->Ban($UserID, array('Reason' => $Reason));
$UserModel->SetField($UserID, 'BanExpire', $AutoExpirePeriod);
}
}
if ($Sender->Form->ErrorCount() == 0) {
// Redirect after a successful save.
if ($Sender->Request->Get('Target')) {
$Sender->RedirectUrl = $Sender->Request->Get('Target');
} else {
$Sender->RedirectUrl = Url(UserUrl($User));
}
}
}
$Sender->SetData('User', $User);
$Sender->AddSideMenu();
$Sender->Title($Unban ? T('Unban User') : T('Temporary Ban User'));
if ($Unban) {
$Sender->View = 'Unban';
} else {
$Sender->View = $this->ThemeView('tempban');
}
$Sender->Render();
}
示例4: Base_Render_Before
/**
* Add the rtl stylesheets to the page.
*
* The rtl stylesheets should always be added separately so that they aren't combined with other stylesheets when
* a non-rtl language is still being displayed.
*
* @param Gdn_Controller $Sender
*/
public function Base_Render_Before(&$Sender)
{
$currentLocale = substr(Gdn::Locale()->Current(), 0, 2);
if (in_array($currentLocale, $this->rtlLocales)) {
if (InSection('Dashboard')) {
$Sender->AddCssFile('admin_rtl.css', 'plugins/RightToLeft');
} else {
$Sender->AddCssFile('style_rtl.css', 'plugins/RightToLeft');
}
$Sender->CssClass .= ' rtl';
}
}
示例5: GetLocaleDefinitions
public static function GetLocaleDefinitions()
{
$Locale = Gdn::Locale();
unset($Locale->EventArguments['WildEventStack']);
$Variable = var_export($Locale, True);
$CutPoint1 = strpos($Variable, "'_Definition' =>") + 16;
$CutPoint2 = strrpos($Variable, "'_Locale' =>", $CutPoint1);
if ($CutPoint1 === False || $CutPoint2 === False) {
throw new Exception('Failed to detect cutpoints.');
}
$Match = substr($Variable, $CutPoint1, $CutPoint2 - $CutPoint1);
$Match = trim(trim(trim($Match), ','));
// Kids, never use eval.
eval("\$Result = {$Match};");
return $Result;
}
示例6: SetMetaTags
function SetMetaTags($Page, $Controller = Null)
{
if (!$Controller) {
$Controller = Gdn::Controller();
}
if ($Page->MetaDescription) {
$Controller->Head->AddTag('meta', array('name' => 'description', 'content' => $Page->MetaDescription, '_sort' => 0));
}
if ($Page->MetaKeywords) {
$Controller->Head->AddTag('meta', array('name' => 'keywords', 'content' => $Page->MetaKeywords, '_sort' => 0));
}
if ($Page->MetaRobots) {
$Controller->Head->AddTag('meta', array('name' => 'robots', 'content' => $Page->MetaRobots, '_sort' => 0));
}
if ($Page->MetaTitle) {
$Controller->Head->Title($Page->MetaTitle);
}
$Controller->Head->AddTag('meta', array('http-equiv' => 'content-language', 'content' => Gdn::Locale()->Current()));
$Controller->Head->AddTag('meta', array('http-equiv' => 'content-type', 'content' => 'text/html; charset=utf-8'));
}
示例7: DiscussionController_Render_Before
public function DiscussionController_Render_Before($Sender)
{
$this->ExpireCheck($Sender->Data('Discussion'));
$this->Expire();
if (Gdn::Session()->CheckPermission('Vanilla.Discussions.Close', TRUE, 'Category', $Sender->Data('Discussion')->PermissionCategoryID) && $Sender->Data('Discussion')->Closed && $Sender->Data('Discussion')->AutoExpire) {
$Sender->AddJsFile('autoexpire.js', 'plugins/AutoExpireDiscussions');
}
if ($Sender->Data('Discussion')->Closed && $Sender->Data('Discussion')->AutoExpire) {
Gdn::Locale()->SetTranslation('This discussion has been closed.', 'This discussion has expired.');
}
}
示例8: DisableApplication
/**
* Undocumented method.
*
* @param string $ApplicationName Undocumented variable.
* @todo Document DisableApplication() method.
*/
public function DisableApplication($ApplicationName)
{
// 1. Check to make sure that this application is allowed to be disabled
$ApplicationInfo = ArrayValueI($ApplicationName, $this->AvailableApplications(), array());
$ApplicationName = $ApplicationInfo['Index'];
if (!ArrayValue('AllowDisable', $ApplicationInfo, TRUE)) {
throw new Exception(sprintf(T('You cannot disable the %s application.'), $ApplicationName));
}
// 2. Check to make sure that no other enabled applications rely on this one
foreach ($this->EnabledApplications() as $CheckingName => $CheckingInfo) {
$RequiredApplications = ArrayValue('RequiredApplications', $CheckingInfo, FALSE);
if (is_array($RequiredApplications) && array_key_exists($ApplicationName, $RequiredApplications) === TRUE) {
throw new Exception(sprintf(T('You cannot disable the %1$s application because the %2$s application requires it in order to function.'), $ApplicationName, $CheckingName));
}
}
// 2. Disable it
RemoveFromConfig("EnabledApplications.{$ApplicationName}");
// Clear the object caches.
Gdn_Autoloader::SmartFree(Gdn_Autoloader::CONTEXT_APPLICATION, $ApplicationInfo);
// Redefine the locale manager's settings $Locale->Set($CurrentLocale, $EnabledApps, $EnabledPlugins, TRUE);
$Locale = Gdn::Locale();
$Locale->Set($Locale->Current(), $this->EnabledApplicationFolders(), Gdn::PluginManager()->EnabledPluginFolders(), TRUE);
$this->EventArguments['AddonName'] = $ApplicationName;
Gdn::PluginManager()->CallEventHandlers($this, 'ApplicationManager', 'AddonDisabled');
}
示例9: LocaleLanguageCode
protected static function LocaleLanguageCode()
{
$T = preg_split('/[_-]/', Gdn::Locale()->Current());
return ArrayValue(0, $T, 'en');
}
示例10: TestLocale
/**
* Enable a locale pack without installing it to the config or mappings.
*
* @param string $LocaleKey The key of the folder.
*/
public function TestLocale($LocaleKey)
{
$Available = $this->AvailableLocalePacks();
if (!isset($Available[$LocaleKey])) {
throw NotFoundException('Locale');
}
// Grab all of the definition files from the locale.
$Paths = SafeGlob(PATH_ROOT . "/locales/{$LocaleKey}/*.php");
foreach ($Paths as $Path) {
Gdn::Locale()->Load($Path);
}
}
示例11: GetInfoArray
public function GetInfoArray()
{
$Info = C('Plugins.LocaleDeveloper');
foreach ($Info as $Key => $Value) {
if (!$Value) {
unset($Info[$Key]);
}
}
$InfoArray = array(GetValue('Key', $Info, 'LocaleDeveloper') => array('Locale' => GetValue('Locale', $Info, Gdn::Locale()->Current()), 'Name' => GetValue('Name', $Info, 'Locale Developer'), 'Description' => 'Automatically gernerated by the Locale Developer plugin.', 'Version' => '0.1a', 'Author' => "Your Name", 'AuthorEmail' => 'Your Email', 'AuthorUrl' => 'http://your.domain.com', 'License' => 'Your choice of license'));
return $InfoArray;
}
示例12: Configure
/**
* Allows the configuration of basic setup information in Garden. This
* should not be functional after the application has been set up.
*
* @since 2.0.0
* @access public
* @param string $RedirectUrl Where to send user afterward.
*/
public function Configure($RedirectUrl = '')
{
// Create a model to save configuration settings
$Validation = new Gdn_Validation();
$ConfigurationModel = new Gdn_ConfigurationModel($Validation);
$ConfigurationModel->SetField(array('Garden.Locale', 'Garden.Title', 'Garden.RewriteUrls', 'Garden.WebRoot', 'Garden.Cookie.Salt', 'Garden.Cookie.Domain', 'Database.Name', 'Database.Host', 'Database.User', 'Database.Password', 'Garden.Registration.ConfirmEmail', 'Garden.Email.SupportName'));
// Set the models on the forms.
$this->Form->SetModel($ConfigurationModel);
// Load the locales for the locale dropdown
// $Locale = Gdn::Locale();
// $AvailableLocales = $Locale->GetAvailableLocaleSources();
// $this->LocaleData = array_combine($AvailableLocales, $AvailableLocales);
// If seeing the form for the first time...
if (!$this->Form->IsPostback()) {
// Force the webroot using our best guesstimates
$ConfigurationModel->Data['Database.Host'] = 'localhost';
$this->Form->SetData($ConfigurationModel->Data);
} else {
// Define some validation rules for the fields being saved
$ConfigurationModel->Validation->ApplyRule('Database.Name', 'Required', 'You must specify the name of the database in which you want to set up Vanilla.');
// Let's make some user-friendly custom errors for database problems
$DatabaseHost = $this->Form->GetFormValue('Database.Host', '~~Invalid~~');
$DatabaseName = $this->Form->GetFormValue('Database.Name', '~~Invalid~~');
$DatabaseUser = $this->Form->GetFormValue('Database.User', '~~Invalid~~');
$DatabasePassword = $this->Form->GetFormValue('Database.Password', '~~Invalid~~');
$ConnectionString = GetConnectionString($DatabaseName, $DatabaseHost);
try {
$Connection = new PDO($ConnectionString, $DatabaseUser, $DatabasePassword);
} catch (PDOException $Exception) {
switch ($Exception->getCode()) {
case 1044:
$this->Form->AddError(T('The database user you specified does not have permission to access the database. Have you created the database yet? The database reported: <code>%s</code>'), strip_tags($Exception->getMessage()));
break;
case 1045:
$this->Form->AddError(T('Failed to connect to the database with the username and password you entered. Did you mistype them? The database reported: <code>%s</code>'), strip_tags($Exception->getMessage()));
break;
case 1049:
$this->Form->AddError(T('It appears as though the database you specified does not exist yet. Have you created it yet? Did you mistype the name? The database reported: <code>%s</code>'), strip_tags($Exception->getMessage()));
break;
case 2005:
$this->Form->AddError(T("Are you sure you've entered the correct database host name? Maybe you mistyped it? The database reported: <code>%s</code>"), strip_tags($Exception->getMessage()));
break;
default:
$this->Form->AddError(sprintf(T('ValidateConnection'), strip_tags($Exception->getMessage())));
break;
}
}
$ConfigurationModel->Validation->ApplyRule('Garden.Title', 'Required');
$ConfigurationFormValues = $this->Form->FormValues();
if ($ConfigurationModel->Validate($ConfigurationFormValues) !== TRUE || $this->Form->ErrorCount() > 0) {
// Apply the validation results to the form(s)
$this->Form->SetValidationResults($ConfigurationModel->ValidationResults());
} else {
$Host = array_shift(explode(':', Gdn::Request()->RequestHost()));
$Domain = Gdn::Request()->Domain();
// Set up cookies now so that the user can be signed in.
$ExistingSalt = C('Garden.Cookie.Salt', FALSE);
$ConfigurationFormValues['Garden.Cookie.Salt'] = $ExistingSalt ? $ExistingSalt : RandomString(10);
$ConfigurationFormValues['Garden.Cookie.Domain'] = '';
// Don't set this to anything by default. # Tim - 2010-06-23
// Additional default setup values.
$ConfigurationFormValues['Garden.Registration.ConfirmEmail'] = TRUE;
$ConfigurationFormValues['Garden.Email.SupportName'] = $ConfigurationFormValues['Garden.Title'];
$ConfigurationModel->Save($ConfigurationFormValues, TRUE);
// If changing locale, redefine locale sources:
$NewLocale = 'en-CA';
// $this->Form->GetFormValue('Garden.Locale', FALSE);
if ($NewLocale !== FALSE && Gdn::Config('Garden.Locale') != $NewLocale) {
$ApplicationManager = new Gdn_ApplicationManager();
$Locale = Gdn::Locale();
$Locale->Set($NewLocale, $ApplicationManager->EnabledApplicationFolders(), Gdn::PluginManager()->EnabledPluginFolders(), TRUE);
}
// Install db structure & basic data.
$Database = Gdn::Database();
$Database->Init();
$Drop = FALSE;
// Gdn::Config('Garden.Version') === FALSE ? TRUE : FALSE;
$Explicit = FALSE;
try {
include PATH_APPLICATIONS . DS . 'dashboard' . DS . 'settings' . DS . 'structure.php';
} catch (Exception $ex) {
$this->Form->AddError($ex);
}
if ($this->Form->ErrorCount() > 0) {
return FALSE;
}
// Create the administrative user
$UserModel = Gdn::UserModel();
$UserModel->DefineSchema();
$UsernameError = T('UsernameError', 'Username can only contain letters, numbers, underscores, and must be between 3 and 20 characters long.');
$UserModel->Validation->ApplyRule('Name', 'Username', $UsernameError);
$UserModel->Validation->ApplyRule('Name', 'Required', T('You must specify an admin username.'));
//.........这里部分代码省略.........
示例13: ThemeOptions
public function ThemeOptions($Style = NULL)
{
$this->Permission('Garden.Themes.Manage');
try {
$this->AddJsFile('addons.js');
$this->AddSideMenu('dashboard/settings/themeoptions');
$ThemeManager = new Gdn_ThemeManager();
$this->SetData('ThemeInfo', $ThemeManager->EnabledThemeInfo());
if ($this->Form->IsPostBack()) {
// Save the styles to the config.
$StyleKey = $this->Form->GetFormValue('StyleKey');
SaveToConfig(array('Garden.ThemeOptions.Styles.Key' => $StyleKey, 'Garden.ThemeOptions.Styles.Value' => $this->Data("ThemeInfo.Options.Styles.{$StyleKey}.Basename")));
// Save the text to the locale.
$Translations = array();
foreach ($this->Data('ThemeInfo.Options.Text', array()) as $Key => $Default) {
$Value = $this->Form->GetFormValue($this->Form->EscapeString('Text_' . $Key));
$Translations['Theme_' . $Key] = $Value;
//$this->Form->SetFormValue('Text_'.$Key, $Value);
}
if (count($Translations) > 0) {
try {
Gdn::Locale()->SaveTranslations($Translations);
Gdn::Locale()->Refresh();
} catch (Exception $Ex) {
$this->Form->AddError($Ex);
}
}
$this->StatusMessage = T("Your changes have been saved.");
} elseif ($Style) {
SaveToConfig(array('Garden.ThemeOptions.Styles.Key' => $Style, 'Garden.ThemeOptions.Styles.Value' => $this->Data("ThemeInfo.Options.Styles.{$Style}.Basename")));
}
$this->SetData('ThemeOptions', C('Garden.ThemeOptions'));
$StyleKey = $this->Data('ThemeOptions.Styles.Key');
if (!$this->Form->IsPostBack()) {
foreach ($this->Data('ThemeInfo.Options.Text', array()) as $Key => $Options) {
$Default = GetValue('Default', $Options, '');
$Value = T('Theme_' . $Key, '#DEFAULT#');
if ($Value === '#DEFAULT#') {
$Value = $Default;
}
$this->Form->SetFormValue($this->Form->EscapeString('Text_' . $Key), $Value);
}
}
$this->SetData('ThemeFolder', $ThemeManager->EnabledTheme());
$this->Title(T('Theme Options'));
$this->Form->AddHidden('StyleKey', $StyleKey);
} catch (Exception $Ex) {
$this->Form->AddError($Ex);
}
$this->Render();
}
示例14: Translate
/**
* Translates a code into the selected locale's definition.
*
* @param string $Code The code related to the language-specific definition.
* @param string $Default The default value to be displayed if the translation code is not found.
* @return string The translated string or $Code if there is no value in $Default.
*/
public static function Translate($Code, $Default = '')
{
if ($Default == '') {
$Default = $Code;
}
return Gdn::Locale()->Translate($Code, $Default);
}
示例15: DisableApplication
/**
* Undocumented method.
*
* @param string $ApplicationName Undocumented variable.
* @todo Document DisableApplication() method.
*/
public function DisableApplication($ApplicationName) {
// 1. Check to make sure that this application is allowed to be disabled
$ApplicationInfo = ArrayValueI($ApplicationName, $this->AvailableApplications(), array());
$ApplicationName = $ApplicationInfo['Index'];
if (!ArrayValue('AllowDisable', $ApplicationInfo, TRUE))
throw new Exception(sprintf(T('You cannot disable the %s application.'), $ApplicationName));
// 2. Check to make sure that no other enabled applications rely on this one
foreach ($this->EnabledApplications() as $CheckingName => $CheckingInfo) {
$RequiredApplications = ArrayValue('RequiredApplications', $CheckingInfo, FALSE);
if (is_array($RequiredApplications) && array_key_exists($ApplicationName, $RequiredApplications) === TRUE) {
throw new Exception(sprintf(T('You cannot disable the %1$s application because the %2$s application requires it in order to function.'), $ApplicationName, $CheckingName));
}
}
// 2. Disable it
RemoveFromConfig('EnabledApplications'.'.'.$ApplicationName);
// Clear the object caches.
@unlink(PATH_LOCAL_CACHE.'/controller_map.ini');
@unlink(PATH_LOCAL_CACHE.'/library_map.ini');
// Redefine the locale manager's settings $Locale->Set($CurrentLocale, $EnabledApps, $EnabledPlugins, TRUE);
$Locale = Gdn::Locale();
$Locale->Set($Locale->Current(), $this->EnabledApplicationFolders(), Gdn::PluginManager()->EnabledPluginFolders(), TRUE);
}