Sulu:如何使自定义实体可翻译? [英] Sulu: how to make custom entity translatable?

查看:48
本文介绍了Sulu:如何使自定义实体可翻译?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有我的自定义实体类型,按照官方教程创建它:

So I have my custom entity type, created it by following official tutorial:

https://docs.sulu.io/en/2.2/book/extend-admin.html

然而,我得到的实体不像标准页面或文章那样可翻译.我也没有任何关于如何使其可翻译的信息.预期行为只是作为那些标准类型工作.如何实现?

However entity I got is not translatable like i.e. standard pages or articles. I also didn't any info on how to make it translatable. Expected behavior is just to work as those standard types. How to achieve that?

推荐答案

基本上要做三件事:

  1. 您必须为您的自定义实体添加一个新的 Translation 实体.因此,如果您有一个 Event 实体,则需要一个额外的 EventTranslation 实体.请参阅 https://github.com/sulu/sulu-workshop/tree/master/src/Entity

  1. You have to add a new Translation entity for your custom entity. So if you have an Event entity, you need an additional EventTranslation entity. See https://github.com/sulu/sulu-workshop/tree/master/src/Entity

您需要告诉 Sulu,您的自定义实体可通过将可用区域设置添加到您的 AppAdmin 类中的视图来翻译,请参阅 https://github.com/sulu/sulu-workshop/blob/master/src/Admin/EventAdmin.php#L74

You need to tell Sulu, that your custom entity is translatable by adding the available locales to the view in your AppAdmin class, see https://github.com/sulu/sulu-workshop/blob/master/src/Admin/EventAdmin.php#L74

您需要调整自定义实体的管理控制器(它现在会收到一个 locale 请求参数)以将本地化的属性持久化到 CustomEntityTranslation 而不是CustomEntity 自己,见 https://github.com/sulu/sulu-workshop/blob/master/src/Controller/Admin/EventController.php

You need to adjust your custom entity's admin controller (it will receive a locale request parameter now) to persist the localized properties to the CustomEntityTranslation instead of the CustomEntity iself, see https://github.com/sulu/sulu-workshop/blob/master/src/Controller/Admin/EventController.php

总之,Sulu 只负责在右上角显示语言环境切换器,并将当前选择的语言环境作为 locale 参数附加到您的 api 调用中.其他一切完全取决于您,您必须像在普通的 symfony 应用程序中一样实现它

So as conclusion, Sulu is only responsible for showing the locale switcher in the upper right corner and appending the current selected locale as locale parameter to your api calls. Everything else is completely up to you, you have to implement that like in a normal symfony application

这篇关于Sulu:如何使自定义实体可翻译?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