简体   繁体   English

如何在symfony2中使用translation:update?

[英]How to use translation:update in symfony2?

I have some bundles in a Symfony2 project and I'm running the "translation:update" command to update the translation file for my bundle. 我在Symfony2项目中有一些捆绑软件,并且正在运行“ translation:update”命令来更新捆绑软件的翻译文件。 While most of the parts works well and get the appropriate names, I don't seem to do the same for the form fields in the view files. 尽管大多数部分都能正常工作并获得适当的名称,但对于视图文件中的表单字段,我似乎并没有做同样的事情。 Every time I run the command, I get back only the field name and not the full path I want them to have. 每次运行该命令时,我只会获取字段名称,而不会获取我希望它们具有的完整路径。 For example eg I get fieldname instead of Mybyndle.formlabel. 例如,例如,我得到的是字段名而不是Mybyndle.formlabel。 fieldname . 字段名 I use the label option in the form builder in order for them to have the appropriate name as key and indeed the name changes when I see the form. 我在表单构建器中使用label选项,以便他们将适当的名称作为键,并且实际上,当我看到表单时,名称会更改。 But when I update the translation file, the entry in the file is only the field name. 但是,当我更新翻译文件时,文件中的条目仅是字段名称。

What should I add to my code so that the translation sequence uses the correct format? 我应该在代码中添加些什么,以便翻译序列使用正确的格式?

EDIT: This an example: 编辑:这是一个例子:

  • address.documentnumber.list: __address.documentnumber.list address.documentnumber.list:__ address.documentnumber.list
  • address.documentnumber.new: __address.documentnumber.new address.documentnumber.new:__address.documentnumber.new
  • documentnumber: __documentnumber 文件编号:__ documentnumber
  • issuingAuthority: __issuingAuthority issuingAuthority:__issuingAuthority
  • documentType: __documentType documentType:__documentType

The two first lines are from some tables and have the correct names. 前两行来自某些表,并具有正确的名称。 The other three are the entity field names (?), because they are used as headers in the list and as form field labels in the "add new document" form. 其他三个是实体字段名称(?),因为它们在列表中用作标题,并在“添加新文档”表单中用作表单字段标签。

What I want is to add a prefix name like "address.formlabel." 我想要的是添加一个前缀名称,例如“ address.formlabel”。 in the entity fields. 在实体字段中。

translation:update wouldn't collect translation messages that used in PHP files( controller and forms ). translation:update不会收集PHP文件( controllerforms )中使用的翻译消息。

I suggest to use jms translation , that can collect all translation messages from any place ( forms , controllers , templates , validations ) 我建议使用jms translation ,它可以从任何地方( formscontrollerstemplatesvalidations )收集所有翻译消息。

translation:update wouldn't collect translation messages that used in PHP files(controller and forms). translation:update不会收集PHP文件(控制器和表单)中使用的翻译消息。

Now, since Symfony 4.3 this feature is available, your comment is no longer relevant for new release. 现在,由于Symfony 4.3可以使用此功能,因此您的评论与新版本不再相关。 So you should prefer this official tool than JMS Translation. 因此,您应该比JMS Translation更喜欢此官方工具。

The feature is here: https://github.com/symfony/symfony/pull/30120 该功能在这里: https : //github.com/symfony/symfony/pull/30120

The documentation: https://symfony.com/doc/current/translation.html#extracting-translation-contents-and-updating-catalogs-automatically 说明文件: https//symfony.com/doc/current/translation.html#extracting-translation-contents-and-updating-catalogs-automatically

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM