[TASK] Change some site configuration details
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / Site / Entity / SiteLanguage.php
1 <?php
2 declare(strict_types = 1);
3
4 namespace TYPO3\CMS\Core\Site\Entity;
5
6 /*
7 * This file is part of the TYPO3 CMS project.
8 *
9 * It is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License, either version 2
11 * of the License, or any later version.
12 *
13 * For the full copyright and license information, please read the
14 * LICENSE.txt file that was distributed with this source code.
15 *
16 * The TYPO3 project - inspiring people to share!
17 */
18
19 /**
20 * Entity representing a site_language configuration of a site object.
21 */
22 class SiteLanguage
23 {
24 /**
25 * @var Site
26 */
27 protected $site;
28
29 /**
30 * The language mapped to the sys_language DB entry.
31 *
32 * @var int
33 */
34 protected $languageId;
35
36 /**
37 * Locale, like 'de_CH' or 'en_GB'
38 *
39 * @var string
40 */
41 protected $locale;
42
43 /**
44 * The Base URL for this language
45 *
46 * @var string
47 */
48 protected $base;
49
50 /**
51 * Label to be used within TYPO3 to identify the language
52 * @var string
53 */
54 protected $title = 'Default';
55
56 /**
57 * Label to be used within language menus
58 * @var string
59 */
60 protected $navigationTitle = '';
61
62 /**
63 * The flag key (like "gb" or "fr") used to be used in TYPO3's Backend.
64 * @var string
65 */
66 protected $flagIdentifier = 'us';
67
68 /**
69 * The iso code for this language (two letter) ISO-639-1
70 * @var string
71 */
72 protected $twoLetterIsoCode = 'en';
73
74 /**
75 * Language tag for this language defined by RFC 1766 / 3066 for "lang"
76 * and "hreflang" attributes
77 *
78 * @var string
79 */
80 protected $hreflang = 'en-US';
81
82 /**
83 * The direction for this language
84 * @var string
85 */
86 protected $direction = '';
87
88 /**
89 * Prefix for TYPO3's language files
90 * "default" for english, otherwise one of TYPO3's internal language keys.
91 * Previously configured via TypoScript config.language = fr
92 *
93 * @var string
94 */
95 protected $typo3Language = 'default';
96
97 /**
98 * @var string
99 */
100 protected $fallbackType = 'strict';
101
102 /**
103 * @var array
104 */
105 protected $fallbackLanguageIds = [];
106
107 /**
108 * Additional parameters configured for this site language
109 * @var array
110 */
111 protected $attributes = [];
112
113 /**
114 * SiteLanguage constructor.
115 * @param Site $site
116 * @param int $languageId
117 * @param string $locale
118 * @param string $base
119 * @param array $attributes
120 */
121 public function __construct(Site $site, int $languageId, string $locale, string $base, array $attributes)
122 {
123 $this->site = $site;
124 $this->languageId = $languageId;
125 $this->locale = $locale;
126 $this->base = $base;
127 $this->attributes = $attributes;
128 if (!empty($attributes['title'])) {
129 $this->title = $attributes['title'];
130 }
131 if (!empty($attributes['navigationTitle'])) {
132 $this->navigationTitle = $attributes['navigationTitle'];
133 }
134 if (!empty($attributes['flag'])) {
135 $this->flagIdentifier = $attributes['flag'];
136 }
137 if (!empty($attributes['typo3Language'])) {
138 $this->typo3Language = $attributes['typo3Language'];
139 }
140 if (!empty($attributes['iso-639-1'])) {
141 $this->twoLetterIsoCode = $attributes['iso-639-1'];
142 }
143 if (!empty($attributes['hreflang'])) {
144 $this->hreflang = $attributes['hreflang'];
145 }
146 if (!empty($attributes['direction'])) {
147 $this->direction = $attributes['direction'];
148 }
149 if (!empty($attributes['fallbackType'])) {
150 $this->fallbackType = $attributes['fallbackType'];
151 }
152 if (!empty($attributes['fallbacks'])) {
153 $this->fallbackLanguageIds = $attributes['fallbacks'];
154 }
155 }
156
157 /**
158 * Returns the SiteLanguage in an array representation for e.g. the usage
159 * in TypoScript.
160 *
161 * @return array
162 */
163 public function toArray(): array
164 {
165 return [
166 'languageId' => $this->getLanguageId(),
167 'locale' => $this->getLocale(),
168 'base' => $this->getBase(),
169 'title' => $this->getTitle(),
170 'navigationTitle' => $this->getNavigationTitle(),
171 'twoLetterIsoCode' => $this->getTwoLetterIsoCode(),
172 'hreflang' => $this->getHreflang(),
173 'direction' => $this->getDirection(),
174 'typo3Language' => $this->getTypo3Language(),
175 'flagIdentifier' => $this->getFlagIdentifier(),
176 'fallbackType' => $this->getFallbackType(),
177 'fallbackLanguageIds' => $this->getFallbackLanguageIds(),
178 ];
179 }
180
181 /**
182 * @return Site
183 */
184 public function getSite(): Site
185 {
186 return $this->site;
187 }
188
189 /**
190 * @return int
191 */
192 public function getLanguageId(): int
193 {
194 return $this->languageId;
195 }
196
197 /**
198 * @return string
199 */
200 public function getLocale(): string
201 {
202 return $this->locale;
203 }
204
205 /**
206 * @return string
207 */
208 public function getBase(): string
209 {
210 return $this->base;
211 }
212
213 /**
214 * @return string
215 */
216 public function getTitle(): string
217 {
218 return $this->title;
219 }
220
221 /**
222 * @return string
223 */
224 public function getNavigationTitle(): string
225 {
226 return $this->navigationTitle ?: $this->getTitle();
227 }
228
229 /**
230 * @return string
231 */
232 public function getFlagIdentifier(): string
233 {
234 return $this->flagIdentifier;
235 }
236
237 /**
238 * @return string
239 */
240 public function getTypo3Language(): string
241 {
242 return $this->typo3Language;
243 }
244
245 /**
246 * Returns the ISO-639-1 language ISO code
247 *
248 * @return string
249 */
250 public function getTwoLetterIsoCode(): string
251 {
252 return $this->twoLetterIsoCode;
253 }
254
255 /**
256 * Returns the RFC 1766 / 3066 language tag
257 *
258 * @return string
259 */
260 public function getHreflang(): string
261 {
262 return $this->hreflang;
263 }
264
265 /**
266 * Returns the language direction
267 *
268 * @return string
269 */
270 public function getDirection(): string
271 {
272 return $this->direction;
273 }
274
275 /**
276 * @return string
277 */
278 public function getFallbackType(): string
279 {
280 return $this->fallbackType;
281 }
282
283 /**
284 * @return array
285 */
286 public function getFallbackLanguageIds(): array
287 {
288 return $this->fallbackLanguageIds;
289 }
290 }