r18n-rails-api 0.4.14 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.yardopts CHANGED
@@ -1,3 +1,3 @@
1
1
  --charset utf-8
2
2
  -
3
- README.rdoc
3
+ README.md
data/LICENSE CHANGED
@@ -10,7 +10,7 @@
10
10
  the terms and conditions of version 3 of the GNU General Public
11
11
  License, supplemented by the additional permissions listed below.
12
12
 
13
- 0. Additional Definitions.
13
+ 0. Additional Definitions.
14
14
 
15
15
  As used herein, "this License" refers to version 3 of the GNU Lesser
16
16
  General Public License, and the "GNU GPL" refers to version 3 of the GNU
@@ -111,7 +111,7 @@ the following:
111
111
  a copy of the Library already present on the user's computer
112
112
  system, and (b) will operate properly with a modified version
113
113
  of the Library that is interface-compatible with the Linked
114
- Version.
114
+ Version.
115
115
 
116
116
  e) Provide Installation Information, but only if you would otherwise
117
117
  be required to provide such information under section 6 of the
data/README.md ADDED
@@ -0,0 +1,85 @@
1
+ # R18n Rails API
2
+
3
+ Rails I18n compatibility for R18n:
4
+ * filters to work with named variables in Rails translation format;
5
+ * R18n loader for Rails I18n translation format;
6
+ * R18n backend.
7
+
8
+ ## How To
9
+
10
+ ### Variables
11
+
12
+ After require-ing `r18n-rails-api` you can use named variables in all
13
+ translations:
14
+
15
+ ```yaml
16
+ greeting: "Hi, %{name}"
17
+ users: !!pl
18
+ 1: One user
19
+ n: %{count} users
20
+ ```
21
+
22
+ ```ruby
23
+ require 'r18n-rails-api'
24
+
25
+ i18n.greeting(:name => 'John') #=> "Hi, John"
26
+ i18n.users(:count => 5) #=> "5 users"
27
+ ```
28
+
29
+ ### Rails Translations
30
+
31
+ You can use `R18n::Loader::Rails` to load translations from `I18n.load_path`:
32
+
33
+ `i18n/en.yml`:
34
+
35
+ ```yaml
36
+ en:
37
+ posts:
38
+ one: One post
39
+ many: %{count} posts
40
+ ```
41
+
42
+ `example.rb`:
43
+
44
+ ```ruby
45
+ require 'r18n-rails-api'
46
+
47
+ I18n.load_path = ['i18n/en.yml']
48
+ i18n = R18n::I18n.new('en', R18n::Loader::Rails)
49
+
50
+ i18n.posts(:count => 5) #=> "5 posts"
51
+ ```
52
+
53
+ ### Backend
54
+
55
+ You can use R18n as a backend for Rails I18n:
56
+
57
+ ```ruby
58
+ require 'r18n-rails-api'
59
+
60
+ R18n.set('en', 'path/to/translation')
61
+ I18n.backend = R18n::Backend
62
+
63
+ I18n.l Time.now, :format => :full #=> "6th of December, 2009 22:44"
64
+ I18n.t :greeting, :name => 'John' #=> "Hi, John"
65
+ I18n.t :users, :count => 5 #=> "5 users"
66
+ ```
67
+
68
+ ## R18n Features
69
+
70
+ * Nice Ruby-style syntax.
71
+ * Filters.
72
+ * Flexible locales.
73
+ * Custom translations loaders.
74
+ * Translation support for any classes.
75
+ * Time and number localization.
76
+ * Several user languages support.
77
+
78
+ ## License
79
+
80
+ R18n is licensed under the GNU Lesser General Public License version 3.
81
+ You can read it in LICENSE file or in http://www.gnu.org/licenses/lgpl.html.
82
+
83
+ ## Author
84
+
85
+ Andrey “A.I.” Sitnik <andrey@sitnik.ru>
data/Rakefile CHANGED
@@ -22,7 +22,8 @@ YARD::Rake::YardocTask.new do |yard|
22
22
  end
