3 Ryzom Core Web-Based Translation Tool
4 Copyright (C) 2011 Piotr Kaczmarek <p.kaczmarek@openlink.pl>
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
25 function parseLine($str)
27 $arr = str_getcsv($str, "\t");
31 function parseFile($file)
35 $prevStringLine = false;
39 $file = mb_convert_encoding($file, 'UTF-8', 'UTF-16');
40 // $file = $this->removeBOM($file);
41 // $file = $this->removeComments($file);
42 $lines = explode("\n", $file);
49 /* var_dump(setlocale(LC_ALL,NULL));
50 var_dump(setlocale(LC_ALL,'pl_PL.UTF-8'));*/
51 // Need to set UTF-8 locale to get str_getcsv to work with UTF-8 cyryllic
52 setlocale(LC_ALL
,'pl_PL.UTF-8');
54 foreach ($lines as $line)
58 echo "\n\t#################### LINE NUMBER " . $line_no . "\n\n";
62 $line = rtrim($line,"\r\n");
64 $parsedLine = $this->parseLine($line);
66 if (!$line ||
mb_strpos($line, "DIFF NOT") === 0 ||
mb_strpos($line, "REMOVE THE") === 0)
71 $parsedEnt["type"] = "sheet_description";
72 if ($parsedLine[0] == "DIFF_CMD")
74 $parsedEnt["sheet_id_column"] = $parsedLine[2];
80 $parsedEnt["diff"] = $parsedEnt["command"] = rtrim($parsedLine[0]);
81 $parsedEnt["hash_value"] = $parsedLine[1];
82 $parsedEnt["identifier"] = $parsedLine[2];
86 $parsedEnt["hash_value"] = $parsedLine[0];
87 $parsedEnt["identifier"] = $parsedLine[1];
89 $parsedEnt["type"] = "sheet";
93 $columns = array_slice($parsedLine, 3);
95 $columns = array_slice($parsedLine, 2);
97 if (!isset($columnsCount))
98 $columnsCount = count($columns);
100 $parsedEnt["columns"] = $columns;
104 echo "%%%% parsedEnt %%%%%\n";
105 var_dump($parsedEnt);
108 /* if ($parsedLine["type"] == "internal_index")
109 $parsedEnt["internal_index"] = $parsedLine["index"];
111 if ($parsedLine["type"] == "diff")
113 $parsedEnt["diff"] = $parsedLine["command"];
114 $parsedEnt["index"] = $parsedLine["index"];
121 if ($this->debug
&& 0)
123 echo "\t%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
124 echo "\t%%%% newEnt %%%%%%%%% newEnt %%%%%%%%% newEnt %%%%%%%%% newEnt %%%%%\n";
125 echo "\t%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n";
126 var_dump($parsedEnt);
128 /* if (!isset($parsedEnt["diff"]) && !isset($parsedEnt["index"]))
129 $parsedEnt["index"] = $parsedEnt["internal_index"];*/
131 $entities[] = $parsedEnt;
138 if ($this->debug
&& 0)
149 $s = str_replace("\r\n", "\n", $s);
150 $s = str_replace("\n", "\r\n", $s);
154 function addBOM($str)
156 if(($bom = substr($str, 0,3)) != pack("CCC",0xef,0xbb,0xbf))
157 return pack("CCC",0xef,0xbb,0xbf) . $str;
162 function buildFile($entities)
165 foreach ($entities as $ent)
167 if ($ent['type'] == 'sheet_description')
169 $_columns = $ent['columns'];
170 $_sheet_id_column = $ent['sheet_id_column'];
172 if (isset($ent['diff']))
174 $content .= 'DIFF_CMD' . "\t" . '*HASH_VALUE' . "\t" . $_sheet_id_column . "\t";
175 foreach ($ent['columns'] as $value)
177 $content .= $value . "\t";
179 $content = mb_substr($content, 0, -1);
185 if (isset($ent['command']))
186 $content .= $ent['command'] . "\t";
187 if (isset($ent['hash_value']))
188 $content .= $ent['hash_value'] . "\t";
190 $content .= '_0000000000000000' . "\t";
191 $content .= $ent['identifier'] . "\t";
192 foreach ($ent['columns'] as $value)
194 $content .= $value . "\t";
196 $content = mb_substr($content, 0, -1);
199 return mb_convert_encoding($this->addBOM($this->CRLF($content)), 'UTF-16LE', 'UTF-8');
200 // return mb_convert_encoding($this->CRLF($content), 'UTF-16LE', 'UTF-8');