2015-05-09 22:42:45 +02:00
|
|
|
<?php
|
2016-05-20 12:41:23 +02:00
|
|
|
/**
|
|
|
|
* Translation.php
|
|
|
|
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
|
|
|
*
|
2016-10-05 06:52:15 +02:00
|
|
|
* This software may be modified and distributed under the terms of the
|
|
|
|
* Creative Commons Attribution-ShareAlike 4.0 International License.
|
|
|
|
*
|
|
|
|
* See the LICENSE file for details.
|
2016-05-20 12:41:23 +02:00
|
|
|
*/
|
|
|
|
|
2017-04-09 07:44:22 +02:00
|
|
|
declare(strict_types=1);
|
2015-05-09 22:42:45 +02:00
|
|
|
|
|
|
|
namespace FireflyIII\Support\Twig;
|
|
|
|
|
|
|
|
use Twig_Extension;
|
|
|
|
use Twig_SimpleFilter;
|
2017-08-25 16:03:36 +02:00
|
|
|
use Twig_SimpleFunction;
|
2015-05-09 22:42:45 +02:00
|
|
|
|
|
|
|
/**
|
2015-06-29 09:53:10 +02:00
|
|
|
*
|
2015-05-09 22:42:45 +02:00
|
|
|
* Class Budget
|
|
|
|
*
|
|
|
|
* @package FireflyIII\Support\Twig
|
|
|
|
*/
|
|
|
|
class Translation extends Twig_Extension
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
2016-04-05 22:00:03 +02:00
|
|
|
public function getFilters(): array
|
2015-05-09 22:42:45 +02:00
|
|
|
{
|
|
|
|
$filters = [];
|
|
|
|
|
|
|
|
$filters[] = new Twig_SimpleFilter(
|
2015-06-06 23:09:12 +02:00
|
|
|
'_', function ($name) {
|
2015-05-09 22:42:45 +02:00
|
|
|
|
2016-11-06 16:17:22 +01:00
|
|
|
return strval(trans(sprintf('firefly.%s', $name)));
|
2015-05-09 22:42:45 +02:00
|
|
|
|
|
|
|
}, ['is_safe' => ['html']]
|
|
|
|
);
|
|
|
|
|
|
|
|
return $filters;
|
|
|
|
}
|
|
|
|
|
2017-08-25 16:03:36 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
|
|
|
public function getFunctions(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
$this->journalLinkTranslation(),
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-09-09 06:41:45 +02:00
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
|
|
|
public function getName(): string
|
|
|
|
{
|
|
|
|
return 'FireflyIII\Support\Twig\Translation';
|
|
|
|
}
|
|
|
|
|
2017-08-25 16:03:36 +02:00
|
|
|
/**
|
|
|
|
* @return Twig_SimpleFunction
|
|
|
|
*/
|
|
|
|
public function journalLinkTranslation(): Twig_SimpleFunction
|
|
|
|
{
|
|
|
|
return new Twig_SimpleFunction(
|
|
|
|
'journalLinkTranslation', function (int $linkTypeId, string $direction, string $original) {
|
2017-09-09 06:41:45 +02:00
|
|
|
$key = sprintf('firefly.%d_%s', $linkTypeId, $direction);
|
2017-08-25 16:03:36 +02:00
|
|
|
$translation = trans($key);
|
2017-09-09 06:41:45 +02:00
|
|
|
if ($key === $translation) {
|
2017-08-25 16:03:36 +02:00
|
|
|
return $original;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $translation;
|
|
|
|
|
|
|
|
|
|
|
|
}, ['is_safe' => ['html']]
|
|
|
|
);
|
|
|
|
}
|
2015-05-09 22:42:45 +02:00
|
|
|
}
|