本文整理汇总了PHP中Translatable类的典型用法代码示例。如果您正苦于以下问题:PHP Translatable类的具体用法?PHP Translatable怎么用?PHP Translatable使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Translatable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: merge
private function merge(\Gettext_Translations $current, Translatable $parent, $locale)
{
$parent_loader = $parent->loadExisting($locale);
$comment = "Copied from {$parent->id}/{$locale}";
foreach ($current->entries as $entry_id => &$entry) {
if (isset($parent_loader->entries[$entry_id]) && (empty($entry->translations) || $entry->translator_comments == $comment)) {
if ($translations = $parent_loader->entries[$entry_id]->translations) {
$entry->translator_comments = $comment;
$entry->translations = $translations;
}
}
}
}
示例2: __construct
/**
* Create a new LanguageDropdownField
* @param string $name
* @param string $title
* @param array $dontInclude list of languages that won't be included
* @param string $translatingClass Name of the class with translated instances where to look for used languages
* @param string $list Indicates the source language list. Can be either Common-English, Common-Native Locale
*/
function __construct($name, $title, $dontInclude = array(), $translatingClass = 'SiteTree', $list = 'Common-English')
{
$usedlangs = array_diff(i18n::get_existing_content_languages($translatingClass), $dontInclude);
// we accept in dontInclude both language codes and names, so another diff is required
$usedlangs = array_diff($usedlangs, array_flip($dontInclude));
if (isset($usedlangs[Translatable::default_lang()])) {
unset($usedlangs[Translatable::default_lang()]);
}
if ('Common-English' == $list) {
$languageList = i18n::get_common_languages();
} else {
if ('Common-Native' == $list) {
$languageList = i18n::get_common_languages(true);
} else {
$languageList = i18n::get_locale_list();
}
}
$alllangs = array_diff($languageList, (array) $usedlangs, $dontInclude);
$alllangs = array_flip(array_diff(array_flip($alllangs), $dontInclude));
if (isset($alllangs[Translatable::default_lang()])) {
unset($alllangs[Translatable::default_lang()]);
}
asort($alllangs);
if (count($usedlangs)) {
asort($usedlangs);
$labelAvail = _t('Form.LANGAVAIL', "Available languages");
$labelOther = _t('Form.LANGAOTHER', "Other languages");
parent::__construct($name, $title, array($labelAvail => $usedlangs, $labelOther => $alllangs), reset($usedlangs));
} else {
parent::__construct($name, $title, $alllangs);
}
}
示例3: 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;
}
示例4: __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');
}
示例5: init
public function init()
{
// set reading lang
if (SiteTree::has_extension('Translatable') && !$this->getRequest()->isAjax()) {
Translatable::choose_site_locale(array_keys(Translatable::get_existing_content_languages('SiteTree')));
}
parent::init();
Versioned::reading_stage("Stage");
Requirements::css(CMS_DIR . '/css/screen.css');
Requirements::customCSS($this->generatePageIconsCss());
Requirements::combine_files('cmsmain.js', array_merge(array(CMS_DIR . '/javascript/CMSMain.js', CMS_DIR . '/javascript/CMSMain.EditForm.js', CMS_DIR . '/javascript/CMSMain.AddForm.js', CMS_DIR . '/javascript/CMSPageHistoryController.js', CMS_DIR . '/javascript/CMSMain.Tree.js', CMS_DIR . '/javascript/SilverStripeNavigator.js', CMS_DIR . '/javascript/SiteTreeURLSegmentField.js'), Requirements::add_i18n_javascript(CMS_DIR . '/javascript/lang', true, true)));
CMSBatchActionHandler::register('publish', 'CMSBatchAction_Publish');
CMSBatchActionHandler::register('unpublish', 'CMSBatchAction_Unpublish');
// Check legacy actions
$legacy = $this->config()->enabled_legacy_actions;
// Delete from live is unnecessary since we have unpublish which does the same thing
if (in_array('CMSBatchAction_DeleteFromLive', $legacy)) {
Deprecation::notice('4.0', 'Delete From Live is deprecated. Use Un-publish instead');
CMSBatchActionHandler::register('deletefromlive', 'CMSBatchAction_DeleteFromLive');
}
// Delete action
if (in_array('CMSBatchAction_Delete', $legacy)) {
Deprecation::notice('4.0', 'Delete from Stage is deprecated. Use Archive instead.');
CMSBatchActionHandler::register('delete', 'CMSBatchAction_Delete');
} else {
CMSBatchActionHandler::register('archive', 'CMSBatchAction_Archive');
CMSBatchActionHandler::register('restore', 'CMSBatchAction_Restore');
}
}
示例6: 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;
}
示例7: run
function run(SS_List $pages)
{
$status = array('translated' => array(), 'error' => array());
foreach ($pages as $page) {
$id = $page->ID;
foreach (Translatable::get_allowed_locales() as $locale) {
if ($page->Locale == $locale) {
continue;
}
if (!$page->hasTranslation($locale)) {
try {
$translation = $page->createTranslation($locale);
$successMessage = $this->duplicateRelations($page, $translation);
$status['translated'][$translation->ID] = array('TreeTitle' => $translation->TreeTitle);
$translation->destroy();
unset($translation);
} catch (Exception $e) {
// no permission - fail gracefully
$status['error'][$page->ID] = true;
}
}
}
$page->destroy();
unset($page);
}
return $this->response(_t('CMSBatchActions.TRANSLATED_PAGES', 'Translated %d pages to draft site, %d failures'), $status);
}
示例8: 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;
}
示例9: 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;
}
示例10: init
public function init() {
// set reading lang
if(Object::has_extension('SiteTree', 'Translatable') && !$this->request->isAjax()) {
Translatable::choose_site_locale(array_keys(Translatable::get_existing_content_languages('SiteTree')));
}
parent::init();
Requirements::css(CMS_DIR . '/css/screen.css');
Requirements::combine_files(
'cmsmain.js',
array_merge(
array(
CMS_DIR . '/javascript/CMSMain.js',
CMS_DIR . '/javascript/CMSMain.EditForm.js',
CMS_DIR . '/javascript/CMSMain.AddForm.js',
CMS_DIR . '/javascript/CMSPageHistoryController.js',
CMS_DIR . '/javascript/CMSMain.Tree.js',
CMS_DIR . '/javascript/SilverStripeNavigator.js'
),
Requirements::add_i18n_javascript(CMS_DIR . '/javascript/lang', true, true)
)
);
CMSBatchActionHandler::register('publish', 'CMSBatchAction_Publish');
CMSBatchActionHandler::register('unpublish', 'CMSBatchAction_Unpublish');
CMSBatchActionHandler::register('delete', 'CMSBatchAction_Delete');
CMSBatchActionHandler::register('deletefromlive', 'CMSBatchAction_DeleteFromLive');
}
示例11: testUpdateCMSFieldsOnSiteTree
function testUpdateCMSFieldsOnSiteTree() {
$pageOrigLang = $this->objFromFixture('Page', 'home');
// first test with default language
$fields = $pageOrigLang->getCMSFields();
$this->assertType(
'TextField',
$fields->dataFieldByName('Title'),
'Translatable doesnt modify fields if called in default language (e.g. "non-translation mode")'
);
$this->assertNull(
$fields->dataFieldByName('Title_original'),
'Translatable doesnt modify fields if called in default language (e.g. "non-translation mode")'
);
// then in "translation mode"
$pageTranslated = Translatable::get_one_by_lang('Page',"fr", "ID = $pageOrigLang->ID");
$fields = $pageTranslated->getCMSFields();
$this->assertType(
'TextField',
$fields->dataFieldByName('Title'),
'Translatable leaves original formfield intact in "translation mode"'
);
$readonlyField = $fields->dataFieldByName('Title')->performReadonlyTransformation();
$this->assertType(
$readonlyField->class,
$fields->dataFieldByName('Title_original'),
'Translatable adds the original value as a ReadonlyField in "translation mode"'
);
}
示例12: 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;
}
}
示例13: getNestedController
public function getNestedController()
{
if ($this->urlParams['URLSegment']) {
$SQL_URLSegment = Convert::raw2sql($this->urlParams['URLSegment']);
if (Translatable::is_enabled()) {
$child = Translatable::get_one("SiteTree", "URLSegment = '{$SQL_URLSegment}'");
} else {
$child = DataObject::get_one("SiteTree", "URLSegment = '{$SQL_URLSegment}'");
}
if (!$child) {
$child = $this->get404Page();
}
if ($child) {
if (isset($_REQUEST['debug'])) {
Debug::message("Using record #{$child->ID} of type {$child->class} with URL {$this->urlParams['URLSegment']}");
}
$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;
}
$controller->setURLParams($this->urlParams);
return $controller;
} else {
die("The requested page couldn't be found.");
}
} else {
user_error("ModelAsController not geting a URLSegment. It looks like the site isn't redirecting to home", E_USER_ERROR);
}
}
示例14: sitemap
/**
* We need to disable Translatable before retreiving the DataObjects or
* Pages for the sitemap, because otherwise only pages in the default
* language are found.
*
* Next we need to add the alternatives for each Translatable Object
* included in the sitemap: basically these are the Translations plus
* the current object itself
*
* @return Array
*/
public function sitemap()
{
Translatable::disable_locale_filter();
$sitemap = parent::sitemap();
Translatable::enable_locale_filter();
$updatedItems = new ArrayList();
foreach ($sitemap as $items) {
foreach ($items as $item) {
if ($item->hasExtension('Translatable')) {
$translations = $item->getTranslations();
if ($translations) {
$alternatives = new ArrayList();
foreach ($translations as $translation) {
$translation->GoogleLocale = $this->getGoogleLocale($translation->Locale);
$alternatives->push($translation);
}
$item->GoogleLocale = $this->getGoogleLocale($item->Locale);
$alternatives->push($item);
$item->Alternatives = $alternatives;
}
$updatedItems->push($item);
}
}
}
if (!empty($updatedItems)) {
return array('Items' => $updatedItems);
} else {
return $sitemap;
}
}
开发者ID:helpfulrobot,项目名称:martimiz-silverstripe-translatablegooglesitemaps,代码行数:41,代码来源:TranslatableGoogleSitemapController.php
示例15: onBeforeWrite
public function onBeforeWrite()
{
parent::onBeforeWrite();
if (!$this->owner->Locale) {
$this->owner->Locale = Translatable::get_current_locale();
}
}