Jump to:

23376 Posts in 18290 Topics by 2867 members

General Questions

SilverStripe Forums » General Questions » Making an element NOT translatable

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

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

Page: 1
Go to End
Author Topic: 826 Views
  • Futureal
    Avatar
    Community Member
    9 Posts

    Making an element NOT translatable Link to this post

    I have a dual language website,
    and I have added various extra Text fields to my Page class, specific to the website I'm making.
    However, I want these extra fields to be non-translatable, so I want them to have identical content for both languages, and not have to update the field in both languages if something changes.

    How can I do this?
    By default, it translates everything I add to a class...

    Thanks in advance.

  • Futureal
    Avatar
    Community Member
    9 Posts

    Re: Making an element NOT translatable Link to this post

    It's basically an easy question: I have a multilingual website, and all I want is for some fields (like a custom Text or something simple) to be *not* translated, so I want it to be identical in both languages?

    Anyone please?

  • Ingo
    Avatar
    Forum Moderator
    801 Posts

    Re: Making an element NOT translatable Link to this post

    Sorry, thats not possible with the current database row setup. A quick workaround is to create a custom getter, and always retrieve the main translation value.

    function getMyUntranslatedField() {
    $t = $this->getTranslation('en_US');
    return $t ? $t->getField('MyUntranslatedField') : null;
    }

    function getCMSFields() {
    $fields = parent::getCMSFields();
    // avoid the field being edited on translations
    if($this->Locale != 'en_US') $fields->fieldByName('MyUntranslatedField')->makeReadonly();
    return $fields;
    }

    I know its a big limitation of the datamodel, it was a tradeoff...
    I'm looking for help adding this "field exclusion" mechanism to the core if you're keen.

    826 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.