Permalink
Fetching contributors…
Cannot retrieve contributors at this time
executable file 85 lines (70 sloc) 2.25 KB
#!/usr/bin/perl -w
use strict;
# Generates EmptyHomes version of .po file, which is a translation
# into a language the same as English, only "problem" becomes "empty property".
use POSIX;
use FindBin;
use lib "$FindBin::Bin/../perllib";
use PoChange;
chdir("$FindBin::Bin/../locale");
mkdir("en_GB.UTF-8");
mkdir("en_GB.UTF-8/LC_MESSAGES");
open(MAINPO, "FixMyStreet.po") or die "";
open(EHAPO, ">FixMyStreet-EmptyHomes.po") or die "";
open(NEWPO, ">en_GB.UTF-8/LC_MESSAGES/FixMyStreet-EmptyHomes.po") or die "";
print NEWPO "# AUTOMATICALLY GENERATED by make_emptyhomes_po, do not edit\n";
print NEWPO "#\n";
print EHAPO "# AUTOMATICALLY GENERATED by make_emptyhomes_po, do not edit\n";
print EHAPO "#\n";
my $buffer = "";
my $start = 0;
while(<MAINPO>) {
if (!$start) {
s/#, fuzzy/#/;
}
if (m/"Last-Translator: FULL NAME/) {
$_ = '"Last-Translator: mysociety/bin/make_emptyhomes_po\\n"'."\n";
}
if (m/"PO-Revision-Date: YEAR-MO-DA/) {
my $time = POSIX::strftime("%Y-%m-%d %H:%M%z", localtime(time()));
$_ = '"PO-Revision-Date: '.$time.'\\n"'."\n";
}
if (m/"Language-Team: LANGUAGE/) {
$_ = '"Language-Team: mySociety\\n"'."\n";
}
if (m/"Plural-Forms: nplurals=/) {
$_ = '"Plural-Forms: nplurals=2; plural=n != 1;\\n"'."\n";
}
if (m/^#/) {
# comment or blank line
print NEWPO $_;
print EHAPO $_;
} elsif (m/^\s+$/) {
# blank line
$start = 1;
$buffer = "";
print NEWPO $_;
print EHAPO $_;
} elsif ($start && (m/^msgstr ""/ || m/^msgstr\[0\] ""/)) {
# start of translated text - translate English into Empty Homes language
$buffer = PoChange::fixmystreet_to_reportemptyhomes($buffer);
print EHAPO $buffer;
if (m/^msgstr\[0\] ""/) {
$buffer =~ s/^msgid "/msgstr[0] "/m;
$buffer =~ s/^msgid_plural "/msgstr[1] "/m;
print EHAPO $_;
$_ = <MAINPO>; # skip untranslated plural
print EHAPO $_;
} else {
$buffer =~ s/^msgid "/msgstr "/;
print EHAPO $_;
}
print NEWPO $buffer;
$buffer = "";
} else {
# English text
print NEWPO $_;
print EHAPO $_ unless $start;
$buffer .= $_;
}
}