LabelFileResolver

readonly class \TYPO3\CMS\Core\Localization\LabelFileResolver

Service class for resolving label file paths and determining loading order.

This class handles:

  • Path resolving for localization files
  • File name resolving with language variants
  • Detecting resource override files via $GLOBALS['TYPO3_CONF_VARS']['LANG']['resourceOverrides']
  • Determining file loading order without merging content

This class does not handle reading of file contents, and also returns the full path, so it does not care about caching. Should be handled at a more outer stage.

Attributes

#[Autoconfigure]
$public: true

Table of Contents

Constants

LABEL_DIRECTORIES  : array = ['Resources/Private/Language/', 'Configuration/...
Directories, relative to a package path, which are scanned for label files

Properties

$packageManager  : PackageManager
$translationDomainResolver  : TranslationDomainResolver

Methods

__construct()  : mixed
getAllLabelFilesOfPackage()  : array
Find all label files in a package, but also find overrides.
getFileReferenceWithoutExtension()  : string
getOverrideFilePaths()  : string[]
Get override file paths for localization
resolveFileReference()  : string|null
getAbsoluteFileReference()  : string
Get absolute file reference
getLocalizedLabelsPathPattern()  : string
Get localized labels path pattern for extensions
getOrderedFileResources()  : array
Finds the actual files needed to resolve a file resource.
getSupportedExtensions()  : array
resolveExtensionResourcePath()  : string
resolveLocalizedFilePath()  : string|null
Resolve localized file path by trying multiple location strategies.

Constants

LABEL_DIRECTORIES

Directories, relative to a package path, which are scanned for label files

public array LABEL_DIRECTORIES = ['Resources/Private/Language/', 'Configuration/Sets/']

Properties

Methods

getAllLabelFilesOfPackage()

Find all label files in a package, but also find overrides.

public getAllLabelFilesOfPackage(string $packageKey[, mixed $defaultLocaleOnlyForCacheWarmup = false ]) : array

All files are returned in the order they should be loaded.

Parameters

$packageKey : string
$defaultLocaleOnlyForCacheWarmup : mixed = false

Return values

array

getFileReferenceWithoutExtension()

public getFileReferenceWithoutExtension(string $fileReference) : string

Parameters

$fileReference : string

Return values

string

getOverrideFilePaths()

Get override file paths for localization

public getOverrideFilePaths(string $fileReference, string $locale) : string[]

This method returns an array of override file paths that should be loaded for the given file reference and language key. It supports both file path syntax (e.g., 'EXT:core/Resources/Private/Language/locallang.xlf') and domain syntax (e.g., 'core.messages').

Parameters

$fileReference : string
$locale : string

Return values

string[] —

Array of absolute file paths to override files

resolveFileReference()

public resolveFileReference(string $fileReference, string $locale) : string|null

Parameters

$fileReference : string
$locale : string

Tags

throws
FileNotFoundException

Return values

string|null

getAbsoluteFileReference()

Get absolute file reference

protected getAbsoluteFileReference(string $fileReference) : string

Parameters

$fileReference : string

Tags

throws
FileNotFoundException

Source localization file not found.

Return values

string

getLocalizedLabelsPathPattern()

Get localized labels path pattern for extensions

protected getLocalizedLabelsPathPattern(string $fileReference) : string

Parameters

$fileReference : string

Return values

string

getOrderedFileResources()

Finds the actual files needed to resolve a file resource.

protected getOrderedFileResources(string $fileReference, string $locale) : array

This should be used later-on directly in LocalizationFactory.

Parameters

$fileReference : string
$locale : string

Return values

array

getSupportedExtensions()

protected getSupportedExtensions() : array

Return values

array

resolveExtensionResourcePath()

protected resolveExtensionResourcePath(string $sourcePath, string $locale, string $fileReference) : string

Parameters

$sourcePath : string
$locale : string
$fileReference : string

Return values

string

resolveLocalizedFilePath()

Resolve localized file path by trying multiple location strategies.

protected resolveLocalizedFilePath(string $sourcePath, string $locale) : string|null

This method attempts to find localized versions of files in the following order:

  1. Check if the file already has the correct locale prefix (early return)
  2. Try same directory with locale prefix: "de.locallang.xlf" in same folder
  3. Try TYPO3 labels directory structure: "/var/labels/de/extension_key/path/de.filename.xlf"

Language variant handling:

  • Supports both underscore and hyphen variants: "de_CH" <-> "de-CH"
  • Tests both formats when resolving files

Examples:

  • Source: "/ext/core/Resources/Private/Language/locallang.xlf"
  • For locale "de": tries "de.locallang.xlf" in same dir, then "/var/labels/de/core/Resources/Private/Language/de.locallang.xlf"
  • For locale "de-CH": tries both "de-CH.locallang.xlf" and "de_CH.locallang.xlf" variants

Parameters

$sourcePath : string

Absolute path to the source localization file

$locale : string

Language locale (e.g., "de", "de-CH", "de_AT")

Return values

string|null —

Absolute path to the localized file, or null if no localized version found

On this page