author | ymh <ymh.work@gmail.com> |
Tue, 27 Sep 2022 16:37:53 +0200 | |
changeset 19 | 3d72ae0968f4 |
parent 18 | be944660c56a |
child 21 | 48c4eec2b7e6 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
3 |
* Contains Translation_Entry class |
|
4 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
5 |
* @version $Id: entry.php 1157 2015-11-20 04:30:11Z dd32 $ |
0 | 6 |
* @package pomo |
7 |
* @subpackage entry |
|
8 |
*/ |
|
9 |
||
9 | 10 |
if ( ! class_exists( 'Translation_Entry', false ) ) : |
0 | 11 |
/** |
19 | 12 |
* Translation_Entry class encapsulates a translatable string. |
0 | 13 |
*/ |
9 | 14 |
class Translation_Entry { |
15 |
||
16 |
/** |
|
19 | 17 |
* Whether the entry contains a string and its plural form, default is false. |
9 | 18 |
* |
19 | 19 |
* @var bool |
9 | 20 |
*/ |
18 | 21 |
public $is_plural = false; |
0 | 22 |
|
18 | 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(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
31 |
|
9 | 32 |
/** |
19 | 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 |
* } |
|
9 | 50 |
*/ |
19 | 51 |
public function __construct( $args = array() ) { |
16 | 52 |
// If no singular -- empty object. |
9 | 53 |
if ( ! isset( $args['singular'] ) ) { |
54 |
return; |
|
55 |
} |
|
16 | 56 |
// Get member variable values from args hash. |
9 | 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 |
} |
|
0 | 72 |
} |
73 |
||
9 | 74 |
/** |
75 |
* PHP4 constructor. |
|
16 | 76 |
* |
77 |
* @deprecated 5.4.0 Use __construct() instead. |
|
78 |
* |
|
79 |
* @see Translation_Entry::__construct() |
|
9 | 80 |
*/ |
81 |
public function Translation_Entry( $args = array() ) { |
|
16 | 82 |
_deprecated_constructor( self::class, '5.4.0', static::class ); |
9 | 83 |
self::__construct( $args ); |
84 |
} |
|
85 |
||
86 |
/** |
|
19 | 87 |
* Generates a unique key for this entry. |
9 | 88 |
* |
19 | 89 |
* @return string|false The key or false if the entry is empty. |
9 | 90 |
*/ |
19 | 91 |
public function key() { |
9 | 92 |
if ( null === $this->singular || '' === $this->singular ) { |
93 |
return false; |
|
94 |
} |
|
95 |
||
16 | 96 |
// Prepend context and EOT, like in MO files. |
9 | 97 |
$key = ! $this->context ? $this->singular : $this->context . "\4" . $this->singular; |
16 | 98 |
// Standardize on \n line endings. |
9 | 99 |
$key = str_replace( array( "\r\n", "\r" ), "\n", $key ); |
100 |
||
101 |
return $key; |
|
102 |
} |
|
103 |
||
104 |
/** |
|
105 |
* @param object $other |
|
106 |
*/ |
|
19 | 107 |
public function merge_with( &$other ) { |
9 | 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 |
} |
|
0 | 115 |
} |
9 | 116 |
endif; |