TranslationString.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. /**
  3. * @file
  4. * Definition of TranslationString.
  5. */
  6. /**
  7. * Defines the locale translation string object.
  8. *
  9. * This class represents a translation of a source string to a given language,
  10. * thus it must have at least a 'language' which is the language code and a
  11. * 'translation' property which is the translated text of the the source string
  12. * in the specified language.
  13. */
  14. class TranslationString extends StringBase {
  15. /**
  16. * The language code.
  17. *
  18. * @var string
  19. */
  20. public $language;
  21. /**
  22. * The string translation.
  23. *
  24. * @var string
  25. */
  26. public $translation;
  27. /**
  28. * Integer indicating whether this string is customized.
  29. *
  30. * @var int
  31. */
  32. public $customized;
  33. /**
  34. * Boolean indicating whether the string object is new.
  35. *
  36. * @var bool
  37. */
  38. protected $is_new;
  39. /**
  40. * Overrides StringBase::__construct().
  41. */
  42. public function __construct($values = array()) {
  43. parent::__construct($values);
  44. if (!isset($this->is_new)) {
  45. // We mark the string as not new if it is a complete translation.
  46. // This will work when loading from database, otherwise the storage
  47. // controller that creates the string object must handle it.
  48. $this->is_new = !$this->isTranslation();
  49. }
  50. }
  51. /**
  52. * Sets the string as customized / not customized.
  53. *
  54. * @param bool $customized
  55. * (optional) Whether the string is customized or not. Defaults to TRUE.
  56. *
  57. * @return TranslationString
  58. * The called object.
  59. */
  60. public function setCustomized($customized = TRUE) {
  61. $this->customized = $customized ? L10N_UPDATE_CUSTOMIZED : L10N_UPDATE_NOT_CUSTOMIZED;
  62. return $this;
  63. }
  64. /**
  65. * Implements StringInterface::isSource().
  66. */
  67. public function isSource() {
  68. return FALSE;
  69. }
  70. /**
  71. * Implements StringInterface::isTranslation().
  72. */
  73. public function isTranslation() {
  74. return !empty($this->lid) && !empty($this->language) && isset($this->translation);
  75. }
  76. /**
  77. * Implements StringInterface::getString().
  78. */
  79. public function getString() {
  80. return isset($this->translation) ? $this->translation : '';
  81. }
  82. /**
  83. * Implements StringInterface::setString().
  84. */
  85. public function setString($string) {
  86. $this->translation = $string;
  87. return $this;
  88. }
  89. /**
  90. * Implements StringInterface::isNew().
  91. */
  92. public function isNew() {
  93. return $this->is_new;
  94. }
  95. /**
  96. * Implements StringInterface::save().
  97. */
  98. public function save() {
  99. parent::save();
  100. $this->is_new = FALSE;
  101. return $this;
  102. }
  103. /**
  104. * Implements StringInterface::delete().
  105. */
  106. public function delete() {
  107. parent::delete();
  108. $this->is_new = TRUE;
  109. return $this;
  110. }
  111. }