roda-i18n 0.3.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: 7c49e1ba809caf572d5d75f55cbe48bedf855f80
4
- data.tar.gz: eb86ad5e8c25b9c152ae1a4c56d7cbcfac084f46
2
+ SHA256:
3
+ metadata.gz: 5c59dec3caf930c42ea639d9d803cd1f96351f4e26de874031d46376ca047b38
4
+ data.tar.gz: 39970d149489f36de80048d86c2451d74922ffee54a6df8459b3e278d5bd43d1
5
5
  SHA512:
6
- metadata.gz: 5d31eee8bb80bc0e147e8b94901c1be53b32c6684eb9471156e4841e3f6cbeff8234e3258f569093e26fa3276606d4d99eecbfd7d3656f7f91fa45c75ea20038
7
- data.tar.gz: d9351ab146c07cd61a0c29f5b234966f5b18deeaf55aecafe7d1018e53f503a6efe54f3b002e2af74a3c24442e5f4affef48015c68b6f9d5986924a179951878
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,78 @@
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)
23
+
24
+ ## 0.4.0 (2018-05-08)
25
+
26
+ * Merge pull request #4 from adam12/yield-matched-locale - Yield matched locale to block
27
+
28
+ > Yield the matched locale to the block, similar to a normal Roda route.
29
+
30
+ * Merge pull request #5 from adam12/no-session-setting - Don't set session (BREAKING CHANGE)
31
+
32
+ I think setting the session should be done by the user inside the yielded block, using the value yielded from the match in #4, if they want that value to be set in the first place.
33
+
34
+ ```ruby
35
+ r.locale do |locale|
36
+ session[:locale] ||= locale
37
+ end
38
+ ```
39
+
40
+ If we assume that a session exists, this plugin can't be used where there is no session - ie. a Roda app that performs mailing only.
41
+
42
+ ```ruby
43
+ class Mailer < Roda
44
+ plugin :mailer
45
+ plugin :i18n
46
+
47
+ route do |r|
48
+ r.locale do
49
+ r.mail "/some-path" {}
50
+ end
51
+ end
52
+ end
53
+
54
+ Mailer.sendmail("/en/some-path") # FAILS! No Rack::Session available
55
+ ```
56
+
57
+ This is likely a breaking change for anybody relying on this functionality.
58
+
59
+ * Merge pull request #6 from adam12/fix-nil - Cast potentially matched locale to string
60
+
61
+ > Without this cast, a `root` block below the `locale` block will never be reached due to an exception of calling `downcase` on `nil`.
62
+
63
+ > I didn't add a new spec as moving the `r.root` call to the bottom of the block was enough to trigger the failure.
64
+
65
+ * Merge pull request #7 from zaidan/update/roda-3 - Making routes behind #locale block work
66
+
67
+ * Fix deprecated use of placeholders in string matchers
68
+ * Fix missing dependency on `r18n-core` < `2.2.0`
69
+ * Fix spec failures caused by unexpected order of `available_locales`
70
+ * Update dependency `roda` to `3.7`
71
+ * Update development dependency `rack-test` to `1.0`
72
+ * Update dependency `r18n-core` to `3.0.x`
73
+ * Update development dependency `rake` to `12.3`
74
+ * Remove noop check for exception
75
+
3
76
 
4
77
  ## 0.3.0 (2016-08-11)
5
78
 
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
@@ -1,6 +1,7 @@
1
1
  # Roda-i18n
2
2
 
