Skip to content
This repository
Browse code

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

  • Loading branch information...
commit 7ff54542f29751b465b4580bac8bfd622eb296da 1 parent 3eacb63
Matthew Somerville authored October 15, 2012
2  commonlib
... ...
@@ -1 +1 @@
1  
-Subproject commit d00cf29f23627fc54eb992dde6a79112677cd86c
  1
+Subproject commit e832140e07bba7697726cae50ec0da26fb547886
3  perllib/FixMyStreet/Cobrand/Default.pm
@@ -159,7 +159,8 @@ sub set_lang_and_domain {
159 159
     my $lang_override = $self->language_override || $lang;
160 160
     my $lang_domain = $self->language_domain || 'FixMyStreet';
161 161
 
162  
-    my $set_lang = mySociety::Locale::negotiate_language( $languages, $lang_override );
  162
+    my $headers = $self->{c} ? $self->{c}->req->headers : undef;
  163
+    my $set_lang = mySociety::Locale::negotiate_language( $languages, $lang_override, $headers );
163 164
     mySociety::Locale::gettext_domain( $lang_domain, $unicode, $dir );
164 165
     mySociety::Locale::change();
165 166
     return $set_lang;
11  t/i18n.t
@@ -7,6 +7,7 @@ use FixMyStreet;
7 7
 use mySociety::Locale;
8 8
 use Encode;
9 9
 use Data::Dumper;
  10
+use HTTP::Headers;
10 11
 use Sort::Key qw(keysort);
11 12
 use POSIX 'strcoll';
12 13
 local $Data::Dumper::Sortkeys = 1;
@@ -18,6 +19,16 @@ die "You need to run 'commonlib/bin/gettext-makemo --quiet FixMyStreet' "
18 19
   unless -e FixMyStreet->path_to(
19 20
     'locale/cy_GB.UTF-8/LC_MESSAGES/FixMyStreet-EmptyHomes.mo');
20 21
 
  22
+# Test the language negotiation works
  23
+my $lang = mySociety::Locale::negotiate_language(
  24
+    'en-gb,English,en_GB|cy,Cymraeg,cy_GB|es,Spanish,es_ES',
  25
+    undef,
  26
+    HTTP::Headers->new(
  27
+        Accept_Language => 'es,en-gb;q=0.6,en;q=0.4'
  28
+    )
  29
+);
  30
+is $lang, 'es', 'Language negotiation works okay';
  31
+
21 32
 # Example strings
22 33
 my $english = "Please enter a valid email";
23 34
 my $welsh   = "Cofnodwch gyfeiriad e-bost dilys";

0 notes on commit 7ff5454

Please sign in to comment.
Something went wrong with that request. Please try again.