Skip to content

Commit

Permalink
Fix multiple partial translations (#354)
Browse files Browse the repository at this point in the history
  • Loading branch information
adelinerobinet authored Dec 15, 2021
1 parent 880f9ae commit 821ebd2
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/Resources/views/macros.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Example:
{% set locale = translationsFields.vars.name %}

<li class="nav-item">
<a href="#{{ translationsFields.vars.id }}_a2lix_translations-fields" class="nav-link {% if app.request.locale == locale %}active{% endif %}" data-toggle="tab" role="tab">
<a href="#{{ translationsFields.vars.id }}_{{ fieldsNames|join('_') }}_a2lix_translations-fields" class="nav-link {% if app.request.locale == locale %}active{% endif %}" data-toggle="tab" role="tab">
{{ translationsFields.vars.label|default(locale|humanize)|trans }}
{% if form.vars.default_locale == locale %}{{ '[Default]'|trans }}{% endif %}
{% if translationsFields.vars.required %}*{% endif %}
Expand All @@ -29,7 +29,7 @@ Example:
{% for translationsFields in form %}
{% set locale = translationsFields.vars.name %}

<div id="{{ translationsFields.vars.id }}_a2lix_translations-fields" class="tab-pane {% if app.request.locale == locale %}show active{% endif %} {% if not form.vars.valid %}sonata-ba-field-error{% endif %}" role="tabpanel">
<div id="{{ translationsFields.vars.id }}_{{ fieldsNames|join('_') }}_a2lix_translations-fields" class="tab-pane {% if app.request.locale == locale %}show active{% endif %} {% if not form.vars.valid %}sonata-ba-field-error{% endif %}" role="tabpanel">
{% for translationsField in translationsFields|filter(translationsField => translationsField.vars.name in fieldsNames) %}
{{ form_row(translationsField) }}
{% endfor %}
Expand Down
4 changes: 2 additions & 2 deletions src/Resources/views/macros_bootstrap_3.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Example:
{% set locale = translationsFields.vars.name %}

<li{% if app.request.locale == locale %} class="active"{% endif %}>
<a href="#{{ translationsFields.vars.id }}_a2lix_translations-fields" data-toggle="tab" role="tab">
<a href="#{{ translationsFields.vars.id }}_{{ fieldsNames|join('_') }}_a2lix_translations-fields" data-toggle="tab" role="tab">
{{ translationsFields.vars.label|default(locale|humanize)|trans }}
{% if form.vars.default_locale == locale %}{{ '[Default]'|trans }}{% endif %}
{% if translationsFields.vars.required %}*{% endif %}
Expand All @@ -27,7 +27,7 @@ Example:
{% for translationsFields in form %}
{% set locale = translationsFields.vars.name %}

<div id="{{ translationsFields.vars.id }}_a2lix_translations-fields" class="tab-pane {% if app.request.locale == locale %}active{% endif %} {% if not form.vars.valid %}sonata-ba-field-error{% endif %}" role="tabpanel">
<div id="{{ translationsFields.vars.id }}_{{ fieldsNames|join('_') }}_a2lix_translations-fields" class="tab-pane {% if app.request.locale == locale %}active{% endif %} {% if not form.vars.valid %}sonata-ba-field-error{% endif %}" role="tabpanel">
{% for translationsField in translationsFields|filter(translationsField => translationsField.vars.name in fieldsNames) %}
{{ form_row(translationsField) }}
{% endfor %}
Expand Down
38 changes: 38 additions & 0 deletions src/Resources/views/macros_bootstrap_4.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{#
Example:
{% import "@A2lixTranslationForm/macros_bootstrap_4.html.twig" as a2lixTranslations %}
{{ a2lixTranslations.partialTranslations(editForm.translations, ['title','description']) }}
{{ a2lixTranslations.partialTranslations(editForm.translations, ['url']) }}
#}

{% macro partialTranslations(form, fieldsNames) %}
{{ form_errors(form) }}

<div class="a2lix_translations">
<ul class="a2lix_translationsLocales nav nav-tabs" role="tablist">
{% for translationsFields in form %}
{% set locale = translationsFields.vars.name %}

<li{% if app.request.locale == locale %} class="active"{% endif %}>
<a href="#{{ translationsFields.vars.id }}_{{ fieldsNames|join('_') }}_a2lix_translations-fields" data-toggle="tab" role="tab">
{{ translationsFields.vars.label|default(locale|humanize)|trans }}
{% if form.vars.default_locale == locale %}{{ '[Default]'|trans }}{% endif %}
{% if translationsFields.vars.required %}*{% endif %}
</a>
</li>
{% endfor %}
</ul>

<div class="a2lix_translationsFields tab-content">
{% for translationsFields in form %}
{% set locale = translationsFields.vars.name %}

<div id="{{ translationsFields.vars.id }}_{{ fieldsNames|join('_') }}_a2lix_translations-fields" class="tab-pane {% if app.request.locale == locale %}active{% endif %} {% if not form.vars.valid %}sonata-ba-field-error{% endif %}" role="tabpanel">
{% for translationsField in translationsFields|filter(translationsField => translationsField.vars.name in fieldsNames) %}
{{ form_row(translationsField) }}
{% endfor %}
</div>
{% endfor %}
</div>
</div>
{% endmacro %}
38 changes: 38 additions & 0 deletions src/Resources/views/macros_bootstrap_5.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{#
Example:
{% import "@A2lixTranslationForm/macros_bootstrap_5.html.twig" as a2lixTranslations %}
{{ a2lixTranslations.partialTranslations(editForm.translations, ['title','description']) }}
{{ a2lixTranslations.partialTranslations(editForm.translations, ['url']) }}
#}

{% macro partialTranslations(form, fieldsNames) %}
{{ form_errors(form) }}

<div class="a2lix_translations">
<ul class="a2lix_translationsLocales nav nav-tabs" role="tablist">
{% for translationsFields in form %}
{% set locale = translationsFields.vars.name %}

<li{% if app.request.locale == locale %} class="active"{% endif %}>
<a href="#{{ translationsFields.vars.id }}_{{ fieldsNames|join('_') }}_a2lix_translations-fields" data-toggle="tab" role="tab">
{{ translationsFields.vars.label|default(locale|humanize)|trans }}
{% if form.vars.default_locale == locale %}{{ '[Default]'|trans }}{% endif %}
{% if translationsFields.vars.required %}*{% endif %}
</a>
</li>
{% endfor %}
</ul>

<div class="a2lix_translationsFields tab-content">
{% for translationsFields in form %}
{% set locale = translationsFields.vars.name %}

<div id="{{ translationsFields.vars.id }}_{{ fieldsNames|join('_') }}_a2lix_translations-fields" class="tab-pane {% if app.request.locale == locale %}active{% endif %} {% if not form.vars.valid %}sonata-ba-field-error{% endif %}" role="tabpanel">
{% for translationsField in translationsFields|filter(translationsField => translationsField.vars.name in fieldsNames) %}
{{ form_row(translationsField) }}
{% endfor %}
</div>
{% endfor %}
</div>
</div>
{% endmacro %}

0 comments on commit 821ebd2

Please sign in to comment.