diff options
Diffstat (limited to 'bin/make_po')
-rwxr-xr-x | bin/make_po | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/bin/make_po b/bin/make_po new file mode 100755 index 000000000..76dc4566b --- /dev/null +++ b/bin/make_po @@ -0,0 +1,86 @@ +#!/usr/bin/perl -w +use strict; + +# Generates a version of .po file, which is a translation +# into a language the same as English, with replacement as specified in PoChange + +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"); + +my $pofile = shift; + +open(MAINPO, "FixMyStreet.po") or die ""; +open(EHAPO, ">$pofile.po") or die ""; +open(NEWPO, ">en_GB.UTF-8/LC_MESSAGES/$pofile.po") or die ""; + +print NEWPO "# AUTOMATICALLY GENERATED by make_po, do not edit\n"; +print NEWPO "#\n"; + +print EHAPO "# AUTOMATICALLY GENERATED by make_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_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::translate($pofile, $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 .= $_; + } + +} + |