【问题标题】:Change translation path Symfony and DDD更改翻译路径 Symfony 和 DDD
【发布时间】:2016-12-09 12:28:04
【问题描述】:

我正在使用 DDD 架构在 Symfony 3 中构建 API REST。我的目标是在 ApiBundle 中有以下文件夹。

  • 应用
  • 基础设施
  • 用户界面

我想将我的 Resources/translations/messages.en.yml 文件放在 UserInterface 中(例如:ApiBundle/UserInterface/Resources/translations/messages.en.yml),但我不知道如何通知 Symfony在此文件夹中查找。

我尝试将此代码示例放在我的 config.yml 中的框架键下,但不起作用:

translator:
  fallbacks: ["%locale%"]
  path: "@ApiBundle/UserInterface/Resources/config/translations"

有什么帮助吗?

【问题讨论】:

    标签: php symfony domain-driven-design


    【解决方案1】:

    你在配置中犯了一个错误。正确的参数是 paths(不是 path),它接受值数组:

    # app/config/config.yml
    framework:
        translator:
            paths:
                - '@ApiBundle/UserInterface/Resources/config/translations'
    

    【讨论】:

    • 我使用了你给我的这个配置,并显示以下错误:@ApiBundle/UserInterface/Resources/config/translations defined in translater.paths does not exist or is not a directory 你知道吗为什么?
    • 您必须先创建该翻译文件夹。在运行 cache:clear 或 cache:warmup 之前它必须存在
    【解决方案2】:

    解决办法是

        framework:
                translator:
                    paths:
                       - "%kernel.root_dir%/../src/ApiBundle/UserInterface/Resources/translations"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-02-20
      • 1970-01-01
      • 2017-05-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-23
      • 2011-08-23
      相关资源
      最近更新 更多