-
-
Notifications
You must be signed in to change notification settings - Fork 384
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
run script to check that .po files don't have empty strings
- Loading branch information
1 parent
28e62c1
commit 9ec83be
Showing
2 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |