Skip to content

Commit

Permalink
fix: fallback to english for knowledge panels
Browse files Browse the repository at this point in the history
fixes #6771
  • Loading branch information
alexgarel committed May 20, 2022
1 parent b8e36da commit 3468601
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/ProductOpener/Display.pm
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ sub process_template($$$) {

# Display one taxonomy entry in the target language
$template_data_ref->{display_taxonomy_tag} = sub ($$) {
return display_taxonomy_tag($lc, $_[0], $_[1]);
return display_taxonomy_tag_name($lc, $_[0], $_[1]);
};

# Display a list of taxonomy entries in the target language
Expand Down
4 changes: 4 additions & 0 deletions lib/ProductOpener/KnowledgePanels.pm
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,10 @@ sub create_ecoscore_panel($$$) {
# Add properties of interest
foreach my $property (qw(environmental_benefits description)) {
my $property_value = get_inherited_property("labels", $labelid, $property . ":" . $target_lc);
if (not defined $property_value && $target_lc != "en") {
# fallback to english
$property_value = get_inherited_property("labels", $labelid, $property . ":" . "en");
}
if (defined $property_value) {
$label_panel_data_ref->{$property} = $property_value;
}
Expand Down
46 changes: 46 additions & 0 deletions lib/ProductOpener/Tags.pm
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ BEGIN
&canonicalize_taxonomy_tag_link
&exists_taxonomy_tag
&display_taxonomy_tag
&display_taxonomy_tag_name
&display_taxonomy_tag_link
&get_taxonomy_tag_and_link_for_lang
Expand Down Expand Up @@ -3443,6 +3444,25 @@ sub exists_taxonomy_tag($$) {
}


=head2 display_taxonomy_tag ( $target_lc, $tagtype, $canon_tagid )
Return the name of a tag for displaying it to the user
=head3 Arguments
=head4 $target_lc - target language code
=head4 $tagtype
=head4 $canon_tagid
=head3 Return values
The tag translation if it exists in target language,
otherwise, the tag id.
=cut

sub display_taxonomy_tag($$$)
{
my $target_lc = shift; $target_lc =~ s/_.*//;
Expand Down Expand Up @@ -3548,6 +3568,32 @@ sub display_taxonomy_tag($$$)
}


=head2 display_taxonomy_tag_name ( $target_lc, $tagtype, $canon_tagid )
A version of display_taxonomy_tag that removes eventual language prefix
=head3 Arguments
=head4 $target_lc - target language code
=head4 $tagtype
=head4 $canon_tagid
=head3 Return values
The tag translation if it exists in target language,
otherwise, the tag in its primary language
=cut

sub display_taxonomy_tag_name($$$)
{
my $display_value = display_taxonomy_tag($_[0], $_[1], $_[2]);
# remove eventual leading language code
$display_value =~ s/^\w\w://;
return $display_value;
}

sub canonicalize_tag_link($$)
{
Expand Down

0 comments on commit 3468601

Please sign in to comment.