mattetti / merb_babel

Merb Babel is a dead simple translation/localization tool for Merb

genki (author)
Fri Jan 16 11:43:50 -0800 2009
Matt Aimonetti (committer)
Fri Jan 16 16:15:00 -0800 2009
merb_babel / spec / locale_detector_spec.rb
100644 43 lines (36 sloc) 1.263 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
require File.dirname(__FILE__) + '/spec_helper'
 
describe 'country detector' do
  it "should detect country from request" do
    c = dispatch_to(TestController, :index, {},
      'HTTP_ACCEPT_LANGUAGE' => 'en-UK')
    c.country.should == 'UK'
  end
 
  it "should detect language from request" do
    c = dispatch_to(TestController, :index, {},
      'HTTP_ACCEPT_LANGUAGE' => 'fr-FR')
    c.language.should == 'fr'
  end
 
  it "should detect full locale from request" do
    c = dispatch_to(TestController, :index, {},
      'HTTP_ACCEPT_LANGUAGE' => 'en-UK')
    c.locale.should == 'en-UK'
  end
 
  it "should detect full locale from request 2" do
    c = dispatch_to(TestController, :index, {},
      'HTTP_ACCEPT_LANGUAGE' => 'en_UK')
    c.language.should == 'en'
    c.country.should == 'UK'
    c.locale.should == 'en-UK'
  end
 
  it "should guess country from language" do
    c = dispatch_to(TestController, :index, {},
      'HTTP_ACCEPT_LANGUAGE' => 'ja')
    c.country.should == 'JP'
    c.locale.should == 'ja-JP'
  end
 
  it "should detect language from request including candidates" do
    c = dispatch_to(TestController, :index, {},
      'HTTP_ACCEPT_LANGUAGE' => 'ja,en;q=0.9,fr;q=0.8,de;q=0.7,es;q=0.6')
    c.locale.should == 'ja-JP'
  end
end