‪TYPO3CMS  ‪main
TYPO3\CMS\Form\Service\TranslationService Class Reference
Inheritance diagram for TYPO3\CMS\Form\Service\TranslationService:
TYPO3\CMS\Core\SingletonInterface

Public Member Functions

 __construct (protected readonly ConfigurationManagerInterface $configurationManager, protected readonly LanguageServiceFactory $languageServiceFactory, protected readonly FrontendInterface $runtimeCache, protected readonly Locales $locales)
 
mixed translate ( $key, array $arguments=null, string $locallangPathAndFilename=null, string $language=null, $defaultValue='')
 
array translateValuesRecursive (array $array, array $translationFiles=[])
 
array translateToAllBackendLanguages (string $key, array $arguments=null, array $translationFiles=[])
 
 translateFinisherOption (FormRuntime $formRuntime, string $finisherIdentifier, string $optionKey, string $optionValue, array $renderingOptions=[])
 
string array translateFormElementValue (RootRenderableInterface $element, array $propertyParts, FormRuntime $formRuntime)
 
 translateFormElementError (RootRenderableInterface $element, int $code, array $arguments, string $defaultValue, FormRuntime $formRuntime)
 
 setLanguage (string $languageKey)
 
 getLanguage ()
 

Protected Member Functions

string null processTranslationChain (array $translationKeyChain, string $language=null, array $arguments=null)
 
 initializeLocalization (string $locallangPathAndFilename)
 
 buildLanguageService (string $languageKey, $languageFilePath)
 
 setLanguageKeys (?string $language)
 
 loadTypoScriptLabels ()
 
array flattenTypoScriptLabelArray (array $labelValues, string $parentKey='')
 
 sortArrayWithIntegerKeysDescending (array $array)
 
 isEmptyTranslatedValue (mixed $translatedValue)
 
 getCurrentSiteLanguage ()
 

Protected Attributes

string $languageKey = ''
 

Detailed Description

Advanced translations This class is subjected to change. Do NOT subclass

Scope: frontend / backend

Definition at line 44 of file TranslationService.php.

Constructor & Destructor Documentation

◆ __construct()

TYPO3\CMS\Form\Service\TranslationService::__construct ( protected readonly ConfigurationManagerInterface  $configurationManager,
protected readonly LanguageServiceFactory  $languageServiceFactory,
protected readonly FrontendInterface  $runtimeCache,
protected readonly Locales  $locales 
)

Definition at line 53 of file TranslationService.php.

Member Function Documentation

◆ buildLanguageService()

TYPO3\CMS\Form\Service\TranslationService::buildLanguageService ( string  $languageKey,
  $languageFilePath 
)
protected

◆ flattenTypoScriptLabelArray()

array TYPO3\CMS\Form\Service\TranslationService::flattenTypoScriptLabelArray ( array  $labelValues,
string  $parentKey = '' 
)
protected

Flatten TypoScript label array; converting a hierarchical array into a flat array with the keys separated by dots.

Example Input: array('k1' => array('subkey1' => 'val1')) Example Output: array('k1.subkey1' => 'val1')

Parameters
array$labelValues‪Hierarchical array of labels
string$parentKey‪the name of the parent key in the recursion; is only needed for recursion.
Returns
‪array flattened array of labels.

Definition at line 567 of file TranslationService.php.

Referenced by TYPO3\CMS\Form\Service\TranslationService\loadTypoScriptLabels().

◆ getCurrentSiteLanguage()

TYPO3\CMS\Form\Service\TranslationService::getCurrentSiteLanguage ( )
protected

Returns the currently configured "site language" if a site is configured (= resolved) in the current request.

Definition at line 629 of file TranslationService.php.

References $GLOBALS.

Referenced by TYPO3\CMS\Form\Service\TranslationService\setLanguageKeys().

◆ getLanguage()

TYPO3\CMS\Form\Service\TranslationService::getLanguage ( )

◆ initializeLocalization()

TYPO3\CMS\Form\Service\TranslationService::initializeLocalization ( string  $locallangPathAndFilename)
protected

