Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
6 / 6 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
TranslatableString | |
100.00% |
6 / 6 |
|
100.00% |
4 / 4 |
4 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
__toString | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getDisplayString | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
isTranslatable | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | /** |
4 | * Class for translatable string with a special default translation. |
5 | * |
6 | * PHP version 8 |
7 | * |
8 | * Copyright (C) The National Library of Finland 2015. |
9 | * |
10 | * This program is free software; you can redistribute it and/or modify |
11 | * it under the terms of the GNU General Public License version 2, |
12 | * as published by the Free Software Foundation. |
13 | * |
14 | * This program is distributed in the hope that it will be useful, |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 | * GNU General Public License for more details. |
18 | * |
19 | * You should have received a copy of the GNU General Public License |
20 | * along with this program; if not, write to the Free Software |
21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
22 | * |
23 | * @category VuFind |
24 | * @package Translator |
25 | * @author Ere Maijala <ere.maijala@helsinki.fi> |
26 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
27 | * @link https://vufind.org Main Site |
28 | */ |
29 | |
30 | namespace VuFind\I18n; |
31 | |
32 | /** |
33 | * Class for translatable string with a special default translation. |
34 | * |
35 | * @category VuFind |
36 | * @package Translator |
37 | * @author Ere Maijala <ere.maijala@helsinki.fi> |
38 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
39 | * @link https://vufind.org Main Site |
40 | */ |
41 | class TranslatableString implements TranslatableStringInterface |
42 | { |
43 | /** |
44 | * Original string |
45 | * |
46 | * @var string |
47 | */ |
48 | protected $string; |
49 | |
50 | /** |
51 | * Default display string |
52 | * |
53 | * @var string |
54 | */ |
55 | protected $displayString; |
56 | |
57 | /** |
58 | * Whether translation is allowed |
59 | * |
60 | * @var bool |
61 | */ |
62 | protected $translatable; |
63 | |
64 | /** |
65 | * Constructor |
66 | * |
67 | * @param string $string Original string |
68 | * @param string $displayString Translatable display string |
69 | * @param bool $translatable Whether translation is allowed |
70 | */ |
71 | public function __construct($string, $displayString, $translatable = true) |
72 | { |
73 | $this->string = (string)$string; |
74 | $this->displayString = $displayString; |
75 | $this->translatable = $translatable; |
76 | } |
77 | |
78 | /** |
79 | * Return the original string by default |
80 | * |
81 | * @return string |
82 | */ |
83 | public function __toString() |
84 | { |
85 | return $this->string; |
86 | } |
87 | |
88 | /** |
89 | * Return string for display if raw value has no translation available (can be |
90 | * further translated) |
91 | * |
92 | * @return string |
93 | */ |
94 | public function getDisplayString() |
95 | { |
96 | return $this->displayString; |
97 | } |
98 | |
99 | /** |
100 | * Checks if the string can be translated |
101 | * |
102 | * @return bool |
103 | */ |
104 | public function isTranslatable() |
105 | { |
106 | return $this->translatable; |
107 | } |
108 | } |