Choice 字段的翻译标签在 Sonata Admin Datagrid 过滤器中不起作用
Translation label for Choice field are not working in Sonata Admin Datagrid filter
我在 Symfony 2.7 应用程序中使用 Sonata Admin Bundle 和 Sonata User Bundle。我有一个 属性 管理页面。这是它在我的 services.yml:
中的配置
// ...
mybundle.admin.property:
class: MyBundle\Admin\PropertyAdmin
tags:
- { name: sonata.admin, manager_type: orm, group: Property, label: Properties }
arguments:
- ~
- MyBundle\Entity\Property
- 'MyBundle:PropertyAdmin'
我在 属性 管理列表中添加了两个自定义操作按钮。我必须为从 vendor/sonata-project/admin-bundle/Sonata/AdminBundle/Resources/translations/SonataAdminBundle.en.xliff
复制的 app/Resource/SonataAdminBundle/translations/SonataAdminBundle.en.xliff
中的那两个按钮添加两个翻译字符串 action_rooms
和 action_stations
。他们工作正常。
问题是数据网格过滤器中 label_type_yes
和 label_type_no
的翻译不起作用,尽管它们是在 SonataAdminBundle.en.xliff
中定义的。这是 属性 列表的屏幕截图。
我用 SonataAdminBundle.en.xliff
的内容创建了 app/Resources/translations/MyBundle.en.xliff
,并在 services.yml
中为 mybundle.admin.property
添加了 setTranslationDomain
,但没有成功。
calls:
- [setTranslationDomain, ['MyBundle']]
他们也没有在 Sonata User Bundle 生成的用户列表 /admin/sonata/user/user/list
中工作。我注意到在我创建 app/Resource/SonataAdminBundle/translations/SonataAdminBundle.en.xliff
.
之前它不起作用
我在 config.yml 和 parameters.yml 中启用了翻译器。
// config.yml
framework:
translator: { fallbacks: ["%locale%"] }
// parameters.yml
parameters:
// ..
locale: en
首先检查分析器说的是什么,在 2.7 中你可以检查缺失的翻译。只需检查缺少什么翻译并将其放入 app/Resources/translations/MyBundle.en.xliff
我通过添加具有以下内容的 /app/Resources/translations/messages.en.xliff
解决了这个问题:
<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="en" datatype="plaintext" original="file.ext">
<body>
<trans-unit id="filter.label_enabled">
<source>filter.label_enabled</source>
<target>Enabled</target>
</trans-unit>
<trans-unit id="label_type_yes">
<source>label_type_yes</source>
<target>Yes</target>
</trans-unit>
<trans-unit id="label_type_no">
<source>label_type_no</source>
<target>No</target>
</trans-unit>
</body>
</file>
</xliff>
似乎压倒了app/Resource/SonataAdminBundle/translations/SonataAdminBundle.en.xliff
unlike what is said in the symfony documentation.
似乎这是最新奏鸣曲中的错误,因为 label_type_yes/label_type_no 使用 "messages" 域而不是 SonataAdminBundle/SonataCoreBundle。
我在 Symfony 2.7 应用程序中使用 Sonata Admin Bundle 和 Sonata User Bundle。我有一个 属性 管理页面。这是它在我的 services.yml:
中的配置// ...
mybundle.admin.property:
class: MyBundle\Admin\PropertyAdmin
tags:
- { name: sonata.admin, manager_type: orm, group: Property, label: Properties }
arguments:
- ~
- MyBundle\Entity\Property
- 'MyBundle:PropertyAdmin'
我在 属性 管理列表中添加了两个自定义操作按钮。我必须为从 vendor/sonata-project/admin-bundle/Sonata/AdminBundle/Resources/translations/SonataAdminBundle.en.xliff
复制的 app/Resource/SonataAdminBundle/translations/SonataAdminBundle.en.xliff
中的那两个按钮添加两个翻译字符串 action_rooms
和 action_stations
。他们工作正常。
问题是数据网格过滤器中 label_type_yes
和 label_type_no
的翻译不起作用,尽管它们是在 SonataAdminBundle.en.xliff
中定义的。这是 属性 列表的屏幕截图。
我用 SonataAdminBundle.en.xliff
的内容创建了 app/Resources/translations/MyBundle.en.xliff
,并在 services.yml
中为 mybundle.admin.property
添加了 setTranslationDomain
,但没有成功。
calls:
- [setTranslationDomain, ['MyBundle']]
他们也没有在 Sonata User Bundle 生成的用户列表 /admin/sonata/user/user/list
中工作。我注意到在我创建 app/Resource/SonataAdminBundle/translations/SonataAdminBundle.en.xliff
.
我在 config.yml 和 parameters.yml 中启用了翻译器。
// config.yml
framework:
translator: { fallbacks: ["%locale%"] }
// parameters.yml
parameters:
// ..
locale: en
首先检查分析器说的是什么,在 2.7 中你可以检查缺失的翻译。只需检查缺少什么翻译并将其放入 app/Resources/translations/MyBundle.en.xliff
我通过添加具有以下内容的 /app/Resources/translations/messages.en.xliff
解决了这个问题:
<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="en" datatype="plaintext" original="file.ext">
<body>
<trans-unit id="filter.label_enabled">
<source>filter.label_enabled</source>
<target>Enabled</target>
</trans-unit>
<trans-unit id="label_type_yes">
<source>label_type_yes</source>
<target>Yes</target>
</trans-unit>
<trans-unit id="label_type_no">
<source>label_type_no</source>
<target>No</target>
</trans-unit>
</body>
</file>
</xliff>
似乎压倒了app/Resource/SonataAdminBundle/translations/SonataAdminBundle.en.xliff
unlike what is said in the symfony documentation.
似乎这是最新奏鸣曲中的错误,因为 label_type_yes/label_type_no 使用 "messages" 域而不是 SonataAdminBundle/SonataCoreBundle。