You are here

class TranslationString in Localization update 7.2

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

1 string reference to 'TranslationString'
StringDatabaseStorage::getTranslations in includes/locale/StringDatabaseStorage.php
Implements StringStorageInterface::getTranslations().

File

includes/locale/TranslationString.php, line 16
Definition of TranslationString.

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 integer
   */
  public $customized;

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

  /**
   * Overrides 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 TranslationString
   *   The called object.
   */
  public function setCustomized($customized = TRUE) {
    $this->customized = $customized ? L10N_UPDATE_CUSTOMIZED : L10N_UPDATE_NOT_CUSTOMIZED;
    return $this;
  }

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

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

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

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

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

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

  /**
   * Implements 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::$plid public property The parent string identifier for plural translations.
StringBase::$plural public property Plural index in case of plural string.
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::$textgroup public property The string group.
StringBase::$version public property The string version.
StringBase::getId public function Implements StringInterface::getId(). Overrides StringInterface::getId
StringBase::getParentId public function Implements StringInterface::getParentId(). Overrides StringInterface::getParentId 1
StringBase::getStorage public function Implements StringInterface::getStorage(). Overrides StringInterface::getStorage
StringBase::getTextgroup public function Implements StringInterface::getTextgroup(). Overrides StringInterface::getTextgroup
StringBase::getValues public function Implements StringInterface::getValues(). Overrides StringInterface::getValues
StringBase::getVersion public function Implements StringInterface::getVersion(). Overrides StringInterface::getVersion
StringBase::setId public function Implements StringInterface::setId(). Overrides StringInterface::setId
StringBase::setParentId public function Implements StringInterface::setParentId(). Overrides StringInterface::setParentId
StringBase::setStorage public function Implements StringInterface::setStorage(). Overrides StringInterface::setStorage
StringBase::setTextgroup public function Implements StringInterface::setTextgroup(). Overrides StringInterface::setTextgroup
StringBase::setValues public function Implements StringInterface::setValues(). Overrides StringInterface::setValues
StringBase::setVersion public function Implements 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 StringInterface::delete(). Overrides StringBase::delete
TranslationString::getString public function Implements StringInterface::getString(). Overrides StringInterface::getString
TranslationString::isNew public function Implements StringInterface::isNew(). Overrides StringInterface::isNew
TranslationString::isSource public function Implements StringInterface::isSource(). Overrides StringInterface::isSource
TranslationString::isTranslation public function Implements StringInterface::isTranslation(). Overrides StringInterface::isTranslation
TranslationString::save public function Implements StringInterface::save(). Overrides StringBase::save
TranslationString::setCustomized public function Sets the string as customized / not customized.
TranslationString::setString public function Implements StringInterface::setString(). Overrides StringInterface::setString
TranslationString::__construct public function Overrides StringBase::__construct(). Overrides StringBase::__construct