Files
firefly-iii/app/Support/Twig/Translation.php

85 lines
2.1 KiB
PHP
Raw Normal View History

2015-05-09 22:42:45 +02:00
<?php
/**
* Translation.php
2017-10-21 08:40:00 +02:00
* Copyright (c) 2017 thegrumpydictator@gmail.com
*
2017-10-21 08:40:00 +02:00
* This file is part of Firefly III.
*
2017-10-21 08:40:00 +02:00
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
2017-12-17 14:44:05 +01:00
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
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
/**
2017-11-15 12:25:49 +01:00
* Class Budget.
2015-05-09 22:42:45 +02:00
*/
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(
2017-11-15 10:52:29 +01:00
'_',
function ($name) {
2018-03-29 19:01:47 +02:00
return (string)trans(sprintf('firefly.%s', $name));
2017-11-15 10:52:29 +01:00
},
['is_safe' => ['html']]
2015-05-09 22:42:45 +02:00
);
return $filters;
}
2017-08-25 16:03:36 +02:00
/**
2017-11-15 12:25:49 +01:00
* {@inheritdoc}
2017-08-25 16:03:36 +02:00
*/
public function getFunctions(): array
{
return [
$this->journalLinkTranslation(),
];
}
2017-09-09 06:41:45 +02:00
2017-08-25 16:03:36 +02:00
/**
* @return Twig_SimpleFunction
*/
public function journalLinkTranslation(): Twig_SimpleFunction
{
return new Twig_SimpleFunction(
2017-11-15 10:52:29 +01:00
'journalLinkTranslation',
function (string $direction, string $original) {
$key = sprintf('firefly.%s_%s', $original, $direction);
2018-08-04 17:30:47 +02:00
return $key;
2017-11-15 10:52:29 +01:00
$translation = trans($key);
2018-08-04 17:30:47 +02:00
2017-11-15 10:52:29 +01:00
if ($key === $translation) {
return $original;
}
return $translation;
},
['is_safe' => ['html']]
2017-08-25 16:03:36 +02:00
);
}
2015-05-09 22:42:45 +02:00
}