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:
Collaboration diagram for fiftyone\pipeline\translation\TranslationEngine:
Public Member Functions | |
| __construct (string|array $elementDataKey=[], ?string $sourceElementDataKey=null, array $propertyMap=[], array $localeMaps=[], ?string $fixedLanguage=null, string $missingTranslationBehavior=MissingTranslationBehavior::ORIGINAL, ?string $behavior=null) | |
| Builds the engine from its arguments, or from the settings array that PipelineBuilder::buildFromConfig passes every element it builds from a configuration file. | |
| getEvidenceKeyFilter () | |
| The Evidence this element accepts. | |
| 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 |
| const | DEFAULT_ELEMENT_DATA_KEY = 'translation' |
| The element data key of an engine built from settings, the key the .NET Translation Engine uses. | |
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 Member Functions inherited from fiftyone\pipeline\engines\Engine | |
| holdsValueForOneRequest (ElementData $data) | |
| Whether a result holds a value created for the one request that asked for it, such as a 51Did. | |
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|array | $elementDataKey = [], |
| ?string | $sourceElementDataKey = null, | ||
| array | $propertyMap = [], | ||
| array | $localeMaps = [], | ||
| ?string | $fixedLanguage = null, | ||
| string | $missingTranslationBehavior = MissingTranslationBehavior::ORIGINAL, | ||
| ?string | $behavior = null ) |
Builds the engine from its arguments, or from the settings array that PipelineBuilder::buildFromConfig passes every element it builds from a configuration file.
The settings use the specification's option names, SourceElementDataKey (required), FixedLanguage and MissingTranslationBehavior (Original, EmptyString or FlowError, in any case), or the same names in camelCase, the style the settings of other PHP elements use. This engine does not read sources and translations from settings, so an engine built from settings has none and returns no properties. A subclass that adds its own is the way to build a useful one from a configuration file.
- Parameters
-
string|array<string,mixed> $elementDataKey this engine's element data key, or the settings null | string $sourceElementDataKey upstream element to read from array<string,string> $propertyMap source => destination names array<string,array<string,string>> $localeMaps locale => map null | string $fixedLanguage a locale to always use, or null to resolve from evidence string $missingTranslationBehavior what a value with no translation gives, one of the MissingTranslationBehavior values null | string $behavior deprecated, use $missingTranslationBehavior. Used in its place when given.
- Exceptions
-
InvalidArgumentException when no source element data key is given, or the settings name a missing translation behavior that is not one of the three
Member Function Documentation
◆ buildTranslatedProperties()
|
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 | ( | ) |
The Evidence this element accepts.
An element overrides this to name the Evidence that can change its results. One that does not accepts no Evidence, so it never widens what the Pipeline keeps.
Reimplemented from fiftyone\pipeline\core\FlowElement.
◆ getEvidenceValue()
|
protected |
Read the first non-blank translation evidence value, in precedence order.
Each key is read through the evidence, which matches without regard to letter case, because a key arrives in the letters it was first set with.
◆ 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()
|
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 |
