root/trunk/robots/pot2sql.php

Revision 1, 3.9 KB (checked in by anonymous, 7 years ago)

initial import

Line 
1#!/usr/bin/php
2<?
3include('../includes/includes.inc.php');
4include('../includes/config/dntp.inc.php');
5
6
7$pot_a = file('../locales/locale/fr_FR/LC_MESSAGES/dotnode.po');
8
9$db=&DB::connect($dsn);
10if (DB::isError($db))
11    error_log($_SERVER['HTTP_HOST'].' | '.__FILE__.' | Connexion SQL impossible : '.$db->getMessage());
12   
13$db->setFetchMode(DB_FETCHMODE_ASSOC);
14
15$db->query('TRUNCATE TABLE dntp_msgid');
16$db->query('TRUNCATE TABLE dntp_msgstr');
17
18function stripslashes2($str)
19{
20        return str_replace('\"', '"', $str);
21}
22
23
24foreach($pot_a as $line)
25{
26    $line = trim($line);
27    $context['line']++;
28    $context['source'] = $line;
29
30    if(preg_match("/^msgid/", $line) && isset($m_msgid) && isset($m_msgstr))
31    {
32        $rval = $db->query('INSERT INTO dntp_msgid SET md5=?, msgid=?, first_see=?, multiline=?, status=?, date=?', array(md5(stripslashes2($m_msgid)),  stripslashes2($m_msgid), $comment, 'y', 'ok', time()));
33        if(DB::isError($rval))
34        {
35            print_r($context);
36            print('m_msgid: '.$rval->getUserInfo()."\n");
37        }
38        $msgid_id = $db->getOne('SELECT LAST_INSERT_ID()');
39
40        $context['msgid_id']=$msgid_id;
41
42        $rval = $db->query('INSERT INTO dntp_msgstr SET id=?, msgstr=?, `key`=?, lang=?, translator=?, multiline=?, status=?, date=?', array($msgid_id, stripslashes2($m_msgstr), 0, 'fr_FR', 'importation', 'y', 'ok', time()));
43        if(DB::isError($rval))
44        {
45            print_r($context);
46            print('m_msgstr: '.$rval->getUserInfo()."\n");
47        }
48
49        unset($where);
50        unset($m_msgid);
51        unset($m_msgstr);
52    }
53
54    if(preg_match("/^#(.*)$/", $line, $reg))
55    {
56        $comment = '/'.trim($reg[1]);
57        $context['comment'] = $comment;
58    }
59    elseif(preg_match("/^msgstr \"\"$/", $line, $reg))
60        {
61                $where = 'm_msgstr';
62                $m_msgstr = '';
63                $context['where'] = $where;
64        }
65        elseif(preg_match("/^msgid \"\"$/", $line, $reg))
66        {
67                $where = 'm_msgid';
68                $m_msgid = '';
69                $context['where'] = $where;
70        }
71        elseif(preg_match("/^\"(.*)\"$/", $line, $reg))
72        {
73                $$where .= $reg[1]."\n";
74                $context[$where] = $reg[1];
75        }
76
77    elseif(preg_match("/^msgid \"(.*)\"$/", $line, $reg))
78    {
79        if(strlen($reg[1])>1)
80        {
81            $msgid = $reg[1];
82            $rval = $db->query('INSERT INTO dntp_msgid SET md5=?, msgid=?, first_see=?, status=?, date=?', array(md5(stripslashes2($msgid)), stripslashes2($msgid), $comment, 'ok', time()));
83            if(DB::isError($rval))
84            {
85                print_r($context);
86                print('msgid: '.$rval->getUserInfo()."\n");
87            }
88            $msgid_id = $db->getOne('SELECT LAST_INSERT_ID()');
89            $context['msgid_id']=$msgid_id;
90        }
91
92    }
93    elseif(preg_match("/^msgid_plural \"(.*)\"$/", $line, $reg))
94    {
95        if(strlen($reg[1])>1)
96        {
97            $msgid_plural = $reg[1];
98            $rval = $db->query('UPDATE dntp_msgid SET msgid_plural=? WHERE id=?', array(stripslashes2($msgid_plural), $msgid_id));
99            if(DB::isError($rval))
100            {
101                print_r($context);
102                print('msgid_plural: '.$rval->getUserInfo()."\n");
103            }
104        }
105    }
106    elseif(preg_match("/^msgstr \"(.*)\"$/", $line, $reg))
107    {
108        if(strlen($reg[1])>1)
109        {
110            $msgstr = $reg[1];
111            $rval = $db->query('INSERT INTO dntp_msgstr SET id=?, msgstr=?, `key`=?, lang=?, translator=?, status=?, date=?', array($msgid_id, stripslashes2($msgstr), 0, 'fr_FR', 'importation','ok', time()));
112            if(DB::isError($rval))
113            {
114                print_r($context);
115                print('msgstr: '.$rval->getUserInfo()."\n");
116            }
117        }
118    }
119    elseif(preg_match("/^msgstr\[(.)\] \"(.*)\"$/", $line, $reg))
120    {
121        if(strlen($reg[2])>1)
122        {
123            $msgstr = $reg[2];
124            $rval = $db->query('INSERT INTO dntp_msgstr SET id=?,msgstr=?,`key`=?, lang=?, translator=?, status=?, date=?', array($msgid_id, stripslashes2($msgstr), $reg[1], 'fr_FR', 'importation', 'ok', time()));
125            if(DB::isError($rval))
126            {
127                print_r($context);
128                print('msgstr plural: '.$rval->getUserInfo()."\n");
129            }
130        }
131    }
132    else
133    {
134        unset($msgid_id);
135        unset($msgid);
136        unset($msgstr);
137        unset($msgstr);
138    }
139}
140
141$db->disconnect();
Note: See TracBrowser for help on using the browser.