#!perl
our
$VERSION
= 0;
use
English
qw(-no_match_vars $OS_ERROR)
;
our
$PATH
;
() =
eval
'use Test::DBD::PO::Defaults qw($PATH)'
;
my
$path
=
$PATH
||
q{.}
;
my
@table
=
qw(de ru de_to_ru)
;
{
my
$file_name
=
"$path/$table[0].po"
;
open
my
$file
,
'>'
,
$file_name
or croak
"Can't open file $file_name: $OS_ERROR"
;
print
{
$file
}
<<'EOT' or croak "Can't write file $file_name: $OS_ERROR";
msgid ""
msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit"
msgid "text 1 en"
msgstr "text 1 de"
msgid "text 2 en"
msgstr "text 3 de"
msgid "text3 en"
msgstr "text3 de"
EOT
}
{
my
$file_name
=
"$path/$table[1].po"
;
open
my
$file
,
'>'
,
$file_name
or croak
"Can't open file $file_name: $OS_ERROR"
;
print
{
$file
}
<<'EOT' or croak "Can't write file $file_name: $OS_ERROR";
msgid ""
msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit"
msgid "text 1 en"
msgstr "text 1 ru"
msgid "text 2 en"
msgstr "text 3 ru"
msgid "text3 en"
msgstr "text3 ru"
EOT
}
my
$dbh
= DBI->
connect
(
"DBI:PO:f_dir=$path;po_charset=utf-8"
,
undef
,
undef
,
{
RaiseError
=> 1,
PrintError
=> 0,
},
) or croak
'Cannot connect: '
. DBI->errstr();
for
(
@table
) {
$dbh
->{po_tables}->{
$_
} = {
file
=>
"$_.po"
};
}
$dbh
->
do
(
<<"EOT");
CREATE TABLE $table[2]
(
msgid VARCHAR,
msgstr VARCHAR
)
EOT
my
$sth_insert
=
$dbh
->prepare(
<<"EOT");
INSERT INTO $table[2]
(msgid, msgstr)
VALUES (?, ?)
EOT
$sth_insert
->execute(
q{}
,
$dbh
->func(
undef
,
'build_header_msgstr'
,
),
);
my
$sth_select
=
$dbh
->prepare(
<<"EOT");
SELECT $table[0].msgstr, $table[1].msgstr
FROM $table[0]
INNER JOIN $table[1] ON $table[0].msgid = $table[1].msgid
WHERE $table[0].msgid <> ''
EOT
$sth_select
->execute();
while
(
my
@data
=
$sth_select
->fetchrow_array() ) {
$sth_insert
->execute(
@data
);
}
$dbh
->disconnect();