Locale-XGettext
view release on metacpan or search on metacpan
lib/Locale/XGettext/Util/POEntries.pm view on Meta::CPAN
return $self;
}
sub entries {
@{shift->{__entries}};
}
# This is a simplified merge for merging entries without any translations.
sub __mergeEntries {
my ($self, $entry, $overlay) = @_;
if (defined $entry->msgid_plural
&& defined $overlay->msgid_plural
&& $entry->msgid_plural ne $overlay->msgid_plural) {
# This is a fatal error as GNU gettext cannot grok with
# this case.
# See https://savannah.gnu.org/bugs/index.php?48411
$self->__conflict($entry, $overlay,
__"conflicting plural forms");
}
# If one of the two entries currently has no plural form, there is no
# problem.
$entry->msgid_plural($overlay->dequote($overlay->msgid_plural))
if defined $overlay->msgid_plural;
my $new_ref = $overlay->reference;
my $reference = $entry->reference;
my @lines = split "\n", $reference;
if (!@lines) {
push @lines, $new_ref;
} else {
my $last_line = $lines[-1];
my $ref_length = 1 + length $new_ref;
if ($ref_length > 76) {
push @lines, $new_ref;
} elsif ($ref_length + length $last_line > 76) {
push @lines, $new_ref;
} else {
$lines[-1] .= ' ' . $new_ref;
}
}
$entry->reference(join "\n", @lines);
$entry->fuzzy($overlay->fuzzy) if $overlay->fuzzy;
if (defined $entry->comment) {
$entry->comment(join "\n", $entry->comment, $overlay->comment);
} else {
$entry->comment($overlay->comment) if defined $overlay->comment;
}
if (defined $entry->automatic) {
$entry->automatic(join "\n", $entry->automatic, $overlay->automatic);
} else {
$entry->automatic($overlay->automatic) if defined $overlay->automatic;
}
# Locale::PO does not allow to iterate over the flags. We have to
# use the private property directly.
my @flags = @{$overlay->{_flags} || []};
foreach my $flag (@flags) {
if ($flag =~ /^no-(.*)/) {
$self->__conflict($entry, $overlay,
__x"conflicting flags")
if $entry->has_flag($1);
} elsif ($entry->has_flag("no-$flag")) {
$self->__conflict($entry, $overlay,
__x"conflicting flags");
}
$entry->add_flag($flag) if !$entry->has_flag($flag);
}
return $self;
}
sub __conflict {
my ($self, $old, $new, $msg) = @_;
( run in 0.764 second using v1.01-cache-2.11-cpan-49f99fa48dc )