Add ability to translate links.

This commit is contained in:
James Cole 2017-08-25 16:03:36 +02:00
parent 72b7900ce2
commit 4b2abb6f25
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
4 changed files with 73 additions and 30 deletions

View File

@ -61,6 +61,7 @@ class General extends Twig_Extension
$this->steamPositive(),
$this->activeRoutePartial(),
$this->activeRoutePartialWhat(),
];
}

View File

@ -15,6 +15,7 @@ namespace FireflyIII\Support\Twig;
use Twig_Extension;
use Twig_SimpleFilter;
use Twig_SimpleFunction;
/**
*
@ -43,6 +44,39 @@ class Translation extends Twig_Extension
return $filters;
}
/**
* {@inheritDoc}
*/
public function getFunctions(): array
{
return [
$this->journalLinkTranslation(),
];
}
/**
* @return Twig_SimpleFunction
*/
public function journalLinkTranslation(): Twig_SimpleFunction
{
return new Twig_SimpleFunction(
'journalLinkTranslation', function (int $linkTypeId, string $direction, string $original) {
$key = sprintf('firefly.%d_%s', $linkTypeId, $direction);
$translation = trans($key);
if($key === $translation) {
return $original;
}
return $translation;
}, ['is_safe' => ['html']]
);
}
/**
* {@inheritDoc}
*/

View File

@ -899,6 +899,14 @@ return [
'overview_for_link' => 'Overview for link type ":name"',
'delete_journal_link' => 'Delete the link between <a href=":source_link">:source</a> and <a href=":destination_link">:destination</a>',
'deleted_link' => 'Deleted link',
'1_outward' => 'relates to',
'2_outward' => '(partially) refunds',
'3_outward' => '(partially) pays for',
'4_outward' => '(partially) reimburses',
'1_inward' => 'relates to',
'2_inward' => 'is (partially) refunded by',
'3_inward' => 'is (partially) paid for by',
'4_inward' => 'is (partially) reimbursed by',
// split a transaction:

View File

@ -329,13 +329,13 @@
<td>
{{ ('this_'~(what|lower))|_ }}
{% if link.source.id == journal.id %}
{{ link.linkType.outward }}
{{ journalLinkTranslation(link.link_type_id,'outward', link.linkType.outward) }}
<a href="{{ route('transactions.show',link.destination.id) }}">
#{{ link.destination.id }}: {{ link.destination.description }}
</a>
({{ journalAmount(link.destination) }})
{% else %}
{{ link.linkType.inward }}
{{ journalLinkTranslation(link.link_type_id,'inward', link.linkType.inward) }}
<a href="{{ route('transactions.show',link.source.id) }}">
#{{ link.source.id }}: {{ link.source.description }}</a>
({{ journalAmount(link.source) }})