sinatra-r18n 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,115 @@
1
+ # Sinatra R18n Plugin
2
+
3
+ Sinatra extension which provides i18n support to translate your web application.
4
+
5
+ It is a wrapper for R18n core library. See R18n documentation for more
6
+ information.
7
+
8
+ # Features
9
+
10
+ * Nice Ruby-style syntax.
11
+ * Filters.
12
+ * Flexible locales.
13
+ * Custom translations loaders.
14
+ * Translation support for any classes.
15
+ * Time and number localization.
16
+ * Several user language support.
17
+
18
+ # How To
19
+
20
+ 1. Create translations dir `./i18n/`.
21
+ 2. Add file with translation to `./i18n/` with language code in file name
22
+ (for example, `en.yml` for English or `en-us.yml` USA English dialect).
23
+ For example, `./i18n/en.yml`:
24
+
25
+ ```yaml
26
+ post:
27
+ friends: Post only for friends
28
+ tags: Post tags is %1
29
+
30
+ comments: !!pl
31
+ 0: No comments
32
+ 1: One comment
33
+ n: %1 comments
34
+
35
+ html: !!html
36
+ <b>Don't escape HTML</b>
37
+ ```
38
+
39
+ 3. Add R18n to your Sinatra application:
40
+
41
+ ```ruby
42
+ require 'sinatra/r18n'
43
+ ```
44
+ If your application inherits from `Sinatra::Base` also add:
45
+
46
+ ```ruby
47
+ class YourApp < Sinatra::Base
48
+ register Sinatra::R18n
49
+ set :root, File.dirname(__FILE__)
50
+ ```
51
+
52
+ 4. Add locale to your URLs. For example:
53
+
54
+ ```ruby
55
+ get '/:locale/posts/:id' do
56
+ @post = Post.find(params[:id])
57
+ haml :post
58
+ end
59
+ ```
60
+ Or save locale in session, when user change it:
61
+
62
+ ```ruby
63
+ before do
64
+ session[:locale] = params[:locale] if params[:locale]
65
+ end
66
+ ```
67
+
68
+ 5. Use translation messages in views. For example in HAML:
69
+
70
+ ```haml
71
+ %p= t.post.friends
72
+ %p= t.post.tags(@post.tags.join(', '))
73
+
74
+ %h2= t.comments(@post.comments.size)
75
+ ```
76
+
77
+ 6. Print localized time and numbers. For example:
78
+
79
+ ```ruby
80
+ l @post.created_at, :human
81
+ ```
82
+
83
+ 7. Print available translations. For example in HAML:
84
+
85
+ ```haml
86
+ %ul
87
+ - r18n.available_locales.each do |locale|
88
+ %li
89
+ %a( href="/#{locale.code}/" )= locale.title
90
+ ```
91
+
92
+ # Configuration
93
+
94
+ You can change default locale and translations dir:
95
+
96
+ ```ruby
97
+ set :default_locale, 'ru'
98
+ set :translations, './translations'
99
+ ```
100
+
101
+ You can also provide an Array of translations directories, which may be
102
+ useful, for instance, in a plugin-based architecture:
103
+
104
+ ```ruby
105
+ set :translations, Dir.glob('./myplugins/*/i18n')
106
+ ```
107
+
108
+ # License
109
+
110
+ R18n is licensed under the GNU Lesser General Public License version 3.
111
+ You can read it in LICENSE file or in http://www.gnu.org/licenses/lgpl.html.
112
+
113
+ # Author
114
+
115
+ 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
data/lib/sinatra/r18n.rb CHANGED
@@ -21,13 +21,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
21
21
  require 'sinatra/base'
22
22
  require 'r18n-core'
23
23
 
24
- module Sinatra #::nodoc::
25
- module R18n #::nodoc::
26
- def self.registered(app) #::nodoc::
24
+ module Sinatra
25
+ module R18n
26
+ def self.registered(app)
27
27
  app.helpers ::R18n::Helpers
28
28
  app.set :default_locale, 'en'
29
29
  app.set :translations, Proc.new { File.join(app.root, 'i18n/') }
30
30
 
31
+ ::R18n.default_places { settings.translations }
32
+
31
33
  app.before do
32
34
  ::R18n.set do
33
35
  ::R18n::I18n.default = settings.default_locale
