Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fixes for Green-Score #11155

Merged
merged 8 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from 6 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
161 changes: 72 additions & 89 deletions html/images/attributes/src/green-score-e.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
54 changes: 4 additions & 50 deletions lib/ProductOpener/Display.pm
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ BEGIN {
&add_params_to_query
&add_params_and_filters_to_query

&url_for_text
&process_template

@search_series
Expand Down Expand Up @@ -329,47 +328,6 @@ $images_subdomain = format_subdomain('images');

=head1 FUNCTIONS


=head2 url_for_text ( $textid )

Return the localized URL for a text. (e.g. "data" points to /data in English and /donnees in French)
Note: This currently only has environmental_score

=cut

# Note: the following urls are currently hardcoded, but the idea is to build the mapping table
# at startup from the available translated texts in the repository. (TODO)
my %urls_for_texts = (
"environmental_score" => {
en => "eco-score-the-environmental-impact-of-food-products",
de => "eco-score-die-umweltauswirkungen-von-lebensmitteln",
es => "eco-score-el-impacto-medioambiental-de-los-productos-alimenticios",
fr => "eco-score-l-impact-environnemental-des-produits-alimentaires",
it => "eco-score-impatto-ambientale-dei-prodotti-alimentari",
nl => "eco-score-de-milieu-impact-van-voedingsproducten",
pt => "eco-score-o-impacto-ambiental-dos-produtos-alimentares",
},
);

sub url_for_text ($textid) {

# remove starting / if passed
$textid =~ s/^\///;

if (not defined $urls_for_texts{$textid}) {
return "/" . $textid;
}
elsif (defined $urls_for_texts{$textid}{$lc}) {
return "/" . $urls_for_texts{$textid}{$lc};
}
elsif ($urls_for_texts{$textid}{en}) {
return "/" . $urls_for_texts{$textid}{en};
}
else {
return "/" . $textid;
}
}

=head2 process_template ( $template_filename , $template_data_ref , $result_content_ref, $request_ref = {} )

Add some functions and variables needed by many templates and process the template with template toolkit.
Expand Down Expand Up @@ -424,7 +382,6 @@ sub process_template ($template_filename, $template_data_ref, $result_content_re
$template_data_ref->{display_date_without_time} = \&display_date_without_time;
$template_data_ref->{display_date_ymd} = \&display_date_ymd;
$template_data_ref->{display_date_tag} = \&display_date_tag;
$template_data_ref->{url_for_text} = \&url_for_text;
$template_data_ref->{product_url} = \&product_url;
$template_data_ref->{product_action_url} = \&product_action_url;
$template_data_ref->{product_name_brand_quantity} = \&product_name_brand_quantity;
Expand Down Expand Up @@ -2041,7 +1998,7 @@ sub display_list_of_tags ($request_ref, $query_ref) {

# For the Environmental-Score, we want to display A+ before A even though A+ is after A in alphabetical order
# If the tagid "a" is followed by tagid "a-plus", invert them
if (($tagtype eq 'environmental_score') and (defined $tags[1])) {
if (($tagtype eq 'ecoscore') or ($tagtype eq 'environmental_score') and (defined $tags[1])) {

if (($tags[0]{_id} eq 'a') and ($tags[1]{_id} eq 'a-plus')) {
my $tags_tmp = $tags[0];
Expand Down Expand Up @@ -2236,7 +2193,7 @@ sub display_list_of_tags ($request_ref, $query_ref) {
. "\" style=\"max-height:80px;\"> "
. $grade;
}
elsif ($tagtype eq 'environmental_score') {
elsif (($tagtype eq 'ecoscore') or ($tagtype eq 'environmental_score')) {
my $grade;

if ($tagid eq "a-plus") {
Expand All @@ -2257,9 +2214,9 @@ sub display_list_of_tags ($request_ref, $query_ref) {
}

$display
= "<img src=\"/images/attributes/dist/environmental-score-$tagid.svg\" alt=\"Environmental-Score "
= "<img src=\"/images/attributes/dist/green-score-$tagid.svg\" alt=\"Green-Score "
. $grade
. "\" title=\"Environmental-Score "
. "\" title=\"Green-Score "
. $grade
. "\" style=\"max-height:80px;\"> "
. $grade;
Expand Down Expand Up @@ -7661,9 +7618,6 @@ sub display_page ($request_ref) {
# Twitter account
$html =~ s/<twitter_account>/$twitter_account/g;

# Replace urls for texts in links like <a href="/environmental_score"> with a localized name
$html =~ s/(href=")(\/[^"]+)/$1 . url_for_text($2)/eg;

my $status_code = $request_ref->{status_code} // 200;

my $http_headers_ref = {
Expand Down
12 changes: 6 additions & 6 deletions po/common/fr.po
Original file line number Diff line number Diff line change
Expand Up @@ -5048,7 +5048,7 @@ msgstr "Note Green-Score"
# do not translate Green-Score
msgctxt "environmental_score_calculation_details"
msgid "Details of the calculation of the Green-Score"
msgstr "Détails du calcul de le Green-Score"
msgstr "Détails du calcul du Green-Score"

# do not translate Green-Score
msgctxt "environmental_score_information"
Expand Down Expand Up @@ -5705,7 +5705,7 @@ msgstr "Les informations sur les ingrédients de ce produit ne sont pas indiqué

msgctxt "environmental_score_edit_for_more_precise_environmental_score"
msgid "For a more precise calculation of the Green-Score, you can edit the product page and add them."
msgstr "Pour un calcul plus précis de le Green-Score, vous pouvez modifier la fiche produit et les ajouter."
msgstr "Pour un calcul plus précis du Green-Score, vous pouvez modifier la fiche produit et les ajouter."

msgctxt "environmental_score_packaging_ratio"
msgid "ratio"
Expand All @@ -5729,7 +5729,7 @@ msgstr "Les informations sur l'emballage de ce produit ne sont pas suffisamment

msgctxt "environmental_score_edit_for_more_precise_environmental_score"
msgid "For a more precise calculation of the Green-Score, you can modify the product page and add them."
msgstr "Pour un calcul plus précis de le Green-Score, vous pouvez modifier la fiche produit et les ajouter."
msgstr "Pour un calcul plus précis du Green-Score, vous pouvez modifier la fiche produit et les ajouter."

msgctxt "environmental_score_final_score"
msgid "Final score"
Expand All @@ -5751,17 +5751,17 @@ msgstr "Si vous êtes le fabricant de ce produit, vous pouvez nous transmettre l
# do not translate Green-Score and the link
msgctxt "environmental_score_description"
msgid "The <a href=\"/green-score\">Green-Score</a> is an experimental score that summarizes the environmental impacts of food products."
msgstr "L'<a href=\"/green-score\">Green-Score</a> est un score expérimental qui synthétise les impacts environnementaux des produits alimentaires."
msgstr "Le <a href=\"/green-score\">Green-Score</a> est un score expérimental qui synthétise les impacts environnementaux des produits alimentaires."

# do not translate Green-Score
msgctxt "environmental_score_warning_fr"
msgid "The Green-Score formula is subject to change as it is regularly improved to make it more precise."
msgstr "La formule de le Green-Score est susceptible d'évoluer car elle est régulièrement améliorée pour la rendre plus précise."
msgstr "La formule du Green-Score est susceptible d'évoluer car elle est régulièrement améliorée pour la rendre plus précise."

# do not translate Green-Score
msgctxt "environmental_score_warning_international"
msgid "The Green-Score was initially developped for France and it is being extended to other European countries. The Green-Score formula is subject to change as it is regularly improved to make it more precise and better suited to each country."
msgstr "Le Green-Score a été initialement conçu pour la France et est en cours d'extension à d'autres pays européens. La formule de le Green-Score est susceptible d'évoluer car elle est régulièrement améliorée pour la rendre plus précise et mieux adaptée à chaque pays."
msgstr "Le Green-Score a été initialement conçu pour la France et est en cours d'extension à d'autres pays européens. La formule du Green-Score est susceptible d'évoluer car elle est régulièrement améliorée pour la rendre plus précise et mieux adaptée à chaque pays."

msgctxt "environmental_score_warning_transportation_world"
msgid "Select a country in order to include the full impact of transportation."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"element_type": "text",
"text_element": {
"html": `
<p>&rarr; <a href="[% url_for_text("environmental_score") %]">[% lang('environmental_score_learn_more') %]</a></p>
<p>&rarr; <a href="/green-score">[% lang('environmental_score_learn_more') %]</a></p>
`
},
},
Expand Down
Loading
Loading