translatable-dataobject icon indicating copy to clipboard operation
translatable-dataobject copied to clipboard

How to get translations from within another controller?

Open brasileric opened this issue 9 years ago • 1 comments

Hi,

I want to get the translations of the dataobject from within another controller. Is it possible to do that:

Example:

$sms_data_s = DataObject::get_by_id('SMSTemplate', 1)->SMSContent;

I have translations for SMSContent, but don't know how to call them.

brasileric avatar Oct 07 '15 16:10 brasileric

Have you tried using getLocalizedValue or the shortcut T? Eg. Something like this:

$sms_data_s = DataObject::get_by_id('SMSTemplate', 1)->T('SMSContent');

Btw. If you're using SilverStripe 3.1 or newer, I suggest you use the newer syntax to get your DataObject:

$sms_data_s = SMSTemplate::get()->byID(1)->T('SMSContent');

bummzack avatar Oct 21 '15 09:10 bummzack