diff options
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/gettext-extract | 53 | ||||
-rwxr-xr-x | bin/make_emptyhomes_po | 79 |
2 files changed, 132 insertions, 0 deletions
diff --git a/bin/gettext-extract b/bin/gettext-extract new file mode 100755 index 000000000..70ed66a4f --- /dev/null +++ b/bin/gettext-extract @@ -0,0 +1,53 @@ +#!/bin/bash +# +# bci/bin/gettext-extract +# Generate English language .po files from the source code and email templates, +# for FixMyStreet. Writes the output to appropriate .po files in locale/. +# +# Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved. +# Email: matthew@mysociety.org; WWW: http://www.mysociety.org/ +# +# $Id: gettext-extract,v 1.1 2008-05-06 10:01:23 matthew Exp $ + +if [ -e ../../locale ] +then + cd ../../ +else if [ -e ../locale ] +then + cd ../ +else if [ -e locale ] +then + cd . +else + echo "Please run with current directory bci/bin" + exit 1 +fi +fi +fi + + +# File to write to, clear it to start with +PO=locale/FixMyStreet.po +rm -f $PO + +# Extract from Perl +xgettext --add-comments=TRANS --language=Perl --keyword=_ --from-code=utf-8 -o $PO perllib/mySociety/*.pm bci/perllib/*.pm bci/web/*.cgi bci/bin/send-reports + +# Fix headers +TEMP=`tempfile` +cat $PO | sed " + s/SOME DESCRIPTIVE TITLE/FixMyStreet original .po file, autogenerated by gettext-extract/; + s/YEAR THE PACKAGE'S COPYRIGHT HOLDER/2008 UK Citizens Online Democracy/; + s/PACKAGE package/main FixMyStreet code/; + s/FIRST AUTHOR <EMAIL@ADDRESS>, YEAR./Matthew Somerville <matthew@mysociety.org>, 2008-04-15./; + + s/PACKAGE VERSION/1.0/; + s/Report-Msgid-Bugs-To: /Report-Msgid-Bugs-To: matthew@mysociety.org/; + s/LL@li.org/team@fixmystreet.com/; + s/charset=CHARSET/charset=UTF-8/; +" >> $TEMP +mv $TEMP $PO + +# XXX: Email templates - should be in >1 language... +# And the XSL page too. + diff --git a/bin/make_emptyhomes_po b/bin/make_emptyhomes_po new file mode 100755 index 000000000..69e8c625b --- /dev/null +++ b/bin/make_emptyhomes_po @@ -0,0 +1,79 @@ +#!/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; + +chdir("$FindBin::Bin/../../locale"); +mkdir("en_GB.UTF-8"); +mkdir("en_GB.UTF-8/LC_MESSAGES"); + +open(MAINPO, "FixMyStreet.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"; + +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: Live Simply Promise\\n"'."\n"; + } + if (m/"Plural-Forms: nplurals=/) { + $_ = '"Plural-Forms: nplurals=2; plural=n != 1;\\n"'."\n"; + } + + if (m/^#/) { + # comment or blank line + print NEWPO $_; + } elsif (m/^\s+$/) { + # blank line + $start = 1; + $buffer = ""; + print NEWPO $_; + } elsif ($start && (m/^msgstr ""/ || m/^msgstr\[0\] ""/)) { + # start of translated text - translate English into Live Simple Promise + # langauage + if (m/^msgstr\[0\] ""/) { + $buffer =~ s/^msgid "/msgstr[0] "/m; + $buffer =~ s/^msgid_plural "/msgstr[1] "/m; + <MAINPO>; # skip untranslated plural + } else { + $buffer =~ s/^msgid "/msgstr "/; + } + + # Basics + $buffer =~ s/FixMyStreet/Empty Homes Agency/g; + $buffer =~ s/\bproblem\b/empty property/g; + $buffer =~ s/\bProblem\b/Empty property/g; + $buffer =~ s/\bproblems\b/empty properties/g; + $buffer =~ s/\bProblems\b/Empty properties/g; + $buffer =~ s/a empty/an empty/g; + + $buffer =~ s/^\(like graffiti.*/ /; + + print NEWPO $buffer; + $buffer = ""; + } else { + # English text + print NEWPO $_; + $buffer .= $_; + } + + +} + |