r18n-rails 0.4.10 → 0.4.11

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,20 +1,20 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- r18n-rails (0.4.10)
5
- r18n-rails-api (= 0.4.10)
4
+ r18n-rails (0.4.11)
5
+ r18n-rails-api (= 0.4.11)
6
6
 
7
7
  PATH
8
8
  remote: ../r18n-core/
9
9
  specs:
10
- r18n-core (0.4.10)
10
+ r18n-core (0.4.11)
11
11
 
12
12
  PATH
13
13
  remote: ../r18n-rails-api/
14
14
  specs:
15
- r18n-rails-api (0.4.10)
15
+ r18n-rails-api (0.4.11)
16
16
  i18n
17
- r18n-core (= 0.4.10)
17
+ r18n-core (= 0.4.11)
18
18
 
19
19
  GEM
20
20
  remote: http://rubygems.org/
data/README.rdoc CHANGED
@@ -57,28 +57,28 @@ R18n can add i18n support for your ActiveRecord model and any other class
57
57
  (include DataMapper, MongoMapper, Mongoid):
58
58
 
59
59
  1. Add separate columns for all supported translations:
60
-
60
+
61
61
  def self.up
62
62
  create_table :posts do |t|
63
63
  t.string :title_en
64
64
  t.string :title_ru
65
65
  end
66
66
  end
67
-
67
+
68
68
  2. Add virtual method +title+, which will use <tt>title_<i>locale</i></tt>
69
69
  methods to find actual translation:
70
-
70
+
71
71
  class Post < ActiveRecord::Base
72
72
  include R18n::Translated
73
73
  translations :title
74
74
  end
75
-
75
+
76
76
  # For Russian user
77
77
  post = Post.new
78
78
  post.title_en = 'Post'
79
79
  post.title_ru = 'Запись'
80
80
  post.title = 'Запись'
81
-
81
+
82
82
  post.title = 'Другая' # will use title_ru, by first user's locale
83
83
 
84
84
  === Time Fomatters
@@ -87,7 +87,7 @@ R18n add +full+ time formatter based on locale info:
87
87
 
88
88
  # English
89
89
  l Time.now, :full #=> "1st of December, 2009 12:00"
90
-
90
+
91
91
  # French
92
92
  l Time.now, :full #=> "1er décembre 2009 12:00"
93
93
 
@@ -103,7 +103,7 @@ rules for non-English locales out-of-box:
103
103
  1: %1 пользователь
104
104
  2: %1 пользователя
105
105
  n: %1 пользователей
106
-
106
+
107
107
  t.user.count(2) #=> "2 пользователя"
108
108
  t.user.count(21) #=> "21 пользователь"
109
109
 
@@ -123,24 +123,24 @@ You can create another R18n I18n instance with another languages. For example,
123
123
  to send e-mail for English admin on error with French user:
124
124
 
125
125
  puts I18n.t :error # Show error in French
126
-
126
+
127
127
  admin_i18n = R18n::I18n.new(@admin_locales, Rails.root + 'app/i18n')
128
128
  send_email(admin_i18n.error_messages)
129
129
 
130
130
  == How To
131
131
 
132
132
  1. Add <tt>r18n-rails</tt> gem to your <tt>config/environment.rb</tt>:
133
-
133
+
134
134
  config.gem 'r18n-rails'
135
-
135
+
136
136
  Now R18n will autodetect user locales.
137
137
  2. Define your way to set locale manually. R18n will find it in
138
138
  <tt>params[:locale]</tt> or <tt>session[:locale]</tt>. Best way is a put
139
139
  optional locale prefix to URLs:
140
-
140
+
141
141
  map.connect ':controller/:action'
142
142
  map.connect ':locale/:controller/:action'
143
-
143
+
144
144
  3. Print available translations, to choose from them manually (and to helpsearch
145
145
  engines):
146
146
 
@@ -151,10 +151,10 @@ to send e-mail for English admin on error with French user:
151
151
  </li>
152
152
  <% end %>
153
153
  </ul>
154
-
154
+
155
155
  4. Translations in I18n format are stored in
