Adding makepo.sh.php which is currently under heavy development
authorRobert Sesek <rsesek@bluestatic.org>
Thu, 17 Aug 2006 05:41:31 +0000 (05:41 +0000)
committerRobert Sesek <rsesek@bluestatic.org>
Thu, 17 Aug 2006 05:41:31 +0000 (05:41 +0000)
docs/makepo.sh.php [new file with mode: 0755]

diff --git a/docs/makepo.sh.php b/docs/makepo.sh.php
new file mode 100755 (executable)
index 0000000..47fcc95
--- /dev/null
@@ -0,0 +1,84 @@
+#!/usr/bin/php
+<?php
+/*=====================================================================*\
+|| ###################################################################
+|| # xgettext For ISSO PHP and Template Files [#]version[#]
+|| # Copyright ©2002-[#]year[#] Iris Studios, Inc.
+|| #
+|| # This program is free software; you can redistribute it and/or modify
+|| # it under the terms of the GNU General Public License as published by
+|| # the Free Software Foundation; version [#]gpl[#] of the License.
+|| #
+|| # This program is distributed in the hope that it will be useful, but
+|| # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+|| # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+|| # more details.
+|| #
+|| # You should have received a copy of the GNU General Public License along
+|| # with this program; if not, write to the Free Software Foundation, Inc.,
+|| # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+|| ###################################################################
+\*=====================================================================*/
+
+require_once('/Server/htdocs/ISSO/Functions.php');
+
+// TODO - process $argv and translate them into xgettext arguments
+
+// ###################################################################
+// generate the list of files to process
+
+$filelist = BSFunctions::ScanDirectory('.');
+
+foreach ($filelist AS $dirpath => $nodes)
+{
+       $dirpath = ($dirpath ? BSFunctions::FetchSourcePath($dirpath) : '');
+       foreach ($nodes AS $file)
+       {
+               $ext = BSFunctions::FetchExtension($file);
+               if ($ext == 'php')
+               {
+                       $files[] = '.' . BSFunctions::FetchSourcePath($search) . $dirpath . $file;
+               }
+               else if ($ext == 'xml' OR $ext == 'tpl' OR $ext == 'html' OR $ext == 'htm')
+               {
+                       $templates[] = array(
+                               'orig' => '.' . BSFunctions::FetchSourcePath($search) . $dirpath . $file,
+                               'temp' => '.' . BSFunctions::FetchSourcePath($search) . $dirpath . 'xgtxt-' . $file . '.php'
+                       );
+               }
+       }
+}
+
+// ###################################################################
+// compile the templates into gettext-friendly PHP code
+
+function process_template_text($text)
+{
+       return '<?php gettext("' . str_replace(array('\\\"', "'"), array('"', "\'"), $text) . '"); ?>';
+}
+
+foreach ($templates AS $paths)
+{
+       $template = file_get_contents($paths['orig']);
+       
+       if (strpos($template, '{@') === false)
+       {
+               continue;
+       }
+       
+       $template = str_replace('"', '\"', $template);
+       
+       $template = preg_replace('#\{@\\\"(.*?)\\\"\}#ise', 'process_template_text(\'$1\')', $template);
+       
+       print($template); exit;
+       
+       file_put_contents($paths['temp'], preg_replace('#\{@"(.*)"\}#e', "process_template_text('\1')", $template));
+}
+
+/*=====================================================================*\
+|| ###################################################################
+|| # $HeadURL$
+|| # $Id$
+|| ###################################################################
+\*=====================================================================*/
+?>
\ No newline at end of file