Skip to content

Commit

Permalink
run script to check that .po files don't have empty strings
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanegigandet committed Sep 29, 2017
1 parent 28e62c1 commit 9ec83be
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
55 changes: 55 additions & 0 deletions scripts/check_po_file.pl
Original file line number Diff line number Diff line change
@@ -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);

0 comments on commit 9ec83be

Please sign in to comment.