Locales
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.
Table of Contents
Properties
- $languages : array<non-empty-string, non-empty-string>
- Supported TYPO3 languages with locales
- $localeDependencies : array<string|int, mixed>
- Dependencies for locales.
Methods
- __construct() : mixed
- createLocale() : Locale
- createLocaleFromRequest() : Locale
- createLocaleFromUserPreferences() : Locale
- getActiveLanguages() : array<int, non-empty-string>
- Returns a list of all ISO codes / TYPO3 languages that have active language packs, including "en" (English).
- getAllSystemLocales() : array<string|int, mixed>
- getLanguages() : array<non-empty-string, non-empty-string>
- Returns the supported languages indexed by their corresponding locale.
- getLocaleDependencies() : array<int, non-empty-string>
- Returns the dependencies of a given locale, if any.
- getLocales() : array<int, non-empty-string>
- Returns the locales.
- getPreferredClientLanguage() : non-empty-string
- Converts the language codes that we get from the client (usually HTTP_ACCEPT_LANGUAGE) into a TYPO3-readable language code
- isLanguageKeyAvailable() : bool
- isValidLanguageKey() : bool
- setSystemLocaleFromSiteLanguage() : bool
- Setting locale based on a SiteLanguage's defined locale. Used for frontend rendering.
- normalizeLanguage() : string
- normalizeLocale() : string
- normalizeLocaleDependencies() : array<int, non-empty-string>
- Normalizes dependencies
- setLocale() : bool
- Internal method, which calls itself again, in order to avoid multiple logging issues.
Properties
$languages
Supported TYPO3 languages with locales
protected
array<non-empty-string, non-empty-string>
$languages
= ['en' => 'English', 'af' => 'Afrikaans', 'ar' => 'Arabic', 'bs' => 'Bosnian', 'bg' => 'Bulgarian', 'ca' => 'Catalan', 'ch' => 'Chinese (Simple)', 'cs' => 'Czech', 'cy' => 'Welsh', 'da' => 'Danish', 'de' => 'German', 'el' => 'Greek', 'eo' => 'Esperanto', 'es' => 'Spanish', 'et' => 'Estonian', 'eu' => 'Basque', 'fa' => 'Persian', 'fi' => 'Finnish', 'fo' => 'Faroese', 'fr' => 'French', 'fr_CA' => 'French (Canada)', 'ga' => 'Irish Gaelic', 'gd' => 'Scottish Gaelic', 'gl' => 'Galician', 'he' => 'Hebrew', 'hi' => 'Hindi', 'hr' => 'Croatian', 'hu' => 'Hungarian', 'is' => 'Icelandic', 'it' => 'Italian', 'ja' => 'Japanese', 'ka' => 'Georgian', 'kl' => 'Greenlandic', 'km' => 'Khmer', 'ko' => 'Korean', 'lb' => 'Luxembourgish', 'lo' => 'Lao', 'lt' => 'Lithuanian', 'lv' => 'Latvian', 'mi' => 'Maori', 'mk' => 'Macedonian', 'ms' => 'Malay', 'mt' => 'Maltese', 'nl' => 'Dutch', 'no' => 'Norwegian', 'pl' => 'Polish', 'pt' => 'Portuguese', 'pt_BR' => 'Brazilian Portuguese', 'ro' => 'Romanian', 'ru' => 'Russian', 'rw' => 'Kinyarwanda', 'sk' => 'Slovak', 'sl' => 'Slovenian', 'sn' => 'Shona (Bantu)', 'sq' => 'Albanian', 'sr' => 'Serbian', 'sv' => 'Swedish', 'th' => 'Thai', 'tr' => 'Turkish', 'uk' => 'Ukrainian', 'vi' => 'Vietnamese', 'zh' => 'Chinese (Traditional)', 'zh_CN' => 'Chinese (Simplified)', 'zh_HK' => 'Chinese (Simplified Hong Kong)', 'zh_Hans_CN' => 'Chinese (Simplified Han)']
Important: This uses "underscore" to separate locale and country e.g. fr_CA
$localeDependencies
Dependencies for locales.
protected
array<string|int, mixed>
$localeDependencies
= ['lb' => ['de-LU']]
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.
Important: This uses "dash" to separate locale and country e.g. fr-CA
Example: If "lb" is chosen, but no label was found, a fallback to the label in "de-LU" is used.
Methods
__construct()
public
__construct() : mixed
createLocale()
public
createLocale(string $localeKey[, array<string|int, mixed>|null $alternativeDependencies = null ]) : Locale
Parameters
- $localeKey : string
- $alternativeDependencies : array<string|int, mixed>|null = null
Return values
LocalecreateLocaleFromRequest()
public
createLocaleFromRequest(ServerRequestInterface|null $request) : Locale
Parameters
- $request : ServerRequestInterface|null
Return values
LocalecreateLocaleFromUserPreferences()
public
createLocaleFromUserPreferences(AbstractUserAuthentication|null $user) : Locale
Parameters
- $user : AbstractUserAuthentication|null
Return values
LocalegetActiveLanguages()
Returns a list of all ISO codes / TYPO3 languages that have active language packs, including "en" (English).
public
getActiveLanguages() : array<int, non-empty-string>
Return values
array<int, non-empty-string>getAllSystemLocales()
public
static getAllSystemLocales() : array<string|int, mixed>
not part of TYPO3 Core API, don't use outside of TYPO3 Core
Return values
array<string|int, mixed>getLanguages()
Returns the supported languages indexed by their corresponding locale.
public
getLanguages() : array<non-empty-string, non-empty-string>
Return values
array<non-empty-string, non-empty-string>getLocaleDependencies()
Returns the dependencies of a given locale, if any.
public
getLocaleDependencies(string $localeKey) : array<int, non-empty-string>
Parameters
- $localeKey : string
Return values
array<int, non-empty-string>getLocales()
Returns the locales.
public
getLocales() : array<int, non-empty-string>
Return values
array<int, non-empty-string>getPreferredClientLanguage()
Converts the language codes that we get from the client (usually HTTP_ACCEPT_LANGUAGE) into a TYPO3-readable language code
public
getPreferredClientLanguage(string $languageCodesList) : non-empty-string
Parameters
- $languageCodesList : string
-
List of language codes. something like 'de,en-us;q=0.9,de-de;q=0.7,es-cl;q=0.6,en;q=0.4,es;q=0.3,zh;q=0.1'
Return values
non-empty-string —A preferred language that TYPO3 supports, or "en" as fallback if none found
isLanguageKeyAvailable()
public
isLanguageKeyAvailable(string $languageKey) : bool
Parameters
- $languageKey : string
Return values
boolisValidLanguageKey()
public
isValidLanguageKey(string $locale) : bool
Parameters
- $locale : string
Return values
boolsetSystemLocaleFromSiteLanguage()
Setting locale based on a SiteLanguage's defined locale. Used for frontend rendering.
public
static setSystemLocaleFromSiteLanguage(SiteLanguage $siteLanguage) : bool
Parameters
- $siteLanguage : SiteLanguage
Return values
bool —whether the locale was found on the system (and could be set properly) or not
normalizeLanguage()
protected
normalizeLanguage(string $locale) : string
Parameters
- $locale : string
Return values
stringnormalizeLocale()
protected
normalizeLocale(string $locale) : string
Parameters
- $locale : string
Return values
stringnormalizeLocaleDependencies()
Normalizes dependencies
protected
normalizeLocaleDependencies(array<string|int, mixed> $dependencies) : array<int, non-empty-string>
Parameters
- $dependencies : array<string|int, mixed>
Return values
array<int, non-empty-string>setLocale()
Internal method, which calls itself again, in order to avoid multiple logging issues.
protected
static setLocale(string $locale, string $localeStringForTrigger) : bool
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.
Parameters
- $locale : string
- $localeStringForTrigger : string