【发布时间】:2021-06-15 15:03:18
【问题描述】:
上下文
我实际上是在尝试更改OroDateTimeType::class 的时间输入的默认占位符。
例如,我想要文本 Horaires 而不是 Temps。
这是我的 FormType 中的表单字段:
->add('expirationDate', OroDateTimeType::class, [
'label' => 'app.subscription.fields.expirationDate',
])
在我的树枝视图中:
form_row(form.expirationDate)
问题
一开始,我尝试将 Symfony 4 placeholder 选项用于 DateTime 类型:https://symfony.com/doc/4.4/reference/forms/types/date.html#placeholder。它不起作用,因为OroDateTime 使用了不同的日期选择器,并且它在加载时覆盖了 Symfony 值:
{# vendor/oro/platform/src/Oro/Bundle/FormBundle/Resources/views/Form/fields.html.twig #}
{% block oro_datetime_widget %}
{% set dateValidation = {'Date' : {}} %}
{% set timeValidation = {'Time' : {}} %}
{% if required %}
{% set dateValidation = dateValidation|merge({'NotBlank' : {}}) %}
{% set timeValidation = timeValidation|merge({'NotBlank' : {}}) %}
{% endif %}
{% if attribute(attr, 'class') is defined %}
{% set attrClass = attr['class'] %}
{% else %}
{% set attrClass = '' %}
{% endif %}
{% set options = {
view: 'oroui/js/app/views/datepicker/datetimepicker-view',
nativeMode: isMobileVersion(),
dateInputAttrs: {
placeholder: 'oro.form.choose_date'|trans,
id: id,
name: id,
class: 'input-small datepicker-input ' ~ attrClass,
'data-validation': dateValidation|json_encode(constant('JSON_FORCE_OBJECT')),
'aria-live': 'assertive',
autocomplete: 'off',
autocorrect: 'off',
autocapitalize: 'off'
},
datePickerOptions: {
altFormat: 'yy-mm-dd',
changeMonth: true,
changeYear: true,
yearRange: years|default('-80:+1'),
showButtonPanel: true
},
timeInputAttrs: {
placeholder: 'oro.form.choose_time'|trans,
id: 'time_selector_' ~ id,
name: 'time_selector_' ~ id,
class: 'input-small timepicker-input ' ~ attrClass,
'data-validation': timeValidation|json_encode(constant('JSON_FORCE_OBJECT'))
},
timePickerOptions: {
}
} %}
{% set id = 'hidden_' ~ id %}
{% set attr = attr|merge({
'data-page-component-module': 'oroui/js/app/components/view-component',
'data-page-component-options': options|json_encode(constant('JSON_FORCE_OBJECT'))
}) %}
{{ block('datetime_widget') }}
{% endblock oro_datetime_widget %}
如果我从 options 变量中更改值 timeInputAttrs.placeholder。有用。
但是,我想将此变量传递给我的特定表单字段,而不是全局传递。
更新
我最终选择在全局更改我的项目中的oro.form.choose_time 翻译。
所以,在我的Resources/translations/messages.fr_FR.yml 中,我创建了这些行:
oro:
form:
choose_time: Horaires
auth:
description:
main: Baltimore
然后,我了解到翻译是在位于var/cache/dev/translations/catalogue.fr_FR 的文件中生成的:
<?php
use Symfony\Component\Translation\MessageCatalogue;
$catalogue = new MessageCatalogue('fr_FR', array (
'messages' =>
array (
'oro.form.choose_time' => 'Temps',
'oro.auth.description.main' => 'Baltimore',
在这里,我可以看到 oro.auth.description.main 更改已应用,但键 oro.form.choose_time 的值仍然相同。
也许我有一个命令要运行?
【问题讨论】:
-
当您已经使用来自 Crowdin 的更新或 UI 中的手动编辑覆盖翻译时,将不再应用 YAML 更改。在这种情况下,您必须编写数据迁移来更新数据库中加载的翻译。
标签: symfony orocrm orocommerce