当前位置: 首页>>代码示例>>PHP>>正文


PHP Translatable::default_locale方法代码示例

本文整理汇总了PHP中Translatable::default_locale方法的典型用法代码示例。如果您正苦于以下问题:PHP Translatable::default_locale方法的具体用法?PHP Translatable::default_locale怎么用?PHP Translatable::default_locale使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Translatable的用法示例。


在下文中一共展示了Translatable::default_locale方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: alternateFilepathForErrorcode

 /**
  * Alter file path to generated a static (static) error page file to handle error page template on different sub-sites 
  *
  * @see Error::get_filepath_for_errorcode()
  *
  * FIXME since {@link Subsite::currentSubsite()} partly relies on Session, viewing other sub-site (including main site) between 
  * opening ErrorPage in the CMS and publish ErrorPage causes static error page to get generated incorrectly. 
  */
 function alternateFilepathForErrorcode($statusCode, $locale = null)
 {
     $static_filepath = Object::get_static($this->owner->ClassName, 'static_filepath');
     $subdomainPart = "";
     // Try to get current subsite from session
     $subsite = Subsite::currentSubsite(false);
     // since this function is called from Page class before the controller is created, we have to get subsite from domain instead
     if (!$subsite) {
         $subsiteID = Subsite::getSubsiteIDForDomain();
         if ($subsiteID != 0) {
             $subsite = DataObject::get_by_id("Subsite", $subsiteID);
         } else {
             $subsite = null;
         }
     }
     if ($subsite) {
         $subdomain = $subsite->domain();
         $subdomainPart = "-{$subdomain}";
     }
     if (singleton('SiteTree')->hasExtension('Translatable') && $locale && $locale != Translatable::default_locale()) {
         $filepath = $static_filepath . "/error-{$statusCode}-{$locale}{$subdomainPart}.html";
     } else {
         $filepath = $static_filepath . "/error-{$statusCode}{$subdomainPart}.html";
     }
     return $filepath;
 }
开发者ID:hafriedlander,项目名称:silverstripe-config-experiment,代码行数:34,代码来源:ErrorPageSubsite.php

示例2: setUp

 public function setUp()
 {
     parent::setUp();
     //Remap translation group for home pages
     Translatable::disable_locale_filter();
     $default = $this->objFromFixture('Page', 'home');
     $defaultFR = $this->objFromFixture('Page', 'home_fr');
     $defaultFR->addTranslationGroup($default->ID, true);
     Translatable::enable_locale_filter();
     $this->origLocaleRoutingEnabled = Config::inst()->get('MultilingualRootURLController', 'UseLocaleURL');
     Config::inst()->update('MultilingualRootURLController', 'UseLocaleURL', false);
     $this->origDashLocaleEnabled = Config::inst()->get('MultilingualRootURLController', 'UseDashLocale');
     Config::inst()->update('MultilingualRootURLController', 'UseDashLocale', false);
     $this->origAcceptLanguage = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
     $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'en-US,en;q=0.5';
     $this->origCookieLocale = Cookie::get('language');
     Cookie::force_expiry('language');
     $this->origCurrentLocale = Translatable::get_current_locale();
     Translatable::set_current_locale('en_US');
     $this->origLocale = Translatable::default_locale();
     Translatable::set_default_locale('en_US');
     $this->origi18nLocale = i18n::get_locale();
     i18n::set_locale('en_US');
     $this->origAllowedLocales = Translatable::get_allowed_locales();
     Translatable::set_allowed_locales(array('en_US', 'fr_FR'));
     MultilingualRootURLController::reset();
 }
开发者ID:helpfulrobot,项目名称:webbuilders-group-silverstripe-translatablerouting,代码行数:27,代码来源:MultilingualRootURLControllerTest.php

