-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathPhpScanner.php
More file actions
66 lines (56 loc) · 1.73 KB
/
PhpScanner.php
File metadata and controls
66 lines (56 loc) · 1.73 KB
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
<?php
declare(strict_types = 1);
namespace Gettext\Scanner;
use Gettext\Translation;
/**
* Class to scan PHP files and get gettext translations
*/
class PhpScanner extends CodeScanner
{
use FunctionsHandlersTrait;
protected $functions = [
'gettext' => 'gettext',
'_' => 'gettext',
'__' => 'gettext',
'ngettext' => 'ngettext',
'n__' => 'ngettext',
'pgettext' => 'pgettext',
'p__' => 'pgettext',
'dgettext' => 'dgettext',
'd__' => 'dgettext',
'dngettext' => 'dngettext',
'dn__' => 'dngettext',
'dpgettext' => 'dpgettext',
'dp__' => 'dpgettext',
'npgettext' => 'npgettext',
'np__' => 'npgettext',
'dnpgettext' => 'dnpgettext',
'dnp__' => 'dnpgettext',
'noop' => 'gettext',
'noop__' => 'gettext',
];
public function getFunctionsScanner(): FunctionsScannerInterface
{
return new PhpFunctionsScanner(array_keys($this->functions));
}
protected function saveTranslation(
?string $domain,
?string $context,
string $original,
?string $plural = null
): ?Translation {
$translation = parent::saveTranslation($domain, $context, $original, $plural);
if (!$translation) {
return null;
}
$original = $translation->getOriginal();
//Check if it includes a sprintf
if (strpos($original, '%') !== false) {
// %[argnum$][flags][width][.precision]specifier
if (preg_match('/%(\d+\$)?([\-\+\s0]|\'.)?(\d+)?(\.\d+)?[bcdeEfFgGhHosuxX]/', $original)) {
$translation->getFlags()->add('php-format');
}
}
return $translation;
}
}