Changeset 35714
- Timestamp:
- 11/20/2015 04:33:12 AM (9 years ago)
- Location:
- trunk/src/wp-includes/pomo
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/pomo/entry.php
r35686 r35714 3 3 * Contains Translation_Entry class 4 4 * 5 * @version $Id: entry.php 718 2012-10-31 00:32:02Z nbachiyski$5 * @version $Id: entry.php 1157 2015-11-20 04:30:11Z dd32 $ 6 6 * @package pomo 7 7 * @subpackage entry … … 50 50 $this->$varname = $value; 51 51 } 52 if (isset($args['plural']) ) $this->is_plural = true;52 if (isset($args['plural']) && $args['plural']) $this->is_plural = true; 53 53 if (!is_array($this->translations)) $this->translations = array(); 54 54 if (!is_array($this->references)) $this->references = array(); … … 69 69 */ 70 70 function key() { 71 if ( is_null($this->singular)) return false;71 if ( null === $this->singular || '' === $this->singular ) return false; 72 72 73 73 // Prepend context and EOT, like in MO files 74 $key = is_null($this->context)? $this->singular : $this->context.chr(4).$this->singular;74 $key = !$this->context? $this->singular : $this->context.chr(4).$this->singular; 75 75 // Standardize on \n line endings 76 76 $key = str_replace( array( "\r\n", "\r" ), "\n", $key ); -
trunk/src/wp-includes/pomo/mo.php
r34348 r35714 3 3 * Class for working with MO files 4 4 * 5 * @version $Id: mo.php 718 2012-10-31 00:32:02Z nbachiyski$5 * @version $Id: mo.php 1157 2015-11-20 04:30:11Z dd32 $ 6 6 * @package pomo 7 7 * @subpackage mo … … 125 125 $exported = $entry->singular; 126 126 if ($entry->is_plural) $exported .= chr(0).$entry->plural; 127 if ( !is_null($entry->context)) $exported = $entry->context . chr(4) . $exported;127 if ($entry->context) $exported = $entry->context . chr(4) . $exported; 128 128 return $exported; 129 129 } … … 135 135 function export_translations($entry) { 136 136 //TODO: warnings for control characters 137 return implode(chr(0), $entry->translations);137 return $entry->is_plural ? implode(chr(0), $entry->translations) : $entry->translations[0]; 138 138 } 139 139 -
trunk/src/wp-includes/pomo/po.php
r34348 r35714 3 3 * Class for working with PO files 4 4 * 5 * @version $Id: po.php 718 2012-10-31 00:32:02Z nbachiyski$5 * @version $Id: po.php 1158 2015-11-20 04:31:23Z dd32 $ 6 6 * @package pomo 7 7 * @subpackage po … … 10 10 require_once dirname(__FILE__) . '/translations.php'; 11 11 12 define('PO_MAX_LINE_LEN', 79); 12 if ( ! defined( 'PO_MAX_LINE_LEN' ) ) { 13 define('PO_MAX_LINE_LEN', 79); 14 } 13 15 14 16 ini_set('auto_detect_line_endings', 1); … … 98 100 * @return string the poified string 99 101 */ 100 function poify($string) {102 public static function poify($string) { 101 103 $quote = '"'; 102 104 $slash = '\\'; … … 129 131 * @return string enascaped string 130 132 */ 131 function unpoify($string) {132 $escapes = array('t' => "\t", 'n' => "\n", ' \\' => '\\');133 public static function unpoify($string) { 134 $escapes = array('t' => "\t", 'n' => "\n", 'r' => "\r", '\\' => '\\'); 133 135 $lines = array_map('trim', explode("\n", $string)); 134 136 $lines = array_map(array('PO', 'trim_quotes'), $lines); … … 150 152 } 151 153 } 154 155 // Standardise the line endings on imported content, technically PO files shouldn't contain \r 156 $unpoified = str_replace( array( "\r\n", "\r" ), "\n", $unpoified ); 157 152 158 return $unpoified; 153 159 } … … 161 167 * @param string $with prepend lines with this string 162 168 */ 163 function prepend_each_line($string, $with) {169 public static function prepend_each_line($string, $with) { 164 170 $php_with = var_export($with, true); 165 171 $lines = explode("\n", $string); … … 181 187 * like :, default is a space 182 188 */ 183 function comment_block($text, $char=' ') {189 public static function comment_block($text, $char=' ') { 184 190 $text = wordwrap($text, PO_MAX_LINE_LEN - 3); 185 191 return PO::prepend_each_line($text, "#$char "); … … 194 200 * false if the entry is empty 195 201 */ 196 function export_entry(&$entry) {197 if ( is_null($entry->singular)) return false;202 public static function export_entry(&$entry) { 203 if ( null === $entry->singular || '' === $entry->singular ) return false; 198 204 $po = array(); 199 205 if (!empty($entry->translator_comments)) $po[] = PO::comment_block($entry->translator_comments); … … 201 207 if (!empty($entry->references)) $po[] = PO::comment_block(implode(' ', $entry->references), ':'); 202 208 if (!empty($entry->flags)) $po[] = PO::comment_block(implode(", ", $entry->flags), ','); 203 if ( !is_null($entry->context)) $po[] = 'msgctxt '.PO::poify($entry->context);209 if ($entry->context) $po[] = 'msgctxt '.PO::poify($entry->context); 204 210 $po[] = 'msgid '.PO::poify($entry->singular); 205 211 if (!$entry->is_plural) { 206 212 $translation = empty($entry->translations)? '' : $entry->translations[0]; 213 $translation = PO::match_begin_and_end_newlines( $translation, $entry->singular ); 207 214 $po[] = 'msgstr '.PO::poify($translation); 208 215 } else { … … 210 217 $translations = empty($entry->translations)? array('', '') : $entry->translations; 211 218 foreach($translations as $i => $translation) { 219 $translation = PO::match_begin_and_end_newlines( $translation, $entry->plural ); 212 220 $po[] = "msgstr[$i] ".PO::poify($translation); 213 221 } 214 222 } 215 223 return implode("\n", $po); 224 } 225 226 public static function match_begin_and_end_newlines( $translation, $original ) { 227 if ( '' === $translation ) { 228 return $translation; 229 } 230 231 $original_begin = "\n" === substr( $original, 0, 1 ); 232 $original_end = "\n" === substr( $original, -1 ); 233 $translation_begin = "\n" === substr( $translation, 0, 1 ); 234 $translation_end = "\n" === substr( $translation, -1 ); 235 236 if ( $original_begin ) { 237 if ( ! $translation_begin ) { 238 $translation = "\n" . $translation; 239 } 240 } elseif ( $translation_begin ) { 241 $translation = ltrim( $translation, "\n" ); 242 } 243 244 if ( $original_end ) { 245 if ( ! $translation_end ) { 246 $translation .= "\n"; 247 } 248 } elseif ( $translation_end ) { 249 $translation = rtrim( $translation, "\n" ); 250 } 251 252 return $translation; 216 253 } 217 254 … … 401 438 * @return sring 402 439 */ 403 function trim_quotes($s) {440 public static function trim_quotes($s) { 404 441 if ( substr($s, 0, 1) == '"') $s = substr($s, 1); 405 442 if ( substr($s, -1, 1) == '"') $s = substr($s, 0, -1); -
trunk/src/wp-includes/pomo/streams.php
r34348 r35714 4 4 * Based on the classes from Danilo Segan <danilo@kvota.net> 5 5 * 6 * @version $Id: streams.php 718 2012-10-31 00:32:02Z nbachiyski$6 * @version $Id: streams.php 1157 2015-11-20 04:30:11Z dd32 $ 7 7 * @package pomo 8 8 * @subpackage streams -
trunk/src/wp-includes/pomo/translations.php
r35686 r35714 3 3 * Class for a set of entries for translation and their associated headers 4 4 * 5 * @version $Id: translations.php 718 2012-10-31 00:32:02Z nbachiyski$5 * @version $Id: translations.php 1157 2015-11-20 04:30:11Z dd32 $ 6 6 * @package pomo 7 7 * @subpackage translations
Note: See TracChangeset
for help on using the changeset viewer.