sinatra-r18n 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -24,24 +24,18 @@ information.
24
24
 
25
25
  post:
26
26
  friends: Post only for friends
27
- tags: Post tags: %1
27
+ tags: Post tags: %1
28
28
 
29
29
  comments: !!pl
30
30
  0: No comments
31
31
  1: One comment
32
32
  n: %1 comments
33
33
 
34
- 3. Add R18n to your application:
34
+ 3. Add R18n to your Sinatra application:
35
35
 
36
- require 'rubygems'
37
- require 'sinatra'
38
36
  require 'sinatra/r18n'
39
37
 
40
- 4. Set default locale (if it isn’t English):
41
-
42
- set :default_locale, 'ru'
43
-
44
- 5. Add locale to your URLs. For example:
38
+ 4. Add locale to your URLs. For example:
45
39
 
46
40
  get '/:locale/posts/:id' do
47
41
  @post = Post.find(params[:id])
@@ -54,18 +48,18 @@ information.
54
48
  session[:locale] = params[:locale] if params[:locale]
55
49
  end
56
50
 
57
- 6. Use translation messages in view. For example in HAML:
51
+ 5. Use translation messages in view. For example in HAML:
58
52
 
59
53
  %p= i18n.post.friends
60
54
  %p= i18n.post.tags(@post.tags.join(', '))
61
55
 
62
56
  %h2= i18n.comments(@post.comments.size)
63
57
 
64
- 7. Print localized time and numbers. For example:
58
+ 6. Print localized time and numbers. For example:
65
59
 
66
60
  i18n.l @post.created_at, :date
67
61
 
68
- 8. Print available translation. For example in HAML:
62
+ 7. Print available translations. For example in HAML:
69
63
 
70
64
  %ul
71
65
  - i18n.translations.each_pair do |locale, title|
@@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
19
19
  =end
20
20
 
21
21
  require 'rubygems'
22
+ gem 'sinatra'
22
23
  require 'sinatra/base'
23
24
 
24
25
  gem 'r18n-core', '~>0.2'
@@ -41,8 +42,9 @@ module Sinatra #::nodoc::
41
42
  end
42
43
 
43
44
  @i18n = ::R18n::I18n.new(locales, options.translations)
45
+ else
46
+ @i18n
44
47
  end
45
- @i18n
46
48
  end
47
49
  end
48
50
 
@@ -2,42 +2,45 @@
2
2
  require File.join(File.dirname(__FILE__), 'spec_helper')
3
3
 
4
4
  describe Sinatra::R18n do
5
+ before :all do
6
+ ::R18n.set(nil)
7
+ end
5
8
 
6
9
  it "should translate messages" do
7
10
  get '/ru/posts/1'
8
- response.should be_ok
9
- response.body.should == "<h1>Запись 1</h1>\n"
11
+ last_response.should be_ok
12
+ last_response.body.should == "<h1>Запись 1</h1>\n"
10
13
  end
11
14
 
12
15
  it "should use translations from default locale" do
13
16
  get '/ru/posts/1/comments'
14
- response.should be_ok
15
- response.body.should == '3 comments'
17
+ last_response.should be_ok
18
+ last_response.body.should == '3 comments'
16
19
  end
17
20
 
18
21
  it "should use default locale" do
19
22
  set :default_locale, 'ru'
20
23
  get '/locale'
21
- response.should be_ok
22
- response.body.should == 'Русский'
24
+ last_response.should be_ok
25
+ last_response.body.should == 'Русский'
23
26
  end
24
27
 
25
28
  it "should autodetect user locale" do
26
- get '/locale', :env => {'HTTP_ACCEPT_LANGUAGE' => 'ru,en;q=0.9'}
27
- response.should be_ok
28
- response.body.should == 'Русский'
29
+ get '/locale', {}, {'HTTP_ACCEPT_LANGUAGE' => 'ru,en;q=0.9'}
30
+ last_response.should be_ok
31
+ last_response.body.should == 'Русский'
29
32
  end
30
33
 
31
34
  it "should use locale from session" do
32
- get '/locale', :env => { 'rack.session' => { :locale => 'ru' } }
33
- response.should be_ok
34
- response.body.should == 'Русский'
35
+ get '/locale', {}, { 'rack.session' => { :locale => 'ru' } }
36
+ last_response.should be_ok
37
+ last_response.body.should == 'Русский'
35
38
  end
36
39
 
37
40
  it "should return locales list" do
38
41
  get '/locales'
39
- response.should be_ok
40
- response.body.should == 'ru: Русский; en: English'
42
+ last_response.should be_ok
43
+ last_response.body.should == 'ru: Русский; en: English'
41
44
  end
42
45
 
43
46
  end
@@ -3,7 +3,9 @@ require File.join(File.dirname(__FILE__), '../lib/sinatra/r18n')
3
3
  require File.join(File.dirname(__FILE__), 'app/app')
4
4
 
5
5
  require 'spec/interop/test'
6
- require 'sinatra/test'
7
- Test::Unit::TestCase.send :include, Sinatra::Test
6
+ gem 'rack-test'
7
+ require 'rack/test'
8
+ Test::Unit::TestCase.send(:include, Rack::Test::Methods)
9
+ Test::Unit::TestCase.send(:define_method, :app) { Sinatra::Application }
8
10
 
9
11
  set :environment, :test
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra-r18n
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrey "A.I." Sitnik
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-16 00:00:00 +04:00
12
+ date: 2009-06-25 00:00:00 +04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -20,7 +20,7 @@ dependencies:
20
20
  requirements:
21
21
  - - "="
22
22
  - !ruby/object:Gem::Version
23
- version: 0.2.1
23
+ version: 0.2.2
24
24
  version:
25
25
  description: A Sinatra extension that provides i18n support to translate your web application. It is just a wrap for R18n core library. It can format numbers and time to the rules of the user locale, has translation for common words, storage translation in YAML format with pluralization and procedures and has special support for countries with two official languages.
26
26
  email: andrey@sitnik.ru