示例3: init

 public function init()
 {
     parent::init();
     // Locale" attribute is either explicitly added by LeftAndMain Javascript logic,
     // or implied on a translated record (see {@link Translatable->updateCMSFields()}).
     // $Lang serves as a "context" which can be inspected by Translatable - hence it
     // has the same name as the database property on Translatable.
     if ($this->getRequest()->requestVar("Locale")) {
         $this->Locale = $this->getRequest()->requestVar("Locale");
     } elseif ($this->getRequest()->requestVar("locale")) {
         $this->Locale = $this->getRequest()->requestVar("locale");
     } else {
         $this->Locale = Translatable::default_locale();
     }
     Translatable::set_current_locale($this->Locale);
     // collect languages for TinyMCE spellchecker plugin.
     // see http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/spellchecker
     $langName = i18n::get_locale_name($this->Locale);
     HtmlEditorConfig::get('cms')->setOption('spellchecker_languages', "+{$langName}={$this->Locale}");
     Requirements::javascript(CMS_DIR . '/javascript/CMSMain.js');
     Requirements::javascript(CMS_DIR . '/javascript/CMSMain.Tree.js');
     Requirements::javascript(CMS_DIR . '/javascript/CMSMain.EditForm.js');
     Requirements::javascript(CMS_DIR . '/javascript/CMSMain.Translatable.js');
     Requirements::css(CMS_DIR . '/css/CMSMain.css');
     CMSBatchActionHandler::register('publish', 'CMSBatchAction_Publish');
     CMSBatchActionHandler::register('unpublish', 'CMSBatchAction_Unpublish');
     CMSBatchActionHandler::register('delete', 'CMSBatchAction_Delete');
     CMSBatchActionHandler::register('deletefromlive', 'CMSBatchAction_DeleteFromLive');
 }
开发者ID:rodneyway,项目名称:silverstripe-cms,代码行数:29,代码来源:CMSMain.php

示例4: getUploadEditorFields

 /**
  * Convenience method to use within a locale context.
  * Eg. by specifying the edit fields with the UploadField.
  * <code>
  * $imageUpload = UploadField::create('Image');
  * $imageUpload->setFileEditFields('getUploadEditorFields');
  * </code>
  * @return FieldList
  */
 public function getUploadEditorFields()
 {
     /** @var FieldList $fields */
     $fields = FieldList::create();
     $translatedFields = TranslatableDataObject::get_localized_class_fields($this->owner->class);
     $transformation = null;
     $defaultLocale = Translatable::default_locale();
     if ($defaultLocale != Translatable::get_current_locale()) {
         /** @var TranslatableFormFieldTransformation $transformation */
         $transformation = TranslatableFormFieldTransformation::create($this->owner);
     }
     foreach ($translatedFields as $fieldName) {
         // create the field in the default locale
         /** @var FormField $field */
         $field = $this->owner->getLocalizedFormField($fieldName, $defaultLocale);
         // use translated title if available
         $field->setTitle(_t('File.' . $fieldName, $fieldName));
         // if not in the default locale, we apply the form field transformation to the field
         if ($transformation) {
             $field = $transformation->transformFormField($field);
         }
         $fields->push($field);
     }
     return $fields;
 }
开发者ID:bummzack,项目名称:translatable-dataobject,代码行数:34,代码来源:TranslatedFile.php

示例5: get_content_languages

 /**
  * Helper method to get content languages from the live DB table.
  * Most of the code is borrowed from the Translatable::get_live_content_languages method.
  * This method operates on "SiteTree" and makes a distinction between Live and Stage.
  * @return array
  */
 public static function get_content_languages()
 {
     $table = Versioned::current_stage() == 'Live' ? 'SiteTree_Live' : 'SiteTree';
     if (class_exists('SQLSelect')) {
         $query = new SQLSelect("Distinct \"Locale\"", "\"{$table}\"");
     } else {
         // SS 3.1 compat
         $query = new SQLQuery("Distinct \"Locale\"", array("\"{$table}\""));
     }
     $query = $query->setGroupBy('"Locale"');
     $dbLangs = $query->execute()->column();
     $langlist = array_merge((array) Translatable::default_locale(), (array) $dbLangs);
     $returnMap = array();
     $allCodes = array_merge(Config::inst()->get('i18n', 'all_locales'), Config::inst()->get('i18n', 'common_locales'));
     foreach ($langlist as $langCode) {
         if ($langCode && isset($allCodes[$langCode])) {
             if (is_array($allCodes[$langCode])) {
                 $returnMap[$langCode] = $allCodes[$langCode]['name'];
             } else {
                 $returnMap[$langCode] = $allCodes[$langCode];
             }
         }
     }
     return $returnMap;
 }
开发者ID:bummzack,项目名称:translatable-dataobject,代码行数:31,代码来源:TranslatableUtility.php

示例6: set_up_once

	static function set_up_once() {
		// needs to recreate the database schema with language properties
		self::kill_temp_db();

		// store old defaults	
		if(class_exists('Translatable')) {
			self::$origTranslatableSettings['has_extension'] = singleton('SiteTree')->hasExtension('Translatable');
			self::$origTranslatableSettings['default_locale'] = Translatable::default_locale();
			
			// overwrite locale
			Translatable::set_default_locale("en_US");

			// refresh the extended statics - different fields in $db with Translatable enabled
			if(self::$origTranslatableSettings['has_extension']) {
				Object::remove_extension('SiteTree', 'Translatable');
				Object::remove_extension('SiteConfig', 'Translatable');
			}
		}

		// recreate database with new settings
		$dbname = self::create_temp_db();
		DB::set_alternative_database_name($dbname);

		parent::set_up_once();
	}
开发者ID:redema,项目名称:silverstripe-cms,代码行数:25,代码来源:SiteTreeTest.php

示例7: setUp

 public function setUp()
 {
     parent::setUp();
     Translatable::disable_locale_filter();
     //Publish all english pages
     $pages = Page::get()->filter('Locale', 'en_US');
     foreach ($pages as $page) {
         $page->publish('Stage', 'Live');
     }
     //Rewrite the french translation groups and publish french pages
     $pagesFR = Page::get()->filter('Locale', 'fr_FR');
     foreach ($pagesFR as $index => $page) {
         $page->addTranslationGroup($pages->offsetGet($index)->ID, true);
         $page->publish('Stage', 'Live');
     }
     Translatable::enable_locale_filter();
     $this->origLocaleRoutingEnabled = Config::inst()->get('MultilingualRootURLController', 'UseLocaleURL');
     Config::inst()->update('MultilingualRootURLController', 'UseLocaleURL', false);
     $this->origDashLocaleEnabled = Config::inst()->get('MultilingualRootURLController', 'UseDashLocale');
     Config::inst()->update('MultilingualRootURLController', 'UseDashLocale', false);
     $this->origAcceptLanguage = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
     $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'en-US,en;q=0.5';
     $this->origCookieLocale = Cookie::get('language');
     Cookie::force_expiry('language');
     Cookie::set('language', 'en');
     $this->origCurrentLocale = Translatable::get_current_locale();
     Translatable::set_current_locale('en_US');
     $this->origLocale = Translatable::default_locale();
     Translatable::set_default_locale('en_US');
     $this->origi18nLocale = i18n::get_locale();
     i18n::set_locale('en_US');
     $this->origAllowedLocales = Translatable::get_allowed_locales();
     Translatable::set_allowed_locales(array('en_US', 'fr_FR'));
     MultilingualRootURLController::reset();
 }
开发者ID:helpfulrobot,项目名称:webbuilders-group-silverstripe-translatablerouting,代码行数:35,代码来源:MultilingualModelAsControllerTest.php

示例8: should_be_on_root

 /**
  * Returns TRUE if a request to a certain page should be redirected to the site root (i.e. if the page acts as the
  * home page).
  *
  * @param SiteTree $page
  * @return bool
  */
 public static function should_be_on_root(SiteTree $page)
 {
     if (!self::$is_at_root && self::get_homepage_link() == trim($page->RelativeLink(true), '/')) {
         return !(class_exists('Translatable') && $page->hasExtension('Translatable') && $page->Locale && $page->Locale != Translatable::default_locale());
     }
     return false;
 }
开发者ID:prostart,项目名称:cobblestonepath,代码行数:14,代码来源:RootURLController.php

