Skip to content

Commit

Permalink
ecoscore / environmental score
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanegigandet committed Dec 17, 2024
1 parent e6c4234 commit b249ede
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 16 deletions.
11 changes: 9 additions & 2 deletions lib/ProductOpener/Attributes.pm
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ sub initialize_attribute ($attribute_id, $target_lc) {
$attribute_ref->{icon_url} = "$static_subdomain/images/attributes/dist/nutriscore-a.svg";
$attribute_ref->{panel_id} = "nutriscore";
}
elsif ($attribute_id eq "environmental_score") {
elsif ($attribute_id eq "ecoscore") {
$attribute_ref->{icon_url} = "$static_subdomain/images/attributes/dist/ecoscore-a.svg";
$attribute_ref->{panel_id} = "environmental_score";
}
Expand Down Expand Up @@ -616,6 +616,10 @@ sub compute_attribute_nutriscore ($product_ref, $target_lc, $target_cc) {
Computes an environmental impact attribute based on the Environmental-Score.
Note: before 2025, the Environmental-Score was called the Eco-Score,
as the id of the attribute is stored inside clients, we keep the
id "ecoscore" for the attribute.
=head3 Arguments
=head4 product reference $product_ref
Expand Down Expand Up @@ -648,7 +652,10 @@ sub compute_attribute_environmental_score ($product_ref, $target_lc, $target_cc)
{code => $product_ref->{code}, environmental_score_data => $product_ref->{environmental_score_data}})
if $log->is_debug();

my $attribute_id = "environmental_score";
# Note: before 2025, the Environmental-Score was called the Eco-Score,
# as the id of the attribute is stored inside clients, we keep the
# id "ecoscore" for the attribute.
my $attribute_id = "ecoscore";

my $attribute_ref = initialize_attribute($attribute_id, $target_lc);

Expand Down
11 changes: 7 additions & 4 deletions lib/ProductOpener/Config_off.pm
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ $options{replace_existing_values_when_importing_those_tags_fields} = {
);

# tag types (=facets) that should be indexed by web crawlers, all other tag types are not indexable
@index_tag_types = qw(brands categories labels additives nova_groups environmental_score nutrition_grades products);
@index_tag_types = qw(brands categories labels additives nova_groups ecoscore nutrition_grades products);

# fields in product edit form, above ingredients and nutrition facts

Expand Down Expand Up @@ -794,7 +794,7 @@ $options{replace_existing_values_when_importing_those_tags_fields} = {
@drilldown_fields = qw(
nutrition_grades
nova_groups
environmental_score
ecoscore
brands
categories
labels
Expand Down Expand Up @@ -965,7 +965,10 @@ $options{attribute_groups} = [
],
["ingredients_analysis", ["vegan", "vegetarian", "palm_oil_free",]],
["labels", ["labels_organic", "labels_fair_trade"]],
["environment", ["environmental_score", "forest_footprint",]],
# Note: before 2025, the Environmental-Score was called the Eco-Score,
# as the id of the attribute is stored inside clients, we keep the
# id "ecoscore" for the attribute.
["environment", ["ecoscore", "forest_footprint",]],
];

# By default attributes have 4 possible values: not_important, important, very_important, mandatory
Expand Down Expand Up @@ -995,7 +998,7 @@ $options{attribute_values} = {
$options{attribute_default_preferences} = {
"nutriscore" => "very_important",
"nova" => "important",
"environmental_score" => "important",
"ecoscore" => "important",
};

use JSON::MaybeXS;
Expand Down
7 changes: 7 additions & 0 deletions lib/ProductOpener/EnvironmentalScore.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,13 @@ sub compute_environmental_score ($product_ref) {
}
}

# Before 2025, the Environmental Score was called the Eco-Score.
# to ease the transition, we copy environmental_score_tags to eco_score_tags
# so that queries to MongoDB and off-query do not have to change
if (defined $product_ref->{environmental_score_tags}) {
$product_ref->{ecoscore_tags} = $product_ref->{environmental_score_tags};
}

return;
}

Expand Down
29 changes: 29 additions & 0 deletions po/common/common.pot
Original file line number Diff line number Diff line change
Expand Up @@ -4820,6 +4820,19 @@ msgctxt "attribute_environmental_score_setting_note"
msgid "The Eco-Score is an environmental score from A to E which makes it easy to compare the impact of food products on the environment."
msgstr ""

# Note: the Eco-Score is renamed to Environmental Score, but we keep the ecoscore identifier as it is stored in clients
msgctxt "attribute_ecoscore_name"
msgid "Eco-Score"
msgstr "Eco-Score"

msgctxt "attribute_ecoscore_setting_name"
msgid "Low environmental impact (Eco-Score)"
msgstr "Low environmental impact (Eco-Score)"

msgctxt "attribute_ecoscore_setting_note"
msgid "The Eco-Score is an environmental score from A to E which makes it easy to compare the impact of food products on the environment."
msgstr "The Eco-Score is an environmental score from A to E which makes it easy to compare the impact of food products on the environment."

# keep %s, it will be replaced by the letter A+, A, B, C, D, E or F
msgctxt "attribute_environmental_score_grade_title"
msgid "Eco-Score %s"
Expand Down Expand Up @@ -5051,6 +5064,14 @@ msgctxt "missing_nutrition_facts"
msgid "Missing nutrition facts"
msgstr "Missing nutrition facts"

msgctxt "ecoscore_p"
msgid "Eco-Score"
msgstr "Eco-Score"

msgctxt "ecoscore_s"
msgid "Eco-Score"
msgstr "Eco-Score"

msgctxt "environmental_score_p"
msgid "Eco-Score"
msgstr "Eco-Score"
Expand All @@ -5059,6 +5080,14 @@ msgctxt "environmental_score_s"
msgid "Eco-Score"
msgstr "Eco-Score"

msgctxt "misc_p"
msgid "Miscellaneous"
msgstr "Miscellaneous"

msgctxt "misc_s"
msgid "Miscellaneous"
msgstr "Miscellaneous"

msgctxt "packaging_parts"
msgid "Packaging parts"
msgstr "Packaging parts"
Expand Down
29 changes: 29 additions & 0 deletions po/common/en.po
Original file line number Diff line number Diff line change
Expand Up @@ -4839,6 +4839,19 @@ msgctxt "attribute_environmental_score_setting_note"
msgid "The Eco-Score is an environmental score from A to E which makes it easy to compare the impact of food products on the environment."
msgstr "The Eco-Score is an environmental score from A to E which makes it easy to compare the impact of food products on the environment."

# Note: the Eco-Score is renamed to Environmental Score, but we keep the ecoscore identifier as it is stored in clients
msgctxt "attribute_ecoscore_name"
msgid "Eco-Score"
msgstr "Eco-Score"

msgctxt "attribute_ecoscore_setting_name"
msgid "Low environmental impact (Eco-Score)"
msgstr "Low environmental impact (Eco-Score)"

msgctxt "attribute_ecoscore_setting_note"
msgid "The Eco-Score is an environmental score from A to E which makes it easy to compare the impact of food products on the environment."
msgstr "The Eco-Score is an environmental score from A to E which makes it easy to compare the impact of food products on the environment."

# keep %s, it will be replaced by the letter A+, A, B, C, D, E or F
msgctxt "attribute_environmental_score_grade_title"
msgid "Eco-Score %s"
Expand Down Expand Up @@ -5070,6 +5083,14 @@ msgctxt "missing_nutrition_facts"
msgid "Missing nutrition facts"
msgstr "Missing nutrition facts"

msgctxt "ecoscore_p"
msgid "Eco-Score"
msgstr "Eco-Score"

msgctxt "ecoscore_s"
msgid "Eco-Score"
msgstr "Eco-Score"

msgctxt "environmental_score_p"
msgid "Eco-Score"
msgstr "Eco-Score"
Expand All @@ -5078,6 +5099,14 @@ msgctxt "environmental_score_s"
msgid "Eco-Score"
msgstr "Eco-Score"

msgctxt "misc_p"
msgid "Miscellaneous"
msgstr "Miscellaneous"

msgctxt "misc_s"
msgid "Miscellaneous"
msgstr "Miscellaneous"

msgctxt "packaging_parts"
msgid "Packaging parts"
msgstr "Packaging parts"
Expand Down
29 changes: 29 additions & 0 deletions po/common/fr.po
Original file line number Diff line number Diff line change
Expand Up @@ -4838,6 +4838,19 @@ msgctxt "attribute_environmental_score_setting_note"
msgid "The Eco-Score is an environmental score (environmental_score) from A to E which makes it easy to compare the impact of food products on the environment."
msgstr "L'Eco-Score est un score environnemental (écoscore) de A à E qui permet de comparer facilement l'impact des produits alimentaires sur l'environnement."

# Note: the Eco-Score is renamed to Environmental Score, but we keep the ecoscore identifier as it is stored in clients
msgctxt "attribute_ecoscore_name"
msgid "Eco-Score"
msgstr "Eco-Score"

msgctxt "attribute_ecoscore_setting_name"
msgid "Low environmental impact (Eco-Score)"
msgstr "Faible impact environnemental (Eco-Score)"

msgctxt "attribute_ecoscore_setting_note"
msgid "The Eco-Score is an environmental score from A to E which makes it easy to compare the impact of food products on the environment."
msgstr "L'Eco-Score est un score environnemental (écoscore) de A à E qui permet de comparer facilement l'impact des produits alimentaires sur l'environnement."

# keep %s, it will be replaced by the letter A+, A, B, C, D, E or F
msgctxt "attribute_environmental_score_grade_title"
msgid "Eco-Score %s"
Expand Down Expand Up @@ -5069,6 +5082,14 @@ msgctxt "missing_nutrition_facts"
msgid "Missing nutrition facts"
msgstr "Données nutritionnelles manquantes"

msgctxt "ecoscore_p"
msgid "Eco-Score"
msgstr "Eco-Score"

msgctxt "ecoscore_s"
msgid "Eco-Score"
msgstr "Eco-Score"

msgctxt "environmental_score_p"
msgid "Eco-Score"
msgstr "Eco-Score"
Expand All @@ -5077,6 +5098,14 @@ msgctxt "environmental_score_s"
msgid "Eco-Score"
msgstr "Eco-Score"

msgctxt "misc_p"
msgid "Miscellaneous"
msgstr "Divers"

msgctxt "misc_s"
msgid "Miscellaneous"
msgstr "Divers"

msgctxt "packaging_parts"
msgid "Packaging parts"
msgstr "Elements d'emballage"
Expand Down
12 changes: 6 additions & 6 deletions po/tags/en.po
Original file line number Diff line number Diff line change
Expand Up @@ -542,13 +542,13 @@ msgctxt "owners:singular"
msgid "owner"
msgstr "owner"

msgctxt "environmental_score:plural"
msgid "eco-score"
msgstr "eco-score"
msgctxt "ecoscore:plural"
msgid "environmental-score"
msgstr "environmental-score"

msgctxt "environmental_score:singular"
msgid "eco-score"
msgstr "eco-score"
msgctxt "ecoscore:singular"
msgid "environmental-score"
msgstr "environmental-score"

msgctxt "food_groups:plural"
msgid "food-groups"
Expand Down
4 changes: 2 additions & 2 deletions po/tags/hu.po
Original file line number Diff line number Diff line change
Expand Up @@ -633,10 +633,10 @@ msgctxt "owners:singular"
msgid "owner"
msgstr "tulajdonos"

msgctxt "environmental_score:plural"
msgctxt "ecoscore:plural"
msgid "environmental_score"
msgstr "environmental_score"

msgctxt "environmental_score:singular"
msgctxt "ecoscore:singular"
msgid "environmental_score"
msgstr "environmental_score"
4 changes: 2 additions & 2 deletions po/tags/tags.pot
Original file line number Diff line number Diff line change
Expand Up @@ -638,11 +638,11 @@ msgctxt "owners:singular"
msgid "owner"
msgstr "owner"

msgctxt "environmental_score:plural"
msgctxt "ecoscore:plural"
msgid "environmental_score"
msgstr "environmental_score"

msgctxt "environmental_score:singular"
msgctxt "ecoscore:singular"
msgid "environmental_score"
msgstr "environmental_score"

Expand Down

0 comments on commit b249ede

Please sign in to comment.