/var/www/html_sp/wp-content/plugins/loco-translate/src/fs/LocaleDirectory.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
<?php
/**
 * 
 */
class Loco_fs_LocaleDirectory extends Loco_fs_Directory {  

    
/**
     * Get location identifier which signifies the type if translation storage.
     * 
     * - "plugin": bundled inside a plugin (official/author)
     * - "theme":  bundled inside a theme (official/author)
     * - "wplang": under the global languages directory and probably installed by auto-updates
     * - "custom": Loco protected directory
     * - "other":  anywhere else
     * 
     * @return string 
     */
    
public function getTypeId(){
        
// paths must be compared with trailing slashes so "/foo" doesn't match "/foo-bar"
        
$path trailingslashit$this->normalize() );
        
        
// anything under Loco's protected directory is our location for custom overrides
        
$prefix trailingslashitloco_constant('LOCO_LANG_DIR') );
        if( 
substr($path,0,strlen($prefix) ) === $prefix ){
            return 
'custom';
        }

        
// standard subdirectories of WP_LANG_DIR are under WordPress auto-update control
        
$prefix trailingslashitloco_constant('WP_LANG_DIR') );
        if( 
substr($path,0,strlen($prefix) ) === $prefix ){
            if( 
$path === $prefix || $path === $prefix.'plugins/' || $path === $prefix.'themes/' ){
                return 
'wplang';
            }
        }
        else {
            
// anything under a registered theme directory is bundled
            
$dirs Loco_fs_Locations::getThemes();
            if( 
$dirs->check($path) ){
                return 
'theme';
            }
            
// anything under a registered plugin directory is bundled
            
$dirs Loco_fs_Locations::getPlugins();
            if( 
$dirs->check($path) ){
                return 
'plugin';
            }
        }
        
        
// anything else, which includes subdirectories of WP_LANG_DIR etc..
        
return 'other';
    }


    
/**
     * Get translated version of getTypeId
     * @param string $id
     * @return string
     */
    
public function getTypeLabel$id ){
        switch( 
$id ){
        case 
'theme':
        case 
'plugin'
            
// Translators: Refers to bundled plugin or theme translation files - i.e. those supplied by the author
            
return _x('Author','File location','loco-translate');
        case 
'wplang'
            
// Translators: Refers to system-installed translation files - i.e. those under WP_LANG_DIR  
            
return _x('System','File location','loco-translate');
        case 
'custom'
            
// Translators: Refers to translation files in Loco's custom/protected directory
            
return _x('Custom','File location','loco-translate');
        case 
'other':
            
// Translators: Refers to translation files in an alternative location that isn't Author, System or Custom.
            
return _x('Other','File location','loco-translate');
        }
        
        throw new 
InvalidArgumentException('Invalid location type: '.$id );
    }        


}