|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, https://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2025 |
|
6
|
|
|
* @package Base |
|
7
|
|
|
* @subpackage View |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
namespace Aimeos\Base\View\Helper\Translate; |
|
12
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* View helper class for translating strings. |
|
16
|
|
|
* |
|
17
|
|
|
* @package Base |
|
18
|
|
|
* @subpackage View |
|
19
|
|
|
*/ |
|
20
|
|
|
class Standard |
|
21
|
|
|
extends \Aimeos\Base\View\Helper\Base |
|
22
|
|
|
implements \Aimeos\Base\View\Helper\Translate\Iface |
|
23
|
|
|
{ |
|
24
|
|
|
private \Aimeos\Base\Translation\Iface $translator; |
|
25
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Initializes the translator view helper. |
|
29
|
|
|
* |
|
30
|
|
|
* @param \Aimeos\Base\View\Iface $view View instance with registered view helpers |
|
31
|
|
|
* @param \Aimeos\Base\Translation\Iface $translator Translation object |
|
32
|
|
|
*/ |
|
33
|
|
|
public function __construct( \Aimeos\Base\View\Iface $view, \Aimeos\Base\Translation\Iface $translator ) |
|
34
|
|
|
{ |
|
35
|
|
|
parent::__construct( $view ); |
|
36
|
|
|
|
|
37
|
|
|
$this->translator = $translator; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Returns the translated string or the original one if no translation is available. |
|
43
|
|
|
* |
|
44
|
|
|
* @param string $domain Translation domain from core or an extension |
|
45
|
|
|
* @param string|null $singular Singular form of the text to translate |
|
46
|
|
|
* @param string|null $plural Plural form of the text, used if $number is greater than one |
|
47
|
|
|
* @param int $number Amount of things relevant for the plural form |
|
48
|
|
|
* @param bool $force Return string untranslated if no translation is available |
|
49
|
|
|
* @return string|null Translated string or NULL if no translation is available and force parameter is FALSE |
|
50
|
|
|
*/ |
|
51
|
|
|
public function transform( string $domain, ?string $singular, ?string $plural = null, int $number = 1, bool $force = true ) : ?string |
|
52
|
|
|
{ |
|
53
|
|
|
if( $plural ) |
|
54
|
|
|
{ |
|
55
|
|
|
$trans = $this->translator->dn( $domain, (string) $singular, $plural, $number ); |
|
56
|
|
|
return $trans !== $plural || $force ? $trans : null; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
$trans = $this->translator->dt( $domain, (string) $singular ); |
|
60
|
|
|
return $trans !== $singular || $force ? $trans : null; |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|