1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the TYPO3 CMS project. |
7
|
|
|
* |
8
|
|
|
* It is free software; you can redistribute it and/or modify it under |
9
|
|
|
* the terms of the GNU General Public License, either version 2 |
10
|
|
|
* of the License, or any later version. |
11
|
|
|
* |
12
|
|
|
* For the full copyright and license information, please read the |
13
|
|
|
* LICENSE.txt file that was distributed with this source code. |
14
|
|
|
* |
15
|
|
|
* The TYPO3 project - inspiring people to share! |
16
|
|
|
*/ |
17
|
|
|
|
18
|
|
|
namespace TYPO3\CMS\Core\Localization; |
19
|
|
|
|
20
|
|
|
use TYPO3\CMS\Core\Authentication\AbstractUserAuthentication; |
21
|
|
|
use TYPO3\CMS\Core\Site\Entity\SiteLanguage; |
22
|
|
|
|
23
|
|
|
class LanguageServiceFactory |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @var Locales |
27
|
|
|
*/ |
28
|
|
|
protected $locales; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var LocalizationFactory |
32
|
|
|
*/ |
33
|
|
|
protected $localizationFactory; |
34
|
|
|
|
35
|
|
|
public function __construct(Locales $locales, LocalizationFactory $localizationFactory) |
36
|
|
|
{ |
37
|
|
|
$this->locales = $locales; |
38
|
|
|
$this->localizationFactory = $localizationFactory; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Factory method to create a language service object. |
43
|
|
|
* |
44
|
|
|
* @param string $locale the locale (= the TYPO3-internal locale given) |
45
|
|
|
* @return LanguageService |
46
|
|
|
*/ |
47
|
|
|
public function create(string $locale): LanguageService |
48
|
|
|
{ |
49
|
|
|
$obj = new LanguageService($this->locales, $this->localizationFactory); |
50
|
|
|
$obj->init($locale); |
51
|
|
|
return $obj; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function createFromUserPreferences(?AbstractUserAuthentication $user): LanguageService |
55
|
|
|
{ |
56
|
|
|
if ($user->user['lang'] ?? false) { |
57
|
|
|
return $this->create($user->user['lang']); |
58
|
|
|
} |
59
|
|
|
return $this->create('default'); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function createFromSiteLanguage(SiteLanguage $language): LanguageService |
63
|
|
|
{ |
64
|
|
|
return $this->create($language->getTypo3Language()); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|