rails-panda-i18n 1.1.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 +7 -0
- data/CHANGELOG.md +92 -0
- data/Gemfile +3 -0
- data/LICENSE +20 -0
- data/README.md +227 -0
- data/lib/rails/panda/i18n.rb +3 -0
- data/lib/rails_panda_i18n/i18n.rb +121 -0
- data/lib/rails_panda_i18n/version.rb +7 -0
- data/lib/rails_panda_i18n.rb +8 -0
- data/rails_panda_i18n.gemspec +44 -0
- metadata +247 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 88e70e146678cc25a1b5e5a70f9fb1304c09f41e3c8eee76e16bfc1f08911e1d
|
|
4
|
+
data.tar.gz: d1b20cef9c7e4e3aaed09c842a50e4e7b5637f4c8a17bcac006bbc628f36af42
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: bfe1ab03c2a5433db50fe15b210203b8ce4f61ca17c19ea5f6dd04bc972cbc08843a817706ca0b32266b29bb519369a64336ac919bdd7692fe52aa588f02587b
|
|
7
|
+
data.tar.gz: 1250398e4b95efbf808cd9da182b7488d2343856340100a6ee29cd4b2efb1d42165352583008ce7e20ca078f79ff6f9c60d5173e0e2230a19f20dcd325d7f1c3
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
## [1.1.0] - 2025-11-23
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- Comprehensive RSpec test suite
|
|
14
|
+
- SimpleCov integration for test coverage tracking
|
|
15
|
+
- README.md with comprehensive documentation
|
|
16
|
+
- CHANGELOG.md following Keep a Changelog format
|
|
17
|
+
|
|
18
|
+
### Changed
|
|
19
|
+
- Improved code safety by using `options.dup.tap` in `rails_panda__add_ui_language_to` to avoid mutating input hashes
|
|
20
|
+
- `rails_panda__get_user_locale` now consistently returns symbols for locales
|
|
21
|
+
- `rails_panda__add_ui_language_to` now returns the options hash (or duplicated version) even when param support is disabled, instead of returning `nil`
|
|
22
|
+
|
|
23
|
+
### Fixed
|
|
24
|
+
- Fixed module scoping issues by using `::I18n` to correctly reference the global I18n module
|
|
25
|
+
- Fixed return value consistency when param support is disabled
|
|
26
|
+
|
|
27
|
+
## [1.0.6] - 2025-10-06
|
|
28
|
+
|
|
29
|
+
### Changed
|
|
30
|
+
- Renamed gem from `definerails-i18n` to `rails-panda-i18n`
|
|
31
|
+
- Moved from Rubocop to StandardRb for code style enforcement
|
|
32
|
+
- Fixed loading issues - gem now loads correctly
|
|
33
|
+
- Added frozen string literal comments to all files
|
|
34
|
+
|
|
35
|
+
### Fixed
|
|
36
|
+
- Fixed module loading and initialization issues
|
|
37
|
+
|
|
38
|
+
## [1.0.5] - 2025-08-09
|
|
39
|
+
|
|
40
|
+
### Fixed
|
|
41
|
+
- Corrected a breaking bug
|
|
42
|
+
|
|
43
|
+
## [1.0.4] - 2025-07-10
|
|
44
|
+
|
|
45
|
+
### Fixed
|
|
46
|
+
- Corrected problems that would occur if cookies and/or params were not used
|
|
47
|
+
|
|
48
|
+
## [1.0.2] - 2022-05-01
|
|
49
|
+
|
|
50
|
+
### Added
|
|
51
|
+
- Added LICENSE file
|
|
52
|
+
|
|
53
|
+
### Changed
|
|
54
|
+
- Updated Gemfile dependencies
|
|
55
|
+
- Cleaned up Rakefile and tasks
|
|
56
|
+
- Updated gemspec
|
|
57
|
+
|
|
58
|
+
## [1.0.1.3] - 2019-08-20
|
|
59
|
+
|
|
60
|
+
### Changed
|
|
61
|
+
- Minor updates and improvements
|
|
62
|
+
|
|
63
|
+
## [1.0.1.2] - 2016-07-08
|
|
64
|
+
|
|
65
|
+
### Fixed
|
|
66
|
+
- Corrected bug with `http_accept_language` not being loaded
|
|
67
|
+
|
|
68
|
+
## [1.0.1.1] - 2016-02-01
|
|
69
|
+
|
|
70
|
+
### Added
|
|
71
|
+
- Added more configurability options
|
|
72
|
+
|
|
73
|
+
## [1.0.0] - 2015-11-10
|
|
74
|
+
|
|
75
|
+
### Added
|
|
76
|
+
- Initial release
|
|
77
|
+
- Basic locale detection from URL parameters and cookies
|
|
78
|
+
- Automatic locale setting via `before_action`
|
|
79
|
+
- URL helper integration
|
|
80
|
+
- Cookie persistence
|
|
81
|
+
- HTTP Accept-Language header fallback support
|
|
82
|
+
|
|
83
|
+
[Unreleased]: https://github.com/bigbadpanda-tech/rails-panda-i18n/compare/v1.1.0...HEAD
|
|
84
|
+
[1.1.0]: https://github.com/bigbadpanda-tech/rails-panda-i18n/compare/v1.0.6...v1.1.0
|
|
85
|
+
[1.0.6]: https://github.com/bigbadpanda-tech/rails-panda-i18n/compare/v1.0.5...v1.0.6
|
|
86
|
+
[1.0.5]: https://github.com/bigbadpanda-tech/rails-panda-i18n/compare/v1.0.4...v1.0.5
|
|
87
|
+
[1.0.4]: https://github.com/bigbadpanda-tech/rails-panda-i18n/compare/v1.0.2...v1.0.4
|
|
88
|
+
[1.0.2]: https://github.com/bigbadpanda-tech/rails-panda-i18n/compare/v1.0.1.3...v1.0.2
|
|
89
|
+
[1.0.1.3]: https://github.com/bigbadpanda-tech/rails-panda-i18n/compare/v1.0.1.2...v1.0.1.3
|
|
90
|
+
[1.0.1.2]: https://github.com/bigbadpanda-tech/rails-panda-i18n/compare/v1.0.1.1...v1.0.1.2
|
|
91
|
+
[1.0.1.1]: https://github.com/bigbadpanda-tech/rails-panda-i18n/compare/v1.0.0...v1.0.1.1
|
|
92
|
+
[1.0.0]: https://github.com/bigbadpanda-tech/rails-panda-i18n/releases/tag/v1.0.0
|
data/Gemfile
ADDED
data/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright 2015 bigbadpanda.com
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
# Rails Panda I18n
|
|
2
|
+
|
|
3
|
+
A Rails gem that provides automatic internationalization (i18n) support for Rails applications. It automatically detects user locale from URL parameters, cookies, or HTTP Accept-Language headers, and seamlessly integrates with Rails' URL helpers.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Automatic locale detection** from multiple sources (priority order):
|
|
8
|
+
1. URL parameters (e.g., `?hl=pt`)
|
|
9
|
+
2. Cookies
|
|
10
|
+
3. HTTP Accept-Language header
|
|
11
|
+
- **Automatic locale setting** via `before_action` callback
|
|
12
|
+
- **URL helper integration** - automatically adds locale parameter to all generated URLs
|
|
13
|
+
- **Cookie persistence** - saves user's language preference in a cookie (1 year expiration)
|
|
14
|
+
- **Fully configurable** - enable/disable features as needed
|
|
15
|
+
- **Rails 7.0+ compatible** (required for Ruby 3.2+ support)
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
Add this line to your application's Gemfile:
|
|
20
|
+
|
|
21
|
+
```ruby
|
|
22
|
+
gem "rails-panda-i18n"
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
And then execute:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
$ bundle install
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Usage
|
|
32
|
+
|
|
33
|
+
### Basic Setup
|
|
34
|
+
|
|
35
|
+
The gem automatically includes itself in `ActionController::Base`, so no explicit inclusion is needed. Simply configure it in your `ApplicationController`:
|
|
36
|
+
|
|
37
|
+
```ruby
|
|
38
|
+
class ApplicationController < ActionController::Base
|
|
39
|
+
use_rails_panda_i18n
|
|
40
|
+
end
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
That's it! The gem will now:
|
|
44
|
+
|
|
45
|
+
- Detect locale from URL parameters, cookies, or HTTP headers
|
|
46
|
+
- Set `I18n.locale` automatically on each request
|
|
47
|
+
- Add the locale parameter to all generated URLs
|
|
48
|
+
|
|
49
|
+
### Configuration Options
|
|
50
|
+
|
|
51
|
+
You can customize the behavior with various options:
|
|
52
|
+
|
|
53
|
+
```ruby
|
|
54
|
+
class ApplicationController < ActionController::Base
|
|
55
|
+
use_rails_panda_i18n(
|
|
56
|
+
# Cookie support
|
|
57
|
+
enable_cookie_support: true, # Enable/disable cookie support
|
|
58
|
+
cookie_name: :hl, # Cookie name (default: :hl)
|
|
59
|
+
|
|
60
|
+
# Parameter support
|
|
61
|
+
enable_param_support: true, # Enable/disable parameter support
|
|
62
|
+
param_name: :hl, # Parameter name (default: :hl)
|
|
63
|
+
|
|
64
|
+
# URL options
|
|
65
|
+
setup_default_url_options: true, # Enable URL helper integration
|
|
66
|
+
setup_class_default_url_options: true, # Add to class-level default_url_options
|
|
67
|
+
setup_instance_default_url_options: true, # Add to instance-level default_url_options
|
|
68
|
+
|
|
69
|
+
# Automatic locale setting
|
|
70
|
+
setup_locale_on_before_action: true # Automatically set locale via before_action
|
|
71
|
+
)
|
|
72
|
+
end
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Examples
|
|
76
|
+
|
|
77
|
+
#### Custom Parameter and Cookie Names
|
|
78
|
+
|
|
79
|
+
```ruby
|
|
80
|
+
class ApplicationController < ActionController::Base
|
|
81
|
+
use_rails_panda_i18n(
|
|
82
|
+
cookie_name: :language,
|
|
83
|
+
param_name: :lang
|
|
84
|
+
)
|
|
85
|
+
end
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Now the locale will be detected from `?lang=pt` and stored in a `language` cookie.
|
|
89
|
+
|
|
90
|
+
#### Disable Cookie Support
|
|
91
|
+
|
|
92
|
+
```ruby
|
|
93
|
+
class ApplicationController < ActionController::Base
|
|
94
|
+
use_rails_panda_i18n(
|
|
95
|
+
enable_cookie_support: false
|
|
96
|
+
)
|
|
97
|
+
end
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
#### Disable Parameter Support
|
|
101
|
+
|
|
102
|
+
```ruby
|
|
103
|
+
class ApplicationController < ActionController::Base
|
|
104
|
+
use_rails_panda_i18n(
|
|
105
|
+
enable_param_support: false
|
|
106
|
+
)
|
|
107
|
+
end
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
#### Manual Locale Setting
|
|
111
|
+
|
|
112
|
+
If you want to set the locale manually instead of using the `before_action`:
|
|
113
|
+
|
|
114
|
+
```ruby
|
|
115
|
+
class ApplicationController < ActionController::Base
|
|
116
|
+
use_rails_panda_i18n(
|
|
117
|
+
setup_locale_on_before_action: false
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
before_action :set_locale
|
|
121
|
+
|
|
122
|
+
private
|
|
123
|
+
|
|
124
|
+
def set_locale
|
|
125
|
+
locale = rails_panda__get_user_locale || I18n.default_locale
|
|
126
|
+
I18n.locale = locale
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
#### Disable URL Helper Integration
|
|
132
|
+
|
|
133
|
+
```ruby
|
|
134
|
+
class ApplicationController < ActionController::Base
|
|
135
|
+
use_rails_panda_i18n(
|
|
136
|
+
setup_default_url_options: false
|
|
137
|
+
)
|
|
138
|
+
end
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### Locale Detection Priority
|
|
142
|
+
|
|
143
|
+
The gem detects locale in the following order:
|
|
144
|
+
|
|
145
|
+
1. **URL Parameter** - If present and valid (e.g., `?hl=pt`)
|
|
146
|
+
2. **Cookie** - If present and valid
|
|
147
|
+
3. **HTTP Accept-Language Header** - Falls back to browser's language preference
|
|
148
|
+
|
|
149
|
+
Only locales in `I18n.available_locales` are considered valid.
|
|
150
|
+
|
|
151
|
+
### URL Helper Integration
|
|
152
|
+
|
|
153
|
+
When enabled, the gem automatically adds the locale parameter to all URLs generated by Rails URL helpers:
|
|
154
|
+
|
|
155
|
+
```ruby
|
|
156
|
+
# If current locale is :pt
|
|
157
|
+
root_path
|
|
158
|
+
# => "/?hl=pt"
|
|
159
|
+
|
|
160
|
+
users_path
|
|
161
|
+
# => "/users?hl=pt"
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
This works with both class-level and instance-level `default_url_options`.
|
|
165
|
+
|
|
166
|
+
### Available Methods
|
|
167
|
+
|
|
168
|
+
The gem provides several methods you can use in your controllers:
|
|
169
|
+
|
|
170
|
+
#### `rails_panda__get_user_locale`
|
|
171
|
+
|
|
172
|
+
Returns the detected user locale (as a symbol) or `nil` if none found:
|
|
173
|
+
|
|
174
|
+
```ruby
|
|
175
|
+
def show
|
|
176
|
+
locale = rails_panda__get_user_locale
|
|
177
|
+
# => :pt, :en, etc. or nil
|
|
178
|
+
end
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
#### `rails_panda__add_ui_language_to(options)`
|
|
182
|
+
|
|
183
|
+
Adds the current locale to a hash of URL options:
|
|
184
|
+
|
|
185
|
+
```ruby
|
|
186
|
+
options = { controller: "users", action: "index" }
|
|
187
|
+
rails_panda__add_ui_language_to(options)
|
|
188
|
+
# => { controller: "users", action: "index", hl: :pt }
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
#### `rails_panda__set_locale`
|
|
192
|
+
|
|
193
|
+
Sets the locale and cookie (if cookie support is enabled):
|
|
194
|
+
|
|
195
|
+
```ruby
|
|
196
|
+
rails_panda__set_locale
|
|
197
|
+
# Sets I18n.locale and cookie
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
## Requirements
|
|
201
|
+
|
|
202
|
+
- Ruby >= 3.2
|
|
203
|
+
- Rails >= 7.0 (required for Ruby 3.2+ support)
|
|
204
|
+
- `http_accept_language` gem (automatically included as a dependency)
|
|
205
|
+
|
|
206
|
+
## Configuration
|
|
207
|
+
|
|
208
|
+
Make sure you have configured `I18n.available_locales` in your Rails application:
|
|
209
|
+
|
|
210
|
+
```ruby
|
|
211
|
+
# config/initializers/i18n.rb
|
|
212
|
+
I18n.available_locales = [:en, :pt, :es, :fr]
|
|
213
|
+
I18n.default_locale = :en
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
## Development
|
|
217
|
+
|
|
218
|
+
After checking out the repo, run `bundle install` to install dependencies. Then, run `bundle exec rspec` to run the tests.
|
|
219
|
+
|
|
220
|
+
## Contributing
|
|
221
|
+
|
|
222
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/bigbadpanda-tech/rails-panda-i18n.
|
|
223
|
+
|
|
224
|
+
## License
|
|
225
|
+
|
|
226
|
+
The gem is available as open source under the terms of the [MIT License](LICENSE).
|
|
227
|
+
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "active_support"
|
|
4
|
+
require "active_support/concern"
|
|
5
|
+
|
|
6
|
+
module RailsPanda
|
|
7
|
+
module I18n
|
|
8
|
+
extend ActiveSupport::Concern
|
|
9
|
+
|
|
10
|
+
require "http_accept_language"
|
|
11
|
+
|
|
12
|
+
module ClassMethods
|
|
13
|
+
def use_rails_panda_i18n(options = {})
|
|
14
|
+
options = {
|
|
15
|
+
setup_default_url_options: true,
|
|
16
|
+
setup_class_default_url_options: true,
|
|
17
|
+
setup_instance_default_url_options: true,
|
|
18
|
+
setup_locale_on_before_action: true,
|
|
19
|
+
enable_cookie_support: true,
|
|
20
|
+
cookie_name: :hl,
|
|
21
|
+
enable_param_support: true,
|
|
22
|
+
param_name: :hl
|
|
23
|
+
}.merge(options)
|
|
24
|
+
|
|
25
|
+
if options[:enable_cookie_support]
|
|
26
|
+
mattr_accessor :ui_language_cookie_name
|
|
27
|
+
self.ui_language_cookie_name = options[:cookie_name].to_sym
|
|
28
|
+
else
|
|
29
|
+
mattr_reader :ui_language_cookie_name
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
if options[:enable_param_support]
|
|
33
|
+
mattr_accessor :ui_language_param_name
|
|
34
|
+
self.ui_language_param_name = options[:param_name].to_sym
|
|
35
|
+
|
|
36
|
+
if options[:setup_default_url_options] && options[:setup_class_default_url_options]
|
|
37
|
+
include RailsPanda::I18n::MethodClassDefaultUrlOptions
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
if options[:setup_default_url_options] && options[:setup_instance_default_url_options]
|
|
41
|
+
include RailsPanda::I18n::MethodInstanceDefaultUrlOptions
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
else
|
|
45
|
+
mattr_reader :ui_language_param_name
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
before_action :rails_panda__set_locale if options[:setup_locale_on_before_action]
|
|
49
|
+
|
|
50
|
+
include RailsPanda::I18n::Methods
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
module MethodClassDefaultUrlOptions
|
|
55
|
+
extend ActiveSupport::Concern
|
|
56
|
+
|
|
57
|
+
module ClassMethods
|
|
58
|
+
def default_url_options(options = {})
|
|
59
|
+
rails_panda__add_ui_language_to options
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
module MethodInstanceDefaultUrlOptions
|
|
65
|
+
extend ActiveSupport::Concern
|
|
66
|
+
|
|
67
|
+
def default_url_options(options = {})
|
|
68
|
+
rails_panda__add_ui_language_to options
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
module Methods
|
|
73
|
+
extend ActiveSupport::Concern
|
|
74
|
+
|
|
75
|
+
module ClassMethods
|
|
76
|
+
def rails_panda__add_ui_language_to(options = {})
|
|
77
|
+
options.dup.tap do |o|
|
|
78
|
+
o[ui_language_param_name] = ::I18n.locale unless ui_language_param_name.nil?
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def rails_panda__add_ui_language_to(options = {})
|
|
84
|
+
options.dup.tap do |o|
|
|
85
|
+
o[ui_language_param_name] = ::I18n.locale unless ui_language_param_name.nil?
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def rails_panda__set_locale
|
|
90
|
+
new_locale = rails_panda__get_user_locale || ::I18n.default_locale
|
|
91
|
+
|
|
92
|
+
::I18n.locale = new_locale
|
|
93
|
+
|
|
94
|
+
unless ui_language_cookie_name.nil?
|
|
95
|
+
cookies[ui_language_cookie_name] = {
|
|
96
|
+
value: new_locale,
|
|
97
|
+
expires: 1.year.from_now
|
|
98
|
+
}
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def rails_panda__get_user_locale
|
|
103
|
+
available_langs = ::I18n.available_locales
|
|
104
|
+
|
|
105
|
+
cookie_lang = cookies[ui_language_cookie_name] unless ui_language_cookie_name.nil?
|
|
106
|
+
params_lang = params[ui_language_param_name] unless ui_language_param_name.nil?
|
|
107
|
+
|
|
108
|
+
if params_lang.present? && available_langs.include?(params_lang.to_sym)
|
|
109
|
+
params_lang.to_sym
|
|
110
|
+
elsif cookie_lang.present? && available_langs.include?(cookie_lang.to_sym)
|
|
111
|
+
cookie_lang.to_sym
|
|
112
|
+
else
|
|
113
|
+
result = http_accept_language.compatible_language_from available_langs
|
|
114
|
+
result.is_a?(String) ? result.to_sym : result
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
ActiveSupport.on_load(:action_controller) { include RailsPanda::I18n }
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
$LOAD_PATH.push File.expand_path("lib", __dir__)
|
|
2
|
+
|
|
3
|
+
require "rails_panda_i18n/version"
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.required_ruby_version = ">= 3.2"
|
|
7
|
+
|
|
8
|
+
spec.name = "rails-panda-i18n"
|
|
9
|
+
spec.version = RailsPanda::I18n::VERSION
|
|
10
|
+
spec.authors = ["João Saraiva"]
|
|
11
|
+
spec.email = ["panda@bigbadpanda.com"]
|
|
12
|
+
spec.homepage = "https://github.com/bigbadpanda-tech/rails-panda-i18n"
|
|
13
|
+
spec.summary = "Code that Rails applications use for dealing with internationalization (i18n)."
|
|
14
|
+
spec.description = "Code that Rails applications use for dealing with internationalization (i18n)."
|
|
15
|
+
spec.license = "MIT"
|
|
16
|
+
spec.metadata["rubygems_mfa_required"] = "true"
|
|
17
|
+
|
|
18
|
+
spec.files = Dir[
|
|
19
|
+
"lib/**/*",
|
|
20
|
+
"rails_panda_i18n.gemspec",
|
|
21
|
+
"Gemfile",
|
|
22
|
+
# "Rakefile",
|
|
23
|
+
"LICENSE",
|
|
24
|
+
"CHANGELOG.md",
|
|
25
|
+
"README.md"
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
spec.add_dependency "rails", ">= 7.0.0"
|
|
29
|
+
spec.add_dependency "http_accept_language" # Get the HTTP ACCEPT-LANGUAGE header
|
|
30
|
+
|
|
31
|
+
# spec.add_development_dependency "combustion"
|
|
32
|
+
spec.add_development_dependency "rake"
|
|
33
|
+
spec.add_development_dependency "rspec"
|
|
34
|
+
spec.add_development_dependency "rspec-rails"
|
|
35
|
+
spec.add_development_dependency "simplecov"
|
|
36
|
+
spec.add_development_dependency "rubocop"
|
|
37
|
+
spec.add_development_dependency "rubocop-rails"
|
|
38
|
+
spec.add_development_dependency "rubocop-rspec"
|
|
39
|
+
spec.add_development_dependency "rubocop-rspec_rails"
|
|
40
|
+
spec.add_development_dependency "rubocop-rake"
|
|
41
|
+
spec.add_development_dependency "rubocop-performance"
|
|
42
|
+
spec.add_development_dependency "standard"
|
|
43
|
+
spec.add_development_dependency "standard-rails"
|
|
44
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: rails-panda-i18n
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- João Saraiva
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: rails
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: 7.0.0
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ">="
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: 7.0.0
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: http_accept_language
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '0'
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '0'
|
|
40
|
+
- !ruby/object:Gem::Dependency
|
|
41
|
+
name: rake
|
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - ">="
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '0'
|
|
47
|
+
type: :development
|
|
48
|
+
prerelease: false
|
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - ">="
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '0'
|
|
54
|
+
- !ruby/object:Gem::Dependency
|
|
55
|
+
name: rspec
|
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
|
57
|
+
requirements:
|
|
58
|
+
- - ">="
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
version: '0'
|
|
61
|
+
type: :development
|
|
62
|
+
prerelease: false
|
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
64
|
+
requirements:
|
|
65
|
+
- - ">="
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: '0'
|
|
68
|
+
- !ruby/object:Gem::Dependency
|
|
69
|
+
name: rspec-rails
|
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
|
71
|
+
requirements:
|
|
72
|
+
- - ">="
|
|
73
|
+
- !ruby/object:Gem::Version
|
|
74
|
+
version: '0'
|
|
75
|
+
type: :development
|
|
76
|
+
prerelease: false
|
|
77
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
78
|
+
requirements:
|
|
79
|
+
- - ">="
|
|
80
|
+
- !ruby/object:Gem::Version
|
|
81
|
+
version: '0'
|
|
82
|
+
- !ruby/object:Gem::Dependency
|
|
83
|
+
name: simplecov
|
|
84
|
+
requirement: !ruby/object:Gem::Requirement
|
|
85
|
+
requirements:
|
|
86
|
+
- - ">="
|
|
87
|
+
- !ruby/object:Gem::Version
|
|
88
|
+
version: '0'
|
|
89
|
+
type: :development
|
|
90
|
+
prerelease: false
|
|
91
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
92
|
+
requirements:
|
|
93
|
+
- - ">="
|
|
94
|
+
- !ruby/object:Gem::Version
|
|
95
|
+
version: '0'
|
|
96
|
+
- !ruby/object:Gem::Dependency
|
|
97
|
+
name: rubocop
|
|
98
|
+
requirement: !ruby/object:Gem::Requirement
|
|
99
|
+
requirements:
|
|
100
|
+
- - ">="
|
|
101
|
+
- !ruby/object:Gem::Version
|
|
102
|
+
version: '0'
|
|
103
|
+
type: :development
|
|
104
|
+
prerelease: false
|
|
105
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
106
|
+
requirements:
|
|
107
|
+
- - ">="
|
|
108
|
+
- !ruby/object:Gem::Version
|
|
109
|
+
version: '0'
|
|
110
|
+
- !ruby/object:Gem::Dependency
|
|
111
|
+
name: rubocop-rails
|
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
|
113
|
+
requirements:
|
|
114
|
+
- - ">="
|
|
115
|
+
- !ruby/object:Gem::Version
|
|
116
|
+
version: '0'
|
|
117
|
+
type: :development
|
|
118
|
+
prerelease: false
|
|
119
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
120
|
+
requirements:
|
|
121
|
+
- - ">="
|
|
122
|
+
- !ruby/object:Gem::Version
|
|
123
|
+
version: '0'
|
|
124
|
+
- !ruby/object:Gem::Dependency
|
|
125
|
+
name: rubocop-rspec
|
|
126
|
+
requirement: !ruby/object:Gem::Requirement
|
|
127
|
+
requirements:
|
|
128
|
+
- - ">="
|
|
129
|
+
- !ruby/object:Gem::Version
|
|
130
|
+
version: '0'
|
|
131
|
+
type: :development
|
|
132
|
+
prerelease: false
|
|
133
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
134
|
+
requirements:
|
|
135
|
+
- - ">="
|
|
136
|
+
- !ruby/object:Gem::Version
|
|
137
|
+
version: '0'
|
|
138
|
+
- !ruby/object:Gem::Dependency
|
|
139
|
+
name: rubocop-rspec_rails
|
|
140
|
+
requirement: !ruby/object:Gem::Requirement
|
|
141
|
+
requirements:
|
|
142
|
+
- - ">="
|
|
143
|
+
- !ruby/object:Gem::Version
|
|
144
|
+
version: '0'
|
|
145
|
+
type: :development
|
|
146
|
+
prerelease: false
|
|
147
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
148
|
+
requirements:
|
|
149
|
+
- - ">="
|
|
150
|
+
- !ruby/object:Gem::Version
|
|
151
|
+
version: '0'
|
|
152
|
+
- !ruby/object:Gem::Dependency
|
|
153
|
+
name: rubocop-rake
|
|
154
|
+
requirement: !ruby/object:Gem::Requirement
|
|
155
|
+
requirements:
|
|
156
|
+
- - ">="
|
|
157
|
+
- !ruby/object:Gem::Version
|
|
158
|
+
version: '0'
|
|
159
|
+
type: :development
|
|
160
|
+
prerelease: false
|
|
161
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
162
|
+
requirements:
|
|
163
|
+
- - ">="
|
|
164
|
+
- !ruby/object:Gem::Version
|
|
165
|
+
version: '0'
|
|
166
|
+
- !ruby/object:Gem::Dependency
|
|
167
|
+
name: rubocop-performance
|
|
168
|
+
requirement: !ruby/object:Gem::Requirement
|
|
169
|
+
requirements:
|
|
170
|
+
- - ">="
|
|
171
|
+
- !ruby/object:Gem::Version
|
|
172
|
+
version: '0'
|
|
173
|
+
type: :development
|
|
174
|
+
prerelease: false
|
|
175
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
176
|
+
requirements:
|
|
177
|
+
- - ">="
|
|
178
|
+
- !ruby/object:Gem::Version
|
|
179
|
+
version: '0'
|
|
180
|
+
- !ruby/object:Gem::Dependency
|
|
181
|
+
name: standard
|
|
182
|
+
requirement: !ruby/object:Gem::Requirement
|
|
183
|
+
requirements:
|
|
184
|
+
- - ">="
|
|
185
|
+
- !ruby/object:Gem::Version
|
|
186
|
+
version: '0'
|
|
187
|
+
type: :development
|
|
188
|
+
prerelease: false
|
|
189
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
190
|
+
requirements:
|
|
191
|
+
- - ">="
|
|
192
|
+
- !ruby/object:Gem::Version
|
|
193
|
+
version: '0'
|
|
194
|
+
- !ruby/object:Gem::Dependency
|
|
195
|
+
name: standard-rails
|
|
196
|
+
requirement: !ruby/object:Gem::Requirement
|
|
197
|
+
requirements:
|
|
198
|
+
- - ">="
|
|
199
|
+
- !ruby/object:Gem::Version
|
|
200
|
+
version: '0'
|
|
201
|
+
type: :development
|
|
202
|
+
prerelease: false
|
|
203
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
204
|
+
requirements:
|
|
205
|
+
- - ">="
|
|
206
|
+
- !ruby/object:Gem::Version
|
|
207
|
+
version: '0'
|
|
208
|
+
description: Code that Rails applications use for dealing with internationalization
|
|
209
|
+
(i18n).
|
|
210
|
+
email:
|
|
211
|
+
- panda@bigbadpanda.com
|
|
212
|
+
executables: []
|
|
213
|
+
extensions: []
|
|
214
|
+
extra_rdoc_files: []
|
|
215
|
+
files:
|
|
216
|
+
- CHANGELOG.md
|
|
217
|
+
- Gemfile
|
|
218
|
+
- LICENSE
|
|
219
|
+
- README.md
|
|
220
|
+
- lib/rails/panda/i18n.rb
|
|
221
|
+
- lib/rails_panda_i18n.rb
|
|
222
|
+
- lib/rails_panda_i18n/i18n.rb
|
|
223
|
+
- lib/rails_panda_i18n/version.rb
|
|
224
|
+
- rails_panda_i18n.gemspec
|
|
225
|
+
homepage: https://github.com/bigbadpanda-tech/rails-panda-i18n
|
|
226
|
+
licenses:
|
|
227
|
+
- MIT
|
|
228
|
+
metadata:
|
|
229
|
+
rubygems_mfa_required: 'true'
|
|
230
|
+
rdoc_options: []
|
|
231
|
+
require_paths:
|
|
232
|
+
- lib
|
|
233
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
234
|
+
requirements:
|
|
235
|
+
- - ">="
|
|
236
|
+
- !ruby/object:Gem::Version
|
|
237
|
+
version: '3.2'
|
|
238
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
239
|
+
requirements:
|
|
240
|
+
- - ">="
|
|
241
|
+
- !ruby/object:Gem::Version
|
|
242
|
+
version: '0'
|
|
243
|
+
requirements: []
|
|
244
|
+
rubygems_version: 3.7.2
|
|
245
|
+
specification_version: 4
|
|
246
|
+
summary: Code that Rails applications use for dealing with internationalization (i18n).
|
|
247
|
+
test_files: []
|