Açıklama Yok

entry.php 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. /**
  3. * Contains Translation_Entry class
  4. *
  5. * @version $Id: entry.php 1157 2015-11-20 04:30:11Z dd32 $
  6. * @package pomo
  7. * @subpackage entry
  8. */
  9. if ( ! class_exists( 'Translation_Entry', false ) ) :
  10. /**
  11. * Translation_Entry class encapsulates a translatable string
  12. */
  13. class Translation_Entry {
  14. /**
  15. * Whether the entry contains a string and its plural form, default is false
  16. *
  17. * @var boolean
  18. */
  19. public $is_plural = false;
  20. public $context = null;
  21. public $singular = null;
  22. public $plural = null;
  23. public $translations = array();
  24. public $translator_comments = '';
  25. public $extracted_comments = '';
  26. public $references = array();
  27. public $flags = array();
  28. /**
  29. * @param array $args associative array, support following keys:
  30. * - singular (string) -- the string to translate, if omitted and empty entry will be created
  31. * - plural (string) -- the plural form of the string, setting this will set {@link $is_plural} to true
  32. * - translations (array) -- translations of the string and possibly -- its plural forms
  33. * - context (string) -- a string differentiating two equal strings used in different contexts
  34. * - translator_comments (string) -- comments left by translators
  35. * - extracted_comments (string) -- comments left by developers
  36. * - references (array) -- places in the code this strings is used, in relative_to_root_path/file.php:linenum form
  37. * - flags (array) -- flags like php-format
  38. */
  39. function __construct( $args = array() ) {
  40. // If no singular -- empty object.
  41. if ( ! isset( $args['singular'] ) ) {
  42. return;
  43. }
  44. // Get member variable values from args hash.
  45. foreach ( $args as $varname => $value ) {
  46. $this->$varname = $value;
  47. }
  48. if ( isset( $args['plural'] ) && $args['plural'] ) {
  49. $this->is_plural = true;
  50. }
  51. if ( ! is_array( $this->translations ) ) {
  52. $this->translations = array();
  53. }
  54. if ( ! is_array( $this->references ) ) {
  55. $this->references = array();
  56. }
  57. if ( ! is_array( $this->flags ) ) {
  58. $this->flags = array();
  59. }
  60. }
  61. /**
  62. * PHP4 constructor.
  63. *
  64. * @deprecated 5.4.0 Use __construct() instead.
  65. *
  66. * @see Translation_Entry::__construct()
  67. */
  68. public function Translation_Entry( $args = array() ) {
  69. _deprecated_constructor( self::class, '5.4.0', static::class );
  70. self::__construct( $args );
  71. }
  72. /**
  73. * Generates a unique key for this entry
  74. *
  75. * @return string|bool the key or false if the entry is empty
  76. */
  77. function key() {
  78. if ( null === $this->singular || '' === $this->singular ) {
  79. return false;
  80. }
  81. // Prepend context and EOT, like in MO files.
  82. $key = ! $this->context ? $this->singular : $this->context . "\4" . $this->singular;
  83. // Standardize on \n line endings.
  84. $key = str_replace( array( "\r\n", "\r" ), "\n", $key );
  85. return $key;
  86. }
  87. /**
  88. * @param object $other
  89. */
  90. function merge_with( &$other ) {
  91. $this->flags = array_unique( array_merge( $this->flags, $other->flags ) );
  92. $this->references = array_unique( array_merge( $this->references, $other->references ) );
  93. if ( $this->extracted_comments != $other->extracted_comments ) {
  94. $this->extracted_comments .= $other->extracted_comments;
  95. }
  96. }
  97. }
  98. endif;