8 define(
"SEPCHAR",
';');
9 define(
"ALTSEPCHAR",
' --- ');
22 for ($i = 2; $i < count($argv); $i++) {
24 $familyFile = $argv[$i];
27 $familyFilePathInfo = pathinfo($familyFile);
28 if (file_exists($familyFile)) {
29 if (isset($familyFilePathInfo[
'extension'])) {
30 switch ($familyFilePathInfo[
'extension']) {
38 throw new Exception(
"Unable to generate CSV from " . $familyFile);
48 debugMessage($familyFile .
" has an unknown extension, skipping it.");
51 debugMessage($familyFile .
" has no extension, skipping it.");
54 throw new Exception(
"Can't access file " . $familyFile);
58 $err.= $e->getMessage() .
" " . $e->getFile() .
" line (" . $e->getLine() .
")\n";
61 throw new Exception($e);
69 error_log(
"fam2po: " . $msg);
81 $fdoc = fopen($fi,
"r");
83 new Exception(
"fam2po: Can't access file [$fi]");
93 while (!feof($fdoc)) {
97 $buffer = rtrim(fgets($fdoc, 16384));
98 $data = explode(
";", $buffer);
110 if ($famname) $podoc = fopen(
$podir .
"/" . $famname .
".pot",
"w+");
111 $contentToWrite =
"msgid \"\"\n";
112 $contentToWrite.=
"msgstr \"\"\n";
113 $contentToWrite.=
"\"Project-Id-Version: $famname \\n\"\n";
114 $contentToWrite.=
"\"Report-Msgid-Bugs-To: \\n\"\n";
115 $contentToWrite.=
"\"PO-Revision-Date: $date\\n\"\n";
116 $contentToWrite.=
"\"Last-Translator: Automatically generated\\n\"\n";
117 $contentToWrite.=
"\"Language-Team: none\\n\"\n";
118 $contentToWrite.=
"\"MIME-Version: 1.0\\n\"\n";
119 $contentToWrite.=
"\"Content-Type: text/plain; charset=UTF-8\\n\"\n";
120 $contentToWrite.=
"\"Content-Transfer-Encoding: 8bit\\n\"\n";
121 $contentToWrite.=
"\"Language: \\n\"\n\n";
122 $contentToWrite.=
"#, fuzzy, ($fi)\n";
123 $contentToWrite.=
"msgid \"" . $famname .
"#title\"\n";
124 $contentToWrite.=
"msgstr \"" .
$famtitle .
"\"\n\n";
129 new Exception(
"fam2po: Can't create tempory family po file [$podir/$famname.pot]");
131 fwrite($podoc, $contentToWrite);
134 $famname =
"*******";
139 $cv_idview_index = 0;
142 if (
$type ===
"CVDOC") {
144 if (
$value ===
"cv_idview") $cv_idview_index = $index;
145 else if (
$value ===
"cv_lview") $cv_lview_index = $index;
146 else if (
$value ===
"cv_menu") $cv_menu_index = $index;
147 if ($cv_idview_index && $cv_lview_index && $cv_menu_index)
break;
154 if (
$type ===
"CVDOC") {
156 if ($cvName && !is_numeric($cvName) && $cv_idview_index) {
157 $cvdoc = fopen(
$podir .
"/" . $cvName .
".pot",
"w+");
159 new Exception(
"fam2po: Can't create tempory CV po file [$podir/$cvName.pot]");
161 $cvContentToWrite =
"msgid \"\"\n";
162 $cvContentToWrite.=
"msgstr \"\"\n";
163 $cvContentToWrite.=
"\"Project-Id-Version: $cvName \\n\"\n";
164 $cvContentToWrite.=
"\"Report-Msgid-Bugs-To: \\n\"\n";
165 $cvContentToWrite.=
"\"PO-Revision-Date: $date\\n\"\n";
166 $cvContentToWrite.=
"\"Last-Translator: Automatically generated\\n\"\n";
167 $cvContentToWrite.=
"\"Language-Team: none\\n\"\n";
168 $cvContentToWrite.=
"\"MIME-Version: 1.0\\n\"\n";
169 $cvContentToWrite.=
"\"Content-Type: text/plain; charset=UTF-8\\n\"\n";
170 $cvContentToWrite.=
"\"Content-Transfer-Encoding: 8bit\\n\"\n";
171 $cvContentToWrite.=
"\"Language: \\n\"\n\n";
175 foreach ($tcv_idview as $i => $id) {
176 if ($cv_lview_index && $tcv_lview[$i]) {
177 $cvContentToWrite.=
"#: $fi\n";
178 $cvContentToWrite.=
"#, fuzzy\n";
179 $cvContentToWrite.=
"msgid \"" . $cvName .
"#label#" . $id .
"\"\n";
180 $cvContentToWrite.=
"msgstr \"" . $tcv_lview[$i] .
"\"\n\n";
182 if ($cv_menu_index && $tcv_menu[$i]) {
183 $cvContentToWrite.=
"#: $fi\n";
184 $cvContentToWrite.=
"#, fuzzy\n";
185 $cvContentToWrite.=
"msgid \"" . $cvName .
"#menu#" . $id .
"\"\n";
186 $cvContentToWrite.=
"msgstr \"" . $tcv_menu[$i] .
"\"\n\n";
189 fwrite($cvdoc, $cvContentToWrite);
199 $contentToWrite.=
"#: $fi\n";
200 $contentToWrite.=
"#, fuzzy, ($fi)\n";
207 $tenum = explode(
",",
$d);
208 foreach ($tenum as $ve) {
209 $d = str_replace(
'\#',
',', $ve);
210 $enumValues = explode(
"|",
$d);
211 $contentToWrite.=
"#, fuzzy, ($fi)\n";
213 $contentToWrite.=
"msgstr \"" . (str_replace(
'\\',
'',
getArrayIndexValue($enumValues, 1))) .
"\"\n\n";
218 $options = explode(
"|", $options);
219 foreach ($options as $currentOption) {
220 $currentOption = explode(
"=", $currentOption);
223 switch (strtolower($currentOptionKey)) {
232 $contentToWrite.=
"#, fuzzy, ($fi)\n";
233 $contentToWrite.=
"msgid \"" . $famname .
"#" . strtolower(
getArrayIndexValue(
$data, 1)) .
"#" . strtolower($currentOptionKey) .
"\"\n";
234 $contentToWrite.=
"msgstr \"" . $currentOptionValue .
"\"\n\n";
243 return isset($array[$index]) ? $array[$index] :
"";
257 throw new Exception(
"ODS convert needs an ODS path and a CSV path");
263 if ($isWrited ===
false) {
264 throw new Exception(sprintf(
"Unable to convert ODS to CSV fo %s",
$odsfile));
277 throw new Exception(
"file $odsfile not found");
279 $cibledir = uniqid(
"/var/tmp/ods");
281 $cmd = sprintf(
"unzip -j %s content.xml -d %s >/dev/null",
$odsfile, $cibledir);
284 $contentxml = $cibledir .
"/content.xml";
285 if (file_exists($contentxml)) {
286 $content = file_get_contents($contentxml);
289 throw new Exception(
"unable to extract $odsfile");
304 $xml_parser = xml_parser_create();
306 xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING,
true);
307 xml_parser_set_option($xml_parser, XML_OPTION_SKIP_WHITE, 0);
308 xml_set_element_handler($xml_parser,
"startElement",
"endElement");
309 xml_set_character_data_handler($xml_parser,
"characterData");
311 if (!xml_parse($xml_parser, $xmlcontent)) {
312 throw new Exception(sprintf(
"Unable to parse XML : %s line %d", xml_error_string(xml_get_error_code($xml_parser)) , xml_get_current_line_number($xml_parser)));
315 xml_parser_free($xml_parser);
316 foreach ($rows as $row) {
317 $fcsv.= implode(
SEPCHAR, $row) .
"\n";
324 $parser, $name, $attrs)
327 if ($name ==
"TABLE:TABLE-ROW") {
329 if (isset($rows[$nrow])) {
332 foreach ($rows[$nrow] as $k => $v) {
333 if (!isset($rows[$nrow][$idx])) {
334 $rows[
$nrow][$idx] =
'';
338 ksort($rows[$nrow], SORT_NUMERIC);
342 $rows[
$nrow] = array();
345 if ($name ==
"TABLE:TABLE-CELL") {
349 if (!empty($attrs[
"TABLE:NUMBER-COLUMNS-REPEATED"])) {
350 $colrepeat = intval($attrs[
"TABLE:NUMBER-COLUMNS-REPEATED"]);
353 if ($name ==
"TEXT:P") {
354 if (isset($rows[$nrow][$ncol])) {
355 if (strlen($rows[$nrow][$ncol]) > 0) {
367 if ($name ==
"TABLE:TABLE-ROW") {
371 if (strlen($rows[$nrow][$i]) > 0) {
376 array_splice($rows[$nrow], $i + 1);
380 if ($name ==
"TABLE:TABLE-CELL") {
383 if ($celldata ===
'') {
389 if ($colrepeat > 1) {
406 if ($inrow && $incell) {
415 if (isset($attrs[
'OFFICE:VALUE-TYPE'])) {
416 $type = strtoupper($attrs[
'OFFICE:VALUE-TYPE']);
417 $propName =
'OFFICE:' .
$type .
'-VALUE';
418 if (isset($attrs[$propName])) {
419 $value = (string)$attrs[$propName];
423 if (
$value ==
'' && isset($attrs[
'OFFICE:VALUE'])) {
424 $value = (string)$attrs[
'OFFICE:VALUE'];
getArrayIndexValue(&$array, $index)
if($dbaccess=="") if($statusFile=== '') $famtitle
startElement($parser, $name, $attrs)
getOfficeTypedValue($attrs)
foreach($argv as $arg) $cmd
characterData($parser, $data)
xmlcontent2csv($xmlcontent)
extractPOFromCSV($fi, $podir)
ods2csv($odsfile, $csvfile)
if($file) if($subject==""&&$file) if($subject=="") $err
endElement($parser, $name)
for($i=2;$i< count($argv);$i++) debugMessage($msg)