roda-i18n 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 9c2738c4186efd7bb356272c3fad656bd1a79237
4
- data.tar.gz: 72a1cb79f9dbc234b12411d58e7801e935933a7e
2
+ SHA256:
3
+ metadata.gz: 5c59dec3caf930c42ea639d9d803cd1f96351f4e26de874031d46376ca047b38
4
+ data.tar.gz: 39970d149489f36de80048d86c2451d74922ffee54a6df8459b3e278d5bd43d1
5
5
  SHA512:
6
- metadata.gz: 941708ff91f4da8c9da9d03e2dafe545d1845e9e679d0e66d249408832c8aa3ecd53dbc2dbde3b56e756b5c2091eeb0e0eb529a305154fb0857f4b8972ab6b6d
7
- data.tar.gz: 4781db341bd8d1fa1154dcc68d0ca45b56f7ccb76a9a4b3be103e066a26ea521472ff7af9a7e5515bed4d11e4d0e64de0812be79d89f77a9baca7597488590b7
6
+ metadata.gz: ae7c28fff45a8bd38ec31b89843132c1a6fd8c09f248078589f7249d8f5b26e5b32b6a8a2843f3a67bd2c919f14cac25c32fda1c7fd064b208774c735e2c9e5a
7
+ data.tar.gz: ed1d0c3bd35f808b89e88c02fac1a3c626d40bb5235a6fa3c540cd893938e749d471c735ce70f2a782a485d067fa640763bc5d4b22d34b59be228b3faee498e6
@@ -0,0 +1,24 @@
1
+ # To get started with Dependabot version updates, you'll need to specify which
2
+ # package ecosystems to update and where the package manifests are located.
3
+ # Please see the documentation for all configuration options:
4
+ # https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5
+
6
+ version: 2
7
+ updates:
8
+ - package-ecosystem: "github-actions"
9
+ directory: "/"
10
+ schedule:
11
+ interval: "weekly"
12
+ day: "saturday"
13
+ time: "21:45"
14
+ timezone: "Europe/Berlin"
15
+ - package-ecosystem: "bundler" # See documentation for possible values
16
+ directory: "/" # Location of package manifests
17
+ groups:
18
+ patch-and-minor-dependencies:
19
+ update-types: ["patch", "minor"]
20
+ schedule:
21
+ interval: "weekly"
22
+ day: "saturday"
23
+ time: "21:45"
24
+ timezone: "Europe/Berlin"
@@ -0,0 +1,37 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+
6
+ # GitHub recommends pinning actions to a commit SHA.
7
+ # To get a newer version, you will need to update the SHA.
8
+ # You can also reference a tag or branch, but the action may change without warning.
9
+
10
+ name: Ruby
11
+
12
+ on:
13
+ pull_request:
14
+ branches: [master]
15
+
16
+ jobs:
17
+ lint_and_test:
18
+ env:
19
+ RACK_ENV: test
20
+ strategy:
21
+ fail-fast: false
22
+ matrix:
23
+ # os: [ubuntu-latest, macos-latest]
24
+ os: [ubuntu-latest]
25
+ ruby: ["3.0", "3.1", "3.2", "3.3"]
26
+ runs-on: ${{ matrix.os }}
27
+ timeout-minutes: 2
28
+
29
+ steps:
30
+ - uses: actions/checkout@v4
31
+ - name: Set up Ruby
32
+ uses: ruby/setup-ruby@v1
33
+ with:
34
+ ruby-version: ${{ matrix.ruby }}
35
+ bundler-cache: true
36
+ - name: Run rake (lint and test)
37
+ run: bundle exec rake
data/.gitignore CHANGED
@@ -7,3 +7,5 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+
11
+ .tool-versions
data/.rubocop.yml ADDED
@@ -0,0 +1,30 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
3
+ require:
4
+ - rubocop-rake
5
+ - rubocop-performance
6
+ - rubocop-minitest
7
+
8
+ # The behavior of RuboCop can be controlled via the .rubocop.yml
9
+ # configuration file. It makes it possible to enable/disable
10
+ # certain cops (checks) and to alter their behavior if they accept
11
+ # any parameters. The file can be placed either in your home
12
+ # directory or in some project directory.
13
+ #
14
+ # RuboCop will start looking for the configuration file in the directory
15
+ # where the inspected file is and continue its way up to the root directory.
16
+ #
17
+ # See https://docs.rubocop.org/rubocop/configuration
18
+
19
+ AllCops:
20
+ NewCops: enable
21
+
22
+ Layout/LineLength:
23
+ Exclude:
24
+ - "roda-i18n.gemspec"
25
+
26
+ Style/Documentation:
27
+ Exclude:
28
+ - 'spec/**/*'
29
+ - 'test/**/*'
30
+ - 'lib/roda/plugins/i18n.rb'
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,34 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2024-09-09 20:36:04 UTC using RuboCop version 1.66.1.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 4
10
+ # Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
11
+ Metrics/AbcSize:
12
+ Max: 39
13
+
14
+ # Offense count: 15
15
+ # Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
16
+ # AllowedMethods: refine
17
+ Metrics/BlockLength:
18
+ Max: 639
19
+
20
+ # Offense count: 2
21
+ # Configuration parameters: CountComments, CountAsOne.
22
+ Metrics/ClassLength:
23
+ Max: 641
24
+
25
+ # Offense count: 1
26
+ # Configuration parameters: AllowedMethods, AllowedPatterns.
27
+ Metrics/CyclomaticComplexity:
28
+ Max: 9
29
+
30
+ # Offense count: 8
31
+ # Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
32
+ Metrics/MethodLength:
33
+ Max: 22
34
+
data/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## next (unreleased)
4
+
5
+ * Merge pull request #5 from simonneutert/bump-dependencies - Add/Bump dependencies, minimum Ruby version to 3.0.0
6
+
7
+ * __Breaking Changes:__
8
+ * minimum Ruby version is now >= 3.0.0
9
+
10
+ * __Dependencies:__
11
+ * Add `date` to `gemspec`
12
+ * Bump `r18n-core` to `~> 5.0`
13
+ * Bump `roda` to `~> 3.8`
14
+ * Bump `rack-test` to `1.1.0`
15
+
16
+ * Bump `bundler` to `~> 2.5`
17
+ * Bump `rack-test` to `~> 2.1`
18
+ * Bump `rake` to `~> 13.2`
19
+
20
+ * __Tests:__
21
+ * switched from rack session to roda session (as plugin in test suite)
22
+ * fixed failing tests and updated fixtures for proper YAML due to the above changes (Psych was freaking out about the prior YAML formatting)
3
23
 
4
24
  ## 0.4.0 (2018-05-08)
5
25
 
data/Gemfile CHANGED
@@ -1,4 +1,21 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in roda-i18n.gemspec
4
6
  gemspec
7
+
8
+ gem 'bundler', '~> 2.5'
9
+ gem 'erubis'
10
+ gem 'kramdown'
11
+ gem 'minitest', '~> 5.7', '>= 5.7.0'
12
+ gem 'minitest-hooks', '~> 1.1', '>= 1.1.0'
13
+ gem 'minitest-rg'
14
+ gem 'nokogiri'
15
+ gem 'rack-test', '~> 2.1'
16
+ gem 'rake', '~> 13.2'
17
+ gem 'rubocop'
18
+ gem 'rubocop-minitest'
19
+ gem 'rubocop-performance'
20
+ gem 'rubocop-rake'
21
+ gem 'simplecov'
data/README.md CHANGED
@@ -14,13 +14,13 @@ Extensively tested and with 100% code test coverage.
14
14
  To use this gem, just do
15
15
 
16
16
  ```bash
17
- $ (sudo) gem install roda-i18n
17
+ $ (sudo) gem install roda-i18n
18
18
  ```
19
19
 
20
20
  or if you use Bundler
21
21
 
22
22
  ```ruby
23
- gem "roda-i18n"
23
+ gem 'roda-i18n'
24
24
  ```
25
25
 
26
26
  <br>
@@ -62,7 +62,7 @@ plugin :i18n, :locale => ['de'], :translations => ['absolute/path/2/i18n']
62
62
  1. You must set `opts[:root]` in your app if you do not define the `:translations` path during
63
63
  plugin configuration.
64
64
 
65
- 3. When overriding `:translations` the **any path(s) given must be absolute**.
65
+ 2. When overriding `:translations` the **any path(s) given must be absolute**.
66
66
 
67
67
 
68
68
  #### Loading translations from multiple i18n directories
@@ -304,7 +304,7 @@ plugin :i18n, :translations => ['app1/i18n', 'app2/i18n', 'app3/i18n']
304
304
 
305
305
  ### Sequel DBLoader for DB based translations support
306
306
 
307
- Som form of built-in support for storing / loading translations from a Sequel based DB.
307
+ Some form of built-in support for storing / loading translations from a Sequel based DB.
308
308
 
309
309
 
310
310
  <br>
@@ -327,23 +327,25 @@ Som form of built-in support for storing / loading translations from a Sequel ba
327
327
 
328
328
  ## Credits
329
329
 
330
- * This plugin have been inspired by the `sinatra-i18n` gem available at
330
+ * This plugin has been inspired by the `sinatra-i18n` gem available at
331
331
  [github/ai/r18n](http://github.com/ai/r18n) created by [Andrey Sitnik](http://github.com/ai).
332
332
 
333
- * Testing code have been partly copied from [Forme](github.com/jeremyevans/forme).
333
+ * Testing code has been partly copied from [Forme](https://github.com/jeremyevans/forme).
334
334
 
335
- * Inspiration and assistance by [Jeremy Evans](github.com/jeremyevans). Many thanks Jeremy!!
335
+ * Inspiration and assistance by [Jeremy Evans](https://github.com/jeremyevans). Many thanks Jeremy!!
336
336
 
337
337
  * Code fixes and improvements by:
338
338
 
339
- * [Jonathan Duarte](github.com/jonduarte). Many thanks Jonathan
339
+ * [Jonathan Duarte](https://github.com/jonduarte). Many thanks Jonathan for PR [#3](https://github.com/kematzy/roda-i18n/pull/3)
340
340
 
341
+ * [Adam Daniels](https://github.com/adam12). Many thanks Adam for PR [#4](https://github.com/kematzy/roda-i18n/pull/4), [#5](https://github.com/kematzy/roda-i18n/pull/5) & [#6](https://github.com/kematzy/roda-i18n/pull/6)
342
+
343
+ * [Firas Zaidan](https://github.com/zaidan). Many thanks Firas for PR [#7](https://github.com/kematzy/roda-i18n/pull/7)
344
+
345
+ * [Simon Neutert](https://github.com/simonneutert). Many thanks Simon for PR [#8](https://github.com/kematzy/roda-i18n/pull/8)
341
346
 
342
347
  ## Licence
343
348
 
344
349
  MIT
345
350
 
346
- Copyright: 2015 Kematzy
347
-
348
-
349
-
351
+ Copyright: 2015 - 2024 Kematzy
data/Rakefile CHANGED
@@ -1,29 +1,25 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_tasks'
4
+ require 'rubocop/rake_task'
2
5
  require 'rake/testtask'
3
6
 
7
+ RuboCop::RakeTask.new
8
+
4
9
  Rake::TestTask.new(:spec) do |t|
5
10
  t.libs << 'spec'
6
11
  t.libs << 'lib'
7
12
  t.test_files = FileList['spec/**/*_spec.rb']
8
13
  end
9
14
 
10
- task :default => :spec
11
- task :test => :spec
15
+ task default: %i[rubocop spec]
16
+
17
+ desc 'alias for spec task'
18
+ task test: :spec
12
19
 
13
20
  desc 'Run specs with coverage'
14
21
  task :coverage do
15
22
  ENV['COVERAGE'] = '1'
16
23
  Rake::Task['spec'].invoke
17
- # `open coverage/index.html` # if OSX
18
- end
19
-
20
- desc 'Run Rubocop report'
21
- task :rubocop do
22
- res = `which rubocop`
23
- if res != ""
24
- `rubocop -f html -o ./rubocop/report.html lib/`
25
- # `open rubocop/report.html` # if OSX
26
- else
27
- puts "\nERROR: 'rubocop' gem is not installed or available. Please install with 'gem install rubocop'."
28
- end
24
+ # `open coverage/index.html` # if OSX
29
25
  end
@@ -1,7 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Roda
2
-
3
4
  module I18n
4
- VERSION = '0.4.0'
5
+ VERSION = '0.5.0'
5
6
  end
6
-
7
7
  end
data/lib/roda/i18n.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'roda'
2
4
  require 'roda/i18n/version'
3
5
  require 'roda/plugins/i18n'
@@ -1,217 +1,210 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'r18n-core'
2
4
 
3
- #
4
5
  class Roda
5
-
6
- #
7
6
  module RodaPlugins
8
-
9
7
  # The i18n plugin allows you to easily add internationalisation (i18n) and
10
8
  # localisation support to your Roda app, by adding the following:
11
- #
9
+ #
12
10
  # plugin :i18n
13
- #
14
- # By default the default locale is set to <tt>'en'</tt> and the translations directory
11
+ #
12
+ # By default the default locale is set to <tt>'en'</tt> and the translations directory
15
13
  # is set to <tt>'i18n'</tt> in the rooot of your app.
16
- #
14
+ #
17
15
  # Both <tt>:locale</tt> and <tt>:translations</tt> can be overridden during configuration:
18
- #
16
+ #
19
17
  # plugin :i18n, :locale => ['de'], :translations => ['absolute/path/2/i18n']
20
- #
21
- # Please note!
18
+ #
19
+ # Please note!
22
20
  # 1) You must set +opts[:root]+ in your app if you don't define the +:translations+ path.
23
- #
21
+ #
24
22
  # 2) When overriding <tt>:translations</tt> the path given <b>must be absolute</b>.
25
- #
23
+ #
26
24
  # The path supports 'wildcards', ie: path/**/i18n so you can load translations from multiple
27
25
  # combined apps each with their own <tt>i18n</tt> folder with translations.
28
- #
29
- # Note! when loading translations from multiple sources and the same translation key is used
30
- # in both files, the first loaded file takes precedence, ie: <tt>./i18n/en.yml</tt> takes
26
+ #
27
+ # Note! when loading translations from multiple sources and the same translation key is used
28
+ # in both files, the first loaded file takes precedence, ie: <tt>./i18n/en.yml</tt> takes
31
29
  # precedence over <tt>./apps/app1/i18n/en.yml</tt>
32
- #
30
+ #
33
31
  # == USAGE
34
- #
32
+ #
35
33
  # The i18n plugin depends upon simple YAML based translations files:
36
- #
34
+ #
37
35
  # # app/i18n/en.yml
38
- #
36
+ #
39
37
  # user:
40
38
  # edit: Edit user
41
39
  # name: User name is %1
42
40
  # count: !!pl
43
41
  # 1: There is 1 user
44
42
  # n: There are %1 users
45
- #
46
- #
43
+ #
44
+ #
47
45
  # and the <tt>:t</tt> instance method to output the translations:
48
- #
49
- #
46
+ #
47
+ #
50
48
  # t.user.edit #=> "Edit user"
51
49
  # t.user.name('John') #=> "User name is John"
52
50
  # t.user.count(5) #=> "There are 5 users"
53
- #
51
+ #
54
52
  # t.does.not.exist | 'default' #=> "default"
55
- #
56
- #
53
+ #
54
+ #
57
55
  # the <tt>:l</tt> instance method provides built-in localisations support:
58
- #
56
+ #
59
57
  # l Time.now #=> "03/01/2010 18:54"
60
58
  # l Time.now, :human #=> "now"
61
59
  # l Time.now, :full #=> "3rd of January, 2010 18:54"
62
- #
60
+ #
63
61
  # Both the +:t+ and +:l+ methods are available in the route and template (erb) scopes. ie:
64
- #
62
+ #
65
63
  # route do |r|
66
64
  # r.root do
67
65
  # t.welcome.message
68
66
  # end
69
67
  # end
70
- #
68
+ #
71
69
  # # app/views/layout.erb
72
70
  # <snip...>
73
71
  # <h1><%= t.welcome.message %></h1>
74
72
  # <snip...>
75
- #
76
- #
77
- #
73
+ #
74
+ #
75
+ #
78
76
  # Visit [R18n](https://github.com/ai/r18n/tree/master/r18n-core) for more information.
79
- #
80
- #
77
+ #
78
+ #
81
79
  # The i18n plugin also makes it easy to handle locales:
82
- #
83
- #
80
+ #
81
+ #
84
82
  # === <tt>:locale</tt> RequestMethod
85
- #
83
+ #
86
84
  # This request method makes it to handle translations based upon the :locale prefix on a URL,
87
85
  # ie: <tt>blog.com/de/posts</tt>, just use the following code:
88
- #
86
+ #
89
87
  # route do |r|
90
- #
88
+ #
91
89
  # r.locale do # or r.i18n_locale
92
- # r.is 'posts' do
90
+ # r.is 'posts' do
93
91
  # t.posts.header
94
92
  # end
95
93
  # end
96
- #
94
+ #
97
95
  # end
98
- #
99
- #
96
+ #
97
+ #
100
98
  # === <tt>:i18n_set_locale_from</tt> RequestMethod
101
- #
99
+ #
102
100
  # Obtains the locale from either ENV, HTTP (browser), Params or Session values
103
- #
104
- #
101
+ #
102
+ #
105
103
  # Naturally we can allow browsers to override the default locale within routes, like this:
106
- #
104
+ #
107
105
  # route do |r|
108
106
  # i18n_set_locale_from(:http) #=> set to the browser's default locale (en-US)
109
107
  # r.get '' do
110
108
  # t.hello #=> 'Howdy, I speak American English'
111
109
  # end
112
110
  # end
113
- #
111
+ #
114
112
  # The def
115
- #
116
- #
113
+ #
114
+ #
117
115
  # route do |r|
118
116
  # i18n_set_locale('de')
119
117
  # r.get 'in-german' do
120
118
  # t.hello #=> 'Guten tag, ich spreche deutsch'
121
119
  # end
122
120
  # end
123
- #
124
- #
125
- #
126
- #
121
+ #
122
+ #
123
+ #
124
+ #
127
125
  module RodaI18n
128
-
129
126
  # default options
130
127
  OPTS = {
131
128
  # set the default locale
132
- locale: 'en',
129
+ locale: 'en',
133
130
  # set the default fallback locale
134
- default_locale: 'en',
131
+ default_locale: 'en',
135
132
  # set the default translations.
136
- translations: nil
133
+ translations: nil
137
134
  }.freeze
138
-
139
-
135
+
140
136
  def self.configure(app, opts = OPTS)
141
- if app.opts[:i18n]
142
- opts = app.opts[:i18n][:orig_opts].merge(opts)
143
- else
144
- opts = OPTS.merge(opts)
145
- end
146
-
137
+ opts = if app.opts[:i18n]
138
+ app.opts[:i18n][:orig_opts].merge(opts)
139
+ else
140
+ OPTS.merge(opts)
141
+ end
142
+
147
143
  app.opts[:i18n] = opts.dup
148
144
  app.opts[:i18n][:orig_opts] = opts
149
145
  opts = app.opts[:i18n]
150
-
146
+
151
147
  # set the translations path to defaults if nil
152
148
  opts[:translations] = File.expand_path('i18n', app.opts[:root]) if opts[:translations].nil?
153
149
  ::R18n.default_places = opts[:translations]
154
-
155
- # default_locale is either 'en' or the set value, so reset :default_locale if
150
+
151
+ # default_locale is either 'en' or the set value, so reset :default_locale if
156
152
  # it is somehow nil or an empty string ' '
157
- if opts[:default_locale].nil? || opts[:default_locale] =~ /^\s*$/
158
- opts[:default_locale] = 'en'
159
- end
153
+ opts[:default_locale] = 'en' if opts[:default_locale].nil? || opts[:default_locale] =~ /^\s*$/
160
154
  ::R18n::I18n.default = opts[:default_locale]
161
-
155
+
162
156
  ::R18n.clear_cache! if ENV['RACK_ENV'] != 'production'
163
- i18n = R18n::I18n.new(
164
- opts[:locale],
157
+ i18n = R18n::I18n.new(
158
+ opts[:locale],
165
159
  ::R18n.default_places,
166
- off_filters: :untranslated,
167
- on_filters: :untranslated_html
160
+ off_filters: :untranslated,
161
+ on_filters: :untranslated_html
168
162
  )
169
163
  ::R18n.set(i18n)
170
164
  end
171
-
165
+
172
166
  # methods used within Roda's route block
173
- #
167
+ #
174
168
  module RequestMethods
175
-
176
169
  # Obtains the locale from either ENV, HTTP (browser), Params or Session
177
170
  # values.
178
- #
171
+ #
179
172
  # route do |r|
180
173
  # # A): set from URL params ie: GET /posts?locale=de
181
174
  # r.i18n_set_locale_from(:params)
182
- #
175
+ #
183
176
  # /url?locale=de
184
177
  # <%= t.one %> #=> Ein
185
178
  # /url?locale=es
186
179
  # <%= t.one %> #=> Uno
187
- #
180
+ #
188
181
  # # B): set from session[:locale] (if present)
189
182
  # r.i18n_set_locale_from(:session)
190
- #
183
+ #
191
184
  # session[:locale] = 'de'
192
185
  # <%= t.one %> #=> Ein
193
186
  # session[:locale] = 'es'
194
187
  # <%= t.one %> #=> Uno
195
- #
188
+ #
196
189
  # # C): set from the browser's HTTP request locale
197
190
  # r.i18n_set_locale_from(:http)
198
- #
191
+ #
199
192
  # HTTP_ACCEPT_LANGUAGE = 'sv-se;q=1,es;q=0.8,en;q=0.6'
200
193
  # <%= t.one %> #=> Ett
201
- #
194
+ #
202
195
  # # D): set from the server ENV['LANG'] variable
203
196
  # r.i18n_set_locale_from(:ENV)
204
- #
197
+ #
205
198
  # ENV['LANG'] = 'en_US.UTF8'
206
199
  # <%= t.one %> #=> One
207
200
  # ENV['LANG'] = 'es'
208
201
  # <%= t.one %> #=> Uno
209
- #
210
- # r.is 'posts' do
202
+ #
203
+ # r.is 'posts' do
211
204
  # t.posts.header # use translations
212
205
  # end
213
206
  # end
214
- #
207
+ #
215
208
  def i18n_set_locale_from(type)
216
209
  case type.to_sym
217
210
  when :http
@@ -228,73 +221,73 @@ class Roda
228
221
  end
229
222
  # sanity check: set to default locale if not set above
230
223
  loc = ::R18n::I18n.default.to_s if loc.nil?
231
-
224
+
232
225
  i18n = ::R18n::I18n.new(
233
- loc,
226
+ loc,
234
227
  ::R18n.default_places,
235
- off_filters: :untranslated,
236
- on_filters: :untranslated_html
228
+ off_filters: :untranslated,
229
+ on_filters: :untranslated_html
237
230
  )
238
231
  ::R18n.set(i18n)
239
232
  end
240
-
233
+
241
234
  # Enables setting temporary :locale blocks within the routing block.
242
- #
235
+ #
243
236
  # route do |r|
244
- #
237
+ #
245
238
  # r.i18n_set_locale('de') do
246
239
  # # within this block the locale is DE (German)
247
240
  # end
248
- #
241
+ #
249
242
  # r.i18n_set_locale('es') do
250
243
  # # within this block the locale is ES (Spanish)
251
244
  # end
252
- #
245
+ #
253
246
  # end
254
- #
255
- def i18n_set_locale(locale, &blk)
247
+ #
248
+ def i18n_set_locale(locale)
256
249
  locale = ::R18n::I18n.default.to_s if locale.nil?
257
-
250
+
258
251
  i18n = ::R18n::I18n.new(
259
- locale,
260
- ::R18n.default_places,
261
- off_filters: :untranslated,
262
- on_filters: :untranslated_html
252
+ locale,
253
+ ::R18n.default_places,
254
+ off_filters: :untranslated,
255
+ on_filters: :untranslated_html
263
256
  )
264
257
  ::R18n.set(i18n)
265
258
  yield if block_given?
266
259
  # return # NB!! needed to enable routes below to work
267
260
  end
268
-
261
+
269
262
  # Match only paths that contain one available locale from the ::R18n.available_locales
270
263
  # list, otherwise skip it.
271
264
  #
272
265
  # This custom matcher allows us to have other routes below the r.locale .. declaration
273
266
  def _match_available_locales_only
274
- lambda do
275
- locale = remaining_path.split("/").reject(&:empty?).first.to_s
276
- if ::R18n.available_locales.map(&:code).map(&:downcase).include?(locale.downcase)
277
- @captures.push(locale)
278
- @remaining_path = remaining_path.sub("/#{locale}", "")
279
- end
280
- end
267
+ lambda do
268
+ locale = remaining_path.split('/').reject(&:empty?).first.to_s
269
+ if ::R18n.available_locales.map { |locale| locale.code.downcase }.include?(locale.downcase)
270
+ @captures.push(locale)
271
+ @remaining_path = remaining_path.sub("/#{locale}", '')
272
+ end
273
+ end
281
274
  end
282
-
275
+
283
276
  # Sets the locale based upon <tt>:locale</tt> prefixed routes
284
- #
277
+ #
285
278
  # route do |r|
286
279
  # r.locale do
287
280
  # # all routes are prefixed with '/:locale'
288
281
  # # ie: GET /de/posts => will use DE translations
289
282
  # # ie: GET /es/posts => will use ES translations
290
- # r.is 'posts' do
283
+ # r.is 'posts' do
291
284
  # t.posts.header # use translations or locales
292
285
  # end
293
286
  # end
294
287
  # r.get(:about) { erb(:about) }
295
288
  # end
296
289
  #
297
- def locale(opts = {}, &blk)
290
+ def locale(opts = {})
298
291
  on(_match_available_locales_only, opts) do |l|
299
292
  loc = l || Roda.opts[:locale]
300
293
  ::R18n.set(loc)
@@ -302,25 +295,20 @@ class Roda
302
295
  return # NB!! needed to enable routes below to work
303
296
  end
304
297
  end
305
- alias_method :i18n_locale, :locale
306
-
307
- end # /module RequestMethods
308
-
309
-
298
+ alias i18n_locale locale
299
+ end
300
+
310
301
  module ClassMethods
311
-
312
302
  # Return the i18n options for this plugin.
313
303
  def i18n_opts
314
304
  opts[:i18n]
315
305
  end
316
-
317
- end # /module ClassMethods
318
-
319
-
306
+ end
307
+
320
308
  # defines method available within the views / routing block
321
309
  module InstanceMethods
322
310
  include ::R18n::Helpers
323
-
311
+
324
312
  def i18n_available_locales
325
313
  @available_locales = []
326
314
  ::R18n.available_locales.each do |l|
@@ -328,15 +316,13 @@ class Roda
328
316
  end
329
317
  @available_locales
330
318
  end
331
-
319
+
332
320
  def i18n_default_places
333
321
  ::R18n.default_places
334
322
  end
335
-
336
323
  end
337
-
338
- end # /module RodaI18n
339
-
324
+ end
325
+
340
326
  register_plugin(:i18n, RodaI18n)
341
- end # /module RodaPlugins
342
- end # /class Roda
327
+ end
328
+ end
data/roda-i18n.gemspec CHANGED
@@ -1,19 +1,20 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'roda/i18n/version'
5
6
 
6
7
  Gem::Specification.new do |spec|
7
8
  spec.name = 'roda-i18n'
8
- spec.version = ::Roda::I18n::VERSION
9
+ spec.version = Roda::I18n::VERSION
9
10
  spec.authors = ['Kematzy']
10
11
  spec.email = ['kematzy@gmail.com']
11
-
12
+
12
13
  spec.summary = 'Roda Internationalisation plugin'
13
- spec.description = "The Roda-i18n plugin enables easy addition of internationalisation (i18n) and localisation support in Roda apps"
14
+ spec.description = 'The Roda-i18n plugin enables easy addition of internationalisation (i18n) and localisation support in Roda apps'
14
15
  spec.homepage = 'http://github.com/kematzy/roda-i18n'
15
16
  spec.license = 'MIT'
16
-
17
+
17
18
  # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
19
  # delete this section to allow pushing this gem to any host.
19
20
  # if spec.respond_to?(:metadata)
@@ -23,28 +24,21 @@ Gem::Specification.new do |spec|
23
24
  # end
24
25
 
25
26
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
- spec.bindir = "exe"
27
+ spec.bindir = 'exe'
27
28
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
- spec.require_paths = ["lib"]
29
-
29
+ spec.require_paths = ['lib']
30
+
30
31
  spec.platform = Gem::Platform::RUBY
31
- spec.has_rdoc = true
32
- spec.extra_rdoc_files = ['README.md', "MIT-LICENSE"]
33
- spec.rdoc_options += ['--quiet', '--line-numbers', '--inline-source', '--title', 'Roda-i18n: internationalisation plugin', '--main', 'README.md']
34
-
35
- spec.add_runtime_dependency 'roda', '~> 3.7'
36
- spec.add_runtime_dependency 'tilt'
37
- spec.add_runtime_dependency 'r18n-core', '~> 3.0'
38
-
39
- spec.add_development_dependency 'bundler', "~> 1.10"
40
- spec.add_development_dependency 'rake', "~> 12.3"
41
- spec.add_development_dependency 'erubis'
42
- spec.add_development_dependency 'kramdown'
43
- spec.add_development_dependency 'minitest', '~> 5.7', '>= 5.7.0'
44
- spec.add_development_dependency 'minitest-hooks', '~> 1.1', '>= 1.1.0'
45
- spec.add_development_dependency 'minitest-rg'
46
- spec.add_development_dependency 'rack-test', '~> 1.0'
47
- spec.add_development_dependency 'nokogiri'
48
- spec.add_development_dependency 'simplecov'
49
-
32
+ spec.extra_rdoc_files = ['README.md', 'MIT-LICENSE']
33
+ spec.rdoc_options += ['--quiet', '--line-numbers', '--inline-source', '--title',
34
+ 'Roda-i18n: internationalisation plugin', '--main', 'README.md']
35
+
36
+ spec.required_ruby_version = '>= 3.0.0'
37
+
38
+ spec.add_dependency 'date'
39
+ spec.add_dependency 'r18n-core', '~> 5.0'
40
+ spec.add_dependency 'roda', '~> 3.8'
41
+ spec.add_dependency 'tilt'
42
+
43
+ spec.metadata['rubygems_mfa_required'] = 'true'
50
44
  end
metadata CHANGED
@@ -1,31 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roda-i18n
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kematzy
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-05-08 00:00:00.000000000 Z
11
+ date: 2024-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: roda
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '3.7'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '3.7'
27
- - !ruby/object:Gem::Dependency
28
- name: tilt
14
+ name: date
29
15
  requirement: !ruby/object:Gem::Requirement
30
16
  requirements:
31
17
  - - ">="
@@ -44,160 +30,36 @@ dependencies:
44
30
  requirements:
45
31
  - - "~>"
46
32
  - !ruby/object:Gem::Version
47
- version: '3.0'
33
+ version: '5.0'
48
34
  type: :runtime
49
35
  prerelease: false
50
36
  version_requirements: !ruby/object:Gem::Requirement
51
37
  requirements:
52
38
  - - "~>"
53
39
  - !ruby/object:Gem::Version
54
- version: '3.0'
55
- - !ruby/object:Gem::Dependency
56
- name: bundler
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '1.10'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '1.10'
69
- - !ruby/object:Gem::Dependency
70
- name: rake
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '12.3'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '12.3'
83
- - !ruby/object:Gem::Dependency
84
- name: erubis
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
- - !ruby/object:Gem::Dependency
98
- name: kramdown
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- version: '0'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- version: '0'
111
- - !ruby/object:Gem::Dependency
112
- name: minitest
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - "~>"
116
- - !ruby/object:Gem::Version
117
- version: '5.7'
118
- - - ">="
119
- - !ruby/object:Gem::Version
120
- version: 5.7.0
121
- type: :development
122
- prerelease: false
123
- version_requirements: !ruby/object:Gem::Requirement
124
- requirements:
125
- - - "~>"
126
- - !ruby/object:Gem::Version
127
- version: '5.7'
128
- - - ">="
129
- - !ruby/object:Gem::Version
130
- version: 5.7.0
40
+ version: '5.0'
131
41
  - !ruby/object:Gem::Dependency
132
- name: minitest-hooks
133
- requirement: !ruby/object:Gem::Requirement
134
- requirements:
135
- - - "~>"
136
- - !ruby/object:Gem::Version
137
- version: '1.1'
138
- - - ">="
139
- - !ruby/object:Gem::Version
140
- version: 1.1.0
141
- type: :development
142
- prerelease: false
143
- version_requirements: !ruby/object:Gem::Requirement
144
- requirements:
145
- - - "~>"
146
- - !ruby/object:Gem::Version
147
- version: '1.1'
148
- - - ">="
149
- - !ruby/object:Gem::Version
150
- version: 1.1.0
151
- - !ruby/object:Gem::Dependency
152
- name: minitest-rg
153
- requirement: !ruby/object:Gem::Requirement
154
- requirements:
155
- - - ">="
156
- - !ruby/object:Gem::Version
157
- version: '0'
158
- type: :development
159
- prerelease: false
160
- version_requirements: !ruby/object:Gem::Requirement
161
- requirements:
162
- - - ">="
163
- - !ruby/object:Gem::Version
164
- version: '0'
165
- - !ruby/object:Gem::Dependency
166
- name: rack-test
42
+ name: roda
167
43
  requirement: !ruby/object:Gem::Requirement
168
44
  requirements:
169
45
  - - "~>"
170
46
  - !ruby/object:Gem::Version
171
- version: '1.0'
172
- type: :development
47
+ version: '3.8'
48
+ type: :runtime
173
49
  prerelease: false
174
50
  version_requirements: !ruby/object:Gem::Requirement
175
51
  requirements:
176
52
  - - "~>"
177
53
  - !ruby/object:Gem::Version
178
- version: '1.0'
179
- - !ruby/object:Gem::Dependency
180
- name: nokogiri
181
- requirement: !ruby/object:Gem::Requirement
182
- requirements:
183
- - - ">="
184
- - !ruby/object:Gem::Version
185
- version: '0'
186
- type: :development
187
- prerelease: false
188
- version_requirements: !ruby/object:Gem::Requirement
189
- requirements:
190
- - - ">="
191
- - !ruby/object:Gem::Version
192
- version: '0'
54
+ version: '3.8'
193
55
  - !ruby/object:Gem::Dependency
194
- name: simplecov
56
+ name: tilt
195
57
  requirement: !ruby/object:Gem::Requirement
196
58
  requirements:
197
59
  - - ">="
198
60
  - !ruby/object:Gem::Version
199
61
  version: '0'
200
- type: :development
62
+ type: :runtime
201
63
  prerelease: false
202
64
  version_requirements: !ruby/object:Gem::Requirement
203
65
  requirements:
@@ -214,7 +76,11 @@ extra_rdoc_files:
214
76
  - README.md
215
77
  - MIT-LICENSE
216
78
  files:
79
+ - ".github/dependabot.yml"
80
+ - ".github/workflows/ruby.yml"
217
81
  - ".gitignore"
82
+ - ".rubocop.yml"
83
+ - ".rubocop_todo.yml"
218
84
  - ".travis.yml"
219
85
  - CHANGELOG.md
220
86
  - Gemfile
@@ -228,8 +94,9 @@ files:
228
94
  homepage: http://github.com/kematzy/roda-i18n
229
95
  licenses:
230
96
  - MIT
231
- metadata: {}
232
- post_install_message:
97
+ metadata:
98
+ rubygems_mfa_required: 'true'
99
+ post_install_message:
233
100
  rdoc_options:
234
101
  - "--quiet"
235
102
  - "--line-numbers"
@@ -244,16 +111,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
244
111
  requirements:
245
112
  - - ">="
246
113
  - !ruby/object:Gem::Version
247
- version: '0'
114
+ version: 3.0.0
248
115
  required_rubygems_version: !ruby/object:Gem::Requirement
249
116
  requirements:
250
117
  - - ">="
251
118
  - !ruby/object:Gem::Version
252
119
  version: '0'
253
120
  requirements: []
254
- rubyforge_project:
255
- rubygems_version: 2.5.2
256
- signing_key:
121
+ rubygems_version: 3.5.11
122
+ signing_key:
257
123
  specification_version: 4
258
124
  summary: Roda Internationalisation plugin
259
125
  test_files: []