Translation_Entry

Translation_Entry class encapsulates a translatable string.

Defined (1)

The class is defined in the following location(s).

/wp-includes/pomo/entry.php  
  1. class Translation_Entry { 
  2.  
  3. /** 
  4. * Whether the entry contains a string and its plural form, default is false 
  5. * @var boolean 
  6. */ 
  7. var $is_plural = false; 
  8.  
  9. var $context = null; 
  10. var $singular = null; 
  11. var $plural = null; 
  12. var $translations = array(); 
  13. var $translator_comments = ''; 
  14. var $extracted_comments = ''; 
  15. var $references = array(); 
  16. var $flags = array(); 
  17.  
  18. /** 
  19. * @param array $args associative array, support following keys: 
  20. * - singular (string) -- the string to translate, if omitted and empty entry will be created 
  21. * - plural (string) -- the plural form of the string, setting this will set {@link $is_plural} to true 
  22. * - translations (array) -- translations of the string and possibly -- its plural forms 
  23. * - context (string) -- a string differentiating two equal strings used in different contexts 
  24. * - translator_comments (string) -- comments left by translators 
  25. * - extracted_comments (string) -- comments left by developers 
  26. * - references (array) -- places in the code this strings is used, in relative_to_root_path/file.php:linenum form 
  27. * - flags (array) -- flags like php-format 
  28. */ 
  29. function __construct( $args = array() ) { 
  30. // if no singular -- empty object 
  31. if (!isset($args['singular'])) { 
  32. return; 
  33. // get member variable values from args hash 
  34. foreach ($args as $varname => $value) { 
  35. $this->$varname = $value; 
  36. if (isset($args['plural']) && $args['plural']) $this->is_plural = true; 
  37. if (!is_array($this->translations)) $this->translations = array(); 
  38. if (!is_array($this->references)) $this->references = array(); 
  39. if (!is_array($this->flags)) $this->flags = array(); 
  40.  
  41. /** 
  42. * PHP4 constructor. 
  43. */ 
  44. public function Translation_Entry( $args = array() ) { 
  45. self::__construct( $args ); 
  46.  
  47. /** 
  48. * Generates a unique key for this entry 
  49. * @return string|bool the key or false if the entry is empty 
  50. */ 
  51. function key() { 
  52. if ( null === $this->singular || '' === $this->singular ) return false; 
  53.  
  54. // Prepend context and EOT, like in MO files 
  55. $key = !$this->context? $this->singular : $this->context.chr(4).$this->singular; 
  56. // Standardize on \n line endings 
  57. $key = str_replace( array( "\r\n", "\r" ), "\n", $key ); 
  58.  
  59. return $key; 
  60.  
  61. /** 
  62. * @param object $other 
  63. */ 
  64. function merge_with(&$other) { 
  65. $this->flags = array_unique( array_merge( $this->flags, $other->flags ) ); 
  66. $this->references = array_unique( array_merge( $this->references, $other->references ) ); 
  67. if ( $this->extracted_comments != $other->extracted_comments ) { 
  68. $this->extracted_comments .= $other->extracted_comments; 
  69.