例如,我有一个可翻译的模型:
class Settings extends Model {
public $implement = [
'System.Behaviors.SettingsModel',
'RainLab.Translate.Behaviors.TranslatableModel'
];
public $settingsCode = 'zollerboy_customtheme_settings';
public $settingsFields = 'fields.yaml';
public $translatable = [
'site_name',
//I have a lot more here
];
}
我的fields.yaml
如下:
tabs:
fields:
site_name:
tab: Info
label: Website Name
type: text
# And so on ...
是否可以为字段site_name
设置每种语言的默认值?
我尝试过
default: name.plugin::lang.settings.default.site_name
但这似乎仅适用于标签,但不适用于默认值。
答案 0 :(得分:0)
是的,默认选项不适用于翻译,但是您可以通过小部件形式显示此字段,从而在可视化方法中获取默认值。
public function render() {
$value= Lang::get('name.plugin::lang.settings.default.site_name');
return $this->makePartial('site_name', ['value' => $value, 'name' =>
'site_name']);
}
通过覆盖Plugin注册类中的registerFormWidgets方法来注册表单小部件。
public function registerFormWidgets() {
return [
'Name\Plugin\FormWidgets\SiteName' => 'site_name'
];
}
fields.yaml示例:
tabs:
fields:
site_name:
tab: Info
label: Website Name
type: site_name
# And so on ...