/var/www/html_sp/wp-content/plugins/loco-translate/src/gettext/SyncOptions.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
<?php
/**
 * Abstracts PO sync options held in custom headers
 */
class Loco_gettext_SyncOptions {

    
/**
     * @var LocoPoHeaders
     */
    
private $head;


    public function 
__constructLocoPoHeaders $head ){
        
$this->head $head;
    }


    
/**
     * Test if PO file has alternative template path
     * @return bool
     */
    
public function hasTemplate(){
        return 
'' !== $this->head->trimmed('X-Loco-Template');
    }


    
/**
     * Get *relative* path to alternative template path.
     * @return Loco_fs_LocaleFile
     */
    
public function getTemplate(){
        return new 
Loco_fs_LocaleFile$this->head['X-Loco-Template'] );
    }


    
/**
     * Set *relative* path to alternative template path. 
     * @param string $path
     */
    
public function setTemplate$path ){
        
$this->head['X-Loco-Template'] = (string) $path;
    }


    
/**
     * Test if translations (msgstr fields) are to be merged.
     * @return bool true if NOT in pot mode
     */
    
public function mergeMsgstr(){
        return 
=== preg_match'/\\bpot\\b/'$this->getSyncMode() );
    }


    
/**
     * Test if JSON files are to be merged.
     * @return bool
     */
    
public function mergeJson(){
        return 
=== preg_match'/\\bjson\\b/'$this->getSyncMode() );
    }


    
/**
     * @return string
     */
    
public function getSyncMode(){
        
$mode strtolower$this->head->trimmed('X-Loco-Template-Mode') );
        
// Default sync mode when undefined is to honour the type of source.
        // i.e. for legacy compatibility, copy msgstr fields if source is a PO file.
        
if( '' === $mode ){
            
$mode $this->hasTemplate() ? strtolower$this->getTemplate()->extension() ) : 'pot';
        }
        return 
$mode;
    }


    
/**
     * @param string $mode
     */
    
public function setSyncMode$mode ){
        
$this->head['X-Loco-Template-Mode'] = (string) $mode;
    }
    
    
    
/**
     * Remove redundant headers
     * @return LocoPoHeaders
     */
    
public function getHeaders(){
        if( ! 
$this->hasTemplate() ){
            
$this->head->offsetUnset('X-Loco-Template');
            if( 
'pot' === $this->getSyncMode() ){
                
$this->head->offsetUnset('X-Loco-Template-Mode');
            }
        }
        return 
$this->head;
    }

}