Serge
view release on metacpan or search on metacpan
lib/Serge/Engine/Plugin/feature_branch.pm view on Meta::CPAN
my $sth = $db->prepare($sqlquery);
my $n = 1;
$sth->bind_param($n++, $self->{parent}->{db_namespace}) || die $sth->errstr;
$sth->bind_param($n++, $job_id) || die $sth->errstr;
map {
$sth->bind_param($n++, $_) || die $sth->errstr;
} @languages;
$sth->execute || die $sth->errstr;
my $n = 0;
while (my $hr = $sth->fetchrow_hashref()) {
$n++;
my $lang = $hr->{language};
my $skey = generate_key($hr->{string}, $hr->{context});
# save string+context key (to know the string exists in master job
# even if it doesn't have a translation)
$cache->{''} = {} unless defined $cache->{''};
$cache->{''}->{$skey} = 1;
# save translation
if ($lang ne '') {
$cache->{$lang} = {} unless defined $cache->{$lang};
$cache->{$lang}->{$skey} = $hr->{translation};
}
}
$sth->finish;
$sth = undef;
my $delta = tv_interval($start);
print "feature_branch::load_translations() took $delta seconds\n";
}
sub get_translation_pre {
my ($self, $phase, $string, $context, $namespace, $filepath, $lang, $disallow_similar_lang, $item_id, $key) = @_;
return () if $self->{master_mode}; # do nothing in master mode
# otherwise, return current translation (or empty array if there's no matching translation)
my $key = generate_key($string, $context);
return exists $self->{cache}->{$lang}->{$key} ? ($self->{cache}->{$lang}->{$key}, undef, undef, undef) : ();
}
sub string_exists {
my ($self, $stringref, $context) = @_;
return exists $self->{cache}->{''}->{generate_key($$stringref, $context)};
}
sub can_extract {
my ($self, $phase, $file, $lang, $stringref, $hintref, $context, $key) = @_;
# extract everything for master job, and collect string+context pairs
if ($self->{master_mode}) {
$self->{cache}->{''}->{generate_key($$stringref, $context)} = 1;
return 1;
}
# otherwise, we're in a slave job
# if we're generating localized files, $lang will be set
return 1 if defined $lang; # extract everything to translate all the strings, not just overlay ones
# otherwise (when $lang is not set) we're parsing the source file
return $self->string_exists($stringref, $context, ) ? 0 : 1; # extract only strings which are missing from the master job
}
1;
( run in 1.137 second using v1.01-cache-2.11-cpan-7fcb06a456a )