Skip to content

Commit

Permalink
fix: remove nutrient_levels.txt which is generated by Food.pm (#9851)
Browse files Browse the repository at this point in the history
as the file changes when translations in .po files change

---------

Co-authored-by: Alex Garel <[email protected]>
  • Loading branch information
stephanegigandet and alexgarel authored Mar 6, 2024
1 parent a3fcac9 commit 421dc91
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 2,287 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ cache
taxonomies/*.sto
taxonomies/*.result.txt
taxonomies/*.all.txt
# nutrient_levels.txt is generated by Food.pm
taxonomies/nutrient_levels.txt
/build-cache/taxonomies/*.json
/build-cache/taxonomies/*.sto
/build-cache/taxonomies/*.result.txt
2 changes: 1 addition & 1 deletion lib/ProductOpener/Food.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2472,7 +2472,7 @@ sub create_nutrients_level_taxonomy() {

open(my $OUT, ">:encoding(UTF-8)", "$data_root/taxonomies/nutrient_levels.txt");
print $OUT <<TXT
# nutrient levels taxonomy generated automatically by Food.pm
# nutrient levels taxonomy generated automatically by Food.pm from nutrients taxonomy + language translations (.po files)
TXT
;
Expand Down
17 changes: 14 additions & 3 deletions lib/ProductOpener/Tags.pm
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ BEGIN {
&gen_tags_hierarchy_taxonomy
&gen_ingredients_tags_hierarchy_taxonomy
&display_tags_hierarchy_taxonomy
&build_tags_taxonomy
&build_all_taxonomies
&list_taxonomy_tags_in_language
Expand Down Expand Up @@ -1184,7 +1185,7 @@ sub build_tags_taxonomy ($tagtype, $publish) {
return;
}

print "building taxonomy for $tagtype - publish: $publish\n";
print("building taxonomy for $tagtype - publish: $publish\n");

# Concatenate taxonomy files if needed
my $file = "$tagtype.txt";
Expand Down Expand Up @@ -2462,9 +2463,19 @@ sub retrieve_tags_taxonomy ($tagtype) {
}
}

# Build taxonomies on the fly
if (!-e "$data_root/taxonomies/$file.result.sto") {
print "Building $file on the fly\n";
build_tags_taxonomy($file, 1);
print("Building $file on the fly\n");
# Nutrients levels taxonomy is generated from the nutrients taxonomy + language translations in Food.pm
# nutrients_levels.txt is not checked in the taxonomy directory and will be generated by build_lang.pl
# To avoid circular dependencies, we don't build it on the fly when Tags.pm is loaded.
if (($tagtype eq "nutrient_levels") and (!-e "$data_root/taxonomies/$file.txt")) {
print("Skipping nutrient_levels.txt as it is has not been generated by build_lang.pl yet\n");
return;
}
else {
build_tags_taxonomy($file, 1);
}
}

my $taxonomy_ref = retrieve("$data_root/taxonomies/$file.result.sto")
Expand Down
2 changes: 1 addition & 1 deletion scripts/build_lang.pl
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
# Generate JSON files for JavaScript I18N
ProductOpener::Lang::build_json();

# Nutrients level taxonomy file is build using languages
# Nutrients level taxonomy file is built using languages
create_nutrients_level_taxonomy();

exit(0);
Expand Down
Loading

0 comments on commit 421dc91

Please sign in to comment.