23
23
 
24
24
  task :clobber_doc do
25
- rm_r 'doc' rescue nil
25
+ rm_r 'doc' rescue nil
26
+ rm_r '.yardoc' rescue nil
26
27
  end
27
28
  task :clobber_package do
28
29
  rm_r 'pkg' rescue nil
@@ -57,10 +57,10 @@ module R18n
57
57
  end
58
58
  end
59
59
 
60
- # Convert +object+ to String, according to the rules of the current
60
+ # Convert +object+ to String, according to the rules of the current
61
61
  # R18n locale. It didn’t use +locale+ argument, only current R18n I18n
62
62
  # object. It support Fixnum, Bignum, Float, Time, Date and DateTime.
63
- #
63
+ #
64
64
  # Support Rails I18n (+:default+, +:short+, +:long+, +:long_ordinal+,
65
65
  # +:only_day+ and +:only_second+) and R18n (+:full+, +:human+, +:standard+
66
66
  # and +:month+) time formatters.
@@ -26,9 +26,12 @@ R18n::Filters.add(String, :named_variables) do |content, config, params|
26
26
  if params.is_a? Hash
27
27
  content = content.clone
28
28
  params.each_pair do |name, value|
29
- v = config[:locale].localize(value)
30
- content.gsub! "%{#{name}}", v
31
- content.gsub! "{{#{name}}}", v
29
+ value = config[:locale].localize(value)
30
+ if defined? ActiveSupport::SafeBuffer
31
+ value = ActiveSupport::SafeBuffer.new + value
32
+ end
33
+ content.gsub! "%{#{name}}", value
34
+ content.gsub! "{{#{name}}}", value
32
35
  end
33
36
  end
34
37
  content
@@ -29,7 +29,7 @@ module R18n
29
29
  # It use Rails I18n backend to load translations. By default, simple
30
30
  # backend will be used, by you can change it, if use extended backend
31
31
  # (for example, with ActiveRecord storage):
32
- #
32
+ #
33
33
  # R18n::I18n.new('en',
34
34
  # R18n::Loader::Rails.new(I18n::Backend::ActiveRecord.new))
35
35
  class Rails
@@ -50,7 +50,7 @@ module R18n
50
50
  # Array of locales, which has translations in +I18n.load_path+.
51
51
  def available
52
52
  reload!
53
- @translations.keys.map { |code| R18n::Locale.load(code) }
53
+ @translations.keys.map { |code| R18n.locale(code) }
54
54
  end
55
55
 
56
56
  # Return Hash with translations for +locale+.
@@ -15,15 +15,14 @@ Gem::Specification.new do |s|
15
15
  Rails, Sinatra, Merb and desktop applications.
16
16
  EOF
17
17
 
18
- s.files = `git ls-files`.split("\n")
19
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
- s.extra_rdoc_files = ['README.rdoc', 'LICENSE']
21
- s.require_path = 'lib'
18
+ s.files = `git ls-files`.split("\n")
19
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
+ s.extra_rdoc_files = ['README.md', 'LICENSE']
21
+ s.require_path = 'lib'
22
22
 
23
- s.author = 'Andrey "A.I." Sitnik'
24
- s.email = 'andrey@sitnik.ru'
25
- s.homepage = 'http://r18n.rubyforge.org/'
26
- s.rubyforge_project = 'r18n-rails-api'
23
+ s.author = 'Andrey "A.I." Sitnik'
24
+ s.email = 'andrey@sitnik.ru'
25
+ s.homepage = 'https://github.com/ai/r18n/tree/master/r18n-rails-api'
27
26
 
28
27
  s.add_dependency 'r18n-core', ["= #{R18n::VERSION}"]
29
28
  s.add_dependency 'i18n'
@@ -34,4 +33,5 @@ Gem::Specification.new do |s|
34
33
  s.add_development_dependency "rspec-core", [">= 0"]
35
34
  s.add_development_dependency "rspec-expectations", [">= 0"]
