comparison vendor/symfony/translation/DataCollector/TranslationDataCollector.php @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents 1fec387a4317
children
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
55 /** 55 /**
56 * {@inheritdoc} 56 * {@inheritdoc}
57 */ 57 */
58 public function reset() 58 public function reset()
59 { 59 {
60 $this->data = array(); 60 $this->data = [];
61 } 61 }
62 62
63 /** 63 /**
64 * @return array 64 * @return array
65 */ 65 */
66 public function getMessages() 66 public function getMessages()
67 { 67 {
68 return isset($this->data['messages']) ? $this->data['messages'] : array(); 68 return isset($this->data['messages']) ? $this->data['messages'] : [];
69 } 69 }
70 70
71 /** 71 /**
72 * @return int 72 * @return int
73 */ 73 */
97 return !empty($this->data['locale']) ? $this->data['locale'] : null; 97 return !empty($this->data['locale']) ? $this->data['locale'] : null;
98 } 98 }
99 99
100 public function getFallbackLocales() 100 public function getFallbackLocales()
101 { 101 {
102 return (isset($this->data['fallback_locales']) && count($this->data['fallback_locales']) > 0) ? $this->data['fallback_locales'] : array(); 102 return (isset($this->data['fallback_locales']) && \count($this->data['fallback_locales']) > 0) ? $this->data['fallback_locales'] : [];
103 } 103 }
104 104
105 /** 105 /**
106 * {@inheritdoc} 106 * {@inheritdoc}
107 */ 107 */
110 return 'translation'; 110 return 'translation';
111 } 111 }
112 112
113 private function sanitizeCollectedMessages($messages) 113 private function sanitizeCollectedMessages($messages)
114 { 114 {
115 $result = array(); 115 $result = [];
116 foreach ($messages as $key => $message) { 116 foreach ($messages as $key => $message) {
117 $messageId = $message['locale'].$message['domain'].$message['id']; 117 $messageId = $message['locale'].$message['domain'].$message['id'];
118 118
119 if (!isset($result[$messageId])) { 119 if (!isset($result[$messageId])) {
120 $message['count'] = 1; 120 $message['count'] = 1;
121 $message['parameters'] = !empty($message['parameters']) ? array($message['parameters']) : array(); 121 $message['parameters'] = !empty($message['parameters']) ? [$message['parameters']] : [];
122 $messages[$key]['translation'] = $this->sanitizeString($message['translation']); 122 $messages[$key]['translation'] = $this->sanitizeString($message['translation']);
123 $result[$messageId] = $message; 123 $result[$messageId] = $message;
124 } else { 124 } else {
125 if (!empty($message['parameters'])) { 125 if (!empty($message['parameters'])) {
126 $result[$messageId]['parameters'][] = $message['parameters']; 126 $result[$messageId]['parameters'][] = $message['parameters'];
135 return $result; 135 return $result;
136 } 136 }
137 137
138 private function computeCount($messages) 138 private function computeCount($messages)
139 { 139 {
140 $count = array( 140 $count = [
141 DataCollectorTranslator::MESSAGE_DEFINED => 0, 141 DataCollectorTranslator::MESSAGE_DEFINED => 0,
142 DataCollectorTranslator::MESSAGE_MISSING => 0, 142 DataCollectorTranslator::MESSAGE_MISSING => 0,
143 DataCollectorTranslator::MESSAGE_EQUALS_FALLBACK => 0, 143 DataCollectorTranslator::MESSAGE_EQUALS_FALLBACK => 0,
144 ); 144 ];
145 145
146 foreach ($messages as $message) { 146 foreach ($messages as $message) {
147 ++$count[$message['state']]; 147 ++$count[$message['state']];
148 } 148 }
149 149
156 156
157 if (false !== $encoding = mb_detect_encoding($string, null, true)) { 157 if (false !== $encoding = mb_detect_encoding($string, null, true)) {
158 if (mb_strlen($string, $encoding) > $length) { 158 if (mb_strlen($string, $encoding) > $length) {
159 return mb_substr($string, 0, $length - 3, $encoding).'...'; 159 return mb_substr($string, 0, $length - 3, $encoding).'...';
160 } 160 }
161 } elseif (strlen($string) > $length) { 161 } elseif (\strlen($string) > $length) {
162 return substr($string, 0, $length - 3).'...'; 162 return substr($string, 0, $length - 3).'...';
163 } 163 }
164 164
165 return $string; 165 return $string;
166 } 166 }