author | ymh <ymh.work@gmail.com> |
Wed, 21 Sep 2022 18:19:35 +0200 | |
changeset 18 | be944660c56a |
parent 16 | a86126ab1dd4 |
child 19 | 3d72ae0968f4 |
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 |
/** |
9 | 12 |
* Translation_Entry class encapsulates a translatable string |
0 | 13 |
*/ |
9 | 14 |
class Translation_Entry { |
15 |
||
16 |
/** |
|
17 |
* Whether the entry contains a string and its plural form, default is false |
|
18 |
* |
|
19 |
* @var boolean |
|
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 |
/** |
33 |
* @param array $args associative array, support following keys: |
|
34 |
* - singular (string) -- the string to translate, if omitted and empty entry will be created |
|
35 |
* - plural (string) -- the plural form of the string, setting this will set {@link $is_plural} to true |
|
36 |
* - translations (array) -- translations of the string and possibly -- its plural forms |
|
37 |
* - context (string) -- a string differentiating two equal strings used in different contexts |
|
38 |
* - translator_comments (string) -- comments left by translators |
|
39 |
* - extracted_comments (string) -- comments left by developers |
|
40 |
* - references (array) -- places in the code this strings is used, in relative_to_root_path/file.php:linenum form |
|
41 |
* - flags (array) -- flags like php-format |
|
42 |
*/ |
|
43 |
function __construct( $args = array() ) { |
|
16 | 44 |
// If no singular -- empty object. |
9 | 45 |
if ( ! isset( $args['singular'] ) ) { |
46 |
return; |
|
47 |
} |
|
16 | 48 |
// Get member variable values from args hash. |
9 | 49 |
foreach ( $args as $varname => $value ) { |
50 |
$this->$varname = $value; |
|
51 |
} |
|
52 |
if ( isset( $args['plural'] ) && $args['plural'] ) { |
|
53 |
$this->is_plural = true; |
|
54 |
} |
|
55 |
if ( ! is_array( $this->translations ) ) { |
|
56 |
$this->translations = array(); |
|
57 |
} |
|
58 |
if ( ! is_array( $this->references ) ) { |
|
59 |
$this->references = array(); |
|
60 |
} |
|
61 |
if ( ! is_array( $this->flags ) ) { |
|
62 |
$this->flags = array(); |
|
63 |
} |
|
0 | 64 |
} |
65 |
||
9 | 66 |
/** |
67 |
* PHP4 constructor. |
|
16 | 68 |
* |
69 |
* @deprecated 5.4.0 Use __construct() instead. |
|
70 |
* |
|
71 |
* @see Translation_Entry::__construct() |
|
9 | 72 |
*/ |
73 |
public function Translation_Entry( $args = array() ) { |
|
16 | 74 |
_deprecated_constructor( self::class, '5.4.0', static::class ); |
9 | 75 |
self::__construct( $args ); |
76 |
} |
|
77 |
||
78 |
/** |
|
79 |
* Generates a unique key for this entry |
|
80 |
* |
|
81 |
* @return string|bool the key or false if the entry is empty |
|
82 |
*/ |
|
83 |
function key() { |
|
84 |
if ( null === $this->singular || '' === $this->singular ) { |
|
85 |
return false; |
|
86 |
} |
|
87 |
||
16 | 88 |
// Prepend context and EOT, like in MO files. |
9 | 89 |
$key = ! $this->context ? $this->singular : $this->context . "\4" . $this->singular; |
16 | 90 |
// Standardize on \n line endings. |
9 | 91 |
$key = str_replace( array( "\r\n", "\r" ), "\n", $key ); |
92 |
||
93 |
return $key; |
|
94 |
} |
|
95 |
||
96 |
/** |
|
97 |
* @param object $other |
|
98 |
*/ |
|
99 |
function merge_with( &$other ) { |
|
100 |
$this->flags = array_unique( array_merge( $this->flags, $other->flags ) ); |
|
101 |
$this->references = array_unique( array_merge( $this->references, $other->references ) ); |
|
102 |
if ( $this->extracted_comments != $other->extracted_comments ) { |
|
103 |
$this->extracted_comments .= $other->extracted_comments; |
|
104 |
} |
|
105 |
||
106 |
} |
|
0 | 107 |
} |
9 | 108 |
endif; |