156
156
  <tt>config/locales/_locale_.yml</tt>:
157
-
157
+
158
158
  en:
159
159
  user:
160
160
  name: "User name is %{name}"
@@ -162,57 +162,57 @@ to send e-mail for English admin on error with French user:
162
162
  zero: "No users"
163
163
  one: "One user"
164
164
  many: "%{count} users"
165
-
165
+
166
166
  Translations in R18n format go to <tt>app/i18n/_locale_.yml</tt>:
167
-
167
+
168
168
  user:
169
169
  name: User name is %1
170
170
  count: !!pl
171
171
  0: No users
172
172
  1: 1 user
173
173
  n: %1 users
174
-
174
+
175
175
  5. Use translated messages in views. You can use Rails I18n syntax:
176
-
176
+
177
177
  t 'user.name', :name => 'John'
178
178
  t 'user.count', :count => 5
179
-
179
+
180
180
  or R18n syntax:
181
-
181
+
182
182
  t.user.name(:name => 'John') # for Rails I18n named variables
183
183
  t.user.name('John') # for R18n variables
184
184
  t.user.count(5)
185
-
185
+
186
186
  6. Print dates and numbers in user’s tradition:
187
-
187
+
188
188
  l Date.today, :standard #=> "20/12/2009"
189
189
  l Time.now, :full #=> "20th of December, 2009 12:00"
190
190
  l 1234.5 #=> "1,234.5"
191
191
 
192
192
  7. Translate models:
193
-
193
+
194
194
  1. Add to migration columns for each of the supported locales, named as
195
195
  <tt><i>name</i>_<i>locale</i></tt>:
196
-
196
+
197
197
  t.string :title_en
198
198
  t.string :title_ru
199
-
199
+
200
200
  t.string :text_en
201
201
  t.string :text_ru
202
-
202
+
203
203
  2. Add <tt>R18n::Translated</tt> mixin to model:
204
-
204
+
205
205
  class Post < ActiveRecord::Base
206
206
  include R18n::Translated
207
-
207
+
208
208
  3. Call +translations+ method in model with all columns to be translated:
209
-
209
+
210
210
  translations :title, :text
211
-
211
+
212
212
  Now model will have virtual methods +title+, +text+, <tt>title=</tt>
213
213
  and <tt>text=</tt>, which will call +title_ru+ or +title_en+ and etc based
214
214
  on current user locales.
215
-
215
+
216
216
  You can use <tt>R18n::Translated</tt> mixin for any Ruby class, not only for
217
217
  ActiveRecord models.
218
218
 
data/Rakefile CHANGED
@@ -2,7 +2,6 @@
2
2
  require 'rubygems'
3
3
 
4
4
  begin
5
- require 'bundler'
6
5
  require 'bundler/setup'
7
6
  Bundler::GemHelper.install_tasks
8
7
  rescue LoadError
data/lib/r18n-rails.rb CHANGED
@@ -33,3 +33,5 @@ R18n::Filters.on(:untranslated_html)
33
33
  ActionController::Base.helper(R18n::Rails::Helpers)
34
34
  ActionController::Base.send(:include, R18n::Rails::Controller)
35
35
  ActionController::Base.send(:before_filter, :set_r18n)
36
+
37
+ ActionMailer::Base.helper(R18n::Rails::Helpers)
@@ -23,26 +23,26 @@ module R18n
23
23
  module Rails
24
24
  module Controller
25
25
  include Helpers
26
-
26
+
27
27
  private
28
-
28
+
29
29
  # Auto detect user locales and change backend.
30
30
  def set_r18n
31
31
  R18n.set do
32
32
  R18n::I18n.default = ::I18n.default_locale.to_s
33
33
  locales = R18n::I18n.parse_http(request.env['HTTP_ACCEPT_LANGUAGE'])
34
-
34
+
35
35
  if params[:locale]
36
36
  locales.insert(0, params[:locale])
37
37
  elsif session[:locale]
38
38
  locales.insert(0, session[:locale])
39
39
  end
40
-
40
+
41
41
  places = [::Rails.root.join('app/i18n'), R18n::Loader::Rails.new]
