flame-r18n 2.3.1 → 3.0.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
- SHA1:
3
- metadata.gz: f7b0223f3e2c36030c264cc491def07e23c87799
4
- data.tar.gz: 3d8fdc16f0e55ef2028d59f34646f42fa8d39519
2
+ SHA256:
3
+ metadata.gz: 98564e3e120c050c410ffe7a6d5017cd8e4e4019c7cb982916d6150fac06a381
4
+ data.tar.gz: 3bfea7a4a8484f208086b62f82013c1dfa26471e34f76e58d2ea3aa32e1d18ea
5
5
  SHA512:
6
- metadata.gz: d20a69c75064726642204b896aa71222b8f9529d1898b3d82e9e8ecdc1dbf4132c2011d9f81507922e0a7c8cdff02baea111229e6d059cbf1c998cd151cd1470
7
- data.tar.gz: dececf076eaff24214df9788b3e05fd3dc2d9e7c4e827b3ea8f6858a56e4f6e031b9bdf49fde3a66d55b0c79bf68871bd80c26ad00e67d8c7bc6ebaa9dea31a6
6
+ metadata.gz: d778aa75b1002bafb821fee3d90a7002ffe137c8133dcdcc9d1ae325831bb9f2d693a887fea1f660cfcb636fd5ce7fdd90587477b3d09c92fc961688aef03f23
7
+ data.tar.gz: d97d5f299203934c6bd555a606a91aef7c0692450ff0abc63863664f05eef190498eeb7153739723399426f3af7cc7031aba8f50e55038c44b1e3645fc7e91ab
data/CHANGELOG.md ADDED
@@ -0,0 +1,99 @@
1
+ # Changelog
2
+
3
+ ## Unreleased
4
+
5
+ ## 3.0.0 (2026-02-19)
6
+
7
+ * Drop Ruby 2.5, 2.6, 2.7, 3.0 and 3.1 support.
8
+ * Add Ruby 3.2, 3.3, 3.4 and 4.0 support.
9
+ * Update runtime (Flame and R18n) dependencies.
10
+ * Update development dependencies.
11
+ * Resolve new RuboCop offenses.
12
+ * Improve CI config.
13
+
14
+ ## 3.0.0.rc1 (2021-04-16)
15
+
16
+ * Add tests, fix some errors.
17
+ 100% coverage, yay!
18
+ * Update version of Flame dependency to `~> 5.0`.
19
+ * Set locale with region by locale without.
20
+ From `Accept-Language` HTTP header.
21
+ * Remove extra slashes in a root path with query string when redirecting (`LocaleInPath`).
22
+ * Replace `LocaleInPath#path_witout_locale` with `#fullpath_without_locale`.
23
+ * Take out `path_with_preferred_locale` from `redirect_to_path_with_preferred_locale`.
24
+ * Update R18n dependency.
25
+ * Update development dependencies, lock them better.
26
+ * Add Travis CI, then switch to Cirrus CI.
27
+ * Add `rubocop-performance` and `rubocop-rspec`.
28
+ Resolve new offenses.
29
+ * Support Ruby 3.
30
+ * Move gem version to a separate file.
31
+ * Add RuboCop task for CI.
32
+ * Add `remark` task for CI.
33
+ * Replace `rake` with `toys`.
34
+ * Add code documentation.
35
+ * Add more meta-information to gem specs.
36
+ * Add badges to README.
37
+ * Add "Development", "Contributing" and "License" sections to README.
38
+
39
+ ## 2.3.1 (2017-10-13)
40
+
41
+ * Fix the critical issue with caching 301 Location by browsers.
42
+
43
+ ## 2.3.0.1 (2017-10-13)
44
+
45
+ * Fix the critical issue with caching 301 Location by browsers.
46
+
47
+ ## 2.3.0 (2017-08-23)
48
+
49
+ * Add redefined `LocaleInPath#path_to` method.
50
+
51
+ ## 2.2.1 (2017-08-10)
52
+
53
+ * Fix an error with `LocaleInPath` module.
54
+
55
+ ## 2.2.0 (2017-08-09)
56
+
57
+ * Add `Flame::R18n::LocaleInPath` module for general methods in such case.
58
+
59
+ ## 2.1.1 (2017-08-08)
60
+
61
+ * Fix calling root `::R18n` constant.
62
+
63
+ ## 2.1.0 (2017-08-08)
64
+
65
+ * Don't use locale param if it is not in available locales.
66
+
67
+ ## 2.0.0 (2017-05-17)
68
+
69
+ * Split `Flame::R18n` to `Configuration` and `Initialization`.
70
+ Change `prepend` to `include`s for application and controller.
71
+ * Fix gem building.
72
+ * Add RuboCop config.
73
+
74
+ ## 1.3.0 (2016-11-11)
75
+
76
+ * Initialize `R18n` already with `preferred_locale` instead of setting it later to `session`.
77
+
78
+ ## 1.2.0 (2016-11-08)
79
+
80
+ * Add possibility of redefining `preferred_locale`.
81
+
82
+ ## 1.1.1 (2016-09-28)
83
+
84
+ * Fix an error with non-word chars in `preferred_locale`.
85
+
86
+ ## 1.1.0 (2016-05-20)
87
+
88
+ * Set default locale to `session[:locale]` when no preferred.
89
+ Change `include` to `prepend`.
90
+ * Prevent `preferred_locale` duplicates in `locales`.
91
+ * Fix issue when `locales_from_env` returns `nil`.
92
+ * Add README file.
93
+ * Add LICENSE file.
94
+ * Fix gem specs file name.
95
+ * Change homepage in gem specs from GitLab to GitHub.
96
+
97
+ ## 1.0.0 (2016-01-29)
98
+
99
+ * Initial release.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Alexander Popov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,56 @@
1
+ # Flame R18n
2
+
3
+ Flame plugin which provides
4
+ [i18n and L10n](https://en.wikipedia.org/wiki/Internationalization_and_localization) support
5
+ to your web application.
6
+
7
+ It is a wrapper for [R18n core library](https://github.com/r18n/r18n-core).
8
+ See [R18n documentation](https://github.com/r18n/r18n-core/blob/main/README.md)
9
+ for more information.
10
+
11
+ [![Cirrus CI - Base Branch Build Status](https://img.shields.io/cirrus/github/AlexWayfer/flame-r18n?style=flat-square)](https://cirrus-ci.com/github/AlexWayfer/flame-r18n)
12
+ [![Codecov branch](https://img.shields.io/codecov/c/github/AlexWayfer/flame-r18n/main.svg?style=flat-square)](https://codecov.io/gh/AlexWayfer/flame-r18n)
13
+ [![Inline docs](https://inch-ci.org/github/AlexWayfer/flame-r18n.svg?branch=main)](https://inch-ci.org/github/AlexWayfer/flame-r18n)
14
+ [![license](https://img.shields.io/github/license/AlexWayfer/flame-r18n.svg?style=flat-square)](https://github.com/AlexWayfer/flame-r18n/blob/main/LICENSE.txt)
15
+ [![Gem](https://img.shields.io/gem/v/flame-r18n.svg?style=flat-square)](https://rubygems.org/gems/flame-r18n)
16
+
17
+ ## Usage
18
+
19
+ ```ruby
20
+ # Gemfile
21
+ gem 'flame-r18n'
22
+
23
+ # config.ru
24
+ require 'flame-r18n' # or `Bundler.require`
25
+
26
+ # For application configuration
27
+ # config/processors/r18n.rb
28
+ ::R18n.default_places = File.join config[:root_dir], 'locales'
29
+ ::R18n::I18n.default = 'en'
30
+
31
+ # _controller.rb
32
+ include Flame::R18n::Initialization # for loading thread-based locale
33
+
34
+ # site/_controller.rb
35
+ prepend Flame::R18n::LocaleInPath # for mounting controllers at `/:locale`
36
+ ```
37
+
38
+ ## Development
39
+
40
+ After checking out the repo, run `bundle install` to install dependencies.
41
+
42
+ Then, run `toys rspec` to run the tests.
43
+
44
+ To install this gem onto your local machine, run `toys gem install`.
45
+
46
+ To release a new version, run `toys gem release %version%`.
47
+ See how it works [here](https://github.com/AlexWayfer/gem_toys#release).
48
+
49
+ ## Contributing
50
+
51
+ Bug reports and pull requests are welcome on [GitHub](https://github.com/AlexWayfer/flame-r18n).
52
+
53
+ ## License
54
+
55
+ The gem is available as open source under the terms of the
56
+ [MIT License](https://opensource.org/licenses/MIT).
@@ -1,28 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'r18n-core'
4
-
5
3
  module Flame
6
4
  module R18n
7
5
  ## Module for R18n in thread initialization with helper methods
8
6
  module Initialization
9
7
  include ::R18n::Helpers
10
8
 
9
+ ## Patch controller initialization
10
+ ## Load R18n and set the current locale to the session
11
11
  def initialize(*)
12
12
  super
13
13
  load_r18n
14
14
  session[:locale] = r18n.locale.code
15
15
  end
16
16
 
17
- def init_r18n(locale)
18
- ::R18n::I18n.new(
19
- Array(locale) | locales_from_env,
20
- ::R18n.default_places,
21
- off_filters: :untranslated,
22
- on_filters: :untranslated_html
23
- )
24
- end
25
-
17
+ ## Force change thread locale
18
+ ## @param locale [R18n::Locale] the locale that will be set
26
19
  def thread_locale=(locale)
27
20
  ::R18n.thread_set init_r18n locale
28
21
  end
@@ -48,12 +41,16 @@ module Flame
48
41
  def load_r18n
49
42
  ::R18n.clear_cache! if config[:environment] == 'development'
50
43
 
51
- ::R18n.thread_set do
52
- default_locale = config[:default_locale]
53
- ::R18n::I18n.default = default_locale if default_locale
44
+ self.thread_locale = preferred_locale
45
+ end
54
46
 
55
- init_r18n preferred_locale
56
- end
47
+ def init_r18n(locale)
48
+ ::R18n::I18n.new(
49
+ Array(locale) | locales_from_env,
50
+ ::R18n.default_places,
51
+ off_filters: :untranslated,
52
+ on_filters: :untranslated_html
53
+ )
57
54
  end
58
55
  end
59
56
  end
@@ -4,19 +4,23 @@ module Flame
4
4
  module R18n
5
5
  ## Module for including to controllers, mounted with `:locale` param in path
6
6
  module LocaleInPath
7
- include Flame::R18n::Initialization
8
-
9
7
  protected
10
8
 
11
- def execute(method)
9
+ ## Patch controller execution
10
+ ## Halt with redirect to the same URL, but with the preferred locale,
11
+ ## if necessary
12
+ ## @param action [Symbol] action which will be executed
13
+ def execute(action)
12
14
  unless request_path_with_available_locale?
13
- return redirect_with_preferred_locale_in_path
15
+ return halt redirect_to_path_with_preferred_locale
14
16
  end
17
+
15
18
  super
16
19
  end
17
20
 
18
21
  private
19
22
 
23
+ ## Complete returning path with locale, if necessary
20
24
  def path_to(*args)
21
25
  args << {} unless args.last.is_a? Hash
22
26
  args.last[:locale] = r18n.locale.code unless args.last.include?(:locale)
@@ -27,21 +31,27 @@ module Flame
27
31
  available_locale_codes.include?(request.path.parts.first.to_s)
28
32
  end
29
33
 
30
- def redirect_with_preferred_locale_in_path
31
- path_with_locale = Flame::Path.merge(
32
- nil, r18n.locale.code, request.fullpath
33
- )
34
- path_with_locale.sub!(%r{(\/)+$}, '')
35
- redirect path_with_locale, 302
34
+ def redirect_to_path_with_preferred_locale
35
+ redirect path_with_preferred_locale.sub(%r{(/)+(?=\?|$)}, ''), 302
36
36
  end
37
37
 
38
- def path_without_locale
39
- return request.path.to_s unless request_path_with_available_locale?
38
+ def path_with_preferred_locale
39
+ Flame::Path.merge(nil, r18n.locale.code, request.fullpath)
40
+ end
41
+
42
+ ## Get the current path without the preferred locale in it
43
+ ## @return [Flame::Path] the current path without locale in it
44
+ def fullpath_without_locale
45
+ return request.fullpath.to_s unless request_path_with_available_locale?
46
+
40
47
  Flame::Path.merge(
41
- request.path.parts[1..-1].unshift('/')
48
+ request.fullpath.to_s.split('/')[2..].unshift('/')
42
49
  )
43
50
  end
44
51
 
52
+ ## Get the current path with the specific locale in it
53
+ ## @param locale [R18n::Locale] the locale that will be in the path
54
+ ## @return [Flame::Path] the current path with the specific locale in it
45
55
  def fullpath_with_specific_locale(locale)
46
56
  fullpath_parts = request.fullpath.to_s.split('/')
47
57
  fullpath_parts[1] = locale.code
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Flame
4
+ module R18n
5
+ VERSION = '3.0.0'
6
+ end
7
+ end
data/lib/flame/r18n.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'r18n-core'
4
4
 
5
- require_relative './r18n/configuration'
6
- require_relative './r18n/initialization'
7
- require_relative './r18n/locale_in_path'
5
+ require_relative 'r18n/version'
6
+
7
+ require_relative 'r18n/initialization'
8
+ require_relative 'r18n/locale_in_path'
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flame-r18n
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.1
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Popov
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2017-10-13 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: flame
@@ -16,35 +15,30 @@ dependencies:
16
15
  requirements:
17
16
  - - "~>"
18
17
  - !ruby/object:Gem::Version
19
- version: '4.0'
20
- - - ">="
21
- - !ruby/object:Gem::Version
22
- version: 4.0.0
18
+ version: '5.0'
23
19
  type: :runtime
24
20
  prerelease: false
25
21
  version_requirements: !ruby/object:Gem::Requirement
26
22
  requirements:
27
23
  - - "~>"
28
24
  - !ruby/object:Gem::Version
29
- version: '4.0'
30
- - - ">="
31
- - !ruby/object:Gem::Version
32
- version: 4.0.0
25
+ version: '5.0'
33
26
  - !ruby/object:Gem::Dependency
34
27
  name: r18n-core
35
28
  requirement: !ruby/object:Gem::Requirement
36
29
  requirements:
37
30
  - - "~>"
38
31
  - !ruby/object:Gem::Version
39
- version: '2'
32
+ version: '6.0'
40
33
  type: :runtime
41
34
  prerelease: false
42
35
  version_requirements: !ruby/object:Gem::Requirement
43
36
  requirements:
44
37
  - - "~>"
45
38
  - !ruby/object:Gem::Version
46
- version: '2'
47
- description: Flame extension which provides i18n support to translate your web application.
39
+ version: '6.0'
40
+ description: |
41
+ Flame plugin which provides i18n and L10n support to your web application.
48
42
  It is a wrapper for R18n core library. See R18n documentation for more information.
49
43
  email:
50
44
  - alex.wayfer@gmail.com
@@ -52,15 +46,21 @@ executables: []
52
46
  extensions: []
53
47
  extra_rdoc_files: []
54
48
  files:
49
+ - CHANGELOG.md
50
+ - LICENSE.txt
51
+ - README.md
55
52
  - lib/flame/r18n.rb
56
- - lib/flame/r18n/configuration.rb
57
53
  - lib/flame/r18n/initialization.rb
58
54
  - lib/flame/r18n/locale_in_path.rb
55
+ - lib/flame/r18n/version.rb
59
56
  homepage: https://github.com/AlexWayfer/flame-r18n
60
57
  licenses:
61
58
  - MIT
62
- metadata: {}
63
- post_install_message:
59
+ metadata:
60
+ source_code_uri: https://github.com/AlexWayfer/flame-r18n
61
+ homepage_uri: https://github.com/AlexWayfer/flame-r18n
62
+ changelog_uri: https://github.com/AlexWayfer/flame-r18n/blob/main/CHANGELOG.md
63
+ rubygems_mfa_required: 'true'
64
64
  rdoc_options: []
65
65
  require_paths:
66
66
  - lib
@@ -68,16 +68,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
68
68
  requirements:
69
69
  - - ">="
70
70
  - !ruby/object:Gem::Version
71
- version: '0'
71
+ version: '3.2'
72
+ - - "<"
73
+ - !ruby/object:Gem::Version
74
+ version: '5'
72
75
  required_rubygems_version: !ruby/object:Gem::Requirement
73
76
  requirements:
74
77
  - - ">="
75
78
  - !ruby/object:Gem::Version
76
79
  version: '0'
77
80
  requirements: []
78
- rubyforge_project:
79
- rubygems_version: 2.6.13
80
- signing_key:
81
+ rubygems_version: 4.0.3
81
82
  specification_version: 4
82
- summary: R18n plugin for Flame-framework
83
+ summary: Flame plugin which provides i18n and L10n support
83
84
  test_files: []
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Flame
4
- module R18n
5
- ## Module for adding Flame::R18n properties into application configuration
6
- module Configuration
7
- def self.included(app)
8
- app.config[:default_locale] = proc { ::R18n::I18n.default }
9
- app.config[:locales] = proc { ::R18n.default_places }
10
- app.config[:locales_dir] = proc do
11
- File.join(app.config[:root_dir], 'locales')
12
- end
13
-
14
- ::R18n.default_places { app.config[:locales_dir] }
15
- end
16
- end
17
- end
18
- end