36
35
  s.add_development_dependency "rspec-mocks", [">= 0"]
36
+ s.add_development_dependency "redcarpet", [">= 0"]
37
37
  end
data/spec/filters_spec.rb CHANGED
@@ -2,28 +2,33 @@
2
2
  require File.expand_path('../spec_helper', __FILE__)
3
3
 
4
4
  describe 'Rails filters' do
5
- before :all do
6
- @en = R18n::Locale.load('en')
7
- end
8
5
 
9
6
  it "should use named variables" do
10
- i18n = R18n::Translation.new(@en, '', @en, {'echo' => 'Value is %{value}'})
7
+ i18n = R18n::Translation.new(EN, '', :locale => EN,
8
+ :translations => { 'echo' => 'Value is %{value}' })
11
9
 
12
10
  i18n.echo(:value => 'R18n').should == 'Value is R18n'
13
- i18n.echo(:value => -5.5).should == 'Value is −5.5'
14
- i18n.echo(:value => 5000).should == 'Value is 5,000'
11
+ i18n.echo(:value => -5.5).should == 'Value is −5.5'
12
+ i18n.echo(:value => 5000).should == 'Value is 5,000'
13
+ i18n.echo(:value => '<b>').should == 'Value is &lt;b&gt;'
15
14
  i18n.echo.should == 'Value is %{value}'
16
15
  end
17
16
 
18
17
  it "should use old variables syntax" do
19
- i18n = R18n::Translation.new(@en, '', @en, {'echo' => 'Value is {{value}}',})
18
+ i18n = R18n::Translation.new(EN, '', :locale => EN,
19
+ :translations => { 'echo' => 'Value is {{value}}' })
20
20
  i18n.echo(:value => 'Old').should == 'Value is Old'
21
21
  end
22
22
 
23
23
  it "should pluralize by variable %{count}" do
24
- i18n = R18n::Translation.new(@en, '', @en, {'users' => R18n::Typed.new('pl',
25
- { 0 => 'no users', 1 => '1 user', 'n' => '%{count} users' }
26
- ) })
24
+ i18n = R18n::Translation.new(EN, '', :locale => EN,
25
+ :translations => {
26
+ 'users' => R18n::Typed.new('pl', {
27
+ 0 => 'no users',
28
+ 1 => '1 user',
29
+ 'n' => '%{count} users'
30
+ })
31
+ })
27
32
 
28
33
  i18n.users(:count => 0).should == 'no users'
29
34
  i18n.users(:count => 1).should == '1 user'
data/spec/spec_helper.rb CHANGED
@@ -1,11 +1,12 @@
1
- require 'rubygems'
1
+ # encoding: utf-8
2
2
  require 'pp'
3
3
  require 'i18n'
4
+ require 'active_support'
4
5
 
5
6
  require File.join(File.dirname(__FILE__), '../lib/r18n-rails-api')
6
7
 
7
- EN = R18n::Locale.load(:en)
8
- RU = R18n::Locale.load(:ru)
8
+ EN = R18n.locale(:en)
9
+ RU = R18n.locale(:ru)
9
10
 
10
11
  GENERAL = Dir.glob(File.join(File.dirname(__FILE__), 'data/general/*'))
11
12
  SIMPLE = Dir.glob(File.join(File.dirname(__FILE__), 'data/simple/*'))
metadata CHANGED
@@ -1,162 +1,182 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: r18n-rails-api
3
- version: !ruby/object:Gem::Version
4
- hash: 19
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 4
9
- - 14
10
- version: 0.4.14
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Andrey "A.I." Sitnik
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-01-25 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
21
- type: :runtime
12
+ date: 2012-06-24 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: r18n-core
23
- version_requirements: &id001 !ruby/object:Gem::Requirement
24
- none: false
25
- requirements:
26
- - - "="
27
- - !ruby/object:Gem::Version
28
- hash: 19
29
- segments:
30
- - 0
31
- - 4
32
- - 14
33
- version: 0.4.14
34
- prerelease: false
35
- requirement: *id001
36
- - !ruby/object:Gem::Dependency
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - '='
20
+ - !ruby/object:Gem::Version
21
+ version: 1.0.0
37
22
  type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - '='
