diff options
author | Edmund von der Burg <evdb@mysociety.org> | 2011-02-24 14:21:47 +0000 |
---|---|---|
committer | Edmund von der Burg <evdb@mysociety.org> | 2011-02-24 14:21:47 +0000 |
commit | b327a36371ea3c0151452ae5e516e63c5fc53b54 (patch) | |
tree | 53680345115830bac4eb617615acac6546f11d10 | |
parent | 9bd3b875d7a16f2a8842feb6913431ae789047bd (diff) |
Return lang to set in HTML
added 'is_default' method to cobrands
tests for i18n (includin checking *.mo files generated)
more debug output in footer
-rw-r--r-- | perllib/FixMyStreet/App.pm | 8 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Default.pm | 18 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/EmptyHomes.pm | 3 | ||||
-rw-r--r-- | t/cobrand/loading.t | 4 | ||||
-rw-r--r-- | t/i18n.t | 32 | ||||
-rw-r--r-- | templates/web/default/footer.html | 10 | ||||
-rw-r--r-- | templates/web/default/header.html | 2 | ||||
-rw-r--r-- | templates/web/emptyhomes/about/index.html | 41 |
8 files changed, 89 insertions, 29 deletions
diff --git a/perllib/FixMyStreet/App.pm b/perllib/FixMyStreet/App.pm index bc9bd7672..825a9f3b3 100644 --- a/perllib/FixMyStreet/App.pm +++ b/perllib/FixMyStreet/App.pm @@ -96,7 +96,8 @@ sub setup_cobrand { # append the cobrand templates to the include path $c->stash->{additional_template_paths} = - [ $cobrand->path_to_web_templates . '' ]; + [ $cobrand->path_to_web_templates . '' ] + unless $cobrand->is_default; my $host = $c->req->uri->host; my $lang = @@ -104,8 +105,9 @@ sub setup_cobrand { : $host =~ /cy/ ? 'cy' : undef; - # set the language and the translation file to use - $cobrand->set_lang_and_domain( $lang, 1 ); + # set the language and the translation file to use - store it on stash + my $set_lang = $cobrand->set_lang_and_domain( $lang, 1 ); + $c->stash->{lang_code} = $set_lang; Problems::set_site_restriction_with_cobrand_object($cobrand); diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm index 608a754f7..f8ec4a319 100644 --- a/perllib/FixMyStreet/Cobrand/Default.pm +++ b/perllib/FixMyStreet/Cobrand/Default.pm @@ -40,6 +40,19 @@ sub moniker { return lc($last_part); } +=head2 is_default + + $bool = $cobrand->is_default(); + +Returns true if this is the default cobrand, false otherwise. + +=cut + +sub is_default { + my $self = shift; + return $self->moniker eq 'default'; +} + =head2 q $request = $cobrand->q; @@ -140,7 +153,7 @@ sub enter_postcode_text { '' } =head2 set_lang_and_domain - $cobrand->set_lang_and_domain( $lang, $unicode ) + my $set_lang = $cobrand->set_lang_and_domain( $lang, $unicode ) Set the language and domain of the site based on the cobrand and host. @@ -148,10 +161,11 @@ Set the language and domain of the site based on the cobrand and host. sub set_lang_and_domain { my ( $self, $lang, $unicode ) = @_; - mySociety::Locale::negotiate_language( + my $set_lang = mySociety::Locale::negotiate_language( 'en-gb,English,en_GB|nb,Norwegian,nb_NO', $lang ); # XXX Testing mySociety::Locale::gettext_domain( 'FixMyStreet', $unicode ); mySociety::Locale::change(); + return $set_lang; } =head2 alert_list_options diff --git a/perllib/FixMyStreet/Cobrand/EmptyHomes.pm b/perllib/FixMyStreet/Cobrand/EmptyHomes.pm index 6b907cbd0..934a9cc23 100644 --- a/perllib/FixMyStreet/Cobrand/EmptyHomes.pm +++ b/perllib/FixMyStreet/Cobrand/EmptyHomes.pm @@ -38,10 +38,11 @@ Set the language and text domain for the site based on the query and host. sub set_lang_and_domain { my ( $self, $lang, $unicode ) = @_; - mySociety::Locale::negotiate_language( + my $set_lang = mySociety::Locale::negotiate_language( 'en-gb,English,en_GB|cy,Cymraeg,cy_GB', $lang ); mySociety::Locale::gettext_domain( 'FixMyStreet-EmptyHomes', $unicode ); mySociety::Locale::change(); + return $set_lang; } =item site_title diff --git a/t/cobrand/loading.t b/t/cobrand/loading.t index aa74bbb91..405ef4761 100644 --- a/t/cobrand/loading.t +++ b/t/cobrand/loading.t @@ -63,5 +63,9 @@ is FixMyStreet::Cobrand::EmptyHomes->moniker, 'emptyhomes', is FixMyStreet::Cobrand::EmptyHomes->new->moniker, 'emptyhomes', 'object->moniker works'; +# check is_default works +ok FixMyStreet::Cobrand::Default->is_default, '::Default is default'; +ok !FixMyStreet::Cobrand::EmptyHomes->is_default, '::Emptyhomes is not default'; + # all done done_testing(); diff --git a/t/i18n.t b/t/i18n.t new file mode 100644 index 000000000..e11589d8b --- /dev/null +++ b/t/i18n.t @@ -0,0 +1,32 @@ +use strict; +use warnings; + +use Test::More; + +use FixMyStreet; +use mySociety::Locale; + +# check that the mo files have been generated +die "You need to run 'commonlib/bin/gettext-makemo --quiet FixMyStreet' " + . "to generate the *.mo files needed." + unless -e FixMyStreet->path_to( + 'locale/cy_GB.UTF-8/LC_MESSAGES/FixMyStreet-EmptyHomes.mo'); + +# Example strings +my $english = "Sorry! Something's gone wrong."; +my $welsh = "Ymddiheuriadau! Mae rhywbeth wedi mynd o'i le."; + +# set english as the language +mySociety::Locale::negotiate_language( # + 'en-gb,English,en_GB|cy,Cymraeg,cy_GB', 'en_GB' +); + +mySociety::Locale::gettext_domain( 'FixMyStreet-EmptyHomes', 1 ); +mySociety::Locale::change(); +is _($english), $english, "english to english"; + +# set to welsh and check for translation +mySociety::Locale::change('cy'); +is _($english), $welsh, "english to welsh"; + +done_testing(); diff --git a/templates/web/default/footer.html b/templates/web/default/footer.html index f5175af8c..6d6c82f0c 100644 --- a/templates/web/default/footer.html +++ b/templates/web/default/footer.html @@ -22,13 +22,13 @@ [% INCLUDE 'tracking_code.html' %] [% IF c.config.STAGING_SITE %] -<hr> - +<hr clear="both"> <ul> - <li>Cobrand: [% c.cobrand.moniker %]</li> - <li>extra template path: [% additional_template_paths.join(',') %]</li> + <li>cobrand.moniker: [% c.cobrand.moniker %]</li> + <li>additional_template_paths: [% additional_template_paths.join(', ') || '--empty--' %]</li> + <li>lang_code: [% lang_code %]</li> </ul> - [% END %] + </body> </html> diff --git a/templates/web/default/header.html b/templates/web/default/header.html index d6da00c8f..d26ebaa2b 100644 --- a/templates/web/default/header.html +++ b/templates/web/default/header.html @@ -5,7 +5,7 @@ <script type="text/javascript" src="/yui/utilities.js"></script> <script type="text/javascript" src="/js.js"></script> - <title>[% title | html %][% c.cobrand.site_title %]</title> + <title>[% title | html %] :: [% c.cobrand.site_title %]</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> diff --git a/templates/web/emptyhomes/about/index.html b/templates/web/emptyhomes/about/index.html index f34d2c9ff..880f69b98 100644 --- a/templates/web/emptyhomes/about/index.html +++ b/templates/web/emptyhomes/about/index.html @@ -1,36 +1,43 @@ -[% INCLUDE 'header.html', title => loc('About Us') %] +[% INCLUDE 'header.html', title => loc('About us') %] <h1>[% loc('About us') %]</h1> <div style="float: left; width: 48%;"> - <h2>The Empty Homes Agency</h2> + <h2>[% loc('The Empty Homes Agency') %]</h2> - <p>The Empty Homes agency is an independent campaigning charity. We are not - part of government, and have no formal links with local councils although we - work in cooperation with both. We exist to highlight the waste of empty - property and work with others to devise and promote sustainable solutions to - bring empty property back into use. We are based in London but work across - England. We also work in partnership with other charities across the UK.</p> + <p>[% loc('The Empty Homes agency is an independent campaigning charity. We + are not part of government, and have no formal links with local councils + although we work in cooperation with both. We exist to highlight the waste + of empty property and work with others to devise and promote sustainable + solutions to bring empty property back into use. We are based in London but + work across England. We also work in partnership with other charities across + the UK.') %]</p> </div> <div style="float: right; width:48%;"> - <h2>Shelter Cymru</h2> + <h2>[% loc('Shelter Cymru') %]</h2> - <p>Shelter Cymru is Wales’ people and homes charity and wants everyone - in Wales to have a decent home. We believe a home is a fundamental right and - essential to the health and well-being of people and communities. We work - for people in housing need. We have offices all over Wales and prevent - people from losing their homes by offering free, confidential and + <p>[% loc('Shelter Cymru is Wales’ people and homes charity and wants + everyone in Wales to have a decent home. We believe a home is a fundamental + right and essential to the health and well-being of people and communities. + We work for people in housing need. We have offices all over Wales and + prevent people from losing their homes by offering free, confidential and independent advice. When necessary we constructively challenge on behalf of people to ensure they are properly assisted and to improve practice and learning. We believe that bringing empty homes back into use can make a - significant contribution to the supply of affordable homes in Wales. <a - href="http://www.sheltercymru.org.uk/shelter/advice/pdetail.asp?cat=20">Further - information about our work on empty homes</a>.</p> + significant contribution to the supply of affordable homes in Wales.') %] + + <a href="http://www.sheltercymru.org.uk/shelter/advice/pdetail.asp?cat=20"> + [% loc('Further information about our work on empty homes.') %] + </a> + + </p> </div> +<br clear="both"> + [% INCLUDE 'footer.html' %]
\ No newline at end of file |