Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

problem about getting dataobjects and pages from another translatable local


Go to End


1256 Views

Avatar
ayyurek

Community Member, 41 Posts

17 June 2010 at 2:33pm

Hello,

I have a problem with translatable extension using getTranslation method.

I built a multilingual site with 5 languages, with en_US as default locale. Many content like Image Galleries, Sliders and Events will be common in every language. I have some basic functions in Page.php for showing last 5 events and etc on the sidebar of the pages.

function TopAttractions($num=3) {
	return DataObject::get("AttractionPage", "FeaturedAtts = 1", "ID DESC", "", $num);
	 }

function UpcomingEvents($num=1) {
	return DataObject::get("Event", "", "Date DESC", "", $num);
    }

How can I create a function to always return the dataobjects from the original locale?
function translatedGalleryImages() {
   $Data = $this -> GalleryImages();
   // Get Dataobjects from Original-Languague-Page
   if ($this->Locale != Translatable::default_locale()) {
      $Data = $this->getTranslation(Translatable::default_locale()) -> GalleryImages();
   }
   return $Data;
}

I used the code below for many times, but I used always for getting the child dataobejects of a page. I think it doesn't work with Pages.
Is there anybody who can help? :)