LabelFileResolver

Read onlyYes

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.

Internal

not part of TYPO3's public API.

Attributes
#[Autoconfigure]
$public: true

Table of Contents

Properties

$packageManager  : PackageManager

Methods

__construct()  : mixed
getAllLabelFilesOfPackage()  : array<string|int, mixed>
Find all label files in a package, but also find overrides.
getFileReferenceWithoutExtension()  : string
getLocaleFromLanguageFile()  : string|null
If a file is called "de_AT.locallang.xlf", this method returns "de_AT".
getOverrideFilePaths()  : array<string|int, string>
Get override file paths for localization
resolveFileReference()  : string
getAbsoluteFileReference()  : string
Get absolute file reference
getLocalizedLabelsPathPattern()  : string
Get localized labels path pattern for extensions
getOrderedFileResources()  : array<string|int, mixed>
Finds the actual files needed to resolve a file resource.
getSupportedExtensions()  : array<string|int, mixed>
resolveExtensionResourcePath()  : string
resolveLocalizedFilePath()  : string
Resolve localized file path by trying multiple location strategies.

Properties

Methods

getAllLabelFilesOfPackage()

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

public getAllLabelFilesOfPackage(string $packageKey) : array<string|int, mixed>

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

Parameters
$packageKey : string
Return values
array<string|int, mixed>

getFileReferenceWithoutExtension()

public getFileReferenceWithoutExtension(string $fileReference) : string
Parameters
$fileReference : string
Return values
string

getLocaleFromLanguageFile()

If a file is called "de_AT.locallang.xlf", this method returns "de_AT".

public getLocaleFromLanguageFile(string $fileName) : string|null

If there is no suffix, NULL is returned.

However, for files like "db.xlf", "db" should not be detected as locale

Parameters
$fileName : string
Return values
string|null

getOverrideFilePaths()

Get override file paths for localization

public getOverrideFilePaths(string $fileReference, string $locale) : array<string|int, string>

This method returns an array of override file paths that should be loaded for the given file reference and language key

Parameters
$fileReference : string
$locale : string
Return values
array<string|int, string>

Array of absolute file paths to override files

resolveFileReference()

public resolveFileReference(string $fileReference, string $locale[, bool $useDefault = true ]) : string
Parameters
$fileReference : string
$locale : string
$useDefault : bool = true
Return values
string

getAbsoluteFileReference()

Get absolute file reference

protected getAbsoluteFileReference(string $fileReference) : string
Parameters
$fileReference : string
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<string|int, mixed>

This should be used later-on directly in LocalizationFactory.

Parameters
$fileReference : string
$locale : string
Return values
array<string|int, mixed>

getSupportedExtensions()

protected getSupportedExtensions() : array<string|int, mixed>
Return values
array<string|int, mixed>

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

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/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

Absolute path to the localized file, or original path if not found


        
On this page

Search results