包含默认内容的Sonata管理员翻译

时间:2018-01-19 16:13:39

标签: symfony localization translation sonata-admin

我可以使用Gedmo Doctrine Extensions

设置包含翻译实体的Sonata Admin
# Doctrine Extensions Configuration
stof_doctrine_extensions:
    default_locale: '%locale%'
    orm:
        default:
            timestampable: true
            blameable: true
            translatable: true

# Sonata Translation Configuration
sonata_translation:
    locales: [en, fr, it]
    default_locale: '%locale%'
    gedmo:
        enabled: true

但是,每次创建新实体时,其他语言中的可翻译字段都将为空。

选择了英语:

enter image description here

选择了意大利语:

enter image description here

如果我不知道他们的英语是什么,翻译项目就会变得非常困难

是否有一个选项,以便在我用英语创建实体时,它还填充其他语言中具有相同内容的实体?

2 个答案:

答案 0 :(得分:2)

您应该为您需要的字段添加后备选项:

gpm

答案 1 :(得分:0)

我猜你忘了加载事件监听器服务。 对于每个Gedmo扩展(Timestampable,Blameable,可翻译等),您必须在服务容器中注册服务。

For Translatable:

    ## app/config/services.yml

    services:

        ## ...

        gedmo.listener.translatable:
        class: Gedmo\Translatable\TranslatableListener
        tags:
            - { name: doctrine.event_subscriber, connection: default }
        calls:
            - [ setAnnotationReader, [ @annotation_reader ] ]
            - [ setDefaultLocale, [ %locale% ] ]
            - [ setTranslationFallback, [ false ] ]