Skip to content

Commit

Permalink
Translation Domain Added
Browse files Browse the repository at this point in the history
  • Loading branch information
cesurapp committed Nov 15, 2018
1 parent 636bc16 commit 00a375c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ You can change the default options.
'template': '@PdMenu/Default/menu.html.twig'
'depth': null
'currentClass': 'active'
'trans_domain': 'admin'
}) }}
```

Expand Down
16 changes: 8 additions & 8 deletions Resources/views/Default/menu.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

{# Begin Menu #}
{% block menu_begin %}
<ul id="{{ menu.id }}" {{ arrayToAttr(menu.childAttr, {'class': 'pd-menu'}) }}>
<ul id="{{ menu.id }}" {{ arrayToAttr(menu.childAttr, {'class': 'pd-menu'}, options) }}>
{% for depth in menu.child %}
{% set menu = depth %}
{{ block('menu_item') }}
Expand All @@ -12,29 +12,29 @@

{# Create Menu Item #}
{% block menu_item %}
<li {{ arrayToAttr(menu.listAttr) }}>
<li {{ arrayToAttr(menu.listAttr, [], options) }}>
{# Create Link #}
{% if menu.link %}
<a href="{{ menu.link }}" {{ arrayToAttr(menu.linkAttr) }}>
<a href="{{ menu.link }}" {{ arrayToAttr(menu.linkAttr, [], options) }}>
{% if menu.extra('label_icon') %}
<i class="material-icons">{{ menu.extra('label_icon') }}</i>
{% endif %}
<span {{ arrayToAttr(menu.labelAttr) }}>
{{ menu.extra('label_translate', true) ? menu.label|trans : menu.label }}
<span {{ arrayToAttr(menu.labelAttr, [], options) }}>
{{ menu.extra('label_translate', true) ? menu.label|trans([], options.trans_domain) : menu.label }}
</span>
</a>
{% else %}
{% if menu.extra('label_icon') %}
<i class="material-icons">{{ menu.extra('label_icon') }}</i>
{% endif %}
<span {{ arrayToAttr(menu.labelAttr) }}>
{{ menu.extra('label_translate', true) ? menu.label|trans : menu.label }}
<span {{ arrayToAttr(menu.labelAttr, [], options) }}>
{{ menu.extra('label_translate', true) ? menu.label|trans([], options.trans_domain) : menu.label }}
</span>
{% endif %}

{# Create Dropdown #}
{% if menu.child|length %}
<ul {{ arrayToAttr(menu.childAttr) }}>
<ul {{ arrayToAttr(menu.childAttr, [], options) }}>
{% for depth in menu.child %}
{% set menu = depth %}
{{ block('menu_item') }}
Expand Down
5 changes: 3 additions & 2 deletions Twig/MenuExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class MenuExtension extends \Twig_Extension
'template' => '@PdMenu/Default/menu.html.twig',
'depth' => null,
'currentClass' => 'active',
'trans_domain' => null
];

/**
Expand Down Expand Up @@ -146,7 +147,7 @@ public function getMenu(string $menuClass, $options = []): ItemInterface
*
* @return string
*/
public function arrayToAttr(array $array = [], array $append = [])
public function arrayToAttr(array $array = [], array $append = [], array $options = [])
{
$array = array_merge_recursive($array, $append);
$attr = '';
Expand All @@ -158,7 +159,7 @@ public function arrayToAttr(array $array = [], array $append = [])

if ('title' === mb_strtolower($key)) {
if (!isset($array['title_translate'])) {
$value = $this->translator->trans($value);
$value = $this->translator->trans($value, [], $options['trans_domain'] ?? null);
}
}

Expand Down

0 comments on commit 00a375c

Please sign in to comment.