@@ -39,12 +41,10 @@ module Sinatra #::nodoc::
39
41
  locales.insert(0, session[:locale])
40
42
  end
41
43
 
42
- ::R18n::I18n.new(locales, settings.translations)
44
+ ::R18n::I18n.new(locales, ::R18n.default_places,
45
+ :off_filters => :untranslated, :on_filters => :untranslated_html)
43
46
  end
44
47
  end
45
-
46
- ::R18n::Filters.off(:untranslated)
47
- ::R18n::Filters.on(:untranslated_html)
48
48
  end
49
49
  end
50
50
 
data/sinatra-r18n.gemspec CHANGED
@@ -13,18 +13,17 @@ Gem::Specification.new do |s|
13
13
  It has nice Ruby-style syntax, filters, flexible locales, custom loaders,
14
14
  translation support for any classes, time and number localization, several
15
15
  user language support, agnostic core package with out-of-box support for
16
- Rails, Sinatra, Merb and desktop applications.
16
+ Rails, Sinatra and desktop applications.
17
17
  EOF
18
18
 
19
19
  s.files = `git ls-files`.split("\n")
20
20
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
- s.extra_rdoc_files = ['README.rdoc', 'LICENSE']
22
- s.require_path = 'lib'
21
+ s.extra_rdoc_files = ['README.md', 'LICENSE']
22
+ s.require_path = 'lib'
23
23
 
24
- s.author = 'Andrey "A.I." Sitnik'
25
- s.email = 'andrey@sitnik.ru'
26
- s.homepage = 'http://r18n.rubyforge.org/'
27
- s.rubyforge_project = 'sinatra-r18n'
24
+ s.author = 'Andrey "A.I." Sitnik'
25
+ s.email = 'andrey@sitnik.ru'
26
+ s.homepage = 'https://github.com/ai/r18n/tree/master/sinatra-r18n'
28
27
 
29
28
  s.add_dependency 'sinatra', [">= 1.3"]
30
29
  s.add_dependency 'r18n-core', ["= #{R18n::VERSION}"]
@@ -36,4 +35,5 @@ Gem::Specification.new do |s|
36
35
  s.add_development_dependency "rspec-core", [">= 0"]
37
36
  s.add_development_dependency "rspec-expectations", [">= 0"]
38
37
  s.add_development_dependency "rspec-mocks", [">= 0"]
38
+ s.add_development_dependency "redcarpet", [">= 0"]
39
39
  end
data/spec/app/i18n/en.yml CHANGED
@@ -1,7 +1,7 @@
1
1
  greater: 1 < 2 is true
2
2
  warning: !!html <b>Warning</b>
3
3
  post:
4
- title: Post %1
4
+ title: Post %1
5
5
  comments: !!pl
6
6
  0: No comments
7
7
  1: One comment
@@ -51,7 +51,7 @@ describe Sinatra::R18n do
51
51
  it "should format untranslated string" do
52
52
  get '/untranslated'
53
53
  last_response.should be_ok
54
- last_response.body.should == 'post.<span style="color: red">no</span>'
54
+ last_response.body.should == 'post.<span style="color: red">[no]</span>'
55
55
  end
56
56
 
57
57
  it "should localize objects" do
@@ -60,4 +60,11 @@ describe Sinatra::R18n do
60
60
  last_response.body.should == "01/01/1970 00:00"
61
61
  end
62
62
 
63
+ it "should set default places" do
64
+ R18n.default_places.should ==
65
+ Pathname(__FILE__).dirname.expand_path.join('app/i18n/').to_s
66
+ R18n.set('en')
67
+ R18n.get.post.title(1).should == 'Post 1'
68
+ end
69
+
63
70
  end
data/spec/spec_helper.rb CHANGED
@@ -1,10 +1,7 @@
1
1
  # encoding: utf-8
2
-
3
- ENV['RACK_ENV'] = 'test'
4
-
5
- require 'bundler/setup'
6
2
  require 'pp'
7
3
 
4
+ ENV['RACK_ENV'] = 'test'
8
5
  require File.join(File.dirname(__FILE__), 'app/app')
9
6
 
10
7
  require 'rack/test'
