ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
FunctionsScanner.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Gettext\Utils;
4 
5 use Exception;
7 
8 abstract class FunctionsScanner
9 {
15  abstract public function getFunctions();
16 
24  public function saveGettextFunctions(array $functions, Translations $translations, $file = '')
25  {
26  foreach ($this->getFunctions() as $function) {
27  list($name, $line, $args) = $function;
28 
29  if (!isset($functions[$name])) {
30  continue;
31  }
32 
33  $translation = null;
34 
35  switch ($functions[$name]) {
36  case '__':
37  if (!isset($args[0])) {
38  continue 2;
39  }
40 
41  $original = $args[0];
42 
43  if ($original !== '') {
44  $translation = $translations->insert('', $original);
45  }
46  break;
47 
48  case 'n__':
49  if (!isset($args[1])) {
50  continue 2;
51  }
52 
53  list($original, $plural) = $args;
54 
55  if ($original !== '') {
56  $translation = $translations->insert('', $original, $plural);
57  }
58  break;
59 
60  case 'p__':
61  if (!isset($args[1])) {
62  continue 2;
63  }
64 
65  list($context, $original) = $args;
66 
67  if ($original !== '') {
68  $translation = $translations->insert($context, $original);
69  }
70  break;
71 
72  case 'd__':
73  if (!isset($args[1])) {
74  continue 2;
75  }
76 
77  list($domain, $original) = $args;
78 
79  if ($original !== '' && $domain === $translations->getDomain()) {
80  $translation = $translations->insert('', $original);
81  }
82  break;
83 
84  case 'dp__':
85  if (!isset($args[2])) {
86  continue 2;
87  }
88 
89  list($domain, $context, $original) = $args;
90 
91  if ($original !== '' && $domain === $translations->getDomain()) {
92  $translation = $translations->insert($context, $original);
93  }
94  break;
95 
96  case 'np__':
97  if (!isset($args[2])) {
98  continue 2;
99  }
100 
101  list($context, $original, $plural) = $args;
102 
103  if ($original !== '') {
104  $translation = $translations->insert($context, $original, $plural);
105  }
106  break;
107 
108  case 'dnp__':
109  if (!isset($args[4])) {
110  continue 2;
111  }
112 
113  list($domain, $context, $original, $plural) = $args;
114 
115  if ($original !== '' && $domain === $translations->getDomain()) {
116  $translation = $translations->insert($context, $original, $plural);
117  }
118  break;
119 
120  default:
121  throw new Exception('Not valid functions');
122  }
123 
124  if (isset($translation)) {
125  $translation->addReference($file, $line);
126  if (isset($function[3])) {
127  foreach ($function[3] as $extractedComment) {
128  $translation->addExtractedComment($extractedComment);
129  }
130  }
131  }
132  }
133  }
134 }
$context
Definition: webdav.php:25
getDomain()
Returns the domain.
insert($context, $original, $plural='')
Creates and insert/merges a new translation.
saveGettextFunctions(array $functions, Translations $translations, $file='')
Search for specific functions and create translations.
getFunctions()
Scan and returns the functions and the arguments.
Class to manage a collection of translations.
if(!array_key_exists('domain', $_REQUEST)) $domain
Definition: resume.php:8