interface TranslatableInterface (View source)

Interface for translatable data.

Classes implementing this interface do not necessarily support translations.

To detect whether an entity type supports translation, call EntityTypeInterface::isTranslatable().

Many entity interfaces are composed of numerous other interfaces such as this one, which allow implementations to pick and choose which features to support through stub implementations of various interface methods. This means that even if an entity class implements TranslatableInterface, it might only have a stub implementation and not a functional one.

Methods

language()

Returns the translation language.

bool
isDefaultTranslation()

Checks whether the translation is the default one.

bool
isNewTranslation()

Checks whether the translation is new.

getTranslationLanguages(bool $include_default = TRUE)

Returns the languages the data is translated to.

$this
getTranslation($langcode)

Gets a translation of the data.

$this
getUntranslated()

Returns the translatable object referring to the original language.

bool
hasTranslation(string $langcode)

Checks there is a translation for the given language code.

$this
addTranslation(string $langcode, array $values = [])

Adds a new translation to the translatable object.

removeTranslation(string $langcode)

Removes the translation identified by the given language code.

bool
isTranslatable()

Returns the translation support status.

Details

LanguageInterface language()

Returns the translation language.

Return Value

LanguageInterface

The language object.

bool isDefaultTranslation()

Checks whether the translation is the default one.

Return Value

bool

TRUE if the translation is the default one, FALSE otherwise.

bool isNewTranslation()

Checks whether the translation is new.

Return Value

bool

TRUE if the translation is new, FALSE otherwise.

LanguageInterface[] getTranslationLanguages(bool $include_default = TRUE)

Returns the languages the data is translated to.

Parameters

bool $include_default

(optional) Whether the default language should be included. Defaults to TRUE.

Return Value

LanguageInterface[]

An associative array of language objects, keyed by language codes.

$this getTranslation($langcode)

Gets a translation of the data.

The returned translation has to be of the same type than this typed data object.

Parameters

$langcode

The language code of the translation to get or LanguageInterface::LANGCODE_DEFAULT to get the data in default language.

Return Value

$this

A typed data object for the translated data.

Exceptions

InvalidArgumentException

$this getUntranslated()

Returns the translatable object referring to the original language.

Return Value

$this

The translation object referring to the original language.

bool hasTranslation(string $langcode)

Checks there is a translation for the given language code.

Parameters

string $langcode

The language code identifying the translation.

Return Value

bool

TRUE if the translation exists, FALSE otherwise.

$this addTranslation(string $langcode, array $values = [])

Adds a new translation to the translatable object.

To create a translation of an entity prefilled with the original data:

Parameters

string $langcode

The language code identifying the translation.

array $values

(optional) An array of initial values to be assigned to the translatable fields. Defaults to none.

Return Value

$this

Exceptions

InvalidArgumentException

removeTranslation(string $langcode)

Removes the translation identified by the given language code.

Parameters

string $langcode

The language code identifying the translation to be removed.

bool isTranslatable()

Returns the translation support status.

Return Value

bool

TRUE if the object has translation support enabled.