Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/QBit/Gettext/Extract/Lang.pm
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package QBit::Gettext::Extract::Lang;

use qbit;
use Text::Balanced qw(extract_quotelike);

use base qw(QBit::Class);

Expand Down Expand Up @@ -53,6 +54,8 @@ sub extract_from_file {
s/\\'/'/sg;
} elsif (s/^"|"$//sg) {
s/\\"/"/sg;
} elsif ( my $quoted_value = (extract_quotelike($_))[5] ) {
$_ = $quoted_value;
}
}

Expand Down
18 changes: 16 additions & 2 deletions lib/QBit/Gettext/Extract/Lang/Perl.pm
Original file line number Diff line number Diff line change
@@ -1,18 +1,32 @@
package QBit::Gettext::Extract::Lang::Perl;

use qbit;
use Text::Balanced qw(extract_multiple extract_quotelike);

use base qw(QBit::Gettext::Extract::Lang);

my $RE_eol = $QBit::Gettext::Extract::Lang::RE_eol;
my $RE_quoted_str = $QBit::Gettext::Extract::Lang::RE_quoted_str;

sub extract_from_file {
my ($self, $filename, $po) = @_;

my @quoted = grep {defined($_)} map {scalar extract_quotelike($_)} extract_multiple(readfile($filename), [\&extract_quotelike]);
if(@quoted) {
my $quoted_regexp = '(?:'.join(')|(?:', map {quotemeta($_)} @quoted).')';
local $QBit::Gettext::Extract::Lang::RE_quoted_str = qr/(?:$QBit::Gettext::Extract::Lang::RE_quoted_str)|$quoted_regexp/ ;
$self->SUPER::extract_from_file($filename, $po);
}
else {
$self->SUPER::extract_from_file($filename, $po);
}
}

sub clean {
my ($self, $text) = @_;

{
no warnings qw(uninitialized);
$text =~ s/($RE_quoted_str)|#.*$/$1/mg; # Remove comments
$text =~ s/($QBit::Gettext::Extract::Lang::RE_quoted_str)|#.*$/$1/mg; # Remove comments
};

# Remove PODs
Expand Down
6 changes: 6 additions & 0 deletions t/files/file.pl
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@
gettext("1

3");
gettext(qq-1

3-); # gettext(q{One more text in comment})

gettext(q{Test 1' # " });
gettext(q|Test 1' # " |);

=head 1

Expand Down
3 changes: 3 additions & 0 deletions t/files/perl.pot
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ msgstr ""
"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"

#: $BIN/files/file.pl:37
#: $BIN/files/file.pl:40
msgid ""
"1\n"
"\n"
Expand Down Expand Up @@ -60,6 +61,8 @@ msgstr[0] ""
msgstr[1] ""

#: $BIN/files/file.pl:14
#: $BIN/files/file.pl:44
#: $BIN/files/file.pl:45
msgid "Test 1' # \" "
msgstr ""

Expand Down