From 9ec83bef86bfa7c01507011869f6b4208af43a4c Mon Sep 17 00:00:00 2001 From: Stephane Gigandet Date: Fri, 29 Sep 2017 20:00:15 +0200 Subject: [PATCH] run script to check that .po files don't have empty strings --- .travis.yml | 1 + scripts/check_po_file.pl | 55 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100755 scripts/check_po_file.pl diff --git a/.travis.yml b/.travis.yml index 2d1eaf5e96498..d9db677d0bbbc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -31,6 +31,7 @@ install: - sed -i -e 's|\$server_domain = "openfoodfacts.org";|\$server_domain = "off.travis-ci.org";|g' $TRAVIS_BUILD_DIR/lib/ProductOpener/Config2.pm - sed -i -e 's|\/home\/off|'$TRAVIS_BUILD_DIR'|g' $TRAVIS_BUILD_DIR/lib/ProductOpener/Config2.pm script: + - scripts/check_po_file.pl $TRAVIS_BUILD_DIR/po/tags/en.po - prove -l - perl -c -CS -I$TRAVIS_BUILD_DIR/lib lib/startup_apache2.pl - perl -c -CS -I$TRAVIS_BUILD_DIR/lib cgi/product_multilingual.pl diff --git a/scripts/check_po_file.pl b/scripts/check_po_file.pl new file mode 100755 index 0000000000000..e20189fcf5c93 --- /dev/null +++ b/scripts/check_po_file.pl @@ -0,0 +1,55 @@ +#!/usr/bin/perl + +use strict; +use utf8; +use warnings; + +my $file = $ARGV[0]; + +if (not defined $file) { + print STDERR "Pass path to .po file to test as first argument.\n"; + exit(1); +} + +print STDERR "Testing $file .po file"; + + +open (my $IN, "<:encoding(UTF-8)", "$file") or die("Could not read $file: $!"); +my @lines = (<$IN>); +close ($IN); + +my %vars = (); +my $key; + +my $errors = 0; + +foreach my $line (@lines) { + + if ($line =~ /^(msgctxt|msgstr|msgid) "(.*)"/) { + $key = $1; + my $value = $2; + if ($key eq "msgctxt") { + + if (defined $vars{"msgctxt"}) { + + # check that we do not have an empty value for the previous msgctxt + + if ((not defined $vars{"msgstr"}) or ($vars{"msgstr"} eq "")) { + print STDERR "Error: empty msgstr string for msgctxt " . $vars{"msgctxt"} . " - msgid " . $vars{"msgid"} . "\n"; + $errors++; + } + + } + + %vars = (); + + + } + defined $vars{$key} or $vars{$key} = ""; + $vars{$key} .= $value; + } + +} + +print STDERR "$errors errors\n"; +exit($errors); \ No newline at end of file