From 8048013eaef26f7d153e37870746a51d54559850 Mon Sep 17 00:00:00 2001 From: Alex Garel Date: Thu, 2 Jun 2022 11:39:46 +0200 Subject: [PATCH] fix: ingredients and nutrition should have titles (#6839) * fix: ingredients and nutrition should have titles because we made them collapsible. fixes: #6835 --- icons/ingredients.svg | 1 + icons/nutrition.svg | 1 + lib/ProductOpener/KnowledgePanels.pm | 10 ++++++++++ po/common/common.pot | 12 ++++++++++++ po/common/en.po | 12 ++++++++++++ .../health/ingredients/ingredients.tt.json | 7 +++++-- .../health/nutrition/nutrition_facts_table.tt.json | 10 ++++++---- 7 files changed, 47 insertions(+), 6 deletions(-) create mode 100644 icons/ingredients.svg create mode 100644 icons/nutrition.svg diff --git a/icons/ingredients.svg b/icons/ingredients.svg new file mode 100644 index 0000000000000..d06393ca59f10 --- /dev/null +++ b/icons/ingredients.svg @@ -0,0 +1 @@ + diff --git a/icons/nutrition.svg b/icons/nutrition.svg new file mode 100644 index 0000000000000..87fbca67fabd5 --- /dev/null +++ b/icons/nutrition.svg @@ -0,0 +1 @@ + diff --git a/lib/ProductOpener/KnowledgePanels.pm b/lib/ProductOpener/KnowledgePanels.pm index 6b817aab3841c..c639c3343ce88 100644 --- a/lib/ProductOpener/KnowledgePanels.pm +++ b/lib/ProductOpener/KnowledgePanels.pm @@ -1031,7 +1031,17 @@ sub create_ingredients_panel($$$) { $ingredients_text_lc = $target_lc; } + my $title =""; + if (!(defined $product_ref->{ingredients_n}) or ($product_ref->{ingredients_n} == 0)) { + $title = lang("no_ingredient"); + } elsif ($product_ref->{ingredients_n} == 1) { + $title = lang("one_ingredient"); + } else { + $title = f_lang("f_ingredients_with_number", { number => $product_ref->{ingredients_n} }); + } + my $panel_data_ref = { + title => $title, ingredients_text => $ingredients_text, ingredients_text_with_allergens => $ingredients_text_with_allergens, ingredients_text_lc => $ingredients_text_lc, diff --git a/po/common/common.pot b/po/common/common.pot index c0e39f34514cc..68633e2fe5068 100644 --- a/po/common/common.pot +++ b/po/common/common.pot @@ -1056,6 +1056,18 @@ msgctxt "ingredients" msgid "Ingredients" msgstr "" +msgctxt "no_ingredient" +msgid "Ingredients are missing" +msgstr "Ingredients are missing" + +msgctxt "one_ingredient" +msgid "1 ingredient" +msgstr "1 ingredient" + +msgctxt "f_ingredients_with_number" +msgid "{number} ingredients" +msgstr "{number} ingredients" + msgctxt "ingredients_alt" msgid "Ingredients" msgstr "" diff --git a/po/common/en.po b/po/common/en.po index 7798549a58411..79dac2a26fb5b 100644 --- a/po/common/en.po +++ b/po/common/en.po @@ -1018,6 +1018,18 @@ msgctxt "ingredients" msgid "Ingredients" msgstr "Ingredients" +msgctxt "no_ingredient" +msgid "Ingredients are missing" +msgstr "Ingredients are missing" + +msgctxt "one_ingredient" +msgid "1 ingredient" +msgstr "1 ingredient" + +msgctxt "f_ingredients_with_number" +msgid "{number} ingredients" +msgstr "{number} ingredients" + msgctxt "ingredients_alt" msgid "Ingredients" msgstr "Ingredients" diff --git a/templates/api/knowledge-panels/health/ingredients/ingredients.tt.json b/templates/api/knowledge-panels/health/ingredients/ingredients.tt.json index fc55df38038be..d4b04a3b34260 100644 --- a/templates/api/knowledge-panels/health/ingredients/ingredients.tt.json +++ b/templates/api/knowledge-panels/health/ingredients/ingredients.tt.json @@ -3,16 +3,19 @@ "topics": [ "health" ], - "type": "inline", "expanded": false, "expand_for": "large", + "title_element": { + "title":"[% panel.title %]", + "icon_url": "[% static_subdomain %]/images/icons/dist/ingredients.svg", + }, "elements": [ { "element_type": "text", "text_element": { "html": `[% panel.ingredients_text_with_allergens %]`, "lc": "[% panel.ingredients_text_lc %]", - "language": "[% panel.ingredients_text_language %]", + "language": "[% panel.ingredients_text_language %]", "edit_field_type": "ingredients_text", "edit_field_id": "ingredients_text_[% panel.ingredients_text_lc %]", "edit_field_value": `[% panel.ingredients_text %]`, diff --git a/templates/api/knowledge-panels/health/nutrition/nutrition_facts_table.tt.json b/templates/api/knowledge-panels/health/nutrition/nutrition_facts_table.tt.json index 55b026acd728e..15f06ff26850f 100644 --- a/templates/api/knowledge-panels/health/nutrition/nutrition_facts_table.tt.json +++ b/templates/api/knowledge-panels/health/nutrition/nutrition_facts_table.tt.json @@ -3,15 +3,17 @@ "topics": [ "health" ], - "type": "inline", "expanded": false, "expand_for": "large", - "elements": [ + "title_element": { + "title": "[% lang('nutrition_data_table') %]", + "icon_url": "[% static_subdomain %]/images/icons/dist/nutrition.svg", + }, + "elements": [ { "element_type": "table", "table_element": { "id": "nutrition_facts_table", - "title": "[% lang('nutrition_data_table') %]", // Create a structure to check if we already have seen a column for a given scope // so that we can mark the first one as the default column for the group [% SET scopes = {} %] @@ -67,7 +69,7 @@ [% END %] ] } - }, + }, ] }