r18n-rails-api 1.1.11 → 2.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 +4 -4
- data/README.md +6 -6
- data/lib/r18n-rails-api/backend.rb +1 -2
- data/lib/r18n-rails-api/filters.rb +1 -1
- data/lib/r18n-rails-api/loader.rb +0 -1
- data/lib/r18n-rails-api/rails_plural.rb +1 -2
- data/r18n-rails-api.gemspec +5 -4
- data/spec/backend_spec.rb +45 -46
- data/spec/data/simple/ru.rb +1 -1
- data/spec/filters_spec.rb +15 -18
- data/spec/loader_spec.rb +23 -16
- data/spec/spec_helper.rb +0 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e3b8232967c7ede7aa7c45724c20e9a0a025f474
|
4
|
+
data.tar.gz: 1b4630a00ed475b1a75b8a84187e96111879d232
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91815fe8b045489832685abcc407f64e75027b550b4b3b0777161c7631034bb5c67da8f126cf5e146c403582d8705153905e927428a27b0c43fa43dce9526cdc
|
7
|
+
data.tar.gz: 1d32715e9e807786b7f740e68e9dfae59e565e92055737eaa2631b46c2e0eb3dda35e2baac245d2ed6b7838b01bcb544537b9da27daa05ba5d197d93515a3f07
|
data/README.md
CHANGED
@@ -22,8 +22,8 @@ users: !!pl
|
|
22
22
|
```ruby
|
23
23
|
require 'r18n-rails-api'
|
24
24
|
|
25
|
-
i18n.greeting(:
|
26
|
-
i18n.users(:
|
25
|
+
i18n.greeting(name: 'John') #=> "Hi, John"
|
26
|
+
i18n.users(count: 5) #=> "5 users"
|
27
27
|
```
|
28
28
|
|
29
29
|
### Rails Translations
|
@@ -47,7 +47,7 @@ require 'r18n-rails-api'
|
|
47
47
|
I18n.load_path = ['i18n/en.yml']
|
48
48
|
i18n = R18n::I18n.new('en', R18n::Loader::Rails)
|
49
49
|
|
50
|
-
i18n.posts(:
|
50
|
+
i18n.posts(count: 5) #=> "5 posts"
|
51
51
|
```
|
52
52
|
|
53
53
|
### Backend
|
@@ -60,9 +60,9 @@ require 'r18n-rails-api'
|
|
60
60
|
R18n.set('en', 'path/to/translation')
|
61
61
|
I18n.backend = R18n::Backend
|
62
62
|
|
63
|
-
I18n.l Time.now, :
|
64
|
-
I18n.t :greeting, :
|
65
|
-
I18n.t :users, :
|
63
|
+
I18n.l Time.now, format: :full #=> "6th of December, 2009 22:44"
|
64
|
+
I18n.t :greeting, name: 'John' #=> "Hi, John"
|
65
|
+
I18n.t :users, count: 5 #=> "5 users"
|
66
66
|
```
|
67
67
|
|
68
68
|
## R18n Features
|
@@ -1,4 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
1
|
=begin
|
3
2
|
R18n backend for Rails I18n.
|
4
3
|
|
@@ -26,7 +25,7 @@ module R18n
|
|
26
25
|
#
|
27
26
|
# R18n.set locales, R18n::Loader::Rails
|
28
27
|
#
|
29
|
-
# I18n.l Time.now, :
|
28
|
+
# I18n.l Time.now, format: :full #=> "6th of December, 2009 22:44"
|
30
29
|
class Backend
|
31
30
|
include ::I18n::Backend::Transliterator
|
32
31
|
|
@@ -60,7 +60,7 @@ R18n::Filters.add('pl', :named_pluralization) do |content, config, param|
|
|
60
60
|
hash[type]
|
61
61
|
elsif content.is_a? R18n::UnpluralizetedTranslation
|
62
62
|
R18n::RailsUnpluralizetedTranslation.new(config[:locale], config[:path],
|
63
|
-
:
|
63
|
+
locale: config[:locale], translations: content.to_hash)
|
64
64
|
else
|
65
65
|
content
|
66
66
|
end
|
@@ -1,4 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
1
|
=begin
|
3
2
|
Converter between R18n and Rails I18n plural keys.
|
4
3
|
|
@@ -28,7 +27,7 @@ module R18n
|
|
28
27
|
|
29
28
|
# Convert Rails I18n plural key to R18n.
|
30
29
|
def self.to_r18n(k)
|
31
|
-
{ :
|
30
|
+
{ zero: 0, one: 1, few: 2, many: 'n', other: 'n' }[k]
|
32
31
|
end
|
33
32
|
|
34
33
|
# Convert R18n plural key to Rails I18n.
|
data/r18n-rails-api.gemspec
CHANGED
@@ -2,10 +2,11 @@ require File.expand_path('../../r18n-core/lib/r18n-core/version', __FILE__)
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.platform = Gem::Platform::RUBY
|
5
|
-
s.name
|
6
|
-
s.version
|
7
|
-
s.date
|
8
|
-
|
5
|
+
s.name = 'r18n-rails-api'
|
6
|
+
s.version = R18n::VERSION.dup
|
7
|
+
s.date = Time.now.strftime('%Y-%m-%d')
|
8
|
+
|
9
|
+
s.summary = 'Rails I18n compatibility for R18n'
|
9
10
|
s.description = <<-EOF
|
10
11
|
R18n backend for Rails I18n and R18n filters and loader to support Rails
|
11
12
|
translation format.
|
data/spec/backend_spec.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
1
|
require File.expand_path('../spec_helper', __FILE__)
|
3
2
|
|
4
3
|
describe R18n::Backend do
|
@@ -10,116 +9,116 @@ describe R18n::Backend do
|
|
10
9
|
end
|
11
10
|
|
12
11
|
it "returns available locales" do
|
13
|
-
I18n.available_locales.
|
12
|
+
expect(I18n.available_locales).to match_array([:en, :ru])
|
14
13
|
end
|
15
14
|
|
16
15
|
it "localizes objects" do
|
17
16
|
time = Time.at(0).utc
|
18
17
|
date = Date.parse('1970-01-01')
|
19
18
|
|
20
|
-
I18n.l(time).
|
21
|
-
I18n.l(date).
|
19
|
+
expect(I18n.l(time)).to eq 'Thu, 01 Jan 1970 00:00:00 +0000'
|
20
|
+
expect(I18n.l(date)).to eq '1970-01-01'
|
22
21
|
|
23
|
-
I18n.l(time, :
|
24
|
-
I18n.l(time, :
|
22
|
+
expect(I18n.l(time, format: :short)).to eq '01 Jan 00:00'
|
23
|
+
expect(I18n.l(time, format: :full)).to eq '1st of January, 1970 00:00'
|
25
24
|
|
26
|
-
I18n.l(-5000.5).
|
25
|
+
expect(I18n.l(-5000.5)).to eq '−5,000.5'
|
27
26
|
end
|
28
27
|
|
29
28
|
it "translates by key and scope" do
|
30
|
-
I18n.t('in.another.level').
|
31
|
-
I18n.t(:level, :
|
32
|
-
I18n.t(:'another.level', :
|
29
|
+
expect(I18n.t('in.another.level')).to eq 'Hierarchical'
|
30
|
+
expect(I18n.t(:level, scope: 'in.another')).to eq 'Hierarchical'
|
31
|
+
expect(I18n.t(:'another.level', scope: 'in')).to eq 'Hierarchical'
|
33
32
|
end
|
34
33
|
|
35
34
|
it "uses pluralization and variables" do
|
36
|
-
I18n.t('users', :
|
37
|
-
I18n.t('users', :
|
38
|
-
I18n.t('users', :
|
35
|
+
expect(I18n.t('users', count: 0)).to eq '0 users'
|
36
|
+
expect(I18n.t('users', count: 1)).to eq '1 user'
|
37
|
+
expect(I18n.t('users', count: 5)).to eq '5 users'
|
39
38
|
end
|
40
39
|
|
41
40
|
it "uses another separator" do
|
42
|
-
I18n.t('in/another/level', :
|
41
|
+
expect(I18n.t('in/another/level', separator: '/')).to eq 'Hierarchical'
|
43
42
|
end
|
44
43
|
|
45
44
|
it "translates array" do
|
46
|
-
I18n.t(['in.another.level', 'in.default']).
|
47
|
-
|
45
|
+
expect(I18n.t(['in.another.level', 'in.default'])).to eq(
|
46
|
+
['Hierarchical', 'Default'])
|
48
47
|
end
|
49
48
|
|
50
49
|
it "uses default value" do
|
51
|
-
I18n.t(:missed, :
|
52
|
-
I18n.t(:missed, :
|
53
|
-
I18n.t(:missed, :
|
54
|
-
I18n.t(:missed, :
|
50
|
+
expect(I18n.t(:missed, default: 'Default')).to eq 'Default'
|
51
|
+
expect(I18n.t(:missed, default: :default, scope: :in)).to eq 'Default'
|
52
|
+
expect(I18n.t(:missed, default: [:also_no, :'in.default'])).to eq 'Default'
|
53
|
+
expect(I18n.t(:missed, default: proc { |key| key.to_s })).to eq 'missed'
|
55
54
|
end
|
56
55
|
|
57
56
|
it "raises error on no translation" do
|
58
|
-
|
57
|
+
expect(-> {
|
59
58
|
I18n.backend.translate(:en, :missed)
|
60
|
-
}.
|
61
|
-
|
59
|
+
}).to raise_error(::I18n::MissingTranslationData)
|
60
|
+
|
61
|
+
expect(-> {
|
62
62
|
I18n.t(:missed)
|
63
|
-
}.
|
63
|
+
}).to raise_error(::I18n::MissingTranslationData)
|
64
64
|
end
|
65
65
|
|
66
66
|
it "reloads translations" do
|
67
|
-
|
67
|
+
expect(-> { I18n.t(:other) }).to raise_error(::I18n::MissingTranslationData)
|
68
68
|
I18n.load_path << OTHER
|
69
69
|
I18n.reload!
|
70
|
-
I18n.t(:other).
|
70
|
+
expect(I18n.t(:other)).to eq 'Other'
|
71
71
|
end
|
72
72
|
|
73
73
|
it "returns plain classes" do
|
74
|
-
I18n.t('in.another.level').class.
|
75
|
-
I18n.t('in.another').class.
|
74
|
+
expect(I18n.t('in.another.level').class).to eq ActiveSupport::SafeBuffer
|
75
|
+
expect(I18n.t('in.another').class).to eq Hash
|
76
76
|
end
|
77
77
|
|
78
78
|
it "returns correct unpluralized hash" do
|
79
|
-
I18n.t('users').
|
79
|
+
expect(I18n.t('users')).to eq ({ one: '1 user', other: '%{count} users' })
|
80
80
|
end
|
81
81
|
|
82
82
|
it "corrects detect untranslated, whem path is deeper than string" do
|
83
|
-
|
83
|
+
expect(-> {
|
84
84
|
I18n.t('in.another.level.deeper')
|
85
|
-
}.
|
85
|
+
}).to raise_error(::I18n::MissingTranslationData)
|
86
86
|
|
87
|
-
|
87
|
+
expect(-> {
|
88
88
|
I18n.t('in.another.level.go.deeper')
|
89
|
-
}.
|
89
|
+
}).to raise_error(::I18n::MissingTranslationData)
|
90
90
|
end
|
91
91
|
|
92
92
|
it "doesn't call String methods" do
|
93
|
-
I18n.t('in.another').class.
|
93
|
+
expect(I18n.t('in.another').class).to eq Hash
|
94
94
|
end
|
95
95
|
|
96
96
|
it "doesn't call object methods" do
|
97
|
-
|
97
|
+
expect(-> {
|
98
98
|
I18n.t('in.another.level.to_sym')
|
99
|
-
}.
|
99
|
+
}).to raise_error(::I18n::MissingTranslationData)
|
100
100
|
end
|
101
101
|
|
102
102
|
it "works deeper pluralization" do
|
103
|
-
I18n.t('users.other', :
|
103
|
+
expect(I18n.t('users.other', count: 5)).to eq '5 users'
|
104
104
|
end
|
105
105
|
|
106
106
|
it "returns hash with symbols keys" do
|
107
|
-
I18n.t('in').
|
108
|
-
:
|
109
|
-
:
|
110
|
-
}
|
107
|
+
expect(I18n.t('in')).to eq({
|
108
|
+
another: { level: 'Hierarchical' },
|
109
|
+
default: 'Default'
|
110
|
+
})
|
111
111
|
end
|
112
112
|
|
113
113
|
it "changes locale in place" do
|
114
114
|
I18n.load_path << PL
|
115
|
-
I18n.t('users', :
|
116
|
-
I18n.t('users', :
|
115
|
+
expect(I18n.t('users', count: 5)).to eq '5 users'
|
116
|
+
expect(I18n.t('users', count: 5, locale: :ru)).to eq 'Много'
|
117
117
|
|
118
|
-
I18n.l(Date.parse('1970-01-01'), :
|
118
|
+
expect(I18n.l(Date.parse('1970-01-01'), locale: :ru)).to eq '01.01.1970'
|
119
119
|
end
|
120
120
|
|
121
121
|
it "has transliterate method" do
|
122
|
-
I18n.transliterate('café').
|
122
|
+
expect(I18n.transliterate('café')).to eq 'cafe'
|
123
123
|
end
|
124
|
-
|
125
124
|
end
|
data/spec/data/simple/ru.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{ :
|
1
|
+
{ ru: { two: "Два" } }
|
data/spec/filters_spec.rb
CHANGED
@@ -1,28 +1,26 @@
|
|
1
|
-
# encoding: utf-8
|
2
1
|
require File.expand_path('../spec_helper', __FILE__)
|
3
2
|
|
4
3
|
describe 'Rails filters' do
|
5
|
-
|
6
4
|
it "uses named variables" do
|
7
|
-
i18n = R18n::Translation.new(EN, '', :
|
8
|
-
:
|
5
|
+
i18n = R18n::Translation.new(EN, '', locale: EN,
|
6
|
+
translations: { 'echo' => 'Value is %{value}' })
|
9
7
|
|
10
|
-
i18n.echo(:
|
11
|
-
i18n.echo(:
|
12
|
-
i18n.echo(:
|
13
|
-
i18n.echo(:
|
14
|
-
i18n.echo.
|
8
|
+
expect(i18n.echo(value: 'R18n')).to eq 'Value is R18n'
|
9
|
+
expect(i18n.echo(value: -5.5)).to eq 'Value is −5.5'
|
10
|
+
expect(i18n.echo(value: 5000)).to eq 'Value is 5,000'
|
11
|
+
expect(i18n.echo(value: '<b>')).to eq 'Value is <b>'
|
12
|
+
expect(i18n.echo).to eq 'Value is %{value}'
|
15
13
|
end
|
16
14
|
|
17
15
|
it "uses old variables syntax" do
|
18
|
-
i18n = R18n::Translation.new(EN, '', :
|
19
|
-
:
|
20
|
-
i18n.echo(:
|
16
|
+
i18n = R18n::Translation.new(EN, '', locale: EN,
|
17
|
+
translations: { 'echo' => 'Value is {{value}}' })
|
18
|
+
expect(i18n.echo(value: 'Old')).to eq 'Value is Old'
|
21
19
|
end
|
22
20
|
|
23
21
|
it "pluralizes by variable %{count}" do
|
24
|
-
i18n = R18n::Translation.new(EN, '', :
|
25
|
-
:
|
22
|
+
i18n = R18n::Translation.new(EN, '', locale: EN,
|
23
|
+
translations: {
|
26
24
|
'users' => R18n::Typed.new('pl', {
|
27
25
|
0 => 'no users',
|
28
26
|
1 => '1 user',
|
@@ -30,9 +28,8 @@ describe 'Rails filters' do
|
|
30
28
|
})
|
31
29
|
})
|
32
30
|
|
33
|
-
i18n.users(:
|
34
|
-
i18n.users(:
|
35
|
-
i18n.users(:
|
31
|
+
expect(i18n.users(count: 0)).to eq 'no users'
|
32
|
+
expect(i18n.users(count: 1)).to eq '1 user'
|
33
|
+
expect(i18n.users(count: 5)).to eq '5 users'
|
36
34
|
end
|
37
|
-
|
38
35
|
end
|
data/spec/loader_spec.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
1
|
require File.expand_path('../spec_helper', __FILE__)
|
3
2
|
|
4
3
|
describe R18n::Loader::Rails do
|
@@ -8,40 +7,48 @@ describe R18n::Loader::Rails do
|
|
8
7
|
end
|
9
8
|
|
10
9
|
it "returns available locales" do
|
11
|
-
@loader.available.
|
10
|
+
expect(@loader.available).to match_array([EN, RU])
|
12
11
|
end
|
13
12
|
|
14
13
|
it "loads translation" do
|
15
|
-
@loader.load(RU).
|
14
|
+
expect(@loader.load(RU)).to eq({ 'one' => 'Один', 'two' => 'Два' })
|
16
15
|
end
|
17
16
|
|
18
17
|
it "changes pluralization" do
|
19
|
-
@loader.load(EN).
|
18
|
+
expect(@loader.load(EN)).to eq({
|
20
19
|
'users' => R18n::Typed.new('pl', {
|
21
|
-
0
|
22
|
-
|
23
|
-
|
20
|
+
0 => 'Zero',
|
21
|
+
1 => 'One',
|
22
|
+
2 => 'Few',
|
23
|
+
'n' => 'Other'
|
24
|
+
})
|
25
|
+
})
|
24
26
|
end
|
25
27
|
|
26
28
|
it "changes Russian pluralization" do
|
27
29
|
I18n.load_path = [PL]
|
28
|
-
@loader.load(RU).
|
29
|
-
'users' => R18n::Typed.new('pl', {
|
30
|
-
0
|
31
|
-
|
32
|
-
|
30
|
+
expect(@loader.load(RU)).to eq({
|
31
|
+
'users' => R18n::Typed.new('pl', {\
|
32
|
+
0 => 'Ноль',
|
33
|
+
1 => 'Один',
|
34
|
+
2 => 'Несколько',
|
35
|
+
'n' => 'Много'
|
36
|
+
})
|
37
|
+
})
|
33
38
|
end
|
34
39
|
|
35
40
|
it "reloads translations on load_path changes" do
|
36
41
|
I18n.load_path << OTHER
|
37
|
-
@loader.load(RU).
|
38
|
-
|
42
|
+
expect(@loader.load(RU)).to eq({
|
43
|
+
'one' => 'Один',
|
44
|
+
'two' => 'Два',
|
45
|
+
'three' => 'Три'
|
46
|
+
})
|
39
47
|
end
|
40
48
|
|
41
49
|
it "changes hash on load_path changes" do
|
42
50
|
before = @loader.hash
|
43
51
|
I18n.load_path << OTHER
|
44
|
-
@loader.hash.
|
52
|
+
expect(@loader.hash).not_to eq before
|
45
53
|
end
|
46
|
-
|
47
54
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: r18n-rails-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.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: 2014-05
|
11
|
+
date: 2014-12-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: r18n-core
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 2.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: 2.0.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: i18n
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|