Skip to content

Commit

Permalink
fix: add field id to examples configuration spreadsheet (#9985)
Browse files Browse the repository at this point in the history
Fixes to @TheSussex 's PR #9975

- added a row with field ids in the spreadsheet configuration file that contains the examples
- uses the id in order to select the example value
---------

Co-authored-by: TheSussex <[email protected]>
  • Loading branch information
stephanegigandet and TheSussex authored Mar 24, 2024
1 parent 9e8a479 commit ccf5d37
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 15 deletions.
42 changes: 30 additions & 12 deletions cgi/generate_sample_import_file.pl
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,42 @@
align => 'center'
),
description => $workbook->add_format(italic => 1, text_wrap => 1, valign => 'vcenter'),
example => $workbook->add_format(italic => 1, valign => 'vcenter', text_wrap => 1,),
);

# Re-use the structure used to output select2 options in import_file_select_format.pl
my $select2_options_ref = generate_import_export_columns_groups_for_select2([$lc]);

my $headers_row = 0;

my $description_row = 1;
my $example_row = 2;
my $col = 1;

my $description = lang("description");
my $field_id;
my $comment;

my $example = lang("example");
my $example_tsv_file = 'conf/pro-platform/Import template - Example translations - Import sheet.tsv';
my %example_values_by_language_and_header;

open(my $example_fh, '<', $example_tsv_file) or die "Cannot open $example_tsv_file: $!";
my $header_line = <$example_fh>;
chomp($header_line);
my @headers = split("\t", $header_line);
while (my $line = <$example_fh>) {
chomp($line);
my @values = split("\t", $line);
my $line_lc = $values[0];
next if not $line_lc; # Skip lines that don't have a language set (e.g. the 2nd line with English colunm names)
for my $i (0 .. $#headers) {
next if $headers[$i] eq 'lc';
$example_values_by_language_and_header{$line_lc}{$headers[$i]} = $values[$i] if defined $values[$i];
}
}
close($example_fh);

$worksheet->set_row(0, 70);
$worksheet->set_column('A:ZZ', 30);
$worksheet->set_column('A:A', 30);
Expand Down Expand Up @@ -169,18 +192,8 @@
}
}

my $example = lang($field_id . "_example");

if ($example ne "") {

my $example_title = lang("example");

# Several examples?
if ($example =~ /,/) {
$example_title = lang("examples");
}
$comment .= $example_title . " " . $example . "\n\n";
}
my $line_lc = lc($request_ref->{lc} || 'en');
my $example_value = $example_values_by_language_and_header{$line_lc}{$field_ref->{id}} // '';

# Set a different format for mandatory / recommended / optional fields

Expand Down Expand Up @@ -224,6 +237,11 @@
$worksheet->write($description_row, $col, $comment, $formats{'description'});
}

if ($example_value) {
$worksheet->write($example_row, 0, $example, $formats{'example'});
$worksheet->write($example_row, $col, $example_value, $formats{'example'});
}

$col++;

