/var/www/hkosl.com/demo_google/application/vendor/gettext/gettext/src/Extractors/Po.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<?php

namespace Gettext\Extractors;

use 
Gettext\Translations;
use 
Gettext\Translation;
use 
Gettext\Utils\HeadersExtractorTrait;

/**
 * Class to get gettext strings from php files returning arrays.
 */
class Po extends Extractor implements ExtractorInterface
{
    use 
HeadersExtractorTrait;

    
/**
     * Parses a .po file and append the translations found in the Translations instance.
     *
     * {@inheritdoc}
     */
    
public static function fromString($stringTranslations $translations, array $options = [])
    {
        
$lines explode("\n"$string);
        
$i 0;

        
$translation = new Translation('''');

        for (
$n count($lines); $i $n; ++$i) {
            
$line trim($lines[$i]);
            
$line self::fixMultiLines($line$lines$i);

            if (
$line === '') {
                if (
$translation->is('''')) {
                    
self::extractHeaders($translation->getTranslation(), $translations);
                } elseif (
$translation->hasOriginal()) {
                    
$translations[] = $translation;
                }

                
$translation = new Translation('''');
                continue;
            }

            
$splitLine preg_split('/\s+/'$line2);
            
$key $splitLine[0];
            
$data = isset($splitLine[1]) ? $splitLine[1] : '';

            switch (
$key) {
                case 
'#':
                    
$translation->addComment($data);
                    
$append null;
                    break;

                case 
'#.':
                    
$translation->addExtractedComment($data);
                    
$append null;
                    break;

                case 
'#,':
                    foreach (
array_map('trim'explode(','trim($data))) as $value) {
                        
$translation->addFlag($value);
                    }
                    
$append null;
                    break;

                case 
'#:':
                    foreach (
preg_split('/\s+/'trim($data)) as $value) {
                        if (
preg_match('/^(.+)(:(\d*))?$/U'$value$matches)) {
                            
$translation->addReference($matches[1], isset($matches[3]) ? $matches[3] : null);
                        }
                    }
                    
$append null;
                    break;

                case 
'msgctxt':
                    
$translation $translation->getClone(self::convertString($data));
                    
$append 'Context';
                    break;

                case 
'msgid':
                    
$translation $translation->getClone(nullself::convertString($data));
                    
$append 'Original';
                    break;

                case 
'msgid_plural':
                    
$translation->setPlural(self::convertString($data));
                    
$append 'Plural';
                    break;

                case 
'msgstr':
                case 
'msgstr[0]':
                    
$translation->setTranslation(self::convertString($data));
                    
$append 'Translation';
                    break;

                case 
'msgstr[1]':
                    
$translation->setPluralTranslations([self::convertString($data)]);
                    
$append 'PluralTranslation';
                    break;

                default:
                    if (
strpos($key'msgstr[') === 0) {
                        
$p $translation->getPluralTranslations();
                        
$p[] = self::convertString($data);

                        
$translation->setPluralTranslations($p);
                        
$append 'PluralTranslation';
                        break;
                    }

                    if (isset(
$append)) {
                        if (
$append === 'Context') {
                            
$translation $translation->getClone($translation->getContext()
                                .
"\n"
                                
.self::convertString($data));
                            break;
                        }

                        if (
$append === 'Original') {
                            
$translation $translation->getClone(null$translation->getOriginal()
                                .
"\n"
                                
.self::convertString($data));
                            break;
                        }

                        if (
$append === 'PluralTranslation') {
                            
$p $translation->getPluralTranslations();
                            
$p[] = array_pop($p)."\n".self::convertString($data);
                            
$translation->setPluralTranslations($p);
                            break;
                        }

                        
$getMethod 'get'.$append;
                        
$setMethod 'set'.$append;
                        
$translation->$setMethod($translation->$getMethod()."\n".self::convertString($data));
                    }
                    break;
            }
        }

        if (
$translation->hasOriginal() && !in_array($translationiterator_to_array($translations))) {
            
$translations[] = $translation;
        }
    }

    
/**
     * Gets one string from multiline strings.
     *
     * @param string $line
     * @param array  $lines
     * @param int    &$i
     *
     * @return string
     */
    
private static function fixMultiLines($line, array $lines, &$i)
    {
        for (
$j $i$t count($lines); $j $t; ++$j) {
            if (
substr($line, -11) == '"'
                
&& isset($lines[$j 1])
                && 
substr(trim($lines[$j 1]), 01) == '"'
            
) {
                
$line substr($line0, -1).substr(trim($lines[$j 1]), 1);
            } else {
                
$i $j;
                break;
            }
        }

        return 
$line;
    }

    
/**
     * Convert a string from its PO representation.
     *
     * @param string $value
     *
     * @return string
     */
    
public static function convertString($value)
    {
        if (!
$value) {
            return 
'';
        }

        if (
$value[0] === '"') {
            
$value substr($value1, -1);
        }

        return 
strtr(
            
$value,
            [
                
'\\\\' => '\\',
                
'\\a' => "\x07",
                
'\\b' => "\x08",
                
'\\t' => "\t",
                
'\\n' => "\n",
                
'\\v' => "\x0b",
                
'\\f' => "\x0c",
                
'\\r' => "\r",
                
'\\"' => '"',
            ]
        );
    }
}