We no longer need to add individual templates to the $files[] array
[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 // TODO - process $argv and translate them into xgettext arguments
26
27 // ###################################################################
28 // generate the list of files to process
29
30 $filelist = BSFunctions::ScanDirectory('.');
31
32 foreach ($filelist AS $dirpath => $nodes)
33 {
34 $dirpath = ($dirpath ? BSFunctions::FetchSourcePath($dirpath) : '');
35 foreach ($nodes AS $file)
36 {
37 $ext = BSFunctions::FetchExtension($file);
38 if ($ext == 'php')
39 {
40 $files["$dirpath"] = BSFunctions::FetchSourcePath('./' . $dirpath) . '*.php';
41 }
42 else if ($ext == 'xml' OR $ext == 'tpl' OR $ext == 'html' OR $ext == 'htm')
43 {
44 $files["$dirpath"] = BSFunctions::FetchSourcePath('./' . $dirpath) . '*.php';
45 $templates[] = array(
46 'orig' => BSFunctions::FetchSourcePath('./' . $dirpath) . $file,
47 'temp' => BSFunctions::FetchSourcePath('./' . $dirpath) . $file . '.xgettext.php'
48 );
49 }
50 }
51 }
52
53 // ###################################################################
54 // compile the templates into gettext-friendly PHP code
55
56 function process_template_text($text)
57 {
58 return '<?php gettext("' . $text . '"); ?>';
59 }
60
61 foreach ($templates AS $paths)
62 {
63 $template = file_get_contents($paths['orig']);
64
65 $template = preg_replace('#\{@\\"(.*?)\\"\}#ise', 'process_template_text(\'$1\')', $template);
66
67 file_put_contents($paths['temp'], $template);
68
69 $removelater[] = $paths['temp'];
70 }
71
72 // ###################################################################
73 // run xgettext on all of the various files that we have now created
74
75 exec('xgettext -n ' . implode(' ', $files));
76
77 // ###################################################################
78 // remove all the files we no longer need
79
80 foreach ($removelater AS $path)
81 {
82 unlink($path);
83 }
84
85 /*=====================================================================*\
86 || ###################################################################
87 || # $HeadURL$
88 || # $Id$
89 || ###################################################################
90 \*=====================================================================*/
91 ?>