42
-
42
+
43
43
  R18n::I18n.new(locales, places)
44
44
  end
45
-
45
+
46
46
  ::I18n.backend = R18n::Backend.new
47
47
  end
48
48
  end
@@ -30,7 +30,7 @@ module R18n
30
30
  def r18n
31
31
  R18n.get
32
32
  end
33
-
33
+
34
34
  # Extend +t+ helper to use also R18n syntax.
35
35
  #
36
36
  # t 'user.name' # Rails I18n style
@@ -43,7 +43,7 @@ module R18n
43
43
  end
44
44
  end
45
45
  alias :translate :t
46
-
46
+
47
47
  # Extend +l+ helper to use also R18n syntax.
48
48
  #
49
49
  # l Time.now # Rails I18n default format
data/r18n-rails.gemspec CHANGED
@@ -14,20 +14,19 @@ Gem::Specification.new do |s|
14
14
  user language support, agnostic core package with out-of-box support for
15
15
  Rails, Sinatra, Merb and desktop applications.
16
16
  EOF
17
-
17
+
18
18
  s.files = `git ls-files`.split("\n")
19
19
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
20
  s.extra_rdoc_files = ['README.rdoc', 'LICENSE']
21
21
  s.require_path = 'lib'
22
- s.has_rdoc = true
23
-
22
+
24
23
  s.author = 'Andrey "A.I." Sitnik'
25
24
  s.email = 'andrey@sitnik.ru'
26
25
  s.homepage = 'http://r18n.rubyforge.org/'
27
26
  s.rubyforge_project = 'r18n-rails'
28
-
27
+
29
28
  s.add_dependency 'r18n-rails-api', ["= #{R18n::VERSION}"]
30
-
29
+
31
30
  s.add_development_dependency "bundler", [">= 1.0.10"]
32
31
  s.add_development_dependency "hanna", [">= 0"]
33
32
  s.add_development_dependency "rake", [">= 0", "!= 0.9.0"]
@@ -1,38 +1,38 @@
1
1
  class TestController < ApplicationController
2
2
  layout false
3
-
3
+
4
4
  def locales
5
5
  render :text => R18n.get.locales.map { |i| i.code }.join(', ')
6
6
  end
7
-
7
+
8
8
  def translations
9
9
  render :text => "R18n: #{R18n.get.r18n.translations}. " +
10
10
  "Rails I18n: #{R18n.get.i18n.translations}"
11
11
  end
12
-
12
+
13
13
  def available
14
14
  render :text => R18n.get.available_locales.map { |i| i.code }.sort.join(' ')
15
15
  end
16
-
16
+
17
17
  def helpers
18
18
  @from_controller = r18n.user.name
19
19
  render
20
20
  end
21
-
21
+
22
22
  def untranslated
23
23
  render :text => "#{R18n.get.user.not.exists}"
24
24
  end
25
-
25
+
26
26
  def controller
27
27
  render :text => "#{t('user.name')}" + "#{t.user.name}" +
28
28
  "#{r18n.t.user.name}"
29
29
  end
30
-
30
+
31
31
  def time
32
32
  render :text => l(Time.at(0).utc) + "\n" +
33
33
  l(Time.at(0).utc, :format => :short)
34
34
  end
35
-
35
+
36
36
  def human_time
37
37
  render :text => l(Time.now, :human)
38
38
  end
data/spec/rails_spec.rb CHANGED
@@ -3,74 +3,74 @@ require File.expand_path('../spec_helper', __FILE__)
3
3
 
4
4
  describe TestController, :type => :controller do
5
5
  render_views
6
-
6
+
7
7
  it 'should use default locale' do
8
8
  get :locales
9
9
  response.should be_success
10
10
  response.body.should == 'ru'
11
- end
12
-
11
+ end
12
+
13
13
  it 'should get locale from param' do
14
14
  get :locales, :locale => 'ru'
15
15
  response.should be_success
16
16
  response.body.should == 'ru, en'
17
17
  end
18
-
18
+
19
19
  it 'should get locale from session' do
