LocalizationFactory
This class acts currently as facade around SymfonyTranslator.
User-land code should use LanguageService for the time being, and this class should not be exposed directly.
Ideally, consider using a runtime cache if needed, if not using LanguageService.
Hand in the locale to load, or english ("en").
What it does:
- Caches on a system-level cache
- Handles loading default (= english) before translated files
- Handles file name juggling of translated files.
- Handles localization overrides via $GLOBALS['TYPO3_CONF_VARS']['LANG']['resourceOverrides']
This class only deals with full files, "resources" a.k.a. "translation domains" right now. It does not care about the actual identifier WITHIN this label bag.
The main issue with this class is that it does not resolve proper dependencies, thus the fallback logic is marode. You can see this when checking for ArrayUtility both here and in LanguageService.
Table of Contents
Constants
- DEPRECATED_FILES = [ // @todo: remove the following files in TYPO3 v15.0 'EXT:backend/Resources/Private/Language/locallang_view_help.xlf', 'EXT:backend/Resources/Private/Language/locallang_view_help.xlf', 'EXT:backend/Resources/Private/Language/locallang_sitesettings_module.xlf', 'EXT:backend/Resources/Private/Language/locallang_siteconfiguration_module.xlf', 'EXT:backend/Resources/Private/Language/locallang_mod.xlf', 'EXT:belog/Resources/Private/Language/locallang_mod.xlf', 'EXT:beuser/Resources/Private/Language/locallang_mod.xlf', 'EXT:core/Resources/Private/Language/locallang_mod_usertools.xlf', 'EXT:core/Resources/Private/Language/locallang_mod_system.xlf', 'EXT:core/Resources/Private/Language/locallang_mod_site.xlf', 'EXT:core/Resources/Private/Language/locallang_mod_file.xlf', 'EXT:core/Resources/Private/Language/locallang_mod_help.xlf', 'EXT:core/Resources/Private/Language/locallang_mod_admintools.xlf', 'EXT:core/Resources/Private/Language/locallang_tsfe.xlf', 'EXT:dashboard/Resources/Private/Language/locallang_mod.xlf', 'EXT:extensionmanager/Resources/Private/Language/locallang_mod.xlf', 'EXT:form/Resources/Private/Language/locallang_module.xlf', 'EXT:indexed_search/Resources/Private/Language/locallang_mod.xlf', 'EXT:install/Resources/Private/Language/ModuleInstallUpgrade.xlf', 'EXT:install/Resources/Private/Language/ModuleInstallSettings.xlf', 'EXT:install/Resources/Private/Language/ModuleInstallMaintenance.xlf', 'EXT:install/Resources/Private/Language/ModuleInstallEnvironment.xlf', 'EXT:install/Resources/Private/Language/BackendModule.xlf', 'EXT:info/Resources/Private/Language/locallang_mod_web_info.xlf', 'EXT:linkvalidator/Resources/Private/Language/Module/locallang_mod.xlf', 'EXT:recycler/Resources/Private/Language/locallang_mod.xlf', ]
- MOVED_FILES = [ // @todo: remove the following files in TYPO3 v15.0, they serve as a fallback for old syntax and files that have been moved 'EXT:core/Resources/Private/Language/locallang_t3lib_fullsearch.xlf' => 'EXT:lowlevel/Resources/Private/Language/fullsearch.xlf', 'EXT:dashboard/Resources/Private/Language/locallang_tca.xlf' => 'EXT:dashboard/Resources/Private/Language/db.xlf', 'EXT:filemetadata/Resources/Private/Language/locallang_tca.xlf' => 'EXT:filemetadata/Resources/Private/Language/db.xlf', 'EXT:lowlevel/Resources/Private/Language/locallang.xlf' => 'EXT:lowlevel/Resources/Private/Language/messages.xlf', 'EXT:impexp/Resources/Private/Language/locallang_tca.xlf' => 'EXT:impexp/Resources/Private/Language/db.xlf', 'EXT:linkvalidator/Resources/Private/Language/locallang.xlf' => 'EXT:linkvalidator/Resources/Private/Language/db.xlf', 'EXT:seo/Resources/Private/Language/locallang_tca.xlf' => 'EXT:seo/Resources/Private/Language/db.xlf', 'EXT:webhooks/Resources/Private/Language/Modules/webhooks.xlf' => 'EXT:webhooks/Resources/Private/Language/module.xlf', 'EXT:reactions/Resources/Private/Language/Modules/webhooks.xlf' => 'EXT:reactions/Resources/Private/Language/module.xlf', ]
Properties
- $labelFileResolver : LabelFileResolver
- $runtimeCache : FrontendInterface
- $systemCache : FrontendInterface
- $translationDomainMapper : TranslationDomainMapper
- $translator : Translator
Methods
- __construct() : mixed
- getParsedData() : array<string, string|array<int, array<string, string>>>
- Returns parsed data from a given file and language key.
- isLanguageFileDeprecated() : bool
- warmupTranslatorResource() : void
- Preload files into Symfony Translator without retrieving catalogues.
- addFileReferenceToTranslator() : void
- Adds translations of one resource to Symfony Translator
- computeAllLanguageKeys() : array<string|int, mixed>
- computeFileDomainAndFallbacks() : array{string, string, string[]}
- Prepares file reference, domain, language fallbacks
- convertCatalogueToLegacyFormat() : array<string|int, mixed>
- Convert Symfony MessageCatalogue to TYPO3's legacy format
- getMessageCatalogue() : MessageCatalogueInterface
- Load complete catalogue for locale using Symfony Translator
- loadFilesIntoSymfonyTranslator() : void
- Load files into Symfony Translator
- loadLanguagesIntoSymfonyTranslator() : void
- Load languages into Symfony Translator
- loadWithSymfonyTranslator() : array<string|int, mixed>
- Get the catalogue and convert to TYPO3 format
- parseIcuPlural() : array<string|int, mixed>
- Simple parser for ICU plural format - extracts plural values
Constants
DEPRECATED_FILES
protected
mixed
DEPRECATED_FILES
= [
// @todo: remove the following files in TYPO3 v15.0
'EXT:backend/Resources/Private/Language/locallang_view_help.xlf',
'EXT:backend/Resources/Private/Language/locallang_view_help.xlf',
'EXT:backend/Resources/Private/Language/locallang_sitesettings_module.xlf',
'EXT:backend/Resources/Private/Language/locallang_siteconfiguration_module.xlf',
'EXT:backend/Resources/Private/Language/locallang_mod.xlf',
'EXT:belog/Resources/Private/Language/locallang_mod.xlf',
'EXT:beuser/Resources/Private/Language/locallang_mod.xlf',
'EXT:core/Resources/Private/Language/locallang_mod_usertools.xlf',
'EXT:core/Resources/Private/Language/locallang_mod_system.xlf',
'EXT:core/Resources/Private/Language/locallang_mod_site.xlf',
'EXT:core/Resources/Private/Language/locallang_mod_file.xlf',
'EXT:core/Resources/Private/Language/locallang_mod_help.xlf',
'EXT:core/Resources/Private/Language/locallang_mod_admintools.xlf',
'EXT:core/Resources/Private/Language/locallang_tsfe.xlf',
'EXT:dashboard/Resources/Private/Language/locallang_mod.xlf',
'EXT:extensionmanager/Resources/Private/Language/locallang_mod.xlf',
'EXT:form/Resources/Private/Language/locallang_module.xlf',
'EXT:indexed_search/Resources/Private/Language/locallang_mod.xlf',
'EXT:install/Resources/Private/Language/ModuleInstallUpgrade.xlf',
'EXT:install/Resources/Private/Language/ModuleInstallSettings.xlf',
'EXT:install/Resources/Private/Language/ModuleInstallMaintenance.xlf',
'EXT:install/Resources/Private/Language/ModuleInstallEnvironment.xlf',
'EXT:install/Resources/Private/Language/BackendModule.xlf',
'EXT:info/Resources/Private/Language/locallang_mod_web_info.xlf',
'EXT:linkvalidator/Resources/Private/Language/Module/locallang_mod.xlf',
'EXT:recycler/Resources/Private/Language/locallang_mod.xlf',
]
MOVED_FILES
protected
mixed
MOVED_FILES
= [
// @todo: remove the following files in TYPO3 v15.0, they serve as a fallback for old syntax and files that have been moved
'EXT:core/Resources/Private/Language/locallang_t3lib_fullsearch.xlf' => 'EXT:lowlevel/Resources/Private/Language/fullsearch.xlf',
'EXT:dashboard/Resources/Private/Language/locallang_tca.xlf' => 'EXT:dashboard/Resources/Private/Language/db.xlf',
'EXT:filemetadata/Resources/Private/Language/locallang_tca.xlf' => 'EXT:filemetadata/Resources/Private/Language/db.xlf',
'EXT:lowlevel/Resources/Private/Language/locallang.xlf' => 'EXT:lowlevel/Resources/Private/Language/messages.xlf',
'EXT:impexp/Resources/Private/Language/locallang_tca.xlf' => 'EXT:impexp/Resources/Private/Language/db.xlf',
'EXT:linkvalidator/Resources/Private/Language/locallang.xlf' => 'EXT:linkvalidator/Resources/Private/Language/db.xlf',
'EXT:seo/Resources/Private/Language/locallang_tca.xlf' => 'EXT:seo/Resources/Private/Language/db.xlf',
'EXT:webhooks/Resources/Private/Language/Modules/webhooks.xlf' => 'EXT:webhooks/Resources/Private/Language/module.xlf',
'EXT:reactions/Resources/Private/Language/Modules/webhooks.xlf' => 'EXT:reactions/Resources/Private/Language/module.xlf',
]
Properties
$labelFileResolver
protected
LabelFileResolver
$labelFileResolver
$runtimeCache
protected
FrontendInterface
$runtimeCache
Attributes
- #[Autowire]
- $service: 'cache.runtime'
$systemCache
protected
FrontendInterface
$systemCache
Attributes
- #[Autowire]
- $service: 'cache.l10n'
$translationDomainMapper
protected
TranslationDomainMapper
$translationDomainMapper
$translator
protected
Translator
$translator
Methods
__construct()
public
__construct(Translator $translator, FrontendInterface $systemCache, FrontendInterface $runtimeCache, TranslationDomainMapper $translationDomainMapper, LabelFileResolver $labelFileResolver) : mixed
Parameters
- $translator : Translator
- $systemCache : FrontendInterface
- $runtimeCache : FrontendInterface
- $translationDomainMapper : TranslationDomainMapper
- $labelFileResolver : LabelFileResolver
getParsedData()
Returns parsed data from a given file and language key.
public
getParsedData(string $fileReference, Locale|string|null $locale[, bool $renewCache = false ]) : array<string, string|array<int, array<string, string>>>
Parameters
- $fileReference : string
-
Input is a file-reference (see \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName). That file is expected to be a supported locallang file format
- $locale : Locale|string|null
-
Locale with dependencies or language key. Null value is set to 'en' with fallback 'default'. @internal Language key as string loads language data with "en" and "default" as the default fallback dependency.
- $renewCache : bool = false
-
Recompute data and renew cache entry.
Return values
array<string, string|array<int, array<string, string>>>isLanguageFileDeprecated()
public
isLanguageFileDeprecated(string $fileReference) : bool
Parameters
- $fileReference : string
Not part of TYPO3 Core API. Do not use outside of TYPO3 Core as this method may vanish at any time.
Return values
boolwarmupTranslatorResource()
Preload files into Symfony Translator without retrieving catalogues.
public
warmupTranslatorResource(string $fileReference, Locale $locale) : void
This is used during cache warmup to batch all addResource() calls before any getCatalogue() calls, avoiding O(n²) catalogue rebuilds.
Parameters
- $fileReference : string
- $locale : Locale
addFileReferenceToTranslator()
Adds translations of one resource to Symfony Translator
protected
addFileReferenceToTranslator(string $fileReference, string $locale, string $domainName) : void
Parameters
- $fileReference : string
- $locale : string
- $domainName : string
Tags
computeAllLanguageKeys()
protected
computeAllLanguageKeys(Locale $locale) : array<string|int, mixed>
Parameters
- $locale : Locale
Return values
array<string|int, mixed>computeFileDomainAndFallbacks()
Prepares file reference, domain, language fallbacks
protected
computeFileDomainAndFallbacks(string $fileReference, Locale $locale) : array{string, string, string[]}
Parameters
- $fileReference : string
- $locale : Locale
Return values
array{string, string, string[]}convertCatalogueToLegacyFormat()
Convert Symfony MessageCatalogue to TYPO3's legacy format
protected
convertCatalogueToLegacyFormat(MessageCatalogueInterface $catalogue, string $domain) : array<string|int, mixed>
Parameters
- $catalogue : MessageCatalogueInterface
- $domain : string
Return values
array<string|int, mixed>getMessageCatalogue()
Load complete catalogue for locale using Symfony Translator
protected
getMessageCatalogue(string $locale) : MessageCatalogueInterface
Parameters
- $locale : string
Return values
MessageCatalogueInterfaceloadFilesIntoSymfonyTranslator()
Load files into Symfony Translator
protected
loadFilesIntoSymfonyTranslator(string $fileReference, string $languageKey, string $domainName) : void
Parameters
- $fileReference : string
- $languageKey : string
- $domainName : string
loadLanguagesIntoSymfonyTranslator()
Load languages into Symfony Translator
protected
loadLanguagesIntoSymfonyTranslator(string $fileReference, string $domainName, array<string|int, mixed> $allLanguageKeysAsOrderedFallback) : void
Parameters
- $fileReference : string
- $domainName : string
- $allLanguageKeysAsOrderedFallback : array<string|int, mixed>
loadWithSymfonyTranslator()
Get the catalogue and convert to TYPO3 format
protected
loadWithSymfonyTranslator(string $languageKey, string $domainName) : array<string|int, mixed>
Parameters
- $languageKey : string
- $domainName : string
Return values
array<string|int, mixed>parseIcuPlural()
Simple parser for ICU plural format - extracts plural values
protected
parseIcuPlural(string $icuString) : array<string|int, mixed>
Parameters
- $icuString : string