Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
TranslateTwigExtension
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
1 / 1
 translate
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3/**
4 * Twig extension to translate the given translation key
5 *
6 * This Source Code Form is subject to the terms of the Mozilla Public License,
7 * v. 2.0. If a copy of the MPL was not distributed with this file, You can
8 * obtain one at https://mozilla.org/MPL/2.0/.
9 *
10 * @package   phpMyFAQ\Template
11 * @author    Thorsten Rinne <thorsten@phpmyfaq.de>
12 * @copyright 2024-2026 phpMyFAQ Team
13 * @license   https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
14 * @link      https://www.phpmyfaq.de
15 * @since     2024-04-21
16 */
17
18declare(strict_types=1);
19
20namespace phpMyFAQ\Twig\Extensions;
21
22use phpMyFAQ\Translation;
23use Twig\Attribute\AsTwigFilter;
24use Twig\Extension\AbstractExtension;
25
26class TranslateTwigExtension extends AbstractExtension
27{
28    #[AsTwigFilter(name: 'translate')]
29    public static function translate(string $translationKey): string
30    {
31        $translation = Translation::get($translationKey);
32
33        return is_string($translation) ? $translation : $translationKey;
34    }
35}