class AttributeTranslationStrategy extends AbstractTranslationStrategy (View source)

Translation strategy that stores the translations in attributes of the same node.

Constants

NAME

Identifier of this strategy.

NULLFIELDS

Properties

protected DocumentManagerInterface $dm from AbstractTranslationStrategy
protected string $prefix Prefix to namespace properties or child nodes. from AbstractTranslationStrategy

Methods

setPrefix(string $prefix)

Set the namespace alias for translation extra properties.

string
getTranslatedPropertyName(string $locale, string $propertyName)

Determine the locale specific property name.

string
getTranslatedPropertyNameAssoc(string $locale, array $mapping)

Determine the locale specific property names for an assoc property.

saveTranslation(array $data, NodeInterface $node, ClassMetadata $metadata, string $locale)

Save the translatable fields of a node.

bool
loadTranslation(object $document, NodeInterface $node, ClassMetadata $metadata, string $locale)

Load the translatable fields of a node.

removeTranslation(object $document, NodeInterface $node, ClassMetadata $metadata, string $locale)

Remove the translated fields of a node in a given language.

removeAllTranslations(object $document, NodeInterface $node, ClassMetadata $metadata)

Removes all the translated fields for all translations of this node.

array
getLocalesFor(object $document, NodeInterface $node, ClassMetadata $metadata)

Get the list of locales persisted for this node.

array
getTranslatedPropertyPath(string $alias, string $propertyName, string $locale)

Get the location of the property for the base property name in a given language.

alterQueryForTranslation(QueryObjectModelFactoryInterface $qomf, SourceInterface $selector, ConstraintInterface $constraint = null, string $alias, string $locale)

This method allows a translation strategy to alter the query to integrate translations that are on other nodes.

Details

setPrefix(string $prefix)

Set the namespace alias for translation extra properties.

Parameters

string $prefix

string getTranslatedPropertyName(string $locale, string $propertyName)

Determine the locale specific property name.

Parameters

string $locale
string $propertyName the untranslated property name

Return Value

string the property name with the translation namespace.

string getTranslatedPropertyNameAssoc(string $locale, array $mapping)

Determine the locale specific property names for an assoc property.

Parameters

string $locale
array $mapping the mapping for the property

Return Value

string the property name with the translation namespace.

saveTranslation(array $data, NodeInterface $node, ClassMetadata $metadata, string $locale)

Save the translatable fields of a node.

Parameters

array $data Data to save (field name => value to persist)
NodeInterface $node The physical node in the content repository
ClassMetadata $metadata The Doctrine metadata of the document
string $locale The language to persist the translations to

bool loadTranslation(object $document, NodeInterface $node, ClassMetadata $metadata, string $locale)

Load the translatable fields of a node.

Either loads all translatable fields into the document and returns true or returns false if this is not possible.

Parameters

object $document The document in which to load the data
NodeInterface $node The physical node in the content repository
ClassMetadata $metadata The Doctrine metadata of the document
string $locale The language to load the translations from

Return Value

bool true if the translation was completely loaded, false otherwise

removeTranslation(object $document, NodeInterface $node, ClassMetadata $metadata, string $locale)

Remove the translated fields of a node in a given language.

The document object is not altered by this operation.

Parameters

object $document The document from which the translations must be removed
NodeInterface $node The physical node in the content repository
ClassMetadata $metadata The Doctrine metadata of the document
string $locale The language to remove

removeAllTranslations(object $document, NodeInterface $node, ClassMetadata $metadata)

Removes all the translated fields for all translations of this node.

This will only be called just before the node itself is removed.

Parameters

object $document The document from which the translations must be removed
NodeInterface $node The physical node in the content repository
ClassMetadata $metadata The Doctrine metadata of the document

array getLocalesFor(object $document, NodeInterface $node, ClassMetadata $metadata)

Get the list of locales persisted for this node.

Parameters

object $document The document that must be checked
NodeInterface $node The Physical node in the content repository
ClassMetadata $metadata The Doctrine metadata of the document

Return Value

array with the locales strings

array getTranslatedPropertyPath(string $alias, string $propertyName, string $locale)

Get the location of the property for the base property name in a given language.

Parameters

string $alias The selector alias of the main node.
string $propertyName The base name of the translated property.
string $locale The requested locale.

Return Value

array with first alias, then the real property name.

alterQueryForTranslation(QueryObjectModelFactoryInterface $qomf, SourceInterface $selector, ConstraintInterface $constraint = null, string $alias, string $locale)

This method allows a translation strategy to alter the query to integrate translations that are on other nodes.

Only called once per alias value. The selector and constraint are passed by reference, the strategy can alter them to let the ConverterInterface instance generate a different query.

Parameters

QueryObjectModelFactoryInterface $qomf The PHPCR query factory.
SourceInterface $selector The current selector.
ConstraintInterface $constraint The current constraint, may be empty.
string $alias The selector alias of the main node.
string $locale The language to use.