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

@@ -0,0 +1,98 @@
<?php
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Twig;
use Symfony\Component\HttpFoundation\RequestStack;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;
class DatatableExtensions extends AbstractExtension
{
/**
* @var RequestStack
*/
protected $requestStack;
/**
* @var array
*/
protected $cookies = [];
/**
* @param RequestStack $requestStack
*/
public function __construct(RequestStack $requestStack)
{
$this->requestStack = $requestStack;
}
/**
* {@inheritdoc}
*/
public function getFunctions()
{
return [
new TwigFunction('is_visible_column', [$this, 'isColumnVisible']),
new TwigFunction('is_datatable_configured', [$this, 'isDatatableConfigured']),
];
}
/**
* @param string $dataTable
* @return bool
*/
public function isDatatableConfigured(string $dataTable)
{
$cookie = $this->getVisibilityCookieName($dataTable);
return $this->requestStack->getCurrentRequest()->cookies->has($cookie);
}
/**
* @param string $dataTable
* @return string
*/
protected function getVisibilityCookieName(string $dataTable)
{
return $dataTable . '_visibility';
}
/**
* This is only for datatables, do not use it outside this context.
*
* @param string $dataTable
* @param string $column
* @return bool
*/
public function isColumnVisible(string $dataTable, string $column)
{
// name handling is spread between here and datatables.html.twig (data_table_column_modal)
$cookie = $this->getVisibilityCookieName($dataTable);
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;
}
}