如何使用messages.en.yml翻译symfony2格式的标签? [英] How to translate labels in symfony2 forms with messages.en.yml?
问题描述
我试图让表单域的翻译工作。我在我的Bundle的Ressource文件夹中有 messages.en.yml
。
测试:它工作
形式:
描述:添加描述。
我想在 EntityType
它相应地转换表单域的标签。
$ builder-> add(
'description',
null,
array ('label'=>'form.description','required'=> false)
);
然而,只有字符串'form.description'
显示,而不是添加描述的预期转换。
翻译服务和 messages.en.yml
正确加载,因为我可以调用
var_dump($ this->在控制器中获得('translator') - > trans('test'));
并获取翻译结果。 p>
当我想将字符串'form.description'
作为应该翻译的内容时,我错过了什么?
我想我必须在它们上调用trans函数,但是我怎样才能自动完成呢?
我必须明确地设置翻译域
/ b>
- > add('description','hidden',
array(
label= >form.description,
required=> true,
'translation_domain'=>'fooo'
)
);
遇到
fooo.de.xlf
I am trying to get translation of form fields to work. I have messages.en.yml
in my Bundle's Ressource folder.
test: it works
form:
description: Add a description.
I want to build a form in an EntityType
which translates the labels of the form fields accordingly.
$builder->add(
'description',
null,
array('label' => 'form.description', 'required' => false)
);
Yet only the literal string 'form.description'
gets shown, not the expected translation of Add a description.
The translation service and the messages.en.yml
are loaded correctly as I can call
var_dump($this->get('translator')->trans('test'));
in a controller and get the translated result.
What am I missing when I want to treat the string 'form.description'
as something that should be translated?
I suppose I have to call the trans function on them anyhow, yet how can I make it in one go automatically?
i had to explicitly set the translation domain
e.g
->add('description','hidden',
array(
"label"=>"form.description",
"required"=>true,
'translation_domain' => 'fooo'
)
);
in case of
fooo.de.xlf
这篇关于如何使用messages.en.yml翻译symfony2格式的标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!