symfony - symfony实体函数autput in twig translate
问题描述
在我的项目中,我有属性类型的实体,为了在树枝模板中显示,我使用函数
public function getTypeString(): string
{
$types = self::getPredefinedTypes();
return $types[$this->type];
}
public static function getPredefinedTypes(): array
{
return [
self::PROJECT_TYPE_ONETIME => 'onetime',
self::PROJECT_TYPE_ONGOING => 'ongoing',
];
}
我有我的messages.cs.yaml
project.type.onetime: první typ
project.type.ongoing: druhý typ
在树枝模板中我有
{{'project.type.' ~ project.getTypeString() | trans }}
但这不显示翻译
我如何用这个例子的关键翻译?
解决方案
目前您只翻译 project.getTypeString() 的返回值
{{ 'project.type.' ~ project.getTypeString() | trans }} # only value of project.getTypeString() is being translated
{{ ('project.type.' ~ project.getTypeString())|trans }} # equals 'project.type.onetime'|trans
推荐阅读
- sas - SAS 原始数据导入
- json - '从字符串转换日期和/或时间时转换失败。' 在 SQL Server 中从 JSON 转换时发生错误
- angular - ngFor 不适用于数组
- c# - 为自动生成的列数据网格中的每个复选框注册选中的事件处理程序
- opencv - OpenCV“坐标特定”匹配模板
- angular - 从选择器编译 Angular 组件
- macos - 如何在 Mac OS X 10.13 High Sierra 上安装 Asterisk?
- java - 一个jsp表单中的多个动作
- python - 是否可以从列表中打印变量名
- javascript - 上传目录时如何在 Chrome 中删除警告消息