‪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  if ($user && ($user->user['lang'] ?? false)) {
55  return $this->‪create($this->locales->createLocale($user->user['lang']));
56  }
57  return $this->‪create('en');
58  }
59 
61  {
62  // createLocale from a string takes care of resolving the automatic dependencies of e.g. "de_AT" to also check for "de"
63  // and also validates if TYPO3 supports the original language (at least in TYPO3 v12, there is a fixed list of
64  // allowed language keys)
65  $languageService = $this->‪create((string)$language->‪getLocale());
66  // Always disable debugging for frontend
67  $languageService->debugKey = false;
68  return $languageService;
69  }
70 }
‪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:197
‪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:60
‪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:63