[NUUG fiksgatami] [patch] Make more strings translatable in fixmystreet

Petter Reinholdtsen pere at hungry.com
Wed Jan 28 19:40:59 CET 2009


[Matthew Somerville]
> As with that example, could you please use the correct
> Locale::gettext nget() function for dealing with strings that vary
> depending upon plurals, as not all languages are simply N != 1.

Absolutely.  Here is a new try, using nget().  Not sure if I should
export it from the mySociety::Locale package or not.  Decided against
it, to avoid new symbol names suddenly visible, but you might want to
change that.

Index: bci/bin/gettext-extract
===================================================================
RCS file: /repos/mysociety/bci/bin/gettext-extract,v
retrieving revision 1.4
diff -u -3 -p -u -r1.4 gettext-extract
--- bci/bin/gettext-extract	17 Nov 2008 11:48:33 -0000	1.4
+++ bci/bin/gettext-extract	28 Jan 2009 18:32:18 -0000
@@ -40,7 +40,7 @@ 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
+xgettext --add-comments=TRANS --language=Perl --keyword=_ --keyword=nget:1,2 --from-code=utf-8 -o $PO perllib/mySociety/*.pm bci/perllib/*.pm bci/web/*.cgi bci/bin/send-reports
 
 # Fix headers
 TEMP=`tempfile`
Index: bci/perllib/Page.pm
===================================================================
RCS file: /repos/mysociety/bci/perllib/Page.pm,v
retrieving revision 1.136
diff -u -3 -p -u -r1.136 Page.pm
--- bci/perllib/Page.pm	26 Jan 2009 14:22:54 -0000	1.136
+++ bci/perllib/Page.pm	28 Jan 2009 18:32:19 -0000
@@ -74,13 +74,16 @@ sub report_error {
     warn "aborting";
     ent($msg);
     my $contact_email = mySociety::Config::get('CONTACT_EMAIL');
+    my $trylater = sprintf(_("Please try again later, or <a href=\"mailto:%s\">email us</a> to let us know."), $contact_email);
+    my $somethingwrong = _("Sorry! Something's gone wrong.");
+    my $errortext = _("The text of the error was:");
     print "Status: 500\nContent-Type: text/html; charset=iso-8859-1\n\n",
-            q(<html><head><title>Sorry! Something's gone wrong.</title></head></html>),
+            qq(<html><head><title>$somethingwrong</title></head></html>),
             q(<body>),
-            q(<h1>Sorry! Something's gone wrong.</h1>),
-            qq(<p>Please try again later, or <a href="mailto:$contact_email">email us</a> to let us know.</p>),
+            qq(<h1>$somethingwrong</h1>),
+            qq(<p>$trylater</p>),
             q(<hr>),
-            q(<p>The text of the error was:</p>),
+            qq(<p>$errortext</p>),
             qq(<blockquote class="errortext">$msg</blockquote>),
             q(</body></html>);
 }
@@ -148,13 +151,14 @@ sub header ($%) {
         close FP;
         $html =~ s#<!-- TITLE -->#$title#;
     } else {
+        my $fixmystreet = _("FixMyStreet");
         $html = <<EOF;
 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 <html lang="en-gb">
     <head>
         <script type="text/javascript" src="/yui/utilities.js"></script>
         <script type="text/javascript" src="/js.js"></script>
-        <title>${title}FixMyStreet</title>
+        <title>${title}$fixmystreet</title>
         <style type="text/css">\@import url("/css/core.css"); \@import url("/css/main.css");</style>
 <!--[if LT IE 7]>
 <style type="text/css">\@import url("/css/ie6.css");</style>
@@ -165,7 +169,7 @@ sub header ($%) {
     <body>
 EOF
         $html .= $home ? '<h1 id="header">' : '<div id="header"><a href="/">';
-        $html .= 'Fix<span id="my">My</span>Street';
+        $html .= _('Fix<span id="my">My</span>Street');
         $html .= $home ? '</h1>' : '</a></div>';
         $html .= '<div id="wrapper"><div id="content">';
     }
@@ -173,7 +177,7 @@ EOF
         $html =~ s#<!-- RSS -->#<link rel="alternate" type="application/rss+xml" title="$params{rss}[0]" href="$params{rss}[1]">#;
     }
     if (mySociety::Config::get('STAGING_SITE')) {
-        $html .= '<p id="error">This is a developer site; things might break at any time.</p>';
+        $html .= '<p id="error">' . _("This is a developer site; things might break at any time.") . '</p>';
     }
     return $html;
 }
@@ -221,22 +225,28 @@ piwik_log(piwik_action_name, piwik_idsit
 EOF
     }
 
+    my $report = _("Report a problem");
+    my $reports = _("All reports");
+    my $alerts = _("Local alerts");
+    my $help = _("Help");
+    my $contact = _("Contact");
+    my $orglogo = _('<a href="http://www.mysociety.org/"><img src="/i/mysociety-dark.png" alt="View mySociety.org"><span id="logoie"></span></a>');
+    my $creditline = _('Built by <a href="http://www.mysociety.org/">mySociety</a>, using some <a href="https://secure.mysociety.org/cvstrac/dir?d=mysociety/bci">clever</a>&nbsp;<a href="https://secure.mysociety.org/cvstrac/dir?d=mysociety/services/TilMa">code</a>.');
+
     return <<EOF;
 </div></div>
 <h2 class="v">Navigation</h2>
 <ul id="navigation">
-<li><a href="/">Report a problem</a></li>
-<li><a href="/reports">All reports</a></li>
-<li><a href="/alert$pc">Local alerts</a></li>
-<li><a href="/faq">Help</a></li>
-<li><a href="/contact">Contact</a></li>
+<li><a href="/">$report</a></li>
+<li><a href="/reports">$reports</a></li>
+<li><a href="/alert$pc">$alerts</a></li>
+<li><a href="/faq">$help</a></li>
+<li><a href="/contact">$contact</a></li>
 </ul>
 
-<a href="http://www.mysociety.org/"><img id="logo" src="/i/mysociety-dark.png" alt="View mySociety.org"><span id="logoie"></span></a>
+<div id="logo">$orglogo</div>
 
-<p id="footer">Built by <a href="http://www.mysociety.org/">mySociety</a>,
-using some <a href="https://secure.mysociety.org/cvstrac/dir?d=mysociety/bci">clever</a>&nbsp;<a
-href="https://secure.mysociety.org/cvstrac/dir?d=mysociety/services/TilMa">code</a>.</p>
+<p id="footer">$creditline</p>
 
 $track
 
@@ -284,7 +295,7 @@ sub display_map {
     my $url = mySociety::Config::get('TILES_URL');
     my $tiles_url = $url . $x . '-' . ($x+1) . ',' . $y . '-' . ($y+1) . '/RABX';
     my $tiles = LWP::Simple::get($tiles_url);
-    return '<div id="map_box"> <div id="map"><div id="drag"> </div></div></div><div id="side">' if !$tiles;
+    return '<div id="map_box"> <div id="map"><div id="drag">' . _("Unable to fetch the map tiles from the tile server.") . '</div></div></div><div id="side">' if !$tiles;
     my $tileids = RABX::unserialise($tiles);
     my $tl = $x . '.' . ($y+1);
     my $tr = ($x+1) . '.' . ($y+1);
@@ -712,9 +726,9 @@ sub geocode_string {
     }
 
     if (!$js) {
-        $error = 'Sorry, we had a problem parsing that location. Please try again.';
+        $error = _('Sorry, we had a problem parsing that location. Please try again.');
     } elsif ($js !~ /"code": *200/) {
-        $error = 'Sorry, we could not find that location.';
+        $error = _('Sorry, we could not find that location.');
     } elsif ($js =~ /}, *{/) { # Multiple
         while ($js =~ /"address": *"(.*?)",\s*"AddressDetails":.*?"PostalCodeNumber": *"(.*?)"/g) {
             my $address = $1;
@@ -722,14 +736,14 @@ sub geocode_string {
             $address =~ s/UK/$pc, UK/;
             push (@$error, $address) unless $address =~ /BT\d/;
         }
-        $error = 'Sorry, we could not find that location.' unless $error;
+        $error = _('Sorry, we could not find that location.') unless $error;
     } elsif ($js =~ /BT\d/) {
         # Northern Ireland, hopefully
         $error = "We do not cover Northern Ireland, I'm afraid, as our licence doesn't include any maps for the region.";
     } else {
         my ($accuracy) = $js =~ /"Accuracy": *(\d)/;
         if ($accuracy < 4) {
-            $error = 'Sorry, that location appears to be too general; please be more specific.';
+            $error = _('Sorry, that location appears to be too general; please be more specific.');
         } else {
             $js =~ /"coordinates" *: *\[ *(.*?), *(.*?),/;
             my $lon = $1; my $lat = $2;
Index: bci/web/contact.cgi
===================================================================
RCS file: /repos/mysociety/bci/web/contact.cgi,v
retrieving revision 1.37
diff -u -3 -p -u -r1.37 contact.cgi
--- bci/web/contact.cgi	26 Jan 2009 14:31:19 -0000	1.37
+++ bci/web/contact.cgi	28 Jan 2009 18:32:19 -0000
@@ -120,8 +120,7 @@ homes; use the box accessed from <a href
         $out .= $q->p(_('Please do <strong>not</strong> report problems through this form; messages go to
 the team behind FixMyStreet, not a council. To report a problem,
 please <a href="/">go to the front page</a> and follow the instructions.'));
-        $out .= $q->p(_("We'd love to hear what you think about this site. Just fill in the form, or
-send an email to <a href='mailto:$mailto'>$mailto</a>:"));
+        $out .= $q->p(sprintf(_("We'd love to hear what you think about this site. Just fill in the form, or send an email to <a href='mailto:%s'>%s</a>:"), $mailto, $mailto));
     }
     my $label_name = _('Your name:');
     my $label_email = _('Your&nbsp;email:');
Index: bci/web/index.cgi
===================================================================
RCS file: /repos/mysociety/bci/web/index.cgi,v
retrieving revision 1.241
diff -u -3 -p -u -r1.241 index.cgi
--- bci/web/index.cgi	26 Jan 2009 14:29:35 -0000	1.241
+++ bci/web/index.cgi	28 Jan 2009 18:32:19 -0000
@@ -28,6 +28,7 @@ use mySociety::PostcodeUtil;
 use mySociety::Random;
 use mySociety::VotingArea;
 use mySociety::Web qw(ent NewURL);
+use mySociety::Locale;
 
 BEGIN {
     if (!dbh()->selectrow_array('select secret from secret for update of secret')) {
@@ -120,28 +121,30 @@ EOF
     my $updates = Problems::number_comments();
     $updates =~ s/(?<=\d)(?=(?:\d\d\d)+$)/,/g;
     my $new = Problems::recent_new('1 week');
-    my $new_text = 'in past week';
+    my $new_text = sprintf(mySociety::Locale::nget('<big>%s</big> report in past week',
+                                '<big>%s</big> reports in past week', $new), $new);
     if ($q->{site} ne 'emptyhomes' && $new > $fixed) {
         $new = Problems::recent_new('3 days');
-        $new_text = 'recently';
+        $new_text = sprintf(mySociety::Locale::nget('<big>%s</big> report recently','<big>%s</big> reports recently',$new), $new);
     }
     $out .= '<form action="/" method="get" id="postcodeForm">';
     if (my $token = $q->param('partial')) {
         my $id = mySociety::AuthToken::retrieve('partial', $token);
         if ($id) {
+            my $thanks = _("Thanks for uploading your photo. We now need to locate your problem, so please enter a nearby street name or postcode in the box below&nbsp;:");
             $out .= <<EOF;
-<p style="margin-top: 0; color: #cc0000;"><img align="right" src="/photo?id=$id" hspace="5">
-Thanks for uploading your photo. We now need to locate your problem,
-so please enter a nearby street name or postcode in the box below&nbsp;:</p>
+<p style="margin-top: 0; color: #cc0000;"><img align="right" src="/photo?id=$id" hspace="5">$thanks</p>
 
 <input type="hidden" name="partial_token" value="$token">
 EOF
         }
     }
+    my $question = _("Enter a nearby GB postcode, or street name and area:");
+    my $activate = _("Go");
     $out .= <<EOF;
-<label for="pc">Enter a nearby GB postcode, or street name and area:</label>
+<label for="pc">$question</label>
 &nbsp;<input type="text" name="pc" value="$pc_h" id="pc" size="10" maxlength="200">
-&nbsp;<input type="submit" value="Go" id="submit">
+&nbsp;<input type="submit" value="$activate" id="submit">
 </form>
 
 <div id="front_intro">
@@ -159,10 +162,11 @@ EOF
 
     $out .= $q->h2(_('FixMyStreet updates'));
     $out .= $q->div({-id => 'front_stats'},
-        $q->div("<big>$new</big> report" . ($new!=1?'s':''), $new_text),
-        ($q->{site} ne 'emptyhomes' ? $q->div("<big>$fixed</big> fixed in past month")
-            : ''), # $q->div("<big>$fixed</big> back in use in past month")),
-        $q->div("<big>$updates</big> update" . ($updates ne '1'?'s':''), "on reports"),
+        $q->div($new_text),
+        ($q->{site} ne 'emptyhomes' ? $q->div(sprintf(mySociety::Locale::nget("<big>%s</big> fixed in past month", "<big>%s</big> fixed in past month", $fixed),$fixed))
+            : ''), # $q->div(sprintf(_('<big>%s</big> back in use in past month"), $fixed)),
+        $q->div(sprintf(mySociety::Locale::nget("<big>%s</big> update on reports",
+                                                "<big>%s</big> updates on reports", $updates), $updates))
     );
 
     $out .= <<EOF;
@@ -881,7 +885,7 @@ sub display_problem {
     $out .= Page::display_problem_text($q, $problem);
 
     $out .= $q->p({align=>'right'},
-        $q->small($q->a({rel => 'nofollow', href => '/contact?id=' . $input{id}}, 'Offensive? Unsuitable? Tell us'))
+        $q->small($q->a({rel => 'nofollow', href => '/contact?id=' . $input{id}}, _('Offensive? Unsuitable? Tell us')))
     );
 
     my $back = NewURL($q, -url => '/', 'x' => $x_tile, 'y' => $y_tile );
Index: perllib/mySociety/Locale.pm
===================================================================
RCS file: /repos/mysociety/perllib/mySociety/Locale.pm,v
retrieving revision 1.6
diff -u -3 -p -u -r1.6 Locale.pm
--- perllib/mySociety/Locale.pm	26 Jan 2009 14:21:52 -0000	1.6
+++ perllib/mySociety/Locale.pm	28 Jan 2009 18:32:20 -0000
@@ -23,6 +23,10 @@ sub _ {
     return $gettext->get($_[0]);
 }
 
+sub nget {
+    return $gettext->nget(@_);
+}
+
 our %langmap = ();
 our %langs = ();
 our $lang;


More information about the fiksgatami mailing list