示例9: init

 function init()
 {
     $req = $this->owner->getRequest();
     // Ignore being called on LeftAndMain base class,
     // which is the case when requests are first routed through AdminRootController
     // as an intermediary rather than the endpoint controller
     if (!$this->owner->stat('tree_class')) {
         return;
     }
     // Locale" attribute is either explicitly added by LeftAndMain Javascript logic,
     // or implied on a translated record (see {@link Translatable->updateCMSFields()}).
     // $Lang serves as a "context" which can be inspected by Translatable - hence it
     // has the same name as the database property on Translatable.
     $id = $req->param('ID');
     if ($req->requestVar("Locale")) {
         $this->owner->Locale = $req->requestVar("Locale");
     } else {
         if ($id && is_numeric($id)) {
             $record = DataObject::get_by_id($this->owner->stat('tree_class'), $id);
             if ($record && $record->Locale) {
                 $this->owner->Locale = $record->Locale;
             }
         } else {
             $this->owner->Locale = Translatable::default_locale();
             if ($this->owner->class == 'CMSPagesController') {
                 // the CMSPagesController always needs to have the locale set,
                 // otherwise page editing will cause an extra
                 // ajax request which looks weird due to multiple "loading"-flashes
                 $getVars = $req->getVars();
                 if (isset($getVars['url'])) {
                     unset($getVars['url']);
                 }
                 return $this->owner->redirect(Controller::join_links($this->owner->Link(), $req->param('Action'), $req->param('ID'), $req->param('OtherID'), ($query = http_build_query($getVars)) ? "?{$query}" : null));
             }
         }
     }
     Translatable::set_current_locale($this->owner->Locale);
     // If a locale is set, it needs to match to the current record
     $requestLocale = $req->requestVar("Locale");
     $page = $this->owner->currentPage();
     if ($req->httpMethod() == 'GET' && $requestLocale && $page && $page->hasExtension('Translatable') && $page->Locale != $requestLocale && $req->latestParam('Action') != 'EditorToolbar') {
         $transPage = $page->getTranslation($requestLocale);
         if ($transPage) {
             Translatable::set_current_locale($transPage->Locale);
             return $this->owner->redirect(Controller::join_links($this->owner->Link('show'), $transPage->ID));
         } else {
             if ($this->owner->class != 'CMSPagesController') {
                 // If the record is not translated, redirect to pages overview
                 return $this->owner->redirect(Controller::join_links(singleton('CMSPagesController')->Link(), '?Locale=' . $requestLocale));
             }
         }
     }
     // collect languages for TinyMCE spellchecker plugin.
     // see http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/spellchecker
     $langName = i18n::get_locale_name($this->owner->Locale);
     HtmlEditorConfig::get('cms')->setOption('spellchecker_languages', "+{$langName}={$this->owner->Locale}");
     Requirements::javascript('translatable/javascript/CMSMain.Translatable.js');
     Requirements::css('translatable/css/CMSMain.Translatable.css');
 }
开发者ID:helpfulrobot,项目名称:silverstripe-translatable,代码行数:59,代码来源:TranslatableCMSMainExtension.php

示例10: requireDefaultRecords

 public function requireDefaultRecords()
 {
     parent::requireDefaultRecords();
     DB::query(sprintf('UPDATE "ContentModule" SET "Locale" = \'%s\' WHERE "Locale" = \'\' OR "Locale" IS NULL', Translatable::default_locale()));
     DB::query(sprintf('UPDATE "ContentModule_Live" SET "Locale" = \'%s\' WHERE "Locale" = \'\' OR "Locale" IS NULL', Translatable::default_locale()));
     DB::query(sprintf('UPDATE "ContentModule_versions" SET "Locale" = \'%s\' WHERE "Locale" = \'\' OR "Locale" IS NULL', Translatable::default_locale()));
     DB::alteration_message('Updated ContentModule for Translatable', 'changed');
 }
开发者ID:webtorque7,项目名称:inpage-modules,代码行数:8,代码来源:ContentModuleLanguageExtension.php

示例11: PageByDefaultLocale

 /**
  * PageByDefaultLocale
  * gets a page in the default locale
  *
  * @param string $pageURL url of a page in the default locale
  * @return DataObject requested page in the current locale, null if none exists.
  */
 function PageByDefaultLocale($pageURL)
 {
     $defLoc = Translatable::default_locale();
     if ($pg = Translatable::get_one_by_locale('Page', $defLoc, "URLSegment = '{$pageURL}'")) {
         return $pg;
     }
     return null;
 }
开发者ID:kertal,项目名称:Translatable-Domains,代码行数:15,代码来源:SingleLocaleDomain.php

