aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xbin/generate_cobrand_po40
-rwxr-xr-xbin/gettext-extract27
-rwxr-xr-xbin/merge_cobrand_po29
-rwxr-xr-xbin/update_po_header.bash33
4 files changed, 111 insertions, 18 deletions
diff --git a/bin/generate_cobrand_po b/bin/generate_cobrand_po
new file mode 100755
index 000000000..1770de7c2
--- /dev/null
+++ b/bin/generate_cobrand_po
@@ -0,0 +1,40 @@
+#!/usr/bin/env perl
+use strict;
+
+=for instructions
+
+This script generates a po file that contains only the strings related to a cobrand.
+Its purpose is to avoid having lots of cobrand specific strings in the
+main FixMyStreet po file confusing translators. Once this is run the
+generated po file can be used to translate the strings. The po files
+with the translation should then be placed in the relevant language
+directories and merge_cobrand_po run which will merge these with
+the main FixMyStreet po files
+
+=cut
+
+my $cobrand = shift;
+
+die "Please provide a cobrand name\n" unless $cobrand;
+
+my $cobrand_lc = lc( $cobrand );
+
+my $PO = "locale/$cobrand.po";
+
+my $cobrand_module = "perllib/FixMyStreet/Cobrand/$cobrand.pm";
+my $web_templates = "templates/web/$cobrand_lc/";
+
+my $opts = '';
+if ( -e $cobrand_module ) {
+ $opts .= " $cobrand_module";
+}
+
+if ( -e -d $web_templates ) {
+ $opts .= " --directory $web_templates";
+}
+
+# first we get the strings from the cobrand
+system("xgettext.pl --gnu-gettext --verbose --output $PO --plugin perl=* --plugin tt2 $opts");
+
+# now replace the template header elements
+system("bin/update_po_header.bash $PO");
diff --git a/bin/gettext-extract b/bin/gettext-extract
index 934bf1711..a38c17127 100755
--- a/bin/gettext-extract
+++ b/bin/gettext-extract
@@ -13,28 +13,19 @@ cd "$(dirname $(readlink -f $BASH_SOURCE))/.."
PO=locale/FixMyStreet.po
rm -f $PO
+# we don't want to extract strings from all the cobrand templates so list
+# the ones we care about
+find templates/web/default templates/web/fixmystreet templates/web/zurich templates/web/fiksgatami templates/web/emptyhomes templates/web/fixmybarangay -name '*.html' > template_list
+
# Extract from Perl
-xgettext.pl --gnu-gettext --verbose --output $PO --plugin perl=* --plugin tt2 --directory perllib --directory templates/web --directory db --directory bin
+xgettext.pl --gnu-gettext --verbose --output $PO --plugin perl=* --plugin tt2 --directory perllib -f template_list --directory db --directory bin
+
+# remove temporary list of templates
+rm template_list
# 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 original .po file, autogenerated by gettext-extract/;
- s/YEAR THE PACKAGE'S COPYRIGHT HOLDER/2011 UK Citizens Online Democracy/;
- s/PACKAGE package/main FixMyStreet code/;
- s/FIRST AUTHOR <EMAIL@ADDRESS>, YEAR./Matthew Somerville <matthew@mysociety.org>, 2011-06-03./;
-
- s/PACKAGE VERSION/1.0\\\n\"\\$nl\"Report-Msgid-Bugs-To: matthew@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
+bin/update_po_header.bash $PO
echo "$( bin/gettext-nget-patch )" >> $PO
diff --git a/bin/merge_cobrand_po b/bin/merge_cobrand_po
new file mode 100755
index 000000000..2785162cf
--- /dev/null
+++ b/bin/merge_cobrand_po
@@ -0,0 +1,29 @@
+#!/usr/bin/env perl
+use strict;
+
+=for instructions
+
+This script is used to merge cobrand po files with the main
+FixMyStreet po file. It should be run after generate_cobrand_po
+and once the cobrand po files with translations are placed in the
+language directories.
+
+It will then create an autoCobrand.po file for each language that
+has a Cobrand.po
+
+=cut
+
+my $cobrand = shift;
+
+die "Please provide a cobrand name\n" unless $cobrand;
+
+# for each language create a .po file with an existing translations
+for (glob( 'locale/*/LC_MESSAGES' ) ) {
+ my $fms = "$_/FixMyStreet.po";
+ my $cobrand_po = "$_/$cobrand.po";
+ my $out = "$_/auto$cobrand.po";
+ if ( -e $cobrand_po and -e $fms ) {
+ print "$_\n";
+ system("msgcat --no-wrap -o $out $fms $cobrand_po");
+ }
+}
diff --git a/bin/update_po_header.bash b/bin/update_po_header.bash
new file mode 100755
index 000000000..2f37ad5d3
--- /dev/null
+++ b/bin/update_po_header.bash
@@ -0,0 +1,33 @@
+#!/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/
+
+cd "$(dirname $(readlink -f $BASH_SOURCE))/.."
+
+# File to write to, clear it to start with
+PO=$1
+
+# 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 original .po file, autogenerated by gettext-extract/;
+ s/YEAR THE PACKAGE'S COPYRIGHT HOLDER/2011 UK Citizens Online Democracy/;
+ s/PACKAGE package/main FixMyStreet code/;
+ s/FIRST AUTHOR <EMAIL@ADDRESS>, YEAR./Matthew Somerville <matthew@mysociety.org>, 2011-06-03./;
+
+ s/PACKAGE VERSION/1.0\\\n\"\\$nl\"Report-Msgid-Bugs-To: matthew@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