metadata CHANGED
@@ -1,177 +1,199 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: sinatra-r18n
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: sinatra
23
- version_requirements: &id001 !ruby/object:Gem::Requirement
24
- none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 9
29
- segments:
30
- - 1
31
- - 3
32
- version: "1.3"
33
- prerelease: false
34
- requirement: *id001
35
- - !ruby/object:Gem::Dependency
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
36
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.3'
30
+ - !ruby/object:Gem::Dependency
37
31
  name: r18n-core
38
- version_requirements: &id002 !ruby/object:Gem::Requirement
39
- none: false
40
- requirements:
41
- - - "="
42
- - !ruby/object:Gem::Version
43
- hash: 19
44
- segments:
45
- - 0
46
- - 4
47
- - 14
48
- version: 0.4.14
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - '='
36
+ - !ruby/object:Gem::Version
37
+ version: 1.0.0
38
+ type: :runtime
49
39
  prerelease: false
50
- requirement: *id002
51
- - !ruby/object:Gem::Dependency
52
- type: :development
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - '='
44
+ - !ruby/object:Gem::Version
45
+ version: 1.0.0
46
+ - !ruby/object:Gem::Dependency
53
47
  name: bundler
54
- version_requirements: &id003 !ruby/object:Gem::Requirement
55
- none: false
56
- requirements:
57
- - - ">="
58
- - !ruby/object:Gem::Version
59
- hash: 3
60
- segments:
61
- - 1
62
- - 0
63
- - 10
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
64
53
  version: 1.0.10
65
- prerelease: false
66
- requirement: *id003
67
- - !ruby/object:Gem::Dependency
68
54
  type: :development
69
- name: yard
70
- version_requirements: &id004 !ruby/object:Gem::Requirement
71
- none: false
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- hash: 3
76
- segments:
77
- - 0
78
- version: "0"
79
55
  prerelease: false
80
- requirement: *id004
81
- - !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'
82
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
83
79
  name: rake
84
- version_requirements: &id005 !ruby/object:Gem::Requirement
85
- none: false
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- hash: 3
90
- segments:
91
- - 0
92
- version: "0"
93
- - - "!="
94
- - !ruby/object:Gem::Version
95
- hash: 59
96
- segments:
97
- - 0
98
- - 9
99
- - 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
100
88
  version: 0.9.0
101
- prerelease: false
102
- requirement: *id005
103
- - !ruby/object:Gem::Dependency
104
89
  type: :development
105
- name: rack-test
106
- version_requirements: &id006 !ruby/object:Gem::Requirement
107
- none: false
108
- requirements:
109
- - - ">="
110
- - !ruby/object:Gem::Version
111
- hash: 3
112
- segments:
113
- - 0
114
- version: "0"
115
90
  prerelease: false
116
- requirement: *id006
117
- - !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: rack-test
102
+ requirement: !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ! '>='
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
118
108
  type: :development
119
- name: rspec-core
120
- version_requirements: &id007 !ruby/object:Gem::Requirement
121
- none: false
122
- requirements:
123
- - - ">="
124
- - !ruby/object:Gem::Version
125
- hash: 3
126
- segments:
127
- - 0
128
- version: "0"
129
109
  prerelease: false
130
- requirement: *id007
131
- - !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-core
118
+ requirement: !ruby/object:Gem::Requirement
119
+ none: false
120
+ requirements:
121
+ - - ! '>='
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
132
124
  type: :development
133
- name: rspec-expectations
134
- version_requirements: &id008 !ruby/object:Gem::Requirement
135
- none: false
136
- requirements:
137
- - - ">="
138
- - !ruby/object:Gem::Version
139
- hash: 3
140
- segments:
141
- - 0
142
- version: "0"
143
125
  prerelease: false
144
- requirement: *id008
145
- - !ruby/object:Gem::Dependency
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
133
+ name: rspec-expectations
134
+ requirement: !ruby/object:Gem::Requirement
135
+ none: false
136
+ requirements:
137
+ - - ! '>='
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
146
140
  type: :development
141
+ prerelease: false
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
147
149
  name: rspec-mocks
148
- version_requirements: &id009 !ruby/object:Gem::Requirement
149
- none: false
150
- requirements:
151
- - - ">="
152
- - !ruby/object:Gem::Version
153
- hash: 3
154
- segments:
155
- - 0
156
- version: "0"
150
+ requirement: !ruby/object:Gem::Requirement
151
+ none: false
152
+ requirements:
153
+ - - ! '>='
154
+ - !ruby/object:Gem::Version
155
+ version: '0'
156
+ type: :development
157
157
  prerelease: false
