aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEdmund von der Burg <evdb@mysociety.org>2011-02-24 15:27:23 +0000
committerEdmund von der Burg <evdb@mysociety.org>2011-02-24 15:27:23 +0000
commit7c9a89eedb17bdafbc171bba5de21cdd5725acd7 (patch)
tree3603445333afb5821ef568711b66d274fac067b6
parentb327a36371ea3c0151452ae5e516e63c5fc53b54 (diff)
Explicitly set gettext_dir so that it does not matter where calling script file is located
m---------commonlib0
-rw-r--r--perllib/FixMyStreet/App.pm13
-rw-r--r--perllib/FixMyStreet/Cobrand/Default.pm8
-rw-r--r--perllib/FixMyStreet/Cobrand/EmptyHomes.pm5
-rw-r--r--perllib/FixMyStreet/Cobrand/FiksGataMi.pm4
-rw-r--r--t/app/controller/about.t12
-rw-r--r--t/i18n.t9
7 files changed, 36 insertions, 15 deletions
diff --git a/commonlib b/commonlib
-Subproject 5179eafd5174b069ea7d6b5855233513f0ec370
+Subproject e25a8fa278b43ab0a35436b4fea9c898f72b799
diff --git a/perllib/FixMyStreet/App.pm b/perllib/FixMyStreet/App.pm
index 825a9f3b3..929889fbd 100644
--- a/perllib/FixMyStreet/App.pm
+++ b/perllib/FixMyStreet/App.pm
@@ -46,6 +46,9 @@ __PACKAGE__->config(
# Start the application
__PACKAGE__->setup();
+# disable debug logging unless in debaug mode
+__PACKAGE__->log->disable('debug') unless __PACKAGE__->debug;
+
=head1 NAME
FixMyStreet::App - Catalyst based application
@@ -106,9 +109,17 @@ sub setup_cobrand {
: undef;
# set the language and the translation file to use - store it on stash
- my $set_lang = $cobrand->set_lang_and_domain( $lang, 1 );
+ my $set_lang = $cobrand->set_lang_and_domain(
+ $lang, # language
+ 1, # return unicode
+ FixMyStreet->path_to('locale')->stringify # use locale directory
+ );
$c->stash->{lang_code} = $set_lang;
+ # debug
+ $c->log->debug( sprintf "Set lang to '%s' and cobrand to '%s'",
+ $set_lang, $cobrand->moniker );
+
Problems::set_site_restriction_with_cobrand_object($cobrand);
Memcached::set_namespace( FixMyStreet->config('BCI_DB_NAME') . ":" );
diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm
index f8ec4a319..fc4581fa1 100644
--- a/perllib/FixMyStreet/Cobrand/Default.pm
+++ b/perllib/FixMyStreet/Cobrand/Default.pm
@@ -153,17 +153,17 @@ sub enter_postcode_text { '' }
=head2 set_lang_and_domain
- my $set_lang = $cobrand->set_lang_and_domain( $lang, $unicode )
+ my $set_lang = $cobrand->set_lang_and_domain( $lang, $unicode, $dir )
Set the language and domain of the site based on the cobrand and host.
=cut
sub set_lang_and_domain {
- my ( $self, $lang, $unicode ) = @_;
+ my ( $self, $lang, $unicode, $dir ) = @_;
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::gettext_domain( 'FixMyStreet', $unicode, $dir );
mySociety::Locale::change();
return $set_lang;
}
@@ -345,7 +345,7 @@ Return the title to be used in page heads.
=cut
-sub site_title { '' }
+sub site_title { 'FixMyStreet.com' }
=head2 on_map_list_limit
diff --git a/perllib/FixMyStreet/Cobrand/EmptyHomes.pm b/perllib/FixMyStreet/Cobrand/EmptyHomes.pm
index 934a9cc23..5ebee0d2b 100644
--- a/perllib/FixMyStreet/Cobrand/EmptyHomes.pm
+++ b/perllib/FixMyStreet/Cobrand/EmptyHomes.pm
@@ -37,10 +37,11 @@ Set the language and text domain for the site based on the query and host.
=cut
sub set_lang_and_domain {
- my ( $self, $lang, $unicode ) = @_;
+ my ( $self, $lang, $unicode, $dir ) = @_;
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::gettext_domain( 'FixMyStreet-EmptyHomes', $unicode,
+ $dir );
mySociety::Locale::change();
return $set_lang;
}
diff --git a/perllib/FixMyStreet/Cobrand/FiksGataMi.pm b/perllib/FixMyStreet/Cobrand/FiksGataMi.pm
index 25a4ad83c..43565d8ea 100644
--- a/perllib/FixMyStreet/Cobrand/FiksGataMi.pm
+++ b/perllib/FixMyStreet/Cobrand/FiksGataMi.pm
@@ -7,10 +7,10 @@ use warnings;
use Carp;
sub set_lang_and_domain {
- my ( $self, $lang, $unicode ) = @_;
+ my ( $self, $lang, $unicode, $dir ) = @_;
mySociety::Locale::negotiate_language(
'en-gb,English,en_GB|nb,Norwegian,nb_NO', 'nb' );
- mySociety::Locale::gettext_domain( 'FixMyStreet', $unicode );
+ mySociety::Locale::gettext_domain( 'FixMyStreet', $unicode, $dir );
mySociety::Locale::change();
}
diff --git a/t/app/controller/about.t b/t/app/controller/about.t
index adbce8f25..aeca47d86 100644
--- a/t/app/controller/about.t
+++ b/t/app/controller/about.t
@@ -8,17 +8,19 @@ ok( my $mech = Test::WWW::Mechanize::Catalyst->new, 'Created mech object' );
# check that we can get the page
$mech->get_ok('/about');
-$mech->content_contains('FixMyStreet.com');
+$mech->content_contains('About Us :: FixMyStreet.com');
+$mech->content_contains('html lang="en-gb"');
# check that geting the page as EHA produces a different page
ok $mech->host("reportemptyhomes.co.uk"), 'change host to reportemptyhomes';
$mech->get_ok('/about');
-$mech->content_contains('The Empty Homes Agency');
+$mech->content_contains('About us :: Report Empty Homes');
+$mech->content_contains('html lang="en-gb"');
# check that geting the page as EHA in welsh produces a different page
-ok $mech->host("cy.reportemptyhomes.co.uk"),
- 'change host to cy.reportemptyhomes';
+ok $mech->host("cy.reportemptyhomes.co.uk"), 'host to cy.reportemptyhomes';
$mech->get_ok('/about');
-$mech->content_contains('Yr Asiantaeth Tai Gwag');
+$mech->content_contains('Amdanom ni :: Adrodd am Eiddo Gwag');
+$mech->content_contains('html lang="cy"');
done_testing();
diff --git a/t/i18n.t b/t/i18n.t
index e11589d8b..6a5d94fa2 100644
--- a/t/i18n.t
+++ b/t/i18n.t
@@ -10,7 +10,7 @@ use mySociety::Locale;
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');
+ 'locale/cy_GB.UTF-8/LC_MESSAGES/FixMyStreet-EmptyHomes.mo');
# Example strings
my $english = "Sorry! Something's gone wrong.";
@@ -29,4 +29,11 @@ is _($english), $english, "english to english";
mySociety::Locale::change('cy');
is _($english), $welsh, "english to welsh";
+# check that being in a deep directory does not confuse the code
+chdir FixMyStreet->path_to('t/app/controller') . '';
+mySociety::Locale::gettext_domain( 'FixMyStreet-EmptyHomes', 1,
+ FixMyStreet->path_to('locale')->stringify );
+mySociety::Locale::change('cy');
+is _($english), $welsh, "english to welsh (deep directory)";
+
done_testing();