comparison core/lib/Drupal/Component/Gettext/PoItem.php @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents 7a779792577d
children af1871eacc83
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
13 /** 13 /**
14 * The language code this translation is in. 14 * The language code this translation is in.
15 * 15 *
16 * @var string 16 * @var string
17 */ 17 */
18 private $_langcode; 18 protected $langcode;
19 19
20 /** 20 /**
21 * The context this translation belongs to. 21 * The context this translation belongs to.
22 * 22 *
23 * @var string 23 * @var string
24 */ 24 */
25 private $_context = ''; 25 protected $context = '';
26 26
27 /** 27 /**
28 * The source string or array of strings if it has plurals. 28 * The source string or array of strings if it has plurals.
29 * 29 *
30 * @var string|array 30 * @var string|array
31 * 31 *
32 * @see $_plural 32 * @see $plural
33 */ 33 */
34 private $_source; 34 protected $source;
35 35
36 /** 36 /**
37 * Flag indicating if this translation has plurals. 37 * Flag indicating if this translation has plurals.
38 * 38 *
39 * @var bool 39 * @var bool
40 */ 40 */
41 private $_plural; 41 protected $plural;
42 42
43 /** 43 /**
44 * The comment of this translation. 44 * The comment of this translation.
45 * 45 *
46 * @var string 46 * @var string
47 */ 47 */
48 private $_comment; 48 protected $comment;
49 49
50 /** 50 /**
51 * The translation string or array of strings if it has plurals. 51 * The translation string or array of strings if it has plurals.
52 * 52 *
53 * @var string|array 53 * @var string|array
54 * @see $_plural 54 * @see $plural
55 */ 55 */
56 private $_translation; 56 protected $translation;
57 57
58 /** 58 /**
59 * Gets the language code of the currently used language. 59 * Gets the language code of the currently used language.
60 * 60 *
61 * @return string with langcode 61 * @return string with langcode
62 */ 62 */
63 public function getLangcode() { 63 public function getLangcode() {
64 return $this->_langcode; 64 return $this->langcode;
65 } 65 }
66 66
67 /** 67 /**
68 * Set the language code of the current language. 68 * Set the language code of the current language.
69 * 69 *
70 * @param string $langcode 70 * @param string $langcode
71 */ 71 */
72 public function setLangcode($langcode) { 72 public function setLangcode($langcode) {
73 $this->_langcode = $langcode; 73 $this->langcode = $langcode;
74 } 74 }
75 75
76 /** 76 /**
77 * Gets the context this translation belongs to. 77 * Gets the context this translation belongs to.
78 * 78 *
79 * @return string $context 79 * @return string $context
80 */ 80 */
81 public function getContext() { 81 public function getContext() {
82 return $this->_context; 82 return $this->context;
83 } 83 }
84 84
85 /** 85 /**
86 * Set the context this translation belongs to. 86 * Set the context this translation belongs to.
87 * 87 *
88 * @param string $context 88 * @param string $context
89 */ 89 */
90 public function setContext($context) { 90 public function setContext($context) {
91 $this->_context = $context; 91 $this->context = $context;
92 } 92 }
93 93
94 /** 94 /**
95 * Gets the source string or the array of strings if the translation has 95 * Gets the source string or the array of strings if the translation has
96 * plurals. 96 * plurals.
97 * 97 *
98 * @return string or array $translation 98 * @return string or array $translation
99 */ 99 */
100 public function getSource() { 100 public function getSource() {
101 return $this->_source; 101 return $this->source;
102 } 102 }
103 103
104 /** 104 /**
105 * Set the source string or the array of strings if the translation has 105 * Set the source string or the array of strings if the translation has
106 * plurals. 106 * plurals.
107 * 107 *
108 * @param string|array $source 108 * @param string|array $source
109 */ 109 */
110 public function setSource($source) { 110 public function setSource($source) {
111 $this->_source = $source; 111 $this->source = $source;
112 } 112 }
113 113
114 /** 114 /**
115 * Gets the translation string or the array of strings if the translation has 115 * Gets the translation string or the array of strings if the translation has
116 * plurals. 116 * plurals.
117 * 117 *
118 * @return string or array $translation 118 * @return string or array $translation
119 */ 119 */
120 public function getTranslation() { 120 public function getTranslation() {
121 return $this->_translation; 121 return $this->translation;
122 } 122 }
123 123
124 /** 124 /**
125 * Set the translation string or the array of strings if the translation has 125 * Set the translation string or the array of strings if the translation has
126 * plurals. 126 * plurals.
127 * 127 *
128 * @param string|array $translation 128 * @param string|array $translation
129 */ 129 */
130 public function setTranslation($translation) { 130 public function setTranslation($translation) {
131 $this->_translation = $translation; 131 $this->translation = $translation;
132 } 132 }
133 133
134 /** 134 /**
135 * Set if the translation has plural values. 135 * Set if the translation has plural values.
136 * 136 *
137 * @param bool $plural 137 * @param bool $plural
138 */ 138 */
139 public function setPlural($plural) { 139 public function setPlural($plural) {
140 $this->_plural = $plural; 140 $this->plural = $plural;
141 } 141 }
142 142
143 /** 143 /**
144 * Get if the translation has plural values. 144 * Get if the translation has plural values.
145 * 145 *
146 * @return bool 146 * @return bool
147 */ 147 */
148 public function isPlural() { 148 public function isPlural() {
149 return $this->_plural; 149 return $this->plural;
150 } 150 }
151 151
152 /** 152 /**
153 * Gets the comment of this translation. 153 * Gets the comment of this translation.
154 * 154 *
155 * @return String $comment 155 * @return String $comment
156 */ 156 */
157 public function getComment() { 157 public function getComment() {
158 return $this->_comment; 158 return $this->comment;
159 } 159 }
160 160
161 /** 161 /**
162 * Set the comment of this translation. 162 * Set the comment of this translation.
163 * 163 *
164 * @param string $comment 164 * @param string $comment
165 */ 165 */
166 public function setComment($comment) { 166 public function setComment($comment) {
167 $this->_comment = $comment; 167 $this->comment = $comment;
168 } 168 }
169 169
170 /** 170 /**
171 * Create the PoItem from a structured array. 171 * Create the PoItem from a structured array.
172 * 172 *
183 $this->setTranslation($values['translation']); 183 $this->setTranslation($values['translation']);
184 } 184 }
185 if (isset($values['comment'])) { 185 if (isset($values['comment'])) {
186 $this->setComment($values['comment']); 186 $this->setComment($values['comment']);
187 } 187 }
188 if (isset($this->_source) && 188 if (isset($this->source) &&
189 strpos($this->_source, LOCALE_PLURAL_DELIMITER) !== FALSE) { 189 strpos($this->source, LOCALE_PLURAL_DELIMITER) !== FALSE) {
190 $this->setSource(explode(LOCALE_PLURAL_DELIMITER, $this->_source)); 190 $this->setSource(explode(LOCALE_PLURAL_DELIMITER, $this->source));
191 $this->setTranslation(explode(LOCALE_PLURAL_DELIMITER, $this->_translation)); 191 $this->setTranslation(explode(LOCALE_PLURAL_DELIMITER, $this->translation));
192 $this->setPlural(count($this->_source) > 1); 192 $this->setPlural(count($this->source) > 1);
193 } 193 }
194 } 194 }
195 195
196 /** 196 /**
197 * Output the PoItem as a string. 197 * Output the PoItem as a string.
205 */ 205 */
206 private function formatItem() { 206 private function formatItem() {
207 $output = ''; 207 $output = '';
208 208
209 // Format string context. 209 // Format string context.
210 if (!empty($this->_context)) { 210 if (!empty($this->context)) {
211 $output .= 'msgctxt ' . $this->formatString($this->_context); 211 $output .= 'msgctxt ' . $this->formatString($this->context);
212 } 212 }
213 213
214 // Format translation. 214 // Format translation.
215 if ($this->_plural) { 215 if ($this->plural) {
216 $output .= $this->formatPlural(); 216 $output .= $this->formatPlural();
217 } 217 }
218 else { 218 else {
219 $output .= $this->formatSingular(); 219 $output .= $this->formatSingular();
220 } 220 }
230 */ 230 */
231 private function formatPlural() { 231 private function formatPlural() {
232 $output = ''; 232 $output = '';
233 233
234 // Format source strings. 234 // Format source strings.
235 $output .= 'msgid ' . $this->formatString($this->_source[0]); 235 $output .= 'msgid ' . $this->formatString($this->source[0]);
236 $output .= 'msgid_plural ' . $this->formatString($this->_source[1]); 236 $output .= 'msgid_plural ' . $this->formatString($this->source[1]);
237 237
238 foreach ($this->_translation as $i => $trans) { 238 foreach ($this->translation as $i => $trans) {
239 if (isset($this->_translation[$i])) { 239 if (isset($this->translation[$i])) {
240 $output .= 'msgstr[' . $i . '] ' . $this->formatString($trans); 240 $output .= 'msgstr[' . $i . '] ' . $this->formatString($trans);
241 } 241 }
242 else { 242 else {
243 $output .= 'msgstr[' . $i . '] ""' . "\n"; 243 $output .= 'msgstr[' . $i . '] ""' . "\n";
244 } 244 }
250 /** 250 /**
251 * Formats a singular translation. 251 * Formats a singular translation.
252 */ 252 */
253 private function formatSingular() { 253 private function formatSingular() {
254 $output = ''; 254 $output = '';
255 $output .= 'msgid ' . $this->formatString($this->_source); 255 $output .= 'msgid ' . $this->formatString($this->source);
256 $output .= 'msgstr ' . (isset($this->_translation) ? $this->formatString($this->_translation) : '""'); 256 $output .= 'msgstr ' . (isset($this->translation) ? $this->formatString($this->translation) : '""');
257 return $output; 257 return $output;
258 } 258 }
259 259
260 /** 260 /**
261 * Formats a string for output on multiple lines. 261 * Formats a string for output on multiple lines.