Merging r695 from the 2.1.x branch to the trunk
[isso.git] / docs / makepo.sh.php
1 #!/usr/bin/php
2 <?php
3 /*=====================================================================*\
4 || ###################################################################
5 || # xgettext For ISSO PHP and Template Files [#]version[#]
6 || # Copyright ©2002-[#]year[#] Iris Studios, Inc.
7 || #
8 || # This program is free software; you can redistribute it and/or modify
9 || # it under the terms of the GNU General Public License as published by
10 || # the Free Software Foundation; version [#]gpl[#] of the License.
11 || #
12 || # This program is distributed in the hope that it will be useful, but
13 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 || # more details.
16 || #
17 || # You should have received a copy of the GNU General Public License along
18 || # with this program; if not, write to the Free Software Foundation, Inc.,
19 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
20 || ###################################################################
21 \*=====================================================================*/
22
23 require_once('/Server/htdocs/ISSO/Functions.php');
24
25 // ###################################################################
26 // generate the list of files to process
27
28 $filelist = BSFunctions::ScanDirectory('.');
29
30 foreach ($filelist AS $dirpath => $nodes)
31 {
32 $dirpath = ($dirpath ? BSFunctions::FetchSourcePath($dirpath) : '');
33 foreach ($nodes AS $file)
34 {
35 $ext = BSFunctions::FetchExtension($file);
36 if ($ext == 'php')
37 {
38 $files["$dirpath"] = BSFunctions::FetchSourcePath('./' . $dirpath) . '*.php';
39 }
40 else if ($ext == 'xml' OR $ext == 'tpl' OR $ext == 'html' OR $ext == 'htm')
41 {
42 $files["$dirpath"] = BSFunctions::FetchSourcePath('./' . $dirpath) . '*.php';
43 $templates[] = array(
44 'orig' => BSFunctions::FetchSourcePath('./' . $dirpath) . $file,
45 'temp' => BSFunctions::FetchSourcePath('./' . $dirpath) . $file . '.xgt.php'
46 );
47 }
48 }
49 }
50
51 // ###################################################################
52 // compile the templates into gettext-friendly PHP code
53
54 function process_template_text($text)
55 {
56 return '<?php gettext("' . $text . '"); ?>';
57 }
58
59 foreach ($templates AS $paths)
60 {
61 $template = file_get_contents($paths['orig']);
62
63 $template = preg_replace('#\{@\\"(.*?)\\"\}#ise', 'process_template_text(\'$1\')', $template);
64
65 file_put_contents($paths['temp'], $template);
66
67 $removelater[] = $paths['temp'];
68 }
69
70 // ###################################################################
71 // run xgettext on all of the various files that we have now created
72
73 // get any arguments and just pass them to xgettext
74 $arguments = $argv;
75 unset($arguments[0]);
76
77 exec('xgettext ' . implode(' ', $arguments) . ' ' . implode(' ', $files));
78
79 // ###################################################################
80 // remove all the files we no longer need
81
82 foreach ($removelater AS $path)
83 {
84 unlink($path);
85 }
86
87 /*=====================================================================*\
88 || ###################################################################
89 || # $HeadURL$
90 || # $Id$
91 || ###################################################################
92 \*=====================================================================*/
93 ?>