Adding makepo.sh.php which is currently under heavy development
[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[] = '.' . BSFunctions::FetchSourcePath($search) . $dirpath . $file;
41 }
42 else if ($ext == 'xml' OR $ext == 'tpl' OR $ext == 'html' OR $ext == 'htm')
43 {
44 $templates[] = array(
45 'orig' => '.' . BSFunctions::FetchSourcePath($search) . $dirpath . $file,
46 'temp' => '.' . BSFunctions::FetchSourcePath($search) . $dirpath . 'xgtxt-' . $file . '.php'
47 );
48 }
49 }
50 }
51
52 // ###################################################################
53 // compile the templates into gettext-friendly PHP code
54
55 function process_template_text($text)
56 {
57 return '<?php gettext("' . str_replace(array('\\\"', "'"), array('"', "\'"), $text) . '"); ?>';
58 }
59
60 foreach ($templates AS $paths)
61 {
62 $template = file_get_contents($paths['orig']);
63
64 if (strpos($template, '{@') === false)
65 {
66 continue;
67 }
68
69 $template = str_replace('"', '\"', $template);
70
71 $template = preg_replace('#\{@\\\"(.*?)\\\"\}#ise', 'process_template_text(\'$1\')', $template);
72
73 print($template); exit;
74
75 file_put_contents($paths['temp'], preg_replace('#\{@"(.*)"\}#e', "process_template_text('\1')", $template));
76 }
77
78 /*=====================================================================*\
79 || ###################################################################
80 || # $HeadURL$
81 || # $Id$
82 || ###################################################################
83 \*=====================================================================*/
84 ?>