Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

executable file 109 lines (94 sloc) 2.91 kb
#!/usr/bin/perl -w
use strict;
# Given a translation of the Empty Homes version of the FixMyStreet .po file,
# fix it all up to go direct from FixMyStreet -> EH translation.
use POSIX;
use FindBin;
use lib "$FindBin::Bin/../perllib";
use PoChange;
chdir("$FindBin::Bin/../locale");
# First read in translation and match up.
open(INPO, 'cy_GB.UTF-8/LC_MESSAGES/EmptyHomes.po') or die $!;
my $state = 'start';
my $msgid = '';
my $fuzzy = 0;
my $msgstr;
my %lookup;
while (<INPO>) {
if (m/^#, fuzzy/) {
$fuzzy = 1;
} elsif (m/^#/) {
# comment or blank line
} elsif (m/^\s+$/) {
# blank line separates translations
$msgid =~ s/"\n"//g;
$lookup{$msgid} = [ $msgstr, $fuzzy ];
$state = 'msgid';
$msgid = "";
$fuzzy = 0;
} elsif ($state eq 'msgid' && (m/^msgstr "/ || m/^msgstr\[0\] "/)) {
$msgstr = $_;
$state = 'msgstr';
} elsif ($state eq 'msgstr') {
$msgstr .= $_;
} elsif ($state eq 'msgid') {
$msgid .= $_;
}
}
$lookup{$msgid} = [ $msgstr, $fuzzy ];
close INPO;
mkdir("en_GB.UTF-8");
mkdir("en_GB.UTF-8/LC_MESSAGES");
mkdir("cy_GB.UTF-8");
mkdir("cy_GB.UTF-8/LC_MESSAGES");
open(MAINPO, 'FixMyStreet.po') or die;
open(OUTPO, ">cy_GB.UTF-8/LC_MESSAGES/FixMyStreet-EmptyHomes.po") or die;
print OUTPO "# AUTOMATICALLY GENERATED by make_emptyhomes_welsh_po, do not edit\n\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 OUTPO $_;
} elsif (m/^\s+$/) {
# blank line
$start = 1;
$buffer = "";
print OUTPO $_;
} elsif ($start && (m/^msgstr "/ || m/^msgstr\[0\] "/)) {
# start of translated text - translate English into Empty Homes language
my $new_buffer = PoChange::fixmystreet_to_reportemptyhomes($buffer);
$new_buffer =~ s/"\n"//g;
if ($lookup{$new_buffer} && $lookup{$new_buffer}[1]) {
print OUTPO "#, fuzzy\n";
}
print OUTPO $buffer;
if ($lookup{$new_buffer}) {
print OUTPO $lookup{$new_buffer}[0];
} else {
print __LINE__ . "\n";
die "Failed to find match with buffer: $new_buffer";
}
$buffer = "";
} elsif (!$start) {
print OUTPO $_;
} else {
$buffer .= $_;
}
}
Jump to Line
Something went wrong with that request. Please try again.