From e02560e28c480dc91bb93adfebc8469dd4aeddcb Mon Sep 17 00:00:00 2001 From: Bertrand Dunogier Date: Wed, 4 Jan 2017 12:15:13 +0100 Subject: [PATCH] EZP-26828: Trigger crowdin in-context translation based on a cookie If an ez_in_context_translation cookie is set with any value, the request's accept-language is set, using an event subscriber, to ach-UG, the pseudo-locale used by crowdin. When the locale is ach-UG, the javascript that adds the in-context overlay is loaded. --- .../CrowdinRequestLocaleSubcriber.php | 31 +++++++++++++++++++ Resources/config/services.yml | 5 +++ Resources/views/PlatformUI/shell.html.twig | 8 +++++ 3 files changed, 44 insertions(+) create mode 100644 EventListener/CrowdinRequestLocaleSubcriber.php diff --git a/EventListener/CrowdinRequestLocaleSubcriber.php b/EventListener/CrowdinRequestLocaleSubcriber.php new file mode 100644 index 000000000..1d7a3654a --- /dev/null +++ b/EventListener/CrowdinRequestLocaleSubcriber.php @@ -0,0 +1,31 @@ + [ + ['setInContextAcceptLanguage', 100], + ], + ]; + } + + public function setInContextAcceptLanguage(GetResponseEvent $e) + { + if (!$e->getRequest()->cookies->has('ez_in_context_translation')) { + return; + } + + $e->getRequest()->headers->set('accept-language', 'ach-UG'); + } +} diff --git a/Resources/config/services.yml b/Resources/config/services.yml index 53cbcd581..d45cb4989 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -291,3 +291,8 @@ services: calls: - [setRequestStack, ['@request_stack']] - [setPjaxRequestMatcher, ['@ezsystems.platformui.pjax.request_matcher']] + + ezsystems.platformui.event_subscriber.crowdin_request_locale: + class: EzSystems\PlatformUIBundle\EventListener\CrowdinRequestLocaleSubcriber + tags: + - {name: kernel.event_subscriber} diff --git a/Resources/views/PlatformUI/shell.html.twig b/Resources/views/PlatformUI/shell.html.twig index a277d2be4..f47413f75 100644 --- a/Resources/views/PlatformUI/shell.html.twig +++ b/Resources/views/PlatformUI/shell.html.twig @@ -5,6 +5,14 @@ eZ Platform UI + + {% if parameters.interfaceLanguages[0] == 'ach_UG' %} + + + {% endif %} {% stylesheets '$css.files;ez_platformui$' filter='cssrewrite' %} {% endstylesheets %}