Completed
Push — ezp26828-trigger_crowdin_in_co... ( fa2c05 )
by
unknown
19:34
created

setInContextAcceptLanguage()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 8
rs 9.4285
1
<?php
2
/**
3
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
4
 * @license For full copyright and license information view LICENSE file distributed with this source code.
5
 */
6
namespace eZ\Bundle\EzPublishCoreBundle\EventSubscriber;
7
8
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
9
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
10
use Symfony\Component\HttpKernel\KernelEvents;
11
12
/**
13
 * If the request has an `ez_in_context_translation` cookie, sets the request accept-language
14
 * to the pseudo-locale used to trigger Crowdin's in-context translation UI.
15
 */
16
class CrowdinRequestLocaleSubscriber implements EventSubscriberInterface
17
{
18
    public static function getSubscribedEvents()
19
    {
20
        return [
21
            KernelEvents::REQUEST => [
22
                ['setInContextAcceptLanguage', 100],
23
            ],
24
        ];
25
    }
26
27
    public function setInContextAcceptLanguage(GetResponseEvent $e)
28
    {
29
        if (!$e->getRequest()->cookies->has('ez_in_context_translation')) {
30
            return;
31
        }
32
33
        $e->getRequest()->headers->set('accept-language', 'ach-UG');
34
    }
35
}
36