-
-
Notifications
You must be signed in to change notification settings - Fork 528
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
language specific money and date display (#180)
* improved date translation * language specific date and money display
- Loading branch information
1 parent
f563e07
commit d4a46cf
Showing
14 changed files
with
308 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?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 DateTime; | ||
use Symfony\Component\HttpFoundation\RequestStack; | ||
use Twig\TwigFilter; | ||
|
||
/** | ||
* Date specific twig extensions | ||
*/ | ||
class DateExtensions extends \Twig_Extension | ||
{ | ||
private const FALLBACK_SHORT = 'Y-m-d'; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
protected $dateSettings; | ||
|
||
/** | ||
* @var RequestStack | ||
*/ | ||
protected $requestStack; | ||
|
||
/** | ||
* DateExtensions constructor. | ||
* @param RequestStack $requestStack | ||
* @param array $dateSettings | ||
*/ | ||
public function __construct(RequestStack $requestStack, array $dateSettings) | ||
{ | ||
$this->requestStack = $requestStack; | ||
$this->dateSettings = $dateSettings; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getFilters() | ||
{ | ||
return [ | ||
new TwigFilter('month_name', [$this, 'monthName']), | ||
new TwigFilter('date_short', [$this, 'dateShort']), | ||
]; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
protected function getLocale() | ||
{ | ||
return $this->requestStack->getCurrentRequest()->getLocale(); | ||
} | ||
|
||
/** | ||
* @param array $context | ||
* @param DateTime $date | ||
* @return string | ||
*/ | ||
public function dateShort(DateTime $date) | ||
{ | ||
$locale = $this->getLocale(); | ||
$format = self::FALLBACK_SHORT; | ||
|
||
if (isset($this->dateSettings[$locale]['date_short'])) { | ||
$format = $this->dateSettings[$locale]['date_short']; | ||
} | ||
|
||
return date_format($date, $format); | ||
} | ||
|
||
/** | ||
* @param \DateTime $date | ||
* @return string | ||
*/ | ||
public function monthName(\DateTime $date) | ||
{ | ||
return 'month.' . $date->format('n'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.