$log->debug("field - comment", {group_id => $group_id, field_id => $field_id, comment => $comment})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
lc Barcode Main language Product name Quantity Brands Categories Labels Countries where sold Ingredients list Allergens Traces Energy (kJ) for 100 g / 100 ml Energy (kcal) for 100 g / 100 ml Fat for 100 g / 100 ml Saturated fat for 100 g / 100 ml Carbohydrates for 100 g / 100 ml Sugars for 100 g / 100 ml Fiber for 100 g / 100 ml Proteins for 100 g / 100 ml Salt for 100 g / 100 ml Link to front product photo Link to ingredients list photo Link to nutrition facts table photo
en 3228857000838 en American Sandwich Nature 550 g Harrys Bran sliced breads Organic, No additives Spain, France, Italy wheat flour 65%, water, sugar, rapeseed oil, salt, vinegar, yeast, flour of beans, wheat gluten, flavor (contains alcohol), extract of acerola, may contain traces of eggs, soya, milk, fruit shell, sesame seeds Gluten Eggs, Milk, Nuts, Sesame seeds, Soybeans 1172 271 4.1 0.4 48.9 7.7 3.9 7.6 1.1 https://drive.google.com/file/d/1N6K0GOy8ZrO21732XF1M6klhRrzyAaaP/view?usp=sharing https://drive.google.com/file/d/14181RIHe89KN2aPzT3C2NQYqFZficOwE/view?usp=drive_link https://drive.google.com/file/d/1e8sW-Xp5QXc41V5ry-hLn8T8s13fvS38/view?usp=sharing
fr 3228857000838 fr Sandwich américain nature 550 g Harrys Pains de mie tranchés Bio, sans additifs Espagne, France, Italie farine de blé 65%, eau, sucre, huile de colza, sel, vinaigre, levure, farine d'haricots, gluten de blé, arôme Gluten Oeufs, lait, fruits à coque, graines de sésame, soja 1172 271 4.1 0.4 48.9 7.7 3.9 7.6 1.1 https://drive.google.com/file/d/1N6K0GOy8ZrO21732XF1M6klhRrzyAaaP/view?usp=sharing https://drive.google.com/file/d/14181RIHe89KN2aPzT3C2NQYqFZficOwE/view?usp=drive_link https://drive.google.com/file/d/1e8sW-Xp5QXc41V5ry-hLn8T8s13fvS38/view?usp=sharing
code lc product_name quantity_value_unit brands categories labels origins ingredients_text allergens traces energy-kj_100g_value_unit energy-kcal_100g_value_unit fat_100g_value_unit saturated-fat_100g_value_unit carbohydrates_100g_value_unit sugars_100g_value_unit fiber_100g_value_unit proteins_100g_value_unit salt_100g_value_unit fruits-vegetables-nuts_100g_value_unit fruits-vegetables-nuts-dried_100g_value_unit packaging_text image_front_url_fr image_ingredients_url_fr image_nutrition_url_fr image_packaging_url_fr image_other_type
Barcode Main language Product name Quantity Brands Categories Labels Countries where sold Ingredients list Allergens Traces Energy (kJ) for 100 g / 100 ml Energy (kcal) for 100 g / 100 ml Fat for 100 g / 100 ml Saturated fat for 100 g / 100 ml Carbohydrates for 100 g / 100 ml Sugars for 100 g / 100 ml Fiber for 100 g / 100 ml Proteins for 100 g / 100 ml Salt for 100 g / 100 ml Link to front product photo Link to ingredients list photo Link to nutrition facts table photo
en 3228857000838 en American Sandwich Nature 550 g Harrys Bran sliced breads Organic, No additives Spain, France, Italy wheat flour 65%, water, sugar, rapeseed oil, salt, vinegar, yeast, flour of beans, wheat gluten, flavor (contains alcohol), extract of acerola, may contain traces of eggs, soya, milk, fruit shell, sesame seeds Gluten Eggs, Milk, Nuts, Sesame seeds, Soybeans 1172 271 4.1 0.4 48.9 7.7 3.9 7.6 1.1 https://drive.google.com/file/d/1N6K0GOy8ZrO21732XF1M6klhRrzyAaaP/view?usp=sharing https://drive.google.com/file/d/14181RIHe89KN2aPzT3C2NQYqFZficOwE/view?usp=drive_link https://drive.google.com/file/d/1e8sW-Xp5QXc41V5ry-hLn8T8s13fvS38/view?usp=sharing
fr 3228857000838 fr Sandwich américain nature 550 g Harrys Pains de mie tranchés Bio, sans additifs Espagne, France, Italie farine de blé 65%, eau, sucre, huile de colza, sel, vinaigre, levure, farine d'haricots, gluten de blé, arôme Gluten Oeufs, lait, fruits à coque, graines de sésame, soja 1172 271 4.1 0.4 48.9 7.7 3.9 7.6 1.1 https://drive.google.com/file/d/1N6K0GOy8ZrO21732XF1M6klhRrzyAaaP/view?usp=sharing https://drive.google.com/file/d/14181RIHe89KN2aPzT3C2NQYqFZficOwE/view?usp=drive_link https://drive.google.com/file/d/1e8sW-Xp5QXc41V5ry-hLn8T8s13fvS38/view?usp=sharing
Binary file modified conf/pro-platform/Import template - Example translations.xlsx
Binary file not shown.

0 comments on commit ccf5d37

Please sign in to comment.