aboutsummaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rwxr-xr-xbin/gettext-extract53
-rwxr-xr-xbin/gettext-merge40
-rwxr-xr-xbin/gettext-nget-patch44
-rw-r--r--bin/localise_templates36
4 files changed, 173 insertions, 0 deletions
diff --git a/bin/gettext-extract b/bin/gettext-extract
new file mode 100755
index 0000000..75b95f1
--- /dev/null
+++ b/bin/gettext-extract
@@ -0,0 +1,53 @@
+#!/bin/bash
+#
+# fixmystreet/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) 2011 UK Citizens Online Democracy. All rights reserved.
+# Email: matthew@mysociety.org; WWW: http://www.mysociety.org/
+
+if [ -e ../../locale ]
+then
+ cd ../../
+else if [ -e ../locale ]
+then
+ cd ../
+else if [ -e locale ]
+then
+ cd .
+else
+ echo "Please run with current directory fixmystreet/bin"
+ exit 1
+fi
+fi
+fi
+
+# File to write to, clear it to start with
+PO=locale/FixMyStreetMobileApp.po
+rm -f $PO
+
+# Extract from Perl
+xgettext.pl --gnu-gettext --verbose --output $PO --plugin perl=* --plugin tt2 --directory templates
+
+# Fix headers
+# no such thing as tempfile on OS X
+TEMP=`tempfile 2>/dev/null || mktemp /tmp/gettext-extract.XXXXXX`
+NOW=`date +"%Y-%m-%d %H:%M%z"`
+# strictly POSIX sed on e.g. OS X doesn't let you used \n in replacements so we do this
+nl=$'\n';
+cat $PO | sed "
+ s/SOME DESCRIPTIVE TITLE/FixMyStreet mobile app original .po file, autogenerated by gettext-extract/;
+ s/YEAR THE PACKAGE'S COPYRIGHT HOLDER/2013 UK Citizens Online Democracy/;
+ s/PACKAGE package/main FixMyStreet code/;
+ s/FIRST AUTHOR <EMAIL@ADDRESS>, YEAR./Struan Donald <struan@mysociety.org>, 2013./;
+
+ s/PACKAGE VERSION/1.0\\\n\"\\$nl\"Report-Msgid-Bugs-To: struan@mysociety.org/;
+ s/POT-Creation-Date: YEAR-MO-DA HO:MI+ZONE/POT-Creation-Date: $NOW/;
+ s/LL@li.org/team@fixmystreet.com/;
+ s/charset=CHARSET/charset=UTF-8/;
+ s/8bit/8bit\\\n\"\\$nl\"Plural-Forms: nplurals=2; plural=n != 1;/;
+" >> $TEMP
+mv $TEMP $PO
+
+echo "$( bin/gettext-nget-patch )" >> $PO
diff --git a/bin/gettext-merge b/bin/gettext-merge
new file mode 100755
index 0000000..9137698
--- /dev/null
+++ b/bin/gettext-merge
@@ -0,0 +1,40 @@
+#!/bin/bash
+#
+# bin/gettext-merge
+# Update all .po files from new .pot
+#
+# Copyright (c) 2013 UK Citizens Online Democracy. All rights reserved.
+# Email: matthew@mysociety.org; WWW: http://www.mysociety.org/
+
+# Yuck
+if [ -e ../../locale ]
+then
+ cd ../../
+else if [ -e ../locale ]
+then
+ cd ../
+else if [ -e locale ]
+then
+ cd .
+else
+ echo "Please run with current directory fixmystreet"
+ exit 1
+fi
+fi
+fi
+
+for X in locale/*.UTF-8
+do
+ if [ -d $X ]
+ then
+ cd $X/LC_MESSAGES
+ echo $X
+ if [ -e FixMyStreetMobileApp.po ]
+ then
+ msgmerge -o New.po FixMyStreetMobileApp.po ../../FixMyStreetMobileApp.po
+ mv New.po FixMyStreetMobileApp.po
+ fi
+ cd - >/dev/null
+ fi
+done
+
diff --git a/bin/gettext-nget-patch b/bin/gettext-nget-patch
new file mode 100755
index 0000000..5ebd8bb
--- /dev/null
+++ b/bin/gettext-nget-patch
@@ -0,0 +1,44 @@
+#!/usr/bin/perl
+#
+# xgettext doesn't deal with TT files, but xgettext.pl doesn't find nget()s, sigh.
+# This will find the nget()s and output a .po file excerpt.
+
+use File::Find qw/find/;
+
+my %out;
+
+find( sub {
+ next unless -f;
+ next if $File::Find::name =~ /ttc$/;
+ open (FP, $_) or die $!;
+ while (<FP>) {
+ next unless /nget/;
+ my $line = $.;
+ my $text = $_;
+ do {
+ $text .= <FP>;
+ } until $text =~ /\)/;
+ if ($text =~ /nget\(\s*"(.*?)"\s*,\s*"(.*?)"\s*,\s*(.*?)\s*\)/s) {
+ $out{$1} = {
+ file => $File::Find::name,
+ line => $line,
+ s => $1,
+ p => $2,
+ };
+ }
+ }
+ close FP;
+}, 'templates', 'perllib');
+
+foreach (values %out) {
+ print <<EOF;
+
+#: $_->{file}:$_->{line}
+#, perl-format
+msgid "$_->{s}"
+msgid_plural "$_->{p}"
+msgstr[0] ""
+msgstr[1] ""
+EOF
+}
+
diff --git a/bin/localise_templates b/bin/localise_templates
new file mode 100644
index 0000000..372535b
--- /dev/null
+++ b/bin/localise_templates
@@ -0,0 +1,36 @@
+#!/bin/env perl
+
+use strict;
+use warnings;
+use Template;
+use mySociety::Locale;
+
+mySociety::Locale::negotiate_language('de-ch,German,de_CH');
+mySociety::Locale::gettext_domain('ZurichMobileApp');
+mySociety::Locale::change('de-ch');
+
+sub loc {
+ my @args = @_;
+ return _(@args);
+}
+
+sub tprintf {
+ my ( $format, @args ) = @_;
+ @args = @{$args[0]} if ref $args[0] eq 'ARRAY';
+ return sprintf $format, @args;
+}
+
+my $t = Template->new({
+ INCLUDE_PATH => 'templates',
+ OUTPUT_PATH => 'compiled'
+});
+
+my $vars = {
+ loc => \&loc,
+ tprintf => \&tprintf,
+};
+
+for my $file ( glob('templates/*') ) {
+ $file =~ s%templates/%%;
+ $t->process( $file, $vars, $file ) or warn $t->error;
+}