Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Pass in headers from Catalyst if present for HTTP language negotiation.

  • Loading branch information...
commit 7ff54542f29751b465b4580bac8bfd622eb296da 1 parent 3eacb63
@dracos dracos authored
Showing with 14 additions and 2 deletions.
  1. +1 −1  commonlib
  2. +2 −1  perllib/FixMyStreet/Cobrand/Default.pm
  3. +11 −0 t/i18n.t
2  commonlib
@@ -1 +1 @@
-Subproject commit d00cf29f23627fc54eb992dde6a79112677cd86c
+Subproject commit e832140e07bba7697726cae50ec0da26fb547886
View
3  perllib/FixMyStreet/Cobrand/Default.pm
@@ -159,7 +159,8 @@ sub set_lang_and_domain {
my $lang_override = $self->language_override || $lang;
my $lang_domain = $self->language_domain || 'FixMyStreet';
- my $set_lang = mySociety::Locale::negotiate_language( $languages, $lang_override );
+ my $headers = $self->{c} ? $self->{c}->req->headers : undef;
+ my $set_lang = mySociety::Locale::negotiate_language( $languages, $lang_override, $headers );
mySociety::Locale::gettext_domain( $lang_domain, $unicode, $dir );
mySociety::Locale::change();
return $set_lang;
View
11 t/i18n.t
@@ -7,6 +7,7 @@ use FixMyStreet;
use mySociety::Locale;
use Encode;
use Data::Dumper;
+use HTTP::Headers;
use Sort::Key qw(keysort);
use POSIX 'strcoll';
local $Data::Dumper::Sortkeys = 1;
@@ -18,6 +19,16 @@ die "You need to run 'commonlib/bin/gettext-makemo --quiet FixMyStreet' "
unless -e FixMyStreet->path_to(
'locale/cy_GB.UTF-8/LC_MESSAGES/FixMyStreet-EmptyHomes.mo');
+# Test the language negotiation works
+my $lang = mySociety::Locale::negotiate_language(
+ 'en-gb,English,en_GB|cy,Cymraeg,cy_GB|es,Spanish,es_ES',
+ undef,
+ HTTP::Headers->new(
+ Accept_Language => 'es,en-gb;q=0.6,en;q=0.4'
+ )
+);
+is $lang, 'es', 'Language negotiation works okay';
+
# Example strings
my $english = "Please enter a valid email";
my $welsh = "Cofnodwch gyfeiriad e-bost dilys";
Please sign in to comment.
Something went wrong with that request. Please try again.