‪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 {
26  public function ‪__construct(
27  protected readonly ‪Locales $locales,
28  protected readonly ‪LocalizationFactory $localizationFactory,
29  protected readonly ‪FrontendInterface $runtimeCache
30  ) {}
31 
37  public function ‪create(‪Locale|string $locale): ‪LanguageService
38  {
39  $obj = new ‪LanguageService($this->locales, $this->localizationFactory, $this->runtimeCache);
40  $obj->init($locale instanceof ‪Locale ? $locale : $this->locales->createLocale($locale));
41  return $obj;
42  }
43 
45  {
46  return $this->‪create($this->locales->createLocaleFromUserPreferences($user));
47  }
48 
50  {
51  // createLocale from a string takes care of resolving the automatic dependencies of e.g. "de_AT" to also check for "de"
52  // and also validates if TYPO3 supports the original language (at least in TYPO3 v12, there is a fixed list of
53  // allowed language keys)
54  return $this->‪create((string)$language->‪getLocale());
55  }
56 }
‪TYPO3\CMS\Core\Localization\LanguageServiceFactory
Definition: LanguageServiceFactory.php:25
‪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:49
‪TYPO3\CMS\Core\Localization\LanguageServiceFactory\create
‪create(Locale|string $locale)
Definition: LanguageServiceFactory.php:37
‪TYPO3\CMS\Core\Cache\Frontend\FrontendInterface
Definition: FrontendInterface.php:22
‪TYPO3\CMS\Core\Localization\Locale
Definition: Locale.php:30
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:46
‪TYPO3\CMS\Core\Localization\LanguageServiceFactory\createFromUserPreferences
‪createFromUserPreferences(?AbstractUserAuthentication $user)
Definition: LanguageServiceFactory.php:44
‪TYPO3\CMS\Core\Localization\LanguageServiceFactory\__construct
‪__construct(protected readonly Locales $locales, protected readonly LocalizationFactory $localizationFactory, protected readonly FrontendInterface $runtimeCache)
Definition: LanguageServiceFactory.php:26
‪TYPO3\CMS\Core\Authentication\AbstractUserAuthentication
Definition: AbstractUserAuthentication.php:65