/var/www/html_sp/wp-content/plugins/loco-translate/src/gettext/String.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
/**
 * Gettext source string. Does not contain translations.
 */
class Loco_gettext_String {

    
/**
     * @var array
     */
    
private $raw;

    
/**
     * @var string
     */
    
private $plural;
    

    
/**
     * Loco_gettext_String constructor.
     *
     * @param string $msgid Mandatory source
     * @param string $msgctxt Optional context
     */
    
public function __construct$msgid$msgctxt '' ){
        
$this->raw =  [
            
'source' => (string) $msgid,
            
'context' => (string) $msgctxt,
        ];
    }


    
/**
     * Get singular form as raw array data
     * @internal
     * @return string[]
     */
    
public function exportSingular(){
        return 
$this->raw;
    }


    
/**
     * Get plural form as raw array data
     * @internal
     * @return string[]
     */
    
public function exportPlural(){
        return  [
            
'source' => $this->plural,
        ];
    }


    
/**
     * @param string $prop
     * @param string|array $value
     * @param string $glue
     * @return void
     */
    
private function merge$prop$value$glue ){
        if( 
is_string($value) ){
            
$value = [$value];
        }
        else if( ! 
is_array($value) ){
            throw new 
InvalidArgumentException('Expected Array or String');
        }
        if( 
array_key_exists($prop,$this->raw) ){
            
$value array_mergeexplode($glue,$this->raw[$prop]), $value );
        }
        
$this->raw[$prop] = implode($glue,$value);
    }


    
/**
     * @param array|string $refs
     * @return self
     */
    
public function addFileReferences$refs ){
        
$this->merge('refs',$refs,' ');
        return 
$this;
    }


    
/**
     * @param array|string $notes
     * @return self
     */
    
public function addExtractedComment$notes ){
        
$this->merge('notes',$notes,' ');
        return 
$this;
    }

    
/**
     * @param string $msgid_plural
     * @return self
     */
    
public function pluralize$msgid_plural ){
        
$this->plural = (string) $msgid_plural;
        return 
$this;
    }


    
/**
     * @return bool
     */
    
public function hasPlural(){
        return 
is_string($this->plural) && '' !== $this->plural;
    }
    
    
    
/*public function __toString(){
        return json_encode( $this->raw );
    }*/
    

}