Symfony为单一语言使用多个翻译文件

Symfony为单一语言使用多个翻译文件,symfony,Symfony,我想知道在使用yml文件时,Symfony 3.5是否可以为一种语言使用多个翻译文件 目前我有这样的想法: AppBundle/Resources/translations/messages.en.yml AppBundle/Resources/translations/messages.de.yml 它包含了我所有的两种语言的翻译。但是,我想知道是否可以将其更改为以下结构: AppBundle/Resources/translations/en/products.yml AppBundle/

我想知道在使用yml文件时,Symfony 3.5是否可以为一种语言使用多个翻译文件

目前我有这样的想法:

AppBundle/Resources/translations/messages.en.yml
AppBundle/Resources/translations/messages.de.yml
它包含了我所有的两种语言的翻译。但是,我想知道是否可以将其更改为以下结构:

AppBundle/Resources/translations/en/products.yml
AppBundle/Resources/translations/en/invoices.yml

AppBundle/Resources/translations/de/products.yml
AppBundle/Resources/translations/de/invoices.yml
我一直在寻找,但我一直无法找到某种解决办法。我用它来分割我的路线

AppBundle/Resources/config/routing.yml

appbundle_routes:
  resource: '@AppBundle/Resources/config/routing'
  type: directory
在该文件夹中,我将所有路线拆分为:

AppBundle/Resources/config/routing/products.yml
AppBundle/Resources/config/routing/users.yml
AppBundle/Resources/config/routing/invoices.yml

我想知道是否有可能在翻译中实现同样的效果?

Symfony的
翻译器
要求以
domain.locale.loader
格式命名文件。如果您有
消息.en.yml

  • messages
    是域的默认名称,您还可以指定例如
    invoices
  • en
    是语言环境
  • yml
    正在指定将使用
    YAML
    加载程序
因此,您提议的使用不可能通过标准配置和功能集实现。但是,您可以将翻译拆分为不同的域文件。所以路径应该是:

AppBundle/Resources/translations/products.en.yml
AppBundle/Resources/translations/invoices.en.yml
当您使用translator时,请指定应在其中查找翻译的域:

$translator->trans('translated.key', [], 'invoices');
或在
小树枝中

{{ 'translated.key'|trans({},'invoices') }}

Symfony的
翻译器
要求文件以
域.locale.loader
格式命名。如果您有
消息.en.yml

  • messages
    是域的默认名称,您还可以指定例如
    invoices
  • en
    是语言环境
  • yml
    正在指定将使用
    YAML
    加载程序
因此,您提议的使用不可能通过标准配置和功能集实现。但是,您可以将翻译拆分为不同的域文件。所以路径应该是:

AppBundle/Resources/translations/products.en.yml
AppBundle/Resources/translations/invoices.en.yml
当您使用translator时,请指定应在其中查找翻译的域:

$translator->trans('translated.key', [], 'invoices');
或在
小树枝中

{{ 'translated.key'|trans({},'invoices') }}

啊,谢谢你提供的信息,我想我会看看这个,或者最终写我自己的翻译服务。啊,谢谢你提供的信息,我想我会看看这个,或者最终写我自己的翻译服务。