I'm using Sonata Admin Bundle with Sonata User Bundle in my Symfony 2.7 application. I have a Property Admin page. Here is its configuration in my 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'
I added two custom action buttons in the property admin list. I had to add two translation strings action_rooms
and action_stations
for those two buttons in app/Resource/SonataAdminBundle/translations/SonataAdminBundle.en.xliff
which I copied from vendor/sonata-project/admin-bundle/Sonata/AdminBundle/Resources/translations/SonataAdminBundle.en.xliff
. They are working fine.
The problem is that translation for label_type_yes
and label_type_no
in the datagrid filter is not working although they are defined in SonataAdminBundle.en.xliff
. Here is the screen shot of the property list.
I created app/Resources/translations/MyBundle.en.xliff
with the content of SonataAdminBundle.en.xliff
and I added setTranslationDomain
in services.yml
for mybundle.admin.property
, but no success.
calls:
- [setTranslationDomain, ['MyBundle']]
They are not also working in the user list /admin/sonata/user/user/list
that is generated by Sonata User Bundle. I notice that it was not working before I created app/Resource/SonataAdminBundle/translations/SonataAdminBundle.en.xliff
.
I have the translator enabled in config.yml and parameters.yml.
// config.yml
framework:
translator: { fallbacks: ["%locale%"] }
// parameters.yml
parameters:
// ..
locale: en
I solved this by adding /app/Resources/translations/messages.en.xliff
with the following content:
<?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>
It seems overriding app/Resource/SonataAdminBundle/translations/SonataAdminBundle.en.xliff
unlike what is said in the symfony documentation .
First of all check what profiler says, in 2.7 you have ability to check missing translations. Just check what translation is missing and put it into app/Resources/translations/MyBundle.en.xliff
似乎这是最新Sonata中的错误,因为label_type_yes / label_type_no使用“邮件”域而不是SonataAdminBundle / SonataCoreBundle。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.