简体   繁体   English

选择字段的翻译标签在Sonata Admin Datagrid过滤器中不起作用

[英]Translation label for Choice field are not working in Sonata Admin Datagrid filter

I'm using Sonata Admin Bundle with Sonata User Bundle in my Symfony 2.7 application. 我在Symfony 2.7应用程序中将Sonata Admin Bundle和Sonata User Bundle一起使用。 I have a Property Admin page. 我有一个“属性管理”页面。 Here is its configuration in my services.yml: 这是我的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 . 我必须为app/Resource/SonataAdminBundle/translations/SonataAdminBundle.en.xliff这两个按钮添加两个翻译字符串action_roomsaction_stations ,这些字符串是我从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 . 问题是,尽管在SonataAdminBundle.en.xliff中定义了datagrid过滤器中的label_type_yeslabel_type_no转换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. 我创建app/Resources/translations/MyBundle.en.xliff与内容SonataAdminBundle.en.xliff和我说setTranslationDomainservices.ymlmybundle.admin.property ,但没有成功。

    calls:
        - [setTranslationDomain, ['MyBundle']]

They are not also working in the user list /admin/sonata/user/user/list that is generated by Sonata User Bundle. 它们在Sonata用户捆绑包生成的用户列表/admin/sonata/user/user/list中也不起作用。 I notice that it was not working before I created app/Resource/SonataAdminBundle/translations/SonataAdminBundle.en.xliff . 我注意到在创建app/Resource/SonataAdminBundle/translations/SonataAdminBundle.en.xliff之前,它app/Resource/SonataAdminBundle/translations/SonataAdminBundle.en.xliff

在此处输入图片说明

I have the translator enabled in config.yml and parameters.yml. 我在config.yml和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: 我通过添加/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>

It seems overriding app/Resource/SonataAdminBundle/translations/SonataAdminBundle.en.xliff unlike what is said in the symfony documentation . 与symfony文档中所说的一样 ,似乎覆盖了app/Resource/SonataAdminBundle/translations/SonataAdminBundle.en.xliff

First of all check what profiler says, in 2.7 you have ability to check missing translations. 首先检查探查器所说的内容,在2.7中,您可以检查缺少的翻译。 Just check what translation is missing and put it into app/Resources/translations/MyBundle.en.xliff 只需检查缺少的翻译并将其放入app / Resources / translations / MyBundle.en.xliff

似乎这是最新Sonata中的错误,因为label_type_yes / label_type_no使用“邮件”域而不是SonataAdminBundle / SonataCoreBundle。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM