roda-i18n 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4feabc4adea61f368ca2a43fc29fbcd00d0ae10e
4
- data.tar.gz: 609e51e11fd9a376c5201dbf07a6eadea8983b07
3
+ metadata.gz: 61da5676e50ba7ef694e025bfd717c279c0dfe01
4
+ data.tar.gz: 57e1b41f3d7856e464e51542fa9c6172f6fe93bc
5
5
  SHA512:
6
- metadata.gz: faa5f46acced714ad64e94220d4c8c944962c92b41cc7463d49439cf83e4c0fb86acb11469c60bad01f3e17855a7492f017fb893626808c9dc1571cbc424ec65
7
- data.tar.gz: 09c908134c0196c657d42c111279dffc083f0f9c54f03ddb979024d66ad4d4ada98518d3f6ce64d07e961a2c54cc09a77132ad6b011057b2565e4ff459367a99
6
+ metadata.gz: 741426239b80ef746c01ba0e3551855af218b12412147d8117da8a2524eba80502b7c934bca41ae1ad6cbbeaa2f1375581c08f639fe233776dbf69a397227437
7
+ data.tar.gz: 931482a0bbd46455887a2f67affc4a93c13329db1acf73c723e386f3cdf29aaecbe4f340cbcabee2ea4f2bdd8f83fc3f22243714eb4734966d602067befe3f17
@@ -0,0 +1,4 @@
1
+ tmp
2
+ Gemfile.lock
3
+ coverage
4
+ pkg
data/Gemfile ADDED
@@ -0,0 +1,19 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in roda-tags.gemspec
4
+ gemspec
5
+
6
+ # gem 'roda', '~> 2.5.1'
7
+ # gem 'r18n-core'
8
+ #
9
+ # group :test do
10
+ # gem 'minitest'
11
+ # gem 'minitest-hooks'
12
+ # gem "rack-test"
13
+ #
14
+ # gem 'tilt'
15
+ # gem 'erubis'
16
+ # gem 'kramdown'
17
+ #
18
+ # gem 'simplecov', :require => false
19
+ # end
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # Roda-i18n
2
2
 
3
- Easily add Internationalisation (i18n) and localisation support for [Roda](http://roda.jeremyevans.net/) apps, based upon the [R18n](https://github.com/ai/r18n) gem.
3
+ Add Internationalisation (i18n) and localisation support to your [Roda](http://roda.jeremyevans.net/)
4
+ apps, based upon the [R18n](https://github.com/ai/r18n) gem.
4
5
 
5
6
  Extensively tested and with 100% code test coverage.
6
7
 
@@ -9,120 +10,136 @@ Extensively tested and with 100% code test coverage.
9
10
 
10
11
  To use this gem, just do
11
12
 
12
- $ (sudo) gem install roda-i18n
13
-
13
+ ```bash
14
+ $ (sudo) gem install roda-i18n
15
+ ```
16
+
14
17
  or if you use Bundler
15
18
 
16
- gem "roda-i18n"
17
-
19
+ ```ruby
20
+ gem "roda-i18n"
21
+ ```
18
22
 
19
23
  <br>
20
24
 
21
25
 
22
26
  ## Getting Started
23
27
 
24
- To add internationalisation and localisation support to your app just add the following code snippet in your app.
28
+ To add internationalisation and localisation support to your app just add the following code snippet
29
+ in your app.
25
30
 
26
- plugin :i18n
31
+ ```ruby
32
+ plugin :i18n
33
+ ```
27
34
 
28
- By default the default locale is set to <tt>'en'</tt> and the translations directory is set to the <tt>'i18n'</tt> directory in the rooot of your app, ie: '<tt>/path/2/app/i18n</tt>'.
35
+ By default the default locale is set to `'en'` and the translations directory is set to the `'i18n'`
36
+ directory in the root of your app, ie: `'/path/2/app/i18n'`.
29
37
 
30
38
 
31
- **IMPORTANT! Make sure you create the 'i18n' folder and add an 'en.yml' file with
32
- at least one translation within it.**
39
+ **IMPORTANT! Make sure you create the 'i18n' folder and add an `'en.yml'` file with at least one
40
+ translation within it.**
33
41
 
34
42
 
35
43
  <br>
44
+ ---
36
45
 
37
46
 
38
47
  ## Configuration
39
48
 
40
49
  ### Overriding defaults during configuration
41
50
 
42
- Both <tt>:locale</tt> and <tt>:translations</tt> can be configured (overridden) during plugin configuration:
43
-
44
- plugin :i18n, :locale => ['de'], :translations => ['absolute/path/2/i18n']
51
+ Both `:locale` and `:translations` can be configured (overridden) during plugin configuration:
45
52
 
53
+ ```ruby
54
+ plugin :i18n, :locale => ['de'], :translations => ['absolute/path/2/i18n']
55
+ ```
46
56
 
47
57
  **NOTE!**
48
58
 
49
- 1. You must set <tt>opts[:root]</tt> in your app if you do not define the <tt>:translations</tt> path during plugin configuration.
59
+ 1. You must set `opts[:root]` in your app if you do not define the `:translations` path during
60
+ plugin configuration.
50
61
 
51
- 2. When overriding <tt>:translations</tt> the **any path(s) given must be absolute**.
62
+ 3. When overriding `:translations` the **any path(s) given must be absolute**.
52
63
 
53
64
 
54
65
  #### Loading translations from multiple i18n directories
55
66
 
56
- The <tt>:translations</tt> path supports 'wildcards', ie: <tt>path/**/i18n</tt> so you can load translations from multiple combined apps, each with their own <tt>i18n</tt> folder with translations.
67
+ The `:translations` path supports 'wildcards', ie: `path/**/i18n` so you can load translations from
68
+ multiple combined apps, each with their own `i18n` folder with translations.
57
69
 
58
70
  **Please Note!**
59
71
 
60
- When loading translations from multiple sources and the same translation key is available in multiple files of the same locale, then **the translations in the first loaded translation file takes precedence over subsequent loaded translations**.
72
+ When loading translations from multiple sources and the same translation key is available in
73
+ multiple files of the same locale, then **the translations in the first loaded translation file
74
+ takes precedence over subsequent loaded translations**.
61
75
 
62
- * ie: translations in <tt>./i18n/en.yml</tt> takes precedence over translations in <tt>./apps/app1/i18n/en.yml</tt>
76
+ * ie: translations in `./i18n/en.yml` takes precedence over translations in `./apps/app1/i18n/en.yml`
63
77
 
64
78
 
65
79
  You can also set a list of preferred locales as an array ordered by priority.
66
80
 
67
- plugin :i18n, :locale => ['es','fr','en']
68
-
81
+ ```ruby
82
+ plugin :i18n, :locale => ['es','fr','en']
83
+ ```
69
84
 
70
85
 
71
86
  <br>
72
-
87
+ ---
73
88
 
74
89
  ## USAGE
75
90
 
76
91
  The **i18n** plugin depends upon simple YAML based translations files:
77
92
 
78
- # app/i18n/en.yml
79
-
80
- user:
81
- edit: Edit user
82
- name: User name is %1
83
- count: !!pl
84
- 1: There is 1 user
85
- n: There are %1 users
86
-
87
-
88
- ...and the **<tt>:t</tt>** instance method to output the translations:
89
-
90
-
91
- t.user.edit #=> "Edit user"
92
- t.user.name('John') #=> "User name is John"
93
- t.user.count(5) #=> "There are 5 users"
94
-
95
- t.does.not.exist | 'default' #=> "default"
96
-
97
-
98
- ...and the **<tt>:l</tt>** (lowercase L) instance method provides built-in localisations support:
99
-
100
-
101
- l Time.now #=> "03/01/2010 18:54"
102
- l Time.now, :human #=> "now"
103
- l Time.now, :full #=> "3rd of January, 2010 18:54"
104
-
105
-
106
-
107
- Both the <tt>:t</tt> and <tt>:l</tt> methods are available within the route and template (erb) scopes. ie:
108
-
109
-
110
- route do |r|
111
- r.root do
112
- t.welcome.message
113
- end
114
- end
115
-
116
- # app/views/layout.erb
117
- <snip...>
118
- <h1><%= t.welcome.message %></h1>
119
- <snip...>
120
-
93
+ ```ruby
94
+ # app/i18n/en.yml
95
+
96
+ user:
97
+ edit: Edit user
98
+ name: User name is %1
99
+ count: !!pl
100
+ 1: There is 1 user
101
+ n: There are %1 users
102
+ ```
103
+
104
+ ...and the **`:t`** instance method to output the translations:
105
+
106
+ ```ruby
107
+ t.user.edit #=> "Edit user"
108
+ t.user.name('John') #=> "User name is John"
109
+ t.user.count(5) #=> "There are 5 users"
110
+
111
+ t.does.not.exist | 'default' #=> "default"
112
+ ```
113
+
114
+ ...and the **`:l`** (lowercase L) instance method provides built-in localisations support:
115
+
116
+ ```ruby
117
+ l Time.now #=> "03/01/2010 18:54"
118
+ l Time.now, :human #=> "now"
119
+ l Time.now, :full #=> "3rd of January, 2010 18:54"
120
+ ```
121
+
122
+
123
+ Both the `:t` and `:l` methods are available within the route and template (erb) scopes. ie:
124
+
125
+ ```ruby
126
+ route do |r|
127
+ r.root do
128
+ t.welcome.message
129
+ end
130
+ end
121
131
 
132
+ # app/views/layout.erb
133
+ <snip...>
134
+ <h1><%= t.welcome.message %></h1>
135
+ <snip...>
136
+ ```
122
137
 
123
- Please visit [R18n](https://github.com/ai/r18n/tree/master/r18n-core) for more information about the R18n gem used to create the above.
138
+ Please visit [R18n](https://github.com/ai/r18n/tree/master/r18n-core) for more information about the
139
+ R18n gem used to create the above.
124
140
 
125
141
  <br>
142
+ ---
126
143
 
127
144
  ## Key Methods / Functionality
128
145
 
@@ -130,59 +147,63 @@ Please visit [R18n](https://github.com/ai/r18n/tree/master/r18n-core) for more i
130
147
  <br>
131
148
 
132
149
 
133
- ### <tt>#locale(opts={},&blk)</tt> - (request method)
150
+ ### `#locale(opts = {}, &blk)` - (request method)
134
151
 
135
- This request method makes it easy to handle translations based upon the **<tt>:locale</tt> prefix on a route / URL**. ie: <tt>blog.com/**de**/posts</tt>.
152
+ This request method makes it easy to handle translations based upon the **`:locale` prefix on a
153
+ route / URL**. ie: `blog.com/**de**/posts`.
136
154
 
137
155
 
138
156
  To enable this, just use the following code structure:
139
157
 
140
- route do |r|
141
-
142
- # all routes are prefixed with '/:locale'
143
- # ie: GET /de/posts => will use DE translations
144
- # ie: GET /es/posts => will use ES translations
145
-
146
- r.locale do # also aliased as #i18n_locale
147
- r.is 'posts' do
148
- t.posts.header # use translations or locales
149
- end
150
- end
151
-
158
+ ```ruby
159
+ route do |r|
160
+
161
+ # all routes are prefixed with '/:locale'
162
+ # ie: GET /de/posts => will use DE translations
163
+ # ie: GET /es/posts => will use ES translations
164
+
165
+ r.locale do # also aliased as #i18n_locale
166
+ r.is 'posts' do
167
+ t.posts.header # use translations or locales
152
168
  end
153
-
169
+ end
170
+
171
+ end
172
+ ```
154
173
 
155
174
 
156
175
 
157
- **NOTE!** Any URL / request with a non-present or not supported locale will be given the **configured default locale** or the EN (English) default locale.
176
+ **NOTE!** Any URL / request with a non-present or not supported locale will be given the
177
+ **configured default locale** or the EN (English) default locale.
158
178
 
159
179
 
160
180
  <br>
161
181
 
162
182
 
163
- ### <tt>#i18n_set_locale_from(type)</tt> - (request method)
183
+ ### ``#i18n_set_locale_from(type)` - (request method)
164
184
 
165
185
  Obtains the locale from either ENV, HTTP (browser), Params or Session values.
166
186
 
167
- route do |r|
168
- # A): set from session[:locale] (if present)
169
- r.i18n_set_locale_from(:session)
170
-
171
- # B): set from URL params ie: GET /posts?locale=de
172
- r.i18n_set_locale_from(:params)
173
-
174
- # C): set from the browser's HTTP request locale
175
- r.i18n_set_locale_from(:http)
176
-
177
- # D): set from the server ENV['LANG'] variable
178
- r.i18n_set_locale_from(:ENV)
179
-
180
-
181
- r.is 'posts' do
182
- t.posts.header # use translations
183
- end
184
- end
185
-
187
+ ```ruby
188
+ route do |r|
189
+ # A): set from session[:locale] (if present)
190
+ r.i18n_set_locale_from(:session)
191
+
192
+ # B): set from URL params ie: GET /posts?locale=de
193
+ r.i18n_set_locale_from(:params)
194
+
195
+ # C): set from the browser's HTTP request locale
196
+ r.i18n_set_locale_from(:http)
197
+
198
+ # D): set from the server ENV['LANG'] variable
199
+ r.i18n_set_locale_from(:ENV)
200
+
201
+
202
+ r.is 'posts' do
203
+ t.posts.header # use translations
204
+ end
205
+ end
206
+ ```
186
207
 
187
208
  **NOTE!** defaults to the configured default locale, or English, if the given locale type is invalid.
188
209
 
@@ -190,30 +211,30 @@ Obtains the locale from either ENV, HTTP (browser), Params or Session values.
190
211
  <br>
191
212
 
192
213
 
193
- ### <tt>#i18n_set_locale(locale, &blk)</tt> - (request method)
214
+ ### `i18n_set_locale(locale, &blk)` - (request method)
194
215
 
195
- Enables overriding the default locale and setting a temporary :locale
196
- within a route block.
216
+ Enables overriding the default locale and setting a temporary `:locale` within a route block.
197
217
 
198
- route do |r|
199
- # configured default locale
200
-
201
- <snip...>
202
-
203
- r.i18n_set_locale('de') do
204
- # within this route block the locale is DE (German)
205
- end
206
-
207
- r.i18n_set_locale('es') do
208
- # within this route block the locale is ES (Spanish)
209
- end
210
-
211
- end
218
+ ```ruby
219
+ route do |r|
220
+ # configured default locale
221
+
222
+ <snip...>
223
+
224
+ r.i18n_set_locale('de') do
225
+ # within this route block the locale is DE (German)
226
+ end
212
227
 
228
+ r.i18n_set_locale('es') do
229
+ # within this route block the locale is ES (Spanish)
230
+ end
213
231
 
232
+ end
233
+ ```
214
234
 
235
+ <br>
236
+ ---
215
237
 
216
-
217
238
  ## InstanceMethods
218
239
 
219
240
  ### `#t`
@@ -236,8 +257,9 @@ Key localisation method. Handles dates etc. (See examples above)
236
257
 
237
258
  Returns a two-dimensional array of available locales.
238
259
 
239
- puts i18n_available_locales #=> [ ['en', 'English'], ...]
240
-
260
+ ```ruby
261
+ puts i18n_available_locales #=> [ ['en', 'English'], ...]
262
+ ```
241
263
 
242
264
 
243
265
 
@@ -249,12 +271,13 @@ Returns a two-dimensional array of available locales.
249
271
 
250
272
  ## Class Methods
251
273
 
252
- ### <tt>#i18n_opts</tt>
274
+ ### `#i18n_opts()`
253
275
 
254
276
  Return the i18n options for this class as a Hash.
255
277
 
256
278
 
257
279
  <br>
280
+ ---
258
281
 
259
282
 
260
283
  ## Ideas
@@ -264,8 +287,9 @@ A few ideas that may be outlandish, but possible?
264
287
 
265
288
  ### Ability to load translations from multiple locations via an array.
266
289
 
267
- plugin :i18n, :translations => ['app1/i18n', 'app2/i18n', 'app3/i18n']
268
-
290
+ ```ruby
291
+ plugin :i18n, :translations => ['app1/i18n', 'app2/i18n', 'app3/i18n']
292
+ ```
269
293
 
270
294
  > [Concept Reference](https://github.com/ai/r18n/tree/master/r18n-core#loaders)
271
295
  >
@@ -300,7 +324,8 @@ Som form of built-in support for storing / loading translations from a Sequel ba
300
324
 
301
325
  ## Credits
302
326
 
303
- * This plugin have been inspired by the `sinatra-i18n` gem available at [github/ai/r18n](http://github.com/ai/r18n) created by [Andrey Sitnik](http://github.com/ai).
327
+ * This plugin have been inspired by the `sinatra-i18n` gem available at
328
+ [github/ai/r18n](http://github.com/ai/r18n) created by [Andrey Sitnik](http://github.com/ai).
304
329
 
305
330
  * Testing code have been partly copied from [Forme](github.com/jeremyevans/forme).
306
331
 
data/Rakefile CHANGED
@@ -1,53 +1,12 @@
1
- require "rake"
2
- require "rake/clean"
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
3
 
4
- NAME = 'roda-i18n'
5
- CLEAN.include ["#{NAME}-*.gem", "rdoc", "coverage", '**/*.rbc']
6
-
7
- # Gem Packaging and Release
8
-
9
- desc "Packages #{NAME}"
10
- task :package=>[:clean] do |p|
11
- sh %{gem build #{NAME}.gemspec}
12
- end
13
-
14
- desc "Upload #{NAME} gem to rubygems"
15
- task :release=>[:package] do
16
- sh %{gem push ./#{NAME}-#{VERS.call}.gem}
4
+ Rake::TestTask.new(:spec) do |t|
5
+ t.libs << "spec"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['spec/**/*_spec.rb']
17
8
  end
18
9
 
19
- # ### RDoc
20
- #
21
- # RDOC_DEFAULT_OPTS = ["--line-numbers", "--inline-source", '--title', 'Roda I18n']
22
- #
23
- # begin
24
- # gem 'hanna-nouveau'
25
- # RDOC_DEFAULT_OPTS.concat(['-f', 'hanna'])
26
- # rescue Gem::LoadError
27
- # end
28
- #
29
- # rdoc_task_class = begin
30
- # require "rdoc/task"
31
- # RDoc::Task
32
- # rescue LoadError
33
- # require "rake/rdoctask"
34
- # Rake::RDocTask
35
- # end
36
- #
37
- # RDOC_OPTS = RDOC_DEFAULT_OPTS + ['--main', 'README.rdoc']
38
- #
39
- # rdoc_task_class.new do |rdoc|
40
- # rdoc.rdoc_dir = "rdoc"
41
- # rdoc.options += RDOC_OPTS
42
- # rdoc.rdoc_files.add %w"README.rdoc CHANGELOG MIT-LICENSE lib/**/*.rb"
43
- # end
44
-
45
- ### Specs
46
-
47
- desc "Run specs"
48
- task :spec do
49
- sh "#{FileUtils::RUBY} -rubygems -I lib -e 'ARGV.each{|f| require f}' ./spec/*_spec.rb"
50
- end
51
10
  task :default => :spec
52
11
 
53
12
  desc "Run specs with coverage"
@@ -56,23 +15,7 @@ task :coverage do
56
15
  Rake::Task['spec'].invoke
57
16
  end
58
17
 
59
- ### Other
60
-
61
- # desc "Print #{NAME} version"
62
- # task :version do
63
- # puts VERS.call
64
- # end
65
-
66
- desc "Check syntax of all .rb files"
67
- task :check_syntax do
68
- Dir['**/*.rb'].each{|file| print `#{ENV['RUBY'] || :ruby} -c #{file} | fgrep -v "Syntax OK"`}
18
+ desc "Run Rubocop report"
19
+ task :rubocop do
20
+ `rubocop -f html -o ./Rubocop-report.html lib/`
69
21
  end
70
-
71
- # desc "Start an IRB shell using the extension"
72
- # task :irb do
73
- # require 'rbconfig'
74
- # ruby = ENV['RUBY'] || File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name'])
75
- # irb = ENV['IRB'] || File.join(RbConfig::CONFIG['bindir'], File.basename(ruby).sub('ruby', 'irb'))
76
- # sh %{#{irb} -I lib -r forme}
77
- # end
78
-