class TranslationString in Drupal 8
Same name and namespace in other branches
- 9 core/modules/locale/src/TranslationString.php \Drupal\locale\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 source string in the specified language.
Hierarchy
- class \Drupal\locale\StringBase implements StringInterface
- class \Drupal\locale\TranslationString
Expanded class hierarchy of TranslationString
1 file declares its use of TranslationString
- LocaleConfigSubscriberTest.php in core/
modules/ locale/ tests/ src/ Kernel/ LocaleConfigSubscriberTest.php
File
- core/
modules/ locale/ src/ TranslationString.php, line 13
Namespace
Drupal\localeView 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 $isNew;
/**
* {@inheritdoc}
*/
public function __construct($values = []) {
parent::__construct($values);
if (!isset($this->isNew)) {
// 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->isNew = !$this
->isTranslation();
}
}
/**
* Sets the string as customized / not customized.
*
* @param bool $customized
* (optional) Whether the string is customized or not. Defaults to TRUE.
*
* @return $this
* The called object.
*/
public function setCustomized($customized = TRUE) {
$this->customized = $customized ? LOCALE_CUSTOMIZED : LOCALE_NOT_CUSTOMIZED;
return $this;
}
/**
* {@inheritdoc}
*/
public function isSource() {
return FALSE;
}
/**
* {@inheritdoc}
*/
public function isTranslation() {
return !empty($this->lid) && !empty($this->language) && isset($this->translation);
}
/**
* {@inheritdoc}
*/
public function getString() {
return isset($this->translation) ? $this->translation : '';
}
/**
* {@inheritdoc}
*/
public function setString($string) {
$this->translation = $string;
return $this;
}
/**
* {@inheritdoc}
*/
public function isNew() {
return $this->isNew;
}
/**
* {@inheritdoc}
*/
public function save() {
parent::save();
$this->isNew = FALSE;
return $this;
}
/**
* {@inheritdoc}
*/
public function delete() {
parent::delete();
$this->isNew = TRUE;
return $this;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
StringBase:: |
public | property | The string context. | |
StringBase:: |
public | property | The string identifier. | |
StringBase:: |
public | property | The string locations indexed by type. | |
StringBase:: |
public | property | The source string. | |
StringBase:: |
protected | property | The locale storage this string comes from or is to be saved to. | |
StringBase:: |
public | property | The string version. | |
StringBase:: |
public | function |
Adds a location for this string. Overrides StringInterface:: |
|
StringBase:: |
public | function |
Gets the string unique identifier. Overrides StringInterface:: |
|
StringBase:: |
public | function |
Gets location information for this string. Overrides StringInterface:: |
|
StringBase:: |
public | function |
Splits string to work with plural values. Overrides StringInterface:: |
|
StringBase:: |
public | function |
Gets the string storage. Overrides StringInterface:: |
|
StringBase:: |
public | function |
Gets field values that are set for given field names. Overrides StringInterface:: |
|
StringBase:: |
public | function |
Gets the string version. Overrides StringInterface:: |
|
StringBase:: |
public | function |
Checks whether the string has a given location. Overrides StringInterface:: |
|
StringBase:: |
public | function |
Sets the string unique identifier. Overrides StringInterface:: |
|
StringBase:: |
public | function |
Sets this string using array of plural values. Overrides StringInterface:: |
|
StringBase:: |
public | function |
Sets the string storage. Overrides StringInterface:: |
|
StringBase:: |
public | function |
Sets an array of values as object properties. Overrides StringInterface:: |
|
StringBase:: |
public | function |
Sets the string version. Overrides StringInterface:: |
|
TranslationString:: |
public | property | Integer indicating whether this string is customized. | |
TranslationString:: |
protected | property | Boolean indicating whether the string object is new. | |
TranslationString:: |
public | property | The language code. | |
TranslationString:: |
public | property | The string translation. | |
TranslationString:: |
public | function |
Deletes string object from storage. Overrides StringBase:: |
|
TranslationString:: |
public | function |
Gets plain string contained in this object. Overrides StringInterface:: |
|
TranslationString:: |
public | function |
Checks whether the object is not saved to storage yet. Overrides StringInterface:: |
|
TranslationString:: |
public | function |
Checks whether the object is a source string. Overrides StringInterface:: |
|
TranslationString:: |
public | function |
Checks whether the object is a translation string. Overrides StringInterface:: |
|
TranslationString:: |
public | function |
Saves string object to storage. Overrides StringBase:: |
|
TranslationString:: |
public | function | Sets the string as customized / not customized. | |
TranslationString:: |
public | function |
Sets the string contained in this object. Overrides StringInterface:: |
|
TranslationString:: |
public | function |
Constructs a new locale string object. Overrides StringBase:: |