Skip to content
This repository has been archived by the owner on May 3, 2022. It is now read-only.

Commit

Permalink
EZP-26828: Trigger crowdin in-context translation based on a cookie
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Bertrand Dunogier committed Jan 4, 2017
1 parent a38ab4a commit e02560e
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
31 changes: 31 additions & 0 deletions EventListener/CrowdinRequestLocaleSubcriber.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
/**
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace EzSystems\PlatformUIBundle\EventListener;

use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;

class CrowdinRequestLocaleSubcriber implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return [
KernelEvents::REQUEST => [
['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');
}
}
5 changes: 5 additions & 0 deletions Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
8 changes: 8 additions & 0 deletions Resources/views/PlatformUI/shell.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
<title>eZ Platform UI</title>
<meta name="viewport" content="width=device-width"/>
<meta charset="utf-8"/>

{% if parameters.interfaceLanguages[0] == 'ach_UG' %}
<script type="text/javascript">
var _jipt = [];
_jipt.push(['project', 'ez-platform']);
</script>
<script type="text/javascript" src="//cdn.crowdin.com/jipt/jipt.js"></script>
{% endif %}
{% stylesheets '$css.files;ez_platformui$' filter='cssrewrite' %}
<link rel="stylesheet" href="{{ asset_url }}"/>
{% endstylesheets %}
Expand Down

0 comments on commit e02560e

Please # to comment.