view release on metacpan or search on metacpan
- run binmode only one time for each file at DBD::PO::Text::PO (performance)
0.07 Fri Sep 05 22:00:00 2008
- seventh developer test version
- API changed for read header "msgstr".
- API changed to connect parameter "po_charset"
- Do not use special characters in comments.
There is no quoting at the moment.
- Do not use "... = $dbh->quote(...);".
The bug is not fixed.
- Fixed bug of quote "msgid" and all the different "msgstr"s.
0.06 Wed Jul 30 22:00:00 2008
- sixth developer test version
- change tests: change use Test::Differences in eval block to require
- add example
0.05 Tue Jul 29 15:00:00 2008
- fifth developer test version
- fixed any problems with charset and eol
- changed parameter po_charset to charset
example/01_write.pl view on Meta::CPAN
# create the new po file (table)
$dbh->do(<<"EOT");
CREATE TABLE
$table (
comment VARCHAR,
automatic VARCHAR,
reference VARCHAR,
obsolete INTEGER,
fuzzy INTEGER,
msgid VARCHAR,
msgstr VARCHAR
)
EOT
# build a default header
my $header_msgstr = $dbh->func(
undef, # minimized
'build_header_msgstr', # function name
);
# write the header (first row)
# header msgid is always empty, will set to NULL or q{} and get back as q{}
# header msgstr must have a length
$dbh->do(<<"EOT", undef, $header_msgstr);
INSERT INTO $table (
msgstr
) VALUES (?)
EOT
# prepare to write some po entrys (rows)
# row msgid must have a length
# row msgstr can be empty (NULL or q{}), will get back as q{}
my $sth = $dbh->prepare(<<"EOT");
INSERT INTO $table (
msgid,
msgstr
) VALUES (?, ?)
EOT
# declare some data only
my @data = (
{
msgid => 'text1 original',
msgstr => 'text1 translated',
},
{
msgid => "text2 original\n2nd line of text2",
msgstr => "text2 translated\n2nd line of text2",
},
{
msgid => 'text3 original %1',
msgstr => 'text3 translated %1',
},
{
msgid => 'text4 original [quant,_1,o_one,o_more,o_nothing]',
msgstr => 'text4 translated [quant,_1,t_one,t_more,t_nothing]',
},
);
# write all the data into the po file (table)
for my $data (@data) {
$sth->execute(
$dbh->func(
@{$data}{qw(msgid msgstr)},
'maketext_to_gettext',
),
);
};
# all done
$dbh->disconnect();
example/02_write_plural_po.pl view on Meta::CPAN
# create the new po file (table)
$dbh->do(<<"EOT");
CREATE TABLE
$table (
comment VARCHAR,
automatic VARCHAR,
reference VARCHAR,
obsolete INTEGER,
fuzzy INTEGER,
msgid VARCHAR,
msgid_plural VARCHAR,
msgstr_0 VARCHAR,
msgstr_1 VARCHAR
)
EOT
# build a header
my $header_msgstr = $dbh->func(
{
# an English/German example
'Plural-Forms' => 'nplurals=2; plural=n != 1;',
},
# function name
'build_header_msgstr',
);
# write the header (first row)
# header msgid is always empty, will set to NULL or q{} and get back as q{}
# header msgstr must have a length
$dbh->do(<<"EOT", undef, $header_msgstr);
INSERT INTO $table (
msgstr
) VALUES (?)
EOT
# prepare to write some po entrys (rows)
# row msgid must have a length
# row msgstr can be empty (NULL or q{}), will get back as q{}
my $sth = $dbh->prepare(<<"EOT");
INSERT INTO $table (
msgid,
msgid_plural,
msgstr,
msgstr_0,
msgstr_1
) VALUES (?, ?, ?, ?, ?)
EOT
# declare some data only
my @data = (
{
msgid => 'text1 original',
msgstr => 'text1 translated',
},
{
msgid => "text2 original\n2nd line of text2",
msgstr => "text2 translated\n2nd line of text2",
},
{
msgid => 'text5 original {text}',
msgstr => 'text5 translated {text}',
},
{
msgid => 'text6 original {num} singular',
msgid_plural => 'text6 original {num} plural',
msgstr_0 => 'text6 translated {num} singular',
msgstr_1 => 'text6 translated {num} plural',
},
);
# write all the data into the po file (table)
for my $data (@data) {
$sth->execute(
@{$data}{qw(msgid msgid_plural msgstr msgstr_0 msgstr_1)},
);
};
# all done
$dbh->disconnect();
example/21_read.pl view on Meta::CPAN
},
) or croak 'Cannot connect: ' . DBI->errstr();
$po_charset = $dbh->func(
{table => $table}, # wich table
'charset', # what to get
'get_header_msgstr_data', # function name
);
}
# get the header (first row) from po file (table)
# header msgid is always empty but not NULL
{
my $header_data_ref = $dbh->func(
{table => $table}, # wich table
DBD::PO->get_all_header_keys(), # what to get
'get_header_msgstr_data', # function name
);
print Data::Dumper->new([@{$header_data_ref}], [DBD::PO->get_all_header_keys()]) ## no critic (LongChainsOfMethodCalls CheckedSyscalls)
->Quotekeys(0)
->Useqq(1)
->Dump();
}
# get all the po entys (rows) from po file (table)
# row msgid is never empty
{
my $sth = $dbh->prepare(<<"EOT");
SELECT msgid, msgstr
FROM $table
WHERE msgid <> ''
EOT
$sth->execute();
while (my $row = $sth->fetchrow_hashref()) {
# and show each po entry (row)
print Data::Dumper->new([$row], [qw(row)]) ## no critic (LongChainsOfMethodCalls CheckedSyscalls)
->Quotekeys(0)
->Useqq(1)
->Dump();
example/22_read_plural.pl view on Meta::CPAN
},
) or croak 'Cannot connect: ' . DBI->errstr();
$po_charset = $dbh->func(
{table => $table}, # wich table
'charset', # what to get
'get_header_msgstr_data', # function name
);
}
# get the header (first row) from po file (table)
# header msgid is always empty but not NULL
{
my $header_data_ref = $dbh->func(
{table => $table}, # wich table
DBD::PO->get_all_header_keys(), # what to get
'get_header_msgstr_data', # function name
);
print Data::Dumper->new([@{$header_data_ref}], [DBD::PO->get_all_header_keys()]) ## no critic (LongChainsOfMethodCalls CheckedSyscalls)
->Quotekeys(0)
->Useqq(1)
->Dump();
}
# get all the po entys (rows) from po file (table)
# row msgid is never empty
{
my $sth = $dbh->prepare(<<"EOT");
SELECT msgid, msgid_plural, msgstr, msgstr_0, msgstr_1
FROM $table
WHERE msgid <> ''
EOT
$sth->execute();
while (my $row = $sth->fetchrow_hashref()) {
# and show each po entry (row)
print Data::Dumper->new([$row], [qw(row)]) ## no critic (LongChainsOfMethodCalls CheckedSyscalls)
->Quotekeys(0)
->Useqq(1)
->Dump();
example/31_join.pl view on Meta::CPAN
my $path = $PATH
|| q{.};
my @table = qw(de ru de_to_ru);
# write a file to disk only
{
my $file_name = "$path/$table[0].po";
open my $file, '>', $file_name ## no critic (BriefOpen)
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
}
# write a file to disk only
{
my $file_name = "$path/$table[1].po";
open my $file, '>', $file_name ## no critic (BriefOpen)
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
}
# connect to database (directory)
my $dbh = DBI->connect(
"DBI:PO:f_dir=$path;po_charset=utf-8",
undef,
example/31_join.pl view on Meta::CPAN
},
) or croak 'Cannot connect: ' . DBI->errstr();
for (@table) {
$dbh->{po_tables}->{$_} = {file => "$_.po"};
}
# create the joined po file (table)
$dbh->do(<<"EOT");
CREATE TABLE $table[2]
(
msgid VARCHAR,
msgstr VARCHAR
)
EOT
# prepare to write the joined po file (table)
my $sth_insert = $dbh->prepare(<<"EOT");
INSERT INTO $table[2]
(msgid, msgstr)
VALUES (?, ?)
EOT
# build and write the header of the joined po file (table)
$sth_insert->execute(
q{},
$dbh->func(
undef, # minimized
'build_header_msgstr', # function name
),
);
# require joined data
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();
# get the joined data
while ( my @data = $sth_select->fetchrow_array() ) {
$sth_insert->execute(@data);
}
# all done
$dbh->disconnect();
lib/DBD/PO.pm view on Meta::CPAN
character is alphabetic, followed by an arbitrary number of alphanumeric
characters. If you want to use other files, the file names must start
with '/', './' or '../' and they must not contain white space.
For conditional execution use CREATE TABLE IF EXISTS statement.
Columns:
=over 14
=item * msgid
The text to translate (emty string for header).
The 'msgid' can contain Locale::Maketext placeholders.
They have to be stored in gettext format.
To change the format, use the database handle function 'maketext_to_gettext'.
=item * msgstr
The translation.
The 'msgid' can contain Locale::Maketext placeholder.
They have to be stored in gettext format.
To change the format, use the database handle function 'maketext_to_gettext'.
=item * comment
The translator comment text concatinated by 'po_separator'.
=item * automatic
The automatic comment text concatinated by 'po_separator'.
lib/DBD/PO.pm view on Meta::CPAN
There are c-format, php-format and so on, see L<DBD::PO::Locale::PO>.
To use these format flags call
C<DBD::PO->init(qw(c-format php-format ...);>
or C<DBD::PO->init(':format');>
or C<DBD::PO->init(':all');> early.
Flag, not set (0), set (1) or negative set (-1).
=item * msgid_plural
The same like msgid but for plural.
To use these format flags call
C<DBD::PO->init(':plural');>
or C<DBD::PO->init(':all');> early.
=item * msgstr_0 .. msgstr_5
Insted of msgstr for plural item 0 .. 5.
To use these format flags call
lib/DBD/PO.pm view on Meta::CPAN
or C<DBD::PO->init(':all');> early.
=item * previous_msgctxt
As comment formatted former msgctxt.
To use these format flags call
C<DBD::PO->init(':previous');>
or C<DBD::PO->init(':all');> early.
=item * previous_msgid
As comment formatted former msgid.
To use these format flags call
C<DBD::PO->init(':previous');>
or C<DBD::PO->init(':all');> early.
=item * previous_msgid_plural
As comment formatted former msgid_plural.
To use these format flags call
C<DBD::PO->init(':previous');>
or C<DBD::PO->init(':all');> early.
=back
..._format, msgid_plural, msgstr_0 .. msgstr_5 and previous_...
are normally switched off.
See method init.
$dbh->do(<<'EOT');
CREATE TABLE
table.po (
msgid VARCHAR,
msgstr VARCHAR,
comment VARCHAR,
automatic VARCHAR,
reference VARCHAR,
msgctxt VARCHAR,
fuzzy INTEGER,
obsolete INTEGER,
..._format INTEGER,
msgid_plural VARCHAR,
msgstr_0 VARCHAR,
msgstr_1 VARCHAR,
msgstr_2 VARCHAR,
msgstr_3 VARCHAR,
msgstr_4 VARCHAR,
msgstr_5 VARCHAR,
previous_msgctxt VARCHAR,
previous_msgid VARCHAR,
previous_msgid_plural VARCHAR
)
EOT
=head2 write the header
=head3 build msgstr
The charset will set to the as parameter 'po_charset' given value
at the connect method.
Note that the default encoding is nothing, not 'utf-8'.
lib/DBD/PO.pm view on Meta::CPAN
undef,
# function name
'build_header_msgstr',
);
=head4 full example
my $header_msgstr = $dbh->func(
{
'Project-Id-Version' => 'Project name',
'Report-Msgid-Bugs-To-Name' => 'Bug Reporter',
'Report-Msgid-Bugs-To-Mail' => 'report.msgid.bugs.to@example.org',
'POT-Creation-Date' => 'the POT creation date',
'PO-Revision-Date' => 'the PO revision date',
'Last-Translator-Name' => 'Steffen Winkler',
'Last-Translator-Mail' => 'steffenw@example.org',
'Language-Team-Name' => 'MyTeam',
'Language-Team-Mail' => 'cpan@example.org',
# Do not set the following values.
# They will be set automaticly.
'MIME-Version' => '1.0',
'Content-Type' => 'text/plain',
lib/DBD/PO.pm view on Meta::CPAN
msgstr
) VALUES (?, ?)
EOT
=head2 write a row
=head2 without Locale::Maketext placeholders
my $sth = $dbh->prepare(<<'EOT');
INSERT INTO table.po (
msgid,
msgstr,
reference
) VALUES (?, ?, ?)
EOT
$sth->execute(
join(
$separator,
'text to translate',
'2nd line of text',
lib/DBD/PO.pm view on Meta::CPAN
$separator,
'my_program: 17',
'my_program: 269',
),
);
=head2 with Locale::Maketext placeholders
my $sth = $dbh->prepare(<<'EOT');
INSERT INTO table.po (
msgid,
msgstr,
reference
) VALUES (?, ?, ?)
EOT
$sth->execute(
$dbh->func(
# mapping:
# - scalar to scalar
# - or array to array
lib/DBD/PO.pm view on Meta::CPAN
[qw(charset Project-Id-Version)],
'get_header_msgstr_data',
);
my ($charset, $project_id_version) = @{$array_ref};
=head2 read a row
$sth = $dbh->prepare(<<'EOT');
SELECT msgstr
FROM table.po
WHERE msgid = ?
EOT
$sth->execute(
join(
$separator,
'text to translate',
'2nd line of text',
),
);
my ($msgstr) = $sth->fetchrow_array();
=head2 update rows
$dbh->do(<<'EOT');
UPDATE table.po
SET msgstr = '',
fuzzy = 1
WHERE msgid = 'my_id'
EOT
=head2 delete rows
$dbh->do(<<'EOT');
DELETE FROM table.po
WHERE obsolete = 1
EOT
=head2 drop table
lib/DBD/PO.pm view on Meta::CPAN
$dbh->disconnect();
=head2 dot's in file suffix and SQL
In case of join tables, SQL::Statement does not allow a file suffix.
File suffix can be used here:
SELECT msgstr
FROM de.po
WHERE msgid <> ''
But not here:
SELECT de.po.msgstr, ru.po.msgstr
FROM de.po
INNER JOIN ru.po
ON de.po.msgid = ru.po.msgid
WHERE de.po.msgid <> ''
Set a mapping hash like:
$dbh->{po_tables}->{'de'} = {file => 'de.po'};
$dbh->{po_tables}->{'ru'} = {file => 'ru.po'};
Do not write the suffix now:
SELECT de.msgstr, ru.msgstr
FROM de
INNER JOIN ru
ON de.msgid = ru.msgid
WHERE de.msgid <> ''
or the same here:
SELECT msgstr
FROM de
WHERE msgid <> ''
=head1 DESCRIPTION
The DBD::PO module is yet another driver for the DBI
(Database independent interface for Perl).
This one is based on the SQL 'engine' SQL::Statement
and the abstract DBI driver DBD::File and implements access to
so-called PO files (GNU gettext).
Such files are readable by Locale::Maketext.
lib/DBD/PO/Locale/PO.pm view on Meta::CPAN
our $ALLOW_LOST_BLANK_LINES = 1;
sub new {
my ($this, %options) = @_;
my $class = ref $this || $this;
my $self = bless {}, $class;
$self->eol( $options{eol} );
$self->_flags({});
for (qw(
msgctxt msgid msgid_plural
previous_msgctxt previous_msgid previous_msgid_plural
msgstr msgstr_n
comment automatic reference fuzzy obsolete
loaded_line_number
)) {
if ( defined $options{"-$_"} ) {
$self->$_( $options{"-$_"} );
}
}
for my $format (@FORMAT_FLAGS) {
if ( defined $options{"-$format"} ) {
lib/DBD/PO/Locale/PO.pm view on Meta::CPAN
$self->{eol} = $eol;
}
return defined $self->{eol}
? $self->{eol}
: "\n";
}
# create methods
for (qw(
msgctxt msgid msgid_plural
previous_msgctxt previous_msgid previous_msgid_plural
msgstr
comment automatic reference obsolete
_flags loaded_line_number
)) {
my $name = $_;
no strict 'refs'; ## no critic (NoStrict)
*{$name} = sub {
my ($self, @params) = @_;
return @params
lib/DBD/PO/Locale/PO.pm view on Meta::CPAN
}
my $flags = join q{}, map {", $_"} sort keys %{ $self->_flags() };
if ($flags) {
$dump .= "#$flags"
. $self->eol();
}
if ( defined $self->previous_msgctxt() ) {
$dump .= '#| msgctxt '
. $self->quote( $self->previous_msgctxt() );
}
if ( defined $self->previous_msgid() ) {
$dump .= '#| msgid '
. $self->quote( $self->previous_msgid() );
}
if ( defined $self->previous_msgid_plural() ) {
$dump .= '#| msgid_plural '
. $self->quote( $self->previous_msgid_plural() );
}
if ( defined $self->msgctxt() ) {
$dump .= "${obsolete}msgctxt "
. $self->quote( $self->msgctxt() );
}
$dump .= "${obsolete}msgid "
. $self->quote( $self->msgid() );
if ( defined $self->msgid_plural() ) {
$dump .= "${obsolete}msgid_plural "
. $self->quote( $self->msgid_plural() );
}
if ( defined $self->msgstr() ) {
$dump .= "${obsolete}msgstr "
. $self->quote( $self->msgstr() );
}
if ( my $msgstr_n = $self->msgstr_n() ) {
$dump .= join
q{},
map {
"${obsolete}msgstr[$_] "
lib/DBD/PO/Locale/PO.pm view on Meta::CPAN
my $po = $self->load_entry(
$file_name,
$file_handle,
\$line_number,
$eol,
)
) {
# ashash
if ($ashash) {
if ( $po->_hash_key_ok(\%entries) ) {
$entries{ $po->msgid() } = $po;
}
}
# asarray
else {
push @entries, $po;
}
}
return $ashash
? \%entries
lib/DBD/PO/Locale/PO.pm view on Meta::CPAN
$line =~ s{\Q$eol\E \z}{}xms;
my $line_number = ++${$line_number_ref};
my ($obsolete, $key, $value);
# Empty line. End of an entry.
if ( $line =~ m{\A \s* \z}xms ) { ## no critic (CascadingIfElse)
last LINE if $po;
}
# strings
elsif (
($obsolete, $key, $value)
= $line =~ m{\A ( \# ~ \s+ )? ( msgctxt | msgid | msgid_plural | msgstr ) \s+ (.*)}xms
) {
last LINE if $is_new_entry->($key);
$po ||= $class->new(eol => $eol, -loaded_line_number => $line_number);
$buffer{$key} = $self->dequote($value, $eol);
$current_buffer = \$buffer{$key};
if ($obsolete) {
$po->obsolete(1);
}
}
# contined string
lib/DBD/PO/Locale/PO.pm view on Meta::CPAN
$po ||= $class->new(eol => $eol, -loaded_line_number => $line_number);
$po->automatic(
defined $po->automatic()
? $po->automatic() . "$eol$value"
: $value
);
}
# previous
elsif (
($key, $value)
= $line =~ m{\A \# \| \s+ ( msgctxt | msgid | msgid_plural ) \s+ (.*)}xms
) {
last LINE if $is_new_entry->('comment');
$po ||= $class->new(eol => $eol, -loaded_line_number => $line_number);
$key = "previous_$key";
$buffer{$key} = $self->dequote($value, $eol);
$current_buffer = \$buffer{$key};
}
else {
warn "Strange line at $file_name line $line_number: $line\n";
}
$safe_current_position->();
}
if ($po) {
for my $key (qw(
msgctxt msgid msgid_plural
previous_msgctxt previous_msgid previous_msgid_plural
msgstr msgstr_n
)) {
if ( defined $buffer{$key} ) {
$po->$key( $buffer{$key} );
}
}
return $po;
}
return; # no entry found
}
sub _hash_key_ok {
my ($self, $entries) = @_;
my $key = $self->msgid();
if ($entries->{$key}) {
# don't overwrite non-obsolete entries with obsolete ones
return if $self->obsolete() && ! $entries->{$key}->obsolete();
# don't overwrite translated entries with untranslated ones
return if $self->msgstr() !~ m{\w}xms
&& $entries->{$key}->msgstr() =~ m{\w}xms;
}
return 1;
lib/DBD/PO/Locale/PO.pm view on Meta::CPAN
=head1 SYNOPSIS
require DBD::PO::Locale::PO;
$po = DBD::PO::Locale::PO->new([eol => $eol, ['-option' => 'value', ...]])
[$string =] $po->comment(['new string']);
[$string =] $po->automatic(['new string']);
[$string =] $po->reference(['new string']);
[$string =] $po->msgctxt(['new string']);
[$string =] $po->previous_msgctxt(['new string']);
[$string =] $po->msgid(['new string']);
[$string =] $po->previous_msgid(['new string']);
[$string =] $po->msgid_plural(['new string']);
[$string =] $po->previous_msgid_plural(['new string']);
[$string =] $po->msgstr(['new string']);
[$string =] $po->msgstr_n([{0 => 'new string', 1 => ...}]);
[$boolean =] $po->obsolete([$boolean]);
[$value =] $po->fuzzy([value]);
[$value =] $po->add_flag('c-format');
[$value =] $po->add_flag('...-format');
print $po->dump();
$quoted_string = $po->quote($string);
$string = $po->dequote($quoted_string);
lib/DBD/PO/Locale/PO.pm view on Meta::CPAN
Specify an eol or accept the default "\n".
eol => "\r\n"
Create a new DBD::PO::Locale::PO object to represent a po entry.
You can optionally set the attributes of the entry by passing
a list/hash of the form:
'-option' => 'value', '-option' => 'value', etc.
Where options are msgid, msgid_plural, msgstr, msgstr_n, msgctxt,
comment, automatic, reference, obsolete, fuzzy. See accessor methods below.
To generate a po file header, add an entry with an empty
msgid, like this:
$po = DBD::PO::Locale::PO->new(
'-msgid' => q{},
'-msgstr' =>
"Project-Id-Version: PACKAGE VERSION\n"
. "PO-Revision-Date: YEAR-MO-DA HO:MI +ZONE\n"
. "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
. "Language-Team: LANGUAGE <LL@li.org>\n"
. "MIME-Version: 1.0\n"
. "Content-Type: text/plain; charset=CHARSET\n"
. "Content-Transfer-Encoding: ENCODING\n",
);
=item method eol
Set or get the eol string from the object.
=item method msgid
Set or get the untranslated string from the object.
This method expects the new string in unquoted form
but returns the current string in quoted form.
=item method previous_msgid
Like before but the previous one.
=item method msgid_plural
Set or get the untranslated plural string from the object.
This method expects the new string in unquoted form
but returns the current string in quoted form.
=item method previous_msgid_plural
Like before but the previous one.
=item method msgstr
Set or get the translated string from the object.
This method expects the new string in unquoted form
but returns the current string in quoted form.
lib/DBD/PO/Locale/PO.pm view on Meta::CPAN
This method expects the new string in unquoted form
but returns the current string in quoted form.
=item method previous_msgctxt
Like before but the previous one.
=item method obsolete
Returns 1 if the entry is obsolete.
Obsolete entries have their msgid, msgid_plural, msgstr, msgstr_n and msgctxt
lines commented out with "#~"
When using load_file_ashash, non-obsolete entries
will always replace obsolete entries with the same msgid.
=item method comment
Set or get translator comments from the object.
If there are no such comments, then the value is undef.
Otherwise, the value is a string
that contains the comment lines delimited with "\n".
The string includes neither the S<"# "> at the beginning of
each comment line nor the newline at the end of the last comment line.
lib/DBD/PO/Locale/PO.pm view on Meta::CPAN
=head1 INCOMPATIBILITIES
not known
=head1 BUGS AND LIMITATIONS
If you load_file_as* then save_file_from*, the output file may have slight
cosmetic differences from the input file (an extra blank line here or there).
(And the quoting of binary values can be changed, but all this is not a Bug.)
msgid, msgid_plural, msgstr, msgstr_n and msgctxt
expect a non-quoted string as input, but return quoted strings.
The maintainer of Locale::PO was hesitant to change this in fear
of breaking the modules/scripts of people already using Locale::PO.
(Fixed in DBD::PO::Locale::PO)
Locale::PO requires blank lines between entries,
but Uniforum style PO files don't have any. (Fixed)
=head1 SEE ALSO
lib/DBD/PO/Text/PO.pm view on Meta::CPAN
$config->delete(':previous');
if ( $config->has(':format') ) {
$config->delete(':format');
$config->insert(@FORMAT_FLAGS);
}
$ALLOW_LOST_BLANK_LINES = $config->has('allow_lost_blank_lines');
$config->delete('allow_lost_blank_lines');
my @cols = (
# typical
[ qw( msgid -msgid msgid ) ], # original text
[ qw( msgstr -msgstr msgstr ) ], # translation
[ qw( comment -comment comment ) ], # translater comment
[ qw( automatic -automatic automatic ) ], # automatic comment
[ qw( reference -reference reference ) ],
[ qw( msgctxt -msgctxt msgctxt ) ], # context
# flags
[ qw( fuzzy -fuzzy fuzzy ) ],
# switch to ignore
[ qw( obsolete -obsolete obsolete ) ],
# plural only
(
$has_plural
? (
[ qw( msgid_plural -msgid_plural msgid_plural ) ],
# dummy # dummy
[ qw( msgstr_0 -msgstr_0 msgstr_0 ) ], # singular or zero
[ qw( msgstr_1 -msgstr_1 msgstr_1 ) ], # plural or singular
[ qw( msgstr_2 -msgstr_2 msgstr_2 ) ], # plural
[ qw( msgstr_3 -msgstr_3 msgstr_3 ) ], # plural
[ qw( msgstr_4 -msgstr_4 msgstr_4 ) ], # plural
[ qw( msgstr_5 -msgstr_5 msgstr_5 ) ], # plural
)
: ()
),
# prevoius
(
$has_previous
? (
[ qw( previous_msgctxt -previous_msgctxt previous_msgctxt ) ],
[ qw( previous_msgid -previous_msgid previous_msgid ) ],
[ qw( previous_msgid_plural -previous_msgid_plural previous_msgid_plural ) ],
)
: ()
),
# format-flags
(
map { ## no critic (ComplexMappings)
(my $col_name = $_) =~ tr{-}{_};
# dummy
([ $col_name, "-$_", $_ ]);
} $config->elements()
lib/DBD/PO/Text/PO.pm view on Meta::CPAN
}
elsif ( $parameter =~ m{\A -msgstr_ ( \d ) \z}xms ) {
if ( @{$values} ) {
$line{'-msgstr_n'}->{$1} = join "\n", @{$values};
}
}
else {
if ( @{$values} ) {
$line{$parameter} = join "\n", @{$values};
if (! tell $file_handle) {
if ($parameter eq '-msgid') {
croak 'A header has no msgid';
}
else { # -msgstr
if ($line{$parameter} !~ m{\b charset =}xms) { ## no critic (DeepNests)
croak 'This can not be a header';
}
}
}
}
else {
if ($parameter eq '-msgid' && tell $file_handle) {
croak 'A line has to have a msgid';
}
elsif ($parameter eq '-msgstr' && ! tell $file_handle) {
croak 'A header has to have a msgstr';
}
}
}
++$index;
}
my $line = DBD::PO::Locale::PO->new(
eol => $self->{eol},
'-msgid' => q{},
(
exists $line{'-msgid_plural'}
? ('-msgstr_n' => { 0 => q{} })
: ('-msgstr' => q{})
),
%line,
)->dump();
print {$file_handle} $line
or croak "Print $file_name: $OS_ERROR";
return $self;
}
lib/DBD/PO/db.pm view on Meta::CPAN
use SQL::Parser;
use DBD::PO::Locale::PO;
use DBD::PO::Text::PO qw($EOL_DEFAULT $SEPARATOR_DEFAULT $CHARSET_DEFAULT);
our $imp_data_size = 0; ## no critic (PackageVars)
my (@HEADER_KEYS, @HEADER_FORMATS, @HEADER_DEFAULTS, @HEADER_REGEX);
{
my @header = (
[ project_id_version => 'Project-Id-Version: %s' ],
[ report_msgid_bugs_to => 'Report-Msgid-Bugs-To: %s <%s>' ],
[ pot_creation_date => 'POT-Creation-Date: %s' ],
[ po_revision_date => 'PO-Revision-Date: %s' ],
[ last_translator => 'Last-Translator: %s <%s>' ],
[ language_team => 'Language-Team: %s <%s>' ],
[ mime_version => 'MIME-Version: %s' ],
[ content_type => 'Content-Type: %s; charset=%s' ],
[ content_transfer_encoding => 'Content-Transfer-Encoding: %s' ],
[ plural_forms => 'Plural-Forms: %s' ],
[ extended => '%s: %s' ],
);
lib/DBD/PO/db.pm view on Meta::CPAN
undef,
'1.0',
['text/plain', undef],
'8bit',
undef,
undef,
);
@HEADER_REGEX = (
qr{\A \QProject-Id-Version:\E \s* (.*) \s* \z}xmsi,
[
qr{\A \QReport-Msgid-Bugs-To:\E \s* ([^<]*) \s+ < ([^>]*) > \s* \z}xmsi,
qr{\A \QReport-Msgid-Bugs-To:\E \s* (.*) () \s* \z}xmsi,
],
qr{\A \QPOT-Creation-Date:\E \s* (.*) \s* \z}xmsi,
qr{\A \QPO-Revision-Date:\E \s* (.*) \s* \z}xmsi,
[
qr{\A \QLast-Translator:\E \s* ([^<]*) \s+ < ([^>]*) > \s* \z}xmsi,
qr{\A \QLast-Translator:\E \s* (.*) () \s* \z}xmsi,
],
[
qr{\A \QLanguage-Team:\E \s* ([^<]*) \s+ < ([^>]*) > \s* \z}xmsi,
qr{\A \QLanguage-Team:\E \s* (.*) () \s* \z}xmsi,
lib/DBD/PO/db.pm view on Meta::CPAN
}
return $is_quoted
? "'_Q_U_O_T_E_D_:$string'"
: "'$string'";
}
## no critic (MagicNumbers)
my %hash2array = (
'Project-Id-Version' => 0,
'Report-Msgid-Bugs-To-Name' => [1, 0],
'Report-Msgid-Bugs-To-Mail' => [1, 1],
'POT-Creation-Date' => 2,
'PO-Revision-Date' => 3,
'Last-Translator-Name' => [4, 0],
'Last-Translator-Mail' => [4, 1],
'Language-Team-Name' => [5, 0],
'Language-Team-Mail' => [5, 1],
'MIME-Version' => 6,
'Content-Type' => [7, 0],
charset => [7, 1],
'Content-Transfer-Encoding' => 8,
lib/DBD/PO/db.pm view on Meta::CPAN
sub get_header_msgstr { ## no critic (ArgUnpacking)
my ($dbh, $hash_ref) = validate_pos(
@_,
{isa => 'DBI::db'},
{type => HASHREF},
);
my $sth = $dbh->prepare(<<"EOT") or croak $dbh->errstr();
SELECT msgstr
FROM $hash_ref->{table}
WHERE msgid = ''
EOT
$sth->execute()
or croak $sth->errstr();
my ($msgstr) = $sth->fetchrow_array()
or croak $sth->errstr();
$sth->finish()
or croak $sth->errstr();
return $msgstr;
}
t/01_Locale-PO/01_quote.t view on Meta::CPAN
ok(
$file->open(
$FILE_LOCALE_PO_01,
'> :encoding(utf-8)',
),
'open file',
);
my $po = DBD::PO::Locale::PO->new(
'-msgid' => 'test',
'-msgstr' => $test_string,
);
isa_ok($po, 'DBD::PO::Locale::PO');
ok(
$file->print( $po->dump() ),
'print file',
);
}
# check_table_file
{
my $po = <<"EOT";
msgid "test"
msgstr $po_string
EOT
local $INPUT_RECORD_SEPARATOR = ();
open my $file1,
'< :encoding(utf-8)',
$FILE_LOCALE_PO_01 or croak $OS_ERROR;
my $content1 = <$file1>;
open my $file2, '< :encoding(utf-8)', \($po) or croak $OS_ERROR;
my $content2 = <$file2>;
t/01_Locale-PO/01_quote.t view on Meta::CPAN
ok(
$file->open(
$FILE_LOCALE_PO_01,
'< :encoding(utf-8)',
),
'open file',
);
my $array = DBD::PO::Locale::PO->load_file_asarray($file);
my $po = $array->[0];
isa_ok($po, 'DBD::PO::Locale::PO');
eq_or_diff($po->msgid(), 'test', 'msgid');
eq_or_diff($po->msgstr(), $test_string, 'msgstr');
}
# drop table
SKIP: {
skip('delete file', 1)
if ! $DROP_TABLE;
unlink $FILE_LOCALE_PO_01;
ok(! -e $FILE_LOCALE_PO_01, 'table file deleted');
t/01_Locale-PO/02_without_emty_lines.t view on Meta::CPAN
{
open my $file, '> :encoding(utf-8)', $FILE_LOCALE_PO_02;
isnt(
$OS_ERROR,
q{},
'open file',
);
for (1 .. 2) {
my $po = DBD::PO::Locale::PO->new(
'-msgid' => "id $_",
'-msgstr' => "str $_",
);
isa_ok($po, 'DBD::PO::Locale::PO');
my $dump = $po->dump();
chomp $dump;
ok(
print($file $dump),
'print file',
);
}
}
# check_table_file
{
my $po = <<'EOT';
msgid "id 1"
msgstr "str 1"
msgid "id 2"
msgstr "str 2"
EOT
local $INPUT_RECORD_SEPARATOR = ();
open my $file1,
'< :encoding(utf-8)',
$FILE_LOCALE_PO_02 or croak $OS_ERROR;
my $content1 = <$file1>;
open my $file2, '< :encoding(utf-8)', \($po) or croak $OS_ERROR;
my $content2 = <$file2>;
eq_or_diff($content1, $content2, 'check po file');
t/01_Locale-PO/02_without_emty_lines.t view on Meta::CPAN
$FILE_LOCALE_PO_02,
$file,
\$line_number,
);
isa_ok($po, 'DBD::PO::Locale::PO');
is(
$po->loaded_line_number(),
{1 => 1, 2 => 3}->{$_},
'loaded_line_number',
);
eq_or_diff($po->msgid(), "id $_", 'msgid');
eq_or_diff($po->msgstr(), "str $_", 'msgstr');
}
}
# drop table
SKIP: {
skip('delete file', 1)
if ! $DROP_TABLE;
unlink $FILE_LOCALE_PO_02;
t/02_Text-PO/01_quote.t view on Meta::CPAN
[
'id',
$test_string,
],
);
}
# check_table_file
{
my $po = <<"EOT";
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8"
msgid "id"
msgstr $po_string
EOT
local $INPUT_RECORD_SEPARATOR = ();
open my $file1,
'< :encoding(utf-8)',
$FILE_TEXT_PO or croak $OS_ERROR;
my $content1 = <$file1>;
open my $file2, '< :encoding(utf-8)', \($po) or croak $OS_ERROR;
my $content2 = <$file2>;
t/03_DBD-PO/01_create_table.t view on Meta::CPAN
}
my $result = $dbh->do(<<"EO_SQL");
CREATE TABLE $TABLE_0X (
comment VARCHAR,
automatic VARCHAR,
reference VARCHAR,
obsolete INTEGER,
fuzzy INTEGER,
msgctxt VARCHAR,
msgid VARCHAR,
msgstr VARCHAR
)
EO_SQL
is($result, '0E0', 'create table');
ok(-e $TABLE_0X, 'table file found');
my @parameters = (
join(
$SEPARATOR,
qw(
t/03_DBD-PO/01_create_table.t view on Meta::CPAN
msgstr
) VALUES (?, ?)
EO_SQL
is($result, 1, 'insert header');
# check table file
{
my $po = <<'EOT';
# comment1
# comment2
msgid ""
msgstr ""
"Project-Id-Version: Testproject\n"
"Report-Msgid-Bugs-To: Bug Reporter <bug@example.org>\n"
"POT-Creation-Date: no POT creation date\n"
"PO-Revision-Date: no PO revision date\n"
"Last-Translator: Steffen Winkler <steffenw@example.org>\n"
"Language-Team: MyTeam <cpan@example.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Poedit-Language: German\n"
"X-Poedit-Country: GERMANY\n"
"X-Poedit-SourceCharset: utf-8"
t/03_DBD-PO/02_fill_table.t view on Meta::CPAN
if ($TRACE) {
open my $file, '>', trace_file_name();
$dbh->trace(4, $file);
}
}
# full row
{
$sth = $dbh->prepare(<<"EO_SQL");
INSERT INTO $TABLE_0X (
msgid,
msgstr,
msgctxt,
reference,
comment,
automatic
) VALUES (?, ?, ?, ?, ?, ?)
EO_SQL
isa_ok($sth, 'DBI::st', 'prepare insert');
my $result = $sth->execute(qw(
t/03_DBD-PO/02_fill_table.t view on Meta::CPAN
"ref_value1${SEPARATOR}ref_value2",
"comment_value1${SEPARATOR}comment_value2",
"automatic_value1${SEPARATOR}automatic_value2",
);
is($result, 1, "insert full row, all are arrays");
}
# minimized row
{
my $result = $dbh->do(<<"EO_SQL", undef, 'id_value_mini');
INSERT INTO $TABLE_0X (msgid) VALUES (?)
EO_SQL
is($result, 1, "insert minimized row");
}
# typical rows
{
$sth = $dbh->prepare(<<"EO_SQL");
INSERT INTO $TABLE_0X (msgid, msgstr) VALUES (?, ?)
EO_SQL
isa_ok($sth, 'DBI::st', 'prepare insert');
for (1 .. 2) {
my $result = $sth->execute("id_$_", "str_$_");
is($result, 1, "insert row $_");
}
}
# plural rows
{
$sth = $dbh->prepare(<<"EO_SQL");
INSERT INTO $TABLE_0X (msgid, msgid_plural, msgstr_0, msgstr_1)
VALUES (?, ?, ?, ? )
EO_SQL
isa_ok($sth, 'DBI::st', 'prepare insert');
my $result = $sth->execute(
'id_singular',
'id_plural',
'str_singular',
'str_plural',
);
t/03_DBD-PO/02_fill_table.t view on Meta::CPAN
"id_plural1${SEPARATOR}id_plural2",
"str_singular1${SEPARATOR}str_singular2",
"str_plural1${SEPARATOR}str_plural2",
);
is($result, 1, 'insert row, plural, multi line');
}
# minimized plural row
{
my $result = $dbh->do(<<"EO_SQL", undef, qw(id_value_singular_mini id_value_plural_mini) );
INSERT INTO $TABLE_0X (msgid, msgid_plural) VALUES (?, ?)
EO_SQL
is($result, 1, "insert minimized plural row");
}
# check table file
{
my $po = <<'EOT';
# comment1
# comment2
msgid ""
msgstr ""
"Project-Id-Version: Testproject\n"
"Report-Msgid-Bugs-To: Bug Reporter <bug@example.org>\n"
"POT-Creation-Date: no POT creation date\n"
"PO-Revision-Date: no PO revision date\n"
"Last-Translator: Steffen Winkler <steffenw@example.org>\n"
"Language-Team: MyTeam <cpan@example.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Poedit-Language: German\n"
"X-Poedit-Country: GERMANY\n"
"X-Poedit-SourceCharset: utf-8"
# comment_value
#. automatic_value
#: ref_value
msgctxt "context_value"
msgid "id_value"
msgstr "str_value"
# comment_value1
# comment_value2
#. automatic_value1
#. automatic_value2
#: ref_value1
#: ref_value2
msgctxt ""
"context_value1\n"
"context_value2"
msgid ""
"id_value1\n"
"id_value2"
msgstr ""
"str_value1\n"
"str_value2"
msgid "id_value_mini"
msgstr ""
msgid "id_1"
msgstr "str_1"
msgid "id_2"
msgstr "str_2"
msgid "id_singular"
msgid_plural "id_plural"
msgstr[0] "str_singular"
msgstr[1] "str_plural"
msgid ""
"id_singular1\n"
"id_singular2"
msgid_plural ""
"id_plural1\n"
"id_plural2"
msgstr[0] ""
"str_singular1\n"
"str_singular2"
msgstr[1] ""
"str_plural1\n"
"str_plural2"
msgid "id_value_singular_mini"
msgid_plural "id_value_plural_mini"
msgstr[0] ""
EOT
open my $file, '< :raw', $FILE_0X or croak $OS_ERROR;
local $INPUT_RECORD_SEPARATOR = ();
my $content = <$file>;
$po =~ s{\n}{$EOL}xmsg;
eq_or_diff($content, $po, 'check po file');
}
t/03_DBD-PO/03_check_table.t view on Meta::CPAN
if ($TRACE) {
open my $file, '>', trace_file_name();
$dbh->trace(4, $file);
}
}
# check table
{
my $sth = $dbh->prepare(<<"EO_SQL");
SELECT msgid, msgstr
FROM $TABLE_0X
WHERE msgid=?
EO_SQL
isa_ok($sth, 'DBI::st');
my @data = (
{
id => 'id_2',
_id => 'id_2',
result => 1,
fetch => [
{
msgid => 'id_2',
msgstr => 'str_2',
},
],
},
{
id => "id_value1${SEPARATOR}id_value2",
_id => "id_value1\${separator}id_value2",
result => 1,
fetch => [
{
msgid => "id_value1${SEPARATOR}id_value2",
msgstr => "str_value1${SEPARATOR}str_value2",
},
],
},
);
for my $data (@data) {
my $result = $sth->execute($data->{id});
is($result, $data->{result}, "execute: $data->{_id}");
t/03_DBD-PO/03_check_table.t view on Meta::CPAN
"fetch result: $data->{_id}",
);
}
}
# check table file
{
my $po = <<'EOT';
# comment1
# comment2
msgid ""
msgstr ""
"Project-Id-Version: Testproject\n"
"Report-Msgid-Bugs-To: Bug Reporter <bug@example.org>\n"
"POT-Creation-Date: no POT creation date\n"
"PO-Revision-Date: no PO revision date\n"
"Last-Translator: Steffen Winkler <steffenw@example.org>\n"
"Language-Team: MyTeam <cpan@example.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Poedit-Language: German\n"
"X-Poedit-Country: GERMANY\n"
"X-Poedit-SourceCharset: utf-8"
# comment_value
#. automatic_value
#: ref_value
msgctxt "context_value"
msgid "id_value"
msgstr "str_value"
# comment_value1
# comment_value2
#. automatic_value1
#. automatic_value2
#: ref_value1
#: ref_value2
msgctxt ""
"context_value1\n"
"context_value2"
msgid ""
"id_value1\n"
"id_value2"
msgstr ""
"str_value1\n"
"str_value2"
msgid "id_value_mini"
msgstr ""
msgid "id_1"
msgstr "str_1"
msgid "id_2"
msgstr "str_2"
msgid "id_singular"
msgid_plural "id_plural"
msgstr[0] "str_singular"
msgstr[1] "str_plural"
msgid ""
"id_singular1\n"
"id_singular2"
msgid_plural ""
"id_plural1\n"
"id_plural2"
msgstr[0] ""
"str_singular1\n"
"str_singular2"
msgstr[1] ""
"str_plural1\n"
"str_plural2"
msgid "id_value_singular_mini"
msgid_plural "id_value_plural_mini"
msgstr[0] ""
EOT
open my $file, '< :raw', $FILE_0X or croak $OS_ERROR;
local $INPUT_RECORD_SEPARATOR = ();
my $content = <$file>;
$po =~ s{\n}{$EOL}xmsg;
eq_or_diff($content, $po, 'check po file');
}
t/03_DBD-PO/04_change_table.t view on Meta::CPAN
open my $file, '>', trace_file_name();
$dbh->trace(4, $file);
}
}
# change table
{
my $result = $dbh->do(<<"EO_SQL", undef, qw(str_1u id_1));
UPDATE $TABLE_0X
SET msgstr=?
WHERE msgid=?
EO_SQL
is($result, 1, 'update row 1');
my $sth = $dbh->prepare(<<"EO_SQL");
SELECT msgid, msgstr
FROM $TABLE_0X
WHERE msgid=?
EO_SQL
isa_ok($sth, 'DBI::st', 'prepare');
$result = $sth->execute('id_1');
is($result, 1, 'execute');
$result = $sth->fetchrow_arrayref();
is_deeply($result, [qw(id_1 str_1u)], 'fetch result');
}
# check table file
{
my $po = <<'EOT';
# comment1
# comment2
msgid ""
msgstr ""
"Project-Id-Version: Testproject\n"
"Report-Msgid-Bugs-To: Bug Reporter <bug@example.org>\n"
"POT-Creation-Date: no POT creation date\n"
"PO-Revision-Date: no PO revision date\n"
"Last-Translator: Steffen Winkler <steffenw@example.org>\n"
"Language-Team: MyTeam <cpan@example.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Poedit-Language: German\n"
"X-Poedit-Country: GERMANY\n"
"X-Poedit-SourceCharset: utf-8"
# comment_value
#. automatic_value
#: ref_value
msgctxt "context_value"
msgid "id_value"
msgstr "str_value"
# comment_value1
# comment_value2
#. automatic_value1
#. automatic_value2
#: ref_value1
#: ref_value2
msgctxt ""
"context_value1\n"
"context_value2"
msgid ""
"id_value1\n"
"id_value2"
msgstr ""
"str_value1\n"
"str_value2"
msgid "id_value_mini"
msgstr ""
msgid "id_1"
msgstr "str_1u"
msgid "id_2"
msgstr "str_2"
msgid "id_singular"
msgid_plural "id_plural"
msgstr[0] "str_singular"
msgstr[1] "str_plural"
msgid ""
"id_singular1\n"
"id_singular2"
msgid_plural ""
"id_plural1\n"
"id_plural2"
msgstr[0] ""
"str_singular1\n"
"str_singular2"
msgstr[1] ""
"str_plural1\n"
"str_plural2"
msgid "id_value_singular_mini"
msgid_plural "id_value_plural_mini"
msgstr[0] ""
EOT
open my $file, '< :raw', $FILE_0X or croak $OS_ERROR;
local $INPUT_RECORD_SEPARATOR = ();
my $content = <$file>;
$po =~ s{\n}{$EOL}xmsg;
eq_or_diff($content, $po, 'check po file');
}
t/03_DBD-PO/05_change_flags.t view on Meta::CPAN
open my $file, '>', trace_file_name();
$dbh->trace(4, $file);
}
}
# change header flags
{
my $sth_update = $dbh->prepare(<<"EO_SQL");
UPDATE $TABLE_0X
SET fuzzy=?
WHERE msgid=?
EO_SQL
isa_ok($sth_update, 'DBI::st', 'prepare update header');
my $sth_select = $dbh->prepare(<<"EO_SQL");
SELECT fuzzy
FROM $TABLE_0X
WHERE msgid=?
EO_SQL
isa_ok($sth_select, 'DBI::st', 'prepare select header');
my @data = (
{
test => 'header fuzzy=1',
set => 1,
get => [1],
callback => sub { check_file(shift, 'header_fuzzy') },
},
t/03_DBD-PO/05_change_flags.t view on Meta::CPAN
$data->{callback}->( $data->{test} );
}
}
# change flags
{
my $sth_update = $dbh->prepare(<<"EO_SQL");
UPDATE $TABLE_0X
SET fuzzy=?, c_format=?, php_format=?
WHERE msgid=?
EO_SQL
isa_ok($sth_update, 'DBI::st');
my $sth_select = $dbh->prepare(<<"EO_SQL");
SELECT fuzzy, c_format, php_format
FROM $TABLE_0X
WHERE msgid=?
EO_SQL
isa_ok($sth_select, 'DBI::st');
my @data = (
{
test => 'fuzzy=1',
set => [1, 0, 0],
get => [
{
fuzzy => 1,
t/03_DBD-PO/05_change_flags.t view on Meta::CPAN
my $flag = shift || q{};
my $po = <<'EOT';
# comment1
# comment2
EOT
$po .= <<'EOT' if $flag eq 'header_fuzzy';
#, fuzzy
EOT
$po .= <<'EOT';
msgid ""
msgstr ""
"Project-Id-Version: Testproject\n"
"Report-Msgid-Bugs-To: Bug Reporter <bug@example.org>\n"
"POT-Creation-Date: no POT creation date\n"
"PO-Revision-Date: no PO revision date\n"
"Last-Translator: Steffen Winkler <steffenw@example.org>\n"
"Language-Team: MyTeam <cpan@example.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Poedit-Language: German\n"
"X-Poedit-Country: GERMANY\n"
"X-Poedit-SourceCharset: utf-8"
# comment_value
#. automatic_value
#: ref_value
msgctxt "context_value"
msgid "id_value"
msgstr "str_value"
# comment_value1
# comment_value2
#. automatic_value1
#. automatic_value2
#: ref_value1
#: ref_value2
EOT
$po .= <<'EOT' if $flag eq 'fuzzy';
t/03_DBD-PO/05_change_flags.t view on Meta::CPAN
$po .= <<'EOT' if $flag eq 'no-php-format';
#, no-php-format
EOT
$po .= <<'EOT' if $flag eq 'all';
#, c-format, fuzzy, php-format
EOT
$po .= <<'EOT';
msgctxt ""
"context_value1\n"
"context_value2"
msgid ""
"id_value1\n"
"id_value2"
msgstr ""
"str_value1\n"
"str_value2"
msgid "id_value_mini"
msgstr ""
msgid "id_1"
msgstr "str_1u"
msgid "id_2"
msgstr "str_2"
msgid "id_singular"
msgid_plural "id_plural"
msgstr[0] "str_singular"
msgstr[1] "str_plural"
msgid ""
"id_singular1\n"
"id_singular2"
msgid_plural ""
"id_plural1\n"
"id_plural2"
msgstr[0] ""
"str_singular1\n"
"str_singular2"
msgstr[1] ""
"str_plural1\n"
"str_plural2"
msgid "id_value_singular_mini"
msgid_plural "id_value_plural_mini"
msgstr[0] ""
EOT
open my $file, '< :raw', $FILE_0X or croak $OS_ERROR;
local $INPUT_RECORD_SEPARATOR = ();
my $content = <$file>;
$po =~ s{\n}{$EOL}xmsg;
eq_or_diff($content, $po, "check po file: $test");
return;
t/03_DBD-PO/06_obsolete.t view on Meta::CPAN
open my $file, '>', trace_file_name();
$dbh->trace(4, $file);
}
}
# obsolete
{
my $sth_update = $dbh->prepare(<<"EO_SQL");
UPDATE $TABLE_0X
SET obsolete=?
WHERE msgid=?
EO_SQL
isa_ok($sth_update, 'DBI::st', 'prepare update');
my $sth_select = $dbh->prepare(<<"EO_SQL");
SELECT obsolete
FROM $TABLE_0X
WHERE msgid=?
EO_SQL
isa_ok($sth_select, 'DBI::st', 'prepare select');
my @data = (
{
test => 'obsolete=1, id_value1\nid_value2',
id => "id_value1${SEPARATOR}id_value2",
set => 1,
get => [1],
callback => sub { check_file(shift, 1, 0) },
t/03_DBD-PO/06_obsolete.t view on Meta::CPAN
}
}
# check table file
sub check_file {
my ($test, $obsolete1, $obsolete2) = @_;
my $po = <<'EOT';
# comment1
# comment2
msgid ""
msgstr ""
"Project-Id-Version: Testproject\n"
"Report-Msgid-Bugs-To: Bug Reporter <bug@example.org>\n"
"POT-Creation-Date: no POT creation date\n"
"PO-Revision-Date: no PO revision date\n"
"Last-Translator: Steffen Winkler <steffenw@example.org>\n"
"Language-Team: MyTeam <cpan@example.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Poedit-Language: German\n"
"X-Poedit-Country: GERMANY\n"
"X-Poedit-SourceCharset: utf-8"
# comment_value
#. automatic_value
#: ref_value
msgctxt "context_value"
msgid "id_value"
msgstr "str_value"
# comment_value1
# comment_value2
#. automatic_value1
#. automatic_value2
#: ref_value1
#: ref_value2
EOT
$po .= <<'EOT' if ! $obsolete1;
msgctxt ""
"context_value1\n"
"context_value2"
msgid ""
"id_value1\n"
"id_value2"
msgstr ""
"str_value1\n"
"str_value2"
EOT
$po .= <<'EOT' if $obsolete1;
#~ msgctxt ""
"context_value1\n"
"context_value2"
#~ msgid ""
"id_value1\n"
"id_value2"
#~ msgstr ""
"str_value1\n"
"str_value2"
EOT
$po .= <<'EOT';
msgid "id_value_mini"
msgstr ""
msgid "id_1"
msgstr "str_1u"
msgid "id_2"
msgstr "str_2"
msgid "id_singular"
msgid_plural "id_plural"
msgstr[0] "str_singular"
msgstr[1] "str_plural"
EOT
$po .= <<'EOT' if ! $obsolete2;
msgid ""
"id_singular1\n"
"id_singular2"
msgid_plural ""
"id_plural1\n"
"id_plural2"
msgstr[0] ""
"str_singular1\n"
"str_singular2"
msgstr[1] ""
"str_plural1\n"
"str_plural2"
EOT
$po .= <<'EOT' if $obsolete2;
#~ msgid ""
"id_singular1\n"
"id_singular2"
#~ msgid_plural ""
"id_plural1\n"
"id_plural2"
#~ msgstr[0] ""
"str_singular1\n"
"str_singular2"
#~ msgstr[1] ""
"str_plural1\n"
"str_plural2"
EOT
$po .= <<'EOT';
msgid "id_value_singular_mini"
msgid_plural "id_value_plural_mini"
msgstr[0] ""
EOT
open my $file, '< :raw', $FILE_0X or croak $OS_ERROR;
local $INPUT_RECORD_SEPARATOR = ();
my $content = <$file>;
$po =~ s{\n}{$EOL}xmsg;
eq_or_diff($content, $po, 'check po file');
}
t/03_DBD-PO/07_split_header_msgstr.t view on Meta::CPAN
if ($TRACE) {
open my $file, '>', trace_file_name();
$dbh->trace(4, $file);
}
}
my $sth = $dbh->prepare(<<"EO_SQL");
SELECT msgstr
FROM $TABLE_0X
WHERE msgid=''
EO_SQL
isa_ok($sth, 'DBI::st', 'prepare');
is(
$sth->execute(),
1,
'execute',
);
my ($msgstr) = $sth->fetchrow_array();
t/03_DBD-PO/08_previous.t view on Meta::CPAN
if ($TRACE) {
open my $file, '>', trace_file_name();
$dbh->trace(4, $file);
}
}
# previous
{
my $sth_update = $dbh->prepare(<<"EO_SQL");
UPDATE $TABLE_0X
SET previous_msgctxt=?,previous_msgid=?,previous_msgid_plural=?
WHERE msgid=?
EO_SQL
isa_ok($sth_update, 'DBI::st', 'prepare update');
my $sth_select = $dbh->prepare(<<"EO_SQL");
SELECT previous_msgctxt, previous_msgid, previous_msgid_plural
FROM $TABLE_0X
WHERE msgid=?
EO_SQL
isa_ok($sth_select, 'DBI::st', 'prepare select');
my @data = (
{
test => 'set previous, id_value',
id => 'id_value',
set => [
'context_old_value',
'id_old_value',
t/03_DBD-PO/08_previous.t view on Meta::CPAN
}
}
# check table file
sub check_file {
my ($test, @previous) = @_;
my $po = <<'EOT';
# comment1
# comment2
msgid ""
msgstr ""
"Project-Id-Version: Testproject\n"
"Report-Msgid-Bugs-To: Bug Reporter <bug@example.org>\n"
"POT-Creation-Date: no POT creation date\n"
"PO-Revision-Date: no PO revision date\n"
"Last-Translator: Steffen Winkler <steffenw@example.org>\n"
"Language-Team: MyTeam <cpan@example.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Poedit-Language: German\n"
"X-Poedit-Country: GERMANY\n"
"X-Poedit-SourceCharset: utf-8"
# comment_value
#. automatic_value
#: ref_value
EOT
$po .= <<'EOT' if $previous[0];
#| msgctxt "context_old_value"
#| msgid "id_old_value"
EOT
$po .= <<'EOT';
msgctxt "context_value"
msgid "id_value"
msgstr "str_value"
# comment_value1
# comment_value2
#. automatic_value1
#. automatic_value2
#: ref_value1
#: ref_value2
EOT
$po .= <<'EOT' if $previous[1];
#| msgctxt ""
"context_old_value1\n"
"context_old_value2"
#| msgid ""
"id_old_value1\n"
"id_old_value2"
EOT
$po .= <<'EOT';
msgctxt ""
"context_value1\n"
"context_value2"
msgid ""
"id_value1\n"
"id_value2"
msgstr ""
"str_value1\n"
"str_value2"
msgid "id_value_mini"
msgstr ""
msgid "id_1"
msgstr "str_1u"
msgid "id_2"
msgstr "str_2"
EOT
$po .= <<'EOT' if $previous[2];
#| msgid_plural "plural_old_value"
EOT
$po .= <<'EOT';
msgid "id_singular"
msgid_plural "id_plural"
msgstr[0] "str_singular"
msgstr[1] "str_plural"
EOT
$po .= <<'EOT' if $previous[3];
#| msgid_plural ""
"plural_old_value1\n"
"plural_old_value2"
EOT
$po .= <<'EOT';
msgid ""
"id_singular1\n"
"id_singular2"
msgid_plural ""
"id_plural1\n"
"id_plural2"
msgstr[0] ""
"str_singular1\n"
"str_singular2"
msgstr[1] ""
"str_plural1\n"
"str_plural2"
msgid "id_value_singular_mini"
msgid_plural "id_value_plural_mini"
msgstr[0] ""
EOT
open my $file, '< :raw', $FILE_0X or croak $OS_ERROR;
local $INPUT_RECORD_SEPARATOR = ();
my $content = <$file>;
$po =~ s{\n}{$EOL}xmsg;
eq_or_diff($content, $po, 'check po file');
}
t/03_DBD-PO/11_crash.t view on Meta::CPAN
);
isa_ok($dbh, 'DBI::db', 'connect');
if ($TRACE) {
open my $file, '>', trace_file_name();
$dbh->trace(4, $file);
}
my $result = $dbh->do(<<"EO_SQL");
CREATE TABLE $TABLE_11 (
msgid VARCHAR,
msgstr VARCHAR
)
EO_SQL
is($result, '0E0', 'create table');
ok(-e $FILE_11, 'table file found');
}
# write a line and not the header at first
throws_ok
{
$dbh->do(<<"EO_SQL", undef, 'id');
INSERT INTO $TABLE_11 (
msgid
) VALUES (?)
EO_SQL
}
qr{\QA header has no msgid}xms,
'write a line and not the header at first',
;
# write an empty header
throws_ok
{
$dbh->do(<<"EO_SQL", undef, undef);
INSERT INTO $TABLE_11 (
msgstr
) VALUES (?)
t/03_DBD-PO/11_crash.t view on Meta::CPAN
msgstr
) VALUES (?)
EO_SQL
is($result, 1, 'write a true header');
}
# write a true line
{
my $result = $dbh->do(<<"EO_SQL", undef, 'id', 'str');
INSERT INTO $TABLE_11 (
msgid,
msgstr
) VALUES (?, ?)
EO_SQL
is($result, 1, 'write a true line');
}
# a line looks like a header
throws_ok
{
$dbh->do(<<"EO_SQL", undef, 'translation');
INSERT INTO $TABLE_11 (
msgstr
) VALUES (?)
EO_SQL
}
qr{\Q A line has to have a msgid}xms,
'a line looks like a header',
;
# change a header to an empty header
throws_ok
{
$dbh->do(<<"EO_SQL", undef, q{}, q{});
UPDATE $TABLE_11
SET msgstr=?
WHERE msgid=?
EO_SQL
}
qr{\QA header has to have a msgstr}xms,
'change a header to an empty header',
;
# change a header to a false header
throws_ok
{
$dbh->do(<<"EO_SQL", undef, 'false', q{});
UPDATE $TABLE_11
SET msgstr=?
WHERE msgid=?
EO_SQL
}
qr{\QThis can not be a header}xms,
'change a header to a false header',
;
# change a line to a false line
throws_ok
{
$dbh->do(<<"EO_SQL", undef, q{}, 'id');
UPDATE $TABLE_11
SET msgid=?
WHERE msgid=?
EO_SQL
}
qr{\QA line has to have a msgid}xms,
'change a line to a false line',
;
# drop table
SKIP: {
skip('drop table', 2)
if ! $DROP_TABLE;
my $result = $dbh->do(<<"EO_SQL");
DROP TABLE $TABLE_11
t/03_DBD-PO/12_more_tables.t view on Meta::CPAN
$FILE_12,
);
for my $name (@{$param}{qw(table table_file)}) {
$name =~ s{\?}{$param->{table_number}}xms;
}
my ($table, $table_file) = @{$param}{qw(table table_file)};
my $result = $dbh->do(<<"EO_SQL");
CREATE TABLE $table (
msgid VARCHAR,
msgstr VARCHAR
)
EO_SQL
is($result, '0E0', "create table ($table)");
ok(-e $table_file, "table file found ($table_file)");
return $param;
}
sub create {
my $param = shift;
my ($table, $table_file) = @{$param}{qw(table table_file)};
my $result = $dbh->do(<<"EO_SQL");
CREATE TABLE $table (
msgid VARCHAR,
msgstr VARCHAR
)
EO_SQL
is($result, '0E0', "create table $table");
ok(-e $table_file, "table $table_file file found");
return $param;
}
sub insert_header {
t/03_DBD-PO/12_more_tables.t view on Meta::CPAN
return $param;
}
sub insert_line {
my $param = shift;
my $table = $param->{table};
my $result = $dbh->do(<<"EO_SQL", undef, $test_data[0], $test_data[1]);
INSERT INTO $table (
msgid,
msgstr
) VALUES (?, ?)
EO_SQL
is($result, 1, "insert line into table $table");
return $param;
}
sub prepare {
my $param = shift;
my $table = $param->{table};
my $sth = $param->{sth} = $dbh->prepare(<<"EO_SQL");
SELECT msgstr
FROM $table
WHERE msgid=?
EO_SQL
isa_ok($sth, 'DBI::st', "prepare $table");
return $param;
}
sub execute {
my $param = shift;
my $table = $param->{table};
t/03_DBD-PO/13_charsets.t view on Meta::CPAN
@{$param}{qw(table table_file)} = (
$TABLE_13,
$FILE_13,
);
for my $name (@{$param}{qw(table table_file)}) {
$name =~ s{\?}{$charset}xms;
}
my $result = $dbh->do(<<"EO_SQL");
CREATE TABLE $param->{table} (
msgid VARCHAR,
msgstr VARCHAR
)
EO_SQL
is($result, '0E0', "create table ($charset)");
ok(-e $param->{table_file}, "table file found ($charset)");
return;
}
sub add_header {
t/03_DBD-PO/13_charsets.t view on Meta::CPAN
return;
}
sub add_line {
my $param = shift;
my $charset = $param->{charset};
my $section_sign = $charset
? "\N{SECTION SIGN}"
: encode 'iso-8859-1', "\N{SECTION SIGN}";
my $msgid = "id_$section_sign";
my $msgstr = "str_$section_sign";
my $result = $param->{dbh}->do(<<"EO_SQL", undef, $msgid, $msgstr);
INSERT INTO $param->{table} (
msgid,
msgstr
) VALUES (?, ?)
EO_SQL
is($result, 1, "add line ($charset)");
return;
}
sub check_table_file {
my $param = shift;
my $charset = $param->{charset};
my $po_charset = $charset || 'iso-8859-1';
my $po = <<"EOT";
msgid ""
msgstr ""
"MIME-Version: 1.0\\n"
"Content-Type: text/plain; charset=$po_charset\\n"
"Content-Transfer-Encoding: 8bit"
msgid "id_\N{SECTION SIGN}"
msgstr "str_\N{SECTION SIGN}"
EOT
local $INPUT_RECORD_SEPARATOR = ();
open
my $file1,
"< :encoding($po_charset)",
$param->{table_file}
or croak $OS_ERROR;
my $content1 = <$file1>;
t/03_DBD-PO/14_quote.t view on Meta::CPAN
);
isa_ok($dbh, 'DBI::db', 'connect');
if ($TRACE) {
open my $file, '>', trace_file_name();
$dbh->trace(4, $file);
}
my $result = $dbh->do(<<"EO_SQL");
CREATE TABLE $TABLE_14 (
msgid VARCHAR,
msgstr VARCHAR
)
EO_SQL
is($result, '0E0', 'create table');
ok(-e $FILE_14, 'table file found');
}
# quote
{
my @data = (
t/03_DBD-PO/14_quote.t view on Meta::CPAN
my $result = $dbh->do(<<"EO_SQL", undef, $msgstr);
INSERT INTO $TABLE_14 (
msgstr
) VALUES (?)
EO_SQL
is($result, 1, 'add header');
}
# add line as parameter
{
my $msgid = 'id_1';
my $msgstr = $test_string;
my $result = $dbh->do(<<"EO_SQL", undef, $msgid, $msgstr);
INSERT INTO $TABLE_14 (
msgid,
msgstr
) VALUES (?, ?)
EO_SQL
is($result, 1, 'add line as parameter');
}
# add line using method quote
{
my $msgid = $dbh->quote('id_2');
my $msgstr = $dbh->quote($test_string);
my $result = $dbh->do(<<"EO_SQL");
INSERT INTO $TABLE_14 (
msgid,
msgstr
) VALUES ($msgid, $msgstr)
EO_SQL
is($result, 1, 'add line using method quote');
}
# check_table_file
{
my $po = <<"EOT";
msgid ""
msgstr ""
"MIME-Version: 1.0\\n"
"Content-Type: text/plain; charset=utf-8\\n"
"Content-Transfer-Encoding: 8bit"
msgid "id_1"
msgstr $po_string
EOT
$po .= <<"EOT";
msgid "id_2"
msgstr $po_string
EOT
local $INPUT_RECORD_SEPARATOR = ();
open my $file1, '< :encoding(utf-8)', $TABLE_14 or croak $OS_ERROR;
my $content1 = <$file1>;
open my $file2, '< :encoding(utf-8)', \($po) or croak $OS_ERROR;
my $content2 = <$file2>;
eq_or_diff($content1, $content2, 'check po file');
}
t/03_DBD-PO/15_header_msgstr_hash.t view on Meta::CPAN
BEGIN {
require_ok('DBI');
}
my %test_data = (
'Project-Id-Version' => [
[qw( Project-Id-Version )],
[qw( MyProject )],
],
'Report-Msgid-Bugs-Mail' => [
[qw( Report-Msgid-Bugs-To-Mail )],
[qw( report.msgid.bugs.to@example.com )],
],
'Last-Translator-Mail' => [
[qw( Last-Translator-Mail )],
[qw( last.translator@example.com )],
],
extended => [
[qw( extended )],
[
[
'Extended-1' => 'extended_1',
'Extended-2' => 'extended_2',
],
],
],
all => [
[qw(
Project-Id-Version
Report-Msgid-Bugs-To-Mail
Last-Translator-Mail
extended
)],
[
'MyProject',
'report.msgid.bugs.to@example.com',
'last.translator@example.com',
[
'Extended-1' => 'extended_1',
'Extended-2' => 'extended_2',
],
],
],
);
my ($dbh, $sth_update, $sth_select);
t/03_DBD-PO/15_header_msgstr_hash.t view on Meta::CPAN
);
isa_ok($dbh, 'DBI::db', 'connect');
if ($TRACE) {
open my $file, '>', trace_file_name();
$dbh->trace(4, $file);
}
my $result = $dbh->do(<<"EO_SQL");
CREATE TABLE $TABLE_15 (
msgid VARCHAR,
msgstr VARCHAR
)
EO_SQL
is($result, '0E0', 'create table');
ok(-e $FILE_15, 'table file found');
}
# add header
{
my $msgstr = $dbh->func(
t/03_DBD-PO/15_header_msgstr_hash.t view on Meta::CPAN
) VALUES (?)
EO_SQL
is($result, 1, 'add header');
}
# prepare
{
$sth_update = $dbh->prepare(<<"EOT");
UPDATE $TABLE_15
SET msgstr=?
WHERE msgid=''
EOT
isa_ok($sth_update, 'DBI::st', 'prepare update');
$sth_select = $dbh->prepare(<<"EOT");
SELECT msgstr
FROM $TABLE_15
WHERE msgid=''
EOT
isa_ok($sth_update, 'DBI::st', 'prepare select');
}
sub update_header {
my $name = shift;
my ($test_keys, $test_values) = @{ $test_data{$name} };
my %params;
t/03_DBD-PO/15_header_msgstr_hash.t view on Meta::CPAN
return;
}
sub check_table_file {
my $name = shift;
my %test_of = map {$_ => 1} @{ $test_data{$name}->[0] };
my $po = <<"EOT";
msgid ""
msgstr ""
EOT
$po .= <<"EOT" if $test_of{'Project-Id-Version'};
"Project-Id-Version: MyProject\\n"
EOT
$po .= <<"EOT" if $test_of{'Report-Msgid-Bugs-To-Mail'};
"Report-Msgid-Bugs-To: <report.msgid.bugs.to\@example.com>\\n"
EOT
$po .= <<"EOT" if $test_of{'Last-Translator-Mail'};
"Last-Translator: <last.translator\@example.com>\\n"
EOT
$po .= <<"EOT";
"MIME-Version: 1.0\\n"
"Content-Type: text/plain; charset=utf-8\\n"
EOT
$po .= <<"EOT" if ! $test_of{extended};
"Content-Transfer-Encoding: 8bit"