示例12: setUp

 function setUp()
 {
     parent::setUp();
     // whenever a translation is created, canTranslate() is checked
     $cmseditor = $this->objFromFixture('Member', 'cmseditor');
     $cmseditor->logIn();
     $this->origLocale = Translatable::default_locale();
     Translatable::set_default_locale("en_US");
 }
开发者ID:muskie9,项目名称:silverstripe-translatable,代码行数:9,代码来源:TranslatableTest.php

示例13: SortedImages

 public function SortedImages()
 {
     //Debug::dump($this->Images()->Sort('SortOrder')->toArray());
     $obj = $this;
     if (class_exists('Translatable') && $this->Locale != Translatable::default_locale()) {
         $obj = $this->getTranslation(Translatable::default_locale());
     }
     return $obj->Images()->Sort('SortOrder');
 }
开发者ID:helpfulrobot,项目名称:titledk-silverstripe-gallery,代码行数:9,代码来源:GalleryPage.php

示例14: tMaxPhotos

 public function tMaxPhotos()
 {
     if (class_exists("Translatable") && $this->owner->Locale != Translatable::default_locale() && !$this->owner->MaxPhotos()->exists()) {
         $tPage = $this->owner->getTranslation(Translatable::default_locale());
         if ($tPage) {
             return $tPage->MaxPhotos();
         }
     }
     return $this->owner->MaxPhotos();
 }
开发者ID:helpfulrobot,项目名称:silvermax-maxphotos,代码行数:10,代码来源:MaxPhotosPageExtension.php

示例15: onBeforeInit

 /**
  * Handles enabling translations for controllers that are not pages
  */
 public function onBeforeInit()
 {
     //Bail for the root url controller and model as controller classes as they handle this internally, also disable for development admin and cms
     if ($this->owner instanceof MultilingualRootURLController || $this->owner instanceof MultilingualModelAsController || $this->owner instanceof LeftAndMain || $this->owner instanceof DevelopmentAdmin || $this->owner instanceof TestRunner) {
         return;
     }
     //Bail for pages since this would have been handled by MultilingualModelAsController, we're assuming that data has not been set to a page by other code
     if (method_exists($this->owner, 'data') && $this->owner->data() instanceof SiteTree) {
         return;
     }
     //Check if the locale is in the url
     $request = $this->owner->getRequest();
     if ($request && $request->param('Language')) {
         $language = $request->param('Language');
         if (Config::inst()->get('MultilingualRootURLController', 'UseLocaleURL')) {
             $locale = $language;
         } else {
             if (strpos($request->param('Language'), '_') !== false) {
                 //Invalid format so redirect to the default
                 $url = $request->getURL(true);
                 $default = Config::inst()->get('MultilingualRootURLController', 'UseLocaleURL') ? Translatable::default_locale() : Translatable::default_lang();
                 $this->owner->redirect(preg_replace('/^' . preg_quote($language, '/') . '\\//', $default . '/', $url), 301);
                 return;
             } else {
                 $locale = i18n::get_locale_from_lang($language);
             }
         }
         if (in_array($locale, Translatable::get_allowed_locales())) {
             //Set the language cookie
             Cookie::set('language', $language);
             //Set the various locales
             Translatable::set_current_locale($locale);
             i18n::set_locale($locale);
         } else {
             //Unknown language so redirect to the default
             $url = $request->getURL(true);
             $default = Config::inst()->get('MultilingualRootURLController', 'UseLocaleURL') ? Translatable::default_locale() : Translatable::default_lang();
             $this->owner->redirect(preg_replace('/^' . preg_quote($language, '/') . '\\//', $default . '/', $url), 301);
         }
         return;
     }
     //Detect the locale
     if ($locale = MultilingualRootURLController::detect_browser_locale()) {
         if (Config::inst()->get('MultilingualRootURLController', 'UseLocaleURL')) {
             $language = $locale;
         } else {
             $language = i18n::get_lang_from_locale($locale);
         }
         //Set the language cookie
         Cookie::set('language', $language);
         //Set the various locales
         Translatable::set_current_locale($locale);
         i18n::set_locale($locale);
     }
 }
开发者ID:helpfulrobot,项目名称:webbuilders-group-silverstripe-translatablerouting,代码行数:58,代码来源:MultilingualControllerExtension.php


注:本文中的Translatable::default_locale方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。