本文整理汇总了PHP中Translatable::get_current_locale方法的典型用法代码示例。如果您正苦于以下问题:PHP Translatable::get_current_locale方法的具体用法?PHP Translatable::get_current_locale怎么用?PHP Translatable::get_current_locale使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Translatable
的用法示例。
在下文中一共展示了Translatable::get_current_locale方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testConvertURLLocaleToTLD
/**
* Test conversion of a url's locale to a TLD
* (make sure a german page shows with a .de extension)
*/
function testConvertURLLocaleToTLD()
{
$orig_locale = Translatable::get_current_locale();
Translatable::set_current_locale('en_US');
$url = "http://www.mysite.co.uk:8888/home/";
$expectedResult = "mysite.com";
$newURL = TranslatableDomains::setDomainByPageLocale($url);
$newURLTLD = TranslatableDomains::getTLD($newURL);
$this->assertTrue($newURLTLD == $expectedResult, "Failed converting {$url} to {$expectedResult}");
Translatable::set_current_locale('de_DE');
$url = "http://mysite.com/home-de/";
$expectedResult = "another.de";
$newURL = TranslatableDomains::setDomainByPageLocale($url);
$newURLTLD = TranslatableDomains::getTLD($newURL);
$this->assertTrue($newURLTLD == $expectedResult, "Failed converting {$url} to {$expectedResult}");
Translatable::set_current_locale('en_GB');
$url = "http://sub.sub.mysite.com/home-gb/";
$expectedResult = "mysite.co.uk";
$newURL = TranslatableDomains::setDomainByPageLocale($url);
$newURLTLD = TranslatableDomains::getTLD($newURL);
$this->assertTrue($newURLTLD == $expectedResult, "Failed converting {$url} to {$expectedResult}");
Translatable::set_current_locale('fr_FR');
$url = "http://sub.localhost-jp/home-fr/";
$expectedResult = "localhost-fr";
$newURL = TranslatableDomains::setDomainByPageLocale($url);
$newURLTLD = TranslatableDomains::getTLD($newURL);
$this->assertTrue($newURLTLD == $expectedResult, "Failed converting {$url} to {$expectedResult}");
Translatable::set_current_locale('ja_JP');
$url = "http://localhost-jp:8888/home-jp/";
$expectedResult = "localhost-jp";
$newURL = TranslatableDomains::setDomainByPageLocale($url);
$newURLTLD = TranslatableDomains::getTLD($newURL);
$this->assertTrue($newURLTLD == $expectedResult, "Failed converting {$url} to {$expectedResult}");
Translatable::set_current_locale($orig_locale);
}
示例2: LanguageChooser
/**
* Returns a DataList containing Pages.
* The provided links point to their translated pages.
* You can use it in templates like this:
*
* <% loop LanguageChooser %>
* $Title, $Current, and any other vars in your page instance
* <% end_loop %>
*
* @return DataList
*/
public function LanguageChooser()
{
if (!Controller::curr()) {
return;
}
if ($langs = Translatable::get_allowed_locales()) {
$data = ArrayList::create();
foreach ($langs as $key => $code) {
if ($code == Translatable::get_current_locale()) {
$this->owner->Current = 'current';
$data->push($this->owner);
} else {
$translation = $this->owner->getTranslation($code);
if ($translation) {
$data->push($translation);
} else {
$page = Translatable::get_one_by_locale("SiteTree", $code, "URLSegment LIKE 'home%'");
if ($page) {
$data->push($page);
}
}
}
}
return $data;
}
return false;
}
示例3: get_homepage_link
/**
* Get the full form (e.g. /home/) relative link to the home page for the current HTTP_HOST value. Note that the
* link is trimmed of leading and trailing slashes before returning to ensure consistency.
*
* @return string
*/
public static function get_homepage_link()
{
if (!self::$cached_homepage_link) {
// @todo Move to 'homepagefordomain' module
if (class_exists('HomepageForDomainExtension')) {
$host = str_replace('www.', null, $_SERVER['HTTP_HOST']);
$candidates = SiteTree::get()->where(array('"SiteTree"."HomepageForDomain" LIKE ?' => "%{$host}%"));
if ($candidates) {
foreach ($candidates as $candidate) {
if (preg_match('/(,|^) *' . preg_quote($host) . ' *(,|$)/', $candidate->HomepageForDomain)) {
self::$cached_homepage_link = trim($candidate->RelativeLink(true), '/');
}
}
}
}
if (!self::$cached_homepage_link) {
// TODO Move to 'translatable' module
if (class_exists('Translatable') && SiteTree::has_extension('Translatable') && ($link = Translatable::get_homepage_link_by_locale(Translatable::get_current_locale()))) {
self::$cached_homepage_link = $link;
} else {
self::$cached_homepage_link = Config::inst()->get('RootURLController', 'default_homepage_link');
}
}
}
return self::$cached_homepage_link;
}
示例4: 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;
}
示例5: 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;
}
示例6: __construct
/**
* Initiate the standard Metadata catalogue search form. The
* additional parameter $defaults defines the default values for the form.
*
* @param Controller $controller The parent controller, necessary to create the appropriate form action tag.
* @param String $name The method on the controller that will return this form object.
* @param FieldSet $fields All of the fields in the form - a {@link FieldSet} of {@link FormField} objects.
* @param FieldSet $actions All of the action buttons in the form - a {@link FieldSet} of {@link FormAction} objects
* @param Validator $validator Override the default validator instance (Default: {@link RequiredFields})
* @param Array $defaults Override the default values of the form.
*/
function __construct($controller, $name, FieldSet $fields = null, FieldSet $actions = null, $validator = null, $defaults = null)
{
$format = $defaults['format'];
$searchTerm = $defaults['searchTerm'];
$bboxUpper = $bboxLower = null;
if (isset($defaults['bboxUpper']) && isset($defaults['bboxLower'])) {
$bboxUpper = $defaults['bboxUpper'];
$bboxLower = $defaults['bboxLower'];
}
$values = CataloguePage_Controller::get_standard_names();
$upperField = new HiddenField('bboxUpper', _t('SearchForm.SEARCH', 'bboxUpper'), $bboxUpper);
$upperField->addExtraClass('upper');
$lowerField = new HiddenField('bboxLower', _t('SearchForm.SEARCH', 'bboxLower'), $bboxLower);
$lowerField->addExtraClass('lower');
if (!$fields) {
$fields = new FieldSet(new TextField('searchTerm', _t('SearchForm.SEARCH', 'Search'), $searchTerm), $upperField, $lowerField, new OptionsetField('format', _t('SearchForm.MetadataStandard', 'Metadata Standard'), $values, $format));
}
if (singleton('SiteTree')->hasExtension('Translatable')) {
$fields->push(new HiddenField('locale', 'locale', Translatable::get_current_locale()));
}
if (!$actions) {
$actions = new FieldSet(new FormAction("submit", _t('SearchForm.Search', 'Search')));
}
parent::__construct($controller, $name, $fields, $actions);
$this->setFormMethod('get');
}
示例7: 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
示例8: output
public function output()
{
// TODO: Refactor into a content-type option
if (\Director::is_ajax()) {
return $this->friendlyErrorMessage;
} else {
// TODO: Refactor this into CMS
if (class_exists('ErrorPage')) {
$errorFilePath = \ErrorPage::get_filepath_for_errorcode($this->statusCode, class_exists('Translatable') ? \Translatable::get_current_locale() : null);
if (file_exists($errorFilePath)) {
$content = file_get_contents($errorFilePath);
if (!headers_sent()) {
header('Content-Type: text/html');
}
// $BaseURL is left dynamic in error-###.html, so that multi-domain sites don't get broken
return str_replace('$BaseURL', \Director::absoluteBaseURL(), $content);
}
}
$renderer = \Debug::create_debug_view();
$output = $renderer->renderHeader();
$output .= $renderer->renderInfo("Website Error", $this->friendlyErrorMessage, $this->friendlyErrorDetail);
if (\Email::config()->admin_email) {
$mailto = \Email::obfuscate(\Email::config()->admin_email);
$output .= $renderer->renderParagraph('Contact an administrator: ' . $mailto . '');
}
$output .= $renderer->renderFooter();
return $output;
}
}
示例9: onBeforeWrite
public function onBeforeWrite()
{
parent::onBeforeWrite();
if (!$this->owner->Locale) {
$this->owner->Locale = Translatable::get_current_locale();
}
}
示例10: 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
示例11: get_homepage_link
/**
* Get the full form (e.g. /home/) relative link to the home page for the current HTTP_HOST value. Note that the
* link is trimmed of leading and trailing slashes before returning to ensure consistency.
*
* @return string
*/
public static function get_homepage_link()
{
if (!self::$cached_homepage_link) {
// TODO Move to 'homepagefordomain' module
if (class_exists('HomepageForDomainExtension')) {
$host = str_replace('www.', null, $_SERVER['HTTP_HOST']);
$SQL_host = Convert::raw2sql($host);
$candidates = DataObject::get('SiteTree', "\"HomepageForDomain\" LIKE '%{$SQL_host}%'");
if ($candidates) {
foreach ($candidates as $candidate) {
if (preg_match('/(,|^) *' . preg_quote($host) . ' *(,|$)/', $candidate->HomepageForDomain)) {
self::$cached_homepage_link = trim($candidate->RelativeLink(true), '/');
}
}
}
}
if (!self::$cached_homepage_link) {
// TODO Move to 'translatable' module
if (class_exists('Translatable') && Object::has_extension('SiteTree', 'Translatable') && ($link = Translatable::get_homepage_link_by_locale(Translatable::get_current_locale()))) {
self::$cached_homepage_link = $link;
} else {
self::$cached_homepage_link = self::get_default_homepage_link();
}
}
}
return self::$cached_homepage_link;
}
示例12: PageByCurrentLocale
/**
* PageByCurrentLocale
* gets a page in the default locale and finds its translation in the current locale
*
* @param string $pageURL url of a page in the default locale
* @return DataObject Translated record of the requested page in the current locale, null if none exists.
*/
function PageByCurrentLocale($pageURL)
{
if ($pg = Translatable::get_one_by_locale('Page', Translatable::default_locale(), "URLSegment = '{$pageURL}'")) {
return $pg->getTranslation(Translatable::get_current_locale());
}
return null;
}
示例13: __construct
/**
* Creates a form object with a free configurable markup.
* Adds the current locale to the custom params.
*
* @param ContentController $controller the calling controller instance
* @param array $params optional parameters
* @param array $preferences optional preferences
* @param bool $barebone defines if a form should only be instanciated or be used too
*
* @return CustomHtmlForm
*
* @author Sebastian Diel <sdiel@pixeltricks.de>
* @since 26.06.2013
*/
public function __construct($controller, $params = null, $preferences = null, $barebone = false)
{
if (is_null($params)) {
$params = array();
}
$params['locale'] = Translatable::get_current_locale();
parent::__construct($controller, $params, $preferences, $barebone);
}
示例14: updateLinkForm
function updateLinkForm(&$form)
{
$field = new LanguageDropdownField('Language', _t('CMSMain.LANGUAGEDROPDOWNLABEL', 'Language'));
$field->setValue(Translatable::get_current_locale());
$field->setForm($form);
$form->Fields()->insertBefore($field, 'internal');
Requirements::javascript('translatable/javascript/HtmlEditorField.Translatable.js');
}
示例15: 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