r18n-rails 3.2.0 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -12
- data/lib/r18n-rails.rb +2 -2
- data/lib/r18n-rails/filters.rb +1 -0
- data/lib/r18n-rails/helpers.rb +6 -6
- data/r18n-rails.gemspec +1 -1
- data/spec/app/app/controllers/test_controller.rb +2 -2
- data/spec/app/config/initializers/r18n.rb +1 -1
- data/spec/rails_spec.rb +21 -5
- data/spec/spec_helper.rb +0 -4
- metadata +6 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bffe7c01c01781a342b1dd447c2bf438a307cc5a5c8113e7520af8d4de706787
|
4
|
+
data.tar.gz: e261678db0929a8ac27f39e6b91e7f954bde7c363a48e8fee5438d4b6060876e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e100aec03ba69b888f04bf1bca45e8cd7d2e96b284d29478036e624e559bf9c663c0b1eeedec6dab8fd19fda2de3b45b7ced98d3b695972a2ed8613dbcab2802
|
7
|
+
data.tar.gz: 42f6d7bba9aad7561e312417f08c971840500587e2ab75e0a5299d786a89948d7f063891cd8cf523d37afe67040eaaa205ebc01a1c16ba22f7ac7f79bd1b55f9
|
data/README.md
CHANGED
@@ -7,16 +7,16 @@ documentation for more information.
|
|
7
7
|
|
8
8
|
## Features
|
9
9
|
|
10
|
-
R18n for Rails is fully
|
10
|
+
R18n for Rails is fully compatible with Rails I18n, and add extra features:
|
11
11
|
|
12
12
|
* Nice Ruby-style syntax.
|
13
13
|
* Filters.
|
14
14
|
* Model Translation (or any Ruby object).
|
15
|
-
*
|
15
|
+
* Auto-detect user locales.
|
16
16
|
* Flexible locales.
|
17
17
|
* Total flexibility.
|
18
18
|
|
19
|
-
See full features in [main README](https://github.com/
|
19
|
+
See full features in [main README](https://github.com/r18n/r18n/blob/master/README.md).
|
20
20
|
|
21
21
|
## How To
|
22
22
|
|
@@ -25,7 +25,7 @@ See full features in [main README](https://github.com/ai/r18n/blob/master/README
|
|
25
25
|
```
|
26
26
|
gem 'r18n-rails'
|
27
27
|
```
|
28
|
-
Now R18n will
|
28
|
+
Now R18n will auto-detect user locales.
|
29
29
|
2. Define your way to set locale manually. R18n will find it in
|
30
30
|
`params[:locale]` or `session[:locale]`. Best way is a put optional
|
31
31
|
locale prefix to URLs:
|
@@ -46,7 +46,7 @@ See full features in [main README](https://github.com/ai/r18n/blob/master/README
|
|
46
46
|
```
|
47
47
|
|
48
48
|
4. Translations in I18n format are stored in
|
49
|
-
|
49
|
+
`config/locales/%{locale}.yml`:
|
50
50
|
|
51
51
|
```yaml
|
52
52
|
en:
|
@@ -57,7 +57,7 @@ See full features in [main README](https://github.com/ai/r18n/blob/master/README
|
|
57
57
|
one: "One user"
|
58
58
|
many: "%{count} users"
|
59
59
|
```
|
60
|
-
Translations in R18n format go to
|
60
|
+
Translations in R18n format go to `app/i18n/%{locale}.yml`:
|
61
61
|
|
62
62
|
```yaml
|
63
63
|
user:
|
@@ -82,7 +82,7 @@ See full features in [main README](https://github.com/ai/r18n/blob/master/README
|
|
82
82
|
t.user.count(5)
|
83
83
|
```
|
84
84
|
|
85
|
-
6. Print dates and numbers in user
|
85
|
+
6. Print dates and numbers in user's tradition:
|
86
86
|
|
87
87
|
```ruby
|
88
88
|
l Date.today, :standard #=> "2009-12-20"
|
@@ -94,7 +94,7 @@ See full features in [main README](https://github.com/ai/r18n/blob/master/README
|
|
94
94
|
not only for ActiveRecord models
|
95
95
|
|
96
96
|
1. Add to migration columns for each of the supported locales, named as
|
97
|
-
|
97
|
+
`%{name}_%{locale}`:
|
98
98
|
|
99
99
|
```ruby
|
100
100
|
t.string :title_en
|
@@ -121,8 +121,8 @@ See full features in [main README](https://github.com/ai/r18n/blob/master/README
|
|
121
121
|
on current user locales.
|
122
122
|
|
123
123
|
8. Download translations for Rails system messages (validation, etc) from
|
124
|
-
https://github.com/svenfuchs/rails-i18n/tree/master/rails/locale
|
125
|
-
put them to `config/locales/` (because them use Rails I18n format).
|
124
|
+
[svenfuchs/rails-i18n](https://github.com/svenfuchs/rails-i18n/tree/master/rails/locale)
|
125
|
+
and put them to `config/locales/` (because them use Rails I18n format).
|
126
126
|
9. Add your own translations filters to `app/i18n/filters.rb`:
|
127
127
|
|
128
128
|
```ruby
|
@@ -147,8 +147,8 @@ See full features in [main README](https://github.com/ai/r18n/blob/master/README
|
|
147
147
|
## License
|
148
148
|
|
149
149
|
R18n is licensed under the GNU Lesser General Public License version 3.
|
150
|
-
You can read it in LICENSE file or in
|
150
|
+
You can read it in LICENSE file or in [www.gnu.org/licenses/lgpl-3.0.html](https://www.gnu.org/licenses/lgpl-3.0.html).
|
151
151
|
|
152
152
|
## Author
|
153
153
|
|
154
|
-
Andrey “A.I.” Sitnik
|
154
|
+
Andrey “A.I.” Sitnik [andrey@sitnik.ru](mailto:andrey@sitnik.ru)
|
data/lib/r18n-rails.rb
CHANGED
@@ -28,7 +28,7 @@ require_relative 'r18n-rails/filters'
|
|
28
28
|
R18n.default_places { [Rails.root.join('app/i18n'), R18n::Loader::Rails.new] }
|
29
29
|
|
30
30
|
ActionController::Base.helper(R18n::Rails::Helpers)
|
31
|
-
ActionController::Base.
|
31
|
+
ActionController::Base.include R18n::Rails::Controller
|
32
32
|
|
33
33
|
if ActionController::Base.respond_to? :before_action
|
34
34
|
ActionController::Base.send(:before_action, :set_r18n)
|
@@ -52,7 +52,7 @@ ActiveSupport.on_load(:after_initialize) do
|
|
52
52
|
i18n = R18n::I18n.new(
|
53
53
|
locale, R18n.default_places,
|
54
54
|
off_filters: :untranslated,
|
55
|
-
on_filters:
|
55
|
+
on_filters: :untranslated_bash
|
56
56
|
)
|
57
57
|
R18n.set(i18n)
|
58
58
|
else
|
data/lib/r18n-rails/filters.rb
CHANGED
data/lib/r18n-rails/helpers.rb
CHANGED
@@ -21,17 +21,17 @@ module R18n
|
|
21
21
|
module Rails
|
22
22
|
module Helpers
|
23
23
|
# Return current R18n I18n object, to use R18n API:
|
24
|
-
# *
|
25
|
-
# *
|
26
|
-
# *
|
24
|
+
# * `r18n.available_locales` – available application translations.
|
25
|
+
# * `r18n.locales` – List of user locales
|
26
|
+
# * `r18n.reload!` – Reload R18n translations
|
27
27
|
#
|
28
|
-
# You can get translations by
|
28
|
+
# You can get translations by `r18n.user.name`, but `t` helper is
|
29
29
|
# more beautiful, short and also support R18n syntax.
|
30
30
|
def r18n
|
31
31
|
R18n.get
|
32
32
|
end
|
33
33
|
|
34
|
-
# Extend
|
34
|
+
# Extend `t` helper to use also R18n syntax.
|
35
35
|
#
|
36
36
|
# t 'user.name' # Rails I18n style
|
37
37
|
# t.user.name # R18n style
|
@@ -44,7 +44,7 @@ module R18n
|
|
44
44
|
end
|
45
45
|
alias translate t
|
46
46
|
|
47
|
-
# Extend
|
47
|
+
# Extend `l` helper to use also R18n syntax.
|
48
48
|
#
|
49
49
|
# l Time.now # Rails I18n default format
|
50
50
|
# l Time.now, format: :short # Rails I18n style
|
data/r18n-rails.gemspec
CHANGED
@@ -25,7 +25,7 @@ Gem::Specification.new do |s|
|
|
25
25
|
|
26
26
|
s.author = 'Andrey Sitnik'
|
27
27
|
s.email = 'andrey@sitnik.ru'
|
28
|
-
s.homepage = 'https://github.com/
|
28
|
+
s.homepage = 'https://github.com/r18n/r18n/tree/master/r18n-rails'
|
29
29
|
s.license = 'LGPL-3.0'
|
30
30
|
|
31
31
|
s.add_dependency 'r18n-rails-api', "= #{R18n::VERSION}"
|
@@ -32,8 +32,8 @@ class TestController < ApplicationController
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def time
|
35
|
-
render plain:
|
36
|
-
|
35
|
+
render plain:
|
36
|
+
l(Time.at(0).utc) + "\n" + l(Time.at(0).utc, format: :short)
|
37
37
|
end
|
38
38
|
|
39
39
|
def human_time
|
data/spec/rails_spec.rb
CHANGED
@@ -21,11 +21,27 @@ describe TestController, type: :controller do
|
|
21
21
|
expect(response.body).to eq 'ru, en'
|
22
22
|
end
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
24
|
+
describe 'locales from http' do
|
25
|
+
it 'gets from regular locales' do
|
26
|
+
request.env['HTTP_ACCEPT_LANGUAGE'] = 'ru,fr;q=0.9'
|
27
|
+
get :locales
|
28
|
+
expect(response).to have_http_status(200)
|
29
|
+
expect(response.body).to eq 'ru, fr, en'
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'gets from wildcard' do
|
33
|
+
request.env['HTTP_ACCEPT_LANGUAGE'] = '*'
|
34
|
+
get :locales
|
35
|
+
expect(response).to have_http_status(200)
|
36
|
+
expect(response.body).to eq 'ru'
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'gets from regular locales with wildcard' do
|
40
|
+
request.env['HTTP_ACCEPT_LANGUAGE'] = 'ru, fr;q=0.9, *;q=0.5'
|
41
|
+
get :locales
|
42
|
+
expect(response).to have_http_status(200)
|
43
|
+
expect(response.body).to eq 'ru, fr, en'
|
44
|
+
end
|
29
45
|
end
|
30
46
|
|
31
47
|
it 'loads translations' do
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: r18n-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 4.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrey Sitnik
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-01-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: r18n-rails-api
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 4.0.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 4.0.0
|
27
27
|
description: |2
|
28
28
|
Out-of-box R18n support for Ruby on Rails.
|
29
29
|
It is just a wrapper for R18n Rails API and R18n core libraries.
|
@@ -73,7 +73,7 @@ files:
|
|
73
73
|
- spec/app/db/schema.rb
|
74
74
|
- spec/rails_spec.rb
|
75
75
|
- spec/spec_helper.rb
|
76
|
-
homepage: https://github.com/
|
76
|
+
homepage: https://github.com/r18n/r18n/tree/master/r18n-rails
|
77
77
|
licenses:
|
78
78
|
- LGPL-3.0
|
79
79
|
metadata: {}
|
@@ -92,8 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
92
|
- !ruby/object:Gem::Version
|
93
93
|
version: '0'
|
94
94
|
requirements: []
|
95
|
-
|
96
|
-
rubygems_version: 2.7.6
|
95
|
+
rubygems_version: 3.1.2
|
97
96
|
signing_key:
|
98
97
|
specification_version: 4
|
99
98
|
summary: R18n for Rails
|