Symfony 形式的包之间的翻译冲突
Translation conflict between bundles in Symfony forms
我创建了一个 Symfony 应用程序并且我在我的应用程序中使用文本翻译。
我的一个包中的翻译覆盖了所有其他包,而翻译是特定于包的,我没有使用 app
级别!
例如,我将这两个包命名为 MessagingBundle
& CongratBundle
并且 Title
键在它们中都定义如下:
src/ITW/CongratBundle/Resources/translations/messages.en.yml:
...
Title: Congrat Title
...
src/ITW/MessagingBundle/Resources/translations/messages.en.yml:
...
Title: Message Title
...
尽管如此,在 MessagingBundle
和 CongratBundle
中,当我使用 {{ "Title"|trans }}
!!
时,我得到 Congrat Title
我正在使用 Symfony 2.5.6
有什么问题?
提取自documentation:
Symfony looks for message files (i.e. translations) in the following
locations:
the app/Resources/translations directory;
the app/Resources//translations directory;
the Resources/translations/ directory inside of any bundle.
The locations are listed here with the highest priority first. That
is, you can override the translation messages of a bundle in any of
the top 2 directories.
我认为这里的重要部分是选项三的任何捆绑包。看起来 Symfony 正在从第一个包(两个包之一)中获取翻译。
我会试试这个:
- 删除包中的翻译目录。
- 创建
app/Resources/CongratBundle/translations
目录并添加其 messages.en.yml
- 创建
app/Resources/MessagingBundle/translations
目录并添加其 messages.en.yml
重要:即使在开发环境中也不要忘记清除缓存:
php app/console cache:clear
希望这能解决问题。
我创建了一个 Symfony 应用程序并且我在我的应用程序中使用文本翻译。
我的一个包中的翻译覆盖了所有其他包,而翻译是特定于包的,我没有使用 app
级别!
例如,我将这两个包命名为 MessagingBundle
& CongratBundle
并且 Title
键在它们中都定义如下:
src/ITW/CongratBundle/Resources/translations/messages.en.yml:
...
Title: Congrat Title
...
src/ITW/MessagingBundle/Resources/translations/messages.en.yml:
...
Title: Message Title
...
尽管如此,在 MessagingBundle
和 CongratBundle
中,当我使用 {{ "Title"|trans }}
!!
Congrat Title
我正在使用 Symfony 2.5.6
有什么问题?
提取自documentation:
Symfony looks for message files (i.e. translations) in the following locations:
the app/Resources/translations directory;
the app/Resources//translations directory;
the Resources/translations/ directory inside of any bundle.
The locations are listed here with the highest priority first. That is, you can override the translation messages of a bundle in any of the top 2 directories.
我认为这里的重要部分是选项三的任何捆绑包。看起来 Symfony 正在从第一个包(两个包之一)中获取翻译。
我会试试这个:
- 删除包中的翻译目录。
- 创建
app/Resources/CongratBundle/translations
目录并添加其messages.en.yml
- 创建
app/Resources/MessagingBundle/translations
目录并添加其messages.en.yml
重要:即使在开发环境中也不要忘记清除缓存:
php app/console cache:clear
希望这能解决问题。