38 * - translator_comments (string) -- comments left by translators |
38 * - translator_comments (string) -- comments left by translators |
39 * - extracted_comments (string) -- comments left by developers |
39 * - extracted_comments (string) -- comments left by developers |
40 * - references (array) -- places in the code this strings is used, in relative_to_root_path/file.php:linenum form |
40 * - references (array) -- places in the code this strings is used, in relative_to_root_path/file.php:linenum form |
41 * - flags (array) -- flags like php-format |
41 * - flags (array) -- flags like php-format |
42 */ |
42 */ |
43 function Translation_Entry($args=array()) { |
43 function __construct( $args = array() ) { |
44 // if no singular -- empty object |
44 // if no singular -- empty object |
45 if (!isset($args['singular'])) { |
45 if (!isset($args['singular'])) { |
46 return; |
46 return; |
47 } |
47 } |
48 // get member variable values from args hash |
48 // get member variable values from args hash |
49 foreach ($args as $varname => $value) { |
49 foreach ($args as $varname => $value) { |
50 $this->$varname = $value; |
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 if (!is_array($this->translations)) $this->translations = array(); |
53 if (!is_array($this->translations)) $this->translations = array(); |
54 if (!is_array($this->references)) $this->references = array(); |
54 if (!is_array($this->references)) $this->references = array(); |
55 if (!is_array($this->flags)) $this->flags = array(); |
55 if (!is_array($this->flags)) $this->flags = array(); |
|
56 } |
|
57 |
|
58 /** |
|
59 * PHP4 constructor. |
|
60 */ |
|
61 public function Translation_Entry( $args = array() ) { |
|
62 self::__construct( $args ); |
56 } |
63 } |
57 |
64 |
58 /** |
65 /** |
59 * Generates a unique key for this entry |
66 * Generates a unique key for this entry |
60 * |
67 * |
61 * @return string|bool the key or false if the entry is empty |
68 * @return string|bool the key or false if the entry is empty |
62 */ |
69 */ |
63 function key() { |
70 function key() { |
64 if (is_null($this->singular)) return false; |
71 if ( null === $this->singular || '' === $this->singular ) return false; |
65 // prepend context and EOT, like in MO files |
72 |
66 return is_null($this->context)? $this->singular : $this->context.chr(4).$this->singular; |
73 // Prepend context and EOT, like in MO files |
|
74 $key = !$this->context? $this->singular : $this->context.chr(4).$this->singular; |
|
75 // Standardize on \n line endings |
|
76 $key = str_replace( array( "\r\n", "\r" ), "\n", $key ); |
|
77 |
|
78 return $key; |
67 } |
79 } |
68 |
80 |
|
81 /** |
|
82 * @param object $other |
|
83 */ |
69 function merge_with(&$other) { |
84 function merge_with(&$other) { |
70 $this->flags = array_unique( array_merge( $this->flags, $other->flags ) ); |
85 $this->flags = array_unique( array_merge( $this->flags, $other->flags ) ); |
71 $this->references = array_unique( array_merge( $this->references, $other->references ) ); |
86 $this->references = array_unique( array_merge( $this->references, $other->references ) ); |
72 if ( $this->extracted_comments != $other->extracted_comments ) { |
87 if ( $this->extracted_comments != $other->extracted_comments ) { |
73 $this->extracted_comments .= $other->extracted_comments; |
88 $this->extracted_comments .= $other->extracted_comments; |