20
20
  get :locales, {}, { :locale => 'ru' }
21
21
  response.should be_success
22
22
  response.body.should == 'ru, en'
23
23
  end
24
-
24
+
25
25
  it 'should get locales from http' do
26
26
  request.env['HTTP_ACCEPT_LANGUAGE'] = 'ru,fr;q=0.9'
27
27
  get :locales
28
28
  response.should be_success
29
29
  response.body.should == 'ru, fr, en'
30
30
  end
31
-
31
+
32
32
  it 'should load translations' do
33
33
  get :translations, :locale => 'en'
34
34
  response.should be_success
35
35
  response.body.should == 'R18n: supported. Rails I18n: supported'
36
36
  end
37
-
37
+
38
38
  it 'should return available translations' do
39
39
  get :available
40
40
  response.should be_success
41
41
  response.body.should == 'en ru'
42
42
  end
43
-
43
+
44
44
  it 'should add helpers' do
45
45
  get :helpers, :locale => 'en'
46
46
  response.should be_success
47
47
  response.body.should == "Name\nName\nName\nName\n"
48
48
  end
49
-
49
+
50
50
  it 'should format untranslated' do
51
51
  get :untranslated
52
52
  response.should be_success
53
53
  response.body.should == 'user.<span style="color: red">not.exists</span>'
54
54
  end
55
-
55
+
56
56
  it "should add methods to controller" do
57
57
  get :controller, :locale => 'en'
58
58
  response.should be_success
59
59
  response.body.should == "NameNameName"
60
60
  end
61
-
61
+
62
62
  it "should localize time by Rails I18n" do
63
63
  get :time, :locale => 'en'
64
64
  response.should be_success
65
65
  response.body.should == "Thu, 01 Jan 1970 00:00:00 +0000\n01 Jan 00:00"
66
66
  end
67
-
67
+
68
68
  it "should localize time by R18n" do
69
69
  get :human_time, :locale => 'en'
70
70
  response.should be_success
71
71
  response.body.should == "now"
72
72
  end
73
-
73
+
74
74
  it "should translate models" do
75
75
  ActiveRecord::Schema.verbose = false
76
76
  ActiveRecord::Schema.define(:version => 20091218130034) do
@@ -79,22 +79,22 @@ describe TestController, :type => :controller do
79
79
  t.string "title_ru"
80
80
  end
81
81
  end
82
-
82
+
83
83
  Post.unlocalized_getters(:title).should == { 'ru' => 'title_ru',
84
84
  'en' => 'title_en' }
85
85
  Post.unlocalized_setters(:title).should == { 'ru' => 'title_ru=',
86
86
  'en' => 'title_en=' }
87
-
87
+
88
88
  @post = Post.new
89
89
  @post.title_en = 'Record'
90
-
90
+
91
91
  R18n.set('ru')
92
92
  @post.title.should == 'Record'
93
-
93
+
94
94
  @post.title = 'Запись'
95
95
  @post.title_ru.should == 'Запись'
96
96
  @post.title_en.should == 'Record'
97
97
  @post.title.should == 'Запись'
98
98
  end
99
-
99
+
100
100
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: r18n-rails
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
5
- prerelease: false
4
+ hash: 25
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 10
10
- version: 0.4.10
9
+ - 11
10
+ version: 0.4.11
11
11
  platform: ruby
12
12
  authors:
13
13
  - Andrey "A.I." Sitnik
@@ -15,26 +15,27 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-07-08 00:00:00 +04:00
19
- default_executable:
18
+ date: 2011-10-02 00:00:00 Z
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
21
+ type: :runtime
22
+ name: r18n-rails-api
22
23
  prerelease: false
23
24
  version_requirements: &id001 !ruby/object:Gem::Requirement
24
25
  none: false
25
26
  requirements:
26
27
  - - "="
27
28
  - !ruby/object:Gem::Version
28
- hash: 27
29
+ hash: 25
29
30
  segments:
30
31
  - 0
31
32
  - 4
32
- - 10
33
- version: 0.4.10
33
+ - 11
34
+ version: 0.4.11
34
35
  requirement: *id001
