3 namespace Drupal\locale;
6 * Defines the locale translation string object.
8 * This class represents a translation of a source string to a given language,
9 * thus it must have at least a 'language' which is the language code and a
10 * 'translation' property which is the translated text of the source string
11 * in the specified language.
13 class TranslationString extends StringBase {
22 * The string translation.
29 * Integer indicating whether this string is customized.
36 * Boolean indicating whether the string object is new.
45 public function __construct($values = []) {
46 parent::__construct($values);
47 if (!isset($this->isNew)) {
48 // We mark the string as not new if it is a complete translation.
49 // This will work when loading from database, otherwise the storage
50 // controller that creates the string object must handle it.
51 $this->isNew = !$this->isTranslation();
56 * Sets the string as customized / not customized.
58 * @param bool $customized
59 * (optional) Whether the string is customized or not. Defaults to TRUE.
61 * @return \Drupal\locale\TranslationString
64 public function setCustomized($customized = TRUE) {
65 $this->customized = $customized ? LOCALE_CUSTOMIZED : LOCALE_NOT_CUSTOMIZED;
72 public function isSource() {
79 public function isTranslation() {
80 return !empty($this->lid) && !empty($this->language) && isset($this->translation);
86 public function getString() {
87 return isset($this->translation) ? $this->translation : '';
93 public function setString($string) {
94 $this->translation = $string;
101 public function isNew() {
108 public function save() {
110 $this->isNew = FALSE;
117 public function delete() {