首页 > 解决方案 > 是否可以更改开关的文本?

问题描述

而已。我用谷歌搜索。我什么也没找到。

在此处输入图像描述

标签: octobercms

解决方案


是的,您绝对需要为字段添加其他属性。

你可以在这里找到完整的参考:https ://octobercms.com/docs/backend/forms#field-switch

my_switch:
    label: Yes/No
    type: switch
    comment: Just Example
    on: myauthor.myplugin::lang.models.mymodel.my_switch.on <- this
    off: myauthor.myplugin::lang.models.mymodel.my_switch.off <- n this

现在对于语言文件,请参考:https ://octobercms.com/docs/plugin/localization#file-structure

您需要为此添加语言字符串。或者如果您不希望它用于多语言,您可以直接应用它

my_switch:
    label: Yes/No
    type: switch
    comment: Just Example
    on: Yes <- this
    off: No <- n this

以上示例仅适用于单个表单字段切换。

要使其在后端的整个站点范围内工作,请参考:https ://octobercms.com/docs/plugin/localization#overriding

你需要创建新的语言文件

lang/               <=== App localization directory
  en/               <=== Language directory
    backend/        <=== Plugin / Module directory         
        lang.php    <=== Localization override file

并且你需要添加这个语言数组来覆盖文本、lang.php 文件内容

<?php

return [
    'form' => [
        'field_off' => 'Off',
        'field_on' => 'On'
    ]
];

如有任何疑问,请发表评论。


推荐阅读