[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

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


Generated : Sat Dec 21 08:20:01 2024 Cross-referenced by PHPXref