51Degrees Pipeline for PHP

fiftyone\pipeline\translation\TranslationEngine Class Reference

Detailed Description

Generic translation engine.

Reads one or more properties from an upstream element, translates each value (string, list of strings, or weighted list of strings) into the language resolved from request evidence, and writes the translated values under this engine's element data key.

The locale is resolved from the evidence keys (in precedence order) query.translation, query.accept-language, header.accept-language, unless a fixed language is configured. See Languages::tryResolveLocale for the resolution rules, including the English short-circuit.

Inheritance diagram for fiftyone\pipeline\translation\TranslationEngine:

[legend]

Collaboration diagram for fiftyone\pipeline\translation\TranslationEngine:

[legend]

Public Member Functions

 __construct (string $elementDataKey, string $sourceElementDataKey, array $propertyMap, array $localeMaps, ?string $fixedLanguage=null, string $behavior=MissingTranslationBehavior::ORIGINAL)
 getEvidenceKeyFilter ()
 Function for getting the FlowElement's EvidenceKeyFilter Used by the filterEvidence method.
 processInternal (FlowData $flowData)
 Process FlowData - this is process function is usually overridden by specific FlowElements to do their core work.

Public Member Functions inherited from fiftyone\pipeline\engines\Engine

 getDataSourceTier ()
 Get the tier to which the current data source belongs.
 setCache (DataKeyedCache $cache)
 Add a cache to an engine.
 setRestrictedProperties (array $propertiesList)
 Add a subset of properties.
 inCache (FlowData $flowData)
 A method to check if a flowData's evidence is in the cache.
 process (FlowData $flowData)
 Engine's core process function.

Public Member Functions inherited from fiftyone\pipeline\core\FlowElement

 __construct ()
 A default dummy constructor is needed for there are classes inheriting this class deeper than 1-level of inheritance and calling parent::__construct() in their explicit constructors.
 filterEvidence (FlowData $flowData)
 Filter FlowData evidence using the FlowElement's EvidenceKeyFilter.
 filterEvidenceKey (string $key)
 Filter FlowData evidence using the FlowElement's EvidenceKeyFilter.
 onRegistration (Pipeline $pipeline)
 Callback called when an engine is added to a pipeline.
 getProperties ()
 Get properties Usually overridden by specific FlowElements.
 updatePropertyList ()
 Update a FlowElement's property list This is used by elements that are only aware of their properties at a later stage, such as cloud request based FlowElements or FlowElements that change their properties later based on new datafiles.

Data Fields

string $dataKey
const EVIDENCE_KEYS

Data Fields inherited from fiftyone\pipeline\engines\Engine

array $restrictedProperties

Data Fields inherited from fiftyone\pipeline\core\FlowElement

string $dataKey
array $properties = []
array $pipelines = []

Protected Member Functions

 buildTranslatedProperties (FlowData $flowData, Translator $translator)
 Translate every mapped property and return the result keyed by lower-cased destination property name.
 resolveTranslator (FlowData $flowData)
 Resolve the translator and locale to use for this request.
 getEvidenceValue (FlowData $flowData)
 Read the first non-blank translation evidence value, in precedence order.

Protected Attributes

array $propertyMap
string $sourceElementDataKey
string $fixedLanguage
string $behavior
array $translators = []
array $availableLocales = []
Translator $emptyTranslator

Constructor & Destructor Documentation

◆ __construct()

fiftyone\pipeline\translation\TranslationEngine::__construct ( string $elementDataKey,
string $sourceElementDataKey,
array $propertyMap,
array $localeMaps,
?string $fixedLanguage = null,
string $behavior = MissingTranslationBehavior::ORIGINAL )
Parameters
string$sourceElementDataKeyupstream element to read from
array<string,string>$propertyMap source => destination names
array<string,array<string,string>>$localeMaps locale => map
null | string$fixedLanguagea locale to always use, or null to resolve from evidence

Member Function Documentation

◆ buildTranslatedProperties()

fiftyone\pipeline\translation\TranslationEngine::buildTranslatedProperties ( FlowData $flowData,
Translator $translator )
protected

Translate every mapped property and return the result keyed by lower-cased destination property name.

Subclasses can call this, add further properties, and then set the element data themselves.

Returns
array<string, AspectPropertyValue>

◆ getEvidenceKeyFilter()

fiftyone\pipeline\translation\TranslationEngine::getEvidenceKeyFilter ( )

Function for getting the FlowElement's EvidenceKeyFilter Used by the filterEvidence method.

Reimplemented from fiftyone\pipeline\core\FlowElement.

◆ processInternal()

fiftyone\pipeline\translation\TranslationEngine::processInternal ( FlowData $flowData)

Process FlowData - this is process function is usually overridden by specific FlowElements to do their core work.

Reimplemented from fiftyone\pipeline\core\FlowElement.

Reimplemented in fiftyone\pipeline\ipintelligence\translation\CountriesTranslationEngine.

◆ resolveTranslator()

fiftyone\pipeline\translation\TranslationEngine::resolveTranslator ( FlowData $flowData)
protected

Resolve the translator and locale to use for this request.

Returns
array{translator: Translator, locale: null|string}

Field Documentation

◆ EVIDENCE_KEYS

const fiftyone\pipeline\translation\TranslationEngine::EVIDENCE_KEYS
Initial value:
= [
'query.translation',
'query.accept-language',
'header.accept-language',
]