' . "\n"; echo '' . "\n"; ?> base = WBParam::get('wb/dir/base'); WBClass::load('patI18n'); $config = WBClass::create('WBConfig'); $config->load('locale'); $trans = $config->get('translators', array()); if (empty($trans) || !isset($trans['modules'])) { $trans['modules'] = array(); } foreach ($trans['modules'] as $mod) { if (isset($mod['defaultdomain'])) { $mod['domain'] = $mod['defaultdomain']; } $this->imp = patI18n::createImporter($mod['module'], $mod); } } public function import($lang = 'de') { $this->lang = $lang; echo "

Wombat

\n"; $po = sprintf('%s/resource/gettext/%s/%s.po', $this->base, 'wombat', $this->lang); $csv = $this->po2csv($po, 'wombat'); $this->csv2db($csv, 'wombat'); echo "

patForms

\n"; $po = sprintf('%s/include/patForms/data/gettext/%s/%s.po', $this->base, 'patForms', $this->lang); $csv = $this->po2csv($po, 'patForms'); $this->csv2db($csv, 'patForms'); } /** * requires po2csv * * do a "apt-get install translate-toolkit" * @see http://translate.sourceforge.net/wiki/toolkit/csv2po */ private function po2csv($po, $domain) { if (empty($po) || !file_exists($po)) { echo "PO file not found
\n"; return null; } $csv = sprintf('%s/var/tmp/%s_%s.csv', $this->base, $domain, $this->lang); $cmd = sprintf('po2csv %s %s', $po, $csv); exec($cmd, $out, $ret); if($ret) { echo "
" . print_r($out, true) . "
\n"; } return $csv; } private function csv2db($csv, $domain) { if (empty($csv) || !file_exists($csv)) { return null; } $fh = fopen($csv, 'r'); fgetcsv($fh, 0, self::CSV_DEL, self::CSV_ENC); while (!feof($fh)) { $line = fgetcsv($fh, 0, self::CSV_DEL, self::CSV_ENC); if(!is_array($line) || empty($line)) { continue; } $empty = trim(implode('', $line)); if (empty($empty)) { continue; } $id = $this->imp->addMsg($line[1], null, $domain); echo "id: $id $line[2]
"; $this->imp->addTranslation($id, $line[2], $this->lang); } fclose($fh); } } $imp = new POImporter(); $imp->import($_GET['lang']); ?>