28
+ - !ruby/object:Gem::Version
29
+ version: 1.0.0
30
+ - !ruby/object:Gem::Dependency
38
31
  name: i18n
39
- version_requirements: &id002 !ruby/object:Gem::Requirement
40
- none: false
41
- requirements:
42
- - - ">="
43
- - !ruby/object:Gem::Version
44
- hash: 3
45
- segments:
46
- - 0
47
- version: "0"
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
48
39
  prerelease: false
49
- requirement: *id002
50
- - !ruby/object:Gem::Dependency
51
- type: :development
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
52
47
  name: bundler
53
- version_requirements: &id003 !ruby/object:Gem::Requirement
54
- none: false
55
- requirements:
56
- - - ">="
57
- - !ruby/object:Gem::Version
58
- hash: 3
59
- segments:
60
- - 1
61
- - 0
62
- - 10
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
63
53
  version: 1.0.10
64
- prerelease: false
65
- requirement: *id003
66
- - !ruby/object:Gem::Dependency
67
54
  type: :development
68
- name: yard
69
- version_requirements: &id004 !ruby/object:Gem::Requirement
70
- none: false
71
- requirements:
72
- - - ">="
73
- - !ruby/object:Gem::Version
74
- hash: 3
75
- segments:
76
- - 0
77
- version: "0"
78
55
  prerelease: false
79
- requirement: *id004
80
- - !ruby/object:Gem::Dependency
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 1.0.10
62
+ - !ruby/object:Gem::Dependency
63
+ name: yard
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
81
70
  type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
82
79
  name: rake
83
- version_requirements: &id005 !ruby/object:Gem::Requirement
84
- none: false
85
- requirements:
86
- - - ">="
87
- - !ruby/object:Gem::Version
88
- hash: 3
89
- segments:
90
- - 0
91
- version: "0"
92
- - - "!="
93
- - !ruby/object:Gem::Version
94
- hash: 59
95
- segments:
96
- - 0
97
- - 9
98
- - 0
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ - - ! '!='
87
+ - !ruby/object:Gem::Version
99
88
  version: 0.9.0
100
- prerelease: false
101
- requirement: *id005
102
- - !ruby/object:Gem::Dependency
103
89
  type: :development
104
- name: rspec-core
105
- version_requirements: &id006 !ruby/object:Gem::Requirement
106
- none: false
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- hash: 3
111
- segments:
112
- - 0
113
- version: "0"
114
90
  prerelease: false
115
- requirement: *id006
116
- - !ruby/object:Gem::Dependency
91
+ version_requirements: !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - - ! '!='
98
+ - !ruby/object:Gem::Version
99
+ version: 0.9.0
100
+ - !ruby/object:Gem::Dependency
101
+ name: rspec-core
102
+ requirement: !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ! '>='
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
117
108
  type: :development
118
- name: rspec-expectations
119
- version_requirements: &id007 !ruby/object:Gem::Requirement
120
- none: false
121
- requirements:
122
- - - ">="
123
- - !ruby/object:Gem::Version
124
- hash: 3
125
- segments:
126
- - 0
127
- version: "0"
128
109
  prerelease: false
129
- requirement: *id007
130
- - !ruby/object:Gem::Dependency
110
+ version_requirements: !ruby/object:Gem::Requirement
111
+ none: false
112
+ requirements:
113
+ - - ! '>='
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ - !ruby/object:Gem::Dependency
117
+ name: rspec-expectations
118
+ requirement: !ruby/object:Gem::Requirement
119
+ none: false
120
+ requirements:
121
+ - - ! '>='
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
131
124
  type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ none: false
128
+ requirements:
129
+ - - ! '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ - !ruby/object:Gem::Dependency
132
133
  name: rspec-mocks
