Skip to content

Commit

Permalink
fix: Green-Score attributes/panels titles and subtitles (#11244)
Browse files Browse the repository at this point in the history
A few fixes/changes:
- we still had a "A-PLUS" instead of "A+" in a knowledge panel title
- separated title and subtitle
- for not-applicable, changed the "short description" so that it
includes the non-applicable category (e.g. "sodas"), and display it
directly in the attribute subtitle. (it's a bit longer, but probably
worth displaying directly).
  • Loading branch information
stephanegigandet authored Jan 15, 2025
1 parent 19ab7bb commit 1eb84a5
Show file tree
Hide file tree
Showing 30 changed files with 83 additions and 70 deletions.
14 changes: 8 additions & 6 deletions lib/ProductOpener/Attributes.pm
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,8 @@ sub compute_attribute_nutriscore ($product_ref, $target_lc, $target_cc) {
$attribute_ref->{match} = 0;
if ($target_lc ne "data") {
$attribute_ref->{title} = lang_in_other_lc($target_lc, "attribute_nutriscore_not_applicable_title");
$attribute_ref->{description} = f_lang_in_lc(
# Note: we now display the not-applicable category in the short description
$attribute_ref->{description_short} = f_lang_in_lc(
$target_lc,
"f_attribute_nutriscore_not_applicable_description",
{
Expand All @@ -580,8 +581,8 @@ sub compute_attribute_nutriscore ($product_ref, $target_lc, $target_cc) {
)
}
);
$attribute_ref->{description_short}
= lang_in_other_lc($target_lc, "attribute_nutriscore_not_applicable_description_short");
#$attribute_ref->{description_short}
# = lang_in_other_lc($target_lc, "attribute_nutriscore_not_applicable_description_short");
}
}

Expand Down Expand Up @@ -727,7 +728,8 @@ sub compute_attribute_environmental_score ($product_ref, $target_lc, $target_cc)
if ($target_lc ne "data") {
$attribute_ref->{title}
= lang_in_other_lc($target_lc, "attribute_environmental_score_not_applicable_title");
$attribute_ref->{description} = f_lang_in_lc(
# Note: we now display the not-applicable category in the short description
$attribute_ref->{description_short} = f_lang_in_lc(
$target_lc,
"f_attribute_environmental_score_not_applicable_description",
{
Expand All @@ -740,8 +742,8 @@ sub compute_attribute_environmental_score ($product_ref, $target_lc, $target_cc)
)
}
);
$attribute_ref->{description_short}
= lang_in_other_lc($target_lc, "attribute_environmental_score_not_applicable_description_short");
#$attribute_ref->{description_short}
# = lang_in_other_lc($target_lc, "attribute_environmental_score_not_applicable_description_short");
}
}
# Environmental-Score is unknown
Expand Down
24 changes: 4 additions & 20 deletions lib/ProductOpener/KnowledgePanels.pm
Original file line number Diff line number Diff line change
Expand Up @@ -642,9 +642,9 @@ sub create_environmental_score_panel ($product_ref, $target_lc, $target_cc, $opt
}

# We can reuse some strings from the Environmental-Score attribute
my $title
= sprintf(lang_in_other_lc($target_lc, "attribute_environmental_score_grade_title"), uc($grade)) . ' - '
. lang_in_other_lc($target_lc, "attribute_environmental_score_" . $grade_underscore . "_description_short");
my $title = sprintf(lang_in_other_lc($target_lc, "attribute_environmental_score_grade_title"), $letter_grade);
my $subtitle
= lang_in_other_lc($target_lc, "attribute_environmental_score_" . $grade_underscore . "_description_short");

my $panel_data_ref = {
"agribalyse_category_name" => $agribalyse_category_name,
Expand All @@ -658,6 +658,7 @@ sub create_environmental_score_panel ($product_ref, $target_lc, $target_cc, $opt
"grade_underscore" => $grade_underscore,
"letter_grade" => $letter_grade,
"title" => $title,
"subtitle" => $subtitle,
"transportation_warning" => $transportation_warning,
};

Expand All @@ -673,23 +674,6 @@ sub create_environmental_score_panel ($product_ref, $target_lc, $target_cc, $opt
$panel_data_ref, $product_ref, $target_lc, $target_cc, $options_ref
);

# Create an extra panel for products that have extended environmental_score data from the impact estimator

# 2022/05/06: disabled as we currently have few products with reliable extended environmental_score data

# if (defined $product_ref->{environmental_score_extended_data}) {

# extract_data_from_impact_estimator_best_recipe($product_ref, $panel_data_ref);

# compare_impact_estimator_data_to_category_average($product_ref, $panel_data_ref, $target_cc);

# # Display a panel only if we can compare the product extended impact
# if (defined $panel_data_ref->{environmental_score_extended_data_for_category}) {
# create_panel_from_json_template("environmental_score_extended", "api/knowledge-panels/environment/environmental_score/environmental_score_extended.tt.json",
# $panel_data_ref, $product_ref, $target_lc, $target_cc, $options_ref);
# }
# }

create_panel_from_json_template("carbon_footprint",
"api/knowledge-panels/environment/carbon_footprint_food.tt.json",
$panel_data_ref, $product_ref, $target_lc, $target_cc, $options_ref);
Expand Down
8 changes: 4 additions & 4 deletions po/common/common.pot
Original file line number Diff line number Diff line change
Expand Up @@ -5385,12 +5385,12 @@ msgid "User is being deleted. This may take a few minutes."
msgstr "User is being deleted. This may take a few minutes."

msgctxt "attribute_environmental_score_not_applicable_title"
msgid "Green-Score not yet applicable"
msgstr "Green-Score not yet applicable"
msgid "Green-Score not applicable"
msgstr "Green-Score not applicable"

msgctxt "attribute_environmental_score_not_applicable_description_short"
msgid "Not yet applicable for the category"
msgstr "Not yet applicable for the category"
msgid "Not applicable for the category"
msgstr "Not applicable for the category"

# variable names between { } must not be translated
msgctxt "f_attribute_environmental_score_not_applicable_description"
Expand Down
12 changes: 6 additions & 6 deletions po/common/en.po
Original file line number Diff line number Diff line change
Expand Up @@ -5404,17 +5404,17 @@ msgid "User is being deleted. This may take a few minutes."
msgstr "User is being deleted. This may take a few minutes."

msgctxt "attribute_environmental_score_not_applicable_title"
msgid "Green-Score not yet applicable"
msgstr "Green-Score not yet applicable"
msgid "Green-Score not applicable"
msgstr "Green-Score not applicable"

msgctxt "attribute_environmental_score_not_applicable_description_short"
msgid "Not yet applicable for the category"
msgstr "Not yet applicable for the category"
msgid "Not applicable for the category"
msgstr "Not applicable for the category"

# variable names between { } must not be translated
msgctxt "f_attribute_environmental_score_not_applicable_description"
msgid "Not yet applicable for the category: {category}"
msgstr "Not yet applicable for the category: {category}"
msgid "Not applicable for the category: {category}"
msgstr "Not applicable for the category: {category}"

msgctxt "environmental_score_not_applicable_coming_soon"
msgid "The Green-Score is not yet applicable for this category, but we are working on adding support for it."
Expand Down
12 changes: 6 additions & 6 deletions po/common/fr.po
Original file line number Diff line number Diff line change
Expand Up @@ -5403,17 +5403,17 @@ msgid "User is being deleted. This may take a few minutes."
msgstr "L'utilisateur est en cours de suppression. Cela peut prendre quelques minutes."

msgctxt "attribute_environmental_score_not_applicable_title"
msgid "Green-Score not yet applicable"
msgstr "Green-Score n'est pas encore applicable"
msgid "Green-Score not applicable"
msgstr "Green-Score non applicable"

msgctxt "attribute_environmental_score_not_applicable_description_short"
msgid "Not yet applicable for the category"
msgstr "Pas encore applicable pour la catégorie"
msgid "Not applicable for the category"
msgstr "Non applicable pour la catégorie"

# variable names between { } must not be translated
msgctxt "f_attribute_environmental_score_not_applicable_description"
msgid "Not yet applicable for the category: {category}"
msgstr "Pas encore applicable pour la catégorie : {category}"
msgid "Not applicable for the category: {category}"
msgstr "Non applicable pour la catégorie : {category}"

msgctxt "environmental_score_not_applicable_coming_soon"
msgid "The Green-Score is not yet applicable for this category, but we are working on adding support for it."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"name": "[% panel.name %]",
"icon_url": "[% static_subdomain %]/images/attributes/dist/green-score-[% panel.grade %].svg",
"title": "[% panel.title %]",
"subtitle": "[% panel.subtitle %]",
"type": "grade",
"grade": "[% panel.grade_underscore %]"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
],
"title_element": {
"icon_url": "[% static_subdomain %]/images/attributes/dist/green-score-unknown.svg",
"title": "[% edq(lang('attribute_environmental_score_unknown_title')) %] - [% edq(lang('attribute_environmental_score_unknown_description_short')) %]",
"title": "[% edq(lang('attribute_environmental_score_unknown_title')) %]",
"subtitle": "[% edq(lang('attribute_environmental_score_unknown_description_short')) %]",
"type": "grade",
"grade": "unknown",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1105,7 +1105,8 @@
"grade" : "c",
"icon_url" : "http://static.openfoodfacts.localhost/images/attributes/dist/green-score-c.svg",
"name" : "Green-Score",
"title" : "Green-Score C - Moderate environmental impact",
"subtitle" : "Moderate environmental impact",
"title" : "Green-Score C",
"type" : "grade"
},
"topics" : [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1759,7 +1759,8 @@
"grade" : "c",
"icon_url" : "http://static.openfoodfacts.localhost/images/attributes/dist/green-score-c.svg",
"name" : "Green-Score",
"title" : "Green-Score C - Moderate environmental impact",
"subtitle" : "Moderate environmental impact",
"title" : "Green-Score C",
"type" : "grade"
},
"topics" : [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,8 @@
"grade" : "c",
"icon_url" : "http://static.openfoodfacts.localhost/images/attributes/dist/green-score-c.svg",
"name" : "Green-Score",
"title" : "Green-Score C - Moderate environmental impact",
"subtitle" : "Moderate environmental impact",
"title" : "Green-Score C",
"type" : "grade"
},
"topics" : [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,8 @@
"grade" : "c",
"icon_url" : "http://static.openfoodfacts.localhost/images/attributes/dist/green-score-c.svg",
"name" : "Green-Score",
"title" : "Green-Score C - Moderate environmental impact",
"subtitle" : "Moderate environmental impact",
"title" : "Green-Score C",
"type" : "grade"
},
"topics" : [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,8 @@
"grade" : "c",
"icon_url" : "http://static.openfoodfacts.localhost/images/attributes/dist/green-score-c.svg",
"name" : "Green-Score",
"title" : "Green-Score C - Impact modéré sur l'environnement",
"subtitle" : "Impact modéré sur l'environnement",
"title" : "Green-Score C",
"type" : "grade"
},
"topics" : [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,8 @@
"grade" : "c",
"icon_url" : "http://static.openfoodfacts.localhost/images/attributes/dist/green-score-c.svg",
"name" : "Green-Score",
"title" : "Green-Score C - Moderate environmental impact",
"subtitle" : "Moderate environmental impact",
"title" : "Green-Score C",
"type" : "grade"
},
"topics" : [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1099,7 +1099,8 @@
"grade" : "c",
"icon_url" : "http://static.openfoodfacts.localhost/images/attributes/dist/green-score-c.svg",
"name" : "Green-Score",
"title" : "Green-Score C - Moderate environmental impact",
"subtitle" : "Moderate environmental impact",
"title" : "Green-Score C",
"type" : "grade"
},
"topics" : [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1745,7 +1745,8 @@
"grade" : "c",
"icon_url" : "http://static.openfoodfacts.localhost/images/attributes/dist/green-score-c.svg",
"name" : "Green-Score",
"title" : "Green-Score C - Moderate environmental impact",
"subtitle" : "Moderate environmental impact",
"title" : "Green-Score C",
"type" : "grade"
},
"topics" : [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@
"grade" : "c",
"icon_url" : "http://static.openfoodfacts.localhost/images/attributes/dist/green-score-c.svg",
"name" : "Green-Score",
"title" : "Green-Score C - Moderate environmental impact",
"subtitle" : "Moderate environmental impact",
"title" : "Green-Score C",
"type" : "grade"
},
"topics" : [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,8 @@
"grade" : "c",
"icon_url" : "http://static.openfoodfacts.localhost/images/attributes/dist/green-score-c.svg",
"name" : "Green-Score",
"title" : "Green-Score C - Moderate environmental impact",
"subtitle" : "Moderate environmental impact",
"title" : "Green-Score C",
"type" : "grade"
},
"topics" : [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,8 @@
"grade" : "c",
"icon_url" : "http://static.openfoodfacts.localhost/images/attributes/dist/green-score-c.svg",
"name" : "Green-Score",
"title" : "Green-Score C - Impact modéré sur l'environnement",
"subtitle" : "Impact modéré sur l'environnement",
"title" : "Green-Score C",
"type" : "grade"
},
"topics" : [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,8 @@
"grade" : "c",
"icon_url" : "http://static.openfoodfacts.localhost/images/attributes/dist/green-score-c.svg",
"name" : "Green-Score",
"title" : "Green-Score C - Moderate environmental impact",
"subtitle" : "Moderate environmental impact",
"title" : "Green-Score C",
"type" : "grade"
},
"topics" : [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,8 @@
"title_element" : {
"grade" : "unknown",
"icon_url" : "http://static.openfoodfacts.localhost/images/attributes/dist/green-score-unknown.svg",
"title" : "Green-Score not computed - Unknown environmental impact",
"subtitle" : "Unknown environmental impact",
"title" : "Green-Score not computed",
"type" : "grade"
},
"topics" : [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@
"title_element" : {
"grade" : "unknown",
"icon_url" : "http://static.openfoodfacts.localhost/images/attributes/dist/green-score-unknown.svg",
"title" : "Green-Score not computed - Unknown environmental impact",
"subtitle" : "Unknown environmental impact",
"title" : "Green-Score not computed",
"type" : "grade"
},
"topics" : [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@
"title_element" : {
"grade" : "unknown",
"icon_url" : "http://static.openfoodfacts.localhost/images/attributes/dist/green-score-unknown.svg",
"title" : "Green-Score not computed - Unknown environmental impact",
"subtitle" : "Unknown environmental impact",
"title" : "Green-Score not computed",
"type" : "grade"
},
"topics" : [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2228,9 +2228,11 @@ <h2 class="panel_title_card text-medium">Environment</h2>

>

Green-Score D - High environmental impact
Green-Score D
</h4>

<span >High environmental impact</span>

<hr class="floatclear">
</a>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2228,9 +2228,11 @@ <h2 class="panel_title_card text-medium">Environment</h2>

>

Green-Score D - High environmental impact
Green-Score D
</h4>

<span >High environmental impact</span>

<hr class="floatclear">
</a>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2652,9 +2652,11 @@ <h2 class="panel_title_card text-medium">Environment</h2>

>

Green-Score C - Moderate environmental impact
Green-Score C
</h4>

<span >Moderate environmental impact</span>

<hr class="floatclear">
</a>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2834,9 +2834,11 @@ <h2 class="panel_title_card text-medium">Environnement</h2>

>

Green-Score B - Faible impact environnemental
Green-Score B
</h4>

<span >Faible impact environnemental</span>

<hr class="floatclear">
</a>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2848,9 +2848,11 @@ <h2 class="panel_title_card text-medium">Environnement</h2>

>

Green-Score B - Faible impact environnemental
Green-Score B
</h4>

<span >Faible impact environnemental</span>

<hr class="floatclear">
</a>

Expand Down
Loading

0 comments on commit 1eb84a5

Please sign in to comment.