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
|
<?php
namespace Gettext\Utils;
use Exception; use Gettext\Translations;
abstract class FunctionsScanner { /** * Scan and returns the functions and the arguments. * * @param array $constants Constants used in the code to replace * * @return array */ abstract public function getFunctions(array $constants = []);
/** * Search for specific functions and create translations. * * @param Translations $translations The translations instance where save the values * @param array $options The extractor options */ public function saveGettextFunctions(Translations $translations, array $options) { $functions = $options['functions']; $file = $options['file'];
foreach ($this->getFunctions($options['constants']) as $function) { list($name, $line, $args) = $function;
if (!isset($functions[$name])) { continue; }
$domain = $context = $original = $plural = null;
switch ($functions[$name]) { case 'noop': case 'gettext': if (!isset($args[0])) { continue 2; }
$original = $args[0]; break;
case 'ngettext': if (!isset($args[1])) { continue 2; }
list($original, $plural) = $args; break;
case 'pgettext': if (!isset($args[1])) { continue 2; }
list($context, $original) = $args; break;
case 'dgettext': if (!isset($args[1])) { continue 2; }
list($domain, $original) = $args; break;
case 'dpgettext': if (!isset($args[2])) { continue 2; }
list($domain, $context, $original) = $args; break;
case 'npgettext': if (!isset($args[2])) { continue 2; }
list($context, $original, $plural) = $args; break;
case 'dnpgettext': if (!isset($args[3])) { continue 2; }
list($domain, $context, $original, $plural) = $args; break;
case 'dngettext': if (!isset($args[2])) { continue 2; }
list($domain, $original, $plural) = $args; break;
default: throw new Exception(sprintf('Not valid function %s', $functions[$name])); }
if ((string) $original !== '' && ($domain === null || $domain === $translations->getDomain())) { $translation = $translations->insert($context, $original, $plural); $translation->addReference($file, $line);
if (isset($function[3])) { foreach ($function[3] as $extractedComment) { $translation->addExtractedComment($extractedComment); } } } } } }
|