本文整理汇总了PHP中Translatable::set_current_locale方法的典型用法代码示例。如果您正苦于以下问题:PHP Translatable::set_current_locale方法的具体用法?PHP Translatable::set_current_locale怎么用?PHP Translatable::set_current_locale使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Translatable
的用法示例。
在下文中一共展示了Translatable::set_current_locale方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Languages
/**
* Get a set of content languages (for quick language navigation)
* @example
* <code>
* <!-- in your template -->
* <ul class="langNav">
* <% loop Languages %>
* <li><a href="$Link" class="$LinkingMode" title="$Title.ATT">$Language</a></li>
* <% end_loop %>
* </ul>
* </code>
*
* @return ArrayList|null
*/
public function Languages()
{
$locales = TranslatableUtility::get_content_languages();
// there's no need to show a navigation when there's less than 2 languages. So return null
if (count($locales) < 2) {
return null;
}
$currentLocale = Translatable::get_current_locale();
$homeTranslated = null;
if ($home = SiteTree::get_by_link('home')) {
/** @var SiteTree $homeTranslated */
$homeTranslated = $home->getTranslation($currentLocale);
}
/** @var ArrayList $langSet */
$langSet = ArrayList::create();
foreach ($locales as $locale => $name) {
Translatable::set_current_locale($locale);
/** @var SiteTree $translation */
$translation = $this->owner->hasTranslation($locale) ? $this->owner->getTranslation($locale) : null;
$langSet->push(new ArrayData(array('Locale' => $locale, 'RFC1766' => i18n::convert_rfc1766($locale), 'Language' => DBField::create_field('Varchar', strtoupper(i18n::get_lang_from_locale($locale))), 'Title' => DBField::create_field('Varchar', html_entity_decode(i18n::get_language_name(i18n::get_lang_from_locale($locale), true), ENT_NOQUOTES, 'UTF-8')), 'LinkingMode' => $currentLocale == $locale ? 'current' : 'link', 'Link' => $translation ? $translation->AbsoluteLink() : ($homeTranslated ? $homeTranslated->Link() : ''))));
}
Translatable::set_current_locale($currentLocale);
i18n::set_locale($currentLocale);
return $langSet;
}
示例2: onAfterInit
/**
* Injects some custom javascript to provide instant loading of DataObject
* tables.
*
* @return void
*
* @author Sebastian Diel <sdiel@pixeltricks.de>
* @since 13.01.2011
*/
public function onAfterInit()
{
Translatable::set_current_locale(i18n::get_locale());
if (Director::is_ajax()) {
return true;
}
Requirements::css('silvercart/admin/css/SilvercartMain.css');
}
示例3: getResults
public function getResults($pageLength = null, $data = null)
{
// legacy usage: $data was defaulting to $_REQUEST, parameter not passed in doc.silverstripe.org tutorials
if (!isset($data) || !is_array($data)) {
$data = $_REQUEST;
}
// set language (if present)
if (class_exists('Translatable') && singleton('SiteTree')->hasExtension('Translatable') && isset($data['locale'])) {
$origLocale = Translatable::get_current_locale();
Translatable::set_current_locale($data['locale']);
}
$keywords = $data['Search'];
$andProcessor = create_function('$matches', '
return " +" . $matches[2] . " +" . $matches[4] . " ";
');
$notProcessor = create_function('$matches', '
return " -" . $matches[3];
');
$keywords = preg_replace_callback('/()("[^()"]+")( and )("[^"()]+")()/i', $andProcessor, $keywords);
$keywords = preg_replace_callback('/(^| )([^() ]+)( and )([^ ()]+)( |$)/i', $andProcessor, $keywords);
$keywords = preg_replace_callback('/(^| )(not )("[^"()]+")/i', $notProcessor, $keywords);
$keywords = preg_replace_callback('/(^| )(not )([^() ]+)( |$)/i', $notProcessor, $keywords);
$keywords = $this->addStarsToKeywords($keywords);
if (!$pageLength) {
$pageLength = $this->pageLength;
}
$start = isset($_GET['start']) ? (int) $_GET['start'] : 0;
$siteFilter = '';
$fileFilter = "ID != 0";
$site = Multisites::inst()->getCurrentSite();
$siteFilter = 'SiteID = ' . $site->ID;
if ($this->config()->restrict_files_by_site) {
if ($site->FolderID) {
$prefix = $site->Folder()->Filename;
if (strlen($prefix)) {
$fileFilter .= ' AND "Filename" LIKE \'' . Convert::raw2sql($prefix) . '%\'';
}
}
}
if (strpos($keywords, '"') !== false || strpos($keywords, '+') !== false || strpos($keywords, '-') !== false || strpos($keywords, '*') !== false) {
$results = DB::getConn()->searchEngine($this->classesToSearch, $keywords, $start, $pageLength, "\"Relevance\" DESC", $siteFilter, true, $fileFilter);
} else {
$results = DB::getConn()->searchEngine($this->classesToSearch, $keywords, $start, $pageLength, '', $siteFilter, false, $fileFilter);
}
// filter by permission
if ($results) {
foreach ($results as $result) {
if (!$result->canView()) {
$results->remove($result);
}
}
}
// reset locale
if (class_exists('Translatable') && singleton('SiteTree')->hasExtension('Translatable') && isset($data['locale'])) {
Translatable::set_current_locale($origLocale);
}
return $results;
}
示例4: getExtendedResults
public function getExtendedResults($pageLength = null, $sort = 'Relevance DESC', $filter = '', $data = null)
{
// legacy usage: $data was defaulting to $_REQUEST, parameter not passed in doc.silverstripe.org tutorials
if (!isset($data) || !is_array($data)) {
$data = $_REQUEST;
}
// set language (if present)
if (class_exists('Translatable')) {
if (singleton('SiteTree')->hasExtension('Translatable') && isset($data['searchlocale'])) {
if ($data['searchlocale'] == "ALL") {
Translatable::disable_locale_filter();
} else {
$origLocale = Translatable::get_current_locale();
Translatable::set_current_locale($data['searchlocale']);
}
}
}
$keywords = $data['Search'];
$andProcessor = create_function('$matches', '
return " +" . $matches[2] . " +" . $matches[4] . " ";
');
$notProcessor = create_function('$matches', '
return " -" . $matches[3];
');
$keywords = preg_replace_callback('/()("[^()"]+")( and )("[^"()]+")()/i', $andProcessor, $keywords);
$keywords = preg_replace_callback('/(^| )([^() ]+)( and )([^ ()]+)( |$)/i', $andProcessor, $keywords);
$keywords = preg_replace_callback('/(^| )(not )("[^"()]+")/i', $notProcessor, $keywords);
$keywords = preg_replace_callback('/(^| )(not )([^() ]+)( |$)/i', $notProcessor, $keywords);
$keywords = $this->addStarsToKeywords($keywords);
if (!$pageLength) {
$pageLength = $this->owner->pageLength;
}
$start = isset($_GET['start']) ? (int) $_GET['start'] : 0;
if (strpos($keywords, '"') !== false || strpos($keywords, '+') !== false || strpos($keywords, '-') !== false || strpos($keywords, '*') !== false) {
$results = DB::getConn()->searchEngine($this->owner->classesToSearch, $keywords, $start, $pageLength, $sort, $filter, true);
} else {
$results = DB::getConn()->searchEngine($this->owner->classesToSearch, $keywords, $start, $pageLength);
}
// filter by permission
if ($results) {
foreach ($results as $result) {
if (!$result->canView()) {
$results->remove($result);
}
}
}
// reset locale
if (class_exists('Translatable')) {
if (singleton('SiteTree')->hasExtension('Translatable') && isset($data['searchlocale'])) {
if ($data['searchlocale'] == "ALL") {
Translatable::enable_locale_filter();
} else {
Translatable::set_current_locale($origLocale);
}
}
}
return $results;
}
开发者ID:helpfulrobot,项目名称:nglasl-silverstripe-extensible-search,代码行数:58,代码来源:SearchFormResultsExtension.php
示例5: 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
示例6: updateEditForm
public function updateEditForm(Form $form)
{
$locale = isset($_REQUEST['locale']) ? $_REQUEST['locale'] : $_REQUEST['Locale'];
if (!empty($locale) && i18n::validate_locale($locale) && singleton('SiteConfig')->has_extension('Translatable') && (Translatable::get_allowed_locales() === null || in_array($locale, (array) Translatable::get_allowed_locales(), false)) && $locale != Translatable::get_current_locale()) {
$orig = Translatable::get_current_locale();
Translatable::set_current_locale($locale);
$formAction = $form->FormAction();
$form->setFormAction($formAction);
Translatable::set_current_locale($orig);
}
}
示例7: testCurrentCreatesDefaultForLocale
function testCurrentCreatesDefaultForLocale()
{
Translatable::set_current_locale(Translatable::default_locale());
$configEn = SiteConfig::current_site_config();
Translatable::set_current_locale('fr_FR');
$configFr = SiteConfig::current_site_config();
Translatable::set_current_locale(Translatable::default_locale());
$this->assertInstanceOf('SiteConfig', $configFr);
$this->assertEquals($configFr->Locale, 'fr_FR');
$this->assertEquals($configFr->Title, $configEn->Title, 'Copies title from existing config');
$this->assertEquals($configFr->getTranslationGroup(), $configEn->getTranslationGroup(), 'Created in the same translation group');
}
示例8: tear_down_once
static function tear_down_once()
{
if (self::$origTranslatableSettings['has_extension']) {
Object::add_extension('SiteTree', 'Translatable');
Object::add_extension('SiteConfig', 'Translatable');
}
Translatable::set_default_locale(self::$origTranslatableSettings['default_locale']);
Translatable::set_current_locale(self::$origTranslatableSettings['default_locale']);
self::kill_temp_db();
self::create_temp_db();
parent::tear_down_once();
}
示例9: getCMSFields
public function getCMSFields()
{
$fields = parent::getCMSFields();
$boxes = array();
if ($this->hasExtension('Translatable')) {
$fields->removeByName('Locale');
$fields->insertBefore(new LanguageDropdownField('Locale', _t('CMSMain.LANGUAGEDROPDOWNLABEL', 'Language'), array(), 'SiteTree', 'Locale-English', singleton('SiteTree')), 'Title');
$fields->removeByName('Translations');
Translatable::set_current_locale($this->Locale);
}
foreach (ClassInfo::getValidSubClasses('PromoBox') as $boxClass) {
if ($boxClass != 'PromoBox') {
$instance = singleton($boxClass);
$boxes[$boxClass] = $instance->i18n_singular_name();
}
}
$fields->addFieldToTab('Root.Main', new DropdownField('ClassName', 'Type (save after changing this to see fields)', $boxes, 'ImagePromoBox'));
$fields->removeByName('Pages');
return $fields;
}
示例10: getNestedController
public function getNestedController()
{
if ($this->urlParams['URLSegment']) {
$SQL_URLSegment = Convert::raw2sql($this->urlParams['URLSegment']);
$child = SiteTree::get_by_url($SQL_URLSegment);
if (!$child) {
if ($child = $this->findOldPage($SQL_URLSegment)) {
$url = Controller::join_links(Director::baseURL(), $child->URLSegment, isset($this->urlParams['Action']) ? $this->urlParams['Action'] : null, isset($this->urlParams['ID']) ? $this->urlParams['ID'] : null, isset($this->urlParams['OtherID']) ? $this->urlParams['OtherID'] : null);
$response = new HTTPResponse();
$response->redirect($url, 301);
return $response;
}
$child = $this->get404Page();
}
if ($child) {
if (isset($_REQUEST['debug'])) {
Debug::message("Using record #{$child->ID} of type {$child->class} with URL {$this->urlParams['URLSegment']}");
}
// set language
if ($child->Locale) {
Translatable::set_current_locale($child->Locale);
}
$controllerClass = "{$child->class}_Controller";
if ($this->urlParams['Action'] && ClassInfo::exists($controllerClass . '_' . $this->urlParams['Action'])) {
$controllerClass = $controllerClass . '_' . $this->urlParams['Action'];
}
if (ClassInfo::exists($controllerClass)) {
$controller = new $controllerClass($child);
} else {
$controller = $child;
}
return $controller;
} else {
return new HTTPResponse("The requested page couldn't be found.", 404);
}
} else {
user_error("ModelAsController not geting a URLSegment. It looks like the site isn't redirecting to home", E_USER_ERROR);
}
}
示例11: createtranslation
/**
* Create a new translation from an existing item, switch to this language and reload the tree.
*/
function createtranslation($data, $form)
{
$request = $this->owner->getRequest();
// Protect against CSRF on destructive action
if (!SecurityToken::inst()->checkRequest($request)) {
return $this->owner->httpError(400);
}
$langCode = Convert::raw2sql($request->postVar('NewTransLang'));
$record = $this->owner->getRecord($request->postVar('ID'));
if (!$record) {
return $this->httpError(404);
}
$this->owner->Locale = $langCode;
Translatable::set_current_locale($langCode);
// Create a new record in the database - this is different
// to the usual "create page" pattern of storing the record
// in-memory until a "save" is performed by the user, mainly
// to simplify things a bit.
// @todo Allow in-memory creation of translations that don't persist in the database before the user requests it
$translatedRecord = $record->createTranslation($langCode);
$url = sprintf("%s/%d/?locale=%s", singleton('CMSPageEditController')->Link('show'), $translatedRecord->ID, $langCode);
return $this->owner->redirect($url);
}
示例12: install_locale
/**
* Set/Install the given locale.
* This does set the i18n locale as well as the Translatable or Fluent locale (if any of these modules is installed)
* @param string $locale the locale to install
* @throws Zend_Locale_Exception @see Zend_Locale_Format::getDateFormat and @see Zend_Locale_Format::getTimeFormat
*/
public static function install_locale($locale)
{
// If the locale isn't given, silently fail (there might be carts that still have locale set to null)
if (empty($locale)) {
return;
}
if (class_exists('Translatable')) {
Translatable::set_current_locale($locale);
} else {
if (class_exists('Fluent')) {
Fluent::set_persist_locale($locale);
}
}
// Do something like Fluent does to install the locale
i18n::set_locale($locale);
// LC_NUMERIC causes SQL errors for some locales (comma as decimal indicator) so skip
foreach (array(LC_COLLATE, LC_CTYPE, LC_MONETARY, LC_TIME) as $category) {
setlocale($category, "{$locale}.UTF-8", $locale);
}
// Get date/time formats from Zend
require_once 'Zend/Date.php';
i18n::config()->date_format = Zend_Locale_Format::getDateFormat($locale);
i18n::config()->time_format = Zend_Locale_Format::getTimeFormat($locale);
}
示例13: testSavePageInCMS
function testSavePageInCMS()
{
$adminUser = $this->objFromFixture('Member', 'admin');
$enPage = $this->objFromFixture('Page', 'testpage_en');
$group = new Group();
$group->Title = 'Example Group';
$group->write();
$frPage = $enPage->createTranslation('fr_FR');
$frPage->write();
$adminUser->logIn();
$cmsMain = new CMSMain();
$origLocale = Translatable::get_current_locale();
Translatable::set_current_locale('fr_FR');
$form = $cmsMain->getEditForm($frPage->ID);
$form->loadDataFrom(array('Title' => 'Translated', 'ViewerGroups' => $group->ID));
$form->saveInto($frPage);
$frPage->write();
$this->assertEquals('Translated', $frPage->Title);
$this->assertEquals(array($group->ID), $frPage->ViewerGroups()->column('ID'));
$adminUser->logOut();
Translatable::set_current_locale($origLocale);
}
示例14: onBeforeHandleAction
public function onBeforeHandleAction(SS_HTTPRequest $request, $action)
{
if ($locale = $request->getVar('Locale')) {
Translatable::set_current_locale($locale);
}
}
开发者ID:helpfulrobot,项目名称:webtorque7-inpage-modules,代码行数:6,代码来源:ContentModuleFieldTranslatableExtension.php
示例15: createtranslation
/**
* Create a new translation from an existing item, switch to this language and reload the tree.
*/
function createtranslation($data, $form)
{
$request = $this->owner->getRequest();
// Protect against CSRF on destructive action
if (!SecurityToken::inst()->checkRequest($request)) {
return $this->owner->httpError(400);
}
$langCode = Convert::raw2sql($request->postVar('NewTransLang'));
$record = $this->owner->getRecord($request->postVar('ID'));
if (!$record) {
return $this->owner->httpError(404);
}
$this->owner->Locale = $langCode;
Translatable::set_current_locale($langCode);
// Create a new record in the database - this is different
// to the usual "create page" pattern of storing the record
// in-memory until a "save" is performed by the user, mainly
// to simplify things a bit.
// @todo Allow in-memory creation of translations that don't
// persist in the database before the user requests it
$translatedRecord = $record->createTranslation($langCode);
$url = Controller::join_links($this->owner->Link('show'), $translatedRecord->ID);
// set the X-Pjax header to Content, so that the whole admin panel will be refreshed
$this->owner->getResponse()->addHeader('X-Pjax', 'Content');
return $this->owner->redirect($url);
}