TranslationDomainResolver

Read onlyYes

Pure utility class for resolving translation domains from file paths.

This class contains stateless methods for:

  • Converting file paths to translation domains
  • Validating domain names
  • Extracting locale prefixes from file names
  • Stripping file extensions

It has no dependencies on other localization classes, making it safe to inject into both LabelFileResolver and TranslationDomainMapper without creating circular dependencies.

Internal

not part of TYPO3's public API.

Table of Contents

Methods

getFileReferenceWithoutExtension()  : string
Strips the file extension from a file reference.
getLocaleFromLanguageFile()  : string|null
Extracts the locale prefix from a language file name.
isValidDomainName()  : bool
A valid domain consists of lowercase letters, numbers, underscores only and at least one dot in between.
mapFileNameToDomain()  : string
Maps a label resource file reference to a translation domain.
extractExtensionKey()  : string
Extracts the extension key from an EXT: file reference.
transformFilePathToResource()  : string
Transforms a file path to a resource name (for domain).
upperCamelCaseToSnakeCase()  : string
Converts UpperCamelCase to snake_case.

Methods

getFileReferenceWithoutExtension()

Strips the file extension from a file reference.

public getFileReferenceWithoutExtension(string $fileReference) : string

Examples:

  • "EXT:core/Resources/Private/Language/locallang.xlf" -> "EXT:core/Resources/Private/Language/locallang"
  • "locallang.xlf" -> "locallang"
Parameters
$fileReference : string
Return values
string

getLocaleFromLanguageFile()

Extracts the locale prefix from a language file name.

public getLocaleFromLanguageFile(string $fileName) : string|null

If a file is called "de_AT.locallang.xlf", this method returns "de_AT". If there is no locale prefix, NULL is returned.

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

Examples:

  • "de.locallang.xlf" -> "de"
  • "de_AT.locallang.xlf" -> "de_AT"
  • "fr-CA.messages.xlf" -> "fr-CA"
  • "locallang.xlf" -> null
  • "db.xlf" -> null
Parameters
$fileName : string
Return values
string|null

isValidDomainName()

A valid domain consists of lowercase letters, numbers, underscores only and at least one dot in between.

public isValidDomainName(string $domain) : bool
Parameters
$domain : string
Return values
bool

mapFileNameToDomain()

Maps a label resource file reference to a translation domain.

public mapFileNameToDomain(string $fileName) : string

Examples:

  • "EXT:core/Resources/Private/Language/locallang.xlf" -> "core.messages"
  • "EXT:backend/Resources/Private/Language/locallang_toolbar.xlf" -> "backend.toolbar"
  • "EXT:felogin/Configuration/Sets/Felogin/labels.xlf" -> "felogin.sets.felogin"
Parameters
$fileName : string
Return values
string

extractExtensionKey()

Extracts the extension key from an EXT: file reference.

protected extractExtensionKey(string $filePath) : string
Parameters
$filePath : string
Return values
string

transformFilePathToResource()

Transforms a file path to a resource name (for domain).

protected transformFilePathToResource(string $filePath, string $extensionKey) : string

Examples:

  • "Resources/Private/Language/locallang.xlf" -> "messages"
  • "Resources/Private/Language/locallang_toolbar.xlf" -> "toolbar"
  • "Resources/Private/Language/Form/locallang_tabs.xlf" -> "form.tabs"
  • "Configuration/Sets/Felogin/labels.xlf" -> "sets.felogin"
  • "EXT:example/ContentBlocks/ContentElements/simple-relation/language/labels.xlf" -> "content_blocks.content_elements.simple_relation.language.labels"
Parameters
$filePath : string
$extensionKey : string
Return values
string

upperCamelCaseToSnakeCase()

Converts UpperCamelCase to snake_case.

protected upperCamelCaseToSnakeCase(string $input) : string

Examples: "SudoMode" -> "sudo_mode", "Form" -> "form"

Parameters
$input : string
Return values
string
On this page

Search results