Skip to content

Commit

Permalink
Merge pull request #178 from ArmaForces/feature/en_translation
Browse files Browse the repository at this point in the history
Feature/en translation
  • Loading branch information
veteran29 authored Feb 8, 2021
2 parents 3d7ed2e + ab41716 commit 9647f8d
Show file tree
Hide file tree
Showing 12 changed files with 113 additions and 16 deletions.
5 changes: 2 additions & 3 deletions config/packages/translation.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
framework:
default_locale: pl
default_locale: en
translator:
default_path: '%kernel.project_dir%/translations'
fallbacks:
- en
fallbacks: ~
77 changes: 77 additions & 0 deletions src/EventSubscriber/UserLocaleRequestSubscriber.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

declare(strict_types=1);

namespace App\EventSubscriber;

use Negotiation\AcceptLanguage;
use Negotiation\LanguageNegotiator;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\EventListener\LocaleListener;
use Symfony\Component\HttpKernel\KernelEvents;

class UserLocaleRequestSubscriber implements EventSubscriberInterface
{
public const NEGOTIABLE_LANGUAGES = [
'en',
'pl',
];

/** @var SessionInterface */
protected $session;

/** @var LoggerInterface */
protected $logger;

public function __construct(SessionInterface $session, LoggerInterface $logger)
{
$this->session = $session;
$this->logger = $logger;
}

/**
* Priority set to before LocaleListener.
*
* @see https://symfony.com/doc/4.4/translation/locale.html
* @see LocaleListener::onKernelRequest()
*/
public static function getSubscribedEvents(): array
{
return [
KernelEvents::REQUEST => ['onKernelRequest', 17],
];
}

public function onKernelRequest(RequestEvent $event): void
{
if (!$event->isMasterRequest()) {
return;
}

$request = $event->getRequest();

$negotiatedLanguage = $request->getLocale();
$acceptLanguage = $request->headers->get('Accept-Language');

$this->logger->debug('Client Accept language', [$acceptLanguage]);

if (null !== $acceptLanguage) {
/** @var AcceptLanguage $bestLanguage */
$bestLanguage = (new LanguageNegotiator())->getBest(
$acceptLanguage,
self::NEGOTIABLE_LANGUAGES
);

if (null !== $bestLanguage) {
$negotiatedLanguage = $bestLanguage->getBasePart();
}
}

$this->logger->debug('Client Negotiated language', [$negotiatedLanguage]);

$request->setLocale($this->session->get('_locale', $negotiatedLanguage));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<tr>
<th scope="col">#</th>
<th scope="col" class="w-100">{{ 'Mod group name'|trans }}</th>
<th scope="col">{{ 'Include?'|trans }}</th>
<th scope="col">{{ 'Select'|trans }}</th>
</tr>
{% endblock %}
{% block table_body %}
Expand Down
2 changes: 1 addition & 1 deletion templates/_partial/mod_tabs/_mod_tabs_table.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<th scope="col"></th>
<th scope="col" class="w-100">{{ 'Mod name'|trans }}</th>
<th scope="col">{{ 'Mod source'|trans }}</th>
<th scope="col">{{ 'Include?'|trans }}</th>
<th scope="col">{{ 'Select'|trans }}</th>
</tr>
{% endblock %}
{% block table_body %}
Expand Down
5 changes: 4 additions & 1 deletion templates/base.html.twig
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{%- set app_community_description = include('home/index/_partial/' ~ get_current_locale() ~ '/_about_us.html.twig')|striptags -%}
{%- set app_community_description = include([
'home/index/_partial/' ~ get_current_locale() ~ '/_about_us.html.twig',
'home/index/_partial/pl/_about_us.html.twig'
])|striptags -%}

<!doctype html>
<html lang="{{ get_current_locale() }}">
Expand Down
20 changes: 16 additions & 4 deletions templates/home/index/_partial/_about.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
<div class="col-md-8">
<!-- Description -->
<p class="grey-text">
{% include 'home/index/_partial/' ~ get_current_locale() ~ '/_about_us.html.twig' %}
{% include([
'home/index/_partial/' ~ get_current_locale() ~ '/_about_us.html.twig',
'home/index/_partial/pl/_about_us.html.twig'
]) %}
</p>
<!--/ Description -->
</div>
Expand All @@ -26,7 +29,10 @@
<i class="fa fa-fighter-jet fa-4x orange-text"></i>
<h4 class="my-4 font-weight-bold">{{ 'Fun'|trans }}</h4>
<p class="grey-text">
{% include 'home/index/_partial/' ~ get_current_locale() ~ '/_fun.html.twig' %}
{% include([
'home/index/_partial/' ~ get_current_locale() ~ '/_fun.html.twig',
'home/index/_partial/pl/_fun.html.twig'
]) %}
</p>
</div>
<!--/ Grid column -->
Expand All @@ -36,7 +42,10 @@
<i class="fa fa-gamepad fa-4x orange-text"></i>
<h4 class="my-4 font-weight-bold">{{ 'Gaming'|trans }}</h4>
<p class="grey-text">
{% include 'home/index/_partial/' ~ get_current_locale() ~ '/_gaming.html.twig' %}
{% include([
'home/index/_partial/' ~ get_current_locale() ~ '/_gaming.html.twig',
'home/index/_partial/pl/_gaming.html.twig'
]) %}
</p>
</div>
<!--/ Grid column -->
Expand All @@ -46,7 +55,10 @@
<i class="fa fa-user-friends fa-4x orange-text"></i>
<h4 class="my-4 font-weight-bold">{{ 'Community'|trans }}</h4>
<p class="grey-text">
{% include 'home/index/_partial/' ~ get_current_locale() ~ '/_community.html.twig' %}
{% include([
'home/index/_partial/' ~ get_current_locale() ~ '/_community.html.twig',
'home/index/_partial/pl/_community.html.twig'
]) %}
</p>
</div>
<!--/ Grid column -->
Expand Down
5 changes: 4 additions & 1 deletion templates/home/index/_partial/_missions.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
<div class="col-lg-7 col-md-6 mb-4">
<h4 class="my-4 font-weight-bold">{{ 'When do we play'|trans }}</h4>
<p class="grey-text">
{% include 'home/index/_partial/' ~ get_current_locale() ~ '/_games.html.twig' %}
{% include([
'home/index/_partial/' ~ get_current_locale() ~ '/_games.html.twig',
'home/index/_partial/pl/_games.html.twig'
]) %}
</p>
</div>
<!--/ Grid column -->
Expand Down
2 changes: 1 addition & 1 deletion templates/home/join_us/_partial/pl/join_steps.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
{%- endif -%}.
</li>
<li>
Pobierz mody z modlisty "<a href="https://modlist.armaforces.com/#/download/default">default</a>". Są one wymagane na większości misji.
Pobierz mody z modlisty "<a href="{{ path('app_mod_list_public_customize', { name: 'Default'}) }}">Default</a>". Są one wymagane na większości misji.
<br/>
<br/>
Standardowo rozgrywki odbywają się w środy oraz soboty o godzinie 20:00, po rozegraniu swojej pierwszej misji
Expand Down
5 changes: 4 additions & 1 deletion templates/home/join_us/join_us.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@
<h4 class="card-title">{{ 'Join ArmaForces'|trans }}</h4>
<section class="text-left">
<ul id="join-steps">
{% include 'home/join_us/_partial/' ~ get_current_locale() ~ '/join_steps.html.twig' %}
{% include([
'home/join_us/_partial/' ~ get_current_locale() ~ '/join_steps.html.twig',
'home/join_us/_partial/pl/join_steps.html.twig'
]) %}
</ul>
</section>
<section class="text-left">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<th scope="col">#</th>
<th scope="col"></th>
<th scope="col" class="w-100">{{ 'Mod name'|trans }}</th>
<th scope="col">{{ 'Include?'|trans }}</th>
<th scope="col">{{ 'Select'|trans }}</th>
<th scope="col">{{ 'Steam Workshop ID'|trans }}</th>
<th></th>
</tr>
Expand Down
2 changes: 1 addition & 1 deletion templates/user_group/_partial/_users_table.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<th scope="col">{{ 'Discord ID'|trans }}</th>
<th scope="col">{{ 'Created at'|trans }}</th>
<th scope="col">{{ 'Last updated at'|trans }}</th>
<th scope="col">{{ 'Include?'|trans }}</th>
<th scope="col">{{ 'Select'|trans }}</th>
</tr>
{% endblock %}
{% block table_body %}
Expand Down
2 changes: 1 addition & 1 deletion translations/messages.pl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,4 @@ Last updated by: Ostatnia modyfikacja przez
Confirm: Potwierdź
Confirmation: Potwierdzenie
Are you sure you want to delete %name%?: Czy na pewno chcesz usunąć %name%?
Include?: Dołączyć?
Select: Wybierz

0 comments on commit 9647f8d

Please sign in to comment.