PageRenderTime 30ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-includes/pomo/entry.php

https://bitbucket.org/Wallynm/iptb
PHP | 78 lines | 37 code | 7 blank | 34 comment | 9 complexity | 4ce3d1f20ac04637342f333aeb8dd891 MD5 | raw file
Possible License(s): LGPL-2.1, AGPL-1.0, GPL-2.0, GPL-3.0
  1. <?php
  2. /**
  3. * Contains Translation_Entry class
  4. *
  5. * @version $Id: entry.php 621 2011-06-13 12:21:50Z nbachiyski $
  6. * @package pomo
  7. * @subpackage entry
  8. */
  9. if ( !class_exists( 'Translation_Entry' ) ):
  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 Translation_Entry($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'])) $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. * Generates a unique key for this entry
  55. *
  56. * @return string|bool the key or false if the entry is empty
  57. */
  58. function key() {
  59. if (is_null($this->singular)) return false;
  60. // prepend context and EOT, like in MO files
  61. return is_null($this->context)? $this->singular : $this->context.chr(4).$this->singular;
  62. }
  63. function merge_with(&$other) {
  64. $this->flags = array_unique( array_merge( $this->flags, $other->flags ) );
  65. $this->references = array_unique( array_merge( $this->references, $other->references ) );
  66. if ( $this->extracted_comments != $other->extracted_comments ) {
  67. $this->extracted_comments .= $other->extracted_comments;
  68. }
  69. }
  70. }
  71. endif;