3
- [![Build Status](https://travis-ci.org/kematzy/roda-i18n.svg?branch=master)](https://travis-ci.org/kematzy/roda-i18n)
3
+ [![Gem Version](https://badge.fury.io/rb/roda-i18n.svg)](https://badge.fury.io/rb/roda-i18n) [![Build Status](https://travis-ci.org/kematzy/roda-i18n.svg?branch=master)](https://travis-ci.org/kematzy/roda-i18n)
4
+
4
5
 
5
6
  Add Internationalisation (i18n) and localisation support to your [Roda](http://roda.jeremyevans.net/)
6
7
  apps, based upon the [R18n](https://github.com/ai/r18n) gem.
@@ -13,13 +14,13 @@ Extensively tested and with 100% code test coverage.
13
14
  To use this gem, just do
14
15
 
15
16
  ```bash
16
- $ (sudo) gem install roda-i18n
17
+ $ (sudo) gem install roda-i18n
17
18
  ```
18
19
 
19
20
  or if you use Bundler
20
21
 
21
22
  ```ruby
22
- gem "roda-i18n"
23
+ gem 'roda-i18n'
23
24
  ```
24
25
 
25
26
  <br>
@@ -61,7 +62,7 @@ plugin :i18n, :locale => ['de'], :translations => ['absolute/path/2/i18n']
61
62
  1. You must set `opts[:root]` in your app if you do not define the `:translations` path during
62
63
  plugin configuration.
63
64
 
64
- 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**.
65
66
 
66
67
 
67
68
  #### Loading translations from multiple i18n directories
@@ -303,7 +304,7 @@ plugin :i18n, :translations => ['app1/i18n', 'app2/i18n', 'app3/i18n']
303
304
 
304
305
  ### Sequel DBLoader for DB based translations support
305
306
 
306
- 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.
307
308
 
308
309
 
309
310
  <br>
@@ -326,23 +327,25 @@ Som form of built-in support for storing / loading translations from a Sequel ba
326
327
 
327
328
  ## Credits
328
329
 
329
- * 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
330
331
  [github/ai/r18n](http://github.com/ai/r18n) created by [Andrey Sitnik](http://github.com/ai).
331
332
 
332
- * 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).
333
334
 
334
- * 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!!
335
336
 
336
337
  * Code fixes and improvements by:
337
338
 
338
- * [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
+
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)
339
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)
340
346
 
341
347
  ## Licence
342
348
 
343
349
  MIT
344
350
 
345
- Copyright: 2015 Kematzy
346
-
347
-
348
-
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.3.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,99 +221,94 @@ 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
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
287
+ # r.get(:about) { erb(:about) }
294
288
  # end
295
289
  #
296
- def locale(opts = {}, &blk)
290
+ def locale(opts = {})
297
291
  on(_match_available_locales_only, opts) do |l|
298
292
  loc = l || Roda.opts[:locale]
299
- session[:locale] = loc unless session[:locale]
300
293
  ::R18n.set(loc)
301
- yield if block_given?
294
+ yield loc if block_given?
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,29 +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', '~> 2.5', '>= 2.5.0'
36
- spec.add_runtime_dependency 'tilt'
37
- spec.add_runtime_dependency 'r18n-core', '~> 2.0', '>= 2.1.4'
38
-
39
- spec.add_development_dependency 'bundler', "~> 1.10"
40
- spec.add_development_dependency 'rake', "~> 10.0"
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-assert_errors'
45
- spec.add_development_dependency 'minitest-hooks', '~> 1.1', '>= 1.1.0'
46
- spec.add_development_dependency 'minitest-rg'
47
- spec.add_development_dependency 'rack-test', '~> 0.6.3'
48
- spec.add_development_dependency 'nokogiri'
49
- spec.add_development_dependency 'simplecov'
50
-
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'
51
44
  end
metadata CHANGED
@@ -1,37 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roda-i18n
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.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: 2016-08-11 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: '2.5'
20
- - - ">="
21
- - !ruby/object:Gem::Version
22
- version: 2.5.0
23
- type: :runtime
24
- prerelease: false
25
- version_requirements: !ruby/object:Gem::Requirement
26
- requirements:
27
- - - "~>"
28
- - !ruby/object:Gem::Version
29
- version: '2.5'
30
- - - ">="
31
- - !ruby/object:Gem::Version
32
- version: 2.5.0
33
- - !ruby/object:Gem::Dependency
34
- name: tilt
14
+ name: date
35
15
  requirement: !ruby/object:Gem::Requirement
36
16
  requirements:
37
17
  - - ">="
@@ -50,180 +30,36 @@ dependencies:
50
30
  requirements:
51
31
  - - "~>"
52
32
  - !ruby/object:Gem::Version
53
- version: '2.0'
54
- - - ">="
55
- - !ruby/object:Gem::Version
56
- version: 2.1.4
33
+ version: '5.0'
57
34
  type: :runtime
58
35
  prerelease: false
59
36
  version_requirements: !ruby/object:Gem::Requirement
60
37
  requirements:
61
38
  - - "~>"
62
39
  - !ruby/object:Gem::Version
63
- version: '2.0'
64
- - - ">="
65
- - !ruby/object:Gem::Version
66
- version: 2.1.4
67
- - !ruby/object:Gem::Dependency
68
- name: bundler
69
- requirement: !ruby/object:Gem::Requirement
70
- requirements:
71
- - - "~>"
72
- - !ruby/object:Gem::Version
73
- version: '1.10'
74
- type: :development
75
- prerelease: false
76
- version_requirements: !ruby/object:Gem::Requirement
77
- requirements:
78
- - - "~>"
79
- - !ruby/object:Gem::Version
80
- version: '1.10'
81
- - !ruby/object:Gem::Dependency
82
- name: rake
83
- requirement: !ruby/object:Gem::Requirement
84
- requirements:
85
- - - "~>"
86
- - !ruby/object:Gem::Version
87
- version: '10.0'
88
- type: :development
89
- prerelease: false
90
- version_requirements: !ruby/object:Gem::Requirement
91
- requirements:
92
- - - "~>"
93
- - !ruby/object:Gem::Version
94
- version: '10.0'
95
- - !ruby/object:Gem::Dependency
96
- name: erubis
97
- requirement: !ruby/object:Gem::Requirement
98
- requirements:
99
- - - ">="
100
- - !ruby/object:Gem::Version
101
- version: '0'
102
- type: :development
103
- prerelease: false
104
- version_requirements: !ruby/object:Gem::Requirement
105
- requirements:
106
- - - ">="
107
- - !ruby/object:Gem::Version
108
- version: '0'
109
- - !ruby/object:Gem::Dependency
110
- name: kramdown
111
- requirement: !ruby/object:Gem::Requirement
112
- requirements:
113
- - - ">="
114
- - !ruby/object:Gem::Version
115
- version: '0'
116
- type: :development
117
- prerelease: false
118
- version_requirements: !ruby/object:Gem::Requirement
119
- requirements:
120
- - - ">="
121
- - !ruby/object:Gem::Version
122
- version: '0'
123
- - !ruby/object:Gem::Dependency
124
- name: minitest
125
- requirement: !ruby/object:Gem::Requirement
126
- requirements:
127
- - - "~>"
128
- - !ruby/object:Gem::Version
129
- version: '5.7'
130
- - - ">="
131
- - !ruby/object:Gem::Version
132
- version: 5.7.0
133
- type: :development
134
- prerelease: false
135
- version_requirements: !ruby/object:Gem::Requirement
136
- requirements:
137
- - - "~>"
138
- - !ruby/object:Gem::Version
139
- version: '5.7'
140
- - - ">="
141
- - !ruby/object:Gem::Version
142
- version: 5.7.0
143
- - !ruby/object:Gem::Dependency
144
- name: minitest-assert_errors
145
- requirement: !ruby/object:Gem::Requirement
146
- requirements:
147
- - - ">="
148
- - !ruby/object:Gem::Version
149
- version: '0'
150
- type: :development
151
- prerelease: false
152
- version_requirements: !ruby/object:Gem::Requirement
153
- requirements:
154
- - - ">="
155
- - !ruby/object:Gem::Version
156
- version: '0'
40
+ version: '5.0'
157
41
  - !ruby/object:Gem::Dependency
158
- name: minitest-hooks
159
- requirement: !ruby/object:Gem::Requirement
160
- requirements:
161
- - - "~>"
162
- - !ruby/object:Gem::Version
163
- version: '1.1'
164
- - - ">="
165
- - !ruby/object:Gem::Version
166
- version: 1.1.0
167
- type: :development
168
- prerelease: false
169
- version_requirements: !ruby/object:Gem::Requirement
170
- requirements:
171
- - - "~>"
172
- - !ruby/object:Gem::Version
173
- version: '1.1'
174
- - - ">="
175
- - !ruby/object:Gem::Version
176
- version: 1.1.0
177
- - !ruby/object:Gem::Dependency
178
- name: minitest-rg
179
- requirement: !ruby/object:Gem::Requirement
180
- requirements:
181
- - - ">="
182
- - !ruby/object:Gem::Version
183
- version: '0'
184
- type: :development
185
- prerelease: false
186
- version_requirements: !ruby/object:Gem::Requirement
187
- requirements:
188
- - - ">="
189
- - !ruby/object:Gem::Version
190
- version: '0'
191
- - !ruby/object:Gem::Dependency
192
- name: rack-test
42
+ name: roda
193
43
  requirement: !ruby/object:Gem::Requirement
194
44
  requirements:
195
45
  - - "~>"
196
46
  - !ruby/object:Gem::Version
197
- version: 0.6.3
198
- type: :development
47
+ version: '3.8'
48
+ type: :runtime
199
49
  prerelease: false
200
50
  version_requirements: !ruby/object:Gem::Requirement
201
51
  requirements:
202
52
  - - "~>"
203
53
  - !ruby/object:Gem::Version
204
- version: 0.6.3
205
- - !ruby/object:Gem::Dependency
206
- name: nokogiri
207
- requirement: !ruby/object:Gem::Requirement
208
- requirements:
209
- - - ">="
210
- - !ruby/object:Gem::Version
211
- version: '0'
212
- type: :development
213
- prerelease: false
214
- version_requirements: !ruby/object:Gem::Requirement
215
- requirements:
216
- - - ">="
217
- - !ruby/object:Gem::Version
218
- version: '0'
54
+ version: '3.8'
219
55
  - !ruby/object:Gem::Dependency
220
- name: simplecov
56
+ name: tilt
221
57
  requirement: !ruby/object:Gem::Requirement
222
58
  requirements:
223
59
  - - ">="
224
60
  - !ruby/object:Gem::Version
225
61
  version: '0'
226
- type: :development
62
+ type: :runtime
227
63
  prerelease: false
228
64
  version_requirements: !ruby/object:Gem::Requirement
229
65
  requirements:
@@ -240,7 +76,11 @@ extra_rdoc_files:
240
76
  - README.md
241
77
  - MIT-LICENSE
242
78
  files:
79
+ - ".github/dependabot.yml"
80
+ - ".github/workflows/ruby.yml"
243
81
  - ".gitignore"
82
+ - ".rubocop.yml"
83
+ - ".rubocop_todo.yml"
244
84
  - ".travis.yml"
245
85
  - CHANGELOG.md
246
86
  - Gemfile
@@ -254,8 +94,9 @@ files:
254
94
  homepage: http://github.com/kematzy/roda-i18n
255
95
  licenses:
256
96
  - MIT
257
- metadata: {}
258
- post_install_message:
97
+ metadata:
98
+ rubygems_mfa_required: 'true'
99
+ post_install_message:
259
100
  rdoc_options:
260
101
  - "--quiet"
261
102
  - "--line-numbers"
@@ -270,16 +111,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
270
111
  requirements:
271
112
  - - ">="
272
113
  - !ruby/object:Gem::Version
273
- version: '0'
114
+ version: 3.0.0
274
115
  required_rubygems_version: !ruby/object:Gem::Requirement
275
116
  requirements:
276
117
  - - ">="
277
118
  - !ruby/object:Gem::Version
278
119
  version: '0'
279
120
  requirements: []
280
- rubyforge_project:
281
- rubygems_version: 2.5.1
282
- signing_key:
121
+ rubygems_version: 3.5.11
122
+ signing_key:
283
123
  specification_version: 4
284
124
  summary: Roda Internationalisation plugin
285
125
  test_files: []