+++ /dev/null
-#!/usr/bin/php
-<?php
-/*=====================================================================*\
-|| ###################################################################
-|| # mkstrings (ISSO: Lost In Translation) [#]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
-|| ###################################################################
-\*=====================================================================*/
-
-// ###################################################################
-
-if ($argc < 3)
-{
- print("mkstrings creates XML string files from PHP sources that");
- print("\nhave been localized using ISSO's localization module");
- print("\n\n");
- print("Usage: mkstrings <object caller> <ISSO path> [path] [-o <out>]");
- print("\n\t<object caller> The PHP class that contains the string() method,");
- print("\n\t\t\tthe localizer function; this is usually \"lang\".");
- print("\n\t\t\tDo not include the object operator.");
- print("\n\t<ISSO path> Path to the location of the ISSO framework");
- print("\n\t[path] Path in which to parse strings of *.php");
- print("\n\t[-o <out>] Out file path; by default this is ./out.strings.xml");
- print("\n");
- exit;
-}
-
-// ###################################################################
-
-$caller = $argv[1];
-$issopath = $argv[2];
-$search = ($argv[3] ? $argv[3] : './');
-$out = ($argv[4] ? $argv[5] : './out.strings.xml');
-
-require_once($issopath . DIRECTORY_SEPARATOR . 'kernel.php');
-$isso =& $_isso;
-$isso->sourcepath = $isso->fetch_sourcepath($issopath);
-
-$isso->load('functions');
-
-if (is_dir($out))
-{
- $out = $isso->fetch_sourcepath($out) . 'out.strings.xml';
-}
-
-print("Linking framework and needed modules\n");
-
-// ###################################################################
-
-$filelist = $funct->scandir($search);
-
-foreach ($filelist AS $dirpath => $nodes)
-{
- $dirpath = ($dirpath ? $isso->fetch_sourcepath($dirpath) : '');
- foreach ($nodes AS $file)
- {
- $ext = $funct->fetch_extension($file);
- if ($ext == 'php')
- {
- $files[] = $isso->fetch_sourcepath($search) . $dirpath . $file;
- }
- else if ($ext == 'xml' OR $ext == 'tpl' OR $ext == 'html' OR $ext == 'htm')
- {
- $templates[] = $isso->fetch_sourcepath($search) . $dirpath . $file;
- }
- }
-}
-
-print("Generating file node list\n");
-
-// ###################################################################
-
-foreach ($files AS $file)
-{
- $data = file_get_contents($file);
- if ($data === false)
- {
- print("ERROR reading file: $file\n");
- continue;
- }
- print("Read file node: $file\n");
-
- $strings[] = break_tokens($data, $caller);
-}
-
-// ###################################################################
-
-foreach ($templates AS $file)
-{
- $data = file_get_contents($file);
- if ($data === false)
- {
- print("ERROR reading file: $file\n");
- }
- print("Read file node: $file\n");
-
- $strings[] = parse_template($data);
-}
-
-// ###################################################################
-
-foreach ($strings AS $subset)
-{
- foreach ($subset AS $string)
- {
- $masters["$string"] = $string;
- }
-}
-
-// ###################################################################
-
-print("Found a total of " . count($masters) . " localizable strings\n");
-
-$f = fopen($out, 'w');
-
-fwrite($f, '<?xml version="1.0" encoding="iso-8859-1"?>' . "\n\n");
-fwrite($f, '<localization>' . "\n\n");
-
-foreach ($masters AS $string)
-{
- fwrite($f, "\t<string>\n");
- fwrite($f, "\t\t<key><![CDATA[$string]]></key>\n");
- fwrite($f, "\t\t<value><![CDATA[$string]]></value>\n");
- fwrite($f, "\t</string>\n");
-}
-
-fwrite($f, "\n</localization>");
-
-fclose($f);
-
-print("Exported strings as localizable file: out.strings.xml");
-print("\n");
-
-// ###################################################################
-
-function break_tokens($fileraw, $caller)
-{
- $tokens = token_get_all($fileraw);
-
- print("\t... breaking symbols into tokens\n");
-
- // nominalize tokens
- foreach ($tokens AS $id => $token)
- {
- if (is_array($token))
- {
- $tokens["$id"][2] = $name = token_name($token[0]);
- $tokens["$id"][3] = $id;
- }
- else
- {
- $tokens["$id"] = array(
- 0 => -1,
- 1 => $token,
- 2 => 'X_OTHER',
- 3 => $id
- );
- }
- }
-
- $stack = 0;
- $count = 0;
- $strings = array();
-
- // parse calls
- foreach ($tokens AS $id => $token)
- {
- // looking for initial operator
- if ($stack == 0)
- {
- if ($token[2] == 'T_VARIABLE' OR $token[2] == 'T_STRING')
- {
- if ($token[1] == '$' . $caller OR $token[1] == $caller)
- {
- $stack++;
- }
- }
- }
- // need an object operator to continue
- else if ($stack == 1)
- {
- if ($token[2] == 'T_OBJECT_OPERATOR')
- {
- $stack++;
- }
- else
- {
- $stack = 0;
- }
- }
- // look for the string() method
- else if ($stack == 2)
- {
- if ($token[1] == 'string')
- {
- $stack++;
- }
- else
- {
- $stack = 0;
- }
- }
- // first T_CONSTANT_ENCAPSED_STRING will do
- else if ($stack >= 3)
- {
- if ($token[2] == 'T_CONSTANT_ENCAPSED_STRING')
- {
- $strings[] = extract_string($token[1]);
- $count++;
- $stack = 0;
- }
- }
- }
-
- print("\t... found $count localizable strings\n");
- print("\n");
-
- return $strings;
-}
-
-// ###################################################################
-
-function extract_string($string)
-{
- $encap = $string{0};
-
- $string = str_replace('\\' . $encap, $encap, $string);
- $string = substr($string, 1, strlen($string) - 2);
-
- return $string;
-}
-
-// ###################################################################
-
-function parse_template($raw)
-{
- $length = strlen($raw);
-
- $stack = 0;
- $capture = false;
- $index = 0;
- $strings = array();
-
- for ($i = 0; $i < $length; $i++)
- {
- if ($capture)
- {
- if ($raw["$i"] == '"' AND $raw[ $i - 1 ] != '\\' AND $raw[ $i + 1 ] == '}' AND $raw[ $i - 1 ] != '@')
- {
- $stack = 0;
- $capture = false;
- $strings[ ++$index ] = '';
- }
- else
- {
- $strings["$index"] .= $raw["$i"];
- }
- }
- else
- {
- if ($raw["$i"] == '{')
- {
- $stack++;
- $capture = false;
- }
- else if ($stack == 1)
- {
- if ($raw["$i"] == '@')
- {
- $stack++;
- }
- else
- {
- $stack = 0;
- }
- $capture = false;
- }
- else if ($stack == 2)
- {
- if ($raw["$i"] == '"')
- {
- $stack++;
- $capture = true;
- }
- else
- {
- $stack = 0;
- $capture = false;
- }
- }
- }
- }
-
- print("\t... found " . count($strings) . " localizable strings\n");
- print("\n");
-
- return $strings;
-}
-
-/*=====================================================================*\
-|| ###################################################################
-|| # $HeadURL$
-|| # $Id$
-|| ###################################################################
-\*=====================================================================*/
-?>
\ No newline at end of file