7 require_once
"xgettextCommon.php";
8 require_once
"ods2csv.php";
19 return sprintf(
"%s extract tranlation from family structure files\n
20 %s -o <output directory> <input file> [<input file>...]\n
21 If option has '-f-', files from stdin are used\n", $argv[0], $argv[0]);
32 $fdoc = fopen($fi,
"r");
34 throw new Exception(
"fam2po: Can't access file [$fi]");
44 while (!feof($fdoc)) {
48 $buffer = rtrim(fgets($fdoc, 16384));
49 $data = explode(
";", $buffer);
62 $oFileName =
$podir .
"/" . $famname .
".pot";
63 $this->outputFiles[] = $oFileName;
64 $podoc = fopen($oFileName,
"w+");
68 $contentToWrite =
"msgid \"\"\n";
69 $contentToWrite.=
"msgstr \"\"\n";
70 $contentToWrite.=
"\"Project-Id-Version: $famname \\n\"\n";
71 $contentToWrite.=
"\"Report-Msgid-Bugs-To: \\n\"\n";
72 $contentToWrite.=
"\"PO-Revision-Date: $date\\n\"\n";
73 $contentToWrite.=
"\"Last-Translator: Automatically generated\\n\"\n";
74 $contentToWrite.=
"\"Language-Team: none\\n\"\n";
75 $contentToWrite.=
"\"MIME-Version: 1.0\\n\"\n";
76 $contentToWrite.=
"\"Content-Type: text/plain; charset=UTF-8\\n\"\n";
77 $contentToWrite.=
"\"Content-Transfer-Encoding: 8bit\\n\"\n";
78 $contentToWrite.=
"\"Language: \\n\"\n\n";
79 $contentToWrite.=
"#, fuzzy, ($fi)\n";
80 $contentToWrite.=
"msgid \"" . $famname .
"#title\"\n";
81 $contentToWrite.=
"msgstr \"" .
$famtitle .
"\"\n\n";
87 throw new Exception(
"xgettextFamily: Can't create tempory family po file [$podir/$famname.pot]");
89 fwrite($podoc, $contentToWrite);
100 if (
$type ===
"CVDOC") {
102 if (
$value ===
"cv_idview") $cv_idview_index = $index;
103 else if (
$value ===
"cv_lview") $cv_lview_index = $index;
104 else if (
$value ===
"cv_menu") $cv_menu_index = $index;
105 if ($cv_idview_index && $cv_lview_index && $cv_menu_index)
break;
112 if (
$type ===
"CVDOC") {
114 if ($cvName && !is_numeric($cvName) && $cv_idview_index) {
115 $oFileName =
$podir .
"/" . $cvName .
".pot";
116 $cvdoc = fopen($oFileName,
"w+");
118 $this->outputFiles[] = $oFileName;
120 throw new Exception(
"fam2po: Can't create tempory CV po file [$podir/$cvName.pot]");
122 $cvContentToWrite =
"msgid \"\"\n";
123 $cvContentToWrite.=
"msgstr \"\"\n";
124 $cvContentToWrite.=
"\"Project-Id-Version: $cvName \\n\"\n";
125 $cvContentToWrite.=
"\"Report-Msgid-Bugs-To: \\n\"\n";
126 $cvContentToWrite.=
"\"PO-Revision-Date: $date\\n\"\n";
127 $cvContentToWrite.=
"\"Last-Translator: Automatically generated\\n\"\n";
128 $cvContentToWrite.=
"\"Language-Team: none\\n\"\n";
129 $cvContentToWrite.=
"\"MIME-Version: 1.0\\n\"\n";
130 $cvContentToWrite.=
"\"Content-Type: text/plain; charset=UTF-8\\n\"\n";
131 $cvContentToWrite.=
"\"Content-Transfer-Encoding: 8bit\\n\"\n";
132 $cvContentToWrite.=
"\"Language: \\n\"\n\n";
136 foreach ($tcv_idview as $i => $id) {
137 if ($cv_lview_index && $tcv_lview[$i]) {
138 $cvContentToWrite.=
"#: $fi\n";
139 $cvContentToWrite.=
"#, fuzzy\n";
140 $cvContentToWrite.=
"msgid \"" . $cvName .
"#label#" . $id .
"\"\n";
141 $cvContentToWrite.=
"msgstr \"" . $tcv_lview[$i] .
"\"\n\n";
143 if ($cv_menu_index && $tcv_menu[$i]) {
144 $cvContentToWrite.=
"#: $fi\n";
145 $cvContentToWrite.=
"#, fuzzy\n";
146 $cvContentToWrite.=
"msgid \"" . $cvName .
"#menu#" . $id .
"\"\n";
147 $cvContentToWrite.=
"msgstr \"" . $tcv_menu[$i] .
"\"\n\n";
150 fwrite($cvdoc, $cvContentToWrite);
160 $contentToWrite.=
"#: $fi\n";
161 $contentToWrite.=
"#, fuzzy, ($fi)\n";
168 $tenum = explode(
",",
$d);
169 foreach ($tenum as $ve) {
170 $d = str_replace(
'\#',
',', $ve);
171 $enumValues = explode(
"|",
$d);
172 $contentToWrite.=
"#, fuzzy, ($fi)\n";
174 $contentToWrite.=
"msgstr \"" . (str_replace(
'\\',
'', $this->
getArrayIndexValue($enumValues, 1))) .
"\"\n\n";
179 $options = explode(
"|", $options);
180 foreach ($options as $currentOption) {
181 $currentOption = explode(
"=", $currentOption);
184 switch (strtolower($currentOptionKey)) {
193 $contentToWrite.=
"#, fuzzy, ($fi)\n";
194 $contentToWrite.=
"msgid \"" . $famname .
"#" . strtolower($this->
getArrayIndexValue(
$data, 1)) .
"#" . strtolower($currentOptionKey) .
"\"\n";
195 $contentToWrite.=
"msgstr \"" . $currentOptionValue .
"\"\n\n";
205 return isset($array[$index]) ? $array[$index] :
"";
210 return implode(
", ", $this->outputFiles);
215 if (!is_dir($this->outputFile)) {
216 throw new Exception(sprintf(
'output option "%s" must be a directory', $this->outputFile));
220 foreach ($this->inputFiles as $familyFile) {
221 if (empty($familyFile)) {
226 $familyFilePathInfo = pathinfo($familyFile);
227 if (file_exists($familyFile)) {
228 if (isset($familyFilePathInfo[
'extension'])) {
229 switch ($familyFilePathInfo[
'extension']) {
232 $convert->convertOds2csv($familyFile,
$csvfile);
236 throw new Exception(
"Unable to generate CSV from " . $familyFile);
246 $err = ($familyFile .
" has an unknown extension, skipping it.");
249 $err = ($familyFile .
" has no extension, skipping it.");
252 throw new Exception(
"Can't access file " . $familyFile);
255 catch(Exception $e) {
256 $err.= $e->getMessage() .
" " . $e->getFile() .
" line (" . $e->getLine() .
")\n";
259 throw new Exception(
$err);
if($dbaccess=="") if($statusFile=== '') $famtitle
extractPOFromCSV($fi, $podir)
getArrayIndexValue(&$array, $index)
if($file) if($subject==""&&$file) if($subject=="") $err