Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
xgettextLayout.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
5 */
6 
7 require_once "xgettextCommon.php";
9 {
10 
11  public function extract()
12  {
13  $potFile = $this->outputFile;
14  $phpFile = $potFile . "_.php";
15  file_put_contents($phpFile, '<?php' . "\n");
16  foreach ($this->inputFiles as $layoutFile) {
17  $layoutFile = trim($layoutFile);
18  if (!$layoutFile) {
19  continue;
20  }
21  $ext = '';
22  if (strrpos($layoutFile, '.') > 0) {
23  $ext = substr($layoutFile, strrpos($layoutFile, '.') + 1);
24  }
25  if ($ext == 'odt') {
26  $tmpDir = $temp_file = sprintf("%s/%s", sys_get_temp_dir() , uniqid('po'));
27  $cmd = sprintf('mkdir %s && unzip -d %s %s content.xml meta.xml && cat %s/meta.xml >> %s/content.xml', escapeshellarg($tmpDir) , escapeshellarg($tmpDir) , escapeshellarg($layoutFile) , escapeshellarg($tmpDir) , escapeshellarg($tmpDir));
28  self::mySystem($cmd);
29  $layoutFile = sprintf("%s/content.xml", $tmpDir);
30  } else {
31  $tmpDir = '';
32  }
33 
34  $cmd = sprintf('perl -ne \'print "\$a=gettext(\\"$1\\");\n" while(m/\[TEXT:([^]]+)]/g)\' %s >> %s', escapeshellarg($layoutFile) , escapeshellarg($phpFile));
35  self::mySystem($cmd);
36  $cmd = sprintf('perl -ne \'print "\$a=pgettext(\\"$2\\", \\"$1\\");\n" while(m/\[TEXT\(([^\)]+)\):([^]]+)]/g)\' %s >> %s', escapeshellarg($layoutFile) , escapeshellarg($phpFile));
37  self::mySystem($cmd);
38 
39  if ($tmpDir) {
40  $cmd = sprintf('\rm -r %s', escapeshellarg($tmpDir));
41  self::mySystem($cmd);
42  }
43  }
44 
45  $cmd = sprintf('xgettext \
46  --force-po \
47  --language=PHP \
48  --sort-output \
49  --from-code=utf-8 \
50  --no-location \
51  --keyword=pgettext:1,2c \
52  %s -o %s %s && rm %s', $this->getXoptions() , escapeshellarg($potFile) , escapeshellarg($phpFile) , escapeshellarg($phpFile));
53 
54  self::mySystem($cmd);
55  }
56 }
57 
foreach($argv as $arg) $cmd
← centre documentaire © anakeen