158
- requirement: *id009
159
- description: " A Sinatra extension that provides i18n support to translate your web\n application. It is just a wrapper for R18n core library.\n It 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"
158
+ version_requirements: !ruby/object:Gem::Requirement
159
+ none: false
160
+ requirements:
161
+ - - ! '>='
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ - !ruby/object:Gem::Dependency
165
+ name: redcarpet
166
+ requirement: !ruby/object:Gem::Requirement
167
+ none: false
168
+ requirements:
169
+ - - ! '>='
170
+ - !ruby/object:Gem::Version
171
+ version: '0'
172
+ type: :development
173
+ prerelease: false
174
+ version_requirements: !ruby/object:Gem::Requirement
175
+ none: false
176
+ requirements:
177
+ - - ! '>='
178
+ - !ruby/object:Gem::Version
179
+ version: '0'
180
+ description: ! " A Sinatra extension that provides i18n support to translate your
181
+ web\n application. It is just a wrapper for R18n core library.\n It has nice
182
+ Ruby-style syntax, filters, flexible locales, custom loaders,\n translation support
183
+ for any classes, time and number localization, several\n user language support,
184
+ agnostic core package with out-of-box support for\n Rails, Sinatra and desktop
185
+ applications.\n"
160
186
  email: andrey@sitnik.ru
161
187
  executables: []
162
-
163
188
  extensions: []
164
-
165
- extra_rdoc_files:
166
- - README.rdoc
189
+ extra_rdoc_files:
190
+ - README.md
167
191
  - LICENSE
168
- files:
192
+ files:
169
193
  - .rspec
170
194
  - .yardopts
171
- - Gemfile
172
- - Gemfile.lock
173
195
  - LICENSE
174
- - README.rdoc
196
+ - README.md
175
197
  - Rakefile
176
198
  - lib/sinatra/r18n.rb
177
199
  - sinatra-r18n.gemspec
@@ -181,39 +203,35 @@ files:
181
203
  - spec/app/views/post.erb
182
204
  - spec/sinatra-r18n_spec.rb
183
205
  - spec/spec_helper.rb
184
- homepage: http://r18n.rubyforge.org/
206
+ homepage: https://github.com/ai/r18n/tree/master/sinatra-r18n
185
207
  licenses: []
186
-
187
208
  post_install_message:
188
209
  rdoc_options: []
189
-
190
- require_paths:
210
+ require_paths:
191
211
  - lib
192
- required_ruby_version: !ruby/object:Gem::Requirement
212
+ required_ruby_version: !ruby/object:Gem::Requirement
193
213
  none: false
194
- requirements:
195
- - - ">="
196
- - !ruby/object:Gem::Version
197
- hash: 3
198
- segments:
214
+ requirements:
215
+ - - ! '>='
216
+ - !ruby/object:Gem::Version
217
+ version: '0'
218
+ segments:
199
219
  - 0
200
- version: "0"
201
- required_rubygems_version: !ruby/object:Gem::Requirement
220
+ hash: 4184599958665730813
221
+ required_rubygems_version: !ruby/object:Gem::Requirement
202
222
  none: false
203
- requirements:
204
- - - ">="
205
- - !ruby/object:Gem::Version
206
- hash: 3
207
- segments:
223
+ requirements:
224
+ - - ! '>='
225
+ - !ruby/object:Gem::Version
226
+ version: '0'
227
+ segments:
208
228
  - 0
209
- version: "0"
229
+ hash: 4184599958665730813
210
230
  requirements: []
211
-
212
- rubyforge_project: sinatra-r18n
213
- rubygems_version: 1.7.2
231
+ rubyforge_project:
232
+ rubygems_version: 1.8.23
214
233
  signing_key:
215
234
  specification_version: 3
216
235
  summary: A Sinatra extension that provides i18n support to translate your web application.
217
236
  test_files: []
218
-
219
237
  has_rdoc:
data/Gemfile DELETED
@@ -1,7 +0,0 @@
1
- source :rubygems
2
-
3
- gem 'psych', :platforms => :mri_19, :group => [ :test, :development ]
4
-
5
- gem 'r18n-core', :path => '../r18n-core/'
6
-
7
- gemspec
data/Gemfile.lock DELETED
@@ -1,48 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- sinatra-r18n (0.4.14)
5
- r18n-core (= 0.4.14)
6
- sinatra (>= 1.3)
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
- psych (1.2.2)
18
- rack (1.4.1)
19
- rack-protection (1.2.0)
20
- rack
21
- rack-test (0.6.1)
22
- rack (>= 1.0)
23
- rake (0.9.2.2)
24
- rspec-core (2.8.0)
25
- rspec-expectations (2.8.0)
26
- diff-lcs (~> 1.1.2)
27
- rspec-mocks (2.8.0)
28
- sinatra (1.3.2)
29
- rack (~> 1.3, >= 1.3.6)
30
- rack-protection (~> 1.2)
31
- tilt (~> 1.3, >= 1.3.3)
32
- tilt (1.3.3)
33
- yard (0.7.4)
34
-
35
- PLATFORMS
36
- ruby
37
-
38
- DEPENDENCIES
39
- bundler (>= 1.0.10)
40
- psych
41
- r18n-core!
42
- rack-test
43
- rake (>= 0, != 0.9.0)
44
- rspec-core
45
- rspec-expectations
46
- rspec-mocks
47
- sinatra-r18n!
48
- yard
data/README.rdoc DELETED
@@ -1,97 +0,0 @@
1
- = Sinatra R18n Plugin
2
-
3
- Sinatra extension which provides i18n support to translate your web application.
4
-
5
- It is a wrapper for R18n core library. See R18n documentation for more
6
- information.
7
-
8
- == Features
9
-
10
- * Nice Ruby-style syntax.
11
- * Filters.
12
- * Flexible locales.
13
- * Custom translations loaders.
14
- * Translation support for any classes.
15
- * Time and number localization.
16
- * Several user language support.
17
-
18
- == How To
19
-
20
- 1. Create translations dir <tt>./i18n/</tt>.
21
- 2. Add file with translation to <tt>./i18n/</tt> with language code in file name
22
- (for example, <tt>en.yml</tt> for English or <tt>en-us.yml</tt> USA English
23
- dialect). For example, <tt>./i18n/en.yml</tt>:
24
-
25
- post:
26
- friends: Post only for friends
27
- tags: Post tags is %1
28
-
29
- comments: !!pl
30
- 0: No comments
31
- 1: One comment
32
- n: %1 comments
33
-
34
- html: !!html
35
- <b>Don't escape HTML</b>
36
-
37
- 3. Add R18n to your Sinatra application:
38
-
39
- require 'sinatra/r18n'
40
-
41
- If your application inherits from <tt>Sinatra::Base</tt> also add:
42
-
43
- class YourApp < Sinatra::Base
44
- register Sinatra::R18n
45
- set :root, File.dirname(__FILE__)
46
-
47
- 4. Add locale to your URLs. For example:
48
-
49
- get '/:locale/posts/:id' do
50
- @post = Post.find(params[:id])
51
- haml :post
52
- end
53
-
54
- Or save locale in session, when user change it:
55
-
56
- before do
57
- session[:locale] = params[:locale] if params[:locale]
58
- end
59
-
60
- 5. Use translation messages in views. For example in HAML:
61
-
62
- %p= t.post.friends
63
- %p= t.post.tags(@post.tags.join(', '))
64
-
65
- %h2= t.comments(@post.comments.size)
66
-
67
- 6. Print localized time and numbers. For example:
68
-
69
- l @post.created_at, :human
70
-
71
- 7. Print available translations. For example in HAML:
72
-
73
- %ul
74
- - r18n.available_locales.each do |locale|
75
- %li
76
- %a( href="/#{locale.code}/" )= locale.title
77
-
78
- == Configuration
79
-
80
- You can change default locale and translations dir:
81
-
82
- set :default_locale, 'ru'
83
- set :translations, './translations'
84
-
85
- You can also provide an Array of translations directories, which may be
86
- useful, for instance, in a plugin-based architecture:
87
-
88
- set :translations, Dir.glob('./myplugins/*/i18n')
89
-
90
- == License
91
-
92
- R18n is licensed under the GNU Lesser General Public License version 3.
93
- You can read it in LICENSE file or in http://www.gnu.org/licenses/lgpl.html.
94
-
95
- == Author
96
-
97
- Andrey “A.I.” Sitnik <andrey@sitnik.ru>