35
- type: :runtime
36
- name: r18n-rails-api
37
36
  - !ruby/object:Gem::Dependency
37
+ type: :development
38
+ name: bundler
38
39
  prerelease: false
39
40
  version_requirements: &id002 !ruby/object:Gem::Requirement
40
41
  none: false
@@ -48,9 +49,9 @@ dependencies:
48
49
  - 10
49
50
  version: 1.0.10
50
51
  requirement: *id002
51
- type: :development
52
- name: bundler
53
52
  - !ruby/object:Gem::Dependency
53
+ type: :development
54
+ name: hanna
54
55
  prerelease: false
55
56
  version_requirements: &id003 !ruby/object:Gem::Requirement
56
57
  none: false
@@ -62,9 +63,9 @@ dependencies:
62
63
  - 0
63
64
  version: "0"
64
65
  requirement: *id003
65
- type: :development
66
- name: hanna
67
66
  - !ruby/object:Gem::Dependency
67
+ type: :development
68
+ name: rake
68
69
  prerelease: false
69
70
  version_requirements: &id004 !ruby/object:Gem::Requirement
70
71
  none: false
@@ -84,9 +85,9 @@ dependencies:
84
85
  - 0
85
86
  version: 0.9.0
86
87
  requirement: *id004
87
- type: :development
88
- name: rake
89
88
  - !ruby/object:Gem::Dependency
89
+ type: :development
90
+ name: rails
90
91
  prerelease: false
91
92
  version_requirements: &id005 !ruby/object:Gem::Requirement
92
93
  none: false
@@ -98,9 +99,9 @@ dependencies:
98
99
  - 3
99
100
  version: "3"
100
101
  requirement: *id005
101
- type: :development
102
- name: rails
103
102
  - !ruby/object:Gem::Dependency
103
+ type: :development
104
+ name: rspec
104
105
  prerelease: false
105
106
  version_requirements: &id006 !ruby/object:Gem::Requirement
106
107
  none: false
@@ -112,9 +113,9 @@ dependencies:
112
113
  - 2
113
114
  version: "2"
114
115
  requirement: *id006
115
- type: :development
116
- name: rspec
117
116
  - !ruby/object:Gem::Dependency
117
+ type: :development
118
+ name: rspec-rails
118
119
  prerelease: false
119
120
  version_requirements: &id007 !ruby/object:Gem::Requirement
120
121
  none: false
@@ -126,9 +127,9 @@ dependencies:
126
127
  - 2
127
128
  version: "2"
128
129
  requirement: *id007
129
- type: :development
130
- name: rspec-rails
131
130
  - !ruby/object:Gem::Dependency
131
+ type: :development
132
+ name: rcov
132
133
  prerelease: false
133
134
  version_requirements: &id008 !ruby/object:Gem::Requirement
134
135
  none: false
@@ -140,8 +141,6 @@ dependencies:
140
141
  - 0
141
142
  version: "0"
142
143
  requirement: *id008
143
- type: :development
144
- name: rcov
145
144
  description: " Out-of-box R18n support for Ruby on Rails.\n It is just a wrapper for R18n Rails API and R18n core libraries.\n R18n has nice Ruby-style syntax, filters, flexible locales, custom loaders,\n translation support for any classes, time and number localization, several\n user language support, agnostic core package with out-of-box support for\n Rails, Sinatra, Merb and desktop applications.\n"
146
145
  email: andrey@sitnik.ru
147
146
  executables: []
@@ -187,7 +186,6 @@ files:
187
186
  - spec/app/script/rails
188
187
  - spec/rails_spec.rb
189
188
  - spec/spec_helper.rb
190
- has_rdoc: true
191
189
  homepage: http://r18n.rubyforge.org/
192
190
  licenses: []
193
191
 
@@ -217,7 +215,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
217
215
  requirements: []
218
216
 
219
217
  rubyforge_project: r18n-rails
220
- rubygems_version: 1.3.7
218
+ rubygems_version: 1.7.2
221
219
  signing_key:
222
220
  specification_version: 3
223
221
  summary: R18n for Rails