翻译 FormType 中的标签 [英] Translate labels in FormType

查看:41
本文介绍了翻译 FormType 中的标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在表单生成器中翻译标签值.

How can I translate labels values in Form builder.

示例:

->add('google_analytics_key', TextType::class, [
                'label' => 'Analytics Key'
            ])

Analytics Key"是默认语言环境的值.

the "Analytics Key" is the value for the default locale.

我正在使用带有行的表单:

I am using the form with rows:

{{ form_row(myForm.google_analytics_key) }}

这也会使用输入类型呈现标签,因此我无法使用 trans 命令.

This renders the label with input type as well, so I cannot use the trans command.

Symfony/Twig 是否有内置的东西,或者我必须手动实现表单?

Is there something built in Symfony/Twig or I must implement the form manually?

推荐答案

可以添加翻译的域和key

You can add the domain of your translation and the key

例如:

->add('google_analytics_key', TextType::class, [
    'translation_domain' => '<your file name>',//for example 'messages'
    'label' => 'app.analytics_key',
            ])

这篇关于翻译 FormType 中的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