133
- version_requirements: &id008 !ruby/object:Gem::Requirement
134
- none: false
135
- requirements:
136
- - - ">="
137
- - !ruby/object:Gem::Version
138
- hash: 3
139
- segments:
140
- - 0
141
- version: "0"
134
+ requirement: !ruby/object:Gem::Requirement
135
+ none: false
136
+ requirements:
137
+ - - ! '>='
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ type: :development
142
141
  prerelease: false
143
- requirement: *id008
144
- description: " R18n backend for Rails I18n and R18n filters and loader to support Rails\n translation format.\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"
142
+ version_requirements: !ruby/object:Gem::Requirement
143
+ none: false
144
+ requirements:
145
+ - - ! '>='
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ - !ruby/object:Gem::Dependency
149
+ name: redcarpet
150
+ requirement: !ruby/object:Gem::Requirement
151
+ none: false
152
+ requirements:
153
+ - - ! '>='
154
+ - !ruby/object:Gem::Version
155
+ version: '0'
156
+ type: :development
157
+ prerelease: false
158
+ version_requirements: !ruby/object:Gem::Requirement
159
+ none: false
160
+ requirements:
161
+ - - ! '>='
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ description: ! " R18n backend for Rails I18n and R18n filters and loader to support
165
+ Rails\n translation format.\n R18n has nice Ruby-style syntax, filters, flexible
166
+ locales, custom loaders,\n translation support for any classes, time and number
167
+ localization, several\n user language support, agnostic core package with out-of-box
168
+ support for\n Rails, Sinatra, Merb and desktop applications.\n"
145
169
  email: andrey@sitnik.ru
146
170
  executables: []
147
-
148
171
  extensions: []
149
-
150
- extra_rdoc_files:
151
- - README.rdoc
172
+ extra_rdoc_files:
173
+ - README.md
152
174
  - LICENSE
153
- files:
175
+ files:
154
176
  - .rspec
155
177
  - .yardopts
156
- - Gemfile
157
- - Gemfile.lock
158
178
  - LICENSE
159
- - README.rdoc
179
+ - README.md
160
180
  - Rakefile
161
181
  - lib/r18n-rails-api.rb
162
182
  - lib/r18n-rails-api/backend.rb
@@ -173,39 +193,35 @@ files:
173
193
  - spec/filters_spec.rb
174
194
  - spec/loader_spec.rb
175
195
  - spec/spec_helper.rb
176
- homepage: http://r18n.rubyforge.org/
196
+ homepage: https://github.com/ai/r18n/tree/master/r18n-rails-api
177
197
  licenses: []
178
-
179
198
  post_install_message:
180
199
  rdoc_options: []
181
-
182
- require_paths:
200
+ require_paths:
183
201
  - lib
184
- required_ruby_version: !ruby/object:Gem::Requirement
202
+ required_ruby_version: !ruby/object:Gem::Requirement
185
203
  none: false
186
- requirements:
187
- - - ">="
188
- - !ruby/object:Gem::Version
189
- hash: 3
190
- segments:
204
+ requirements:
205
+ - - ! '>='
206
+ - !ruby/object:Gem::Version
207
+ version: '0'
208
+ segments:
191
209
  - 0
192
- version: "0"
193
- required_rubygems_version: !ruby/object:Gem::Requirement
210
+ hash: 1882288151975101443
211
+ required_rubygems_version: !ruby/object:Gem::Requirement
194
212
  none: false
195
- requirements:
196
- - - ">="
197
- - !ruby/object:Gem::Version
198
- hash: 3
199
- segments:
213
+ requirements:
214
+ - - ! '>='
215
+ - !ruby/object:Gem::Version
216
+ version: '0'
217
+ segments:
200
218
  - 0
201
- version: "0"
219
+ hash: 1882288151975101443
202
220
  requirements: []
203
-
204
- rubyforge_project: r18n-rails-api
205
- rubygems_version: 1.7.2
221
+ rubyforge_project:
222
+ rubygems_version: 1.8.23
206
223
  signing_key:
207
224
  specification_version: 3
