Skip to content
This repository has been archived by the owner on Feb 7, 2024. It is now read-only.

Commit

Permalink
Implement 'reuse_fuzzy' option (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
Igor Afanasyev committed Jun 18, 2019
1 parent e0e3b01 commit 386d6af
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
7 changes: 7 additions & 0 deletions doc/sample.serge
Expand Up @@ -292,6 +292,13 @@ jobs
# NO - do not reuse such uncertain translations at all (default)
reuse_uncertain NO

# (BOOLEAN) [OPTIONAL] Should the fuzzy translations be reused?
# Note that for the translation to be reusable, it must satisfy
# all the reuse_* criteria at the same time.
# YES - reuse fuzzy translations (default)
# NO - do not reuse fuzzy translations
reuse_fuzzy YES

# (BOOLEAN) [OPTIONAL] Should the fuzzy flag be set on translations
# which are copied from other strings?
# Fuzzy flag indicates that the translation is not final and needs review.
Expand Down
4 changes: 3 additions & 1 deletion lib/Serge/DB/Cached.pm
Expand Up @@ -687,7 +687,8 @@ sub preload_properties {

sub find_best_translation {
my $self = shift;
my ($namespace, $filepath, $string, $context, $lang, $allow_orphaned, $allow_multiple_variants) = @_;
my ($namespace, $filepath, $string, $context, $lang,
$allow_orphaned, $allow_fuzzy, $allow_multiple_variants) = @_;

# Now that we hit the item we have no translation for, and need to query
# the database for the best translation, preload the portion of the cache
Expand All @@ -706,6 +707,7 @@ sub find_best_translation {
my $variants = {};
foreach my $hr (values %{$cache->{$skey}}) {
next if $hr->{orphaned} && !$allow_orphaned;
next if $hr->{fuzzy} && !$allow_fuzzy;
$variants->{$hr->{string}}++;

my $fitness = 0;
Expand Down
7 changes: 6 additions & 1 deletion lib/Serge/Engine.pm
Expand Up @@ -39,6 +39,7 @@ sub new {
output_bom => 1,
reuse_translations => 1,
reuse_orphaned => 1,
reuse_fuzzy => 1,
reuse_as_fuzzy_default => 1,
reuse_as_fuzzy => [],
reuse_as_not_fuzzy => [],
Expand Down Expand Up @@ -228,6 +229,7 @@ sub adjust_job_defaults {
output_bom
reuse_translations
reuse_orphaned
reuse_fuzzy
reuse_as_fuzzy_default
reuse_as_fuzzy
reuse_as_not_fuzzy
Expand Down Expand Up @@ -1703,7 +1705,10 @@ sub internal_get_translation { # from database
if ($self->{job}->{reuse_translations}) {
# Find the best match from other files or namespaces
my ($translation, $fuzzy, $comment, $multiple_variants) = $self->{db}->find_best_translation(
$namespace, $filepath, $string, $context, $lang, $self->{job}->{reuse_orphaned}, $self->{job}->{reuse_uncertain}
$namespace, $filepath, $string, $context, $lang,
$self->{job}->{reuse_orphaned},
$self->{job}->{reuse_fuzzy},
$self->{job}->{reuse_uncertain}
);

if ($multiple_variants && !$self->{job}->{reuse_uncertain}) {
Expand Down
8 changes: 6 additions & 2 deletions lib/Serge/Engine/Plugin/transform.pm
Expand Up @@ -231,7 +231,9 @@ sub guess_translation {
my ($translation, $fuzzy, $comment, $multiple_variants) =
$self->{parent}->{engine}->{db}->find_best_translation(
$namespace, $filepath, $candidate, $context, $lang,
$self->{parent}->{reuse_orphaned}, $self->{parent}->{reuse_uncertain}
$self->{parent}->{reuse_orphaned},
$self->{parent}->{reuse_fuzzy},
$self->{parent}->{reuse_uncertain}
);

if ($multiple_variants && !$self->{parent}->{reuse_uncertain}) {
Expand Down Expand Up @@ -262,7 +264,9 @@ sub guess_translation {
my ($translation, $fuzzy, $comment, $multiple_variants) =
$self->{parent}->{engine}->{db}->find_best_translation(
$namespace, $filepath, $candidate, $context, $lang,
$self->{parent}->{reuse_orphaned}, $self->{parent}->{reuse_uncertain}
$self->{parent}->{reuse_orphaned},
$self->{parent}->{reuse_fuzzy},
$self->{parent}->{reuse_uncertain}
);

if ($multiple_variants && !$self->{parent}->{reuse_uncertain}) {
Expand Down
1 change: 1 addition & 0 deletions lib/Serge/config_schema.serge
Expand Up @@ -74,6 +74,7 @@ jobs ARRAY
reuse_translations BOOLEAN
reuse_orphaned BOOLEAN
reuse_uncertain BOOLEAN
reuse_fuzzy BOOLEAN
reuse_as_fuzzy_default BOOLEAN
reuse_as_fuzzy ARRAY
reuse_as_not_fuzzy ARRAY
Expand Down

0 comments on commit 386d6af

Please sign in to comment.