translate time-tracking in login screen and browser title (#738)

This commit is contained in:
Kevin Papst
2019-04-30 17:52:19 +02:00
committed by GitHub
parent b35022d161
commit b865add1b3
29 changed files with 307 additions and 125 deletions

View File

@@ -14,7 +14,6 @@ use App\Entity\Timesheet;
use App\Utils\Duration;
use App\Utils\LocaleSettings;
use NumberFormatter;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Intl\Intl;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;
@@ -29,17 +28,14 @@ class Extensions extends AbstractExtension
* @var LocaleSettings
*/
protected $localeSettings;
/**
* @var string
*/
protected $locale;
/**
* @var Duration
*/
protected $durationFormatter;
/**
* @var NumberFormatter
*/
@@ -49,16 +45,6 @@ class Extensions extends AbstractExtension
*/
protected $moneyFormatter;
/**
* @var RequestStack
*/
protected $requestStack;
/**
* @var array
*/
protected $cookies = [];
/**
* @var string[]
*/
@@ -88,7 +74,7 @@ class Extensions extends AbstractExtension
'start-small' => 'fas fa-play-circle',
'stop' => 'fas fa-stop',
'stop-small' => 'far fa-stop-circle',
'timesheet' => 'far fa-clock',
'timesheet' => 'fas fa-clock',
'trash' => 'far fa-trash-alt',
'user' => 'fas fa-user',
'visibility' => 'far fa-eye',
@@ -110,12 +96,10 @@ class Extensions extends AbstractExtension
];
/**
* @param RequestStack $requestStack
* @param LocaleSettings $localeSettings
*/
public function __construct(RequestStack $requestStack, LocaleSettings $localeSettings)
public function __construct(LocaleSettings $localeSettings)
{
$this->requestStack = $requestStack;
$this->localeSettings = $localeSettings;
$this->durationFormatter = new Duration();
}
@@ -142,8 +126,6 @@ class Extensions extends AbstractExtension
{
return [
new TwigFunction('locales', [$this, 'getLocales']),
new TwigFunction('is_visible_column', [$this, 'isColumnVisible']),
new TwigFunction('is_datatable_configured', [$this, 'isDatatableConfigured']),
new TwigFunction('class_name', [$this, 'getClassName']),
];
}
@@ -161,61 +143,6 @@ class Extensions extends AbstractExtension
return get_class($object);
}
/**
* @param string $dataTable
* @param string $size
* @return bool
*/
public function isDatatableConfigured(string $dataTable, string $size)
{
$cookie = $this->getVisibilityCookieName($dataTable, $size);
return $this->requestStack->getCurrentRequest()->cookies->has($cookie);
}
/**
* @param string $dataTable
* @param string $size
* @return string
*/
public function getVisibilityCookieName(string $dataTable, string $size)
{
return $dataTable . '_visibility' . $size;
}
/**
* This is only for datatables, do not use it outside this context.
*
* @param string $dataTable
* @param string $column
* @param string $size
* @return bool
*/
public function isColumnVisible(string $dataTable, string $column, string $size)
{
// name handling is spread between here and datatables.html.twig (data_table_column_modal)
$cookie = $this->getVisibilityCookieName($dataTable, $size);
if (!isset($this->cookies[$cookie])) {
$visibility = false;
if ($this->requestStack->getCurrentRequest()->cookies->has($cookie)) {
$visibility = json_decode($this->requestStack->getCurrentRequest()->cookies->get($cookie), true);
}
$this->cookies[$cookie] = $visibility;
}
$values = $this->cookies[$cookie];
if (empty($values) || !is_array($values)) {
return true;
}
if (isset($values[$column]) && $values[$column] === false) {
return false;
}
return true;
}
/**
* Transforms seconds into a duration string.
*