[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-includes/pomo/ -> entry.php (source)

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


Generated: Sat Nov 2 01:00:02 2024 Cross-referenced by PHPXref 0.7.1