PageRenderTime 25ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-includes/pomo/entry.php

https://gitlab.com/webkod3r/tripolis
PHP | 93 lines | 42 code | 10 blank | 41 comment | 11 complexity | ed9d811ef0cb13bdc0fa60b8314c8d61 MD5 | raw file
  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. var $is_plural = false;
  20. var $context = null;
  21. var $singular = null;
  22. var $plural = null;
  23. var $translations = array();
  24. var $translator_comments = '';
  25. var $extracted_comments = '';
  26. var $references = array();
  27. var $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']) $this->is_plural = true;
  49. if (!is_array($this->translations)) $this->translations = array();
  50. if (!is_array($this->references)) $this->references = array();
  51. if (!is_array($this->flags)) $this->flags = array();
  52. }
  53. /**
  54. * PHP4 constructor.
  55. */
  56. public function Translation_Entry( $args = array() ) {
  57. self::__construct( $args );
  58. }
  59. /**
  60. * Generates a unique key for this entry
  61. *
  62. * @return string|bool the key or false if the entry is empty
  63. */
  64. function key() {
  65. if ( null === $this->singular || '' === $this->singular ) return false;
  66. // Prepend context and EOT, like in MO files
  67. $key = !$this->context? $this->singular : $this->context.chr(4).$this->singular;
  68. // Standardize on \n line endings
  69. $key = str_replace( array( "\r\n", "\r" ), "\n", $key );
  70. return $key;
  71. }
  72. /**
  73. * @param object $other
  74. */
  75. function merge_with(&$other) {
  76. $this->flags = array_unique( array_merge( $this->flags, $other->flags ) );
  77. $this->references = array_unique( array_merge( $this->references, $other->references ) );
  78. if ( $this->extracted_comments != $other->extracted_comments ) {
  79. $this->extracted_comments .= $other->extracted_comments;
  80. }
  81. }
  82. }
  83. endif;