◆ isEmptyTranslatedValue()

TYPO3\CMS\Form\Service\TranslationService::isEmptyTranslatedValue ( mixed  $translatedValue)
protected

Check if given translated value is considered "empty".

A translated value is considered "empty" if it's either NULL or an empty string. This helper method exists to perform a less strict check than the native {

See also
‪empty()} function, because it is too strict in terms of supported translated values. For example, the value "0" is valid, whereas {
‪empty()} would handle it as "empty" and therefore invalid.

Definition at line 605 of file TranslationService.php.

Referenced by TYPO3\CMS\Form\Service\TranslationService\processTranslationChain(), TYPO3\CMS\Form\Service\TranslationService\translateFinisherOption(), TYPO3\CMS\Form\Service\TranslationService\translateFormElementError(), and TYPO3\CMS\Form\Service\TranslationService\translateFormElementValue().

◆ loadTypoScriptLabels()

TYPO3\CMS\Form\Service\TranslationService::loadTypoScriptLabels ( )
protected

Overwrites labels that are set via TypoScript. TS labels have to be configured like: plugin.tx_myextension._LOCAL_LANG.languageKey.key = value

Definition at line 531 of file TranslationService.php.

References TYPO3\CMS\Form\Service\TranslationService\$languageKey, TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface\CONFIGURATION_TYPE_FRAMEWORK, and TYPO3\CMS\Form\Service\TranslationService\flattenTypoScriptLabelArray().

Referenced by TYPO3\CMS\Form\Service\TranslationService\initializeLocalization().

◆ processTranslationChain()

string null TYPO3\CMS\Form\Service\TranslationService::processTranslationChain ( array  $translationKeyChain,
string  $language = null,
array  $arguments = null 
)
protected

◆ setLanguage()

TYPO3\CMS\Form\Service\TranslationService::setLanguage ( string  $languageKey)

◆ setLanguageKeys()

TYPO3\CMS\Form\Service\TranslationService::setLanguageKeys ( ?string  $language)
protected

◆ sortArrayWithIntegerKeysDescending()

◆ translate()

mixed TYPO3\CMS\Form\Service\TranslationService::translate (   $key,
array  $arguments = null,
string  $locallangPathAndFilename = null,
string  $language = null,
  $defaultValue = '' 
)

Returns the localized label of the LOCAL_LANG key, $key.

Parameters
mixed$key‪The key from the LOCAL_LANG array for which to return the value.
array | null$arguments‪the arguments of the extension, being passed over to vsprintf
mixed$defaultValue
Returns
‪mixed The value from LOCAL_LANG or $defaultValue if no translation was found.

Definition at line 69 of file TranslationService.php.

References TYPO3\CMS\Form\Service\TranslationService\initializeLocalization(), TYPO3\CMS\Core\Utility\PathUtility\isExtensionPath(), and TYPO3\CMS\Form\Service\TranslationService\setLanguageKeys().

Referenced by TYPO3\CMS\Form\Service\TranslationService\processTranslationChain(), TYPO3\CMS\Form\Service\TranslationService\translateToAllBackendLanguages(), and TYPO3\CMS\Form\Service\TranslationService\translateValuesRecursive().

◆ translateFinisherOption()

◆ translateFormElementError()

◆ translateFormElementValue()

◆ translateToAllBackendLanguages()

array TYPO3\CMS\Form\Service\TranslationService::translateToAllBackendLanguages ( string  $key,
array  $arguments = null,
array  $translationFiles = [] 
)

◆ translateValuesRecursive()

array TYPO3\CMS\Form\Service\TranslationService::translateValuesRecursive ( array  $array,
array  $translationFiles = [] 
)

Recursively translate values.

Returns
‪array the modified array

Definition at line 126 of file TranslationService.php.

References TYPO3\CMS\Form\Service\TranslationService\sortArrayWithIntegerKeysDescending(), and TYPO3\CMS\Form\Service\TranslationService\translate().

Member Data Documentation

◆ $languageKey