Jump to:

3450 Posts in 1063 Topics by 738 members

Data Model Questions

SilverStripe Forums » Data Model Questions » translatable : fallback on specific language if not translated

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

Page: 1
Go to End
Author Topic: 674 Views
  • pac
    Avatar
    Community Member
    25 Posts

    translatable : fallback on specific language if not translated Link to this post

    HI

    in a bilingual site, I have a few pages that will be changed all the time and will never be translated.

    is it possible to display the original content if page is not translated ?
    or, to put it in different words, how can you access english content from a [translatable] french page ?

    same question for a data object...

    thanks for your help

  • martimiz
    Avatar
    Forum Moderator
    1078 Posts

    Re: translatable : fallback on specific language if not translated Link to this post

    I don't think that is possible out of the box... Pages for which no translation exists, will not be displayed on the translated site, so you always need to create a translation.

    I'm thinking maybe it would be possible to create some functionality in the page controller that would check if the current language is the master language, and if not, get the values for some specific field from the masterpage. You might use a boolean to enable/disable this behaviour on a per-page basis...

    This way things like headers, footers and other stuff would still be French, while specific fields (like Content) would be English? The same would work for DataObjects...

    Martine

  • pac
    Avatar
    Community Member
    25 Posts

    Re: translatable : fallback on specific language if not translated Link to this post

    yes exactly what I need.
    not sure how to make that controller though.
    pretty much

    if
    Content_locale empty
    then
    content_en

    same for specific fields and dataObjects

    will try but could use some help

  • martimiz
    Avatar
    Forum Moderator
    1078 Posts

    Re: translatable : fallback on specific language if not translated Link to this post

    I just put something together, that might start as a beginning. What this does is create a custom getter for Content in the Page_Controller that in turn calls some general function useMaster($fieldName). This function does the following:

    - check if the field is empty
    - if so, check if we're using translatable
    - if so, check if the current page is in fact a translation
    - if all true, get the master page and return its contents

    This is all very scetchy, it might lead to something better, probably need a decorator, I don't know... Curious what you make of it...

    class Page_Controller extends ContentController {

       ...

       public function Content() {
          return $this->UseMaster('Content');
       }

       function useMaster($fieldName) {
          if (empty($this->$fieldName)) {
             if (Object::has_extension($this->ClassName, 'Translatable')) {
             $GroupID = $this->getTranslationGroup();
             if ($GroupID && $this->ID != $GroupID) {
                   $Master = DataObject::get_by_id('SiteTree', $GroupID);
                   if (!empty($Master->ID) && $Master->CanView()) {
                      return $Master->$fieldName;
                   }
                }
             }
          }
          return $this->$fieldName;
       }

    Martine

    674 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.