‪TYPO3CMS  ‪main
TYPO3\CMS\Core\Localization\Locales Class Reference
Inheritance diagram for TYPO3\CMS\Core\Localization\Locales:

Public Member Functions

 __construct ()
 createLocale (string $localeKey, array $alternativeDependencies=null)
array< int, getLocales():array { return array_keys( $this->languages);} public function isValidLanguageKey(string $locale):bool { if( $locale==='en'||$locale==='default') { return true;} if(!isset( $this->languages[ $locale])) { if(str_contains( $locale, '_')) {[ $baseIsoCodeLanguageKey]=explode( '_', $locale);return $this-> isValidLanguageKey ($baseIsoCodeLanguageKey)

Static Public Member Functions

static bool setSystemLocaleFromSiteLanguage (SiteLanguage $siteLanguage)

Public Attributes

if(str_contains($locale, '-')) return false
return true
array< non-empty-string, function getLanguages():array { return $this-> languages
foreach($this->languages as $locale=> $localeTitle) $selectedLanguage = 'default'
 $preferredLanguages = GeneralUtility::trimExplode(',', $languageCodesList)
 $sortedPreferredLanguages = []

Static Protected Member Functions

static setLocale (string $locale, string $localeStringForTrigger)

Protected Attributes

array $languages
array $localeDependencies

Detailed Description

Defines all available TYPO3 system languages, as they differ from actual ISO 639-1 codes. User-defined system languages can be added to $GLOBALS['TYPO3_CONF_VARS']['SYS']['localization']['locales']['user']

These system languages are used for determining the proper language labels of XLF files.

Definition at line 32 of file Locales.php.

Constructor & Destructor Documentation

◆ __construct()

TYPO3\CMS\Core\Localization\Locales::__construct ( )

Definition at line 121 of file Locales.php.

References $GLOBALS, and TYPO3\CMS\Core\Localization\Locales\languages.

Member Function Documentation

◆ createLocale()

TYPO3\CMS\Core\Localization\Locales::createLocale ( string  $localeKey,
array  $alternativeDependencies = null 

◆ isValidLanguageKey()

array<int, getLocales(): array { return array_keys($this->languages); } public function isValidLanguageKey(string $locale): bool { if ($locale === 'en' || $locale === 'default') { return true; } if (!isset($this->languages[$locale])) { if (str_contains($locale, '_')) { [$baseIsoCodeLanguageKey] = explode('_', $locale); return $this-> TYPO3\CMS\Core\Localization\Locales::isValidLanguageKey (   $baseIsoCodeLanguageKey)

Returns the locales.

‪array<int, non-empty-string>

Referenced by TYPO3\CMS\Core\Localization\Locales\createLocale().

◆ setLocale()

static TYPO3\CMS\Core\Localization\Locales::setLocale ( string  $locale,
string  $localeStringForTrigger 

Internal method, which calls itself again, in order to avoid multiple logging issues. The main reason for this method is that it calls itself again by trying again to set the locale. Due to sensible defaults, people used the locale "de_AT.utf-8" with the POSIX platform (see https://en.wikipedia.org/wiki/Locale_(computer_software)#POSIX_platforms) in their site configuration, even though the target system has "de_AT" and not "de_AT.UTF-8" defined. "setLocale()" is now called again without the POSIX platform suffix and is checked again if the locale is then available, and then logs the failed information.

Definition at line 320 of file Locales.php.

Referenced by TYPO3\CMS\Core\Localization\Locales\setSystemLocaleFromSiteLanguage().

◆ setSystemLocaleFromSiteLanguage()

static bool TYPO3\CMS\Core\Localization\Locales::setSystemLocaleFromSiteLanguage ( SiteLanguage  $siteLanguage)

Setting locale based on a SiteLanguage's defined locale. Used for frontend rendering, previously set within TSFE->settingLocale

‪bool whether the locale was found on the system (and could be set properly) or not

Definition at line 302 of file Locales.php.

References TYPO3\CMS\Core\Site\Entity\SiteLanguage\getLocale(), and TYPO3\CMS\Core\Localization\Locales\setLocale().

Referenced by TYPO3\CMS\Frontend\Middleware\SiteResolver\process(), TYPO3\CMS\Core\Tests\Unit\Localization\LocalesTest\setSystemLocaleFromSiteLanguageWithoutLocaleDoesNotSetLocale(), and TYPO3\CMS\Core\Tests\Unit\Localization\LocalesTest\setSystemLocaleFromSiteLanguageWithProperLocaleSetsLocale().

Member Data Documentation

◆ $languages

array TYPO3\CMS\Core\Localization\Locales::$languages

Definition at line 39 of file Locales.php.

◆ $localeDependencies

array TYPO3\CMS\Core\Localization\Locales::$localeDependencies
Initial value:
= [
'lb' => ['de'],

Dependencies for locales. By default, locales with a country/region suffix such as "de_AT" will automatically have the "de" locale as fallback. This way TYPO3 only needs to know about the actual "base" language, however also allows to use country-specific languages. However, when a specific locale such as "lb" has a dependency to a different "de" suffix, this should is defined here. With $GLOBALS['TYPO3_CONF_VARS']['SYS']['localization']['locales']['dependencies'] it is possible to extend the dependency list.

Example: If "lb" is chosen, but no label was found, a fallback to the label in "de" is used.

Definition at line 117 of file Locales.php.

◆ $preferredLanguages

TYPO3\CMS\Core\Localization\Locales::$preferredLanguages = GeneralUtility::trimExplode(',', $languageCodesList)

Definition at line 266 of file Locales.php.

◆ $selectedLanguage

foreach ( $this->languages as $locale=> $localeTitle) TYPO3\CMS\Core\Localization\Locales::$selectedLanguage = 'default'

Definition at line 265 of file Locales.php.

◆ $sortedPreferredLanguages

TYPO3\CMS\Core\Localization\Locales::$sortedPreferredLanguages = []

Definition at line 268 of file Locales.php.

◆ false

if (str_contains( $locale, '-')) return TYPO3\CMS\Core\Localization\Locales::false

Definition at line 180 of file Locales.php.

◆ languages

array<non-empty-string, function getLanguages(): array { return $this-> TYPO3\CMS\Core\Localization\Locales::languages

Returns the supported languages indexed by their corresponding locale.

‪array<non-empty-string, non-empty-string>

Definition at line 191 of file Locales.php.

Referenced by TYPO3\CMS\Core\Localization\Locales\__construct().

◆ true

return TYPO3\CMS\Core\Localization\Locales::true

Definition at line 182 of file Locales.php.