Symfony 形式标题中的日语文本
Japanese text in Symfony form titles
我正在从事一个需要使用 Symfony 表单组件的项目,我需要能够为某些字段名称添加汉字。使用英语这很好用:
$form = $this->createFormBuilder()
->add('name', TextType::class)
->add('price', TextType::class)
->getForm();
当我尝试用日语命名任何字段时,出现错误:
Fatal error: Uncaught exception 'Symfony\Component\Form\Exception\InvalidArgumentException' with message 'The name "名" contains illegal characters. Names should start with a letter, digit or underscore and only contain letters, digits, numbers, underscores ("_"), hyphens ("-") and colons (":").
有没有办法只更改字段的显示名称?
$form = $this->createFormBuilder()
->add('name', TextType::class, [
'label' => '名',
])->...
这应该可以完成工作,或者如果您想避免包含特定于语言的字符,可以使用资源文件。
$form = $this->createFormBuilder()
->add('name', TextType::class, [
'label' => form1.name,
])->...
在您的翻译资源文件中(例如 Resources/tranlations/labels.ja.yml)添加内容
form1.name: "名"
我正在从事一个需要使用 Symfony 表单组件的项目,我需要能够为某些字段名称添加汉字。使用英语这很好用:
$form = $this->createFormBuilder()
->add('name', TextType::class)
->add('price', TextType::class)
->getForm();
当我尝试用日语命名任何字段时,出现错误:
Fatal error: Uncaught exception 'Symfony\Component\Form\Exception\InvalidArgumentException' with message 'The name "名" contains illegal characters. Names should start with a letter, digit or underscore and only contain letters, digits, numbers, underscores ("_"), hyphens ("-") and colons (":").
有没有办法只更改字段的显示名称?
$form = $this->createFormBuilder()
->add('name', TextType::class, [
'label' => '名',
])->...
这应该可以完成工作,或者如果您想避免包含特定于语言的字符,可以使用资源文件。
$form = $this->createFormBuilder()
->add('name', TextType::class, [
'label' => form1.name,
])->...
在您的翻译资源文件中(例如 Resources/tranlations/labels.ja.yml)添加内容
form1.name: "名"