aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Somerville <matthew-github@dracos.co.uk>2012-08-14 11:49:46 +0100
committerMatthew Somerville <matthew@mysociety.org>2012-08-16 21:43:46 +0100
commitc4b88147b23e16dff29a6f16851b7be11080ad0b (patch)
tree3254a79a98ac6d7ef86ff4dad6d09a1e9ae1f557
parent1bb1706fa427513626a39df4ed3f4fdef097ce60 (diff)
Allow languages to be given in config file.
-rw-r--r--conf/general.yml-example5
-rw-r--r--perllib/FixMyStreet/Cobrand/Default.pm17
-rw-r--r--perllib/FixMyStreet/Cobrand/EmptyHomes.pm17
-rw-r--r--perllib/FixMyStreet/Cobrand/FiksGataMi.pm11
4 files changed, 21 insertions, 29 deletions
diff --git a/conf/general.yml-example b/conf/general.yml-example
index 2f26b76d1..78bf9426c 100644
--- a/conf/general.yml-example
+++ b/conf/general.yml-example
@@ -30,6 +30,11 @@ STAGING_SITE: 1
# Defaults to High Street, Main Street
EXAMPLE_PLACES:
+# An array of languages for the site, in the following format:
+# <language code>,<pretty name>,<locale>
+LANGUAGES:
+ - 'en-gb,English,en_GB'
+
# File locations for uploaded photos and cached geocoding results.
UPLOAD_DIR: '../upload/'
GEO_CACHE: '../cache/'
diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm
index e5c74a428..06df07c48 100644
--- a/perllib/FixMyStreet/Cobrand/Default.pm
+++ b/perllib/FixMyStreet/Cobrand/Default.pm
@@ -32,7 +32,8 @@ sub path_to_web_templates {
=head1 country
Returns the country that this cobrand operates in, as an ISO3166-alpha2 code.
-Default is none.
+Default is none. This is not really used for anything important (minor GB only
+things involving eastings/northings mostly).
=cut
@@ -160,13 +161,19 @@ Set the language and domain of the site based on the cobrand and host.
sub set_lang_and_domain {
my ( $self, $lang, $unicode, $dir ) = @_;
- my $set_lang = mySociety::Locale::negotiate_language(
- 'en-gb,English,en_GB', $lang
- );
- mySociety::Locale::gettext_domain( 'FixMyStreet', $unicode, $dir );
+
+ my $languages = join('|', @{$self->languages});
+ my $lang_override = $self->language_override || $lang;
+ my $lang_domain = $self->language_domain || 'FixMyStreet';
+
+ my $set_lang = mySociety::Locale::negotiate_language( $languages, $lang_override );
+ mySociety::Locale::gettext_domain( $lang_domain, $unicode, $dir );
mySociety::Locale::change();
return $set_lang;
}
+sub languages { FixMyStreet->config('LANGUAGES') || [ 'en-gb,English,en_GB' ] }
+sub language_domain { }
+sub language_override { }
=head2 alert_list_options
diff --git a/perllib/FixMyStreet/Cobrand/EmptyHomes.pm b/perllib/FixMyStreet/Cobrand/EmptyHomes.pm
index 679c49889..36bc67835 100644
--- a/perllib/FixMyStreet/Cobrand/EmptyHomes.pm
+++ b/perllib/FixMyStreet/Cobrand/EmptyHomes.pm
@@ -45,21 +45,8 @@ sub base_url_with_lang {
return $base;
}
-=item set_lang_and_domain LANG UNICODE
-
-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, $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,
- $dir );
- mySociety::Locale::change();
- return $set_lang;
-}
+sub languages { [ 'en-gb,English,en_GB', 'cy,Cymraeg,cy_GB' ] }
+sub language_domain { 'FixMyStreet-EmptyHomes' }
=item site_title
diff --git a/perllib/FixMyStreet/Cobrand/FiksGataMi.pm b/perllib/FixMyStreet/Cobrand/FiksGataMi.pm
index 03777ac51..8b2fb06ea 100644
--- a/perllib/FixMyStreet/Cobrand/FiksGataMi.pm
+++ b/perllib/FixMyStreet/Cobrand/FiksGataMi.pm
@@ -17,15 +17,8 @@ sub country {
return 'NO';
}
-sub set_lang_and_domain {
- my ( $self, $lang, $unicode, $dir ) = @_;
- my $set_lang = mySociety::Locale::negotiate_language(
- 'en-gb,English,en_GB|nb,Norwegian,nb_NO', 'nb'
- );
- mySociety::Locale::gettext_domain( 'FixMyStreet', $unicode, $dir );
- mySociety::Locale::change();
- return $set_lang;
-}
+sub languages { [ 'en-gb,English,en_GB', 'nb,Norwegian,nb_NO' ] }
+sub language_override { 'nb' }
sub site_title {
my ($self) = @_;