‪TYPO3CMS  ‪main
LanguageServiceFactory.php
Go to the documentation of this file.
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 
19 
23 
25 {
29 
30  public function ‪__construct(
34  ) {
35  $this->locales = ‪$locales;
36  $this->localizationFactory = ‪$localizationFactory;
37  $this->runtimeCache = ‪$runtimeCache;
38  }
39 
45  public function ‪create(‪Locale|string $locale): ‪LanguageService
46  {
47  $obj = new ‪LanguageService($this->locales, $this->localizationFactory, $this->runtimeCache);
48  $obj->init($locale instanceof ‪Locale ? $locale : $this->locales->createLocale($locale));
49  return $obj;
50  }
51 
53  {
54  return $this->‪create($this->locales->createLocaleFromUserPreferences($user));
55  }
56 
58  {
59  // createLocale from a string takes care of resolving the automatic dependencies of e.g. "de_AT" to also check for "de"
60  // and also validates if TYPO3 supports the original language (at least in TYPO3 v12, there is a fixed list of
61  // allowed language keys)
62  return $this->‪create((string)$language->‪getLocale());
63  }
64 }
‪TYPO3\CMS\Core\Localization\LanguageServiceFactory
Definition: LanguageServiceFactory.php:25
‪TYPO3\CMS\Core\Localization\LanguageServiceFactory\$runtimeCache
‪FrontendInterface $runtimeCache
Definition: LanguageServiceFactory.php:28
‪TYPO3\CMS\Core\Localization\LocalizationFactory
Definition: LocalizationFactory.php:31
‪TYPO3\CMS\Core\Site\Entity\SiteLanguage\getLocale
‪getLocale()
Definition: SiteLanguage.php:174
‪TYPO3\CMS\Core\Localization\Locales
Definition: Locales.php:36
‪TYPO3\CMS\Core\Localization
Definition: CacheWarmer.php:18
‪TYPO3\CMS\Core\Site\Entity\SiteLanguage
Definition: SiteLanguage.php:27
‪TYPO3\CMS\Core\Localization\LanguageServiceFactory\createFromSiteLanguage
‪createFromSiteLanguage(SiteLanguage $language)
Definition: LanguageServiceFactory.php:57
‪TYPO3\CMS\Core\Localization\LanguageServiceFactory\create
‪create(Locale|string $locale)
Definition: LanguageServiceFactory.php:45
‪TYPO3\CMS\Core\Localization\LanguageServiceFactory\$localizationFactory
‪LocalizationFactory $localizationFactory
Definition: LanguageServiceFactory.php:27
‪TYPO3\CMS\Core\Cache\Frontend\FrontendInterface
Definition: FrontendInterface.php:22
‪TYPO3\CMS\Core\Localization\LanguageServiceFactory\__construct
‪__construct(Locales $locales, LocalizationFactory $localizationFactory, FrontendInterface $runtimeCache)
Definition: LanguageServiceFactory.php:30
‪TYPO3\CMS\Core\Localization\Locale
Definition: Locale.php:30
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:46
‪TYPO3\CMS\Core\Localization\LanguageServiceFactory\$locales
‪Locales $locales
Definition: LanguageServiceFactory.php:26
‪TYPO3\CMS\Core\Localization\LanguageServiceFactory\createFromUserPreferences
‪createFromUserPreferences(?AbstractUserAuthentication $user)
Definition: LanguageServiceFactory.php:52
‪TYPO3\CMS\Core\Authentication\AbstractUserAuthentication
Definition: AbstractUserAuthentication.php:64