在我的SilverStripe项目中,我有一个控制器,我用cronjob调用。但是在这个控制器中我想使用yaml语言文件中的翻译。所以我想设置语言环境以使用正确的翻译。我试图做这样的事情,但这不起作用:
class CronController extends Controller {
public function opendataform() {
i18n::set_locale('it_IT');
$Params = $this->getURLParams();
self::$ad = $Params['ID'];
$selectMemberSelectionField = new DropdownField('SelectionName', _t('General.CHOOSE_SELECTION', "Choose selection"), MemberSelection::get()->map('ID', 'Name'));
$fields = new FieldList($selectMemberSelectionField);
$actions = new FieldList(
FormAction::create("doOpen")->setTitle(_t('General.Open', "Open"))
);
$form = new Form($this, 'OpenForm', $fields, $actions);
return $form;
}
}
还试过:Translatable :: set_current_locale(' it_IT');
有什么建议吗?提前谢谢!