Skip to content

Commit

Permalink
Merge pull request #617 from paulandrieux/bugfix/608-js-tranlsation-v…
Browse files Browse the repository at this point in the history
…ictoire-admin

Bugfix/608 js tranlsation victoire admin
  • Loading branch information
paulandrieux authored Sep 19, 2016
2 parents 13d5d26 + 1f20afc commit 74361ce
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 81 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
angular.module('ngApp').filter('translate', function() {
return function(input) {
return Translator.trans(input, {}, 'victoire');
var originalLocale = Translator.locale;
Translator.locale = adminLocale;
var trans = Translator.trans(input, {}, 'victoire');
Translator.locale = originalLocale;

return trans;
};
});
5 changes: 4 additions & 1 deletion Bundle/CoreBundle/Resources/views/Layout/layout.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
{% javascripts injector='victoire-edit, victoire-leftnavbar' %}
<script type="text/javascript" src="{{ asset_url }}"></script>
{% endjavascripts %}
<script src="{{ url('bazinga_jstranslation_js', {'domain': 'victoire'}) }}"></script>
<script src="{{ url('bazinga_jstranslation_js', { 'domain': 'victoire'}) }}?locales={{ victoire_i18n_available_locales|join(',') }}"></script>
{% endif %}
{% if is_granted('ROLE_VICTOIRE') %}
<script type="text/javascript">
Expand All @@ -91,6 +91,9 @@
<script src="{{ url('bazinga_jstranslation_js') }}"></script>
<script src="{{ asset('bundles/fosjsrouting/js/router.js') }}"></script>
<script type="text/javascript">
{% if is_granted('ROLE_VICTOIRE') %}
var adminLocale = '{{ app.user.locale}}';
{% endif %}
var locale = '{{ app.request.locale }}';
var debug = {{ app.debug ? "true" : "false" }};
</script>
Expand Down
27 changes: 27 additions & 0 deletions Bundle/I18nBundle/Listener/KernelRequestListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Victoire\Bundle\I18nBundle\Listener;

use Symfony\Component\HttpKernel\Event\GetResponseEvent;

/**
* KernelRequestListener add the available locas as global twig variable.
*
* @author Paul Andrieux <[email protected]>
*/
class KernelRequestListener
{
protected $twig;
protected $availableLocales;

public function __construct(\Twig_Environment $twig, $availableLocales)
{
$this->twig = $twig;
$this->availableLocales = $availableLocales;
}

public function onKernelRequest(GetResponseEvent $event)
{
$this->twig->addGlobal('victoire_i18n_available_locales', $this->availableLocales);
}
}
78 changes: 0 additions & 78 deletions Bundle/I18nBundle/Listener/LocaleListener.php

This file was deleted.

9 changes: 8 additions & 1 deletion Bundle/I18nBundle/Resources/config/services.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
services:

victoire_i18n.locale_resolver:
class: Victoire\Bundle\I18nBundle\Resolver\LocaleResolver
arguments:
Expand Down Expand Up @@ -27,3 +26,11 @@ services:
- '@victoire_i18n.locale_resolver'
tags:
- { name: routing.loader }

victoire_i18n.kernelrequest.listener:
class: Victoire\Bundle\I18nBundle\Listener\KernelRequestListener
arguments:
- '@twig'
- '%victoire_i18n.available_locales%'
tags:
- { name: kernel.event_listener, event: kernel.request, method: onKernelRequest }

0 comments on commit 74361ce

Please sign in to comment.