【问题标题】:Symfony gedmo translatable not workingSymfony gedmo 可翻译无法正常工作
【发布时间】:2018-02-22 17:15:13
【问题描述】:

这是我的 config.yml:

orm:
    auto_generate_proxy_classes: "%kernel.debug%"
    auto_mapping: true
    naming_strategy: doctrine.orm.naming_strategy.underscore
    mappings:
        gedmo_translatable:
            type: annotation
            prefix: Gedmo\Translatable\Entity
            dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Translatable/Entity/MappedSuperclass"
            alias: GedmoTranslatable
            is_bundle: false
    filters:
        softdeleteable:
            class: Gedmo\SoftDeleteable\Filter\SoftDeleteableFilter
            enabled: true
        product_category_filter:
            class: AppBundle\Bundle\CoreBundle\Doctrine\Filter\CategoryFilter
            enabled: false

这是我需要翻译的实体的注释部分:

/**
 * @Gedmo\TranslationEntity(class="AppBundle\Bundle\CoreBundle\Entity\Translation\ProductCategory")
 * @ORM\Entity(repositoryClass="AppBundle\Bundle\CoreBundle\Entity\Repository\ProductCategoryRepository")
 * @ORM\Table(name="product_categories")
 * @Serializer\ExclusionPolicy("none")
 * @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false)
 */

这是翻译实体的注解部分

/**
 * @ORM\Table(name="product_category_translations", indexes={
 *      @ORM\Index(name="product_category_translation_idx", columns={"locale", "object_class", "field", "foreign_key"})
 * })
 * @ORM\Entity(repositoryClass="Gedmo\Translatable\Entity\Repository\TranslationRepository")
 */

但是当我这样做时:

$category->getTitle()

我总是使用英语(非翻译)值,即使我的语言环境不同。

有人知道我做错了什么?

或者我是否在我的问题中遗漏了信息/代码的关键部分?

PS:我使用的是 symfony 2.8

【问题讨论】:

    标签: php symfony translation


    【解决方案1】:

    您需要在 config.yml 中激活它:

    stof_doctrine_extensions:
      default_locale: "%locale%"
      translation_fallback: false
      orm:
        default:
            translatable: true
    

    【讨论】:

      猜你喜欢
      • 2015-11-25
      • 2020-09-17
      • 1970-01-01
      • 1970-01-01
      • 2017-10-10
      • 1970-01-01
      • 1970-01-01
      • 2015-02-25
      • 1970-01-01
      相关资源
      最近更新 更多