-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better way to handle translation of forms
The old way is deprecated and will be removed in 1.0
- Loading branch information
1 parent
0c09b7c
commit 9b64928
Showing
2 changed files
with
73 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
{%- block choice_widget_collapsed -%} | ||
{%- if required and placeholder is none and not placeholder_in_choices and not multiple and (attr.size is not defined or attr.size <= 1) -%} | ||
{% set required = false %} | ||
{%- endif -%} | ||
<select {{ block('widget_attributes') }}{% if multiple %} multiple="multiple"{% endif %}> | ||
{%- if placeholder is not none -%} | ||
<option value=""{% if required and value is empty %} selected="selected"{% endif %}>{{ placeholder != '' ? (app.request.get('_locale') is null ? placeholder : l(placeholder)) }}</option> | ||
{%- endif -%} | ||
{%- if preferred_choices|length > 0 -%} | ||
{% set options = preferred_choices %} | ||
{{- block('choice_widget_options') -}} | ||
{%- if choices|length > 0 and separator is not none -%} | ||
<option disabled="disabled">{{ separator }}</option> | ||
{%- endif -%} | ||
{%- endif -%} | ||
{%- set options = choices -%} | ||
{{- block('choice_widget_options') -}} | ||
</select> | ||
{%- endblock choice_widget_collapsed -%} | ||
|
||
{%- block choice_widget_options -%} | ||
{% for group_label, choice in options %} | ||
{%- if choice is iterable -%} | ||
<optgroup label="{{ choice_translation_domain is same as(false) ? group_label : group_label|trans({}, choice_translation_domain) }}"> | ||
{% set options = choice %} | ||
{{- block('choice_widget_options') -}} | ||
</optgroup> | ||
{%- else -%} | ||
{% set attr = choice.attr %} | ||
<option value="{{ choice.value }}" {{ block('attributes') }}{% if choice is selectedchoice(value) %} selected="selected"{% endif %}>{{ app.request.get('_locale') is null ? choice.label : l(choice.label) }}</option> | ||
{%- endif -%} | ||
{% endfor %} | ||
{%- endblock choice_widget_options -%} | ||
|
||
{%- block button_widget -%} | ||
{%- if label is empty -%} | ||
{%- if label_format is not empty -%} | ||
{% set label = label_format|replace({ | ||
'%name%': name, | ||
'%id%': id, | ||
}) %} | ||
{%- else -%} | ||
{% set label = name|humanize %} | ||
{%- endif -%} | ||
{%- endif -%} | ||
<button type="{{ type|default('button') }}" {{ block('button_attributes') }}>{{ app.request.get('_locale') is null ? label : l(label) }}</button> | ||
{%- endblock button_widget -%} | ||
|
||
{%- block form_label -%} | ||
{% if label is not same as(false) -%} | ||
{% if not compound -%} | ||
{% set label_attr = label_attr|merge({'for': id}) %} | ||
{%- endif -%} | ||
{% if required -%} | ||
{% set label_attr = label_attr|merge({'class': (label_attr.class|default('') ~ ' required')|trim}) %} | ||
{%- endif -%} | ||
{% if label is empty -%} | ||
{%- if label_format is not empty -%} | ||
{% set label = label_format|replace({ | ||
'%name%': name, | ||
'%id%': id, | ||
}) %} | ||
{%- else -%} | ||
{% set label = name|humanize %} | ||
{%- endif -%} | ||
{%- endif -%} | ||
<label{% for attrname, attrvalue in label_attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}>{{ app.request.get('_locale') is null ? label : l(label) }}</label> | ||
{%- endif -%} | ||
{%- endblock form_label -%} |