class TranslationString

Defines the locale translation string object.

This class represents a translation of a source string to a given language, thus it must have at least a 'language' which is the language code and a 'translation' property which is the translated text of the the source string in the specified language.

Hierarchy

Expanded class hierarchy of TranslationString

5 files declare their use of TranslationString
locale.pages.inc in drupal/core/modules/locale/locale.pages.inc
Interface translation summary, editing and deletion user interfaces.
LocaleLookup.php in drupal/core/modules/locale/lib/Drupal/locale/LocaleLookup.php
Definition of LocaleLookup
LocaleStringTest.php in drupal/core/modules/locale/lib/Drupal/locale/Tests/LocaleStringTest.php
Definition of Drupal\locale\Tests\LocaleStringTest.
PoDatabaseReader.php in drupal/core/modules/locale/lib/Drupal/locale/PoDatabaseReader.php
Definition of Drupal\locale\PoDatabaseReader.
PoDatabaseWriter.php in drupal/core/modules/locale/lib/Drupal/locale/PoDatabaseWriter.php
Definition of Drupal\locale\PoDatabaseWriter.

File

drupal/core/modules/locale/lib/Drupal/locale/TranslationString.php, line 18
Definition of Drupal\locale\TranslationString.

Namespace

Drupal\locale
View source
class TranslationString extends StringBase {

  /**
   * The language code.
   *
   * @var string
   */
  public $language;

  /**
   * The string translation.
   *
   * @var string
   */
  public $translation;

  /**
   * Integer indicating whether this string is customized.
   *
   * @var int
   */
  public $customized;

  /**
   * Boolean indicating whether the string object is new.
   *
   * @var bool
   */
  protected $is_new;

  /**
   * Overrides Drupal\locale\StringBase::__construct().
   */
  public function __construct($values = array()) {
    parent::__construct($values);
    if (!isset($this->is_new)) {

      // We mark the string as not new if it is a complete translation.
      // This will work when loading from database, otherwise the storage
      // controller that creates the string object must handle it.
      $this->is_new = !$this
        ->isTranslation();
    }
  }

  /**
   * Sets the string as customized / not customized.
   *
   * @param bool $customized
   *   (optional) Whether the string is customized or not. Defaults to TRUE.
   *
   * @return Drupal\locale\TranslationString
   *   The called object.
   */
  public function setCustomized($customized = TRUE) {
    $this->customized = $customized ? LOCALE_CUSTOMIZED : LOCALE_NOT_CUSTOMIZED;
    return $this;
  }

  /**
   * Implements Drupal\locale\StringInterface::isSource().
   */
  public function isSource() {
    return FALSE;
  }

  /**
   * Implements Drupal\locale\StringInterface::isTranslation().
   */
  public function isTranslation() {
    return !empty($this->lid) && !empty($this->language) && isset($this->translation);
  }

  /**
   * Implements Drupal\locale\StringInterface::getString().
   */
  public function getString() {
    return isset($this->translation) ? $this->translation : '';
  }

  /**
   * Implements Drupal\locale\StringInterface::setString().
   */
  public function setString($string) {
    $this->translation = $string;
    return $this;
  }

  /**
   * Implements Drupal\locale\StringInterface::isNew().
   */
  public function isNew() {
    return $this->is_new;
  }

  /**
   * Implements Drupal\locale\StringInterface::save().
   */
  public function save() {
    parent::save();
    $this->is_new = FALSE;
    return $this;
  }

  /**
   * Implements Drupal\locale\StringInterface::delete().
   */
  public function delete() {
    parent::delete();
    $this->is_new = TRUE;
    return $this;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
StringBase::$context public property The string context.
StringBase::$lid public property The string identifier.
StringBase::$locations public property The string locations indexed by type.
StringBase::$source public property The source string.
StringBase::$storage protected property The locale storage this string comes from or is to be saved to.
StringBase::$version public property The string version.
StringBase::addLocation public function Implements Drupal\locale\StringInterface::addLocation(). Overrides StringInterface::addLocation
StringBase::getId public function Implements Drupal\locale\StringInterface::getId(). Overrides StringInterface::getId
StringBase::getLocations public function Implements Drupal\locale\StringInterface::getLocation(). Overrides StringInterface::getLocations
StringBase::getPlurals public function Implements Drupal\locale\StringInterface::getPlurals(). Overrides StringInterface::getPlurals
StringBase::getStorage public function Implements Drupal\locale\StringInterface::getStorage(). Overrides StringInterface::getStorage
StringBase::getValues public function Implements Drupal\locale\StringInterface::getValues(). Overrides StringInterface::getValues
StringBase::getVersion public function Implements Drupal\locale\StringInterface::getVersion(). Overrides StringInterface::getVersion
StringBase::hasLocation public function Implements Drupal\locale\StringInterface::hasLocation(). Overrides StringInterface::hasLocation
StringBase::setId public function Implements Drupal\locale\StringInterface::setId(). Overrides StringInterface::setId
StringBase::setPlurals public function Implements Drupal\locale\StringInterface::setPlurals(). Overrides StringInterface::setPlurals
StringBase::setStorage public function Implements Drupal\locale\StringInterface::setStorage(). Overrides StringInterface::setStorage
StringBase::setValues public function Implements Drupal\locale\StringInterface::setValues(). Overrides StringInterface::setValues
StringBase::setVersion public function Implements Drupal\locale\StringInterface::setVersion(). Overrides StringInterface::setVersion
TranslationString::$customized public property Integer indicating whether this string is customized.
TranslationString::$is_new protected property Boolean indicating whether the string object is new.
TranslationString::$language public property The language code.
TranslationString::$translation public property The string translation.
TranslationString::delete public function Implements Drupal\locale\StringInterface::delete(). Overrides StringBase::delete
TranslationString::getString public function Implements Drupal\locale\StringInterface::getString(). Overrides StringInterface::getString
TranslationString::isNew public function Implements Drupal\locale\StringInterface::isNew(). Overrides StringInterface::isNew
TranslationString::isSource public function Implements Drupal\locale\StringInterface::isSource(). Overrides StringInterface::isSource
TranslationString::isTranslation public function Implements Drupal\locale\StringInterface::isTranslation(). Overrides StringInterface::isTranslation
TranslationString::save public function Implements Drupal\locale\StringInterface::save(). Overrides StringBase::save
TranslationString::setCustomized public function Sets the string as customized / not customized.
TranslationString::setString public function Implements Drupal\locale\StringInterface::setString(). Overrides StringInterface::setString
TranslationString::__construct public function Overrides Drupal\locale\StringBase::__construct(). Overrides StringBase::__construct