3 namespace Drupal\Core\TypedData;
6 * Interface for translatable data.
8 * Classes implementing this interface do not necessarily support translations.
10 * To detect whether an entity type supports translation, call
11 * EntityTypeInterface::isTranslatable().
13 * Many entity interfaces are composed of numerous other interfaces such as this
14 * one, which allow implementations to pick and choose which features to support
15 * through stub implementations of various interface methods. This means that
16 * even if an entity class implements TranslatableInterface, it might only have
17 * a stub implementation and not a functional one.
19 * @see \Drupal\Core\Entity\EntityTypeInterface::isTranslatable()
20 * @see https://www.drupal.org/docs/8/api/entity-api/structure-of-an-entity-annotation
21 * @see https://www.drupal.org/docs/8/api/entity-api/entity-translation-api
23 interface TranslatableInterface {
26 * Returns the translation language.
28 * @return \Drupal\Core\Language\LanguageInterface
29 * The language object.
31 public function language();
34 * Checks whether the translation is the default one.
37 * TRUE if the translation is the default one, FALSE otherwise.
39 public function isDefaultTranslation();
42 * Checks whether the translation is new.
45 * TRUE if the translation is new, FALSE otherwise.
47 public function isNewTranslation();
50 * Returns the languages the data is translated to.
52 * @param bool $include_default
53 * (optional) Whether the default language should be included. Defaults to
56 * @return \Drupal\Core\Language\LanguageInterface[]
57 * An associative array of language objects, keyed by language codes.
59 public function getTranslationLanguages($include_default = TRUE);
62 * Gets a translation of the data.
64 * The returned translation has to be of the same type than this typed data
68 * The language code of the translation to get or
69 * LanguageInterface::LANGCODE_DEFAULT
70 * to get the data in default language.
73 * A typed data object for the translated data.
75 * @throws \InvalidArgumentException
76 * If an invalid or non-existing translation language is specified.
78 public function getTranslation($langcode);
81 * Returns the translatable object referring to the original language.
84 * The translation object referring to the original language.
86 public function getUntranslated();
89 * Checks there is a translation for the given language code.
91 * @param string $langcode
92 * The language code identifying the translation.
95 * TRUE if the translation exists, FALSE otherwise.
97 public function hasTranslation($langcode);
100 * Adds a new translation to the translatable object.
102 * @param string $langcode
103 * The language code identifying the translation.
104 * @param array $values
105 * (optional) An array of initial values to be assigned to the translatable
106 * fields. Defaults to none.
110 * @throws \InvalidArgumentException
111 * If an invalid or existing translation language is specified.
113 public function addTranslation($langcode, array $values = []);
116 * Removes the translation identified by the given language code.
118 * @param string $langcode
119 * The language code identifying the translation to be removed.
121 public function removeTranslation($langcode);
124 * Returns the translation support status.
127 * TRUE if the object has translation support enabled.
129 public function isTranslatable();