208
225
  summary: Rails I18n compatibility for R18n
209
226
  test_files: []
210
-
211
227
  has_rdoc:
data/Gemfile DELETED
@@ -1,7 +0,0 @@
1
- source :rubygems
2
-
3
- gem 'psych', :group => :development, :platforms => :mri_19
4
-
5
- gem 'r18n-core', :path => '../r18n-core/'
6
-
7
- gemspec
data/Gemfile.lock DELETED
@@ -1,38 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- r18n-rails-api (0.4.14)
5
- i18n
6
- r18n-core (= 0.4.14)
7
-
8
- PATH
9
- remote: ../r18n-core/
10
- specs:
11
- r18n-core (0.4.14)
12
-
13
- GEM
14
- remote: http://rubygems.org/
15
- specs:
16
- diff-lcs (1.1.3)
17
- i18n (0.6.0)
18
- psych (1.2.2)
19
- rake (0.9.2.2)
20
- rspec-core (2.8.0)
21
- rspec-expectations (2.8.0)
22
- diff-lcs (~> 1.1.2)
23
- rspec-mocks (2.8.0)
24
- yard (0.7.4)
25
-
26
- PLATFORMS
27
- ruby
28
-
29
- DEPENDENCIES
30
- bundler (>= 1.0.10)
31
- psych
32
- r18n-core!
33
- r18n-rails-api!
34
- rake (>= 0, != 0.9.0)
35
- rspec-core
36
- rspec-expectations
37
- rspec-mocks
38
- yard
data/README.rdoc DELETED
@@ -1,74 +0,0 @@
1
- = R18n Rails API
2
-
3
- Rails I18n compatibility for R18n:
4
- * filters to work with named variables in Rails translation format;
5
- * R18n loader for Rails I18n translation format;
6
- * R18n backend.
7
-
8
- == How To
9
-
10
- === Variables
11
-
12
- After require-ing <tt>r18n-rails-api</tt> you can use named variables in all
13
- translations:
14
-
15
- greeting: "Hi, %{name}"
16
- users: !!pl
17
- 1: One user
18
- n: %{count} users
19
-
20
- require 'r18n-rails-api'
21
-
22
- i18n.greeting(:name => 'John') #=> "Hi, John"
23
- i18n.users(:count => 5) #=> "5 users"
24
-
25
- === Rails Translations
26
-
27
- You can use <tt>R18n::Loader::Rails</tt> to load translations from
28
- <tt>I18n.load_path</tt>:
29
-
30
- i18n/en.yml:
31
- en:
32
- posts:
33
- one: One post
34
- many: %{count} posts
35
-
36
- example.rb:
37
- require 'r18n-rails-api'
38
-
39
- I18n.load_path = ['i18n/en.yml']
40
- i18n = R18n::I18n.new('en', R18n::Loader::Rails)
41
-
42
- i18n.posts(:count => 5) #=> "5 posts"
43
-
44
- === Backend
45
-
46
- You can use R18n as a backend for Rails I18n:
47
-
48
- require 'r18n-rails-api'
49
-
50
- R18n.set('en', 'path/to/translation')
51
- I18n.backend = R18n::Backend
52
-
53
- I18n.l Time.now, :format => :full #=> "6th of December, 2009 22:44"
54
- I18n.t :greeting, :name => 'John' #=> "Hi, John"
55
- I18n.t :users, :count => 5 #=> "5 users"
56
-
57
- == R18n Features
58
-
59
- * Nice Ruby-style syntax.
60
- * Filters.
61
- * Flexible locales.
62
- * Custom translations loaders.
63
- * Translation support for any classes.
64
- * Time and number localization.
65
- * Several user languages support.
66
-
67
- == License
68
-
69
- R18n is licensed under the GNU Lesser General Public License version 3.
70
- You can read it in LICENSE file or in http://www.gnu.org/licenses/lgpl.html.
71
-
72
- == Author
73
-
74
- Andrey “A.I.” Sitnik <andrey@sitnik.ru>